cleanup
[linux-2.4.git] / arch / ppc / platforms / lopec_setup.c
1 /*
2  * arch/ppc/platforms/lopec_setup.c
3  *
4  * Setup routines for the Motorola LoPEC.
5  *
6  * Author: Dan Cox
7  *         danc@mvista.com
8  *
9  * Copyright 2001-2002 MontaVista Software Inc.
10  *
11  * This program is free software; you can redistribute  it and/or modify it
12  * under  the terms of  the GNU General Public License as published by the
13  * Free Software Foundation;  either version 2 of the  License, or (at your
14  * option) any later version.
15  */
16
17 #include <linux/config.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/errno.h>
21 #include <linux/pci.h>
22 #include <linux/time.h>
23 #include <linux/types.h>
24 #include <linux/major.h>
25 #include <linux/kdev_t.h>
26 #include <linux/ide.h>
27 #include <linux/irq.h>
28 #include <linux/seq_file.h>
29 #include <linux/console.h>
30 #include <linux/serial.h>
31 #include <linux/serialP.h>
32
33 #include <asm/system.h>
34 #include <asm/pgtable.h>
35 #include <asm/machdep.h>
36 #include <asm/page.h>
37 #include <asm/dma.h>
38 #include <asm/io.h>
39 #include <asm/time.h>
40 #include <asm/delay.h>
41 #include <asm/irq.h>
42 #include <asm/open_pic.h>
43 #include <asm/i8259.h>
44 #include <asm/pci-bridge.h>
45 #include <asm/todc.h>
46 #include <asm/bootinfo.h>
47 #include <asm/mpc10x.h>
48 #include <asm/keyboard.h>
49 #include <asm/prep_nvram.h>
50 #include <asm/serial.h>
51
52 extern char saved_command_line[];
53 extern void lopec_find_bridges(void);
54
55 extern int pckbd_setkeycode(unsigned int scancode, unsigned int keycode);
56 extern int pckbd_getkeycode(unsigned int scancode);
57 extern int pckbd_translate(unsigned char scancode, unsigned char *keycode,
58                            char raw_mode);
59 extern char pckbd_unexpected_up(unsigned char keycode);
60 extern void pckbd_leds(unsigned char leds);
61 extern void pckbd_init_hw(void);
62 extern unsigned char pckbd_sysrq_xlate[128];
63 extern void gen550_progress(char *, unsigned short);
64 extern void gen550_init(int, struct serial_struct *);
65
66 /*
67  * Define all of the IRQ senses and polarities.  Taken from the
68  * LoPEC Programmer's Reference Guide */
69 static u_char lopec_openpic_initsenses[17] __initdata = {
70         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* IRQ 0 */
71         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ 1 */
72         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* IRQ 2 */
73         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ 3 */
74         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* IRQ 4 */
75         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* IRQ 5 */
76         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ 6 */
77         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ 7 */
78         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ 8 */
79         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ 9 */
80         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ 10 */
81         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ 11 */
82         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* IRQ 12 */
83         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* IRQ 13 */
84         (IRQ_SENSE_EDGE | IRQ_POLARITY_NEGATIVE),       /* IRQ 14 */
85         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE)       /* IRQ 15 */
86 };
87
88 static int
89 lopec_show_cpuinfo(struct seq_file *m)
90 {
91         seq_printf(m, "machine\t\t: Motorola LoPEC\n");
92         return 0;
93 }
94
95 static u32
96 lopec_irq_cannonicalize(u32 irq)
97 {
98         if (irq == 2)
99                 return 9;
100         else
101                 return irq;
102 }
103
104 static void
105 lopec_restart(char *cmd)
106 {
107 #define LOPEC_SYSSTAT1 0xffe00000
108         /* force a hard reset, if possible */
109         unsigned char reg = *((unsigned char *) LOPEC_SYSSTAT1);
110         reg |= 0x80;
111         *((unsigned char *) LOPEC_SYSSTAT1) = reg;
112
113         __cli();
114         while(1);
115 #undef LOPEC_SYSSTAT1
116 }
117
118 static void
119 lopec_halt(void)
120 {
121         __cli();
122         while(1);
123 }
124
125 static void
126 lopec_power_off(void)
127 {
128         lopec_halt();
129 }
130
131 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
132 int lopec_ide_ports_known = 0;
133 static ide_ioreg_t lopec_ide_regbase[MAX_HWIFS];
134 static ide_ioreg_t lopec_ide_ctl_regbase[MAX_HWIFS];
135 static ide_ioreg_t lopec_idedma_regbase;
136
137 static void
138 lopec_ide_probe(void)
139 {
140         struct pci_dev *dev = pci_find_device(PCI_VENDOR_ID_WINBOND,
141                                               PCI_DEVICE_ID_WINBOND_82C105,
142                                               NULL);
143         lopec_ide_ports_known = 1;
144
145         if (dev) {
146                 lopec_ide_regbase[0] = dev->resource[0].start;
147                 lopec_ide_regbase[1] = dev->resource[2].start;
148                 lopec_ide_ctl_regbase[0] = dev->resource[1].start;
149                 lopec_ide_ctl_regbase[1] = dev->resource[3].start;
150                 lopec_idedma_regbase = dev->resource[4].start;
151         }
152 }
153
154 static int
155 lopec_ide_default_irq(ide_ioreg_t base)
156 {
157         if (lopec_ide_ports_known == 0)
158                 lopec_ide_probe();
159
160         if (base == lopec_ide_regbase[0])
161                 return 14;
162         else if (base == lopec_ide_regbase[1])
163                 return 15;
164         else
165                 return 0;
166 }
167
168 static ide_ioreg_t
169 lopec_ide_default_io_base(int index)
170 {
171         if (lopec_ide_ports_known == 0)
172                 lopec_ide_probe();
173         return lopec_ide_regbase[index];
174 }
175
176 static void __init
177 lopec_ide_init_hwif_ports(hw_regs_t *hw, ide_ioreg_t data,
178                           ide_ioreg_t ctl, int *irq)
179 {
180         ide_ioreg_t reg = data;
181         uint alt_status_base;
182         int i;
183
184         for(i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
185                 hw->io_ports[i] = reg++;
186
187         if (data == lopec_ide_regbase[0]) {
188                 alt_status_base = lopec_ide_ctl_regbase[0] + 2;
189                 hw->irq = 14;
190         }
191         else if (data == lopec_ide_regbase[1]) {
192                 alt_status_base = lopec_ide_ctl_regbase[1] + 2;
193                 hw->irq = 15;
194         }
195         else {
196                 alt_status_base = 0;
197                 hw->irq = 0;
198         }
199
200         if (ctl)
201                 hw->io_ports[IDE_CONTROL_OFFSET] = ctl;
202         else
203                 hw->io_ports[IDE_CONTROL_OFFSET] = alt_status_base;
204
205         if (irq != NULL)
206                 *irq = hw->irq;
207
208 }
209 #endif /* BLK_DEV_IDE */
210
211 static void __init
212 lopec_init_IRQ(void)
213 {
214         int i;
215
216         OpenPIC_InitSenses = lopec_openpic_initsenses;
217         OpenPIC_NumInitSenses = sizeof(lopec_openpic_initsenses);
218
219         /*
220          * We need to tell openpic_set_sources where things actually are.
221          * mpc10x_common will setup OpenPIC_Addr at ioremap(EUMB phys base +
222          * EPIC offset (0x40000));  The EPIC IRQ Register Address Map -
223          * Interrupt Source Configuration Registers gives these numbers
224          * as offsets starting at 0x50200, we need to adjust occordinly.
225          */
226         /* Map serial interrupts 0-15 */
227         openpic_set_sources(0, 16, OpenPIC_Addr + 0x10200);
228         /* Skip reserved space and map i2c and DMA Ch[01] */
229         openpic_set_sources(16, 3, OpenPIC_Addr + 0x11020);
230         /* Skip reserved space and map Message Unit Interrupt (I2O) */
231         openpic_set_sources(19, 1, OpenPIC_Addr + 0x110C0);
232
233         openpic_init(NUM_8259_INTERRUPTS);
234         /* We have a cascade on OpenPIC IRQ 0, Linux IRQ 16 */
235         openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
236                         &i8259_irq);
237
238         /* Map i8259 interrupts */
239         for(i = 0; i < NUM_8259_INTERRUPTS; i++)
240                 irq_desc[i].handler = &i8259_pic;
241
242         i8259_init(0);
243 }
244
245 static void __init
246 lopec_init2(void)
247 {
248         outb(0x00, 0x4d0);
249         outb(0xc0, 0x4d1);
250
251         request_region(0x00, 0x20, "dma1");
252         request_region(0x20, 0x20, "pic1");
253         request_region(0x40, 0x20, "timer");
254         request_region(0x80, 0x10, "dma page reg");
255         request_region(0xa0, 0x20, "pic2");
256         request_region(0xc0, 0x20, "dma2");
257 }
258
259 static void __init
260 lopec_map_io(void)
261 {
262         io_block_mapping(0xf0000000, 0xf0000000, 0x10000000, _PAGE_IO);
263         io_block_mapping(0xb0000000, 0xb0000000, 0x10000000, _PAGE_IO);
264 }
265
266 static void __init
267 lopec_set_bat(void)
268 {
269         unsigned long batu, batl;
270
271         __asm__ __volatile__(
272                 "lis %0,0xf800\n \
273                  ori %1,%0,0x002a\n \
274                  ori %0,%0,0x0ffe\n \
275                  mtspr 0x21e,%0\n \
276                  mtspr 0x21f,%1\n \
277                  isync\n \
278                  sync "
279                 : "=r" (batu), "=r" (batl));
280 }
281
282 static unsigned long __init
283 lopec_find_end_of_memory(void)
284 {
285         return boot_mem_size;
286 }
287
288 TODC_ALLOC();
289
290 #ifdef CONFIG_SERIAL
291 static void __init
292 lopec_early_serial_map(void)
293 {
294         struct serial_struct serial_req;
295
296         memset(&serial_req, 0, sizeof(serial_req));
297
298         /* Setup ioremapped serial port access */
299         serial_req.line = 0;
300         serial_req.baud_base = BASE_BAUD;
301         serial_req.irq = UART0_INT;
302         serial_req.flags = ASYNC_BOOT_AUTOCONF;
303         serial_req.io_type = SERIAL_IO_MEM;
304         serial_req.iomem_base = ioremap(UART0_PORT, 8);
305
306 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
307         /* Configure debug serial access */
308         gen550_init(0, &serial_req);
309 #endif
310
311         if (early_serial_setup(&serial_req) != 0)
312                 printk("Early serial init of port 0 failed\n");
313
314         /* Assume early_serial_setup() doesn't modify serial_req */
315         serial_req.line = 1;
316         serial_req.port = 1;
317         serial_req.irq = UART1_INT;
318         serial_req.iomem_base = ioremap(UART1_PORT, 8);
319
320 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
321         /* Configure debug serial access */
322         gen550_init(1, &serial_req);
323 #endif
324
325         if (early_serial_setup(&serial_req) != 0)
326                 printk("Early serial init of port 1 failed\n");
327
328         serial_req.line = 2;
329         serial_req.port = 2;
330         serial_req.irq = UART2_INT;
331         serial_req.iomem_base = ioremap(UART2_PORT, 8);
332
333 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
334         /* Configure debug serial access */
335         gen550_init(2, &serial_req);
336 #endif
337
338         if (early_serial_setup(&serial_req) != 0)
339                 printk("Early serial init of port 2 failed\n");
340 }
341 #endif
342
343 static void __init
344 lopec_setup_arch(void)
345 {
346
347         TODC_INIT(TODC_TYPE_MK48T37, 0, 0,
348                   ioremap(0xffe80000, 0x8000), 8);
349
350         loops_per_jiffy = 100000000/HZ;
351
352         lopec_find_bridges();
353
354 #ifdef CONFIG_BLK_DEV_INITRD
355         if (initrd_start)
356                 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
357         else
358 #elif defined(CONFIG_ROOT_NFS)
359                 ROOT_DEV = to_kdev_t(0x00ff);
360 #elif defined(CONFIG_BLK_DEV_IDE)
361                 ROOT_DEV = to_kdev_t(0x0301);
362 #else
363                 ROOT_DEV = to_kdev_t(0x0801);
364 #endif
365
366 #ifdef CONFIG_DUMMY_CONSOLE
367         conswitchp = &dummy_con;
368 #endif
369
370 #ifdef CONFIG_SERIAL
371         lopec_early_serial_map();
372 #endif
373
374 #ifdef CONFIG_PPCBUG_NVRAM
375         /* Read in NVRAM data */
376         init_prep_nvram();
377
378         /* if no bootargs, look in NVRAM */
379         if ( cmd_line[0] == '\0' ) {
380                 char *bootargs;
381                  bootargs = prep_nvram_get_var("bootargs");
382                  if (bootargs != NULL) {
383                          strcpy(cmd_line, bootargs);
384                          /* again.. */
385                          strcpy(saved_command_line, cmd_line);
386                 }
387         }
388 #endif
389 }
390
391 void __init
392 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
393               unsigned long r6, unsigned long r7)
394 {
395         parse_bootinfo(find_bootinfo());
396         lopec_set_bat();
397
398         isa_io_base = MPC10X_MAPB_ISA_IO_BASE;
399         isa_mem_base = MPC10X_MAPB_ISA_MEM_BASE;
400         pci_dram_offset = MPC10X_MAPB_DRAM_OFFSET;
401         ISA_DMA_THRESHOLD = 0x00ffffff;
402         DMA_MODE_READ = 0x44;
403         DMA_MODE_WRITE = 0x48;
404
405         ppc_md.setup_arch = lopec_setup_arch;
406         ppc_md.show_cpuinfo = lopec_show_cpuinfo;
407         ppc_md.irq_cannonicalize = lopec_irq_cannonicalize;
408         ppc_md.init_IRQ = lopec_init_IRQ;
409         ppc_md.get_irq = openpic_get_irq;
410         ppc_md.init = lopec_init2;
411
412         ppc_md.restart = lopec_restart;
413         ppc_md.power_off = lopec_power_off;
414         ppc_md.halt = lopec_halt;
415
416         ppc_md.find_end_of_memory = lopec_find_end_of_memory;
417         ppc_md.setup_io_mappings = lopec_map_io;
418
419 #ifdef CONFIG_VT
420         ppc_md.kbd_setkeycode = pckbd_setkeycode;
421         ppc_md.kbd_getkeycode = pckbd_getkeycode;
422         ppc_md.kbd_translate = pckbd_translate;
423         ppc_md.kbd_unexpected_up = pckbd_unexpected_up;
424 #ifdef CONFIG_MAGIC_SYSRQ
425         ppc_md.ppc_kbd_sysrq_xlate = pckbd_sysrq_xlate;
426         SYSRQ_KEY = 0x54;
427 #endif /* CONFIG_MAGIC_SYSRQ */
428 #endif /* CONFIG_VT */
429
430         ppc_md.time_init = todc_time_init;
431         ppc_md.set_rtc_time = todc_set_rtc_time;
432         ppc_md.get_rtc_time = todc_get_rtc_time;
433         ppc_md.calibrate_decr = todc_calibrate_decr;
434
435         ppc_md.nvram_read_val = todc_direct_read_val;
436         ppc_md.nvram_write_val = todc_direct_write_val;
437
438 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_ID_MODULE)
439         ppc_ide_md.default_irq = lopec_ide_default_irq;
440         ppc_ide_md.default_io_base = lopec_ide_default_io_base;
441         ppc_ide_md.ide_init_hwif = lopec_ide_init_hwif_ports;
442 #endif
443 #ifdef CONFIG_SERIAL
444 #ifdef CONFIG_SERIAL_TEXT_DEBUG
445         ppc_md.progress = gen550_progress;
446 #endif
447         ppc_md.early_serial_map = lopec_early_serial_map;
448 #endif
449 }