port enough sendpoint support for DSM-G600 from D-Link 2.4.21-pre4
[linux-2.4.git] / arch / ppc / platforms / 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/blk.h>
27 #include <linux/console.h>
28 #include <linux/delay.h>
29 #include <linux/ide.h>
30 #include <linux/irq.h>
31 #include <linux/seq_file.h>
32 #include <linux/tty.h>
33 #include <linux/serial.h>
34
35 #include <asm/system.h>
36 #include <asm/pgtable.h>
37 #include <asm/page.h>
38 #include <asm/dma.h>
39 #include <asm/io.h>
40 #include <asm/machdep.h>
41 #include <asm/pci-bridge.h>
42 #include <asm/time.h>
43 #include <asm/todc.h>
44 #include <asm/bootinfo.h>
45 #include <asm/ppc4xx_pic.h>
46
47 #include <kernel/ibm440gx_common.h>
48
49 extern void abort(void);
50 extern int pckbd_setkeycode(unsigned int scancode, unsigned int keycode);
51 extern int pckbd_getkeycode(unsigned int scancode);
52 extern int pckbd_translate(unsigned char scancode, unsigned char *keycode,
53                            char raw_mode);
54 extern void gen550_progress(char *, unsigned short);
55 extern void gen550_init(int, struct serial_struct *);
56
57 /* Global Variables */
58 unsigned char __res[sizeof (bd_t)];
59
60 static void __init
61 ocotea_calibrate_decr(void)
62 {
63         unsigned int freq;
64
65         freq = OCOTEA_SYSCLK;
66         
67         tb_ticks_per_jiffy = freq / HZ;
68         tb_to_us = mulhwu_scale_factor(freq, 1000000);
69
70         /* Set the time base to zero */
71         mtspr(SPRN_TBWL, 0);
72         mtspr(SPRN_TBWU, 0);
73
74         /* Clear any pending timer interrupts */
75         mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
76
77         /* Enable decrementer interrupt */
78         mtspr(SPRN_TCR, TCR_DIE);
79 }
80
81 static int
82 ocotea_show_cpuinfo(struct seq_file *m)
83 {
84         ibm440gx_show_cpuinfo(m);
85         seq_printf(m, "vendor\t\t: IBM\n");
86         seq_printf(m, "machine\t\t: PPC440GX EVB (Ocotea)\n");
87
88         return 0;
89 }
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(0x80000007, 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 serial_struct serial_req;
215
216         /* Setup ioremapped serial port access */
217         memset(&serial_req, 0, sizeof(serial_req));
218         serial_req.line = 0;
219         serial_req.baud_base = clks->uart0 / 16;
220         serial_req.port = 0;
221         serial_req.irq = 0;
222         serial_req.flags = ASYNC_BOOT_AUTOCONF;
223         serial_req.io_type = SERIAL_IO_MEM;
224         serial_req.iomem_base = ioremap64(PPC440GX_UART0_ADDR, 8);
225         serial_req.iomem_reg_shift = 0;
226
227 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
228         /* Configure debug serial access */
229         gen550_init(0, &serial_req);
230 #endif
231
232         if (early_serial_setup(&serial_req) != 0) {
233                 printk("Early serial init of port 0 failed\n");
234         }
235
236         /* Assume early_serial_setup() doesn't modify serial_req */
237         serial_req.line = 1;
238         serial_req.baud_base = clks->uart1 / 16;
239         serial_req.port = 1;
240         serial_req.irq = 1; 
241         serial_req.iomem_base = ioremap64(PPC440GX_UART1_ADDR, 8);
242
243 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
244         /* Configure debug serial access */
245         gen550_init(1, &serial_req);
246 #endif
247
248         if (early_serial_setup(&serial_req) != 0) {
249                 printk("Early serial init of port 1 failed\n");
250         }
251 }
252
253 static void __init
254 ocotea_setup_arch(void)
255 {
256         unsigned char *addr;
257         unsigned long long mac64;
258         bd_t *bip = (bd_t *) __res;
259         struct ibm44x_clocks clocks;
260
261         /* Retrieve MAC addresses from flash */
262         addr = ioremap64(OCOTEA_MAC_BASE, OCOTEA_MAC_SIZE);
263         mac64 = simple_strtoull(addr, 0, 16);
264         memcpy(bip->bi_enetaddr[0], (char *)&mac64+2, 6);
265         mac64 = simple_strtoull(addr+OCOTEA_MAC1_OFFSET, 0, 16);
266         memcpy(bip->bi_enetaddr[1], (char *)&mac64+2, 6);
267         iounmap(addr);
268
269         /* Set EMAC PHY map to not probe address 0x00 */
270         emac_phy_map[0] = 0x00000001;
271         emac_phy_map[1] = 0x00000001;
272
273 #if !defined(CONFIG_BDI_SWITCH)
274         /*
275          * The Abatron BDI JTAG debugger does not tolerate others
276          * mucking with the debug registers.
277          */
278         mtspr(SPRN_DBCR0, (DBCR0_TDE | DBCR0_IDM));
279 #endif
280         /*
281          * Determine various clocks.
282          * To be completely correct we should get SysClk
283          * from FPGA, because it can be changed by on-board switches
284          * --ebs
285          */
286         ibm440gx_get_clocks(&clocks, 33333333, 6 * 1843200);
287         bip->bi_opb_busfreq = clocks.opb;
288         
289         /* Use IIC in standard (100 kHz) mode */
290         bip->bi_iic_fast[0] = bip->bi_iic_fast[1] = 0;
291         
292         /* Setup TODC access */
293         TODC_INIT(TODC_TYPE_DS1743,
294                         0,
295                         0,
296                         ioremap64(OCOTEA_RTC_ADDR, OCOTEA_RTC_SIZE),
297                         8);
298
299         /* init to some ~sane value until calibrate_delay() runs */
300         loops_per_jiffy = 50000000/HZ;
301
302         /* Setup PCI host bridge */
303         ocotea_setup_hose();
304         
305 #ifdef CONFIG_BLK_DEV_INITRD
306         if (initrd_start)
307                 ROOT_DEV = to_kdev_t(0x0100); /* /dev/ram */
308         else
309 #endif
310 #ifdef CONFIG_ROOT_NFS
311                 ROOT_DEV = to_kdev_t(0x00ff); /* /dev/nfs */
312 #else
313                 ROOT_DEV = to_kdev_t(0x0301); /* /dev/hda1 */
314 #endif
315
316 #ifdef CONFIG_VT
317         conswitchp = &dummy_con;
318 #endif
319
320         ocotea_early_serial_map(&clocks);
321
322         /* Identify the system */
323         printk("IBM Ocotea port (MontaVista Software, Inc. <source@mvista.com>)\n");
324 }
325
326 static void
327 ocotea_restart(char *cmd)
328 {
329         local_irq_disable();
330         abort();
331 }
332
333 static void
334 ocotea_power_off(void)
335 {
336         local_irq_disable();
337         for(;;);
338 }
339
340 static void
341 ocotea_halt(void)
342 {
343         local_irq_disable();
344         for(;;);
345 }
346
347 /*
348  * Read the 440GX memory controller to get size of system memory.
349  */
350 static unsigned long __init
351 ocotea_find_end_of_memory(void)
352 {
353         u32 i, bank_config;
354         u32 mem_size = 0;
355
356         for (i=0; i<4; i++)
357         {
358                 switch (i)
359                 {
360                         case 0:
361                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B0CR);
362                                 break;
363                         case 1:
364                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B1CR);
365                                 break;
366                         case 2:
367                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B2CR);
368                                 break;
369                         case 3:
370                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B3CR);
371                                 break;
372                 }
373
374                 bank_config = mfdcr(DCRN_SDRAM0_CFGDATA);
375
376                 if (!(bank_config & SDRAM_CONFIG_BANK_ENABLE))
377                         continue;
378                 switch (SDRAM_CONFIG_BANK_SIZE(bank_config))
379                 {
380                         case SDRAM_CONFIG_SIZE_8M:
381                                 mem_size += PPC44x_MEM_SIZE_8M;
382                                 break;
383                         case SDRAM_CONFIG_SIZE_16M:
384                                 mem_size += PPC44x_MEM_SIZE_16M;
385                                 break;
386                         case SDRAM_CONFIG_SIZE_32M:
387                                 mem_size += PPC44x_MEM_SIZE_32M;
388                                 break;
389                         case SDRAM_CONFIG_SIZE_64M:
390                                 mem_size += PPC44x_MEM_SIZE_64M;
391                                 break;
392                         case SDRAM_CONFIG_SIZE_128M:
393                                 mem_size += PPC44x_MEM_SIZE_128M;
394                                 break;
395                         case SDRAM_CONFIG_SIZE_256M:
396                                 mem_size += PPC44x_MEM_SIZE_256M;
397                                 break;
398                         case SDRAM_CONFIG_SIZE_512M:
399                                 mem_size += PPC44x_MEM_SIZE_512M;
400                                 break;
401                 }
402         }
403         return mem_size;
404 }
405
406 static void __init
407 ocotea_init_irq(void)
408 {
409         int i;
410
411         /* Enable PPC440GP interrupt compatibility mode */
412         SDR_WRITE(DCRN_SDR_MFR,SDR_READ(DCRN_SDR_MFR) | DCRN_SDR_MFR_PCM);
413
414         ppc4xx_pic_init();
415
416         for (i = 0; i < NR_IRQS; i++)
417                 irq_desc[i].handler = ppc4xx_pic;
418 }
419
420 void __init platform_init(unsigned long r3, unsigned long r4,
421                 unsigned long r5, unsigned long r6, unsigned long r7)
422 {
423         parse_bootinfo(find_bootinfo());
424
425         /* Disable L2-Cache due to hardware issues */
426         ibm440gx_l2c_disable();
427
428         ppc_md.setup_arch = ocotea_setup_arch;
429         ppc_md.show_cpuinfo = ocotea_show_cpuinfo;
430         ppc_md.init_IRQ = ocotea_init_irq;
431         ppc_md.get_irq = NULL;          /* Set in ppc4xx_pic_init() */
432
433         ppc_md.find_end_of_memory = ocotea_find_end_of_memory;
434
435         ppc_md.restart = ocotea_restart;
436         ppc_md.power_off = ocotea_power_off;
437         ppc_md.halt = ocotea_halt;
438
439         ppc_md.calibrate_decr = ocotea_calibrate_decr;
440         ppc_md.time_init = todc_time_init;
441         ppc_md.set_rtc_time = todc_set_rtc_time;
442         ppc_md.get_rtc_time = todc_get_rtc_time;
443
444         ppc_md.nvram_read_val = todc_direct_read_val;
445         ppc_md.nvram_write_val = todc_direct_write_val;
446 #if defined(CONFIG_VT) 
447         ppc_md.kbd_setkeycode = pckbd_setkeycode;
448         ppc_md.kbd_getkeycode = pckbd_getkeycode;
449         ppc_md.kbd_translate = pckbd_translate;
450         ppc_md.kbd_unexpected_up = pckbd_unexpected_up;
451         ppc_md.kbd_leds = pckbd_leds;
452         ppc_md.kbd_init_hw = 0;
453 #endif
454
455 #ifdef CONFIG_SERIAL_TEXT_DEBUG
456         ppc_md.progress = gen550_progress;
457 #endif /* CONFIG_SERIAL_TEXT_DEBUG */
458 #ifdef CONFIG_KGDB
459         ppc_md.early_serial_map = ocotea_early_serial_map;
460 #endif
461 }