Merge branch 'viro'
[pandora-kernel.git] / arch / ppc / platforms / 4xx / ebony.c
1 /*
2  * arch/ppc/platforms/4xx/ebony.c
3  *
4  * Ebony board specific routines
5  *
6  * Matt Porter <mporter@kernel.crashing.org>
7  * Copyright 2002-2005 MontaVista Software Inc.
8  *
9  * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
10  * Copyright (c) 2003-2005 Zultys Technologies
11  *
12  * This program is free software; you can redistribute  it and/or modify it
13  * under  the terms of  the GNU General  Public License as published by the
14  * Free Software Foundation;  either version 2 of the  License, or (at your
15  * option) any later version.
16  */
17
18 #include <linux/config.h>
19 #include <linux/stddef.h>
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/errno.h>
23 #include <linux/reboot.h>
24 #include <linux/pci.h>
25 #include <linux/kdev_t.h>
26 #include <linux/types.h>
27 #include <linux/major.h>
28 #include <linux/blkdev.h>
29 #include <linux/console.h>
30 #include <linux/delay.h>
31 #include <linux/ide.h>
32 #include <linux/initrd.h>
33 #include <linux/seq_file.h>
34 #include <linux/root_dev.h>
35 #include <linux/tty.h>
36 #include <linux/serial.h>
37 #include <linux/serial_core.h>
38
39 #include <asm/system.h>
40 #include <asm/pgtable.h>
41 #include <asm/page.h>
42 #include <asm/dma.h>
43 #include <asm/io.h>
44 #include <asm/machdep.h>
45 #include <asm/ocp.h>
46 #include <asm/pci-bridge.h>
47 #include <asm/time.h>
48 #include <asm/todc.h>
49 #include <asm/bootinfo.h>
50 #include <asm/ppc4xx_pic.h>
51 #include <asm/ppcboot.h>
52 #include <asm/tlbflush.h>
53
54 #include <syslib/gen550.h>
55 #include <syslib/ibm440gp_common.h>
56
57 extern bd_t __res;
58
59 static struct ibm44x_clocks clocks __initdata;
60
61 /*
62  * Ebony external IRQ triggering/polarity settings
63  */
64 unsigned char ppc4xx_uic_ext_irq_cfg[] __initdata = {
65         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ0: PCI slot 0 */
66         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ1: PCI slot 1 */
67         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ2: PCI slot 2 */
68         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ3: PCI slot 3 */
69         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* IRQ4: IRDA */
70         (IRQ_SENSE_EDGE  | IRQ_POLARITY_NEGATIVE),      /* IRQ5: SMI pushbutton */
71         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ6: PHYs */
72         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* IRQ7: AUX */
73         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ8: EXT */
74         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ9: EXT */
75         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ10: EXT */
76         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ11: EXT */
77         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* IRQ12: EXT */
78 };
79
80 static void __init
81 ebony_calibrate_decr(void)
82 {
83         unsigned int freq;
84
85         /*
86          * Determine system clock speed
87          *
88          * If we are on Rev. B silicon, then use
89          * default external system clock.  If we are
90          * on Rev. C silicon then errata forces us to
91          * use the internal clock.
92          */
93         if (strcmp(cur_cpu_spec->cpu_name, "440GP Rev. B") == 0)
94                 freq = EBONY_440GP_RB_SYSCLK;
95         else
96                 freq = EBONY_440GP_RC_SYSCLK;
97
98         ibm44x_calibrate_decr(freq);
99 }
100
101 static int
102 ebony_show_cpuinfo(struct seq_file *m)
103 {
104         seq_printf(m, "vendor\t\t: IBM\n");
105         seq_printf(m, "machine\t\t: Ebony\n");
106
107         return 0;
108 }
109
110 static inline int
111 ebony_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
112 {
113         static char pci_irq_table[][4] =
114         /*
115          *      PCI IDSEL/INTPIN->INTLINE
116          *         A   B   C   D
117          */
118         {
119                 { 23, 23, 23, 23 },     /* IDSEL 1 - PCI Slot 0 */
120                 { 24, 24, 24, 24 },     /* IDSEL 2 - PCI Slot 1 */
121                 { 25, 25, 25, 25 },     /* IDSEL 3 - PCI Slot 2 */
122                 { 26, 26, 26, 26 },     /* IDSEL 4 - PCI Slot 3 */
123         };
124
125         const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
126         return PCI_IRQ_TABLE_LOOKUP;
127 }
128
129 #define PCIX_WRITEL(value, offset) \
130         (writel(value, pcix_reg_base + offset))
131
132 /*
133  * FIXME: This is only here to "make it work".  This will move
134  * to a ibm_pcix.c which will contain a generic IBM PCIX bridge
135  * configuration library. -Matt
136  */
137 static void __init
138 ebony_setup_pcix(void)
139 {
140         void __iomem *pcix_reg_base;
141
142         pcix_reg_base = ioremap64(PCIX0_REG_BASE, PCIX_REG_SIZE);
143
144         /* Disable all windows */
145         PCIX_WRITEL(0, PCIX0_POM0SA);
146         PCIX_WRITEL(0, PCIX0_POM1SA);
147         PCIX_WRITEL(0, PCIX0_POM2SA);
148         PCIX_WRITEL(0, PCIX0_PIM0SA);
149         PCIX_WRITEL(0, PCIX0_PIM1SA);
150         PCIX_WRITEL(0, PCIX0_PIM2SA);
151
152         /* Setup 2GB PLB->PCI outbound mem window (3_8000_0000->0_8000_0000) */
153         PCIX_WRITEL(0x00000003, PCIX0_POM0LAH);
154         PCIX_WRITEL(0x80000000, PCIX0_POM0LAL);
155         PCIX_WRITEL(0x00000000, PCIX0_POM0PCIAH);
156         PCIX_WRITEL(0x80000000, PCIX0_POM0PCIAL);
157         PCIX_WRITEL(0x80000001, PCIX0_POM0SA);
158
159         /* Setup 2GB PCI->PLB inbound memory window at 0, enable MSIs */
160         PCIX_WRITEL(0x00000000, PCIX0_PIM0LAH);
161         PCIX_WRITEL(0x00000000, PCIX0_PIM0LAL);
162         PCIX_WRITEL(0x80000007, PCIX0_PIM0SA);
163
164         eieio();
165 }
166
167 static void __init
168 ebony_setup_hose(void)
169 {
170         struct pci_controller *hose;
171
172         /* Configure windows on the PCI-X host bridge */
173         ebony_setup_pcix();
174
175         hose = pcibios_alloc_controller();
176
177         if (!hose)
178                 return;
179
180         hose->first_busno = 0;
181         hose->last_busno = 0xff;
182
183         hose->pci_mem_offset = EBONY_PCI_MEM_OFFSET;
184
185         pci_init_resource(&hose->io_resource,
186                         EBONY_PCI_LOWER_IO,
187                         EBONY_PCI_UPPER_IO,
188                         IORESOURCE_IO,
189                         "PCI host bridge");
190
191         pci_init_resource(&hose->mem_resources[0],
192                         EBONY_PCI_LOWER_MEM,
193                         EBONY_PCI_UPPER_MEM,
194                         IORESOURCE_MEM,
195                         "PCI host bridge");
196
197         hose->io_space.start = EBONY_PCI_LOWER_IO;
198         hose->io_space.end = EBONY_PCI_UPPER_IO;
199         hose->mem_space.start = EBONY_PCI_LOWER_MEM;
200         hose->mem_space.end = EBONY_PCI_UPPER_MEM;
201         hose->io_base_virt = ioremap64(EBONY_PCI_IO_BASE, EBONY_PCI_IO_SIZE);
202         isa_io_base = (unsigned long)hose->io_base_virt;
203
204         setup_indirect_pci(hose,
205                         EBONY_PCI_CFGA_PLB32,
206                         EBONY_PCI_CFGD_PLB32);
207         hose->set_cfg_type = 1;
208
209         hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
210
211         ppc_md.pci_swizzle = common_swizzle;
212         ppc_md.pci_map_irq = ebony_map_irq;
213 }
214
215 TODC_ALLOC();
216
217 static void __init
218 ebony_early_serial_map(void)
219 {
220         struct uart_port port;
221
222         /* Setup ioremapped serial port access */
223         memset(&port, 0, sizeof(port));
224         port.membase = ioremap64(PPC440GP_UART0_ADDR, 8);
225         port.irq = 0;
226         port.uartclk = clocks.uart0;
227         port.regshift = 0;
228         port.iotype = UPIO_MEM;
229         port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
230         port.line = 0;
231
232         if (early_serial_setup(&port) != 0) {
233                 printk("Early serial init of port 0 failed\n");
234         }
235
236 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
237         /* Configure debug serial access */
238         gen550_init(0, &port);
239
240         /* Purge TLB entry added in head_44x.S for early serial access */
241         _tlbie(UART0_IO_BASE);
242 #endif
243
244         port.membase = ioremap64(PPC440GP_UART1_ADDR, 8);
245         port.irq = 1;
246         port.uartclk = clocks.uart1;
247         port.line = 1;
248
249         if (early_serial_setup(&port) != 0) {
250                 printk("Early serial init of port 1 failed\n");
251         }
252
253 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
254         /* Configure debug serial access */
255         gen550_init(1, &port);
256 #endif
257 }
258
259 static void __init
260 ebony_setup_arch(void)
261 {
262         struct ocp_def *def;
263         struct ocp_func_emac_data *emacdata;
264
265         /* Set mac_addr for each EMAC */
266         def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 0);
267         emacdata = def->additions;
268         emacdata->phy_map = 0x00000001; /* Skip 0x00 */
269         emacdata->phy_mode = PHY_MODE_RMII;
270         memcpy(emacdata->mac_addr, __res.bi_enetaddr, 6);
271
272         def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 1);
273         emacdata = def->additions;
274         emacdata->phy_map = 0x00000001; /* Skip 0x00 */
275         emacdata->phy_mode = PHY_MODE_RMII;
276         memcpy(emacdata->mac_addr, __res.bi_enet1addr, 6);
277
278         /*
279          * Determine various clocks.
280          * To be completely correct we should get SysClk
281          * from FPGA, because it can be changed by on-board switches
282          * --ebs
283          */
284         ibm440gp_get_clocks(&clocks, 33333333, 6 * 1843200);
285         ocp_sys_info.opb_bus_freq = clocks.opb;
286
287         /* Setup TODC access */
288         TODC_INIT(TODC_TYPE_DS1743,
289                         0,
290                         0,
291                         ioremap64(EBONY_RTC_ADDR, EBONY_RTC_SIZE),
292                         8);
293
294         /* init to some ~sane value until calibrate_delay() runs */
295         loops_per_jiffy = 50000000/HZ;
296
297         /* Setup PCI host bridge */
298         ebony_setup_hose();
299
300 #ifdef CONFIG_BLK_DEV_INITRD
301         if (initrd_start)
302                 ROOT_DEV = Root_RAM0;
303         else
304 #endif
305 #ifdef CONFIG_ROOT_NFS
306                 ROOT_DEV = Root_NFS;
307 #else
308                 ROOT_DEV = Root_HDA1;
309 #endif
310
311         ebony_early_serial_map();
312
313         /* Identify the system */
314         printk("IBM Ebony port (MontaVista Software, Inc. (source@mvista.com))\n");
315 }
316
317 void __init platform_init(unsigned long r3, unsigned long r4,
318                 unsigned long r5, unsigned long r6, unsigned long r7)
319 {
320         ibm44x_platform_init(r3, r4, r5, r6, r7);
321
322         ppc_md.setup_arch = ebony_setup_arch;
323         ppc_md.show_cpuinfo = ebony_show_cpuinfo;
324         ppc_md.get_irq = NULL;          /* Set in ppc4xx_pic_init() */
325
326         ppc_md.calibrate_decr = ebony_calibrate_decr;
327         ppc_md.time_init = todc_time_init;
328         ppc_md.set_rtc_time = todc_set_rtc_time;
329         ppc_md.get_rtc_time = todc_get_rtc_time;
330
331         ppc_md.nvram_read_val = todc_direct_read_val;
332         ppc_md.nvram_write_val = todc_direct_write_val;
333 #ifdef CONFIG_KGDB
334         ppc_md.early_serial_map = ebony_early_serial_map;
335 #endif
336 }
337