blob: 21d29132aebd97456c20f062724d9b827d701441 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/ppc/platforms/4xx/luan.c
3 *
4 * Luan board specific routines
5 *
6 * Matt Porter <mporter@kernel.crashing.org>
7 *
8 * Copyright 2004-2005 MontaVista Software Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 */
15
16#include <linux/config.h>
17#include <linux/stddef.h>
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/errno.h>
21#include <linux/reboot.h>
22#include <linux/pci.h>
23#include <linux/kdev_t.h>
24#include <linux/types.h>
25#include <linux/major.h>
26#include <linux/blkdev.h>
27#include <linux/console.h>
28#include <linux/delay.h>
29#include <linux/ide.h>
30#include <linux/initrd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/seq_file.h>
32#include <linux/root_dev.h>
33#include <linux/tty.h>
34#include <linux/serial.h>
35#include <linux/serial_core.h>
36
37#include <asm/system.h>
38#include <asm/pgtable.h>
39#include <asm/page.h>
40#include <asm/dma.h>
41#include <asm/io.h>
42#include <asm/machdep.h>
43#include <asm/ocp.h>
44#include <asm/pci-bridge.h>
45#include <asm/time.h>
46#include <asm/todc.h>
47#include <asm/bootinfo.h>
48#include <asm/ppc4xx_pic.h>
49#include <asm/ppcboot.h>
50
51#include <syslib/ibm44x_common.h>
52#include <syslib/ibm440gx_common.h>
53#include <syslib/ibm440sp_common.h>
54
Matt Porterd5f7b062005-10-28 17:46:14 -070055extern bd_t __res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57static struct ibm44x_clocks clocks __initdata;
58
59static void __init
60luan_calibrate_decr(void)
61{
62 unsigned int freq;
63
64 if (mfspr(SPRN_CCR1) & CCR1_TCS)
65 freq = LUAN_TMR_CLK;
66 else
67 freq = clocks.cpu;
68
69 ibm44x_calibrate_decr(freq);
70}
71
72static int
73luan_show_cpuinfo(struct seq_file *m)
74{
75 seq_printf(m, "vendor\t\t: IBM\n");
76 seq_printf(m, "machine\t\t: PPC440SP EVB (Luan)\n");
77
78 return 0;
79}
80
81static inline int
82luan_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
83{
84 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
85
86 /* PCIX0 in adapter mode, no host interrupt routing */
87
88 /* PCIX1 */
89 if (hose->index == 0) {
90 static char pci_irq_table[][4] =
91 /*
92 * PCI IDSEL/INTPIN->INTLINE
93 * A B C D
94 */
95 {
96 { 49, 49, 49, 49 }, /* IDSEL 1 - PCIX1 Slot 0 */
97 { 49, 49, 49, 49 }, /* IDSEL 2 - PCIX1 Slot 1 */
98 { 49, 49, 49, 49 }, /* IDSEL 3 - PCIX1 Slot 2 */
99 { 49, 49, 49, 49 }, /* IDSEL 4 - PCIX1 Slot 3 */
100 };
101 const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
102 return PCI_IRQ_TABLE_LOOKUP;
103 /* PCIX2 */
104 } else if (hose->index == 1) {
105 static char pci_irq_table[][4] =
106 /*
107 * PCI IDSEL/INTPIN->INTLINE
108 * A B C D
109 */
110 {
111 { 50, 50, 50, 50 }, /* IDSEL 1 - PCIX2 Slot 0 */
112 { 50, 50, 50, 50 }, /* IDSEL 2 - PCIX2 Slot 1 */
113 { 50, 50, 50, 50 }, /* IDSEL 3 - PCIX2 Slot 2 */
114 { 50, 50, 50, 50 }, /* IDSEL 4 - PCIX2 Slot 3 */
115 };
116 const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
117 return PCI_IRQ_TABLE_LOOKUP;
118 }
119 return -1;
120}
121
122static void __init luan_set_emacdata(void)
123{
124 struct ocp_def *def;
125 struct ocp_func_emac_data *emacdata;
126
127 /* Set phy_map, phy_mode, and mac_addr for the EMAC */
128 def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 0);
129 emacdata = def->additions;
130 emacdata->phy_map = 0x00000001; /* Skip 0x00 */
131 emacdata->phy_mode = PHY_MODE_GMII;
132 memcpy(emacdata->mac_addr, __res.bi_enetaddr, 6);
133}
134
135#define PCIX_READW(offset) \
136 (readw((void *)((u32)pcix_reg_base+offset)))
137
138#define PCIX_WRITEW(value, offset) \
139 (writew(value, (void *)((u32)pcix_reg_base+offset)))
140
141#define PCIX_WRITEL(value, offset) \
142 (writel(value, (void *)((u32)pcix_reg_base+offset)))
143
144static void __init
145luan_setup_pcix(void)
146{
147 int i;
148 void *pcix_reg_base;
149
150 for (i=0;i<3;i++) {
151 pcix_reg_base = ioremap64(PCIX0_REG_BASE + i*PCIX_REG_OFFSET, PCIX_REG_SIZE);
152
153 /* Enable PCIX0 I/O, Mem, and Busmaster cycles */
154 PCIX_WRITEW(PCIX_READW(PCIX0_COMMAND) | PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER, PCIX0_COMMAND);
155
156 /* Disable all windows */
157 PCIX_WRITEL(0, PCIX0_POM0SA);
158 PCIX_WRITEL(0, PCIX0_POM1SA);
159 PCIX_WRITEL(0, PCIX0_POM2SA);
160 PCIX_WRITEL(0, PCIX0_PIM0SA);
161 PCIX_WRITEL(0, PCIX0_PIM0SAH);
162 PCIX_WRITEL(0, PCIX0_PIM1SA);
163 PCIX_WRITEL(0, PCIX0_PIM2SA);
164 PCIX_WRITEL(0, PCIX0_PIM2SAH);
165
166 /*
167 * Setup 512MB PLB->PCI outbound mem window
168 * (a_n000_0000->0_n000_0000)
169 * */
170 PCIX_WRITEL(0x0000000a, PCIX0_POM0LAH);
171 PCIX_WRITEL(0x80000000 | i*LUAN_PCIX_MEM_SIZE, PCIX0_POM0LAL);
172 PCIX_WRITEL(0x00000000, PCIX0_POM0PCIAH);
173 PCIX_WRITEL(0x80000000 | i*LUAN_PCIX_MEM_SIZE, PCIX0_POM0PCIAL);
174 PCIX_WRITEL(0xe0000001, PCIX0_POM0SA);
175
176 /* Setup 2GB PCI->PLB inbound memory window at 0, enable MSIs */
177 PCIX_WRITEL(0x00000000, PCIX0_PIM0LAH);
178 PCIX_WRITEL(0x00000000, PCIX0_PIM0LAL);
179 PCIX_WRITEL(0xe0000007, PCIX0_PIM0SA);
180 PCIX_WRITEL(0xffffffff, PCIX0_PIM0SAH);
181
182 iounmap(pcix_reg_base);
183 }
184
185 eieio();
186}
187
188static void __init
189luan_setup_hose(struct pci_controller *hose,
190 int lower_mem,
191 int upper_mem,
192 int cfga,
193 int cfgd,
194 u64 pcix_io_base)
195{
196 char name[20];
197
198 sprintf(name, "PCIX%d host bridge", hose->index);
199
200 hose->pci_mem_offset = LUAN_PCIX_MEM_OFFSET;
201
202 pci_init_resource(&hose->io_resource,
203 LUAN_PCIX_LOWER_IO,
204 LUAN_PCIX_UPPER_IO,
205 IORESOURCE_IO,
206 name);
207
208 pci_init_resource(&hose->mem_resources[0],
209 lower_mem,
210 upper_mem,
211 IORESOURCE_MEM,
212 name);
213
214 hose->io_space.start = LUAN_PCIX_LOWER_IO;
215 hose->io_space.end = LUAN_PCIX_UPPER_IO;
216 hose->mem_space.start = lower_mem;
217 hose->mem_space.end = upper_mem;
Al Viro92a11f92005-04-25 07:55:57 -0700218 hose->io_base_virt = ioremap64(pcix_io_base, PCIX_IO_SIZE);
219 isa_io_base = (unsigned long) hose->io_base_virt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 setup_indirect_pci(hose, cfga, cfgd);
222 hose->set_cfg_type = 1;
223}
224
225static void __init
226luan_setup_hoses(void)
227{
228 struct pci_controller *hose1, *hose2;
229
230 /* Configure windows on the PCI-X host bridge */
231 luan_setup_pcix();
232
233 /* Allocate hoses for PCIX1 and PCIX2 */
234 hose1 = pcibios_alloc_controller();
235 hose2 = pcibios_alloc_controller();
236 if (!hose1 || !hose2)
237 return;
238
239 /* Setup PCIX1 */
240 hose1->first_busno = 0;
241 hose1->last_busno = 0xff;
242
243 luan_setup_hose(hose1,
244 LUAN_PCIX1_LOWER_MEM,
245 LUAN_PCIX1_UPPER_MEM,
246 PCIX1_CFGA,
247 PCIX1_CFGD,
248 PCIX1_IO_BASE);
249
250 hose1->last_busno = pciauto_bus_scan(hose1, hose1->first_busno);
251
252 /* Setup PCIX2 */
253 hose2->first_busno = hose1->last_busno + 1;
254 hose2->last_busno = 0xff;
255
256 luan_setup_hose(hose2,
257 LUAN_PCIX2_LOWER_MEM,
258 LUAN_PCIX2_UPPER_MEM,
259 PCIX2_CFGA,
260 PCIX2_CFGD,
261 PCIX2_IO_BASE);
262
263 hose2->last_busno = pciauto_bus_scan(hose2, hose2->first_busno);
264
265 ppc_md.pci_swizzle = common_swizzle;
266 ppc_md.pci_map_irq = luan_map_irq;
267}
268
269TODC_ALLOC();
270
271static void __init
272luan_early_serial_map(void)
273{
274 struct uart_port port;
275
276 /* Setup ioremapped serial port access */
277 memset(&port, 0, sizeof(port));
278 port.membase = ioremap64(PPC440SP_UART0_ADDR, 8);
279 port.irq = UART0_INT;
280 port.uartclk = clocks.uart0;
281 port.regshift = 0;
Russell King9b4a1612006-02-05 10:48:10 +0000282 port.iotype = UPIO_MEM;
Russell King59a675b2006-02-05 10:52:29 +0000283 port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 port.line = 0;
285
286 if (early_serial_setup(&port) != 0) {
287 printk("Early serial init of port 0 failed\n");
288 }
289
290 port.membase = ioremap64(PPC440SP_UART1_ADDR, 8);
291 port.irq = UART1_INT;
292 port.uartclk = clocks.uart1;
293 port.line = 1;
294
295 if (early_serial_setup(&port) != 0) {
296 printk("Early serial init of port 1 failed\n");
297 }
298
299 port.membase = ioremap64(PPC440SP_UART2_ADDR, 8);
300 port.irq = UART2_INT;
301 port.uartclk = BASE_BAUD;
302 port.line = 2;
303
304 if (early_serial_setup(&port) != 0) {
305 printk("Early serial init of port 2 failed\n");
306 }
307}
308
309static void __init
310luan_setup_arch(void)
311{
312 luan_set_emacdata();
313
314#if !defined(CONFIG_BDI_SWITCH)
315 /*
316 * The Abatron BDI JTAG debugger does not tolerate others
317 * mucking with the debug registers.
318 */
319 mtspr(SPRN_DBCR0, (DBCR0_TDE | DBCR0_IDM));
320#endif
321
322 /*
323 * Determine various clocks.
324 * To be completely correct we should get SysClk
325 * from FPGA, because it can be changed by on-board switches
326 * --ebs
327 */
328 /* 440GX and 440SP clocking is the same -mdp */
329 ibm440gx_get_clocks(&clocks, 33333333, 6 * 1843200);
330 ocp_sys_info.opb_bus_freq = clocks.opb;
331
332 /* init to some ~sane value until calibrate_delay() runs */
333 loops_per_jiffy = 50000000/HZ;
334
335 /* Setup PCIXn host bridges */
336 luan_setup_hoses();
337
338#ifdef CONFIG_BLK_DEV_INITRD
339 if (initrd_start)
340 ROOT_DEV = Root_RAM0;
341 else
342#endif
343#ifdef CONFIG_ROOT_NFS
344 ROOT_DEV = Root_NFS;
345#else
346 ROOT_DEV = Root_HDA1;
347#endif
348
349 luan_early_serial_map();
350
351 /* Identify the system */
352 printk("Luan port (MontaVista Software, Inc. <source@mvista.com>)\n");
353}
354
355void __init platform_init(unsigned long r3, unsigned long r4,
356 unsigned long r5, unsigned long r6, unsigned long r7)
357{
Matt Porterd5f7b062005-10-28 17:46:14 -0700358 ibm44x_platform_init(r3, r4, r5, r6, r7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 ppc_md.setup_arch = luan_setup_arch;
361 ppc_md.show_cpuinfo = luan_show_cpuinfo;
362 ppc_md.find_end_of_memory = ibm440sp_find_end_of_memory;
363 ppc_md.get_irq = NULL; /* Set in ppc4xx_pic_init() */
364
365 ppc_md.calibrate_decr = luan_calibrate_decr;
366#ifdef CONFIG_KGDB
367 ppc_md.early_serial_map = luan_early_serial_map;
368#endif
369}