blob: e439fb90e2dc6df612678c926683ce315f88df8b [file] [log] [blame]
Stefan Roese42fbddd2006-09-07 11:51:23 +02001/*
Stefan Roesefa257472007-10-15 11:29:33 +02002 * (C) Copyright 2006-2007
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
Matthias Fuchs62357702008-01-16 10:33:46 +010036extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
Stefan Roese42fbddd2006-09-07 11:51:23 +020037
Stefan Roeseab8e99b2006-12-22 14:29:40 +010038ulong flash_get_size (ulong base, int banknum);
39
Stefan Roese42fbddd2006-09-07 11:51:23 +020040int board_early_init_f(void)
41{
Stefan Roesebc7057d2007-01-05 10:40:36 +010042 u32 sdr0_cust0;
43 u32 sdr0_pfc1, sdr0_pfc2;
44 u32 reg;
Stefan Roese42fbddd2006-09-07 11:51:23 +020045
46 mtdcr(ebccfga, xbcfg);
47 mtdcr(ebccfgd, 0xb8400000);
48
Matthias Fuchs62357702008-01-16 10:33:46 +010049 /*
Stefan Roese42fbddd2006-09-07 11:51:23 +020050 * Setup the interrupt controller polarities, triggers, etc.
Matthias Fuchs62357702008-01-16 10:33:46 +010051 */
Stefan Roese42fbddd2006-09-07 11:51:23 +020052 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 */
59
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 */
67
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 */
75
76 /* 50MHz tmrclk */
Larry Johnsonba972012007-12-22 15:34:39 -050077 out_8((u8 *) CFG_BCSR_BASE + 0x04, 0x00);
Stefan Roese42fbddd2006-09-07 11:51:23 +020078
79 /* clear write protects */
Larry Johnsonba972012007-12-22 15:34:39 -050080 out_8((u8 *) CFG_BCSR_BASE + 0x07, 0x00);
Stefan Roese42fbddd2006-09-07 11:51:23 +020081
82 /* enable Ethernet */
Larry Johnsonba972012007-12-22 15:34:39 -050083 out_8((u8 *) CFG_BCSR_BASE + 0x08, 0x00);
Stefan Roese42fbddd2006-09-07 11:51:23 +020084
85 /* enable USB device */
Larry Johnsonba972012007-12-22 15:34:39 -050086 out_8((u8 *) CFG_BCSR_BASE + 0x09, 0x20);
Stefan Roese42fbddd2006-09-07 11:51:23 +020087
Mike Nuss383b1452008-02-06 11:10:11 -050088 /* select Ethernet (and optionally IIC1) pins */
Stefan Roese42fbddd2006-09-07 11:51:23 +020089 mfsdr(SDR0_PFC1, sdr0_pfc1);
Matthias Fuchs62357702008-01-16 10:33:46 +010090 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
91 SDR0_PFC1_SELECT_CONFIG_4;
Mike Nuss383b1452008-02-06 11:10:11 -050092#ifdef CONFIG_I2C_MULTI_BUS
93 sdr0_pfc1 |= ((sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_IIC1_SEL);
94#endif
Steven A. Falco7bf9cc62008-08-06 15:42:52 -040095 /* Two UARTs, so we need 4-pin mode. Also, we want CTS/RTS mode. */
96 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0IM_MASK) | SDR0_PFC1_U0IM_4PINS;
97 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0ME_MASK) | SDR0_PFC1_U0ME_CTS_RTS;
98 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U1ME_MASK) | SDR0_PFC1_U1ME_CTS_RTS;
99
Stefan Roese42fbddd2006-09-07 11:51:23 +0200100 mfsdr(SDR0_PFC2, sdr0_pfc2);
Matthias Fuchs62357702008-01-16 10:33:46 +0100101 sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
102 SDR0_PFC2_SELECT_CONFIG_4;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200103 mtsdr(SDR0_PFC2, sdr0_pfc2);
104 mtsdr(SDR0_PFC1, sdr0_pfc1);
105
106 /* PCI arbiter enabled */
107 mfsdr(sdr_pci0, reg);
108 mtsdr(sdr_pci0, 0x80000000 | reg);
109
110 /* setup NAND FLASH */
111 mfsdr(SDR0_CUST0, sdr0_cust0);
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200112 sdr0_cust0 = SDR0_CUST0_MUX_NDFC_SEL |
Stefan Roese42fbddd2006-09-07 11:51:23 +0200113 SDR0_CUST0_NDFC_ENABLE |
114 SDR0_CUST0_NDFC_BW_8_BIT |
115 SDR0_CUST0_NDFC_ARE_MASK |
116 (0x80000000 >> (28 + CFG_NAND_CS));
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200117 mtsdr(SDR0_CUST0, sdr0_cust0);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200118
119 return 0;
120}
121
Stefan Roese42fbddd2006-09-07 11:51:23 +0200122int misc_init_r(void)
123{
124 uint pbcr;
125 int size_val = 0;
Stefan Roesebc7057d2007-01-05 10:40:36 +0100126 u32 reg;
Stefan Roesebe6729c2006-09-13 13:51:58 +0200127#ifdef CONFIG_440EPX
Stefan Roese42fbddd2006-09-07 11:51:23 +0200128 unsigned long usb2d0cr = 0;
129 unsigned long usb2phy0cr, usb2h0cr = 0;
130 unsigned long sdr0_pfc1;
131 char *act = getenv("usbact");
Stefan Roesebe6729c2006-09-13 13:51:58 +0200132#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +0200133
Matthias Fuchs62357702008-01-16 10:33:46 +0100134 /* Re-do flash sizing to get full correct info */
Stefan Roeseab8e99b2006-12-22 14:29:40 +0100135
136 /* adjust flash start and offset */
137 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
138 gd->bd->bi_flashoffset = 0;
139
Stefan Roese42fbddd2006-09-07 11:51:23 +0200140#if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
141 mtdcr(ebccfga, pb3cr);
142#else
143 mtdcr(ebccfga, pb0cr);
144#endif
145 pbcr = mfdcr(ebccfgd);
Wolfgang Denk3595e612008-01-23 14:31:17 +0100146 size_val = ffs(gd->bd->bi_flashsize) - 21;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200147 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
148#if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
149 mtdcr(ebccfga, pb3cr);
150#else
151 mtdcr(ebccfga, pb0cr);
152#endif
153 mtdcr(ebccfgd, pbcr);
154
Stefan Roeseab8e99b2006-12-22 14:29:40 +0100155 /*
156 * Re-check to get correct base address
157 */
158 flash_get_size(gd->bd->bi_flashstart, 0);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200159
Jean-Christophe PLAGNIOL-VILLARD53db4cd2008-09-10 22:48:04 +0200160#ifdef CONFIG_ENV_IS_IN_FLASH
Stefan Roese42fbddd2006-09-07 11:51:23 +0200161 /* Monitor protection ON by default */
162 (void)flash_protect(FLAG_PROTECT_SET,
163 -CFG_MONITOR_LEN,
164 0xffffffff,
165 &flash_info[0]);
166
167 /* Env protection ON by default */
168 (void)flash_protect(FLAG_PROTECT_SET,
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200169 CONFIG_ENV_ADDR_REDUND,
170 CONFIG_ENV_ADDR_REDUND + 2*CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese42fbddd2006-09-07 11:51:23 +0200171 &flash_info[0]);
172#endif
173
174 /*
175 * USB suff...
176 */
Stefan Roesebe6729c2006-09-13 13:51:58 +0200177#ifdef CONFIG_440EPX
Matthias Fuchs62357702008-01-16 10:33:46 +0100178 if (act == NULL || strcmp(act, "hostdev") == 0) {
Stefan Roese42fbddd2006-09-07 11:51:23 +0200179 /* SDR Setting */
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200180 mfsdr(SDR0_PFC1, sdr0_pfc1);
Niklaus Giger77cad902007-06-27 18:11:38 +0200181 mfsdr(SDR0_USB2D0CR, usb2d0cr);
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200182 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
183 mfsdr(SDR0_USB2H0CR, usb2h0cr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200184
185 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100186 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200187 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100188 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200189 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100190 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200191 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100192 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200193 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100194 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200195
Matthias Fuchs62357702008-01-16 10:33:46 +0100196 /*
197 * An 8-bit/60MHz interface is the only possible alternative
198 * when connecting the Device to the PHY
199 */
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200200 usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100201 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200202
Matthias Fuchs62357702008-01-16 10:33:46 +0100203 /*
204 * To enable the USB 2.0 Device function
205 * through the UTMI interface
206 */
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200207 usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100208 usb2d0cr = usb2d0cr | SDR0_USB2D0CR_USB2DEV_SELECTION;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200209
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200210 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100211 sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_USB2D_SEL;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200212
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200213 mtsdr(SDR0_PFC1, sdr0_pfc1);
Niklaus Giger77cad902007-06-27 18:11:38 +0200214 mtsdr(SDR0_USB2D0CR, usb2d0cr);
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200215 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
216 mtsdr(SDR0_USB2H0CR, usb2h0cr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200217
218 /*clear resets*/
219 udelay (1000);
220 mtsdr(SDR0_SRST1, 0x00000000);
221 udelay (1000);
222 mtsdr(SDR0_SRST0, 0x00000000);
223
224 printf("USB: Host(int phy) Device(ext phy)\n");
225
226 } else if (strcmp(act, "dev") == 0) {
227 /*-------------------PATCH-------------------------------*/
228 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
229
230 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100231 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200232 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100233 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200234 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100235 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200236 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100237 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200238 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
239
240 udelay (1000);
241 mtsdr(SDR0_SRST1, 0x672c6000);
242
243 udelay (1000);
244 mtsdr(SDR0_SRST0, 0x00000080);
245
246 udelay (1000);
247 mtsdr(SDR0_SRST1, 0x60206000);
248
249 *(unsigned int *)(0xe0000350) = 0x00000001;
250
251 udelay (1000);
252 mtsdr(SDR0_SRST1, 0x60306000);
253 /*-------------------PATCH-------------------------------*/
254
255 /* SDR Setting */
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200256 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200257 mfsdr(SDR0_USB2H0CR, usb2h0cr);
Niklaus Giger77cad902007-06-27 18:11:38 +0200258 mfsdr(SDR0_USB2D0CR, usb2d0cr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200259 mfsdr(SDR0_PFC1, sdr0_pfc1);
260
261 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100262 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200263 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100264 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200265 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100266 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200267 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100268 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200269 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100270 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200271
272 usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100273 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200274
275 usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100276 usb2d0cr = usb2d0cr | SDR0_USB2D0CR_EBC_SELECTION;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200277
278 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
Matthias Fuchs62357702008-01-16 10:33:46 +0100279 sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200280
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200281 mtsdr(SDR0_USB2H0CR, usb2h0cr);
282 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
Niklaus Giger77cad902007-06-27 18:11:38 +0200283 mtsdr(SDR0_USB2D0CR, usb2d0cr);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200284 mtsdr(SDR0_PFC1, sdr0_pfc1);
285
Matthias Fuchs62357702008-01-16 10:33:46 +0100286 /* clear resets */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200287 udelay (1000);
288 mtsdr(SDR0_SRST1, 0x00000000);
289 udelay (1000);
290 mtsdr(SDR0_SRST0, 0x00000000);
291
292 printf("USB: Device(int phy)\n");
293 }
Stefan Roesebe6729c2006-09-13 13:51:58 +0200294#endif /* CONFIG_440EPX */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200295
John Otken john@softadvances.coma70d4082007-03-08 09:39:48 -0600296 mfsdr(SDR0_SRST1, reg); /* enable security/kasumi engines */
297 reg &= ~(SDR0_SRST1_CRYP0 | SDR0_SRST1_KASU0);
298 mtsdr(SDR0_SRST1, reg);
299
Stefan Roesebc7057d2007-01-05 10:40:36 +0100300 /*
301 * Clear PLB4A0_ACR[WRP]
302 * This fix will make the MAL burst disabling patch for the Linux
303 * EMAC driver obsolete.
304 */
305 reg = mfdcr(plb4_acr) & ~PLB4_ACR_WRP;
306 mtdcr(plb4_acr, reg);
307
Stefan Roese42fbddd2006-09-07 11:51:23 +0200308 return 0;
309}
310
311int checkboard(void)
312{
313 char *s = getenv("serial#");
Stefan Roeseeda436a2007-01-13 07:57:51 +0100314 u8 rev;
315 u8 val;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200316
Stefan Roesebe6729c2006-09-13 13:51:58 +0200317#ifdef CONFIG_440EPX
Stefan Roese42fbddd2006-09-07 11:51:23 +0200318 printf("Board: Sequoia - AMCC PPC440EPx Evaluation Board");
Stefan Roesebe6729c2006-09-13 13:51:58 +0200319#else
320 printf("Board: Rainier - AMCC PPC440GRx Evaluation Board");
321#endif
Stefan Roeseeda436a2007-01-13 07:57:51 +0100322
Stefan Roesefa257472007-10-15 11:29:33 +0200323 rev = in_8((void *)(CFG_BCSR_BASE + 0));
324 val = in_8((void *)(CFG_BCSR_BASE + 5)) & CFG_BCSR5_PCI66EN;
Stefan Roeseeda436a2007-01-13 07:57:51 +0100325 printf(", Rev. %X, PCI=%d MHz", rev, val ? 66 : 33);
326
Stefan Roese42fbddd2006-09-07 11:51:23 +0200327 if (s != NULL) {
328 puts(", serial# ");
329 puts(s);
330 }
331 putc('\n');
332
333 return (0);
334}
335
Matthias Fuchseb267ba2008-01-08 15:40:09 +0100336#if defined(CONFIG_PCI) && defined(CONFIG_PCI_PNP)
337/*
338 * Assign interrupts to PCI devices.
339 */
340void sequoia_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
341{
Stefan Roese01edcea2008-06-26 13:40:57 +0200342 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, VECNUM_EIRQ2);
Matthias Fuchseb267ba2008-01-08 15:40:09 +0100343}
344#endif
345
Matthias Fuchs62357702008-01-16 10:33:46 +0100346/*
347 * pci_pre_init
Stefan Roese42fbddd2006-09-07 11:51:23 +0200348 *
Matthias Fuchs62357702008-01-16 10:33:46 +0100349 * This routine is called just prior to registering the hose and gives
350 * the board the opportunity to check things. Returning a value of zero
351 * indicates that things are bad & PCI initialization should be aborted.
Stefan Roese42fbddd2006-09-07 11:51:23 +0200352 *
Matthias Fuchs62357702008-01-16 10:33:46 +0100353 * Different boards may wish to customize the pci controller structure
354 * (add regions, override default access routines, etc) or perform
355 * certain pre-initialization actions.
356 */
Stefan Roese54ef7fd2007-06-25 15:57:39 +0200357#if defined(CONFIG_PCI)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200358int pci_pre_init(struct pci_controller *hose)
359{
360 unsigned long addr;
Stefan Roese42fbddd2006-09-07 11:51:23 +0200361
Matthias Fuchs62357702008-01-16 10:33:46 +0100362 /*
363 * Set priority for all PLB3 devices to 0.
364 * Set PLB3 arbiter to fair mode.
365 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200366 mfsdr(sdr_amp1, addr);
367 mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00);
368 addr = mfdcr(plb3_acr);
369 mtdcr(plb3_acr, addr | 0x80000000);
370
Matthias Fuchs62357702008-01-16 10:33:46 +0100371 /*
372 * Set priority for all PLB4 devices to 0.
373 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200374 mfsdr(sdr_amp0, addr);
375 mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00);
376 addr = mfdcr(plb4_acr) | 0xa0000000; /* Was 0x8---- */
377 mtdcr(plb4_acr, addr);
378
Matthias Fuchs62357702008-01-16 10:33:46 +0100379 /*
380 * Set Nebula PLB4 arbiter to fair mode.
381 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200382 /* Segment0 */
383 addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair;
384 addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled;
385 addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep;
386 addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep;
387 mtdcr(plb0_acr, addr);
388
389 /* Segment1 */
390 addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair;
391 addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled;
392 addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep;
393 addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep;
394 mtdcr(plb1_acr, addr);
395
Matthias Fuchseb267ba2008-01-08 15:40:09 +0100396#ifdef CONFIG_PCI_PNP
397 hose->fixup_irq = sequoia_pci_fixup_irq;
398#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +0200399 return 1;
400}
Stefan Roese54ef7fd2007-06-25 15:57:39 +0200401#endif /* defined(CONFIG_PCI) */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200402
Matthias Fuchs62357702008-01-16 10:33:46 +0100403/*
404 * pci_target_init
Stefan Roese42fbddd2006-09-07 11:51:23 +0200405 *
Matthias Fuchs62357702008-01-16 10:33:46 +0100406 * The bootstrap configuration provides default settings for the pci
407 * inbound map (PIM). But the bootstrap config choices are limited and
408 * may not be sufficient for a given board.
409 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200410#if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
411void pci_target_init(struct pci_controller *hose)
412{
Matthias Fuchs62357702008-01-16 10:33:46 +0100413 /*
Stefan Roese42fbddd2006-09-07 11:51:23 +0200414 * Set up Direct MMIO registers
Matthias Fuchs62357702008-01-16 10:33:46 +0100415 */
416 /*
417 * PowerPC440EPX PCI Master configuration.
418 * Map one 1Gig range of PLB/processor addresses to PCI memory space.
419 * PLB address 0xA0000000-0xDFFFFFFF
420 * ==> PCI address 0xA0000000-0xDFFFFFFF
421 * Use byte reversed out routines to handle endianess.
422 * Make this region non-prefetchable.
423 */
424 out32r(PCIX0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute */
425 /* - disabled b4 setting */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200426 out32r(PCIX0_PMM0LA, CFG_PCI_MEMBASE); /* PMM0 Local Address */
Matthias Fuchs62357702008-01-16 10:33:46 +0100427 out32r(PCIX0_PMM0PCILA, CFG_PCI_MEMBASE); /* PMM0 PCI Low Address */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200428 out32r(PCIX0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */
Matthias Fuchs62357702008-01-16 10:33:46 +0100429 out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M + No prefetching, */
430 /* and enable region */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200431
Matthias Fuchs62357702008-01-16 10:33:46 +0100432 out32r(PCIX0_PMM1MA, 0x00000000); /* PMM0 Mask/Attribute */
433 /* - disabled b4 setting */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200434 out32r(PCIX0_PMM1LA, CFG_PCI_MEMBASE2); /* PMM0 Local Address */
Matthias Fuchs62357702008-01-16 10:33:46 +0100435 out32r(PCIX0_PMM1PCILA, CFG_PCI_MEMBASE2); /* PMM0 PCI Low Address */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200436 out32r(PCIX0_PMM1PCIHA, 0x00000000); /* PMM0 PCI High Address */
Matthias Fuchs62357702008-01-16 10:33:46 +0100437 out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M + No prefetching, */
438 /* and enable region */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200439
440 out32r(PCIX0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
Matthias Fuchs62357702008-01-16 10:33:46 +0100441 out32r(PCIX0_PTM1LA, 0); /* Local Addr. Reg */
442 out32r(PCIX0_PTM2MS, 0); /* Memory Size/Attribute */
443 out32r(PCIX0_PTM2LA, 0); /* Local Addr. Reg */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200444
Matthias Fuchs62357702008-01-16 10:33:46 +0100445 /*
Stefan Roese42fbddd2006-09-07 11:51:23 +0200446 * Set up Configuration registers
Matthias Fuchs62357702008-01-16 10:33:46 +0100447 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200448
449 /* Program the board's subsystem id/vendor id */
450 pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
451 CFG_PCI_SUBSYS_VENDORID);
452 pci_write_config_word(0, PCI_SUBSYSTEM_ID, CFG_PCI_SUBSYS_ID);
453
454 /* Configure command register as bus master */
455 pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
456
457 /* 240nS PCI clock */
458 pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
459
460 /* No error reporting */
461 pci_write_config_word(0, PCI_ERREN, 0);
462
463 pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
464
465}
Matthias Fuchs62357702008-01-16 10:33:46 +0100466#endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200467
Stefan Roese42fbddd2006-09-07 11:51:23 +0200468#if defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT)
469void pci_master_init(struct pci_controller *hose)
470{
471 unsigned short temp_short;
472
Matthias Fuchs62357702008-01-16 10:33:46 +0100473 /*
474 * Write the PowerPC440 EP PCI Configuration regs.
475 * Enable PowerPC440 EP to be a master on the PCI bus (PMM).
476 * Enable PowerPC440 EP to act as a PCI memory target (PTM).
477 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200478 pci_read_config_word(0, PCI_COMMAND, &temp_short);
479 pci_write_config_word(0, PCI_COMMAND,
480 temp_short | PCI_COMMAND_MASTER |
481 PCI_COMMAND_MEMORY);
482}
Matthias Fuchs62357702008-01-16 10:33:46 +0100483#endif /* defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT) */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200484
Matthias Fuchs62357702008-01-16 10:33:46 +0100485/*
486 * is_pci_host
Stefan Roese42fbddd2006-09-07 11:51:23 +0200487 *
Matthias Fuchs62357702008-01-16 10:33:46 +0100488 * This routine is called to determine if a pci scan should be
489 * performed. With various hardware environments (especially cPCI and
490 * PPMC) it's insufficient to depend on the state of the arbiter enable
491 * bit in the strap register, or generic host/adapter assumptions.
Stefan Roese42fbddd2006-09-07 11:51:23 +0200492 *
Matthias Fuchs62357702008-01-16 10:33:46 +0100493 * Rather than hard-code a bad assumption in the general 440 code, the
494 * 440 pci code requires the board to decide at runtime.
Stefan Roese42fbddd2006-09-07 11:51:23 +0200495 *
Matthias Fuchs62357702008-01-16 10:33:46 +0100496 * Return 0 for adapter mode, non-zero for host (monarch) mode.
497 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200498#if defined(CONFIG_PCI)
499int is_pci_host(struct pci_controller *hose)
500{
501 /* Cactus is always configured as host. */
502 return (1);
503}
Matthias Fuchs62357702008-01-16 10:33:46 +0100504#endif /* defined(CONFIG_PCI) */
505
Igor Lisitsin95bcd382007-03-28 19:06:19 +0400506#if defined(CONFIG_POST)
507/*
508 * Returns 1 if keys pressed to start the power-on long-running tests
509 * Called from board_init_f().
510 */
511int post_hotkeys_pressed(void)
512{
513 return 0; /* No hotkeys supported */
514}
515#endif /* CONFIG_POST */