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