b4860qds.c 31 KB

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