patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / arch / ppc / platforms / 4xx / ocotea.c
1 /*
2  * arch/ppc/platforms/ocotea.c
3  *
4  * Ocotea board specific routines
5  *
6  * Matt Porter <mporter@mvista.com>
7  *
8  * Copyright 2003 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
51 #include <syslib/ibm440gx_common.h>
52
53 /*
54  * This is a horrible kludge, we eventually need to abstract this
55  * generic PHY stuff, so the  standard phy mode defines can be
56  * easily used from arch code.
57  */
58 #include "../../../../drivers/net/ibm_emac/ibm_emac_phy.h"
59
60 extern void abort(void);
61
62 static void __init
63 ocotea_calibrate_decr(void)
64 {
65         unsigned int freq;
66
67         freq = OCOTEA_SYSCLK;
68
69         tb_ticks_per_jiffy = freq / HZ;
70         tb_to_us = mulhwu_scale_factor(freq, 1000000);
71
72         /* Set the time base to zero */
73         mtspr(SPRN_TBWL, 0);
74         mtspr(SPRN_TBWU, 0);
75
76         /* Clear any pending timer interrupts */
77         mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
78
79         /* Enable decrementer interrupt */
80         mtspr(SPRN_TCR, TCR_DIE);
81 }
82
83 static int
84 ocotea_show_cpuinfo(struct seq_file *m)
85 {
86         seq_printf(m, "vendor\t\t: IBM\n");
87         seq_printf(m, "machine\t\t: PPC440GX EVB (Ocotea)\n");
88
89         return 0;
90 }
91 static inline int
92 ocotea_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
93 {
94         static char pci_irq_table[][4] =
95         /*
96          *      PCI IDSEL/INTPIN->INTLINE
97          *         A   B   C   D
98          */
99         {
100                 { 23, 23, 23, 23 },     /* IDSEL 1 - PCI Slot 0 */
101                 { 24, 24, 24, 24 },     /* IDSEL 2 - PCI Slot 1 */
102                 { 25, 25, 25, 25 },     /* IDSEL 3 - PCI Slot 2 */
103                 { 26, 26, 26, 26 },     /* IDSEL 4 - PCI Slot 3 */
104         };
105
106         const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
107         return PCI_IRQ_TABLE_LOOKUP;
108 }
109
110 #define PCIX_READW(offset) \
111         (readw((u32)pcix_reg_base+offset))
112
113 #define PCIX_WRITEW(value, offset) \
114         (writew(value, (u32)pcix_reg_base+offset))
115
116 #define PCIX_WRITEL(value, offset) \
117         (writel(value, (u32)pcix_reg_base+offset))
118
119 /*
120  * FIXME: This is only here to "make it work".  This will move
121  * to a ibm_pcix.c which will contain a generic IBM PCIX bridge
122  * configuration library. -Matt
123  */
124 static void __init
125 ocotea_setup_pcix(void)
126 {
127         void *pcix_reg_base;
128
129         pcix_reg_base = ioremap64(PCIX0_REG_BASE, PCIX0_REG_SIZE);
130
131         /* Enable PCIX0 I/O, Mem, and Busmaster cycles */
132         PCIX_WRITEW(PCIX_READW(PCIX0_COMMAND) | PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER, PCIX0_COMMAND);
133
134         /* Disable all windows */
135         PCIX_WRITEL(0, PCIX0_POM0SA);
136         PCIX_WRITEL(0, PCIX0_POM1SA);
137         PCIX_WRITEL(0, PCIX0_POM2SA);
138         PCIX_WRITEL(0, PCIX0_PIM0SA);
139         PCIX_WRITEL(0, PCIX0_PIM0SAH);
140         PCIX_WRITEL(0, PCIX0_PIM1SA);
141         PCIX_WRITEL(0, PCIX0_PIM2SA);
142         PCIX_WRITEL(0, PCIX0_PIM2SAH);
143
144         /* Setup 2GB PLB->PCI outbound mem window (3_8000_0000->0_8000_0000) */
145         PCIX_WRITEL(0x00000003, PCIX0_POM0LAH);
146         PCIX_WRITEL(0x80000000, PCIX0_POM0LAL);
147         PCIX_WRITEL(0x00000000, PCIX0_POM0PCIAH);
148         PCIX_WRITEL(0x80000000, PCIX0_POM0PCIAL);
149         PCIX_WRITEL(0x80000001, PCIX0_POM0SA);
150
151         /* Setup 2GB PCI->PLB inbound memory window at 0, enable MSIs */
152         PCIX_WRITEL(0x00000000, PCIX0_PIM0LAH);
153         PCIX_WRITEL(0x00000000, PCIX0_PIM0LAL);
154         PCIX_WRITEL(0xe0000007, PCIX0_PIM0SA);
155
156         eieio();
157 }
158
159 static void __init
160 ocotea_setup_hose(void)
161 {
162         struct pci_controller *hose;
163
164         /* Configure windows on the PCI-X host bridge */
165         ocotea_setup_pcix();
166
167         hose = pcibios_alloc_controller();
168
169         if (!hose)
170                 return;
171
172         hose->first_busno = 0;
173         hose->last_busno = 0xff;
174
175         hose->pci_mem_offset = OCOTEA_PCI_MEM_OFFSET;
176
177         pci_init_resource(&hose->io_resource,
178                         OCOTEA_PCI_LOWER_IO,
179                         OCOTEA_PCI_UPPER_IO,
180                         IORESOURCE_IO,
181                         "PCI host bridge");
182
183         pci_init_resource(&hose->mem_resources[0],
184                         OCOTEA_PCI_LOWER_MEM,
185                         OCOTEA_PCI_UPPER_MEM,
186                         IORESOURCE_MEM,
187                         "PCI host bridge");
188
189         hose->io_space.start = OCOTEA_PCI_LOWER_IO;
190         hose->io_space.end = OCOTEA_PCI_UPPER_IO;
191         hose->mem_space.start = OCOTEA_PCI_LOWER_MEM;
192         hose->mem_space.end = OCOTEA_PCI_UPPER_MEM;
193         isa_io_base =
194                 (unsigned long)ioremap64(OCOTEA_PCI_IO_BASE, OCOTEA_PCI_IO_SIZE);
195         hose->io_base_virt = (void *)isa_io_base;
196
197         setup_indirect_pci(hose,
198                         OCOTEA_PCI_CFGA_PLB32,
199                         OCOTEA_PCI_CFGD_PLB32);
200         hose->set_cfg_type = 1;
201
202         hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
203
204         ppc_md.pci_swizzle = common_swizzle;
205         ppc_md.pci_map_irq = ocotea_map_irq;
206 }
207
208
209 TODC_ALLOC();
210
211 static void __init
212 ocotea_early_serial_map(const struct ibm44x_clocks *clks)
213 {
214         struct uart_port port;
215
216         /* Setup ioremapped serial port access */
217         memset(&port, 0, sizeof(port));
218         port.membase = ioremap64(PPC440GX_UART0_ADDR, 8);
219         port.irq = UART0_INT;
220         port.uartclk = clks->uart0;
221         port.regshift = 0;
222         port.iotype = SERIAL_IO_MEM;
223         port.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
224         port.line = 0;
225
226         if (early_serial_setup(&port) != 0) {
227                 printk("Early serial init of port 0 failed\n");
228         }
229
230         port.membase = ioremap64(PPC440GX_UART1_ADDR, 8);
231         port.irq = UART1_INT;
232         port.uartclk = clks->uart1;
233         port.line = 1;
234
235         if (early_serial_setup(&port) != 0) {
236                 printk("Early serial init of port 1 failed\n");
237         }
238 }
239
240 static void __init
241 ocotea_setup_arch(void)
242 {
243         unsigned char *addr;
244         unsigned long long mac64;
245         struct ocp_def *def;
246         struct ocp_func_emac_data *emacdata;
247         int i;
248         struct ibm44x_clocks clocks;
249
250         /*
251          * Note: Current rev. board only operates in Group 4a
252          * mode, so we always set EMAC0-1 for SMII and EMAC2-3
253          * for RGMII (though these could run in RTBI just the same).
254          *
255          * The FPGA reg 3 information isn't even suitable for
256          * determining the phy_mode, so if the board becomes
257          * usable in !4a, it will be necessary to parse an environment
258          * variable from the firmware or similar to properly configure
259          * the phy_map/phy_mode.
260          */
261         /* Set phy_map, phy_mode, and mac_addr for each EMAC */
262         addr = ioremap64(OCOTEA_MAC_BASE, OCOTEA_MAC_SIZE);
263         for (i=0; i<4; i++) {
264                 mac64 = simple_strtoull(addr+OCOTEA_MAC_OFFSET*i, 0, 16);
265                 def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, i);
266                 emacdata = def->additions;
267                 if (i < 2) {
268                         emacdata->phy_map = 0x00000001; /* Skip 0x00 */
269                         emacdata->phy_mode = PHY_MODE_SMII;
270                 }
271                 else {
272                         emacdata->phy_map = 0x0000ffff; /* Skip 0x00-0x0f */
273                         emacdata->phy_mode = PHY_MODE_RGMII;
274                 }
275                 memcpy(emacdata->mac_addr, (char *)&mac64+2, 6);
276         }
277         iounmap(addr);
278
279         ibm440gx_tah_enable();
280
281 #if !defined(CONFIG_BDI_SWITCH)
282         /*
283          * The Abatron BDI JTAG debugger does not tolerate others
284          * mucking with the debug registers.
285          */
286         mtspr(SPRN_DBCR0, (DBCR0_TDE | DBCR0_IDM));
287 #endif
288
289         /*
290          * Determine various clocks.
291          * To be completely correct we should get SysClk
292          * from FPGA, because it can be changed by on-board switches
293          * --ebs
294          */
295         ibm440gx_get_clocks(&clocks, 33333333, 6 * 1843200);
296         ocp_sys_info.opb_bus_freq = clocks.opb;
297
298         /* Setup TODC access */
299         TODC_INIT(TODC_TYPE_DS1743,
300                         0,
301                         0,
302                         ioremap64(OCOTEA_RTC_ADDR, OCOTEA_RTC_SIZE),
303                         8);
304
305         /* init to some ~sane value until calibrate_delay() runs */
306         loops_per_jiffy = 50000000/HZ;
307
308         /* Setup PCI host bridge */
309         ocotea_setup_hose();
310
311 #ifdef CONFIG_BLK_DEV_INITRD
312         if (initrd_start)
313                 ROOT_DEV = Root_RAM0;
314         else
315 #endif
316 #ifdef CONFIG_ROOT_NFS
317                 ROOT_DEV = Root_NFS;
318 #else
319                 ROOT_DEV = Root_HDA1;
320 #endif
321
322 #ifdef CONFIG_DUMMY_CONSOLE
323         conswitchp = &dummy_con;
324 #endif
325
326         ocotea_early_serial_map(&clocks);
327
328         /* Identify the system */
329         printk("IBM Ocotea port (MontaVista Software, Inc. <source@mvista.com>)\n");
330 }
331
332 static void
333 ocotea_restart(char *cmd)
334 {
335         local_irq_disable();
336         abort();
337 }
338
339 static void
340 ocotea_power_off(void)
341 {
342         local_irq_disable();
343         for(;;);
344 }
345
346 static void
347 ocotea_halt(void)
348 {
349         local_irq_disable();
350         for(;;);
351 }
352
353 /*
354  * Read the 440GX memory controller to get size of system memory.
355  */
356 static unsigned long __init
357 ocotea_find_end_of_memory(void)
358 {
359         u32 i, bank_config;
360         u32 mem_size = 0;
361
362         for (i=0; i<4; i++)
363         {
364                 switch (i)
365                 {
366                         case 0:
367                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B0CR);
368                                 break;
369                         case 1:
370                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B1CR);
371                                 break;
372                         case 2:
373                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B2CR);
374                                 break;
375                         case 3:
376                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B3CR);
377                                 break;
378                 }
379
380                 bank_config = mfdcr(DCRN_SDRAM0_CFGDATA);
381
382                 if (!(bank_config & SDRAM_CONFIG_BANK_ENABLE))
383                         continue;
384                 switch (SDRAM_CONFIG_BANK_SIZE(bank_config))
385                 {
386                         case SDRAM_CONFIG_SIZE_8M:
387                                 mem_size += PPC44x_MEM_SIZE_8M;
388                                 break;
389                         case SDRAM_CONFIG_SIZE_16M:
390                                 mem_size += PPC44x_MEM_SIZE_16M;
391                                 break;
392                         case SDRAM_CONFIG_SIZE_32M:
393                                 mem_size += PPC44x_MEM_SIZE_32M;
394                                 break;
395                         case SDRAM_CONFIG_SIZE_64M:
396                                 mem_size += PPC44x_MEM_SIZE_64M;
397                                 break;
398                         case SDRAM_CONFIG_SIZE_128M:
399                                 mem_size += PPC44x_MEM_SIZE_128M;
400                                 break;
401                         case SDRAM_CONFIG_SIZE_256M:
402                                 mem_size += PPC44x_MEM_SIZE_256M;
403                                 break;
404                         case SDRAM_CONFIG_SIZE_512M:
405                                 mem_size += PPC44x_MEM_SIZE_512M;
406                                 break;
407                 }
408         }
409         return mem_size;
410 }
411
412 static void __init
413 ocotea_init_irq(void)
414 {
415         int i;
416
417         ppc4xx_pic_init();
418
419         for (i = 0; i < NR_IRQS; i++)
420                 irq_desc[i].handler = ppc4xx_pic;
421 }
422
423 #ifdef CONFIG_SERIAL_TEXT_DEBUG
424 #include <linux/serialP.h>
425 #include <linux/serial_reg.h>
426 #include <asm/serial.h>
427 struct serial_state rs_table[RS_TABLE_SIZE] = {
428         SERIAL_PORT_DFNS        /* Defined in <asm/serial.h> */
429 };
430
431 static void
432 ocotea_progress(char *s, unsigned short hex)
433 {
434         volatile char c;
435         volatile unsigned long com_port;
436         u16 shift;
437
438         com_port = (unsigned long)rs_table[0].iomem_base;
439         shift = rs_table[0].iomem_reg_shift;
440
441         while ((c = *s++) != 0) {
442                 while ((*((volatile unsigned char *)com_port +
443                                 (UART_LSR << shift)) & UART_LSR_THRE) == 0)
444                         ;
445                 *(volatile unsigned char *)com_port = c;
446
447         }
448
449         /* Send LF/CR to pretty up output */
450         while ((*((volatile unsigned char *)com_port +
451                 (UART_LSR << shift)) & UART_LSR_THRE) == 0)
452                 ;
453         *(volatile unsigned char *)com_port = '\r';
454         while ((*((volatile unsigned char *)com_port +
455                 (UART_LSR << shift)) & UART_LSR_THRE) == 0)
456                 ;
457         *(volatile unsigned char *)com_port = '\n';
458 }
459 #endif /* CONFIG_SERIAL_TEXT_DEBUG */
460
461 #if 0
462 static void __init
463 ocotea_map_io(void)
464 {
465         io_block_mapping(0xe0000000, 0x0000000140000000,
466                          0x00001000, _PAGE_IO);
467 }
468 #endif
469
470 void __init platform_init(unsigned long r3, unsigned long r4,
471                 unsigned long r5, unsigned long r6, unsigned long r7)
472 {
473         parse_bootinfo((struct bi_record *) (r3 + KERNELBASE));
474
475         /* Disable L2-Cache due to hardware issues */
476         ibm440gx_l2c_disable();
477
478         ppc_md.setup_arch = ocotea_setup_arch;
479         ppc_md.show_cpuinfo = ocotea_show_cpuinfo;
480         ppc_md.init_IRQ = ocotea_init_irq;
481         ppc_md.get_irq = NULL;          /* Set in ppc4xx_pic_init() */
482
483         ppc_md.find_end_of_memory = ocotea_find_end_of_memory;
484
485         ppc_md.restart = ocotea_restart;
486         ppc_md.power_off = ocotea_power_off;
487         ppc_md.halt = ocotea_halt;
488
489         ppc_md.calibrate_decr = ocotea_calibrate_decr;
490         ppc_md.time_init = todc_time_init;
491         ppc_md.set_rtc_time = todc_set_rtc_time;
492         ppc_md.get_rtc_time = todc_get_rtc_time;
493
494         ppc_md.nvram_read_val = todc_direct_read_val;
495         ppc_md.nvram_write_val = todc_direct_write_val;
496
497 #ifdef CONFIG_SERIAL_TEXT_DEBUG
498         ppc_md.progress = ocotea_progress;
499 #endif /* CONFIG_SERIAL_TEXT_DEBUG */
500 #ifdef CONFIG_KGDB
501         ppc_md.early_serial_map = ocotea_early_serial_map;
502 #endif
503 }