t4240qds.c 21 KB

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