blob: 43938200616375db74c36e175bd5348963af398d [file] [log] [blame]
Stefan Roese42fbddd2006-09-07 11:51:23 +02001/*
Stefan Roesec55fc7a2009-04-08 10:36:22 +02002 * (C) Copyright 2006-2009
Stefan Roese42fbddd2006-09-07 11:51:23 +02003 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
5 * (C) Copyright 2006
6 * Jacqueline Pira-Ferriol, AMCC/IBM, jpira-ferriol@fr.ibm.com
Wolfgang Denk3595e612008-01-23 14:31:17 +01007 * Alain Saurel, AMCC/IBM, alain.saurel@fr.ibm.com
Stefan Roese42fbddd2006-09-07 11:51:23 +02008 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
Stefan Roesefbcee002007-12-13 14:52:53 +010026#include <libfdt.h>
27#include <fdt_support.h>
Stefan Roese41b17462008-06-25 10:59:22 +020028#include <ppc4xx.h>
Lawrence R. Johnson1e8db032008-01-04 02:11:56 -050029#include <asm/gpio.h>
Stefan Roese42fbddd2006-09-07 11:51:23 +020030#include <asm/processor.h>
Stefan Roesefa257472007-10-15 11:29:33 +020031#include <asm/io.h>
Matthias Fuchs62357702008-01-16 10:33:46 +010032#include <asm/bitops.h>
Stefan Roese42fbddd2006-09-07 11:51:23 +020033
34DECLARE_GLOBAL_DATA_PTR;
35
Stefan Roesec20ef322009-05-11 13:46:14 +020036#if !defined(CONFIG_SYS_NO_FLASH)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020037extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
Stefan Roesec20ef322009-05-11 13:46:14 +020038#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +020039
Stefan Roesec55fc7a2009-04-08 10:36:22 +020040extern void __ft_board_setup(void *blob, bd_t *bd);
41ulong flash_get_size(ulong base, int banknum);
Stefan Roeseab8e99b2006-12-22 14:29:40 +010042
Stefan Roesee7f30922009-10-19 14:10:50 +020043static inline u32 get_async_pci_freq(void)
44{
45 if (in_8((void *)(CONFIG_SYS_BCSR_BASE + 5)) &
46 CONFIG_SYS_BCSR5_PCI66EN)
47 return 66666666;
48 else
49 return 33333333;
50}
51
Stefan Roese42fbddd2006-09-07 11:51:23 +020052int board_early_init_f(void)
53{
Stefan Roesebc7057d2007-01-05 10:40:36 +010054 u32 sdr0_cust0;
55 u32 sdr0_pfc1, sdr0_pfc2;
56 u32 reg;
Stefan Roese42fbddd2006-09-07 11:51:23 +020057
Stefan Roese918010a2009-09-09 16:25:29 +020058 mtdcr(EBC0_CFGADDR, EBC0_CFG);
59 mtdcr(EBC0_CFGDATA, 0xb8400000);
Stefan Roese42fbddd2006-09-07 11:51:23 +020060
Matthias Fuchs62357702008-01-16 10:33:46 +010061 /*
Stefan Roese42fbddd2006-09-07 11:51:23 +020062 * Setup the interrupt controller polarities, triggers, etc.
Matthias Fuchs62357702008-01-16 10:33:46 +010063 */
Stefan Roese707fd362009-09-24 09:55:50 +020064 mtdcr(UIC0SR, 0xffffffff); /* clear all */
65 mtdcr(UIC0ER, 0x00000000); /* disable all */
66 mtdcr(UIC0CR, 0x00000005); /* ATI & UIC1 crit are critical */
67 mtdcr(UIC0PR, 0xfffff7ff); /* per ref-board manual */
68 mtdcr(UIC0TR, 0x00000000); /* per ref-board manual */
69 mtdcr(UIC0VR, 0x00000000); /* int31 highest, base=0x000 */
70 mtdcr(UIC0SR, 0xffffffff); /* clear all */
Stefan Roese42fbddd2006-09-07 11:51:23 +020071
Stefan Roese707fd362009-09-24 09:55:50 +020072 mtdcr(UIC1SR, 0xffffffff); /* clear all */
73 mtdcr(UIC1ER, 0x00000000); /* disable all */
74 mtdcr(UIC1CR, 0x00000000); /* all non-critical */
75 mtdcr(UIC1PR, 0xffffffff); /* per ref-board manual */
76 mtdcr(UIC1TR, 0x00000000); /* per ref-board manual */
77 mtdcr(UIC1VR, 0x00000000); /* int31 highest, base=0x000 */
78 mtdcr(UIC1SR, 0xffffffff); /* clear all */
Stefan Roese42fbddd2006-09-07 11:51:23 +020079
Stefan Roese707fd362009-09-24 09:55:50 +020080 mtdcr(UIC2SR, 0xffffffff); /* clear all */
81 mtdcr(UIC2ER, 0x00000000); /* disable all */
82 mtdcr(UIC2CR, 0x00000000); /* all non-critical */
83 mtdcr(UIC2PR, 0xffffffff); /* per ref-board manual */
84 mtdcr(UIC2TR, 0x00000000); /* per ref-board manual */
85 mtdcr(UIC2VR, 0x00000000); /* int31 highest, base=0x000 */
86 mtdcr(UIC2SR, 0xffffffff); /* clear all */
Stefan Roese42fbddd2006-09-07 11:51:23 +020087
Stefan Roesee7f30922009-10-19 14:10:50 +020088 /* Check and reconfigure the PCI sync clock if necessary */
89 ppc4xx_pci_sync_clock_config(get_async_pci_freq());
90
Stefan Roese42fbddd2006-09-07 11:51:23 +020091 /* 50MHz tmrclk */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020092 out_8((u8 *) CONFIG_SYS_BCSR_BASE + 0x04, 0x00);
Stefan Roese42fbddd2006-09-07 11:51:23 +020093
94 /* clear write protects */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020095 out_8((u8 *) CONFIG_SYS_BCSR_BASE + 0x07, 0x00);
Stefan Roese42fbddd2006-09-07 11:51:23 +020096
97 /* enable Ethernet */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098 out_8((u8 *) CONFIG_SYS_BCSR_BASE + 0x08, 0x00);
Stefan Roese42fbddd2006-09-07 11:51:23 +020099
100 /* enable USB device */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200101 out_8((u8 *) CONFIG_SYS_BCSR_BASE + 0x09, 0x20);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200102
Mike Nuss383b1452008-02-06 11:10:11 -0500103 /* select Ethernet (and optionally IIC1) pins */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200104 mfsdr(SDR0_PFC1, sdr0_pfc1);
Matthias Fuchs62357702008-01-16 10:33:46 +0100105 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
106 SDR0_PFC1_SELECT_CONFIG_4;
Mike Nuss383b1452008-02-06 11:10:11 -0500107#ifdef CONFIG_I2C_MULTI_BUS
108 sdr0_pfc1 |= ((sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_IIC1_SEL);
109#endif
Steven A. Falco7bf9cc62008-08-06 15:42:52 -0400110 /* Two UARTs, so we need 4-pin mode. Also, we want CTS/RTS mode. */
111 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0IM_MASK) | SDR0_PFC1_U0IM_4PINS;
112 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0ME_MASK) | SDR0_PFC1_U0ME_CTS_RTS;
113 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U1ME_MASK) | SDR0_PFC1_U1ME_CTS_RTS;
114
Stefan Roese42fbddd2006-09-07 11:51:23 +0200115 mfsdr(SDR0_PFC2, sdr0_pfc2);
Matthias Fuchs62357702008-01-16 10:33:46 +0100116 sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
117 SDR0_PFC2_SELECT_CONFIG_4;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200118 mtsdr(SDR0_PFC2, sdr0_pfc2);
119 mtsdr(SDR0_PFC1, sdr0_pfc1);
120
121 /* PCI arbiter enabled */
Stefan Roese918010a2009-09-09 16:25:29 +0200122 mfsdr(SDR0_PCI0, reg);
123 mtsdr(SDR0_PCI0, 0x80000000 | reg);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200124
125 /* setup NAND FLASH */
126 mfsdr(SDR0_CUST0, sdr0_cust0);
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200127 sdr0_cust0 = SDR0_CUST0_MUX_NDFC_SEL |
Stefan Roese42fbddd2006-09-07 11:51:23 +0200128 SDR0_CUST0_NDFC_ENABLE |
129 SDR0_CUST0_NDFC_BW_8_BIT |
130 SDR0_CUST0_NDFC_ARE_MASK |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200131 (0x80000000 >> (28 + CONFIG_SYS_NAND_CS));
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200132 mtsdr(SDR0_CUST0, sdr0_cust0);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200133
134 return 0;
135}
136
Stefan Roese42fbddd2006-09-07 11:51:23 +0200137int misc_init_r(void)
138{
Stefan Roesec20ef322009-05-11 13:46:14 +0200139#if !defined(CONFIG_SYS_NO_FLASH)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200140 uint pbcr;
141 int size_val = 0;
Stefan Roesec20ef322009-05-11 13:46:14 +0200142#endif
Stefan Roesebe6729c2006-09-13 13:51:58 +0200143#ifdef CONFIG_440EPX
Stefan Roese42fbddd2006-09-07 11:51:23 +0200144 unsigned long usb2d0cr = 0;
145 unsigned long usb2phy0cr, usb2h0cr = 0;
146 unsigned long sdr0_pfc1;
147 char *act = getenv("usbact");
Stefan Roesebe6729c2006-09-13 13:51:58 +0200148#endif
Stefan Roesec20ef322009-05-11 13:46:14 +0200149 u32 reg;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200150
Stefan Roesec20ef322009-05-11 13:46:14 +0200151#if !defined(CONFIG_SYS_NO_FLASH)
Matthias Fuchs62357702008-01-16 10:33:46 +0100152 /* Re-do flash sizing to get full correct info */
Stefan Roeseab8e99b2006-12-22 14:29:40 +0100153
154 /* adjust flash start and offset */
155 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
156 gd->bd->bi_flashoffset = 0;
157
Stefan Roese42fbddd2006-09-07 11:51:23 +0200158#if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
Stefan Roese918010a2009-09-09 16:25:29 +0200159 mtdcr(EBC0_CFGADDR, PB3CR);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200160#else
Stefan Roese918010a2009-09-09 16:25:29 +0200161 mtdcr(EBC0_CFGADDR, PB0CR);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200162#endif
Stefan Roese918010a2009-09-09 16:25:29 +0200163 pbcr = mfdcr(EBC0_CFGDATA);
Wolfgang Denk3595e612008-01-23 14:31:17 +0100164 size_val = ffs(gd->bd->bi_flashsize) - 21;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200165 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
166#if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
Stefan Roese918010a2009-09-09 16:25:29 +0200167 mtdcr(EBC0_CFGADDR, PB3CR);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200168#else
Stefan Roese918010a2009-09-09 16:25:29 +0200169 mtdcr(EBC0_CFGADDR, PB0CR);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200170#endif
Stefan Roese918010a2009-09-09 16:25:29 +0200171 mtdcr(EBC0_CFGDATA, pbcr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200172
Stefan Roeseab8e99b2006-12-22 14:29:40 +0100173 /*
174 * Re-check to get correct base address
175 */
176 flash_get_size(gd->bd->bi_flashstart, 0);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200177
Jean-Christophe PLAGNIOL-VILLARD53db4cd2008-09-10 22:48:04 +0200178#ifdef CONFIG_ENV_IS_IN_FLASH
Stefan Roese42fbddd2006-09-07 11:51:23 +0200179 /* Monitor protection ON by default */
180 (void)flash_protect(FLAG_PROTECT_SET,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200181 -CONFIG_SYS_MONITOR_LEN,
Stefan Roese42fbddd2006-09-07 11:51:23 +0200182 0xffffffff,
183 &flash_info[0]);
184
185 /* Env protection ON by default */
186 (void)flash_protect(FLAG_PROTECT_SET,
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200187 CONFIG_ENV_ADDR_REDUND,
188 CONFIG_ENV_ADDR_REDUND + 2*CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese42fbddd2006-09-07 11:51:23 +0200189 &flash_info[0]);
190#endif
Stefan Roesec20ef322009-05-11 13:46:14 +0200191#endif /* CONFIG_SYS_NO_FLASH */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200192
193 /*
194 * USB suff...
195 */
Stefan Roesebe6729c2006-09-13 13:51:58 +0200196#ifdef CONFIG_440EPX
Matthias Fuchs62357702008-01-16 10:33:46 +0100197 if (act == NULL || strcmp(act, "hostdev") == 0) {
Stefan Roese42fbddd2006-09-07 11:51:23 +0200198 /* SDR Setting */
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200199 mfsdr(SDR0_PFC1, sdr0_pfc1);
Niklaus Giger77cad902007-06-27 18:11:38 +0200200 mfsdr(SDR0_USB2D0CR, usb2d0cr);
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200201 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
202 mfsdr(SDR0_USB2H0CR, usb2h0cr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200203
204 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100205 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200206 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100207 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200208 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100209 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200210 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100211 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200212 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100213 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200214
Matthias Fuchs62357702008-01-16 10:33:46 +0100215 /*
216 * An 8-bit/60MHz interface is the only possible alternative
217 * when connecting the Device to the PHY
218 */
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200219 usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100220 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200221
Matthias Fuchs62357702008-01-16 10:33:46 +0100222 /*
223 * To enable the USB 2.0 Device function
224 * through the UTMI interface
225 */
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200226 usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100227 usb2d0cr = usb2d0cr | SDR0_USB2D0CR_USB2DEV_SELECTION;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200228
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200229 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100230 sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_USB2D_SEL;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200231
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200232 mtsdr(SDR0_PFC1, sdr0_pfc1);
Niklaus Giger77cad902007-06-27 18:11:38 +0200233 mtsdr(SDR0_USB2D0CR, usb2d0cr);
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200234 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
235 mtsdr(SDR0_USB2H0CR, usb2h0cr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200236
237 /*clear resets*/
238 udelay (1000);
239 mtsdr(SDR0_SRST1, 0x00000000);
240 udelay (1000);
241 mtsdr(SDR0_SRST0, 0x00000000);
242
243 printf("USB: Host(int phy) Device(ext phy)\n");
244
245 } else if (strcmp(act, "dev") == 0) {
246 /*-------------------PATCH-------------------------------*/
247 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
248
249 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100250 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200251 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100252 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200253 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100254 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200255 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100256 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200257 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
258
259 udelay (1000);
260 mtsdr(SDR0_SRST1, 0x672c6000);
261
262 udelay (1000);
263 mtsdr(SDR0_SRST0, 0x00000080);
264
265 udelay (1000);
266 mtsdr(SDR0_SRST1, 0x60206000);
267
268 *(unsigned int *)(0xe0000350) = 0x00000001;
269
270 udelay (1000);
271 mtsdr(SDR0_SRST1, 0x60306000);
272 /*-------------------PATCH-------------------------------*/
273
274 /* SDR Setting */
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200275 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200276 mfsdr(SDR0_USB2H0CR, usb2h0cr);
Niklaus Giger77cad902007-06-27 18:11:38 +0200277 mfsdr(SDR0_USB2D0CR, usb2d0cr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200278 mfsdr(SDR0_PFC1, sdr0_pfc1);
279
280 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100281 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200282 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100283 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200284 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100285 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200286 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100287 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200288 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100289 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200290
291 usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100292 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200293
294 usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100295 usb2d0cr = usb2d0cr | SDR0_USB2D0CR_EBC_SELECTION;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200296
297 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100298 sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200299
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200300 mtsdr(SDR0_USB2H0CR, usb2h0cr);
301 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
Niklaus Giger77cad902007-06-27 18:11:38 +0200302 mtsdr(SDR0_USB2D0CR, usb2d0cr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200303 mtsdr(SDR0_PFC1, sdr0_pfc1);
304
Matthias Fuchs62357702008-01-16 10:33:46 +0100305 /* clear resets */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200306 udelay (1000);
307 mtsdr(SDR0_SRST1, 0x00000000);
308 udelay (1000);
309 mtsdr(SDR0_SRST0, 0x00000000);
310
311 printf("USB: Device(int phy)\n");
312 }
Stefan Roesebe6729c2006-09-13 13:51:58 +0200313#endif /* CONFIG_440EPX */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200314
John Otken john@softadvances.coma70d4082007-03-08 09:39:48 -0600315 mfsdr(SDR0_SRST1, reg); /* enable security/kasumi engines */
316 reg &= ~(SDR0_SRST1_CRYP0 | SDR0_SRST1_KASU0);
317 mtsdr(SDR0_SRST1, reg);
318
Stefan Roesebc7057d2007-01-05 10:40:36 +0100319 /*
320 * Clear PLB4A0_ACR[WRP]
321 * This fix will make the MAL burst disabling patch for the Linux
322 * EMAC driver obsolete.
323 */
Stefan Roese918010a2009-09-09 16:25:29 +0200324 reg = mfdcr(PLB4_ACR) & ~PLB4_ACR_WRP;
325 mtdcr(PLB4_ACR, reg);
Stefan Roesebc7057d2007-01-05 10:40:36 +0100326
Stefan Roese42fbddd2006-09-07 11:51:23 +0200327 return 0;
328}
329
330int checkboard(void)
331{
332 char *s = getenv("serial#");
Stefan Roeseeda436a2007-01-13 07:57:51 +0100333 u8 rev;
Stefan Roesee7f30922009-10-19 14:10:50 +0200334 u32 clock = get_async_pci_freq();
Stefan Roese42fbddd2006-09-07 11:51:23 +0200335
Stefan Roesebe6729c2006-09-13 13:51:58 +0200336#ifdef CONFIG_440EPX
Stefan Roese42fbddd2006-09-07 11:51:23 +0200337 printf("Board: Sequoia - AMCC PPC440EPx Evaluation Board");
Stefan Roesebe6729c2006-09-13 13:51:58 +0200338#else
339 printf("Board: Rainier - AMCC PPC440GRx Evaluation Board");
340#endif
Stefan Roeseeda436a2007-01-13 07:57:51 +0100341
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200342 rev = in_8((void *)(CONFIG_SYS_BCSR_BASE + 0));
Stefan Roesee7f30922009-10-19 14:10:50 +0200343 printf(", Rev. %X, PCI-Async=%d MHz", rev, clock / 1000000);
Stefan Roeseeda436a2007-01-13 07:57:51 +0100344
Stefan Roese42fbddd2006-09-07 11:51:23 +0200345 if (s != NULL) {
346 puts(", serial# ");
347 puts(s);
348 }
349 putc('\n');
350
Stefan Roesee7f30922009-10-19 14:10:50 +0200351 /*
352 * Reconfiguration of the PCI sync clock is already done,
353 * now check again if everything is in range:
354 */
355 if (ppc4xx_pci_sync_clock_config(clock)) {
356 printf("ERROR: PCI clocking incorrect (async=%d "
357 "sync=%ld)!\n", clock, get_PCI_freq());
358 }
359
Stefan Roese42fbddd2006-09-07 11:51:23 +0200360 return (0);
361}
362
Matthias Fuchseb267ba2008-01-08 15:40:09 +0100363#if defined(CONFIG_PCI) && defined(CONFIG_PCI_PNP)
364/*
365 * Assign interrupts to PCI devices.
366 */
367void sequoia_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
368{
Stefan Roese01edcea2008-06-26 13:40:57 +0200369 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, VECNUM_EIRQ2);
Matthias Fuchseb267ba2008-01-08 15:40:09 +0100370}
371#endif
372
Matthias Fuchs62357702008-01-16 10:33:46 +0100373/*
374 * pci_pre_init
Stefan Roese42fbddd2006-09-07 11:51:23 +0200375 *
Matthias Fuchs62357702008-01-16 10:33:46 +0100376 * This routine is called just prior to registering the hose and gives
377 * the board the opportunity to check things. Returning a value of zero
378 * indicates that things are bad & PCI initialization should be aborted.
Stefan Roese42fbddd2006-09-07 11:51:23 +0200379 *
Matthias Fuchs62357702008-01-16 10:33:46 +0100380 * Different boards may wish to customize the pci controller structure
381 * (add regions, override default access routines, etc) or perform
382 * certain pre-initialization actions.
383 */
Stefan Roese54ef7fd2007-06-25 15:57:39 +0200384#if defined(CONFIG_PCI)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200385int pci_pre_init(struct pci_controller *hose)
386{
387 unsigned long addr;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200388
Matthias Fuchs62357702008-01-16 10:33:46 +0100389 /*
390 * Set priority for all PLB3 devices to 0.
391 * Set PLB3 arbiter to fair mode.
392 */
Stefan Roese918010a2009-09-09 16:25:29 +0200393 mfsdr(SD0_AMP1, addr);
394 mtsdr(SD0_AMP1, (addr & 0x000000FF) | 0x0000FF00);
395 addr = mfdcr(PLB3_ACR);
396 mtdcr(PLB3_ACR, addr | 0x80000000);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200397
Matthias Fuchs62357702008-01-16 10:33:46 +0100398 /*
399 * Set priority for all PLB4 devices to 0.
400 */
Stefan Roese918010a2009-09-09 16:25:29 +0200401 mfsdr(SD0_AMP0, addr);
402 mtsdr(SD0_AMP0, (addr & 0x000000FF) | 0x0000FF00);
403 addr = mfdcr(PLB4_ACR) | 0xa0000000; /* Was 0x8---- */
404 mtdcr(PLB4_ACR, addr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200405
Matthias Fuchs62357702008-01-16 10:33:46 +0100406 /*
407 * Set Nebula PLB4 arbiter to fair mode.
408 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200409 /* Segment0 */
Stefan Roese918010a2009-09-09 16:25:29 +0200410 addr = (mfdcr(PLB0_ACR) & ~PLB0_ACR_PPM_MASK) | PLB0_ACR_PPM_FAIR;
411 addr = (addr & ~PLB0_ACR_HBU_MASK) | PLB0_ACR_HBU_ENABLED;
412 addr = (addr & ~PLB0_ACR_RDP_MASK) | PLB0_ACR_RDP_4DEEP;
413 addr = (addr & ~PLB0_ACR_WRP_MASK) | PLB0_ACR_WRP_2DEEP;
414 mtdcr(PLB0_ACR, addr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200415
416 /* Segment1 */
Stefan Roese918010a2009-09-09 16:25:29 +0200417 addr = (mfdcr(PLB1_ACR) & ~PLB1_ACR_PPM_MASK) | PLB1_ACR_PPM_FAIR;
418 addr = (addr & ~PLB1_ACR_HBU_MASK) | PLB1_ACR_HBU_ENABLED;
419 addr = (addr & ~PLB1_ACR_RDP_MASK) | PLB1_ACR_RDP_4DEEP;
420 addr = (addr & ~PLB1_ACR_WRP_MASK) | PLB1_ACR_WRP_2DEEP;
421 mtdcr(PLB1_ACR, addr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200422
Matthias Fuchseb267ba2008-01-08 15:40:09 +0100423#ifdef CONFIG_PCI_PNP
424 hose->fixup_irq = sequoia_pci_fixup_irq;
425#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +0200426 return 1;
427}
Stefan Roese54ef7fd2007-06-25 15:57:39 +0200428#endif /* defined(CONFIG_PCI) */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200429
Matthias Fuchs62357702008-01-16 10:33:46 +0100430/*
431 * pci_target_init
Stefan Roese42fbddd2006-09-07 11:51:23 +0200432 *
Matthias Fuchs62357702008-01-16 10:33:46 +0100433 * The bootstrap configuration provides default settings for the pci
434 * inbound map (PIM). But the bootstrap config choices are limited and
435 * may not be sufficient for a given board.
436 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200437#if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200438void pci_target_init(struct pci_controller *hose)
439{
Matthias Fuchs62357702008-01-16 10:33:46 +0100440 /*
Stefan Roese42fbddd2006-09-07 11:51:23 +0200441 * Set up Direct MMIO registers
Matthias Fuchs62357702008-01-16 10:33:46 +0100442 */
443 /*
444 * PowerPC440EPX PCI Master configuration.
445 * Map one 1Gig range of PLB/processor addresses to PCI memory space.
446 * PLB address 0xA0000000-0xDFFFFFFF
447 * ==> PCI address 0xA0000000-0xDFFFFFFF
448 * Use byte reversed out routines to handle endianess.
449 * Make this region non-prefetchable.
450 */
Niklaus Giger728bd0a2009-10-04 20:04:20 +0200451 out32r(PCIL0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute */
Matthias Fuchs62357702008-01-16 10:33:46 +0100452 /* - disabled b4 setting */
Niklaus Giger728bd0a2009-10-04 20:04:20 +0200453 out32r(PCIL0_PMM0LA, CONFIG_SYS_PCI_MEMBASE); /* PMM0 Local Address */
454 out32r(PCIL0_PMM0PCILA, CONFIG_SYS_PCI_MEMBASE); /* PMM0 PCI Low Address */
455 out32r(PCIL0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */
456 out32r(PCIL0_PMM0MA, 0xE0000001); /* 512M + No prefetching, */
Matthias Fuchs62357702008-01-16 10:33:46 +0100457 /* and enable region */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200458
Niklaus Giger728bd0a2009-10-04 20:04:20 +0200459 out32r(PCIL0_PMM1MA, 0x00000000); /* PMM0 Mask/Attribute */
Matthias Fuchs62357702008-01-16 10:33:46 +0100460 /* - disabled b4 setting */
Niklaus Giger728bd0a2009-10-04 20:04:20 +0200461 out32r(PCIL0_PMM1LA, CONFIG_SYS_PCI_MEMBASE2); /* PMM0 Local Address */
462 out32r(PCIL0_PMM1PCILA, CONFIG_SYS_PCI_MEMBASE2); /* PMM0 PCI Low Address */
463 out32r(PCIL0_PMM1PCIHA, 0x00000000); /* PMM0 PCI High Address */
464 out32r(PCIL0_PMM1MA, 0xE0000001); /* 512M + No prefetching, */
Matthias Fuchs62357702008-01-16 10:33:46 +0100465 /* and enable region */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200466
Niklaus Giger728bd0a2009-10-04 20:04:20 +0200467 out32r(PCIL0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
468 out32r(PCIL0_PTM1LA, 0); /* Local Addr. Reg */
469 out32r(PCIL0_PTM2MS, 0); /* Memory Size/Attribute */
470 out32r(PCIL0_PTM2LA, 0); /* Local Addr. Reg */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200471
Matthias Fuchs62357702008-01-16 10:33:46 +0100472 /*
Stefan Roese42fbddd2006-09-07 11:51:23 +0200473 * Set up Configuration registers
Matthias Fuchs62357702008-01-16 10:33:46 +0100474 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200475
476 /* Program the board's subsystem id/vendor id */
477 pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200478 CONFIG_SYS_PCI_SUBSYS_VENDORID);
479 pci_write_config_word(0, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_ID);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200480
481 /* Configure command register as bus master */
482 pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
483
484 /* 240nS PCI clock */
485 pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
486
487 /* No error reporting */
488 pci_write_config_word(0, PCI_ERREN, 0);
489
490 pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
491
492}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200493#endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT) */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200494
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200495#if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200496void pci_master_init(struct pci_controller *hose)
497{
498 unsigned short temp_short;
499
Matthias Fuchs62357702008-01-16 10:33:46 +0100500 /*
501 * Write the PowerPC440 EP PCI Configuration regs.
502 * Enable PowerPC440 EP to be a master on the PCI bus (PMM).
503 * Enable PowerPC440 EP to act as a PCI memory target (PTM).
504 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200505 pci_read_config_word(0, PCI_COMMAND, &temp_short);
506 pci_write_config_word(0, PCI_COMMAND,
507 temp_short | PCI_COMMAND_MASTER |
508 PCI_COMMAND_MEMORY);
509}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200510#endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT) */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200511
Igor Lisitsin95bcd382007-03-28 19:06:19 +0400512#if defined(CONFIG_POST)
513/*
514 * Returns 1 if keys pressed to start the power-on long-running tests
515 * Called from board_init_f().
516 */
517int post_hotkeys_pressed(void)
518{
519 return 0; /* No hotkeys supported */
520}
521#endif /* CONFIG_POST */
Stefan Roesec55fc7a2009-04-08 10:36:22 +0200522
Stefan Roesec20ef322009-05-11 13:46:14 +0200523#if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_SYS_RAMBOOT)
Stefan Roesec55fc7a2009-04-08 10:36:22 +0200524/*
525 * On NAND-booting sequoia, we need to patch the chips select numbers
526 * in the dtb (CS0 - NAND, CS3 - NOR)
527 */
528void ft_board_setup(void *blob, bd_t *bd)
529{
530 int rc;
531 int len;
532 int nodeoffset;
533 struct fdt_property *prop;
534 u32 *reg;
535 char path[32];
536
537 /* First do common fdt setup */
538 __ft_board_setup(blob, bd);
539
540 /* And now configure NOR chip select to 3 instead of 0 */
541 strcpy(path, "/plb/opb/ebc/nor_flash@0,0");
542 nodeoffset = fdt_path_offset(blob, path);
543 prop = fdt_get_property_w(blob, nodeoffset, "reg", &len);
544 if (prop == NULL) {
545 printf("Unable to update NOR chip select for NAND booting\n");
546 return;
547 }
548 reg = (u32 *)&prop->data[0];
549 reg[0] = 3;
550 rc = fdt_find_and_setprop(blob, path, "reg", reg, 3 * sizeof(u32), 1);
551 if (rc) {
552 printf("Unable to update property NOR mappings, err=%s\n",
553 fdt_strerror(rc));
554 return;
555 }
556
557 /* And now configure NAND chip select to 0 instead of 3 */
558 strcpy(path, "/plb/opb/ebc/ndfc@3,0");
559 nodeoffset = fdt_path_offset(blob, path);
560 prop = fdt_get_property_w(blob, nodeoffset, "reg", &len);
561 if (prop == NULL) {
562 printf("Unable to update NDFC chip select for NAND booting\n");
563 return;
564 }
565 reg = (u32 *)&prop->data[0];
566 reg[0] = 0;
567 rc = fdt_find_and_setprop(blob, path, "reg", reg, 3 * sizeof(u32), 1);
568 if (rc) {
569 printf("Unable to update property NDFC mappings, err=%s\n",
570 fdt_strerror(rc));
571 return;
572 }
573}
574#endif /* CONFIG_NAND_U_BOOT */