b4860qds.c 31 KB

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