]> git.sur5r.net Git - u-boot/blob - board/gdsys/gdppc440etx/gdppc440etx.c
ppc4xx: Add GDsys PowerPC 440 ETX board support.
[u-boot] / board / gdsys / gdppc440etx / gdppc440etx.c
1 /*
2  * (C) Copyright 2008
3  * Dirk Eibach,  Guntermann & Drunck GmbH, eibach@gdsys.de
4  *
5  * Based on board/amcc/yosemite/yosemite.c
6  * (C) Copyright 2006-2007
7  * Stefan Roese, DENX Software Engineering, sr@denx.de.
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  */
27
28 #include <common.h>
29 #include <ppc4xx.h>
30 #include <asm/processor.h>
31 #include <asm/io.h>
32
33 DECLARE_GLOBAL_DATA_PTR;
34
35 /* info for FLASH chips */
36 extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
37
38 int board_early_init_f(void)
39 {
40         register uint reg;
41
42         /*
43          * Setup the external bus controller/chip selects
44          */
45         mfebc(xbcfg, reg);
46         mtebc(xbcfg, reg | 0x04000000);         /* Set ATC */
47
48         /*
49          * Setup the GPIO pins
50          */
51
52         /* setup Address lines for flash size 64Meg. */
53         out32(GPIO0_OSRL, in32(GPIO0_OSRL) | 0x54000000);
54         out32(GPIO0_TSRL, in32(GPIO0_TSRL) | 0x54000000);
55         out32(GPIO0_ISR1L, in32(GPIO0_ISR1L) | 0x54000000);
56
57         /* setup emac */
58         out32(GPIO0_TCR, in32(GPIO0_TCR) | 0xC080);
59         out32(GPIO0_TSRL, in32(GPIO0_TSRL) | 0x40);
60         out32(GPIO0_ISR1L, in32(GPIO0_ISR1L) | 0x55);
61         out32(GPIO0_OSRH, in32(GPIO0_OSRH) | 0x50004000);
62         out32(GPIO0_ISR1H, in32(GPIO0_ISR1H) | 0x00440000);
63
64         /* UART0 and UART1*/
65         out32(GPIO1_TCR, in32(GPIO1_TCR)     | 0x16000000);
66         out32(GPIO1_OSRL, in32(GPIO1_OSRL)   | 0x02180000);
67         out32(GPIO1_ISR1L, in32(GPIO1_ISR1L) | 0x00400000);
68         out32(GPIO1_ISR2L, in32(GPIO1_ISR2L) | 0x04010000);
69
70         /* disable boot-eeprom WP */
71         out32(GPIO0_OSRL, in32(GPIO0_OSRL) & ~0x00C00000);
72         out32(GPIO0_TSRL, in32(GPIO0_TSRL) & ~0x00C00000);
73         out32(GPIO0_ISR1L, in32(GPIO0_ISR1L) & ~0x00C00000);
74         out32(GPIO0_TCR, in32(GPIO0_TCR) | 0x08000000);
75         out32(GPIO0_OR, in32(GPIO0_OR) & ~0x08000000);
76
77         /* external interrupts IRQ0...3 */
78         out32(GPIO1_TCR, in32(GPIO1_TCR) & ~0x00f00000);
79         out32(GPIO1_TSRL, in32(GPIO1_TSRL) & ~0x00005500);
80         out32(GPIO1_ISR1L, in32(GPIO1_ISR1L) | 0x00005500);
81
82
83         /*
84          * Setup the interrupt controller polarities, triggers, etc.
85          */
86         mtdcr(uic0sr, 0xffffffff);      /* clear all */
87         mtdcr(uic0er, 0x00000000);      /* disable all */
88         mtdcr(uic0cr, 0x00000009);      /* ATI & UIC1 crit are critical */
89         mtdcr(uic0pr, 0xfffffe13);      /* per ref-board manual */
90         mtdcr(uic0tr, 0x01c00008);      /* per ref-board manual */
91         mtdcr(uic0vr, 0x00000001);      /* int31 highest, base=0x000 */
92         mtdcr(uic0sr, 0xffffffff);      /* clear all */
93
94         mtdcr(uic1sr, 0xffffffff);      /* clear all */
95         mtdcr(uic1er, 0x00000000);      /* disable all */
96         mtdcr(uic1cr, 0x00000000);      /* all non-critical */
97         mtdcr(uic1pr, 0xffffe0ff);      /* per ref-board manual */
98         mtdcr(uic1tr, 0x00ffc000);      /* per ref-board manual */
99         mtdcr(uic1vr, 0x00000001);      /* int31 highest, base=0x000 */
100         mtdcr(uic1sr, 0xffffffff);      /* clear all */
101
102         /*
103          * Setup other serial configuration
104          */
105         mfsdr(sdr_pci0, reg);
106         mtsdr(sdr_pci0, 0x80000000 | reg);      /* PCI arbiter enabled */
107         mtsdr(sdr_pfc0, 0x00003e00);    /* Pin function */
108         mtsdr(sdr_pfc1, 0x00048000);    /* Pin function: UART0 has 4 pins */
109
110         return 0;
111 }
112
113 int misc_init_r(void)
114 {
115         uint pbcr;
116         int size_val;
117         uint sz;
118
119         /* Re-do sizing to get full correct info */
120         mfebc(pb0cr, pbcr);
121
122         if (gd->bd->bi_flashsize > 0x08000000)
123                 panic("Max. flash banksize is 128 MB!\n");
124
125         for (sz = gd->bd->bi_flashsize, size_val = 7;
126             ((sz & 0x08000000) == 0) && (size_val > 0); --size_val)
127                 sz <<= 1;
128
129         pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
130         mtebc(pb0cr, pbcr);
131
132         /* adjust flash start and offset */
133         gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
134         gd->bd->bi_flashoffset = 0;
135
136         /* Monitor protection ON by default */
137         (void)flash_protect(FLAG_PROTECT_SET,
138                             -CONFIG_SYS_MONITOR_LEN,
139                             0xffffffff,
140                             &flash_info[0]);
141
142         return 0;
143 }
144
145 int checkboard(void)
146 {
147         char *s = getenv("serial#");
148         u8 rev;
149         u8 val;
150
151         printf("Board: GDPPC440ETX - G&D PPC440EP/GR ETX-module");
152
153         if (s != NULL) {
154                 puts(", serial# ");
155                 puts(s);
156         }
157         putc('\n');
158
159         return 0;
160 }
161
162 /*
163  * pci_pre_init
164  *
165  * This routine is called just prior to registering the hose and gives
166  * the board the opportunity to check things. Returning a value of zero
167  * indicates that things are bad & PCI initialization should be aborted.
168  *
169  *      Different boards may wish to customize the pci controller structure
170  *      (add regions, override default access routines, etc) or perform
171  *      certain pre-initialization actions.
172  *
173  */
174 #if defined(CONFIG_PCI)
175 int pci_pre_init(struct pci_controller *hose)
176 {
177         unsigned long addr;
178
179         /*
180          * Set priority for all PLB3 devices to 0.
181          * Set PLB3 arbiter to fair mode.
182          */
183         mfsdr(sdr_amp1, addr);
184         mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00);
185         addr = mfdcr(plb3_acr);
186         mtdcr(plb3_acr, addr | 0x80000000);
187
188         /*
189          * Set priority for all PLB4 devices to 0.
190          */
191         mfsdr(sdr_amp0, addr);
192         mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00);
193         addr = mfdcr(plb4_acr) | 0xa0000000;    /* Was 0x8---- */
194         mtdcr(plb4_acr, addr);
195
196         /*
197          * Set Nebula PLB4 arbiter to fair mode.
198          */
199         /* Segment0 */
200         addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair;
201         addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled;
202         addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep;
203         addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep;
204         mtdcr(plb0_acr, addr);
205
206         /* Segment1 */
207         addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair;
208         addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled;
209         addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep;
210         addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep;
211         mtdcr(plb1_acr, addr);
212
213         /* enable 66 MHz ext. Clock */
214         out32(GPIO1_TCR, in32(GPIO1_TCR) | 0x00008000);
215         out32(GPIO1_OR, in32(GPIO1_OR) | 0x00008000);
216
217         return 1;
218 }
219 #endif  /* defined(CONFIG_PCI) */
220
221 /*
222  * pci_target_init
223  *
224  * The bootstrap configuration provides default settings for the pci
225  * inbound map (PIM). But the bootstrap config choices are limited and
226  * may not be sufficient for a given board.
227  *
228  */
229 #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT)
230 void pci_target_init(struct pci_controller *hose)
231 {
232         /*
233          * Set up Direct MMIO registers
234          */
235
236         /*
237          * PowerPC440 EP PCI Master configuration.
238          * Map one 1Gig range of PLB/processor addresses to PCI memory space.
239          *       PLB address 0xA0000000-0xDFFFFFFF
240          *   ==> PCI address 0xA0000000-0xDFFFFFFF
241          *   Use byte reversed out routines to handle endianess.
242          * Make this region non-prefetchable.
243          */
244         out32r(PCIX0_PMM0MA, 0x00000000);       /* disabled b4 setting */
245         out32r(PCIX0_PMM0LA, CONFIG_SYS_PCI_MEMBASE);
246         out32r(PCIX0_PMM0PCILA, CONFIG_SYS_PCI_MEMBASE);
247         out32r(PCIX0_PMM0PCIHA, 0x00000000);
248         out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M, no prefetch, enable region */
249
250         out32r(PCIX0_PMM1MA, 0x00000000);       /* disabled b4 setting */
251         out32r(PCIX0_PMM1LA, CONFIG_SYS_PCI_MEMBASE2);
252         out32r(PCIX0_PMM1PCILA, CONFIG_SYS_PCI_MEMBASE2);
253         out32r(PCIX0_PMM1PCIHA, 0x00000000);
254         out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M, no prefetch, enable region */
255
256         out32r(PCIX0_PTM1MS, 0x00000001);
257         out32r(PCIX0_PTM1LA, 0);
258         out32r(PCIX0_PTM2MS, 0);
259         out32r(PCIX0_PTM2LA, 0);
260
261         /*
262          * Set up Configuration registers
263          */
264
265         /* Program the board's subsystem id/vendor id */
266         pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
267                               CONFIG_SYS_PCI_SUBSYS_VENDORID);
268         pci_write_config_word(0, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_ID);
269
270         /* Configure command register as bus master */
271         pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
272
273         /* 240nS PCI clock */
274         pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
275
276         /* No error reporting */
277         pci_write_config_word(0, PCI_ERREN, 0);
278
279         pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
280
281 }
282 #endif  /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT) */
283
284 /*
285  *  pci_master_init
286  *
287  */
288 #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT)
289 void pci_master_init(struct pci_controller *hose)
290 {
291         unsigned short temp_short;
292
293         /*
294          * Write the PowerPC440 EP PCI Configuration regs.
295          *   Enable PowerPC440 EP to be a master on the PCI bus (PMM).
296          *   Enable PowerPC440 EP to act as a PCI memory target (PTM).
297          */
298         pci_read_config_word(0, PCI_COMMAND, &temp_short);
299         pci_write_config_word(0, PCI_COMMAND,
300                               temp_short | PCI_COMMAND_MASTER |
301                               PCI_COMMAND_MEMORY);
302 }
303 #endif  /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT) */
304
305 /*
306  *  is_pci_host
307  *
308  *      This routine is called to determine if a pci scan should be
309  *      performed. With various hardware environments (especially cPCI and
310  *      PPMC) it's insufficient to depend on the state of the arbiter enable
311  *      bit in the strap register, or generic host/adapter assumptions.
312  *
313  *      Rather than hard-code a bad assumption in the general 440 code, the
314  *      440 pci code requires the board to decide at runtime.
315  *
316  *      Return 0 for adapter mode, non-zero for host (monarch) mode.
317  *
318  *
319  */
320 #if defined(CONFIG_PCI)
321 int is_pci_host(struct pci_controller *hose)
322 {
323         return 1;
324 }
325 #endif  /* defined(CONFIG_PCI) */