t4qds.c 20 KB

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