fsl_corenet_serdes.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2009-2011 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  7. #include <hwconfig.h>
  8. #endif
  9. #include <asm/fsl_serdes.h>
  10. #include <asm/immap_85xx.h>
  11. #include <asm/io.h>
  12. #include <asm/processor.h>
  13. #include <asm/fsl_law.h>
  14. #include <linux/errno.h>
  15. #include "fsl_corenet_serdes.h"
  16. /*
  17. * The work-arounds for erratum SERDES8 and SERDES-A001 are linked together.
  18. * The code is already very complicated as it is, and separating the two
  19. * completely would just make things worse. We try to keep them as separate
  20. * as possible, but for now we require SERDES8 if SERDES_A001 is defined.
  21. */
  22. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES_A001
  23. #ifndef CONFIG_SYS_P4080_ERRATUM_SERDES8
  24. #error "CONFIG_SYS_P4080_ERRATUM_SERDES_A001 requires CONFIG_SYS_P4080_ERRATUM_SERDES8"
  25. #endif
  26. #endif
  27. static u32 serdes_prtcl_map;
  28. #ifdef DEBUG
  29. static const char *serdes_prtcl_str[] = {
  30. [NONE] = "NA",
  31. [PCIE1] = "PCIE1",
  32. [PCIE2] = "PCIE2",
  33. [PCIE3] = "PCIE3",
  34. [PCIE4] = "PCIE4",
  35. [SATA1] = "SATA1",
  36. [SATA2] = "SATA2",
  37. [SRIO1] = "SRIO1",
  38. [SRIO2] = "SRIO2",
  39. [SGMII_FM1_DTSEC1] = "SGMII_FM1_DTSEC1",
  40. [SGMII_FM1_DTSEC2] = "SGMII_FM1_DTSEC2",
  41. [SGMII_FM1_DTSEC3] = "SGMII_FM1_DTSEC3",
  42. [SGMII_FM1_DTSEC4] = "SGMII_FM1_DTSEC4",
  43. [SGMII_FM1_DTSEC5] = "SGMII_FM1_DTSEC5",
  44. [SGMII_FM2_DTSEC1] = "SGMII_FM2_DTSEC1",
  45. [SGMII_FM2_DTSEC2] = "SGMII_FM2_DTSEC2",
  46. [SGMII_FM2_DTSEC3] = "SGMII_FM2_DTSEC3",
  47. [SGMII_FM2_DTSEC4] = "SGMII_FM2_DTSEC4",
  48. [SGMII_FM2_DTSEC5] = "SGMII_FM2_DTSEC5",
  49. [XAUI_FM1] = "XAUI_FM1",
  50. [XAUI_FM2] = "XAUI_FM2",
  51. [AURORA] = "DEBUG",
  52. };
  53. #endif
  54. static const struct {
  55. int idx;
  56. unsigned int lpd; /* RCW lane powerdown bit */
  57. int bank;
  58. } lanes[SRDS_MAX_LANES] = {
  59. { 0, 152, FSL_SRDS_BANK_1 },
  60. { 1, 153, FSL_SRDS_BANK_1 },
  61. { 2, 154, FSL_SRDS_BANK_1 },
  62. { 3, 155, FSL_SRDS_BANK_1 },
  63. { 4, 156, FSL_SRDS_BANK_1 },
  64. { 5, 157, FSL_SRDS_BANK_1 },
  65. { 6, 158, FSL_SRDS_BANK_1 },
  66. { 7, 159, FSL_SRDS_BANK_1 },
  67. { 8, 160, FSL_SRDS_BANK_1 },
  68. { 9, 161, FSL_SRDS_BANK_1 },
  69. { 16, 162, FSL_SRDS_BANK_2 },
  70. { 17, 163, FSL_SRDS_BANK_2 },
  71. { 18, 164, FSL_SRDS_BANK_2 },
  72. { 19, 165, FSL_SRDS_BANK_2 },
  73. #ifdef CONFIG_ARCH_P4080
  74. { 20, 170, FSL_SRDS_BANK_3 },
  75. { 21, 171, FSL_SRDS_BANK_3 },
  76. { 22, 172, FSL_SRDS_BANK_3 },
  77. { 23, 173, FSL_SRDS_BANK_3 },
  78. #else
  79. { 20, 166, FSL_SRDS_BANK_3 },
  80. { 21, 167, FSL_SRDS_BANK_3 },
  81. { 22, 168, FSL_SRDS_BANK_3 },
  82. { 23, 169, FSL_SRDS_BANK_3 },
  83. #endif
  84. #if SRDS_MAX_BANK > 3
  85. { 24, 175, FSL_SRDS_BANK_4 },
  86. { 25, 176, FSL_SRDS_BANK_4 },
  87. #endif
  88. };
  89. int serdes_get_lane_idx(int lane)
  90. {
  91. return lanes[lane].idx;
  92. }
  93. int serdes_get_bank_by_lane(int lane)
  94. {
  95. return lanes[lane].bank;
  96. }
  97. int serdes_lane_enabled(int lane)
  98. {
  99. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  100. serdes_corenet_t *regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
  101. int bank = lanes[lane].bank;
  102. int word = lanes[lane].lpd / 32;
  103. int bit = lanes[lane].lpd % 32;
  104. if (in_be32(&regs->bank[bank].rstctl) & SRDS_RSTCTL_SDPD)
  105. return 0;
  106. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  107. /*
  108. * For banks two and three, use the srds_lpd_b[] array instead of the
  109. * RCW, because this array contains the real values of SRDS_LPD_B2 and
  110. * SRDS_LPD_B3.
  111. */
  112. if (bank > 0)
  113. return !(srds_lpd_b[bank] & (8 >> (lane - (6 + 4 * bank))));
  114. #endif
  115. return !(in_be32(&gur->rcwsr[word]) & (0x80000000 >> bit));
  116. }
  117. int is_serdes_configured(enum srds_prtcl device)
  118. {
  119. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  120. /* Is serdes enabled at all? */
  121. if (!(in_be32(&gur->rcwsr[5]) & FSL_CORENET_RCWSR5_SRDS_EN))
  122. return 0;
  123. if (!(serdes_prtcl_map & (1 << NONE)))
  124. fsl_serdes_init();
  125. return (1 << device) & serdes_prtcl_map;
  126. }
  127. static int __serdes_get_first_lane(uint32_t prtcl, enum srds_prtcl device)
  128. {
  129. int i;
  130. for (i = 0; i < SRDS_MAX_LANES; i++) {
  131. if (serdes_get_prtcl(prtcl, i) == device)
  132. return i;
  133. }
  134. return -ENODEV;
  135. }
  136. /*
  137. * Returns the SERDES lane (0..SRDS_MAX_LANES-1) that routes to the given
  138. * device. This depends on the current SERDES protocol, as defined in the RCW.
  139. *
  140. * Returns a negative error code if SERDES is disabled or the given device is
  141. * not supported in the current SERDES protocol.
  142. */
  143. int serdes_get_first_lane(enum srds_prtcl device)
  144. {
  145. u32 prtcl;
  146. const ccsr_gur_t *gur;
  147. gur = (typeof(gur))CONFIG_SYS_MPC85xx_GUTS_ADDR;
  148. /* Is serdes enabled at all? */
  149. if (unlikely((in_be32(&gur->rcwsr[5]) & 0x2000) == 0))
  150. return -ENODEV;
  151. prtcl = (in_be32(&gur->rcwsr[4]) & FSL_CORENET_RCWSR4_SRDS_PRTCL) >> 26;
  152. return __serdes_get_first_lane(prtcl, device);
  153. }
  154. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES9
  155. /*
  156. * Returns the SERDES bank (1, 2, or 3) that a given device is on for a given
  157. * SERDES protocol.
  158. *
  159. * Returns a negative error code if the given device is not supported for the
  160. * given SERDES protocol.
  161. */
  162. static int serdes_get_bank_by_device(uint32_t prtcl, enum srds_prtcl device)
  163. {
  164. int lane;
  165. lane = __serdes_get_first_lane(prtcl, device);
  166. if (unlikely(lane < 0))
  167. return lane;
  168. return serdes_get_bank_by_lane(lane);
  169. }
  170. static uint32_t __serdes_get_lane_count(uint32_t prtcl, enum srds_prtcl device,
  171. int first)
  172. {
  173. int lane;
  174. for (lane = first; lane < SRDS_MAX_LANES; lane++) {
  175. if (serdes_get_prtcl(prtcl, lane) != device)
  176. break;
  177. }
  178. return lane - first;
  179. }
  180. static void __serdes_reset_rx(serdes_corenet_t *regs,
  181. uint32_t prtcl,
  182. enum srds_prtcl device)
  183. {
  184. int lane, idx, first, last;
  185. lane = __serdes_get_first_lane(prtcl, device);
  186. if (unlikely(lane < 0))
  187. return;
  188. first = serdes_get_lane_idx(lane);
  189. last = first + __serdes_get_lane_count(prtcl, device, lane);
  190. /*
  191. * Set BnGCRy0[RRST] = 0 for each lane in the each bank that is
  192. * selected as XAUI to place the lane into reset.
  193. */
  194. for (idx = first; idx < last; idx++)
  195. clrbits_be32(&regs->lane[idx].gcr0, SRDS_GCR0_RRST);
  196. /* Wait at least 250 ns */
  197. udelay(1);
  198. /*
  199. * Set BnGCRy0[RRST] = 1 for each lane in the each bank that is
  200. * selected as XAUI to bring the lane out of reset.
  201. */
  202. for (idx = first; idx < last; idx++)
  203. setbits_be32(&regs->lane[idx].gcr0, SRDS_GCR0_RRST);
  204. }
  205. void serdes_reset_rx(enum srds_prtcl device)
  206. {
  207. u32 prtcl;
  208. const ccsr_gur_t *gur;
  209. serdes_corenet_t *regs;
  210. if (unlikely(device == NONE))
  211. return;
  212. gur = (typeof(gur))CONFIG_SYS_MPC85xx_GUTS_ADDR;
  213. /* Is serdes enabled at all? */
  214. if (unlikely((in_be32(&gur->rcwsr[5]) & 0x2000) == 0))
  215. return;
  216. regs = (typeof(regs))CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
  217. prtcl = (in_be32(&gur->rcwsr[4]) & FSL_CORENET_RCWSR4_SRDS_PRTCL) >> 26;
  218. __serdes_reset_rx(regs, prtcl, device);
  219. }
  220. #endif
  221. #ifndef CONFIG_SYS_DCSRBAR_PHYS
  222. #define CONFIG_SYS_DCSRBAR_PHYS 0x80000000 /* Must be 1GB-aligned for rev1.0 */
  223. #define CONFIG_SYS_DCSRBAR 0x80000000
  224. #define __DCSR_NOT_DEFINED_BY_CONFIG
  225. #endif
  226. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  227. /*
  228. * Enable a SERDES bank that was disabled via the RCW
  229. *
  230. * We only call this function for SERDES8 and SERDES-A001 in cases we really
  231. * want to enable the bank, whether we actually want to use the lanes or not,
  232. * so make sure at least one lane is enabled. We're only enabling this one
  233. * lane to satisfy errata requirements that the bank be enabled.
  234. *
  235. * We use a local variable instead of srds_lpd_b[] because we want drivers to
  236. * think that the lanes actually are disabled.
  237. */
  238. static void enable_bank(ccsr_gur_t *gur, int bank)
  239. {
  240. u32 rcw5;
  241. u32 temp_lpd_b = srds_lpd_b[bank];
  242. /*
  243. * If we're asked to disable all lanes, just pretend we're doing
  244. * that.
  245. */
  246. if (temp_lpd_b == 0xF)
  247. temp_lpd_b = 0xE;
  248. /*
  249. * Enable the lanes SRDS_LPD_Bn. The RCW bits are read-only in
  250. * CCSR, and read/write in DSCR.
  251. */
  252. rcw5 = in_be32(gur->rcwsr + 5);
  253. if (bank == FSL_SRDS_BANK_2) {
  254. rcw5 &= ~FSL_CORENET_RCWSRn_SRDS_LPD_B2;
  255. rcw5 |= temp_lpd_b << 26;
  256. } else if (bank == FSL_SRDS_BANK_3) {
  257. rcw5 &= ~FSL_CORENET_RCWSRn_SRDS_LPD_B3;
  258. rcw5 |= temp_lpd_b << 18;
  259. } else {
  260. printf("SERDES: enable_bank: bad bank %d\n", bank + 1);
  261. return;
  262. }
  263. /* See similar code in cpu/mpc85xx/cpu_init.c for an explanation
  264. * of the DCSR mapping.
  265. */
  266. {
  267. #ifdef __DCSR_NOT_DEFINED_BY_CONFIG
  268. struct law_entry law = find_law(CONFIG_SYS_DCSRBAR_PHYS);
  269. int law_index;
  270. if (law.index == -1)
  271. law_index = set_next_law(CONFIG_SYS_DCSRBAR_PHYS,
  272. LAW_SIZE_1M, LAW_TRGT_IF_DCSR);
  273. else
  274. set_law(law.index, CONFIG_SYS_DCSRBAR_PHYS, LAW_SIZE_1M,
  275. LAW_TRGT_IF_DCSR);
  276. #endif
  277. u32 *p = (void *)CONFIG_SYS_DCSRBAR + 0x20114;
  278. out_be32(p, rcw5);
  279. #ifdef __DCSR_NOT_DEFINED_BY_CONFIG
  280. if (law.index == -1)
  281. disable_law(law_index);
  282. else
  283. set_law(law.index, law.addr, law.size, law.trgt_id);
  284. #endif
  285. }
  286. }
  287. /*
  288. * To avoid problems with clock jitter, rev 2 p4080 uses the pll from
  289. * bank 3 to clock banks 2 and 3, as well as a limited selection of
  290. * protocol configurations. This requires that banks 2 and 3's lanes be
  291. * disabled in the RCW, and enabled with some fixup here to re-enable
  292. * them, and to configure bank 2's clock parameters in bank 3's pll in
  293. * cases where they differ.
  294. */
  295. static void p4080_erratum_serdes8(serdes_corenet_t *regs, ccsr_gur_t *gur,
  296. u32 devdisr, u32 devdisr2, int cfg)
  297. {
  298. int srds_ratio_b2;
  299. int rfck_sel;
  300. /*
  301. * The disabled lanes of bank 2 will cause the associated
  302. * logic blocks to be disabled in DEVDISR. We reverse that here.
  303. *
  304. * Note that normally it is not permitted to clear DEVDISR bits
  305. * once the device has been disabled, but the hardware people
  306. * say that this special case is OK.
  307. */
  308. clrbits_be32(&gur->devdisr, devdisr);
  309. clrbits_be32(&gur->devdisr2, devdisr2);
  310. /*
  311. * Some protocols require special handling. There are a few
  312. * additional protocol configurations that can be used, which are
  313. * not listed here. See app note 4065 for supported protocol
  314. * configurations.
  315. */
  316. switch (cfg) {
  317. case 0x19:
  318. /*
  319. * Bank 2 has PCIe which wants BWSEL -- tell bank 3's PLL.
  320. * SGMII on bank 3 should still be usable.
  321. */
  322. setbits_be32(&regs->bank[FSL_SRDS_BANK_3].pllcr1,
  323. SRDS_PLLCR1_PLL_BWSEL);
  324. break;
  325. case 0x0f:
  326. case 0x10:
  327. /*
  328. * Banks 2 (XAUI) and 3 (SGMII) have different clocking
  329. * requirements in these configurations. Bank 3 cannot
  330. * be used and should have its lanes (but not the bank
  331. * itself) disabled in the RCW. We set up bank 3's pll
  332. * for bank 2's needs here.
  333. */
  334. srds_ratio_b2 = (in_be32(&gur->rcwsr[4]) >> 13) & 7;
  335. /* Determine refclock from XAUI ratio */
  336. switch (srds_ratio_b2) {
  337. case 1: /* 20:1 */
  338. rfck_sel = SRDS_PLLCR0_RFCK_SEL_156_25;
  339. break;
  340. case 2: /* 25:1 */
  341. rfck_sel = SRDS_PLLCR0_RFCK_SEL_125;
  342. break;
  343. default:
  344. printf("SERDES: bad SRDS_RATIO_B2 %d\n",
  345. srds_ratio_b2);
  346. return;
  347. }
  348. clrsetbits_be32(&regs->bank[FSL_SRDS_BANK_3].pllcr0,
  349. SRDS_PLLCR0_RFCK_SEL_MASK, rfck_sel);
  350. clrsetbits_be32(&regs->bank[FSL_SRDS_BANK_3].pllcr0,
  351. SRDS_PLLCR0_FRATE_SEL_MASK,
  352. SRDS_PLLCR0_FRATE_SEL_6_25);
  353. break;
  354. }
  355. enable_bank(gur, FSL_SRDS_BANK_3);
  356. }
  357. #endif
  358. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES_A005
  359. /*
  360. * If PCIe is not selected as a protocol for any lanes driven by a given PLL,
  361. * that PLL should have SRDSBnPLLCR1[PLLBW_SEL] = 0.
  362. */
  363. static void p4080_erratum_serdes_a005(serdes_corenet_t *regs, unsigned int cfg)
  364. {
  365. enum srds_prtcl device;
  366. switch (cfg) {
  367. case 0x13:
  368. case 0x16:
  369. /*
  370. * If SRDS_PRTCL = 0x13 or 0x16, set SRDSB1PLLCR1[PLLBW_SEL]
  371. * to 0.
  372. */
  373. clrbits_be32(&regs->bank[FSL_SRDS_BANK_1].pllcr1,
  374. SRDS_PLLCR1_PLL_BWSEL);
  375. break;
  376. case 0x19:
  377. /*
  378. * If SRDS_PRTCL = 0x19, set SRDSB1PLLCR1[PLLBW_SEL] to 0 and
  379. * SRDSB3PLLCR1[PLLBW_SEL] to 1.
  380. */
  381. clrbits_be32(&regs->bank[FSL_SRDS_BANK_1].pllcr1,
  382. SRDS_PLLCR1_PLL_BWSEL);
  383. setbits_be32(&regs->bank[FSL_SRDS_BANK_3].pllcr1,
  384. SRDS_PLLCR1_PLL_BWSEL);
  385. break;
  386. }
  387. /*
  388. * Set SRDSBnPLLCR1[PLLBW_SEL] to 0 for each bank that selects XAUI
  389. * before XAUI is initialized.
  390. */
  391. for (device = XAUI_FM1; device <= XAUI_FM2; device++) {
  392. if (is_serdes_configured(device)) {
  393. int bank = serdes_get_bank_by_device(cfg, device);
  394. clrbits_be32(&regs->bank[bank].pllcr1,
  395. SRDS_PLLCR1_PLL_BWSEL);
  396. }
  397. }
  398. }
  399. #endif
  400. /*
  401. * Wait for the RSTDONE bit to get set, or a one-second timeout.
  402. */
  403. static void wait_for_rstdone(unsigned int bank)
  404. {
  405. serdes_corenet_t *srds_regs =
  406. (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
  407. unsigned long long end_tick;
  408. u32 rstctl;
  409. /* wait for reset complete or 1-second timeout */
  410. end_tick = usec2ticks(1000000) + get_ticks();
  411. do {
  412. rstctl = in_be32(&srds_regs->bank[bank].rstctl);
  413. if (rstctl & SRDS_RSTCTL_RSTDONE)
  414. break;
  415. } while (end_tick > get_ticks());
  416. if (!(rstctl & SRDS_RSTCTL_RSTDONE))
  417. printf("SERDES: timeout resetting bank %u\n", bank + 1);
  418. }
  419. static void __soc_serdes_init(void)
  420. {
  421. /* Allow for SoC-specific initialization in <SOC>_serdes.c */
  422. };
  423. void soc_serdes_init(void) __attribute__((weak, alias("__soc_serdes_init")));
  424. void fsl_serdes_init(void)
  425. {
  426. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  427. int cfg;
  428. serdes_corenet_t *srds_regs;
  429. #ifdef CONFIG_ARCH_P5040
  430. serdes_corenet_t *srds2_regs;
  431. #endif
  432. int lane, bank, idx;
  433. int have_bank[SRDS_MAX_BANK] = {};
  434. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  435. u32 serdes8_devdisr = 0;
  436. u32 serdes8_devdisr2 = 0;
  437. char srds_lpd_opt[16];
  438. const char *srds_lpd_arg;
  439. size_t arglen;
  440. #endif
  441. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES_A001
  442. int need_serdes_a001; /* true == need work-around for SERDES A001 */
  443. #endif
  444. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  445. char buffer[HWCONFIG_BUFFER_SIZE];
  446. char *buf = NULL;
  447. /*
  448. * Extract hwconfig from environment since we have not properly setup
  449. * the environment but need it for ddr config params
  450. */
  451. if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
  452. buf = buffer;
  453. #endif
  454. if (serdes_prtcl_map & (1 << NONE))
  455. return;
  456. /* Is serdes enabled at all? */
  457. if (!(in_be32(&gur->rcwsr[5]) & FSL_CORENET_RCWSR5_SRDS_EN))
  458. return;
  459. srds_regs = (void *)(CONFIG_SYS_FSL_CORENET_SERDES_ADDR);
  460. cfg = (in_be32(&gur->rcwsr[4]) & FSL_CORENET_RCWSR4_SRDS_PRTCL) >> 26;
  461. debug("Using SERDES configuration 0x%x, lane settings:\n", cfg);
  462. if (!is_serdes_prtcl_valid(cfg)) {
  463. printf("SERDES[PRTCL] = 0x%x is not valid\n", cfg);
  464. return;
  465. }
  466. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  467. /*
  468. * Display a warning if banks two and three are not disabled in the RCW,
  469. * since our work-around for SERDES8 depends on these banks being
  470. * disabled at power-on.
  471. */
  472. #define B2_B3 (FSL_CORENET_RCWSRn_SRDS_LPD_B2 | FSL_CORENET_RCWSRn_SRDS_LPD_B3)
  473. if ((in_be32(&gur->rcwsr[5]) & B2_B3) != B2_B3) {
  474. printf("Warning: SERDES8 requires banks two and "
  475. "three to be disabled in the RCW\n");
  476. }
  477. /*
  478. * Store the values of the fsl_srds_lpd_b2 and fsl_srds_lpd_b3
  479. * hwconfig options into the srds_lpd_b[] array. See README.p4080ds
  480. * for a description of these options.
  481. */
  482. for (bank = 1; bank < ARRAY_SIZE(srds_lpd_b); bank++) {
  483. sprintf(srds_lpd_opt, "fsl_srds_lpd_b%u", bank + 1);
  484. srds_lpd_arg =
  485. hwconfig_subarg_f("serdes", srds_lpd_opt, &arglen, buf);
  486. if (srds_lpd_arg)
  487. srds_lpd_b[bank] =
  488. simple_strtoul(srds_lpd_arg, NULL, 0) & 0xf;
  489. }
  490. if ((cfg == 0xf) || (cfg == 0x10)) {
  491. /*
  492. * For SERDES protocols 0xF and 0x10, force bank 3 to be
  493. * disabled, because it is not supported.
  494. */
  495. srds_lpd_b[FSL_SRDS_BANK_3] = 0xF;
  496. }
  497. #endif
  498. /* Look for banks with all lanes disabled, and power down the bank. */
  499. for (lane = 0; lane < SRDS_MAX_LANES; lane++) {
  500. enum srds_prtcl lane_prtcl = serdes_get_prtcl(cfg, lane);
  501. if (serdes_lane_enabled(lane)) {
  502. have_bank[serdes_get_bank_by_lane(lane)] = 1;
  503. serdes_prtcl_map |= (1 << lane_prtcl);
  504. }
  505. }
  506. #ifdef CONFIG_ARCH_P5040
  507. /*
  508. * Lanes on bank 4 on P5040 are commented-out, but for some SERDES
  509. * protocols, these lanes are routed to SATA. We use serdes_prtcl_map
  510. * to decide whether a protocol is supported on a given lane, so SATA
  511. * will be identified as not supported, and therefore not initialized.
  512. * So for protocols which use SATA on bank4, we add SATA support in
  513. * serdes_prtcl_map.
  514. */
  515. switch (cfg) {
  516. case 0x0:
  517. case 0x1:
  518. case 0x2:
  519. case 0x3:
  520. case 0x4:
  521. case 0x5:
  522. case 0x6:
  523. case 0x7:
  524. serdes_prtcl_map |= 1 << SATA1 | 1 << SATA2;
  525. break;
  526. default:
  527. srds2_regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES2_ADDR;
  528. /* We don't need bank 4, so power it down */
  529. setbits_be32(&srds2_regs->bank[0].rstctl, SRDS_RSTCTL_SDPD);
  530. }
  531. #endif
  532. soc_serdes_init();
  533. /* Set the first bit to indicate serdes has been initialized */
  534. serdes_prtcl_map |= (1 << NONE);
  535. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  536. /*
  537. * Bank two uses the clock from bank three, so if bank two is enabled,
  538. * then bank three must also be enabled.
  539. */
  540. if (have_bank[FSL_SRDS_BANK_2])
  541. have_bank[FSL_SRDS_BANK_3] = 1;
  542. #endif
  543. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES_A001
  544. /*
  545. * The work-aroud for erratum SERDES-A001 is needed only if bank two
  546. * is disabled and bank three is enabled. The converse is also true,
  547. * but SERDES8 ensures that bank 3 is always enabled if bank 2 is
  548. * enabled, so there's no point in complicating the code to handle
  549. * that situation.
  550. */
  551. need_serdes_a001 =
  552. !have_bank[FSL_SRDS_BANK_2] && have_bank[FSL_SRDS_BANK_3];
  553. #endif
  554. /* Power down the banks we're not interested in */
  555. for (bank = 0; bank < SRDS_MAX_BANK; bank++) {
  556. if (!have_bank[bank]) {
  557. printf("SERDES: bank %d disabled\n", bank + 1);
  558. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES_A001
  559. /*
  560. * Erratum SERDES-A001 says bank two needs to be powered
  561. * down after bank three is powered up, so don't power
  562. * down bank two here.
  563. */
  564. if (!need_serdes_a001 || (bank != FSL_SRDS_BANK_2))
  565. setbits_be32(&srds_regs->bank[bank].rstctl,
  566. SRDS_RSTCTL_SDPD);
  567. #else
  568. setbits_be32(&srds_regs->bank[bank].rstctl,
  569. SRDS_RSTCTL_SDPD);
  570. #endif
  571. }
  572. }
  573. #ifdef CONFIG_SYS_FSL_ERRATUM_A004699
  574. /*
  575. * To avoid the situation that resulted in the P4080 erratum
  576. * SERDES-8, a given SerDes bank will use the PLLs from the previous
  577. * bank if one of the PLL frequencies is a multiple of the other. For
  578. * instance, if bank 3 is running at 2.5GHz and bank 2 is at 1.25GHz,
  579. * then bank 3 will use bank 2's PLL. P5040 Erratum A-004699 says
  580. * that, in this situation, lane synchronization is not initiated. So
  581. * when we detect a bank with a "borrowed" PLL, we have to manually
  582. * initiate lane synchronization.
  583. */
  584. for (bank = FSL_SRDS_BANK_2; bank <= FSL_SRDS_BANK_3; bank++) {
  585. /* Determine the first lane for this bank */
  586. unsigned int lane;
  587. for (lane = 0; lane < SRDS_MAX_LANES; lane++)
  588. if (lanes[lane].bank == bank)
  589. break;
  590. idx = lanes[lane].idx;
  591. /*
  592. * Check if the PLL for the bank is borrowed. The UOTHL
  593. * bit of the first lane will tell us that.
  594. */
  595. if (in_be32(&srds_regs->lane[idx].gcr0) & SRDS_GCR0_UOTHL) {
  596. /* Manually start lane synchronization */
  597. setbits_be32(&srds_regs->bank[bank].pllcr0,
  598. SRDS_PLLCR0_PVCOCNT_EN);
  599. }
  600. }
  601. #endif
  602. #if defined(CONFIG_SYS_P4080_ERRATUM_SERDES8) || defined (CONFIG_SYS_P4080_ERRATUM_SERDES9)
  603. for (lane = 0; lane < SRDS_MAX_LANES; lane++) {
  604. enum srds_prtcl lane_prtcl;
  605. idx = serdes_get_lane_idx(lane);
  606. lane_prtcl = serdes_get_prtcl(cfg, lane);
  607. #ifdef DEBUG
  608. switch (lane) {
  609. case 0:
  610. puts("Bank1: ");
  611. break;
  612. case 10:
  613. puts("\nBank2: ");
  614. break;
  615. case 14:
  616. puts("\nBank3: ");
  617. break;
  618. default:
  619. break;
  620. }
  621. printf("%s ", serdes_prtcl_str[lane_prtcl]);
  622. #endif
  623. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES9
  624. /*
  625. * Set BnTTLCRy0[FLT_SEL] = 011011 and set BnTTLCRy0[31] = 1
  626. * for each of the SerDes lanes selected as SGMII, XAUI, SRIO,
  627. * or AURORA before the device is initialized.
  628. *
  629. * Note that this part of the SERDES-9 work-around is
  630. * redundant if the work-around for A-4580 has already been
  631. * applied via PBI.
  632. */
  633. switch (lane_prtcl) {
  634. case SGMII_FM1_DTSEC1:
  635. case SGMII_FM1_DTSEC2:
  636. case SGMII_FM1_DTSEC3:
  637. case SGMII_FM1_DTSEC4:
  638. case SGMII_FM2_DTSEC1:
  639. case SGMII_FM2_DTSEC2:
  640. case SGMII_FM2_DTSEC3:
  641. case SGMII_FM2_DTSEC4:
  642. case SGMII_FM2_DTSEC5:
  643. case XAUI_FM1:
  644. case XAUI_FM2:
  645. case SRIO1:
  646. case SRIO2:
  647. case AURORA:
  648. out_be32(&srds_regs->lane[idx].ttlcr0,
  649. SRDS_TTLCR0_FLT_SEL_KFR_26 |
  650. SRDS_TTLCR0_FLT_SEL_KPH_28 |
  651. SRDS_TTLCR0_FLT_SEL_750PPM |
  652. SRDS_TTLCR0_FREQOVD_EN);
  653. break;
  654. default:
  655. break;
  656. }
  657. #endif
  658. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  659. switch (lane_prtcl) {
  660. case PCIE1:
  661. case PCIE2:
  662. case PCIE3:
  663. serdes8_devdisr |= FSL_CORENET_DEVDISR_PCIE1 >>
  664. (lane_prtcl - PCIE1);
  665. break;
  666. case SRIO1:
  667. case SRIO2:
  668. serdes8_devdisr |= FSL_CORENET_DEVDISR_SRIO1 >>
  669. (lane_prtcl - SRIO1);
  670. break;
  671. case SGMII_FM1_DTSEC1:
  672. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM1 |
  673. FSL_CORENET_DEVDISR2_DTSEC1_1;
  674. break;
  675. case SGMII_FM1_DTSEC2:
  676. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM1 |
  677. FSL_CORENET_DEVDISR2_DTSEC1_2;
  678. break;
  679. case SGMII_FM1_DTSEC3:
  680. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM1 |
  681. FSL_CORENET_DEVDISR2_DTSEC1_3;
  682. break;
  683. case SGMII_FM1_DTSEC4:
  684. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM1 |
  685. FSL_CORENET_DEVDISR2_DTSEC1_4;
  686. break;
  687. case SGMII_FM2_DTSEC1:
  688. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM2 |
  689. FSL_CORENET_DEVDISR2_DTSEC2_1;
  690. break;
  691. case SGMII_FM2_DTSEC2:
  692. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM2 |
  693. FSL_CORENET_DEVDISR2_DTSEC2_2;
  694. break;
  695. case SGMII_FM2_DTSEC3:
  696. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM2 |
  697. FSL_CORENET_DEVDISR2_DTSEC2_3;
  698. break;
  699. case SGMII_FM2_DTSEC4:
  700. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM2 |
  701. FSL_CORENET_DEVDISR2_DTSEC2_4;
  702. break;
  703. case SGMII_FM2_DTSEC5:
  704. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM2 |
  705. FSL_CORENET_DEVDISR2_DTSEC2_5;
  706. break;
  707. case XAUI_FM1:
  708. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM1 |
  709. FSL_CORENET_DEVDISR2_10GEC1;
  710. break;
  711. case XAUI_FM2:
  712. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM2 |
  713. FSL_CORENET_DEVDISR2_10GEC2;
  714. break;
  715. case AURORA:
  716. break;
  717. default:
  718. break;
  719. }
  720. #endif
  721. }
  722. #endif
  723. #ifdef DEBUG
  724. puts("\n");
  725. #endif
  726. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES_A005
  727. p4080_erratum_serdes_a005(srds_regs, cfg);
  728. #endif
  729. for (idx = 0; idx < SRDS_MAX_BANK; idx++) {
  730. bank = idx;
  731. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  732. /*
  733. * Change bank init order to 0, 2, 1, so that the third bank's
  734. * PLL is established before we start the second bank. The
  735. * second bank uses the third bank's PLL.
  736. */
  737. if (idx == 1)
  738. bank = FSL_SRDS_BANK_3;
  739. else if (idx == 2)
  740. bank = FSL_SRDS_BANK_2;
  741. #endif
  742. /* Skip disabled banks */
  743. if (!have_bank[bank])
  744. continue;
  745. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  746. if (idx == 1) {
  747. /*
  748. * Re-enable devices on banks two and three that were
  749. * disabled by the RCW, and then enable bank three. The
  750. * devices need to be enabled before either bank is
  751. * powered up.
  752. */
  753. p4080_erratum_serdes8(srds_regs, gur, serdes8_devdisr,
  754. serdes8_devdisr2, cfg);
  755. } else if (idx == 2) {
  756. /* Enable bank two now that bank three is enabled. */
  757. enable_bank(gur, FSL_SRDS_BANK_2);
  758. }
  759. #endif
  760. wait_for_rstdone(bank);
  761. }
  762. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES_A001
  763. if (need_serdes_a001) {
  764. /* Bank 3 has been enabled, so now we can disable bank 2 */
  765. setbits_be32(&srds_regs->bank[FSL_SRDS_BANK_2].rstctl,
  766. SRDS_RSTCTL_SDPD);
  767. }
  768. #endif
  769. }
  770. const char *serdes_clock_to_string(u32 clock)
  771. {
  772. switch (clock) {
  773. case SRDS_PLLCR0_RFCK_SEL_100:
  774. return "100";
  775. case SRDS_PLLCR0_RFCK_SEL_125:
  776. return "125";
  777. case SRDS_PLLCR0_RFCK_SEL_156_25:
  778. return "156.25";
  779. case SRDS_PLLCR0_RFCK_SEL_161_13:
  780. return "161.1328123";
  781. default:
  782. return "150";
  783. }
  784. }