t4240qds.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2009-2012 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #include <command.h>
  7. #include <i2c.h>
  8. #include <netdev.h>
  9. #include <linux/compiler.h>
  10. #include <asm/mmu.h>
  11. #include <asm/processor.h>
  12. #include <asm/cache.h>
  13. #include <asm/immap_85xx.h>
  14. #include <asm/fsl_law.h>
  15. #include <asm/fsl_serdes.h>
  16. #include <asm/fsl_liodn.h>
  17. #include <fm_eth.h>
  18. #include "../common/qixis.h"
  19. #include "../common/vsc3316_3308.h"
  20. #include "t4qds.h"
  21. #include "t4240qds_qixis.h"
  22. DECLARE_GLOBAL_DATA_PTR;
  23. static int8_t vsc3316_fsm1_tx[8][2] = { {0, 0}, {1, 1}, {6, 6}, {7, 7},
  24. {8, 8}, {9, 9}, {14, 14}, {15, 15} };
  25. static int8_t vsc3316_fsm2_tx[8][2] = { {2, 2}, {3, 3}, {4, 4}, {5, 5},
  26. {10, 10}, {11, 11}, {12, 12}, {13, 13} };
  27. static int8_t vsc3316_fsm1_rx[8][2] = { {2, 12}, {3, 13}, {4, 5}, {5, 4},
  28. {10, 11}, {11, 10}, {12, 2}, {13, 3} };
  29. static int8_t vsc3316_fsm2_rx[8][2] = { {0, 15}, {1, 14}, {6, 7}, {7, 6},
  30. {8, 9}, {9, 8}, {14, 1}, {15, 0} };
  31. int checkboard(void)
  32. {
  33. char buf[64];
  34. u8 sw;
  35. struct cpu_type *cpu = gd->arch.cpu;
  36. unsigned int i;
  37. printf("Board: %sQDS, ", cpu->name);
  38. printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, ",
  39. QIXIS_READ(id), QIXIS_READ(arch));
  40. sw = QIXIS_READ(brdcfg[0]);
  41. sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
  42. if (sw < 0x8)
  43. printf("vBank: %d\n", sw);
  44. else if (sw == 0x8)
  45. puts("Promjet\n");
  46. else if (sw == 0x9)
  47. puts("NAND\n");
  48. else
  49. printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
  50. printf("FPGA: v%d (%s), build %d",
  51. (int)QIXIS_READ(scver), qixis_read_tag(buf),
  52. (int)qixis_read_minor());
  53. /* the timestamp string contains "\n" at the end */
  54. printf(" on %s", qixis_read_time(buf));
  55. /*
  56. * Display the actual SERDES reference clocks as configured by the
  57. * dip switches on the board. Note that the SWx registers could
  58. * technically be set to force the reference clocks to match the
  59. * values that the SERDES expects (or vice versa). For now, however,
  60. * we just display both values and hope the user notices when they
  61. * don't match.
  62. */
  63. puts("SERDES Reference Clocks: ");
  64. sw = QIXIS_READ(brdcfg[2]);
  65. for (i = 0; i < MAX_SERDES; i++) {
  66. static const char * const freq[] = {
  67. "100", "125", "156.25", "161.1328125"};
  68. unsigned int clock = (sw >> (6 - 2 * i)) & 3;
  69. printf("SERDES%u=%sMHz ", i+1, freq[clock]);
  70. }
  71. puts("\n");
  72. return 0;
  73. }
  74. int select_i2c_ch_pca9547(u8 ch)
  75. {
  76. int ret;
  77. ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
  78. if (ret) {
  79. puts("PCA: failed to select proper channel\n");
  80. return ret;
  81. }
  82. return 0;
  83. }
  84. /*
  85. * read_voltage from sensor on I2C bus
  86. * We use average of 4 readings, waiting for 532us befor another reading
  87. */
  88. #define NUM_READINGS 4 /* prefer to be power of 2 for efficiency */
  89. #define WAIT_FOR_ADC 532 /* wait for 532 microseconds for ADC */
  90. static inline int read_voltage(void)
  91. {
  92. int i, ret, voltage_read = 0;
  93. u16 vol_mon;
  94. for (i = 0; i < NUM_READINGS; i++) {
  95. ret = i2c_read(I2C_VOL_MONITOR_ADDR,
  96. I2C_VOL_MONITOR_BUS_V_OFFSET, 1, (void *)&vol_mon, 2);
  97. if (ret) {
  98. printf("VID: failed to read core voltage\n");
  99. return ret;
  100. }
  101. if (vol_mon & I2C_VOL_MONITOR_BUS_V_OVF) {
  102. printf("VID: Core voltage sensor error\n");
  103. return -1;
  104. }
  105. debug("VID: bus voltage reads 0x%04x\n", vol_mon);
  106. /* LSB = 4mv */
  107. voltage_read += (vol_mon >> I2C_VOL_MONITOR_BUS_V_SHIFT) * 4;
  108. udelay(WAIT_FOR_ADC);
  109. }
  110. /* calculate the average */
  111. voltage_read /= NUM_READINGS;
  112. return voltage_read;
  113. }
  114. /*
  115. * We need to calculate how long before the voltage starts to drop or increase
  116. * It returns with the loop count. Each loop takes several readings (532us)
  117. */
  118. static inline int wait_for_voltage_change(int vdd_last)
  119. {
  120. int timeout, vdd_current;
  121. vdd_current = read_voltage();
  122. /* wait until voltage starts to drop */
  123. for (timeout = 0; abs(vdd_last - vdd_current) <= 4 &&
  124. timeout < 100; timeout++) {
  125. vdd_current = read_voltage();
  126. }
  127. if (timeout >= 100) {
  128. printf("VID: Voltage adjustment timeout\n");
  129. return -1;
  130. }
  131. return timeout;
  132. }
  133. /*
  134. * argument 'wait' is the time we know the voltage difference can be measured
  135. * this function keeps reading the voltage until it is stable
  136. */
  137. static inline int wait_for_voltage_stable(int wait)
  138. {
  139. int timeout, vdd_current, vdd_last;
  140. vdd_last = read_voltage();
  141. udelay(wait * NUM_READINGS * WAIT_FOR_ADC);
  142. /* wait until voltage is stable */
  143. vdd_current = read_voltage();
  144. for (timeout = 0; abs(vdd_last - vdd_current) >= 4 &&
  145. timeout < 100; timeout++) {
  146. vdd_last = vdd_current;
  147. udelay(wait * NUM_READINGS * WAIT_FOR_ADC);
  148. vdd_current = read_voltage();
  149. }
  150. if (timeout >= 100) {
  151. printf("VID: Voltage adjustment timeout\n");
  152. return -1;
  153. }
  154. return vdd_current;
  155. }
  156. static inline int set_voltage(u8 vid)
  157. {
  158. int wait, vdd_last;
  159. vdd_last = read_voltage();
  160. QIXIS_WRITE(brdcfg[6], vid);
  161. wait = wait_for_voltage_change(vdd_last);
  162. if (wait < 0)
  163. return -1;
  164. debug("VID: Waited %d us\n", wait * NUM_READINGS * WAIT_FOR_ADC);
  165. wait = wait ? wait : 1;
  166. vdd_last = wait_for_voltage_stable(wait);
  167. if (vdd_last < 0)
  168. return -1;
  169. debug("VID: Current voltage is %d mV\n", vdd_last);
  170. return vdd_last;
  171. }
  172. static int adjust_vdd(ulong vdd_override)
  173. {
  174. int re_enable = disable_interrupts();
  175. ccsr_gur_t __iomem *gur =
  176. (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  177. u32 fusesr;
  178. u8 vid, vid_current;
  179. int vdd_target, vdd_current, vdd_last;
  180. int ret;
  181. unsigned long vdd_string_override;
  182. char *vdd_string;
  183. static const uint16_t vdd[32] = {
  184. 0, /* unused */
  185. 9875, /* 0.9875V */
  186. 9750,
  187. 9625,
  188. 9500,
  189. 9375,
  190. 9250,
  191. 9125,
  192. 9000,
  193. 8875,
  194. 8750,
  195. 8625,
  196. 8500,
  197. 8375,
  198. 8250,
  199. 8125,
  200. 10000, /* 1.0000V */
  201. 10125,
  202. 10250,
  203. 10375,
  204. 10500,
  205. 10625,
  206. 10750,
  207. 10875,
  208. 11000,
  209. 0, /* reserved */
  210. };
  211. struct vdd_drive {
  212. u8 vid;
  213. unsigned voltage;
  214. };
  215. ret = select_i2c_ch_pca9547(I2C_MUX_CH_VOL_MONITOR);
  216. if (ret) {
  217. debug("VID: I2c failed to switch channel\n");
  218. ret = -1;
  219. goto exit;
  220. }
  221. /* get the voltage ID from fuse status register */
  222. fusesr = in_be32(&gur->dcfg_fusesr);
  223. vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_VID_SHIFT) &
  224. FSL_CORENET_DCFG_FUSESR_VID_MASK;
  225. if (vid == FSL_CORENET_DCFG_FUSESR_VID_MASK) {
  226. vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_ALTVID_SHIFT) &
  227. FSL_CORENET_DCFG_FUSESR_ALTVID_MASK;
  228. }
  229. vdd_target = vdd[vid];
  230. /* check override variable for overriding VDD */
  231. vdd_string = env_get("t4240qds_vdd_mv");
  232. if (vdd_override == 0 && vdd_string &&
  233. !strict_strtoul(vdd_string, 10, &vdd_string_override))
  234. vdd_override = vdd_string_override;
  235. if (vdd_override >= 819 && vdd_override <= 1212) {
  236. vdd_target = vdd_override * 10; /* convert to 1/10 mV */
  237. debug("VDD override is %lu\n", vdd_override);
  238. } else if (vdd_override != 0) {
  239. printf("Invalid value.\n");
  240. }
  241. if (vdd_target == 0) {
  242. debug("VID: VID not used\n");
  243. ret = 0;
  244. goto exit;
  245. } else {
  246. /* round up and divice by 10 to get a value in mV */
  247. vdd_target = DIV_ROUND_UP(vdd_target, 10);
  248. debug("VID: vid = %d mV\n", vdd_target);
  249. }
  250. /*
  251. * Check current board VID setting
  252. * Voltage regulator support output to 6.250mv step
  253. * The highes voltage allowed for this board is (vid=0x40) 1.21250V
  254. * the lowest is (vid=0x7f) 0.81875V
  255. */
  256. vid_current = QIXIS_READ(brdcfg[6]);
  257. vdd_current = 121250 - (vid_current - 0x40) * 625;
  258. debug("VID: Current vid setting is (0x%x) %d mV\n",
  259. vid_current, vdd_current/100);
  260. /*
  261. * Read voltage monitor to check real voltage.
  262. * Voltage monitor LSB is 4mv.
  263. */
  264. vdd_last = read_voltage();
  265. if (vdd_last < 0) {
  266. printf("VID: Could not read voltage sensor abort VID adjustment\n");
  267. ret = -1;
  268. goto exit;
  269. }
  270. debug("VID: Core voltage is at %d mV\n", vdd_last);
  271. /*
  272. * Adjust voltage to at or 8mV above target.
  273. * Each step of adjustment is 6.25mV.
  274. * Stepping down too fast may cause over current.
  275. */
  276. while (vdd_last > 0 && vid_current < 0x80 &&
  277. vdd_last > (vdd_target + 8)) {
  278. vid_current++;
  279. vdd_last = set_voltage(vid_current);
  280. }
  281. /*
  282. * Check if we need to step up
  283. * This happens when board voltage switch was set too low
  284. */
  285. while (vdd_last > 0 && vid_current >= 0x40 &&
  286. vdd_last < vdd_target + 2) {
  287. vid_current--;
  288. vdd_last = set_voltage(vid_current);
  289. }
  290. if (vdd_last > 0)
  291. printf("VID: Core voltage %d mV\n", vdd_last);
  292. else
  293. ret = -1;
  294. exit:
  295. if (re_enable)
  296. enable_interrupts();
  297. return ret;
  298. }
  299. /* Configure Crossbar switches for Front-Side SerDes Ports */
  300. int config_frontside_crossbar_vsc3316(void)
  301. {
  302. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  303. u32 srds_prtcl_s1, srds_prtcl_s2;
  304. int ret;
  305. ret = select_i2c_ch_pca9547(I2C_MUX_CH_VSC3316_FS);
  306. if (ret)
  307. return ret;
  308. srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
  309. FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
  310. srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
  311. switch (srds_prtcl_s1) {
  312. case 37:
  313. case 38:
  314. /* swap first lane and third lane on slot1 */
  315. vsc3316_fsm1_tx[0][1] = 14;
  316. vsc3316_fsm1_tx[6][1] = 0;
  317. vsc3316_fsm1_rx[1][1] = 2;
  318. vsc3316_fsm1_rx[6][1] = 13;
  319. case 39:
  320. case 40:
  321. case 45:
  322. case 46:
  323. case 47:
  324. case 48:
  325. /* swap first lane and third lane on slot2 */
  326. vsc3316_fsm1_tx[2][1] = 8;
  327. vsc3316_fsm1_tx[4][1] = 6;
  328. vsc3316_fsm1_rx[2][1] = 10;
  329. vsc3316_fsm1_rx[5][1] = 5;
  330. default:
  331. ret = vsc3316_config(VSC3316_FSM_TX_ADDR, vsc3316_fsm1_tx, 8);
  332. if (ret)
  333. return ret;
  334. ret = vsc3316_config(VSC3316_FSM_RX_ADDR, vsc3316_fsm1_rx, 8);
  335. if (ret)
  336. return ret;
  337. break;
  338. }
  339. srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
  340. FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
  341. srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
  342. switch (srds_prtcl_s2) {
  343. case 37:
  344. case 38:
  345. /* swap first lane and third lane on slot3 */
  346. vsc3316_fsm2_tx[2][1] = 11;
  347. vsc3316_fsm2_tx[5][1] = 4;
  348. vsc3316_fsm2_rx[2][1] = 9;
  349. vsc3316_fsm2_rx[4][1] = 7;
  350. case 39:
  351. case 40:
  352. case 45:
  353. case 46:
  354. case 47:
  355. case 48:
  356. case 49:
  357. case 50:
  358. case 51:
  359. case 52:
  360. case 53:
  361. case 54:
  362. /* swap first lane and third lane on slot4 */
  363. vsc3316_fsm2_tx[6][1] = 3;
  364. vsc3316_fsm2_tx[1][1] = 12;
  365. vsc3316_fsm2_rx[0][1] = 1;
  366. vsc3316_fsm2_rx[6][1] = 15;
  367. default:
  368. ret = vsc3316_config(VSC3316_FSM_TX_ADDR, vsc3316_fsm2_tx, 8);
  369. if (ret)
  370. return ret;
  371. ret = vsc3316_config(VSC3316_FSM_RX_ADDR, vsc3316_fsm2_rx, 8);
  372. if (ret)
  373. return ret;
  374. break;
  375. }
  376. return 0;
  377. }
  378. int config_backside_crossbar_mux(void)
  379. {
  380. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  381. u32 srds_prtcl_s3, srds_prtcl_s4;
  382. u8 brdcfg;
  383. srds_prtcl_s3 = in_be32(&gur->rcwsr[4]) &
  384. FSL_CORENET2_RCWSR4_SRDS3_PRTCL;
  385. srds_prtcl_s3 >>= FSL_CORENET2_RCWSR4_SRDS3_PRTCL_SHIFT;
  386. switch (srds_prtcl_s3) {
  387. case 0:
  388. /* SerDes3 is not enabled */
  389. break;
  390. case 1:
  391. case 2:
  392. case 9:
  393. case 10:
  394. /* SD3(0:7) => SLOT5(0:7) */
  395. brdcfg = QIXIS_READ(brdcfg[12]);
  396. brdcfg &= ~BRDCFG12_SD3MX_MASK;
  397. brdcfg |= BRDCFG12_SD3MX_SLOT5;
  398. QIXIS_WRITE(brdcfg[12], brdcfg);
  399. break;
  400. case 3:
  401. case 4:
  402. case 5:
  403. case 6:
  404. case 7:
  405. case 8:
  406. case 11:
  407. case 12:
  408. case 13:
  409. case 14:
  410. case 15:
  411. case 16:
  412. case 17:
  413. case 18:
  414. case 19:
  415. case 20:
  416. /* SD3(4:7) => SLOT6(0:3) */
  417. brdcfg = QIXIS_READ(brdcfg[12]);
  418. brdcfg &= ~BRDCFG12_SD3MX_MASK;
  419. brdcfg |= BRDCFG12_SD3MX_SLOT6;
  420. QIXIS_WRITE(brdcfg[12], brdcfg);
  421. break;
  422. default:
  423. printf("WARNING: unsupported for SerDes3 Protocol %d\n",
  424. srds_prtcl_s3);
  425. return -1;
  426. }
  427. srds_prtcl_s4 = in_be32(&gur->rcwsr[4]) &
  428. FSL_CORENET2_RCWSR4_SRDS4_PRTCL;
  429. srds_prtcl_s4 >>= FSL_CORENET2_RCWSR4_SRDS4_PRTCL_SHIFT;
  430. switch (srds_prtcl_s4) {
  431. case 0:
  432. /* SerDes4 is not enabled */
  433. break;
  434. case 1:
  435. case 2:
  436. /* 10b, SD4(0:7) => SLOT7(0:7) */
  437. brdcfg = QIXIS_READ(brdcfg[12]);
  438. brdcfg &= ~BRDCFG12_SD4MX_MASK;
  439. brdcfg |= BRDCFG12_SD4MX_SLOT7;
  440. QIXIS_WRITE(brdcfg[12], brdcfg);
  441. break;
  442. case 3:
  443. case 4:
  444. case 5:
  445. case 6:
  446. case 7:
  447. case 8:
  448. /* x1b, SD4(4:7) => SLOT8(0:3) */
  449. brdcfg = QIXIS_READ(brdcfg[12]);
  450. brdcfg &= ~BRDCFG12_SD4MX_MASK;
  451. brdcfg |= BRDCFG12_SD4MX_SLOT8;
  452. QIXIS_WRITE(brdcfg[12], brdcfg);
  453. break;
  454. case 9:
  455. case 10:
  456. case 11:
  457. case 12:
  458. case 13:
  459. case 14:
  460. case 15:
  461. case 16:
  462. case 18:
  463. /* 00b, SD4(4:5) => AURORA, SD4(6:7) => SATA */
  464. brdcfg = QIXIS_READ(brdcfg[12]);
  465. brdcfg &= ~BRDCFG12_SD4MX_MASK;
  466. brdcfg |= BRDCFG12_SD4MX_AURO_SATA;
  467. QIXIS_WRITE(brdcfg[12], brdcfg);
  468. break;
  469. default:
  470. printf("WARNING: unsupported for SerDes4 Protocol %d\n",
  471. srds_prtcl_s4);
  472. return -1;
  473. }
  474. return 0;
  475. }
  476. int board_early_init_r(void)
  477. {
  478. const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
  479. int flash_esel = find_tlb_idx((void *)flashbase, 1);
  480. /*
  481. * Remap Boot flash + PROMJET region to caching-inhibited
  482. * so that flash can be erased properly.
  483. */
  484. /* Flush d-cache and invalidate i-cache of any FLASH data */
  485. flush_dcache();
  486. invalidate_icache();
  487. if (flash_esel == -1) {
  488. /* very unlikely unless something is messed up */
  489. puts("Error: Could not find TLB for FLASH BASE\n");
  490. flash_esel = 2; /* give our best effort to continue */
  491. } else {
  492. /* invalidate existing TLB entry for flash + promjet */
  493. disable_tlb(flash_esel);
  494. }
  495. set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
  496. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  497. 0, flash_esel, BOOKE_PAGESZ_256M, 1);
  498. /* Disable remote I2C connection to qixis fpga */
  499. QIXIS_WRITE(brdcfg[5], QIXIS_READ(brdcfg[5]) & ~BRDCFG5_IRE);
  500. /*
  501. * Adjust core voltage according to voltage ID
  502. * This function changes I2C mux to channel 2.
  503. */
  504. if (adjust_vdd(0))
  505. printf("Warning: Adjusting core voltage failed.\n");
  506. /* Configure board SERDES ports crossbar */
  507. config_frontside_crossbar_vsc3316();
  508. config_backside_crossbar_mux();
  509. select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
  510. return 0;
  511. }
  512. unsigned long get_board_sys_clk(void)
  513. {
  514. u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
  515. #ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
  516. /* use accurate clock measurement */
  517. int freq = QIXIS_READ(clk_freq[0]) << 8 | QIXIS_READ(clk_freq[1]);
  518. int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
  519. u32 val;
  520. val = freq * base;
  521. if (val) {
  522. debug("SYS Clock measurement is: %d\n", val);
  523. return val;
  524. } else {
  525. printf("Warning: SYS clock measurement is invalid, using value from brdcfg1.\n");
  526. }
  527. #endif
  528. switch (sysclk_conf & 0x0F) {
  529. case QIXIS_SYSCLK_83:
  530. return 83333333;
  531. case QIXIS_SYSCLK_100:
  532. return 100000000;
  533. case QIXIS_SYSCLK_125:
  534. return 125000000;
  535. case QIXIS_SYSCLK_133:
  536. return 133333333;
  537. case QIXIS_SYSCLK_150:
  538. return 150000000;
  539. case QIXIS_SYSCLK_160:
  540. return 160000000;
  541. case QIXIS_SYSCLK_166:
  542. return 166666666;
  543. }
  544. return 66666666;
  545. }
  546. unsigned long get_board_ddr_clk(void)
  547. {
  548. u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
  549. #ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
  550. /* use accurate clock measurement */
  551. int freq = QIXIS_READ(clk_freq[2]) << 8 | QIXIS_READ(clk_freq[3]);
  552. int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
  553. u32 val;
  554. val = freq * base;
  555. if (val) {
  556. debug("DDR Clock measurement is: %d\n", val);
  557. return val;
  558. } else {
  559. printf("Warning: DDR clock measurement is invalid, using value from brdcfg1.\n");
  560. }
  561. #endif
  562. switch ((ddrclk_conf & 0x30) >> 4) {
  563. case QIXIS_DDRCLK_100:
  564. return 100000000;
  565. case QIXIS_DDRCLK_125:
  566. return 125000000;
  567. case QIXIS_DDRCLK_133:
  568. return 133333333;
  569. }
  570. return 66666666;
  571. }
  572. int misc_init_r(void)
  573. {
  574. u8 sw;
  575. void *srds_base = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
  576. serdes_corenet_t *srds_regs;
  577. u32 actual[MAX_SERDES];
  578. u32 pllcr0, expected;
  579. unsigned int i;
  580. sw = QIXIS_READ(brdcfg[2]);
  581. for (i = 0; i < MAX_SERDES; i++) {
  582. unsigned int clock = (sw >> (6 - 2 * i)) & 3;
  583. switch (clock) {
  584. case 0:
  585. actual[i] = SRDS_PLLCR0_RFCK_SEL_100;
  586. break;
  587. case 1:
  588. actual[i] = SRDS_PLLCR0_RFCK_SEL_125;
  589. break;
  590. case 2:
  591. actual[i] = SRDS_PLLCR0_RFCK_SEL_156_25;
  592. break;
  593. case 3:
  594. actual[i] = SRDS_PLLCR0_RFCK_SEL_161_13;
  595. break;
  596. }
  597. }
  598. for (i = 0; i < MAX_SERDES; i++) {
  599. srds_regs = srds_base + i * 0x1000;
  600. pllcr0 = srds_regs->bank[0].pllcr0;
  601. expected = pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
  602. if (expected != actual[i]) {
  603. printf("Warning: SERDES%u expects reference clock %sMHz, but actual is %sMHz\n",
  604. i + 1, serdes_clock_to_string(expected),
  605. serdes_clock_to_string(actual[i]));
  606. }
  607. }
  608. return 0;
  609. }
  610. int ft_board_setup(void *blob, bd_t *bd)
  611. {
  612. phys_addr_t base;
  613. phys_size_t size;
  614. ft_cpu_setup(blob, bd);
  615. base = env_get_bootm_low();
  616. size = env_get_bootm_size();
  617. fdt_fixup_memory(blob, (u64)base, (u64)size);
  618. #ifdef CONFIG_PCI
  619. pci_of_setup(blob, bd);
  620. #endif
  621. fdt_fixup_liodn(blob);
  622. fsl_fdt_fixup_dr_usb(blob, bd);
  623. #ifdef CONFIG_SYS_DPAA_FMAN
  624. fdt_fixup_fman_ethernet(blob);
  625. fdt_fixup_board_enet(blob);
  626. #endif
  627. return 0;
  628. }
  629. /*
  630. * This function is called by bdinfo to print detail board information.
  631. * As an exmaple for future board, we organize the messages into
  632. * several sections. If applicable, the message is in the format of
  633. * <name> = <value>
  634. * It should aligned with normal output of bdinfo command.
  635. *
  636. * Voltage: Core, DDR and another configurable voltages
  637. * Clock : Critical clocks which are not printed already
  638. * RCW : RCW source if not printed already
  639. * Misc : Other important information not in above catagories
  640. */
  641. void board_detail(void)
  642. {
  643. int i;
  644. u8 brdcfg[16], dutcfg[16], rst_ctl;
  645. int vdd, rcwsrc;
  646. static const char * const clk[] = {"66.67", "100", "125", "133.33"};
  647. for (i = 0; i < 16; i++) {
  648. brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i);
  649. dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i);
  650. }
  651. /* Voltage secion */
  652. if (!select_i2c_ch_pca9547(I2C_MUX_CH_VOL_MONITOR)) {
  653. vdd = read_voltage();
  654. if (vdd > 0)
  655. printf("Core voltage= %d mV\n", vdd);
  656. select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
  657. }
  658. printf("XVDD = 1.%d V\n", ((brdcfg[8] & 0xf) - 4) * 5 + 25);
  659. /* clock section */
  660. printf("SYSCLK = %s MHz\nDDRCLK = %s MHz\n",
  661. clk[(brdcfg[11] >> 2) & 0x3], clk[brdcfg[11] & 3]);
  662. /* RCW section */
  663. rcwsrc = (dutcfg[0] << 1) + (dutcfg[1] & 1);
  664. puts("RCW source = ");
  665. switch (rcwsrc) {
  666. case 0x017:
  667. case 0x01f:
  668. puts("8-bit NOR\n");
  669. break;
  670. case 0x027:
  671. case 0x02F:
  672. puts("16-bit NOR\n");
  673. break;
  674. case 0x040:
  675. puts("SDHC/eMMC\n");
  676. break;
  677. case 0x044:
  678. puts("SPI 16-bit addressing\n");
  679. break;
  680. case 0x045:
  681. puts("SPI 24-bit addressing\n");
  682. break;
  683. case 0x048:
  684. puts("I2C normal addressing\n");
  685. break;
  686. case 0x049:
  687. puts("I2C extended addressing\n");
  688. break;
  689. case 0x108:
  690. case 0x109:
  691. case 0x10a:
  692. case 0x10b:
  693. puts("8-bit NAND, 2KB\n");
  694. break;
  695. default:
  696. if ((rcwsrc >= 0x080) && (rcwsrc <= 0x09f))
  697. puts("Hard-coded RCW\n");
  698. else if ((rcwsrc >= 0x110) && (rcwsrc <= 0x11f))
  699. puts("8-bit NAND, 4KB\n");
  700. else
  701. puts("unknown\n");
  702. break;
  703. }
  704. /* Misc section */
  705. rst_ctl = QIXIS_READ(rst_ctl);
  706. puts("HRESET_REQ = ");
  707. switch (rst_ctl & 0x30) {
  708. case 0x00:
  709. puts("Ignored\n");
  710. break;
  711. case 0x10:
  712. puts("Assert HRESET\n");
  713. break;
  714. case 0x30:
  715. puts("Reset system\n");
  716. break;
  717. default:
  718. puts("N/A\n");
  719. break;
  720. }
  721. }
  722. /*
  723. * Reverse engineering switch settings.
  724. * Some bits cannot be figured out. They will be displayed as
  725. * underscore in binary format. mask[] has those bits.
  726. * Some bits are calculated differently than the actual switches
  727. * if booting with overriding by FPGA.
  728. */
  729. void qixis_dump_switch(void)
  730. {
  731. int i;
  732. u8 sw[9];
  733. /*
  734. * Any bit with 1 means that bit cannot be reverse engineered.
  735. * It will be displayed as _ in binary format.
  736. */
  737. static const u8 mask[] = {0, 0, 0, 0, 0, 0x1, 0xcf, 0x3f, 0x1f};
  738. char buf[10];
  739. u8 brdcfg[16], dutcfg[16];
  740. for (i = 0; i < 16; i++) {
  741. brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i);
  742. dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i);
  743. }
  744. sw[0] = dutcfg[0];
  745. sw[1] = (dutcfg[1] << 0x07) |
  746. ((dutcfg[12] & 0xC0) >> 1) |
  747. ((dutcfg[11] & 0xE0) >> 3) |
  748. ((dutcfg[6] & 0x80) >> 6) |
  749. ((dutcfg[1] & 0x80) >> 7);
  750. sw[2] = ((brdcfg[1] & 0x0f) << 4) |
  751. ((brdcfg[1] & 0x30) >> 2) |
  752. ((brdcfg[1] & 0x40) >> 5) |
  753. ((brdcfg[1] & 0x80) >> 7);
  754. sw[3] = brdcfg[2];
  755. sw[4] = ((dutcfg[2] & 0x01) << 7) |
  756. ((dutcfg[2] & 0x06) << 4) |
  757. ((~QIXIS_READ(present)) & 0x10) |
  758. ((brdcfg[3] & 0x80) >> 4) |
  759. ((brdcfg[3] & 0x01) << 2) |
  760. ((brdcfg[6] == 0x62) ? 3 :
  761. ((brdcfg[6] == 0x5a) ? 2 :
  762. ((brdcfg[6] == 0x5e) ? 1 : 0)));
  763. sw[5] = ((brdcfg[0] & 0x0f) << 4) |
  764. ((QIXIS_READ(rst_ctl) & 0x30) >> 2) |
  765. ((brdcfg[0] & 0x40) >> 5);
  766. sw[6] = (brdcfg[11] & 0x20) |
  767. ((brdcfg[5] & 0x02) << 3);
  768. sw[7] = (((~QIXIS_READ(rst_ctl)) & 0x40) << 1) |
  769. ((brdcfg[5] & 0x10) << 2);
  770. sw[8] = ((brdcfg[12] & 0x08) << 4) |
  771. ((brdcfg[12] & 0x03) << 5);
  772. puts("DIP switch (reverse-engineering)\n");
  773. for (i = 0; i < 9; i++) {
  774. printf("SW%d = 0b%s (0x%02x)\n",
  775. i + 1, byte_to_binary_mask(sw[i], mask[i], buf), sw[i]);
  776. }
  777. }
  778. static int do_vdd_adjust(cmd_tbl_t *cmdtp,
  779. int flag, int argc,
  780. char * const argv[])
  781. {
  782. ulong override;
  783. if (argc < 2)
  784. return CMD_RET_USAGE;
  785. if (!strict_strtoul(argv[1], 10, &override))
  786. adjust_vdd(override); /* the value is checked by callee */
  787. else
  788. return CMD_RET_USAGE;
  789. return 0;
  790. }
  791. U_BOOT_CMD(
  792. vdd_override, 2, 0, do_vdd_adjust,
  793. "Override VDD",
  794. "- override with the voltage specified in mV, eg. 1050"
  795. );