Package support for IP over ATM
[openwrt.git] / target / linux / magicbox / files / arch / ppc / platforms / 4xx / magicbox.c
1 /*
2 * Support for IBM PPC 405EP-based MagicBox board
3 * Copyright (C) 2006 Karol Lewandowski
4 *
5 * Heavily based on bubinga.c
6 *
7 * Author: SAW (IBM), derived from walnut.c.
8 * Maintained by MontaVista Software <source@mvista.com>
9 *
10 * 2003 (c) MontaVista Softare Inc. This file is licensed under the
11 * terms of the GNU General Public License version 2. This program is
12 * licensed "as is" without any warranty of any kind, whether express
13 * or implied.
14 */
15
16 #include <linux/init.h>
17 #include <linux/smp.h>
18 #include <linux/threads.h>
19 #include <linux/param.h>
20 #include <linux/string.h>
21 #include <linux/blkdev.h>
22 #include <linux/pci.h>
23 #include <linux/tty.h>
24 #include <linux/serial.h>
25 #include <linux/serial_core.h>
26 #include <linux/platform_device.h>
27 #include <linux/mtd/partitions.h>
28 #include <linux/mtd/physmap.h>
29
30 #include <asm/system.h>
31 #include <asm/pci-bridge.h>
32 #include <asm/processor.h>
33 #include <asm/machdep.h>
34 #include <asm/page.h>
35 #include <asm/time.h>
36 #include <asm/io.h>
37 #include <asm/kgdb.h>
38 #include <asm/ocp.h>
39 #include <asm/ibm_ocp_pci.h>
40
41 #include <platforms/4xx/ibm405ep.h>
42
43 #undef DEBUG
44
45 #ifdef DEBUG
46 #define DBG(x...) printk(x)
47 #else
48 #define DBG(x...)
49 #endif
50
51 extern bd_t __res;
52
53 /* Some IRQs unique to the board
54 * Used by the generic 405 PCI setup functions in ppc4xx_pci.c
55 */
56 int __init
57 ppc405_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
58 {
59 static char pci_irq_table[][4] =
60 /*
61 * PCI IDSEL/INTPIN->INTLINE
62 * A B C D
63 */
64 {
65 {28, 28, 28, 28}, /* IDSEL 1 - PCI slot 1 */
66 {29, 29, 29, 29}, /* IDSEL 2 - PCI slot 2 */
67 {30, 30, 30, 30}, /* IDSEL 3 - PCI slot 3 */
68 {31, 31, 31, 31}, /* IDSEL 4 - PCI slot 4 */
69 };
70
71 const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
72 return PCI_IRQ_TABLE_LOOKUP;
73 };
74
75 /* The serial clock for the chip is an internal clock determined by
76 * different clock speeds/dividers.
77 * Calculate the proper input baud rate and setup the serial driver.
78 */
79 static void __init
80 magicbox_early_serial_map(void)
81 {
82 u32 uart_div;
83 int uart_clock;
84 struct uart_port port;
85
86 /* Calculate the serial clock input frequency
87 *
88 * The base baud is the PLL OUTA (provided in the board info
89 * structure) divided by the external UART Divisor, divided
90 * by 16.
91 */
92 uart_div = (mfdcr(DCRN_CPC0_UCR_BASE) & DCRN_CPC0_UCR_U0DIV);
93 uart_clock = __res.bi_procfreq / uart_div;
94
95 /* Setup serial port access */
96 memset(&port, 0, sizeof(port));
97 port.membase = (void*)ACTING_UART0_IO_BASE;
98 port.irq = ACTING_UART0_INT;
99 port.uartclk = uart_clock;
100 port.regshift = 0;
101 port.iotype = UPIO_MEM;
102 port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
103 port.line = 0;
104
105 if (early_serial_setup(&port) != 0) {
106 printk("Early serial init of port 0 failed\n");
107 }
108
109 port.membase = (void*)ACTING_UART1_IO_BASE;
110 port.irq = ACTING_UART1_INT;
111 port.line = 1;
112
113 if (early_serial_setup(&port) != 0) {
114 printk("Early serial init of port 1 failed\n");
115 }
116 }
117
118 void __init
119 bios_fixup(struct pci_controller *hose, struct pcil0_regs *pcip)
120 {
121 #ifdef CONFIG_PCI
122
123 unsigned int bar_response, bar;
124 /*
125 * Expected PCI mapping:
126 *
127 * PLB addr PCI memory addr
128 * --------------------- ---------------------
129 * 0000'0000 - 7fff'ffff <--- 0000'0000 - 7fff'ffff
130 * 8000'0000 - Bfff'ffff ---> 8000'0000 - Bfff'ffff
131 *
132 * PLB addr PCI io addr
133 * --------------------- ---------------------
134 * e800'0000 - e800'ffff ---> 0000'0000 - 0001'0000
135 *
136 * The following code is simplified by assuming that the bootrom
137 * has been well behaved in following this mapping.
138 */
139
140 #ifdef DEBUG
141 int i;
142
143 printk("ioremap PCLIO_BASE = 0x%x\n", pcip);
144 printk("PCI bridge regs before fixup \n");
145 for (i = 0; i <= 3; i++) {
146 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].ma)));
147 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].la)));
148 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pcila)));
149 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pciha)));
150 }
151 printk(" ptm1ms\t0x%x\n", in_le32(&(pcip->ptm1ms)));
152 printk(" ptm1la\t0x%x\n", in_le32(&(pcip->ptm1la)));
153 printk(" ptm2ms\t0x%x\n", in_le32(&(pcip->ptm2ms)));
154 printk(" ptm2la\t0x%x\n", in_le32(&(pcip->ptm2la)));
155
156 #endif
157
158 /* added for IBM boot rom version 1.15 bios bar changes -AK */
159
160 /* Disable region first */
161 out_le32((void *) &(pcip->pmm[0].ma), 0x00000000);
162 /* PLB starting addr, PCI: 0x80000000 */
163 out_le32((void *) &(pcip->pmm[0].la), 0x80000000);
164 /* PCI start addr, 0x80000000 */
165 out_le32((void *) &(pcip->pmm[0].pcila), PPC405_PCI_MEM_BASE);
166 /* 512MB range of PLB to PCI */
167 out_le32((void *) &(pcip->pmm[0].pciha), 0x00000000);
168 /* Enable no pre-fetch, enable region */
169 out_le32((void *) &(pcip->pmm[0].ma), ((0xffffffff -
170 (PPC405_PCI_UPPER_MEM -
171 PPC405_PCI_MEM_BASE)) | 0x01));
172
173 /* Disable region one */
174 out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
175 out_le32((void *) &(pcip->pmm[1].la), 0x00000000);
176 out_le32((void *) &(pcip->pmm[1].pcila), 0x00000000);
177 out_le32((void *) &(pcip->pmm[1].pciha), 0x00000000);
178 out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
179 out_le32((void *) &(pcip->ptm1ms), 0x00000001);
180
181 /* Disable region two */
182 out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
183 out_le32((void *) &(pcip->pmm[2].la), 0x00000000);
184 out_le32((void *) &(pcip->pmm[2].pcila), 0x00000000);
185 out_le32((void *) &(pcip->pmm[2].pciha), 0x00000000);
186 out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
187 out_le32((void *) &(pcip->ptm2ms), 0x00000000);
188 out_le32((void *) &(pcip->ptm2la), 0x00000000);
189
190 /* Zero config bars */
191 for (bar = PCI_BASE_ADDRESS_1; bar <= PCI_BASE_ADDRESS_2; bar += 4) {
192 early_write_config_dword(hose, hose->first_busno,
193 PCI_FUNC(hose->first_busno), bar,
194 0x00000000);
195 early_read_config_dword(hose, hose->first_busno,
196 PCI_FUNC(hose->first_busno), bar,
197 &bar_response);
198 DBG("BUS %d, device %d, Function %d bar 0x%8.8x is 0x%8.8x\n",
199 hose->first_busno, PCI_SLOT(hose->first_busno),
200 PCI_FUNC(hose->first_busno), bar, bar_response);
201 }
202 /* end workaround */
203
204 #ifdef DEBUG
205 printk("PCI bridge regs after fixup \n");
206 for (i = 0; i <= 3; i++) {
207 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].ma)));
208 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].la)));
209 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pcila)));
210 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pciha)));
211 }
212 printk(" ptm1ms\t0x%x\n", in_le32(&(pcip->ptm1ms)));
213 printk(" ptm1la\t0x%x\n", in_le32(&(pcip->ptm1la)));
214 printk(" ptm2ms\t0x%x\n", in_le32(&(pcip->ptm2ms)));
215 printk(" ptm2la\t0x%x\n", in_le32(&(pcip->ptm2la)));
216
217 #endif
218 #endif
219 }
220
221 static struct resource magicbox_flash_resource = {
222 .start = 0xffc00000,
223 .end = 0xffffffffULL,
224 .flags = IORESOURCE_MEM,
225 };
226
227 static struct mtd_partition magicbox_flash_parts[] = {
228 {
229 .name = "linux",
230 .offset = 0x0,
231 .size = 0x3c0000,
232 },
233 {
234 .name = "rootfs",
235 .offset = 0x100000,
236 .size = 0x2c0000,
237 }
238 };
239
240 static struct physmap_flash_data magicbox_flash_data = {
241 .width = 2,
242 .parts = magicbox_flash_parts,
243 .nr_parts = ARRAY_SIZE(magicbox_flash_parts),
244 };
245
246 static struct platform_device magicbox_flash_device = {
247 .name = "physmap-flash",
248 .id = 0,
249 .dev = {
250 .platform_data = &magicbox_flash_data,
251 },
252 .num_resources = 1,
253 .resource = &magicbox_flash_resource,
254 };
255
256 static int magicbox_setup_flash(void)
257 {
258 platform_device_register(&magicbox_flash_device);
259
260 return 0;
261 };
262
263 arch_initcall (magicbox_setup_flash);
264
265 void __init
266 magicbox_setup_arch(void)
267 {
268 ppc4xx_setup_arch();
269
270 ibm_ocp_set_emac(0, 1);
271
272 magicbox_early_serial_map();
273
274 /* Identify the system */
275 printk("MagicBox port (C) 2005 Karol Lewandowski <kl@jasmine.eu.org>\n");
276 }
277
278 void __init
279 magicbox_map_io(void)
280 {
281 ppc4xx_map_io();
282 }
283
284 void __init
285 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
286 unsigned long r6, unsigned long r7)
287 {
288 ppc4xx_init(r3, r4, r5, r6, r7);
289
290 ppc_md.setup_arch = magicbox_setup_arch;
291 ppc_md.setup_io_mappings = magicbox_map_io;
292
293 #ifdef CONFIG_KGDB
294 ppc_md.early_serial_map = bubinga_early_serial_map;
295 #endif
296 }
297
This page took 0.052125 seconds and 5 git commands to generate.