b4860qds.c 31 KB

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