2 * Support for IBM PPC 405EP-based MagicBox board
3 * Copyright (C) 2006 Karol Lewandowski
5 * Heavily based on bubinga.c
7 * Author: SAW (IBM), derived from walnut.c.
8 * Maintained by MontaVista Software <source@mvista.com>
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
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>
30 #include <asm/system.h>
31 #include <asm/pci-bridge.h>
32 #include <asm/processor.h>
33 #include <asm/machdep.h>
39 #include <asm/ibm_ocp_pci.h>
41 #include <platforms/4xx/ibm405ep.h>
46 #define DBG(x...) printk(x)
53 /* Some IRQs unique to the board
54 * Used by the generic 405 PCI setup functions in ppc4xx_pci.c
57 ppc405_map_irq(struct pci_dev
*dev
, unsigned char idsel
, unsigned char pin
)
59 static char pci_irq_table
[][4] =
61 * PCI IDSEL/INTPIN->INTLINE
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 */
71 const long min_idsel
= 1, max_idsel
= 4, irqs_per_slot
= 4;
72 return PCI_IRQ_TABLE_LOOKUP
;
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.
80 magicbox_early_serial_map(void)
84 struct uart_port port
;
86 /* Calculate the serial clock input frequency
88 * The base baud is the PLL OUTA (provided in the board info
89 * structure) divided by the external UART Divisor, divided
92 uart_div
= (mfdcr(DCRN_CPC0_UCR_BASE
) & DCRN_CPC0_UCR_U0DIV
);
93 uart_clock
= __res
.bi_procfreq
/ uart_div
;
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
;
101 port
.iotype
= UPIO_MEM
;
102 port
.flags
= UPF_BOOT_AUTOCONF
| UPF_SKIP_TEST
;
105 if (early_serial_setup(&port
) != 0) {
106 printk("Early serial init of port 0 failed\n");
109 port
.membase
= (void*)ACTING_UART1_IO_BASE
;
110 port
.irq
= ACTING_UART1_INT
;
113 if (early_serial_setup(&port
) != 0) {
114 printk("Early serial init of port 1 failed\n");
119 bios_fixup(struct pci_controller
*hose
, struct pcil0_regs
*pcip
)
123 unsigned int bar_response
, bar
;
125 * Expected PCI mapping:
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
132 * PLB addr PCI io addr
133 * --------------------- ---------------------
134 * e800'0000 - e800'ffff ---> 0000'0000 - 0001'0000
136 * The following code is simplified by assuming that the bootrom
137 * has been well behaved in following this mapping.
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
)));
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
)));
158 /* added for IBM boot rom version 1.15 bios bar changes -AK */
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));
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);
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);
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
,
195 early_read_config_dword(hose
, hose
->first_busno
,
196 PCI_FUNC(hose
->first_busno
), bar
,
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
);
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
)));
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
)));
221 static struct resource magicbox_flash_resource
= {
223 .end
= 0xffffffffULL
,
224 .flags
= IORESOURCE_MEM
,
227 static struct mtd_partition magicbox_flash_parts
[] = {
240 static struct physmap_flash_data magicbox_flash_data
= {
242 .parts
= magicbox_flash_parts
,
243 .nr_parts
= ARRAY_SIZE(magicbox_flash_parts
),
246 static struct platform_device magicbox_flash_device
= {
247 .name
= "physmap-flash",
250 .platform_data
= &magicbox_flash_data
,
253 .resource
= &magicbox_flash_resource
,
256 static int magicbox_setup_flash(void)
258 platform_device_register(&magicbox_flash_device
);
263 arch_initcall (magicbox_setup_flash
);
266 magicbox_setup_arch(void)
270 ibm_ocp_set_emac(0, 1);
272 magicbox_early_serial_map();
274 /* Identify the system */
275 printk("MagicBox port (C) 2005 Karol Lewandowski <kl@jasmine.eu.org>\n");
279 magicbox_map_io(void)
285 platform_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
286 unsigned long r6
, unsigned long r7
)
288 ppc4xx_init(r3
, r4
, r5
, r6
, r7
);
290 ppc_md
.setup_arch
= magicbox_setup_arch
;
291 ppc_md
.setup_io_mappings
= magicbox_map_io
;
294 ppc_md
.early_serial_map
= bubinga_early_serial_map
;