fsl_corenet_serdes.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /*
  2. * Copyright 2009-2010 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  24. #include <hwconfig.h>
  25. #endif
  26. #include <asm/fsl_serdes.h>
  27. #include <asm/immap_85xx.h>
  28. #include <asm/io.h>
  29. #include <asm/processor.h>
  30. #include <asm/fsl_law.h>
  31. #include "fsl_corenet_serdes.h"
  32. static u32 serdes_prtcl_map;
  33. #ifdef DEBUG
  34. static const char *serdes_prtcl_str[] = {
  35. [NONE] = "NA",
  36. [PCIE1] = "PCIE1",
  37. [PCIE2] = "PCIE2",
  38. [PCIE3] = "PCIE3",
  39. [PCIE4] = "PCIE4",
  40. [SATA1] = "SATA1",
  41. [SATA2] = "SATA2",
  42. [SRIO1] = "SRIO1",
  43. [SRIO2] = "SRIO2",
  44. [SGMII_FM1_DTSEC1] = "SGMII_FM1_DTSEC1",
  45. [SGMII_FM1_DTSEC2] = "SGMII_FM1_DTSEC2",
  46. [SGMII_FM1_DTSEC3] = "SGMII_FM1_DTSEC3",
  47. [SGMII_FM1_DTSEC4] = "SGMII_FM1_DTSEC4",
  48. [SGMII_FM1_DTSEC5] = "SGMII_FM1_DTSEC5",
  49. [SGMII_FM2_DTSEC1] = "SGMII_FM2_DTSEC1",
  50. [SGMII_FM2_DTSEC2] = "SGMII_FM2_DTSEC2",
  51. [SGMII_FM2_DTSEC3] = "SGMII_FM2_DTSEC3",
  52. [SGMII_FM2_DTSEC4] = "SGMII_FM2_DTSEC4",
  53. [XAUI_FM1] = "XAUI_FM1",
  54. [XAUI_FM2] = "XAUI_FM2",
  55. [AURORA] = "DEBUG",
  56. };
  57. #endif
  58. static const struct {
  59. int idx;
  60. unsigned int lpd; /* RCW lane powerdown bit */
  61. int bank;
  62. } lanes[SRDS_MAX_LANES] = {
  63. { 0, 152, FSL_SRDS_BANK_1 },
  64. { 1, 153, FSL_SRDS_BANK_1 },
  65. { 2, 154, FSL_SRDS_BANK_1 },
  66. { 3, 155, FSL_SRDS_BANK_1 },
  67. { 4, 156, FSL_SRDS_BANK_1 },
  68. { 5, 157, FSL_SRDS_BANK_1 },
  69. { 6, 158, FSL_SRDS_BANK_1 },
  70. { 7, 159, FSL_SRDS_BANK_1 },
  71. { 8, 160, FSL_SRDS_BANK_1 },
  72. { 9, 161, FSL_SRDS_BANK_1 },
  73. { 16, 162, FSL_SRDS_BANK_2 },
  74. { 17, 163, FSL_SRDS_BANK_2 },
  75. { 18, 164, FSL_SRDS_BANK_2 },
  76. { 19, 165, FSL_SRDS_BANK_2 },
  77. { 20, 170, FSL_SRDS_BANK_3 },
  78. { 21, 171, FSL_SRDS_BANK_3 },
  79. { 22, 172, FSL_SRDS_BANK_3 },
  80. { 23, 173, FSL_SRDS_BANK_3 },
  81. };
  82. int serdes_get_lane_idx(int lane)
  83. {
  84. return lanes[lane].idx;
  85. }
  86. int serdes_get_bank(int lane)
  87. {
  88. return lanes[lane].bank;
  89. }
  90. int serdes_lane_enabled(int lane)
  91. {
  92. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  93. serdes_corenet_t *regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
  94. int bank = lanes[lane].bank;
  95. int word = lanes[lane].lpd / 32;
  96. int bit = lanes[lane].lpd % 32;
  97. if (in_be32(&regs->bank[bank].rstctl) & SRDS_RSTCTL_SDPD)
  98. return 0;
  99. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  100. if (!IS_SVR_REV(get_svr(), 1, 0))
  101. if (bank > 0)
  102. return !(srds_lpd_b[bank] &
  103. (8 >> (lane - (6 + 4 * bank))));
  104. #endif
  105. return !(in_be32(&gur->rcwsr[word]) & (0x80000000 >> bit));
  106. }
  107. int is_serdes_configured(enum srds_prtcl device)
  108. {
  109. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  110. /* Is serdes enabled at all? */
  111. if (!(in_be32(&gur->rcwsr[5]) & FSL_CORENET_RCWSR5_SRDS_EN))
  112. return 0;
  113. return (1 << device) & serdes_prtcl_map;
  114. }
  115. #ifndef CONFIG_SYS_DCSRBAR_PHYS
  116. #define CONFIG_SYS_DCSRBAR_PHYS 0x80000000 /* Must be 1GB-aligned for rev1.0 */
  117. #define CONFIG_SYS_DCSRBAR 0x80000000
  118. #define __DCSR_NOT_DEFINED_BY_CONFIG
  119. #endif
  120. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  121. static void enable_bank(ccsr_gur_t *gur, int bank)
  122. {
  123. u32 rcw5;
  124. /*
  125. * Enable the lanes SRDS_LPD_Bn. The RCW bits are read-only in
  126. * CCSR, and read/write in DSCR.
  127. */
  128. rcw5 = in_be32(gur->rcwsr + 5);
  129. if (bank == FSL_SRDS_BANK_2) {
  130. rcw5 &= ~FSL_CORENET_RCWSRn_SRDS_LPD_B2;
  131. rcw5 |= srds_lpd_b[bank] << 26;
  132. } else if (bank == FSL_SRDS_BANK_3) {
  133. rcw5 &= ~FSL_CORENET_RCWSRn_SRDS_LPD_B3;
  134. rcw5 |= srds_lpd_b[bank] << 18;
  135. } else {
  136. printf("SERDES: enable_bank: bad bank %d\n", bank + 1);
  137. return;
  138. }
  139. /* See similar code in cpu/mpc85xx/cpu_init.c for an explanation
  140. * of the DCSR mapping.
  141. */
  142. {
  143. #ifdef __DCSR_NOT_DEFINED_BY_CONFIG
  144. struct law_entry law = find_law(CONFIG_SYS_DCSRBAR_PHYS);
  145. int law_index;
  146. if (law.index == -1)
  147. law_index = set_next_law(CONFIG_SYS_DCSRBAR_PHYS,
  148. LAW_SIZE_1M, LAW_TRGT_IF_DCSR);
  149. else
  150. set_law(law.index, CONFIG_SYS_DCSRBAR_PHYS, LAW_SIZE_1M,
  151. LAW_TRGT_IF_DCSR);
  152. #endif
  153. u32 *p = (void *)CONFIG_SYS_DCSRBAR + 0x20114;
  154. out_be32(p, rcw5);
  155. #ifdef __DCSR_NOT_DEFINED_BY_CONFIG
  156. if (law.index == -1)
  157. disable_law(law_index);
  158. else
  159. set_law(law.index, law.addr, law.size, law.trgt_id);
  160. #endif
  161. }
  162. }
  163. /*
  164. * To avoid problems with clock jitter, rev 2 p4080 uses the pll from
  165. * bank 3 to clock banks 2 and 3, as well as a limited selection of
  166. * protocol configurations. This requires that banks 2 and 3's lanes be
  167. * disabled in the RCW, and enabled with some fixup here to re-enable
  168. * them, and to configure bank 2's clock parameters in bank 3's pll in
  169. * cases where they differ.
  170. */
  171. static void p4080_erratum_serdes8(serdes_corenet_t *regs, ccsr_gur_t *gur,
  172. u32 devdisr, u32 devdisr2, int cfg)
  173. {
  174. int srds_ratio_b2;
  175. int rfck_sel;
  176. /*
  177. * The disabled lanes of bank 2 will cause the associated
  178. * logic blocks to be disabled in DEVDISR. We reverse that here.
  179. *
  180. * Note that normally it is not permitted to clear DEVDISR bits
  181. * once the device has been disabled, but the hardware people
  182. * say that this special case is OK.
  183. */
  184. clrbits_be32(&gur->devdisr, devdisr);
  185. clrbits_be32(&gur->devdisr2, devdisr2);
  186. /*
  187. * Some protocols require special handling. There are a few
  188. * additional protocol configurations that can be used, which are
  189. * not listed here. See app note 4065 for supported protocol
  190. * configurations.
  191. */
  192. switch (cfg) {
  193. case 0x19:
  194. /*
  195. * Bank 2 has PCIe which wants BWSEL -- tell bank 3's PLL.
  196. * SGMII on bank 3 should still be usable.
  197. */
  198. setbits_be32(&regs->bank[FSL_SRDS_BANK_3].pllcr1,
  199. SRDS_PLLCR1_PLL_BWSEL);
  200. enable_bank(gur, FSL_SRDS_BANK_3);
  201. break;
  202. case 0x0f:
  203. case 0x10:
  204. /*
  205. * Banks 2 (XAUI) and 3 (SGMII) have different clocking
  206. * requirements in these configurations. Bank 3 cannot
  207. * be used and should have its lanes (but not the bank
  208. * itself) disabled in the RCW. We set up bank 3's pll
  209. * for bank 2's needs here.
  210. */
  211. srds_ratio_b2 = (in_be32(&gur->rcwsr[4]) >> 13) & 7;
  212. /* Determine refclock from XAUI ratio */
  213. switch (srds_ratio_b2) {
  214. case 1: /* 20:1 */
  215. rfck_sel = SRDS_PLLCR0_RFCK_SEL_156_25;
  216. break;
  217. case 2: /* 25:1 */
  218. rfck_sel = SRDS_PLLCR0_RFCK_SEL_125;
  219. break;
  220. default:
  221. printf("SERDES: bad SRDS_RATIO_B2 %d\n",
  222. srds_ratio_b2);
  223. return;
  224. }
  225. clrsetbits_be32(&regs->bank[FSL_SRDS_BANK_3].pllcr0,
  226. SRDS_PLLCR0_RFCK_SEL_MASK, rfck_sel);
  227. clrsetbits_be32(&regs->bank[FSL_SRDS_BANK_3].pllcr0,
  228. SRDS_PLLCR0_FRATE_SEL_MASK,
  229. SRDS_PLLCR0_FRATE_SEL_6_25);
  230. break;
  231. default:
  232. enable_bank(gur, FSL_SRDS_BANK_3);
  233. }
  234. }
  235. #endif
  236. void fsl_serdes_init(void)
  237. {
  238. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  239. int cfg;
  240. serdes_corenet_t *srds_regs;
  241. int lane, bank, idx;
  242. enum srds_prtcl lane_prtcl;
  243. long long end_tick;
  244. int have_bank[SRDS_MAX_BANK] = {};
  245. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  246. u32 serdes8_devdisr = 0;
  247. u32 serdes8_devdisr2 = 0;
  248. char srds_lpd_opt[16];
  249. const char *srds_lpd_arg;
  250. size_t arglen;
  251. #endif
  252. /* Is serdes enabled at all? */
  253. if (!(in_be32(&gur->rcwsr[5]) & FSL_CORENET_RCWSR5_SRDS_EN))
  254. return;
  255. srds_regs = (void *)(CONFIG_SYS_FSL_CORENET_SERDES_ADDR);
  256. cfg = (in_be32(&gur->rcwsr[4]) & FSL_CORENET_RCWSR4_SRDS_PRTCL) >> 26;
  257. debug("Using SERDES configuration 0x%x, lane settings:\n", cfg);
  258. if (!is_serdes_prtcl_valid(cfg)) {
  259. printf("SERDES[PRTCL] = 0x%x is not valid\n", cfg);
  260. return;
  261. }
  262. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  263. if (!IS_SVR_REV(get_svr(), 1, 0))
  264. for (bank = 1; bank < ARRAY_SIZE(srds_lpd_b); bank++) {
  265. sprintf(srds_lpd_opt, "fsl_srds_lpd_b%u", bank + 1);
  266. srds_lpd_arg = hwconfig_subarg("serdes", srds_lpd_opt,
  267. &arglen);
  268. if (srds_lpd_arg)
  269. srds_lpd_b[bank] = simple_strtoul(srds_lpd_arg,
  270. NULL, 0);
  271. }
  272. #endif
  273. /* Look for banks with all lanes disabled, and power down the bank. */
  274. for (lane = 0; lane < SRDS_MAX_LANES; lane++) {
  275. enum srds_prtcl lane_prtcl = serdes_get_prtcl(cfg, lane);
  276. if (serdes_lane_enabled(lane)) {
  277. have_bank[serdes_get_bank(lane)] = 1;
  278. serdes_prtcl_map |= (1 << lane_prtcl);
  279. }
  280. }
  281. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  282. if (IS_SVR_REV(get_svr(), 1, 0)) {
  283. /* At least one bank must be disabled due to SERDES8. If
  284. * no bank is found to be disabled based on lane
  285. * disables, disable bank 3 because we can't turn off its
  286. * lanes in the RCW without disabling MDIO due to erratum
  287. * GEN8.
  288. *
  289. * This means that if you are relying on bank 3 being
  290. * disabled to avoid SERDES8, in some cases you cannot
  291. * also disable all lanes of another bank, or else bank
  292. * 3 won't be disabled, leaving you with a configuration
  293. * that isn't valid according to SERDES8 (e.g. if banks
  294. * 2 and 3 have the same clock, and bank 1 is disabled
  295. * instead of 3).
  296. */
  297. for (bank = 0; bank < SRDS_MAX_BANK; bank++) {
  298. if (!have_bank[bank])
  299. break;
  300. }
  301. if (bank == SRDS_MAX_BANK)
  302. have_bank[FSL_SRDS_BANK_3] = 0;
  303. } else {
  304. if (have_bank[FSL_SRDS_BANK_2])
  305. have_bank[FSL_SRDS_BANK_3] = 1;
  306. }
  307. #endif
  308. for (bank = 0; bank < SRDS_MAX_BANK; bank++) {
  309. if (!have_bank[bank]) {
  310. printf("SERDES: bank %d disabled\n", bank + 1);
  311. setbits_be32(&srds_regs->bank[bank].rstctl,
  312. SRDS_RSTCTL_SDPD);
  313. }
  314. }
  315. for (lane = 0; lane < SRDS_MAX_LANES; lane++) {
  316. idx = serdes_get_lane_idx(lane);
  317. lane_prtcl = serdes_get_prtcl(cfg, lane);
  318. #ifdef DEBUG
  319. switch (lane) {
  320. case 0:
  321. puts("Bank1: ");
  322. break;
  323. case 10:
  324. puts("\nBank2: ");
  325. break;
  326. case 14:
  327. puts("\nBank3: ");
  328. break;
  329. default:
  330. break;
  331. }
  332. printf("%s ", serdes_prtcl_str[lane_prtcl]);
  333. #endif
  334. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  335. switch (lane_prtcl) {
  336. case PCIE1:
  337. case PCIE2:
  338. case PCIE3:
  339. serdes8_devdisr |= FSL_CORENET_DEVDISR_PCIE1 >>
  340. (lane_prtcl - PCIE1);
  341. break;
  342. case SRIO1:
  343. case SRIO2:
  344. serdes8_devdisr |= FSL_CORENET_DEVDISR_SRIO1 >>
  345. (lane_prtcl - SRIO1);
  346. break;
  347. case SGMII_FM1_DTSEC1:
  348. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM1 |
  349. FSL_CORENET_DEVDISR2_DTSEC1_1;
  350. break;
  351. case SGMII_FM1_DTSEC2:
  352. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM1 |
  353. FSL_CORENET_DEVDISR2_DTSEC1_2;
  354. break;
  355. case SGMII_FM1_DTSEC3:
  356. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM1 |
  357. FSL_CORENET_DEVDISR2_DTSEC1_3;
  358. break;
  359. case SGMII_FM1_DTSEC4:
  360. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM1 |
  361. FSL_CORENET_DEVDISR2_DTSEC1_4;
  362. break;
  363. case SGMII_FM2_DTSEC1:
  364. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM2 |
  365. FSL_CORENET_DEVDISR2_DTSEC2_1;
  366. break;
  367. case SGMII_FM2_DTSEC2:
  368. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM2 |
  369. FSL_CORENET_DEVDISR2_DTSEC2_2;
  370. break;
  371. case SGMII_FM2_DTSEC3:
  372. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM2 |
  373. FSL_CORENET_DEVDISR2_DTSEC2_3;
  374. break;
  375. case SGMII_FM2_DTSEC4:
  376. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM2 |
  377. FSL_CORENET_DEVDISR2_DTSEC2_4;
  378. break;
  379. case XAUI_FM1:
  380. case XAUI_FM2:
  381. if (lane_prtcl == XAUI_FM1)
  382. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM1 |
  383. FSL_CORENET_DEVDISR2_10GEC1;
  384. else
  385. serdes8_devdisr2 |= FSL_CORENET_DEVDISR2_FM2 |
  386. FSL_CORENET_DEVDISR2_10GEC2;
  387. break;
  388. case AURORA:
  389. break;
  390. default:
  391. break;
  392. }
  393. #endif
  394. }
  395. #ifdef DEBUG
  396. puts("\n");
  397. #endif
  398. for (idx = 0; idx < SRDS_MAX_BANK; idx++) {
  399. u32 rstctl;
  400. bank = idx;
  401. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  402. if (!IS_SVR_REV(get_svr(), 1, 0)) {
  403. /*
  404. * Change bank init order to 0, 2, 1, so that the
  405. * third bank's PLL is established before we
  406. * start the second bank which shares the third
  407. * bank's PLL.
  408. */
  409. if (idx == 1)
  410. bank = FSL_SRDS_BANK_3;
  411. else if (idx == 2)
  412. bank = FSL_SRDS_BANK_2;
  413. }
  414. #endif
  415. /* Skip disabled banks */
  416. if (!have_bank[bank])
  417. continue;
  418. #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
  419. if (!IS_SVR_REV(get_svr(), 1, 0)) {
  420. if (idx == 1) {
  421. p4080_erratum_serdes8(srds_regs, gur,
  422. serdes8_devdisr,
  423. serdes8_devdisr2, cfg);
  424. } else if (idx == 2) {
  425. enable_bank(gur, FSL_SRDS_BANK_2);
  426. }
  427. }
  428. #endif
  429. /* reset banks for errata */
  430. setbits_be32(&srds_regs->bank[bank].rstctl, SRDS_RSTCTL_RST);
  431. /* wait for reset complete or 1-second timeout */
  432. end_tick = usec2ticks(1000000) + get_ticks();
  433. do {
  434. rstctl = in_be32(&srds_regs->bank[bank].rstctl);
  435. if (rstctl & SRDS_RSTCTL_RSTDONE)
  436. break;
  437. } while (end_tick > get_ticks());
  438. if (!(rstctl & SRDS_RSTCTL_RSTDONE)) {
  439. printf("SERDES: timeout resetting bank %d\n",
  440. bank + 1);
  441. continue;
  442. }
  443. }
  444. }