fsl_corenet_serdes.c 23 KB

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