b4860qds.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2011-2012 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #include <command.h>
  7. #include <env.h>
  8. #include <i2c.h>
  9. #include <irq_func.h>
  10. #include <netdev.h>
  11. #include <linux/compiler.h>
  12. #include <asm/mmu.h>
  13. #include <asm/processor.h>
  14. #include <linux/errno.h>
  15. #include <asm/cache.h>
  16. #include <asm/immap_85xx.h>
  17. #include <asm/fsl_law.h>
  18. #include <asm/fsl_serdes.h>
  19. #include <asm/fsl_liodn.h>
  20. #include <fm_eth.h>
  21. #include <hwconfig.h>
  22. #include "../common/qixis.h"
  23. #include "../common/vsc3316_3308.h"
  24. #include "../common/idt8t49n222a_serdes_clk.h"
  25. #include "../common/zm7300.h"
  26. #include "b4860qds.h"
  27. #include "b4860qds_qixis.h"
  28. #include "b4860qds_crossbar_con.h"
  29. #define CLK_MUX_SEL_MASK 0x4
  30. #define ETH_PHY_CLK_OUT 0x4
  31. DECLARE_GLOBAL_DATA_PTR;
  32. int checkboard(void)
  33. {
  34. char buf[64];
  35. u8 sw;
  36. struct cpu_type *cpu = gd->arch.cpu;
  37. static const char *const freq[] = {"100", "125", "156.25", "161.13",
  38. "122.88", "122.88", "122.88"};
  39. int clock;
  40. printf("Board: %sQDS, ", cpu->name);
  41. printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, ",
  42. QIXIS_READ(id), QIXIS_READ(arch));
  43. sw = QIXIS_READ(brdcfg[0]);
  44. sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
  45. if (sw < 0x8)
  46. printf("vBank: %d\n", sw);
  47. else if (sw >= 0x8 && sw <= 0xE)
  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. clock = (sw >> 5) & 7;
  67. printf("Bank1=%sMHz ", freq[clock]);
  68. sw = QIXIS_READ(brdcfg[4]);
  69. clock = (sw >> 6) & 3;
  70. printf("Bank2=%sMHz\n", freq[clock]);
  71. return 0;
  72. }
  73. int select_i2c_ch_pca(u8 ch)
  74. {
  75. int ret;
  76. /* Selecting proper channel via PCA*/
  77. ret = i2c_write(I2C_MUX_PCA_ADDR, 0x0, 1, &ch, 1);
  78. if (ret) {
  79. printf("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 WAIT_FOR_ADC 532 /* wait for 532 microseconds for ADC */
  89. #define NUM_READINGS 4 /* prefer to be power of 2 for efficiency */
  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. static int adjust_vdd(ulong vdd_override)
  115. {
  116. int re_enable = disable_interrupts();
  117. ccsr_gur_t __iomem *gur =
  118. (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  119. u32 fusesr;
  120. u8 vid;
  121. int vdd_target, vdd_last;
  122. int existing_voltage, temp_voltage, voltage; /* all in 1/10 mV */
  123. int ret;
  124. unsigned int orig_i2c_speed;
  125. unsigned long vdd_string_override;
  126. char *vdd_string;
  127. static const uint16_t vdd[32] = {
  128. 0, /* unused */
  129. 9875, /* 0.9875V */
  130. 9750,
  131. 9625,
  132. 9500,
  133. 9375,
  134. 9250,
  135. 9125,
  136. 9000,
  137. 8875,
  138. 8750,
  139. 8625,
  140. 8500,
  141. 8375,
  142. 8250,
  143. 8125,
  144. 10000, /* 1.0000V */
  145. 10125,
  146. 10250,
  147. 10375,
  148. 10500,
  149. 10625,
  150. 10750,
  151. 10875,
  152. 11000,
  153. 0, /* reserved */
  154. };
  155. struct vdd_drive {
  156. u8 vid;
  157. unsigned voltage;
  158. };
  159. ret = select_i2c_ch_pca(I2C_MUX_CH_VOL_MONITOR);
  160. if (ret) {
  161. printf("VID: I2c failed to switch channel\n");
  162. ret = -1;
  163. goto exit;
  164. }
  165. /* get the voltage ID from fuse status register */
  166. fusesr = in_be32(&gur->dcfg_fusesr);
  167. vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_VID_SHIFT) &
  168. FSL_CORENET_DCFG_FUSESR_VID_MASK;
  169. if (vid == FSL_CORENET_DCFG_FUSESR_VID_MASK) {
  170. vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_ALTVID_SHIFT) &
  171. FSL_CORENET_DCFG_FUSESR_ALTVID_MASK;
  172. }
  173. vdd_target = vdd[vid];
  174. debug("VID:Reading from from fuse,vid=%x vdd is %dmV\n",
  175. vid, vdd_target/10);
  176. /* check override variable for overriding VDD */
  177. vdd_string = env_get("b4qds_vdd_mv");
  178. if (vdd_override == 0 && vdd_string &&
  179. !strict_strtoul(vdd_string, 10, &vdd_string_override))
  180. vdd_override = vdd_string_override;
  181. if (vdd_override >= 819 && vdd_override <= 1212) {
  182. vdd_target = vdd_override * 10; /* convert to 1/10 mV */
  183. debug("VDD override is %lu\n", vdd_override);
  184. } else if (vdd_override != 0) {
  185. printf("Invalid value.\n");
  186. }
  187. if (vdd_target == 0) {
  188. printf("VID: VID not used\n");
  189. ret = 0;
  190. goto exit;
  191. }
  192. /*
  193. * Read voltage monitor to check real voltage.
  194. * Voltage monitor LSB is 4mv.
  195. */
  196. vdd_last = read_voltage();
  197. if (vdd_last < 0) {
  198. printf("VID: abort VID adjustment\n");
  199. ret = -1;
  200. goto exit;
  201. }
  202. debug("VID: Core voltage is at %d mV\n", vdd_last);
  203. ret = select_i2c_ch_pca(I2C_MUX_CH_DPM);
  204. if (ret) {
  205. printf("VID: I2c failed to switch channel to DPM\n");
  206. ret = -1;
  207. goto exit;
  208. }
  209. /* Round up to the value of step of Voltage regulator */
  210. voltage = roundup(vdd_target, ZM_STEP);
  211. debug("VID: rounded up voltage = %d\n", voltage);
  212. /* lower the speed to 100kHz to access ZM7300 device */
  213. debug("VID: Setting bus speed to 100KHz if not already set\n");
  214. orig_i2c_speed = i2c_get_bus_speed();
  215. if (orig_i2c_speed != 100000)
  216. i2c_set_bus_speed(100000);
  217. /* Read the existing level on board, if equal to requsted one,
  218. no need to re-set */
  219. existing_voltage = zm_read_voltage();
  220. /* allowing the voltage difference of one step 0.0125V acceptable */
  221. if ((existing_voltage >= voltage) &&
  222. (existing_voltage < (voltage + ZM_STEP))) {
  223. debug("VID: voltage already set as requested,returning\n");
  224. ret = existing_voltage;
  225. goto out;
  226. }
  227. debug("VID: Changing voltage for board from %dmV to %dmV\n",
  228. existing_voltage/10, voltage/10);
  229. if (zm_disable_wp() < 0) {
  230. ret = -1;
  231. goto out;
  232. }
  233. /* Change Voltage: the change is done through all the steps in the
  234. way, to avoid reset to the board due to power good signal fail
  235. in big voltage change gap jump.
  236. */
  237. if (existing_voltage > voltage) {
  238. temp_voltage = existing_voltage - ZM_STEP;
  239. while (temp_voltage >= voltage) {
  240. ret = zm_write_voltage(temp_voltage);
  241. if (ret == temp_voltage) {
  242. temp_voltage -= ZM_STEP;
  243. } else {
  244. /* ZM7300 device failed to set
  245. * the voltage */
  246. printf
  247. ("VID:Stepping down vol failed:%dmV\n",
  248. temp_voltage/10);
  249. ret = -1;
  250. goto out;
  251. }
  252. }
  253. } else {
  254. temp_voltage = existing_voltage + ZM_STEP;
  255. while (temp_voltage < (voltage + ZM_STEP)) {
  256. ret = zm_write_voltage(temp_voltage);
  257. if (ret == temp_voltage) {
  258. temp_voltage += ZM_STEP;
  259. } else {
  260. /* ZM7300 device failed to set
  261. * the voltage */
  262. printf
  263. ("VID:Stepping up vol failed:%dmV\n",
  264. temp_voltage/10);
  265. ret = -1;
  266. goto out;
  267. }
  268. }
  269. }
  270. if (zm_enable_wp() < 0)
  271. ret = -1;
  272. /* restore the speed to 400kHz */
  273. out: debug("VID: Restore the I2C bus speed to %dKHz\n",
  274. orig_i2c_speed/1000);
  275. i2c_set_bus_speed(orig_i2c_speed);
  276. if (ret < 0)
  277. goto exit;
  278. ret = select_i2c_ch_pca(I2C_MUX_CH_VOL_MONITOR);
  279. if (ret) {
  280. printf("VID: I2c failed to switch channel\n");
  281. ret = -1;
  282. goto exit;
  283. }
  284. vdd_last = read_voltage();
  285. select_i2c_ch_pca(I2C_CH_DEFAULT);
  286. if (vdd_last > 0)
  287. printf("VID: Core voltage %d mV\n", vdd_last);
  288. else
  289. ret = -1;
  290. exit:
  291. if (re_enable)
  292. enable_interrupts();
  293. return ret;
  294. }
  295. int configure_vsc3316_3308(void)
  296. {
  297. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  298. unsigned int num_vsc16_con, num_vsc08_con;
  299. u32 serdes1_prtcl, serdes2_prtcl;
  300. int ret;
  301. char buffer[HWCONFIG_BUFFER_SIZE];
  302. char *buf = NULL;
  303. serdes1_prtcl = in_be32(&gur->rcwsr[4]) &
  304. FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
  305. if (!serdes1_prtcl) {
  306. printf("SERDES1 is not enabled\n");
  307. return 0;
  308. }
  309. serdes1_prtcl >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
  310. debug("Using SERDES1 Protocol: 0x%x:\n", serdes1_prtcl);
  311. serdes2_prtcl = in_be32(&gur->rcwsr[4]) &
  312. FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
  313. if (!serdes2_prtcl) {
  314. printf("SERDES2 is not enabled\n");
  315. return 0;
  316. }
  317. serdes2_prtcl >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
  318. debug("Using SERDES2 Protocol: 0x%x:\n", serdes2_prtcl);
  319. switch (serdes1_prtcl) {
  320. case 0x29:
  321. case 0x2a:
  322. case 0x2C:
  323. case 0x2D:
  324. case 0x2E:
  325. /*
  326. * Configuration:
  327. * SERDES: 1
  328. * Lanes: A,B: SGMII
  329. * Lanes: C,D,E,F,G,H: CPRI
  330. */
  331. debug("Configuring crossbar to use onboard SGMII PHYs:"
  332. "srds_prctl:%x\n", serdes1_prtcl);
  333. num_vsc16_con = NUM_CON_VSC3316;
  334. /* Configure VSC3316 crossbar switch */
  335. ret = select_i2c_ch_pca(I2C_CH_VSC3316);
  336. if (!ret) {
  337. ret = vsc3316_config(VSC3316_TX_ADDRESS,
  338. vsc16_tx_4sfp_sgmii_12_56,
  339. num_vsc16_con);
  340. if (ret)
  341. return ret;
  342. ret = vsc3316_config(VSC3316_RX_ADDRESS,
  343. vsc16_rx_4sfp_sgmii_12_56,
  344. num_vsc16_con);
  345. if (ret)
  346. return ret;
  347. } else {
  348. return ret;
  349. }
  350. break;
  351. case 0x01:
  352. case 0x02:
  353. case 0x04:
  354. case 0x05:
  355. case 0x06:
  356. case 0x07:
  357. case 0x08:
  358. case 0x09:
  359. case 0x0A:
  360. case 0x0B:
  361. case 0x0C:
  362. case 0x2F:
  363. case 0x30:
  364. case 0x32:
  365. case 0x33:
  366. case 0x34:
  367. case 0x39:
  368. case 0x3A:
  369. case 0x3C:
  370. case 0x3D:
  371. case 0x5C:
  372. case 0x5D:
  373. /*
  374. * Configuration:
  375. * SERDES: 1
  376. * Lanes: A,B: AURORA
  377. * Lanes: C,d: SGMII
  378. * Lanes: E,F,G,H: CPRI
  379. */
  380. debug("Configuring crossbar for Aurora, SGMII 3 and 4,"
  381. " and CPRI. srds_prctl:%x\n", serdes1_prtcl);
  382. num_vsc16_con = NUM_CON_VSC3316;
  383. /* Configure VSC3316 crossbar switch */
  384. ret = select_i2c_ch_pca(I2C_CH_VSC3316);
  385. if (!ret) {
  386. ret = vsc3316_config(VSC3316_TX_ADDRESS,
  387. vsc16_tx_sfp_sgmii_aurora,
  388. num_vsc16_con);
  389. if (ret)
  390. return ret;
  391. ret = vsc3316_config(VSC3316_RX_ADDRESS,
  392. vsc16_rx_sfp_sgmii_aurora,
  393. num_vsc16_con);
  394. if (ret)
  395. return ret;
  396. } else {
  397. return ret;
  398. }
  399. break;
  400. #ifdef CONFIG_ARCH_B4420
  401. case 0x17:
  402. case 0x18:
  403. /*
  404. * Configuration:
  405. * SERDES: 1
  406. * Lanes: A,B,C,D: SGMII
  407. * Lanes: E,F,G,H: CPRI
  408. */
  409. debug("Configuring crossbar to use onboard SGMII PHYs:"
  410. "srds_prctl:%x\n", serdes1_prtcl);
  411. num_vsc16_con = NUM_CON_VSC3316;
  412. /* Configure VSC3316 crossbar switch */
  413. ret = select_i2c_ch_pca(I2C_CH_VSC3316);
  414. if (!ret) {
  415. ret = vsc3316_config(VSC3316_TX_ADDRESS,
  416. vsc16_tx_sgmii_lane_cd, num_vsc16_con);
  417. if (ret)
  418. return ret;
  419. ret = vsc3316_config(VSC3316_RX_ADDRESS,
  420. vsc16_rx_sgmii_lane_cd, num_vsc16_con);
  421. if (ret)
  422. return ret;
  423. } else {
  424. return ret;
  425. }
  426. break;
  427. #endif
  428. case 0x3E:
  429. case 0x0D:
  430. case 0x0E:
  431. case 0x12:
  432. num_vsc16_con = NUM_CON_VSC3316;
  433. /* Configure VSC3316 crossbar switch */
  434. ret = select_i2c_ch_pca(I2C_CH_VSC3316);
  435. if (!ret) {
  436. ret = vsc3316_config(VSC3316_TX_ADDRESS,
  437. vsc16_tx_sfp, num_vsc16_con);
  438. if (ret)
  439. return ret;
  440. ret = vsc3316_config(VSC3316_RX_ADDRESS,
  441. vsc16_rx_sfp, num_vsc16_con);
  442. if (ret)
  443. return ret;
  444. } else {
  445. return ret;
  446. }
  447. break;
  448. default:
  449. printf("WARNING:VSC crossbars programming not supported for:%x"
  450. " SerDes1 Protocol.\n", serdes1_prtcl);
  451. return -1;
  452. }
  453. num_vsc08_con = NUM_CON_VSC3308;
  454. /* Configure VSC3308 crossbar switch */
  455. ret = select_i2c_ch_pca(I2C_CH_VSC3308);
  456. switch (serdes2_prtcl) {
  457. #ifdef CONFIG_ARCH_B4420
  458. case 0x9d:
  459. #endif
  460. case 0x9E:
  461. case 0x9A:
  462. case 0x98:
  463. case 0x48:
  464. case 0x49:
  465. case 0x4E:
  466. case 0x79:
  467. case 0x7A:
  468. if (!ret) {
  469. ret = vsc3308_config(VSC3308_TX_ADDRESS,
  470. vsc08_tx_amc, num_vsc08_con);
  471. if (ret)
  472. return ret;
  473. ret = vsc3308_config(VSC3308_RX_ADDRESS,
  474. vsc08_rx_amc, num_vsc08_con);
  475. if (ret)
  476. return ret;
  477. } else {
  478. return ret;
  479. }
  480. break;
  481. case 0x80:
  482. case 0x81:
  483. case 0x82:
  484. case 0x83:
  485. case 0x84:
  486. case 0x85:
  487. case 0x86:
  488. case 0x87:
  489. case 0x88:
  490. case 0x89:
  491. case 0x8a:
  492. case 0x8b:
  493. case 0x8c:
  494. case 0x8d:
  495. case 0x8e:
  496. case 0xb1:
  497. case 0xb2:
  498. if (!ret) {
  499. /*
  500. * Extract hwconfig from environment since environment
  501. * is not setup properly yet
  502. */
  503. env_get_f("hwconfig", buffer, sizeof(buffer));
  504. buf = buffer;
  505. if (hwconfig_subarg_cmp_f("fsl_b4860_serdes2",
  506. "sfp_amc", "sfp", buf)) {
  507. #ifdef CONFIG_SYS_FSL_B4860QDS_XFI_ERR
  508. /* change default VSC3308 for XFI erratum */
  509. ret = vsc3308_config_adjust(VSC3308_TX_ADDRESS,
  510. vsc08_tx_sfp, num_vsc08_con);
  511. if (ret)
  512. return ret;
  513. ret = vsc3308_config_adjust(VSC3308_RX_ADDRESS,
  514. vsc08_rx_sfp, num_vsc08_con);
  515. if (ret)
  516. return ret;
  517. #else
  518. ret = vsc3308_config(VSC3308_TX_ADDRESS,
  519. vsc08_tx_sfp, num_vsc08_con);
  520. if (ret)
  521. return ret;
  522. ret = vsc3308_config(VSC3308_RX_ADDRESS,
  523. vsc08_rx_sfp, num_vsc08_con);
  524. if (ret)
  525. return ret;
  526. #endif
  527. } else {
  528. ret = vsc3308_config(VSC3308_TX_ADDRESS,
  529. vsc08_tx_amc, num_vsc08_con);
  530. if (ret)
  531. return ret;
  532. ret = vsc3308_config(VSC3308_RX_ADDRESS,
  533. vsc08_rx_amc, num_vsc08_con);
  534. if (ret)
  535. return ret;
  536. }
  537. } else {
  538. return ret;
  539. }
  540. break;
  541. default:
  542. printf("WARNING:VSC crossbars programming not supported for: %x"
  543. " SerDes2 Protocol.\n", serdes2_prtcl);
  544. return -1;
  545. }
  546. return 0;
  547. }
  548. static int calibrate_pll(serdes_corenet_t *srds_regs, int pll_num)
  549. {
  550. u32 rst_err;
  551. /* Steps For SerDes PLLs reset and reconfiguration
  552. * or PLL power-up procedure
  553. */
  554. debug("CALIBRATE PLL:%d\n", pll_num);
  555. clrbits_be32(&srds_regs->bank[pll_num].rstctl,
  556. SRDS_RSTCTL_SDRST_B);
  557. udelay(10);
  558. clrbits_be32(&srds_regs->bank[pll_num].rstctl,
  559. (SRDS_RSTCTL_SDEN | SRDS_RSTCTL_PLLRST_B));
  560. udelay(10);
  561. setbits_be32(&srds_regs->bank[pll_num].rstctl,
  562. SRDS_RSTCTL_RST);
  563. setbits_be32(&srds_regs->bank[pll_num].rstctl,
  564. (SRDS_RSTCTL_SDEN | SRDS_RSTCTL_PLLRST_B
  565. | SRDS_RSTCTL_SDRST_B));
  566. udelay(20);
  567. /* Check whether PLL has been locked or not */
  568. rst_err = in_be32(&srds_regs->bank[pll_num].rstctl) &
  569. SRDS_RSTCTL_RSTERR;
  570. rst_err >>= SRDS_RSTCTL_RSTERR_SHIFT;
  571. debug("RST_ERR value for PLL %d is: 0x%x:\n", pll_num, rst_err);
  572. if (rst_err)
  573. return rst_err;
  574. return rst_err;
  575. }
  576. static int check_pll_locks(serdes_corenet_t *srds_regs, int pll_num)
  577. {
  578. int ret = 0;
  579. u32 fcap, dcbias, bcap, pllcr1, pllcr0;
  580. if (calibrate_pll(srds_regs, pll_num)) {
  581. /* STEP 1 */
  582. /* Read fcap, dcbias and bcap value */
  583. clrbits_be32(&srds_regs->bank[pll_num].pllcr0,
  584. SRDS_PLLCR0_DCBIAS_OUT_EN);
  585. fcap = in_be32(&srds_regs->bank[pll_num].pllsr2) &
  586. SRDS_PLLSR2_FCAP;
  587. fcap >>= SRDS_PLLSR2_FCAP_SHIFT;
  588. bcap = in_be32(&srds_regs->bank[pll_num].pllsr2) &
  589. SRDS_PLLSR2_BCAP_EN;
  590. bcap >>= SRDS_PLLSR2_BCAP_EN_SHIFT;
  591. setbits_be32(&srds_regs->bank[pll_num].pllcr0,
  592. SRDS_PLLCR0_DCBIAS_OUT_EN);
  593. dcbias = in_be32(&srds_regs->bank[pll_num].pllsr2) &
  594. SRDS_PLLSR2_DCBIAS;
  595. dcbias >>= SRDS_PLLSR2_DCBIAS_SHIFT;
  596. debug("values of bcap:%x, fcap:%x and dcbias:%x\n",
  597. bcap, fcap, dcbias);
  598. if (fcap == 0 && bcap == 1) {
  599. /* Step 3 */
  600. clrbits_be32(&srds_regs->bank[pll_num].rstctl,
  601. (SRDS_RSTCTL_SDEN | SRDS_RSTCTL_PLLRST_B
  602. | SRDS_RSTCTL_SDRST_B));
  603. clrbits_be32(&srds_regs->bank[pll_num].pllcr1,
  604. SRDS_PLLCR1_BCAP_EN);
  605. setbits_be32(&srds_regs->bank[pll_num].pllcr1,
  606. SRDS_PLLCR1_BCAP_OVD);
  607. if (calibrate_pll(srds_regs, pll_num)) {
  608. /*save the fcap, dcbias and bcap values*/
  609. clrbits_be32(&srds_regs->bank[pll_num].pllcr0,
  610. SRDS_PLLCR0_DCBIAS_OUT_EN);
  611. fcap = in_be32(&srds_regs->bank[pll_num].pllsr2)
  612. & SRDS_PLLSR2_FCAP;
  613. fcap >>= SRDS_PLLSR2_FCAP_SHIFT;
  614. bcap = in_be32(&srds_regs->bank[pll_num].pllsr2)
  615. & SRDS_PLLSR2_BCAP_EN;
  616. bcap >>= SRDS_PLLSR2_BCAP_EN_SHIFT;
  617. setbits_be32(&srds_regs->bank[pll_num].pllcr0,
  618. SRDS_PLLCR0_DCBIAS_OUT_EN);
  619. dcbias = in_be32
  620. (&srds_regs->bank[pll_num].pllsr2) &
  621. SRDS_PLLSR2_DCBIAS;
  622. dcbias >>= SRDS_PLLSR2_DCBIAS_SHIFT;
  623. /* Step 4*/
  624. clrbits_be32(&srds_regs->bank[pll_num].rstctl,
  625. (SRDS_RSTCTL_SDEN | SRDS_RSTCTL_PLLRST_B
  626. | SRDS_RSTCTL_SDRST_B));
  627. setbits_be32(&srds_regs->bank[pll_num].pllcr1,
  628. SRDS_PLLCR1_BYP_CAL);
  629. clrbits_be32(&srds_regs->bank[pll_num].pllcr1,
  630. SRDS_PLLCR1_BCAP_EN);
  631. setbits_be32(&srds_regs->bank[pll_num].pllcr1,
  632. SRDS_PLLCR1_BCAP_OVD);
  633. /* change the fcap and dcbias to the saved
  634. * values from Step 3 */
  635. clrbits_be32(&srds_regs->bank[pll_num].pllcr1,
  636. SRDS_PLLCR1_PLL_FCAP);
  637. pllcr1 = (in_be32
  638. (&srds_regs->bank[pll_num].pllcr1)|
  639. (fcap << SRDS_PLLCR1_PLL_FCAP_SHIFT));
  640. out_be32(&srds_regs->bank[pll_num].pllcr1,
  641. pllcr1);
  642. clrbits_be32(&srds_regs->bank[pll_num].pllcr0,
  643. SRDS_PLLCR0_DCBIAS_OVRD);
  644. pllcr0 = (in_be32
  645. (&srds_regs->bank[pll_num].pllcr0)|
  646. (dcbias << SRDS_PLLCR0_DCBIAS_OVRD_SHIFT));
  647. out_be32(&srds_regs->bank[pll_num].pllcr0,
  648. pllcr0);
  649. ret = calibrate_pll(srds_regs, pll_num);
  650. if (ret)
  651. return ret;
  652. } else {
  653. goto out;
  654. }
  655. } else { /* Step 5 */
  656. clrbits_be32(&srds_regs->bank[pll_num].rstctl,
  657. (SRDS_RSTCTL_SDEN | SRDS_RSTCTL_PLLRST_B
  658. | SRDS_RSTCTL_SDRST_B));
  659. udelay(10);
  660. /* Change the fcap, dcbias, and bcap to the
  661. * values from Step 1 */
  662. setbits_be32(&srds_regs->bank[pll_num].pllcr1,
  663. SRDS_PLLCR1_BYP_CAL);
  664. clrbits_be32(&srds_regs->bank[pll_num].pllcr1,
  665. SRDS_PLLCR1_PLL_FCAP);
  666. pllcr1 = (in_be32(&srds_regs->bank[pll_num].pllcr1)|
  667. (fcap << SRDS_PLLCR1_PLL_FCAP_SHIFT));
  668. out_be32(&srds_regs->bank[pll_num].pllcr1,
  669. pllcr1);
  670. clrbits_be32(&srds_regs->bank[pll_num].pllcr0,
  671. SRDS_PLLCR0_DCBIAS_OVRD);
  672. pllcr0 = (in_be32(&srds_regs->bank[pll_num].pllcr0)|
  673. (dcbias << SRDS_PLLCR0_DCBIAS_OVRD_SHIFT));
  674. out_be32(&srds_regs->bank[pll_num].pllcr0,
  675. pllcr0);
  676. clrbits_be32(&srds_regs->bank[pll_num].pllcr1,
  677. SRDS_PLLCR1_BCAP_EN);
  678. setbits_be32(&srds_regs->bank[pll_num].pllcr1,
  679. SRDS_PLLCR1_BCAP_OVD);
  680. ret = calibrate_pll(srds_regs, pll_num);
  681. if (ret)
  682. return ret;
  683. }
  684. }
  685. out:
  686. return 0;
  687. }
  688. static int check_serdes_pll_locks(void)
  689. {
  690. serdes_corenet_t *srds1_regs =
  691. (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
  692. serdes_corenet_t *srds2_regs =
  693. (void *)CONFIG_SYS_FSL_CORENET_SERDES2_ADDR;
  694. int i, ret1, ret2;
  695. debug("\nSerDes1 Lock check\n");
  696. for (i = 0; i < CONFIG_SYS_FSL_SRDS_NUM_PLLS; i++) {
  697. ret1 = check_pll_locks(srds1_regs, i);
  698. if (ret1) {
  699. printf("SerDes1, PLL:%d didnt lock\n", i);
  700. return ret1;
  701. }
  702. }
  703. debug("\nSerDes2 Lock check\n");
  704. for (i = 0; i < CONFIG_SYS_FSL_SRDS_NUM_PLLS; i++) {
  705. ret2 = check_pll_locks(srds2_regs, i);
  706. if (ret2) {
  707. printf("SerDes2, PLL:%d didnt lock\n", i);
  708. return ret2;
  709. }
  710. }
  711. return 0;
  712. }
  713. int config_serdes1_refclks(void)
  714. {
  715. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  716. serdes_corenet_t *srds_regs =
  717. (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
  718. u32 serdes1_prtcl, lane;
  719. unsigned int flag_sgmii_aurora_prtcl = 0;
  720. int i;
  721. int ret = 0;
  722. serdes1_prtcl = in_be32(&gur->rcwsr[4]) &
  723. FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
  724. if (!serdes1_prtcl) {
  725. printf("SERDES1 is not enabled\n");
  726. return -1;
  727. }
  728. serdes1_prtcl >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
  729. debug("Using SERDES1 Protocol: 0x%x:\n", serdes1_prtcl);
  730. /* To prevent generation of reset request from SerDes
  731. * while changing the refclks, By setting SRDS_RST_MSK bit,
  732. * SerDes reset event cannot cause a reset request
  733. */
  734. setbits_be32(&gur->rstrqmr1, FSL_CORENET_RSTRQMR1_SRDS_RST_MSK);
  735. /* Reconfigure IDT idt8t49n222a device for CPRI to work
  736. * For this SerDes1's Refclk1 and refclk2 need to be set
  737. * to 122.88MHz
  738. */
  739. switch (serdes1_prtcl) {
  740. case 0x29:
  741. case 0x2A:
  742. case 0x2C:
  743. case 0x2D:
  744. case 0x2E:
  745. case 0x01:
  746. case 0x02:
  747. case 0x04:
  748. case 0x05:
  749. case 0x06:
  750. case 0x07:
  751. case 0x08:
  752. case 0x09:
  753. case 0x0A:
  754. case 0x0B:
  755. case 0x0C:
  756. case 0x2F:
  757. case 0x30:
  758. case 0x32:
  759. case 0x33:
  760. case 0x34:
  761. case 0x39:
  762. case 0x3A:
  763. case 0x3C:
  764. case 0x3D:
  765. case 0x5C:
  766. case 0x5D:
  767. debug("Configuring idt8t49n222a for CPRI SerDes clks:"
  768. " for srds_prctl:%x\n", serdes1_prtcl);
  769. ret = select_i2c_ch_pca(I2C_CH_IDT);
  770. if (!ret) {
  771. ret = set_serdes_refclk(IDT_SERDES1_ADDRESS, 1,
  772. SERDES_REFCLK_122_88,
  773. SERDES_REFCLK_122_88, 0);
  774. if (ret) {
  775. printf("IDT8T49N222A configuration failed.\n");
  776. goto out;
  777. } else
  778. debug("IDT8T49N222A configured.\n");
  779. } else {
  780. goto out;
  781. }
  782. select_i2c_ch_pca(I2C_CH_DEFAULT);
  783. /* Change SerDes1's Refclk1 to 125MHz for on board
  784. * SGMIIs or Aurora to work
  785. */
  786. for (lane = 0; lane < SRDS_MAX_LANES; lane++) {
  787. enum srds_prtcl lane_prtcl = serdes_get_prtcl
  788. (0, serdes1_prtcl, lane);
  789. switch (lane_prtcl) {
  790. case SGMII_FM1_DTSEC1:
  791. case SGMII_FM1_DTSEC2:
  792. case SGMII_FM1_DTSEC3:
  793. case SGMII_FM1_DTSEC4:
  794. case SGMII_FM1_DTSEC5:
  795. case SGMII_FM1_DTSEC6:
  796. case AURORA:
  797. flag_sgmii_aurora_prtcl++;
  798. break;
  799. default:
  800. break;
  801. }
  802. }
  803. if (flag_sgmii_aurora_prtcl)
  804. QIXIS_WRITE(brdcfg[4], QIXIS_SRDS1CLK_125);
  805. /* Steps For SerDes PLLs reset and reconfiguration after
  806. * changing SerDes's refclks
  807. */
  808. for (i = 0; i < CONFIG_SYS_FSL_SRDS_NUM_PLLS; i++) {
  809. debug("For PLL%d reset and reconfiguration after"
  810. " changing refclks\n", i+1);
  811. clrbits_be32(&srds_regs->bank[i].rstctl,
  812. SRDS_RSTCTL_SDRST_B);
  813. udelay(10);
  814. clrbits_be32(&srds_regs->bank[i].rstctl,
  815. (SRDS_RSTCTL_SDEN | SRDS_RSTCTL_PLLRST_B));
  816. udelay(10);
  817. setbits_be32(&srds_regs->bank[i].rstctl,
  818. SRDS_RSTCTL_RST);
  819. setbits_be32(&srds_regs->bank[i].rstctl,
  820. (SRDS_RSTCTL_SDEN | SRDS_RSTCTL_PLLRST_B
  821. | SRDS_RSTCTL_SDRST_B));
  822. }
  823. break;
  824. default:
  825. printf("WARNING:IDT8T49N222A configuration not"
  826. " supported for:%x SerDes1 Protocol.\n",
  827. serdes1_prtcl);
  828. }
  829. out:
  830. /* Clearing SRDS_RST_MSK bit as now
  831. * SerDes reset event can cause a reset request
  832. */
  833. clrbits_be32(&gur->rstrqmr1, FSL_CORENET_RSTRQMR1_SRDS_RST_MSK);
  834. return ret;
  835. }
  836. int config_serdes2_refclks(void)
  837. {
  838. ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  839. serdes_corenet_t *srds2_regs =
  840. (void *)CONFIG_SYS_FSL_CORENET_SERDES2_ADDR;
  841. u32 serdes2_prtcl;
  842. int ret = 0;
  843. int i;
  844. serdes2_prtcl = in_be32(&gur->rcwsr[4]) &
  845. FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
  846. if (!serdes2_prtcl) {
  847. debug("SERDES2 is not enabled\n");
  848. return -ENODEV;
  849. }
  850. serdes2_prtcl >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
  851. debug("Using SERDES2 Protocol: 0x%x:\n", serdes2_prtcl);
  852. /* To prevent generation of reset request from SerDes
  853. * while changing the refclks, By setting SRDS_RST_MSK bit,
  854. * SerDes reset event cannot cause a reset request
  855. */
  856. setbits_be32(&gur->rstrqmr1, FSL_CORENET_RSTRQMR1_SRDS_RST_MSK);
  857. /* Reconfigure IDT idt8t49n222a device for PCIe SATA to work
  858. * For this SerDes2's Refclk1 need to be set to 100MHz
  859. */
  860. switch (serdes2_prtcl) {
  861. #ifdef CONFIG_ARCH_B4420
  862. case 0x9d:
  863. #endif
  864. case 0x9E:
  865. case 0x9A:
  866. /* fallthrough */
  867. case 0xb1:
  868. case 0xb2:
  869. debug("Configuring IDT for PCIe SATA for srds_prctl:%x\n",
  870. serdes2_prtcl);
  871. ret = select_i2c_ch_pca(I2C_CH_IDT);
  872. if (!ret) {
  873. ret = set_serdes_refclk(IDT_SERDES2_ADDRESS, 2,
  874. SERDES_REFCLK_100,
  875. SERDES_REFCLK_156_25, 0);
  876. if (ret) {
  877. printf("IDT8T49N222A configuration failed.\n");
  878. goto out;
  879. } else
  880. debug("IDT8T49N222A configured.\n");
  881. } else {
  882. goto out;
  883. }
  884. select_i2c_ch_pca(I2C_CH_DEFAULT);
  885. /* Steps For SerDes PLLs reset and reconfiguration after
  886. * changing SerDes's refclks
  887. */
  888. for (i = 0; i < CONFIG_SYS_FSL_SRDS_NUM_PLLS; i++) {
  889. clrbits_be32(&srds2_regs->bank[i].rstctl,
  890. SRDS_RSTCTL_SDRST_B);
  891. udelay(10);
  892. clrbits_be32(&srds2_regs->bank[i].rstctl,
  893. (SRDS_RSTCTL_SDEN | SRDS_RSTCTL_PLLRST_B));
  894. udelay(10);
  895. setbits_be32(&srds2_regs->bank[i].rstctl,
  896. SRDS_RSTCTL_RST);
  897. setbits_be32(&srds2_regs->bank[i].rstctl,
  898. (SRDS_RSTCTL_SDEN | SRDS_RSTCTL_PLLRST_B
  899. | SRDS_RSTCTL_SDRST_B));
  900. udelay(10);
  901. }
  902. break;
  903. default:
  904. printf("IDT configuration not supported for:%x S2 Protocol.\n",
  905. serdes2_prtcl);
  906. }
  907. out:
  908. /* Clearing SRDS_RST_MSK bit as now
  909. * SerDes reset event can cause a reset request
  910. */
  911. clrbits_be32(&gur->rstrqmr1, FSL_CORENET_RSTRQMR1_SRDS_RST_MSK);
  912. return ret;
  913. }
  914. int board_early_init_r(void)
  915. {
  916. const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
  917. int flash_esel = find_tlb_idx((void *)flashbase, 1);
  918. int ret;
  919. u32 svr = SVR_SOC_VER(get_svr());
  920. /* Create law for MAPLE only for personalities having MAPLE */
  921. if ((svr == SVR_B4860) || (svr == SVR_B4440) ||
  922. (svr == SVR_B4420) || (svr == SVR_B4220)) {
  923. set_next_law(CONFIG_SYS_MAPLE_MEM_PHYS, LAW_SIZE_16M,
  924. LAW_TRGT_IF_MAPLE);
  925. }
  926. /*
  927. * Remap Boot flash + PROMJET region to caching-inhibited
  928. * so that flash can be erased properly.
  929. */
  930. /* Flush d-cache and invalidate i-cache of any FLASH data */
  931. flush_dcache();
  932. invalidate_icache();
  933. if (flash_esel == -1) {
  934. /* very unlikely unless something is messed up */
  935. puts("Error: Could not find TLB for FLASH BASE\n");
  936. flash_esel = 2; /* give our best effort to continue */
  937. } else {
  938. /* invalidate existing TLB entry for flash + promjet */
  939. disable_tlb(flash_esel);
  940. }
  941. set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
  942. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  943. 0, flash_esel, BOOKE_PAGESZ_256M, 1);
  944. /*
  945. * Adjust core voltage according to voltage ID
  946. * This function changes I2C mux to channel 2.
  947. */
  948. if (adjust_vdd(0) < 0)
  949. printf("Warning: Adjusting core voltage failed\n");
  950. /* SerDes1 refclks need to be set again, as default clks
  951. * are not suitable for CPRI and onboard SGMIIs to work
  952. * simultaneously.
  953. * This function will set SerDes1's Refclk1 and refclk2
  954. * as per SerDes1 protocols
  955. */
  956. if (config_serdes1_refclks())
  957. printf("SerDes1 Refclks couldn't set properly.\n");
  958. else
  959. printf("SerDes1 Refclks have been set.\n");
  960. /* SerDes2 refclks need to be set again, as default clks
  961. * are not suitable for PCIe SATA to work
  962. * This function will set SerDes2's Refclk1 and refclk2
  963. * for SerDes2 protocols having PCIe in them
  964. * for PCIe SATA to work
  965. */
  966. ret = config_serdes2_refclks();
  967. if (!ret)
  968. printf("SerDes2 Refclks have been set.\n");
  969. else if (ret == -ENODEV)
  970. printf("SerDes disable, Refclks couldn't change.\n");
  971. else
  972. printf("SerDes2 Refclk reconfiguring failed.\n");
  973. #if defined(CONFIG_SYS_FSL_ERRATUM_A006384) || \
  974. defined(CONFIG_SYS_FSL_ERRATUM_A006475)
  975. /* Rechecking the SerDes locks after all SerDes configurations
  976. * are done, As SerDes PLLs may not lock reliably at 5 G VCO
  977. * and at cold temperatures.
  978. * Following sequence ensure the proper locking of SerDes PLLs.
  979. */
  980. if (SVR_MAJ(get_svr()) == 1) {
  981. if (check_serdes_pll_locks())
  982. printf("SerDes plls still not locked properly.\n");
  983. else
  984. printf("SerDes plls have been locked well.\n");
  985. }
  986. #endif
  987. /* Configure VSC3316 and VSC3308 crossbar switches */
  988. if (configure_vsc3316_3308())
  989. printf("VSC:failed to configure VSC3316/3308.\n");
  990. else
  991. printf("VSC:VSC3316/3308 successfully configured.\n");
  992. select_i2c_ch_pca(I2C_CH_DEFAULT);
  993. return 0;
  994. }
  995. unsigned long get_board_sys_clk(void)
  996. {
  997. u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
  998. switch ((sysclk_conf & 0x0C) >> 2) {
  999. case QIXIS_CLK_100:
  1000. return 100000000;
  1001. case QIXIS_CLK_125:
  1002. return 125000000;
  1003. case QIXIS_CLK_133:
  1004. return 133333333;
  1005. }
  1006. return 66666666;
  1007. }
  1008. unsigned long get_board_ddr_clk(void)
  1009. {
  1010. u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
  1011. switch (ddrclk_conf & 0x03) {
  1012. case QIXIS_CLK_100:
  1013. return 100000000;
  1014. case QIXIS_CLK_125:
  1015. return 125000000;
  1016. case QIXIS_CLK_133:
  1017. return 133333333;
  1018. }
  1019. return 66666666;
  1020. }
  1021. static int serdes_refclock(u8 sw, u8 sdclk)
  1022. {
  1023. unsigned int clock;
  1024. int ret = -1;
  1025. u8 brdcfg4;
  1026. if (sdclk == 1) {
  1027. brdcfg4 = QIXIS_READ(brdcfg[4]);
  1028. if ((brdcfg4 & CLK_MUX_SEL_MASK) == ETH_PHY_CLK_OUT)
  1029. return SRDS_PLLCR0_RFCK_SEL_125;
  1030. else
  1031. clock = (sw >> 5) & 7;
  1032. } else
  1033. clock = (sw >> 6) & 3;
  1034. switch (clock) {
  1035. case 0:
  1036. ret = SRDS_PLLCR0_RFCK_SEL_100;
  1037. break;
  1038. case 1:
  1039. ret = SRDS_PLLCR0_RFCK_SEL_125;
  1040. break;
  1041. case 2:
  1042. ret = SRDS_PLLCR0_RFCK_SEL_156_25;
  1043. break;
  1044. case 3:
  1045. ret = SRDS_PLLCR0_RFCK_SEL_161_13;
  1046. break;
  1047. case 4:
  1048. case 5:
  1049. case 6:
  1050. ret = SRDS_PLLCR0_RFCK_SEL_122_88;
  1051. break;
  1052. default:
  1053. ret = -1;
  1054. break;
  1055. }
  1056. return ret;
  1057. }
  1058. #define NUM_SRDS_BANKS 2
  1059. int misc_init_r(void)
  1060. {
  1061. u8 sw;
  1062. serdes_corenet_t *srds_regs =
  1063. (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
  1064. u32 actual[NUM_SRDS_BANKS];
  1065. unsigned int i;
  1066. int clock;
  1067. sw = QIXIS_READ(brdcfg[2]);
  1068. clock = serdes_refclock(sw, 1);
  1069. if (clock >= 0)
  1070. actual[0] = clock;
  1071. else
  1072. printf("Warning: SDREFCLK1 switch setting is unsupported\n");
  1073. sw = QIXIS_READ(brdcfg[4]);
  1074. clock = serdes_refclock(sw, 2);
  1075. if (clock >= 0)
  1076. actual[1] = clock;
  1077. else
  1078. printf("Warning: SDREFCLK2 switch setting unsupported\n");
  1079. for (i = 0; i < NUM_SRDS_BANKS; i++) {
  1080. u32 pllcr0 = srds_regs->bank[i].pllcr0;
  1081. u32 expected = pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
  1082. if (expected != actual[i]) {
  1083. printf("Warning: SERDES bank %u expects reference clock"
  1084. " %sMHz, but actual is %sMHz\n", i + 1,
  1085. serdes_clock_to_string(expected),
  1086. serdes_clock_to_string(actual[i]));
  1087. }
  1088. }
  1089. return 0;
  1090. }
  1091. int ft_board_setup(void *blob, bd_t *bd)
  1092. {
  1093. phys_addr_t base;
  1094. phys_size_t size;
  1095. ft_cpu_setup(blob, bd);
  1096. base = env_get_bootm_low();
  1097. size = env_get_bootm_size();
  1098. fdt_fixup_memory(blob, (u64)base, (u64)size);
  1099. #ifdef CONFIG_PCI
  1100. pci_of_setup(blob, bd);
  1101. #endif
  1102. fdt_fixup_liodn(blob);
  1103. #ifdef CONFIG_HAS_FSL_DR_USB
  1104. fsl_fdt_fixup_dr_usb(blob, bd);
  1105. #endif
  1106. #ifdef CONFIG_SYS_DPAA_FMAN
  1107. fdt_fixup_fman_ethernet(blob);
  1108. fdt_fixup_board_enet(blob);
  1109. #endif
  1110. return 0;
  1111. }
  1112. /*
  1113. * Dump board switch settings.
  1114. * The bits that cannot be read/sampled via some FPGA or some
  1115. * registers, they will be displayed as
  1116. * underscore in binary format. mask[] has those bits.
  1117. * Some bits are calculated differently than the actual switches
  1118. * if booting with overriding by FPGA.
  1119. */
  1120. void qixis_dump_switch(void)
  1121. {
  1122. int i;
  1123. u8 sw[5];
  1124. /*
  1125. * Any bit with 1 means that bit cannot be reverse engineered.
  1126. * It will be displayed as _ in binary format.
  1127. */
  1128. static const u8 mask[] = {0x07, 0, 0, 0xff, 0};
  1129. char buf[10];
  1130. u8 brdcfg[16], dutcfg[16];
  1131. for (i = 0; i < 16; i++) {
  1132. brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i);
  1133. dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i);
  1134. }
  1135. sw[0] = ((brdcfg[0] & 0x0f) << 4) | \
  1136. (brdcfg[9] & 0x08);
  1137. sw[1] = ((dutcfg[1] & 0x01) << 7) | \
  1138. ((dutcfg[2] & 0x07) << 4) | \
  1139. ((dutcfg[6] & 0x10) >> 1) | \
  1140. ((dutcfg[6] & 0x80) >> 5) | \
  1141. ((dutcfg[1] & 0x40) >> 5) | \
  1142. (dutcfg[6] & 0x01);
  1143. sw[2] = dutcfg[0];
  1144. sw[3] = 0;
  1145. sw[4] = ((brdcfg[1] & 0x30) << 2) | \
  1146. ((brdcfg[1] & 0xc0) >> 2) | \
  1147. (brdcfg[1] & 0x0f);
  1148. puts("DIP switch settings:\n");
  1149. for (i = 0; i < 5; i++) {
  1150. printf("SW%d = 0b%s (0x%02x)\n",
  1151. i + 1, byte_to_binary_mask(sw[i], mask[i], buf), sw[i]);
  1152. }
  1153. }