fsl_corenet_serdes.c 13 KB

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