28 static unsigned long chip_11_errata(
unsigned long memsize)
34 switch (pvr & 0xf0000ff0) {
51 unsigned long memsize, bank_config;
60 memsize = chip_11_errata(memsize);
65 #define DCRN_MQ0_B0BAS 0x40
66 #define DCRN_MQ0_B1BAS 0x41
67 #define DCRN_MQ0_B2BAS 0x42
68 #define DCRN_MQ0_B3BAS 0x43
70 static u64 ibm440spe_decode_bas(
u32 bas)
75 switch ((bas >> 4) & 0xFFF) {
79 return base + 0x000800000ull;
81 return base + 0x001000000ull;
83 return base + 0x002000000ull;
85 return base + 0x004000000ull;
87 return base + 0x008000000ull;
89 return base + 0x010000000ull;
91 return base + 0x020000000ull;
93 return base + 0x040000000ull;
95 return base + 0x080000000ull;
97 return base + 0x100000000ull;
99 printf(
"Memory BAS value 0x%08x unsupported !\n", bas);
105 u64 banktop, memsize = 0;
111 if (banktop > memsize)
114 if (banktop > memsize)
117 if (banktop > memsize)
120 if (banktop > memsize)
137 #define DDR_START 0x1
138 #define DDR_START_SHIFT 0
139 #define DDR_MAX_CS_REG 0x3
140 #define DDR_MAX_CS_REG_SHIFT 24
141 #define DDR_MAX_COL_REG 0xf
142 #define DDR_MAX_COL_REG_SHIFT 16
143 #define DDR_MAX_ROW_REG 0xf
144 #define DDR_MAX_ROW_REG_SHIFT 8
146 #define DDR_DDR2_MODE 0x1
147 #define DDR_DDR2_MODE_SHIFT 0
149 #define DDR_CS_MAP 0x3
150 #define DDR_CS_MAP_SHIFT 8
152 #define DDR_REDUC 0x1
153 #define DDR_REDUC_SHIFT 16
156 #define DDR_APIN_SHIFT 24
158 #define DDR_COL_SZ 0x7
159 #define DDR_COL_SZ_SHIFT 8
160 #define DDR_BANK8 0x1
161 #define DDR_BANK8_SHIFT 0
163 #define DDR_GET_VAL(val, mask, shift) (((val) >> (shift)) & (mask))
172 static inline u32 ibm4xx_denali_get_cs(
void)
178 devp = finddevice(
"/");
182 if (getprop(devp,
"model", model,
sizeof(model)) <= 0)
185 model[
sizeof(model)-1] = 0;
187 if (!
strcmp(model,
"amcc,sequoia") ||
188 !
strcmp(model,
"amcc,rainier"))
207 u32 val, max_cs, max_col, max_row;
208 u32 cs, col, row, bank, dpath;
213 fatal(
"DDR controller is not initialized\n");
220 cs = ibm4xx_denali_get_cs();
222 fatal(
"No memory installed\n");
224 fatal(
"DDR wrong CS configuration\n");
239 fatal(
"DDR wrong APIN configuration\n");
247 fatal(
"DDR wrong COL configuration\n");
255 memsize = cs * (1 << (col+row)) * bank * dpath;
256 memsize = chip_11_errata(memsize);
260 #define SPRN_DBCR0_40X 0x3F2
261 #define SPRN_DBCR0_44X 0x134
262 #define DBCR0_RST_SYSTEM 0x30000000
289 #define EMAC_RESET 0x20000000
327 devp = finddevice(ebc);
329 fatal(
"Couldn't locate EBC node %s\n\r", ebc);
331 setprop(devp,
"ranges", ranges, (p - ranges) *
sizeof(
u32));
339 u32 cpu, plb, opb, ebc,
tb, uart0, uart1,
m;
361 if ((mfpvr() & 0xf0000fff) == 0x40000440)
382 printf(
"PPC440GP: SysClk = %dMHz (%x)\n\r",
383 (sys_clk + 500000) / 1000000, sys_clk);
394 #define SPRN_CCR1 0x378
401 static unsigned int __ibm440eplike_fixup_clocks(
unsigned int sys_clk,
402 unsigned int tmr_clk,
403 int per_clk_from_opb)
410 u32 fbdv = __fix_zero((plld >> 24) & 0x1f, 32);
411 u32 fwdva = __fix_zero((plld >> 16) & 0xf, 16);
412 u32 fwdvb = __fix_zero((plld >> 8) & 7, 8);
413 u32 lfbdv = __fix_zero(plld & 0x3f, 64);
423 u32 cpu, plb, opb, ebc, vco;
426 u32 ccr1,
tb = tmr_clk;
428 if (pllc & 0x40000000) {
432 switch ((pllc >> 24) & 7) {
435 m = ((pllc & 0x20000000) ? fwdvb : fwdva) * lfbdv;
443 m = fwdvb * prbdv0 * opbdv0 * perdv0;
446 printf(
"WARNING ! Invalid PLL feedback source !\n");
460 cpu = clk_a / pradv0;
461 plb = clk_b / prbdv0;
463 ebc = (per_clk_from_opb ? opb : plb) / perdv0;
473 if ((ccr1 & 0x0080) == 0)
484 static void eplike_fixup_uart_clk(
int index,
const char *
path,
485 unsigned int ser_clk,
486 unsigned int plb_clk)
508 if (sdr & 0x00800000u)
511 clock = plb_clk / __fix_zero(sdr & 0xff, 256);
517 unsigned int ser_clk,
518 unsigned int tmr_clk)
520 unsigned int plb_clk = __ibm440eplike_fixup_clocks(sys_clk, tmr_clk, 0);
523 eplike_fixup_uart_clk(0,
"/plb/opb/serial@ef600300", ser_clk, plb_clk);
524 eplike_fixup_uart_clk(1,
"/plb/opb/serial@ef600400", ser_clk, plb_clk);
525 eplike_fixup_uart_clk(2,
"/plb/opb/serial@ef600500", ser_clk, plb_clk);
526 eplike_fixup_uart_clk(3,
"/plb/opb/serial@ef600600", ser_clk, plb_clk);
530 unsigned int ser_clk,
531 unsigned int tmr_clk)
533 unsigned int plb_clk = __ibm440eplike_fixup_clocks(sys_clk, tmr_clk, 1);
536 eplike_fixup_uart_clk(0,
"/plb/opb/serial@40000200", ser_clk, plb_clk);
537 eplike_fixup_uart_clk(1,
"/plb/opb/serial@40000300", ser_clk, plb_clk);
541 unsigned int ser_clk,
542 unsigned int tmr_clk)
544 unsigned int plb_clk = __ibm440eplike_fixup_clocks(sys_clk, tmr_clk, 1);
547 eplike_fixup_uart_clk(0,
"/plb/opb/serial@f0000200", ser_clk, plb_clk);
548 eplike_fixup_uart_clk(1,
"/plb/opb/serial@f0000300", ser_clk, plb_clk);
549 eplike_fixup_uart_clk(2,
"/plb/opb/serial@f0000600", ser_clk, plb_clk);
558 u32 cpu, plb, opb, ebc,
tb, uart0, uart1,
m;
559 u32 fwdv, fwdvb, fbdv, cbdv, opdv, epdv, ppdv, udiv;
561 fwdv = (8 - ((pllmr & 0xe0000000) >> 29));
562 fbdv = (pllmr & 0x1e000000) >> 25;
565 cbdv = ((pllmr & 0x00060000) >> 17) + 1;
566 opdv = ((pllmr & 0x00018000) >> 15) + 1;
567 ppdv = ((pllmr & 0x00001800) >> 13) + 1;
568 epdv = ((pllmr & 0x00001800) >> 11) + 2;
569 udiv = ((cpc0_cr0 & 0x3e) >> 1) + 1;
572 if ((mfpvr() & 0xfffffff0) == (0x50910951 & 0xfffffff0)) {
573 fwdvb = 8 - (pllmr & 0x00000007);
574 if (!(psr & 0x00001000))
575 if (psr & 0x00000020)
576 m = fwdvb * 2 * ppdv;
578 m = fwdvb * cbdv * ppdv;
579 else if (psr & 0x00000020)
580 if (psr & 0x00000800)
581 m = fwdvb * 2 * epdv;
584 else if (epdv == fbdv)
585 m = fbdv * cbdv * epdv;
587 m = fbdv * fwdvb * cbdv;
589 cpu = sys_clk * m / fwdv;
590 plb = sys_clk * m / (fwdvb * cbdv);
592 m = fwdv * fbdv * cbdv;
593 cpu = sys_clk * m / fwdv;
612 cpc0_cr1 = cpc0_cr1 & ~0x00800000;
630 u32 cpu, plb, opb, ebc, uart0, uart1;
631 u32 fwdva, fwdvb, fbdv, cbdv, opdv, epdv;
634 fwdva = 8 - ((pllmr1 & 0x00070000) >> 16);
635 fwdvb = 8 - ((pllmr1 & 0x00007000) >> 12);
636 fbdv = (pllmr1 & 0x00f00000) >> 20;
640 cbdv = ((pllmr0 & 0x00030000) >> 16) + 1;
641 epdv = ((pllmr0 & 0x00000300) >> 8) + 2;
642 opdv = ((pllmr0 & 0x00003000) >> 12) + 1;
646 pllmr0_ccdv = ((pllmr0 & 0x00300000) >> 20) + 1;
647 if (pllmr1 & 0x80000000)
648 cpu = sys_clk * m / (fwdva * pllmr0_ccdv);
650 cpu = sys_clk / pllmr0_ccdv;
656 uart0 = cpu / (cpc0_ucr & 0x0000007f);
657 uart1 = cpu / ((cpc0_ucr & 0x00007f00) >> 8);
667 static u8 ibm405ex_fwdv_multi_bits[] = {
669 0x01, 0x02, 0x0e, 0x09, 0x04, 0x0b, 0x10, 0x0d, 0x0c, 0x05,
670 0x06, 0x0f, 0x0a, 0x07, 0x08, 0x03
677 for (index = 0; index <
ARRAY_SIZE(ibm405ex_fwdv_multi_bits); index++)
678 if (cpr_fwdv == (
u32)ibm405ex_fwdv_multi_bits[
index])
684 static u8 ibm405ex_fbdv_multi_bits[] = {
686 0x00, 0xff, 0x7e, 0xfd, 0x7a, 0xf5, 0x6a, 0xd5, 0x2a, 0xd4,
687 0x29, 0xd3, 0x26, 0xcc, 0x19, 0xb3, 0x67, 0xce, 0x1d, 0xbb,
688 0x77, 0xee, 0x5d, 0xba, 0x74, 0xe9, 0x52, 0xa5, 0x4b, 0x96,
689 0x2c, 0xd8, 0x31, 0xe3, 0x46, 0x8d, 0x1b, 0xb7, 0x6f, 0xde,
690 0x3d, 0xfb, 0x76, 0xed, 0x5a, 0xb5, 0x6b, 0xd6, 0x2d, 0xdb,
691 0x36, 0xec, 0x59, 0xb2, 0x64, 0xc9, 0x12, 0xa4, 0x48, 0x91,
692 0x23, 0xc7, 0x0e, 0x9c, 0x38, 0xf0, 0x61, 0xc2, 0x05, 0x8b,
693 0x17, 0xaf, 0x5f, 0xbe, 0x7c, 0xf9, 0x72, 0xe5, 0x4a, 0x95,
694 0x2b, 0xd7, 0x2e, 0xdc, 0x39, 0xf3, 0x66, 0xcd, 0x1a, 0xb4,
695 0x68, 0xd1, 0x22, 0xc4, 0x09, 0x93, 0x27, 0xcf, 0x1e, 0xbc,
697 0x78, 0xf1, 0x62, 0xc5, 0x0a, 0x94, 0x28, 0xd0, 0x21, 0xc3,
698 0x06, 0x8c, 0x18, 0xb0, 0x60, 0xc1, 0x02, 0x84, 0x08, 0x90,
699 0x20, 0xc0, 0x01, 0x83, 0x07, 0x8f, 0x1f, 0xbf, 0x7f, 0xfe,
700 0x7d, 0xfa, 0x75, 0xea, 0x55, 0xaa, 0x54, 0xa9, 0x53, 0xa6,
701 0x4c, 0x99, 0x33, 0xe7, 0x4e, 0x9d, 0x3b, 0xf7, 0x6e, 0xdd,
702 0x3a, 0xf4, 0x69, 0xd2, 0x25, 0xcb, 0x16, 0xac, 0x58, 0xb1,
703 0x63, 0xc6, 0x0d, 0x9b, 0x37, 0xef, 0x5e, 0xbd, 0x7b, 0xf6,
704 0x6d, 0xda, 0x35, 0xeb, 0x56, 0xad, 0x5b, 0xb6, 0x6c, 0xd9,
705 0x32, 0xe4, 0x49, 0x92, 0x24, 0xc8, 0x11, 0xa3, 0x47, 0x8e,
706 0x1c, 0xb8, 0x70, 0xe1, 0x42, 0x85, 0x0b, 0x97, 0x2f, 0xdf,
708 0x3e, 0xfc, 0x79, 0xf2, 0x65, 0xca, 0x15, 0xab, 0x57, 0xae,
709 0x5c, 0xb9, 0x73, 0xe6, 0x4d, 0x9a, 0x34, 0xe8, 0x51, 0xa2,
710 0x44, 0x89, 0x13, 0xa7, 0x4f, 0x9e, 0x3c, 0xf8, 0x71, 0xe2,
711 0x45, 0x8a, 0x14, 0xa8, 0x50, 0xa1, 0x43, 0x86, 0x0c, 0x98,
712 0x30, 0xe0, 0x41, 0x82, 0x04, 0x88, 0x10, 0xa0, 0x40, 0x81,
713 0x03, 0x87, 0x0f, 0x9f, 0x3f
720 for (index = 0; index <
ARRAY_SIZE(ibm405ex_fbdv_multi_bits); index++)
721 if (cpr_fbdv == (
u32)ibm405ex_fbdv_multi_bits[
index])
742 u32 cpudv0 = __fix_zero((cpud >> 24) & 7, 8);
746 u32 plb2xdv0 = __fix_zero((plbd >> 16) & 7, 8);
748 u32 opbdv0 = __fix_zero((opbd >> 24) & 3, 4);
750 u32 perdv0 = __fix_zero((perd >> 24) & 3, 4);
753 u32 cpu, plb, opb, ebc, vco,
tb, uart0, uart1;
756 if (pllc & 0x40000000) {
760 switch ((pllc >> 24) & 7) {
767 m = fbdv * fwdva * cpudv0;
771 m = fbdv * fwdva * plb2xdv0 * plbdv0 * opbdv0 * perdv0;
774 printf(
"WARNING ! Invalid PLL feedback source !\n");
778 vco = (
unsigned int)(sys_clk * m);
786 cpu = vco / (fwdva * cpudv0);
788 plb = vco / (fwdva * plb2xdv0 * plbdv0);
795 uart0 = uart1 = uart_clk;