]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/ppc/platforms/4xx/ocotea.c
Merge master.kernel.org:/home/rmk/linux-2.6-arm
[linux-2.6-omap-h63xx.git] / arch / ppc / platforms / 4xx / ocotea.c
1 /*
2  * arch/ppc/platforms/4xx/ocotea.c
3  *
4  * Ocotea board specific routines
5  *
6  * Matt Porter <mporter@kernel.crashing.org>
7  *
8  * Copyright 2003-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>
31 #include <linux/irq.h>
32 #include <linux/seq_file.h>
33 #include <linux/root_dev.h>
34 #include <linux/tty.h>
35 #include <linux/serial.h>
36 #include <linux/serial_core.h>
37
38 #include <asm/system.h>
39 #include <asm/pgtable.h>
40 #include <asm/page.h>
41 #include <asm/dma.h>
42 #include <asm/io.h>
43 #include <asm/machdep.h>
44 #include <asm/ocp.h>
45 #include <asm/pci-bridge.h>
46 #include <asm/time.h>
47 #include <asm/todc.h>
48 #include <asm/bootinfo.h>
49 #include <asm/ppc4xx_pic.h>
50 #include <asm/ppcboot.h>
51 #include <asm/tlbflush.h>
52
53 #include <syslib/gen550.h>
54 #include <syslib/ibm440gx_common.h>
55
56 bd_t __res;
57
58 static struct ibm44x_clocks clocks __initdata;
59
60 static void __init
61 ocotea_calibrate_decr(void)
62 {
63         unsigned int freq;
64
65         if (mfspr(SPRN_CCR1) & CCR1_TCS)
66                 freq = OCOTEA_TMR_CLK;
67         else
68                 freq = clocks.cpu;
69
70         ibm44x_calibrate_decr(freq);
71 }
72
73 static int
74 ocotea_show_cpuinfo(struct seq_file *m)
75 {
76         seq_printf(m, "vendor\t\t: IBM\n");
77         seq_printf(m, "machine\t\t: PPC440GX EVB (Ocotea)\n");
78         ibm440gx_show_cpuinfo(m);
79         return 0;
80 }
81
82 static inline int
83 ocotea_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
84 {
85         static char pci_irq_table[][4] =
86         /*
87          *      PCI IDSEL/INTPIN->INTLINE
88          *         A   B   C   D
89          */
90         {
91                 { 23, 23, 23, 23 },     /* IDSEL 1 - PCI Slot 0 */
92                 { 24, 24, 24, 24 },     /* IDSEL 2 - PCI Slot 1 */
93                 { 25, 25, 25, 25 },     /* IDSEL 3 - PCI Slot 2 */
94                 { 26, 26, 26, 26 },     /* IDSEL 4 - PCI Slot 3 */
95         };
96
97         const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
98         return PCI_IRQ_TABLE_LOOKUP;
99 }
100
101 static void __init ocotea_set_emacdata(void)
102 {
103         struct ocp_def *def;
104         struct ocp_func_emac_data *emacdata;
105         int i;
106
107         /*
108          * Note: Current rev. board only operates in Group 4a
109          * mode, so we always set EMAC0-1 for SMII and EMAC2-3
110          * for RGMII (though these could run in RTBI just the same).
111          *
112          * The FPGA reg 3 information isn't even suitable for
113          * determining the phy_mode, so if the board becomes
114          * usable in !4a, it will be necessary to parse an environment
115          * variable from the firmware or similar to properly configure
116          * the phy_map/phy_mode.
117          */
118         /* Set phy_map, phy_mode, and mac_addr for each EMAC */
119         for (i=0; i<4; i++) {
120                 def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, i);
121                 emacdata = def->additions;
122                 if (i < 2) {
123                         emacdata->phy_map = 0x00000001; /* Skip 0x00 */
124                         emacdata->phy_mode = PHY_MODE_SMII;
125                 }
126                 else {
127                         emacdata->phy_map = 0x0000ffff; /* Skip 0x00-0x0f */
128                         emacdata->phy_mode = PHY_MODE_RGMII;
129                 }
130                 if (i == 0)
131                         memcpy(emacdata->mac_addr, __res.bi_enetaddr, 6);
132                 else if (i == 1)
133                         memcpy(emacdata->mac_addr, __res.bi_enet1addr, 6);
134                 else if (i == 2)
135                         memcpy(emacdata->mac_addr, __res.bi_enet2addr, 6);
136                 else if (i == 3)
137                         memcpy(emacdata->mac_addr, __res.bi_enet3addr, 6);
138         }
139 }
140
141 #define PCIX_READW(offset) \
142         (readw(pcix_reg_base+offset))
143
144 #define PCIX_WRITEW(value, offset) \
145         (writew(value, pcix_reg_base+offset))
146
147 #define PCIX_WRITEL(value, offset) \
148         (writel(value, pcix_reg_base+offset))
149
150 /*
151  * FIXME: This is only here to "make it work".  This will move
152  * to a ibm_pcix.c which will contain a generic IBM PCIX bridge
153  * configuration library. -Matt
154  */
155 static void __init
156 ocotea_setup_pcix(void)
157 {
158         void *pcix_reg_base;
159
160         pcix_reg_base = ioremap64(PCIX0_REG_BASE, PCIX_REG_SIZE);
161
162         /* Enable PCIX0 I/O, Mem, and Busmaster cycles */
163         PCIX_WRITEW(PCIX_READW(PCIX0_COMMAND) | PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER, PCIX0_COMMAND);
164
165         /* Disable all windows */
166         PCIX_WRITEL(0, PCIX0_POM0SA);
167         PCIX_WRITEL(0, PCIX0_POM1SA);
168         PCIX_WRITEL(0, PCIX0_POM2SA);
169         PCIX_WRITEL(0, PCIX0_PIM0SA);
170         PCIX_WRITEL(0, PCIX0_PIM0SAH);
171         PCIX_WRITEL(0, PCIX0_PIM1SA);
172         PCIX_WRITEL(0, PCIX0_PIM2SA);
173         PCIX_WRITEL(0, PCIX0_PIM2SAH);
174
175         /* Setup 2GB PLB->PCI outbound mem window (3_8000_0000->0_8000_0000) */
176         PCIX_WRITEL(0x00000003, PCIX0_POM0LAH);
177         PCIX_WRITEL(0x80000000, PCIX0_POM0LAL);
178         PCIX_WRITEL(0x00000000, PCIX0_POM0PCIAH);
179         PCIX_WRITEL(0x80000000, PCIX0_POM0PCIAL);
180         PCIX_WRITEL(0x80000001, PCIX0_POM0SA);
181
182         /* Setup 2GB PCI->PLB inbound memory window at 0, enable MSIs */
183         PCIX_WRITEL(0x00000000, PCIX0_PIM0LAH);
184         PCIX_WRITEL(0x00000000, PCIX0_PIM0LAL);
185         PCIX_WRITEL(0xe0000007, PCIX0_PIM0SA);
186
187         eieio();
188 }
189
190 static void __init
191 ocotea_setup_hose(void)
192 {
193         struct pci_controller *hose;
194
195         /* Configure windows on the PCI-X host bridge */
196         ocotea_setup_pcix();
197
198         hose = pcibios_alloc_controller();
199
200         if (!hose)
201                 return;
202
203         hose->first_busno = 0;
204         hose->last_busno = 0xff;
205
206         hose->pci_mem_offset = OCOTEA_PCI_MEM_OFFSET;
207
208         pci_init_resource(&hose->io_resource,
209                         OCOTEA_PCI_LOWER_IO,
210                         OCOTEA_PCI_UPPER_IO,
211                         IORESOURCE_IO,
212                         "PCI host bridge");
213
214         pci_init_resource(&hose->mem_resources[0],
215                         OCOTEA_PCI_LOWER_MEM,
216                         OCOTEA_PCI_UPPER_MEM,
217                         IORESOURCE_MEM,
218                         "PCI host bridge");
219
220         hose->io_space.start = OCOTEA_PCI_LOWER_IO;
221         hose->io_space.end = OCOTEA_PCI_UPPER_IO;
222         hose->mem_space.start = OCOTEA_PCI_LOWER_MEM;
223         hose->mem_space.end = OCOTEA_PCI_UPPER_MEM;
224         hose->io_base_virt = ioremap64(OCOTEA_PCI_IO_BASE, OCOTEA_PCI_IO_SIZE);
225         isa_io_base = (unsigned long) hose->io_base_virt;
226
227         setup_indirect_pci(hose,
228                         OCOTEA_PCI_CFGA_PLB32,
229                         OCOTEA_PCI_CFGD_PLB32);
230         hose->set_cfg_type = 1;
231
232         hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
233
234         ppc_md.pci_swizzle = common_swizzle;
235         ppc_md.pci_map_irq = ocotea_map_irq;
236 }
237
238
239 TODC_ALLOC();
240
241 static void __init
242 ocotea_early_serial_map(void)
243 {
244         struct uart_port port;
245
246         /* Setup ioremapped serial port access */
247         memset(&port, 0, sizeof(port));
248         port.membase = ioremap64(PPC440GX_UART0_ADDR, 8);
249         port.irq = UART0_INT;
250         port.uartclk = clocks.uart0;
251         port.regshift = 0;
252         port.iotype = SERIAL_IO_MEM;
253         port.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
254         port.line = 0;
255
256         if (early_serial_setup(&port) != 0) {
257                 printk("Early serial init of port 0 failed\n");
258         }
259
260 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
261         /* Configure debug serial access */
262         gen550_init(0, &port);
263
264         /* Purge TLB entry added in head_44x.S for early serial access */
265         _tlbie(UART0_IO_BASE);
266 #endif
267
268         port.membase = ioremap64(PPC440GX_UART1_ADDR, 8);
269         port.irq = UART1_INT;
270         port.uartclk = clocks.uart1;
271         port.line = 1;
272
273         if (early_serial_setup(&port) != 0) {
274                 printk("Early serial init of port 1 failed\n");
275         }
276
277 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
278         /* Configure debug serial access */
279         gen550_init(1, &port);
280 #endif
281 }
282
283 static void __init
284 ocotea_setup_arch(void)
285 {
286         ocotea_set_emacdata();
287
288         ibm440gx_tah_enable();
289
290         /* Setup TODC access */
291         TODC_INIT(TODC_TYPE_DS1743,
292                         0,
293                         0,
294                         ioremap64(OCOTEA_RTC_ADDR, OCOTEA_RTC_SIZE),
295                         8);
296
297         /* init to some ~sane value until calibrate_delay() runs */
298         loops_per_jiffy = 50000000/HZ;
299
300         /* Setup PCI host bridge */
301         ocotea_setup_hose();
302
303 #ifdef CONFIG_BLK_DEV_INITRD
304         if (initrd_start)
305                 ROOT_DEV = Root_RAM0;
306         else
307 #endif
308 #ifdef CONFIG_ROOT_NFS
309                 ROOT_DEV = Root_NFS;
310 #else
311                 ROOT_DEV = Root_HDA1;
312 #endif
313
314         ocotea_early_serial_map();
315
316         /* Identify the system */
317         printk("IBM Ocotea port (MontaVista Software, Inc. <source@mvista.com>)\n");
318 }
319
320 static void __init ocotea_init(void)
321 {
322         ibm440gx_l2c_setup(&clocks);
323 }
324
325 void __init platform_init(unsigned long r3, unsigned long r4,
326                 unsigned long r5, unsigned long r6, unsigned long r7)
327 {
328         parse_bootinfo(find_bootinfo());
329
330         /*
331          * If we were passed in a board information, copy it into the
332          * residual data area.
333          */
334         if (r3)
335                 __res = *(bd_t *)(r3 + KERNELBASE);
336
337         /*
338          * Determine various clocks.
339          * To be completely correct we should get SysClk
340          * from FPGA, because it can be changed by on-board switches
341          * --ebs
342          */
343         ibm440gx_get_clocks(&clocks, 33333333, 6 * 1843200);
344         ocp_sys_info.opb_bus_freq = clocks.opb;
345
346         ibm44x_platform_init();
347
348         ppc_md.setup_arch = ocotea_setup_arch;
349         ppc_md.show_cpuinfo = ocotea_show_cpuinfo;
350         ppc_md.get_irq = NULL;          /* Set in ppc4xx_pic_init() */
351
352         ppc_md.calibrate_decr = ocotea_calibrate_decr;
353         ppc_md.time_init = todc_time_init;
354         ppc_md.set_rtc_time = todc_set_rtc_time;
355         ppc_md.get_rtc_time = todc_get_rtc_time;
356
357         ppc_md.nvram_read_val = todc_direct_read_val;
358         ppc_md.nvram_write_val = todc_direct_write_val;
359 #ifdef CONFIG_KGDB
360         ppc_md.early_serial_map = ocotea_early_serial_map;
361 #endif
362         ppc_md.init = ocotea_init;
363 }