2 * (C) Copyright 2006-2009
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
6 * Jacqueline Pira-Ferriol, AMCC/IBM, jpira-ferriol@fr.ibm.com
7 * Alain Saurel, AMCC/IBM, alain.saurel@fr.ibm.com
9 * SPDX-License-Identifier: GPL-2.0+
15 #include <fdt_support.h>
16 #include <asm/ppc4xx.h>
17 #include <asm/ppc4xx-gpio.h>
18 #include <asm/processor.h>
20 #include <asm/bitops.h>
22 DECLARE_GLOBAL_DATA_PTR;
24 #if !defined(CONFIG_SYS_NO_FLASH)
25 extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
28 extern void __ft_board_setup(void *blob, bd_t *bd);
29 ulong flash_get_size(ulong base, int banknum);
31 static inline u32 get_async_pci_freq(void)
33 if (in_8((void *)(CONFIG_SYS_BCSR_BASE + 5)) &
34 CONFIG_SYS_BCSR5_PCI66EN)
40 int board_early_init_f(void)
43 u32 sdr0_pfc1, sdr0_pfc2;
46 mtdcr(EBC0_CFGADDR, EBC0_CFG);
47 mtdcr(EBC0_CFGDATA, 0xb8400000);
50 * Setup the interrupt controller polarities, triggers, etc.
52 mtdcr(UIC0SR, 0xffffffff); /* clear all */
53 mtdcr(UIC0ER, 0x00000000); /* disable all */
54 mtdcr(UIC0CR, 0x00000005); /* ATI & UIC1 crit are critical */
55 mtdcr(UIC0PR, 0xfffff7ff); /* per ref-board manual */
56 mtdcr(UIC0TR, 0x00000000); /* per ref-board manual */
57 mtdcr(UIC0VR, 0x00000000); /* int31 highest, base=0x000 */
58 mtdcr(UIC0SR, 0xffffffff); /* clear all */
60 mtdcr(UIC1SR, 0xffffffff); /* clear all */
61 mtdcr(UIC1ER, 0x00000000); /* disable all */
62 mtdcr(UIC1CR, 0x00000000); /* all non-critical */
63 mtdcr(UIC1PR, 0xffffffff); /* per ref-board manual */
64 mtdcr(UIC1TR, 0x00000000); /* per ref-board manual */
65 mtdcr(UIC1VR, 0x00000000); /* int31 highest, base=0x000 */
66 mtdcr(UIC1SR, 0xffffffff); /* clear all */
68 mtdcr(UIC2SR, 0xffffffff); /* clear all */
69 mtdcr(UIC2ER, 0x00000000); /* disable all */
70 mtdcr(UIC2CR, 0x00000000); /* all non-critical */
71 mtdcr(UIC2PR, 0xffffffff); /* per ref-board manual */
72 mtdcr(UIC2TR, 0x00000000); /* per ref-board manual */
73 mtdcr(UIC2VR, 0x00000000); /* int31 highest, base=0x000 */
74 mtdcr(UIC2SR, 0xffffffff); /* clear all */
76 /* Check and reconfigure the PCI sync clock if necessary */
77 ppc4xx_pci_sync_clock_config(get_async_pci_freq());
80 out_8((u8 *) CONFIG_SYS_BCSR_BASE + 0x04, 0x00);
82 /* clear write protects */
83 out_8((u8 *) CONFIG_SYS_BCSR_BASE + 0x07, 0x00);
86 out_8((u8 *) CONFIG_SYS_BCSR_BASE + 0x08, 0x00);
88 /* enable USB device */
89 out_8((u8 *) CONFIG_SYS_BCSR_BASE + 0x09, 0x20);
91 /* select Ethernet (and optionally IIC1) pins */
92 mfsdr(SDR0_PFC1, sdr0_pfc1);
93 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
94 SDR0_PFC1_SELECT_CONFIG_4;
95 #ifdef CONFIG_I2C_MULTI_BUS
96 sdr0_pfc1 |= ((sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_IIC1_SEL);
98 /* Two UARTs, so we need 4-pin mode. Also, we want CTS/RTS mode. */
99 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0IM_MASK) | SDR0_PFC1_U0IM_4PINS;
100 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0ME_MASK) | SDR0_PFC1_U0ME_CTS_RTS;
101 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U1ME_MASK) | SDR0_PFC1_U1ME_CTS_RTS;
103 mfsdr(SDR0_PFC2, sdr0_pfc2);
104 sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
105 SDR0_PFC2_SELECT_CONFIG_4;
106 mtsdr(SDR0_PFC2, sdr0_pfc2);
107 mtsdr(SDR0_PFC1, sdr0_pfc1);
109 /* PCI arbiter enabled */
110 mfsdr(SDR0_PCI0, reg);
111 mtsdr(SDR0_PCI0, 0x80000000 | reg);
113 /* setup NAND FLASH */
114 mfsdr(SDR0_CUST0, sdr0_cust0);
115 sdr0_cust0 = SDR0_CUST0_MUX_NDFC_SEL |
116 SDR0_CUST0_NDFC_ENABLE |
117 SDR0_CUST0_NDFC_BW_8_BIT |
118 SDR0_CUST0_NDFC_ARE_MASK |
119 (0x80000000 >> (28 + CONFIG_SYS_NAND_CS));
120 mtsdr(SDR0_CUST0, sdr0_cust0);
125 int misc_init_r(void)
127 #if !defined(CONFIG_SYS_NO_FLASH)
132 unsigned long usb2d0cr = 0;
133 unsigned long usb2phy0cr, usb2h0cr = 0;
134 unsigned long sdr0_pfc1;
135 char *act = getenv("usbact");
139 #if !defined(CONFIG_SYS_NO_FLASH)
140 /* Re-do flash sizing to get full correct info */
142 /* adjust flash start and offset */
143 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
144 gd->bd->bi_flashoffset = 0;
146 #if defined(CONFIG_SYS_RAMBOOT)
147 mtdcr(EBC0_CFGADDR, PB3CR);
149 mtdcr(EBC0_CFGADDR, PB0CR);
151 pbcr = mfdcr(EBC0_CFGDATA);
152 size_val = ffs(gd->bd->bi_flashsize) - 21;
153 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
154 #if defined(CONFIG_SYS_RAMBOOT)
155 mtdcr(EBC0_CFGADDR, PB3CR);
157 mtdcr(EBC0_CFGADDR, PB0CR);
159 mtdcr(EBC0_CFGDATA, pbcr);
162 * Re-check to get correct base address
164 flash_get_size(gd->bd->bi_flashstart, 0);
166 #ifdef CONFIG_ENV_IS_IN_FLASH
167 /* Monitor protection ON by default */
168 (void)flash_protect(FLAG_PROTECT_SET,
169 -CONFIG_SYS_MONITOR_LEN,
173 /* Env protection ON by default */
174 (void)flash_protect(FLAG_PROTECT_SET,
175 CONFIG_ENV_ADDR_REDUND,
176 CONFIG_ENV_ADDR_REDUND + 2*CONFIG_ENV_SECT_SIZE - 1,
179 #endif /* CONFIG_SYS_NO_FLASH */
185 if (act == NULL || strcmp(act, "hostdev") == 0) {
187 mfsdr(SDR0_PFC1, sdr0_pfc1);
188 mfsdr(SDR0_USB2D0CR, usb2d0cr);
189 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
190 mfsdr(SDR0_USB2H0CR, usb2h0cr);
192 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
193 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
194 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
195 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ;
196 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
197 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
198 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
199 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
200 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
201 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
204 * An 8-bit/60MHz interface is the only possible alternative
205 * when connecting the Device to the PHY
207 usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
208 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ;
211 * To enable the USB 2.0 Device function
212 * through the UTMI interface
214 usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
215 usb2d0cr = usb2d0cr | SDR0_USB2D0CR_USB2DEV_SELECTION;
217 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
218 sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_USB2D_SEL;
220 mtsdr(SDR0_PFC1, sdr0_pfc1);
221 mtsdr(SDR0_USB2D0CR, usb2d0cr);
222 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
223 mtsdr(SDR0_USB2H0CR, usb2h0cr);
227 mtsdr(SDR0_SRST1, 0x00000000);
229 mtsdr(SDR0_SRST0, 0x00000000);
231 printf("USB: Host(int phy) Device(ext phy)\n");
233 } else if (strcmp(act, "dev") == 0) {
234 /*-------------------PATCH-------------------------------*/
235 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
237 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
238 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
239 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
240 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
241 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
242 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
243 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
244 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
245 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
248 mtsdr(SDR0_SRST1, 0x672c6000);
251 mtsdr(SDR0_SRST0, 0x00000080);
254 mtsdr(SDR0_SRST1, 0x60206000);
256 *(unsigned int *)(0xe0000350) = 0x00000001;
259 mtsdr(SDR0_SRST1, 0x60306000);
260 /*-------------------PATCH-------------------------------*/
263 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
264 mfsdr(SDR0_USB2H0CR, usb2h0cr);
265 mfsdr(SDR0_USB2D0CR, usb2d0cr);
266 mfsdr(SDR0_PFC1, sdr0_pfc1);
268 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
269 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
270 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
271 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ;
272 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
273 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN;
274 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
275 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV;
276 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
277 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV;
279 usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
280 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ;
282 usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
283 usb2d0cr = usb2d0cr | SDR0_USB2D0CR_EBC_SELECTION;
285 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
286 sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL;
288 mtsdr(SDR0_USB2H0CR, usb2h0cr);
289 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
290 mtsdr(SDR0_USB2D0CR, usb2d0cr);
291 mtsdr(SDR0_PFC1, sdr0_pfc1);
295 mtsdr(SDR0_SRST1, 0x00000000);
297 mtsdr(SDR0_SRST0, 0x00000000);
299 printf("USB: Device(int phy)\n");
301 #endif /* CONFIG_440EPX */
303 mfsdr(SDR0_SRST1, reg); /* enable security/kasumi engines */
304 reg &= ~(SDR0_SRST1_CRYP0 | SDR0_SRST1_KASU0);
305 mtsdr(SDR0_SRST1, reg);
308 * Clear PLB4A0_ACR[WRP]
309 * This fix will make the MAL burst disabling patch for the Linux
310 * EMAC driver obsolete.
312 reg = mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_WRP_MASK;
313 mtdcr(PLB4A0_ACR, reg);
321 int i = getenv_f("serial#", buf, sizeof(buf));
323 u32 clock = get_async_pci_freq();
326 printf("Board: Sequoia - AMCC PPC440EPx Evaluation Board");
328 printf("Board: Rainier - AMCC PPC440GRx Evaluation Board");
331 rev = in_8((void *)(CONFIG_SYS_BCSR_BASE + 0));
332 printf(", Rev. %X, PCI-Async=%d MHz", rev, clock / 1000000);
341 * Reconfiguration of the PCI sync clock is already done,
342 * now check again if everything is in range:
344 if (ppc4xx_pci_sync_clock_config(clock)) {
345 printf("ERROR: PCI clocking incorrect (async=%d "
346 "sync=%ld)!\n", clock, get_PCI_freq());
352 #if defined(CONFIG_PCI) && defined(CONFIG_PCI_PNP)
354 * Assign interrupts to PCI devices.
356 void board_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
358 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, VECNUM_EIRQ2);
362 #if defined(CONFIG_SYS_RAMBOOT)
364 * On NAND-booting sequoia, we need to patch the chips select numbers
365 * in the dtb (CS0 - NAND, CS3 - NOR)
367 int ft_board_setup(void *blob, bd_t *bd)
372 struct fdt_property *prop;
376 /* First do common fdt setup */
377 __ft_board_setup(blob, bd);
379 /* And now configure NOR chip select to 3 instead of 0 */
380 strcpy(path, "/plb/opb/ebc/nor_flash@0,0");
381 nodeoffset = fdt_path_offset(blob, path);
382 prop = fdt_get_property_w(blob, nodeoffset, "reg", &len);
384 printf("Unable to update NOR chip select for NAND booting\n");
385 return -FDT_ERR_NOTFOUND;
387 reg = (u32 *)&prop->data[0];
389 rc = fdt_find_and_setprop(blob, path, "reg", reg, 3 * sizeof(u32), 1);
391 printf("Unable to update property NOR mappings\n");
395 /* And now configure NAND chip select to 0 instead of 3 */
396 strcpy(path, "/plb/opb/ebc/ndfc@3,0");
397 nodeoffset = fdt_path_offset(blob, path);
398 prop = fdt_get_property_w(blob, nodeoffset, "reg", &len);
400 printf("Unable to update NDFC chip select for NAND booting\n");
403 reg = (u32 *)&prop->data[0];
405 rc = fdt_find_and_setprop(blob, path, "reg", reg, 3 * sizeof(u32), 1);
407 printf("Unable to update property NDFC mapping\n");
413 #endif /* CONFIG_SYS_RAMBOOT */