Linux 3.1-rc1
[linux-kbuild.git] / arch / arm / mach-footbridge / netwinder-hw.c
blob06e514f372d0f2a702d79d28963f48e18ac26aa6
1 /*
2 * linux/arch/arm/mach-footbridge/netwinder-hw.c
4 * Netwinder machine fixup
6 * Copyright (C) 1998, 1999 Russell King, Phil Blundell
7 */
8 #include <linux/module.h>
9 #include <linux/ioport.h>
10 #include <linux/kernel.h>
11 #include <linux/delay.h>
12 #include <linux/init.h>
13 #include <linux/io.h>
14 #include <linux/spinlock.h>
16 #include <asm/hardware/dec21285.h>
17 #include <asm/leds.h>
18 #include <asm/mach-types.h>
19 #include <asm/setup.h>
21 #include <asm/mach/arch.h>
23 #include "common.h"
25 #define IRDA_IO_BASE 0x180
26 #define GP1_IO_BASE 0x338
27 #define GP2_IO_BASE 0x33a
30 #ifdef CONFIG_LEDS
31 #define DEFAULT_LEDS 0
32 #else
33 #define DEFAULT_LEDS GPIO_GREEN_LED
34 #endif
37 * Winbond WB83977F accessibility stuff
39 static inline void wb977_open(void)
41 outb(0x87, 0x370);
42 outb(0x87, 0x370);
45 static inline void wb977_close(void)
47 outb(0xaa, 0x370);
50 static inline void wb977_wb(int reg, int val)
52 outb(reg, 0x370);
53 outb(val, 0x371);
56 static inline void wb977_ww(int reg, int val)
58 outb(reg, 0x370);
59 outb(val >> 8, 0x371);
60 outb(reg + 1, 0x370);
61 outb(val & 255, 0x371);
64 #define wb977_device_select(dev) wb977_wb(0x07, dev)
65 #define wb977_device_disable() wb977_wb(0x30, 0x00)
66 #define wb977_device_enable() wb977_wb(0x30, 0x01)
69 * This is a lock for accessing ports GP1_IO_BASE and GP2_IO_BASE
71 DEFINE_SPINLOCK(nw_gpio_lock);
72 EXPORT_SYMBOL(nw_gpio_lock);
74 static unsigned int current_gpio_op;
75 static unsigned int current_gpio_io;
76 static unsigned int current_cpld;
78 void nw_gpio_modify_op(unsigned int mask, unsigned int set)
80 unsigned int new_gpio, changed;
82 new_gpio = (current_gpio_op & ~mask) | set;
83 changed = new_gpio ^ current_gpio_op;
84 current_gpio_op = new_gpio;
86 if (changed & 0xff)
87 outb(new_gpio, GP1_IO_BASE);
88 if (changed & 0xff00)
89 outb(new_gpio >> 8, GP2_IO_BASE);
91 EXPORT_SYMBOL(nw_gpio_modify_op);
93 static inline void __gpio_modify_io(int mask, int in)
95 unsigned int new_gpio, changed;
96 int port;
98 new_gpio = (current_gpio_io & ~mask) | in;
99 changed = new_gpio ^ current_gpio_io;
100 current_gpio_io = new_gpio;
102 changed >>= 1;
103 new_gpio >>= 1;
105 wb977_device_select(7);
107 for (port = 0xe1; changed && port < 0xe8; changed >>= 1) {
108 wb977_wb(port, new_gpio & 1);
110 port += 1;
111 new_gpio >>= 1;
114 wb977_device_select(8);
116 for (port = 0xe8; changed && port < 0xec; changed >>= 1) {
117 wb977_wb(port, new_gpio & 1);
119 port += 1;
120 new_gpio >>= 1;
124 void nw_gpio_modify_io(unsigned int mask, unsigned int in)
126 /* Open up the SuperIO chip */
127 wb977_open();
129 __gpio_modify_io(mask, in);
131 /* Close up the EFER gate */
132 wb977_close();
134 EXPORT_SYMBOL(nw_gpio_modify_io);
136 unsigned int nw_gpio_read(void)
138 return inb(GP1_IO_BASE) | inb(GP2_IO_BASE) << 8;
140 EXPORT_SYMBOL(nw_gpio_read);
143 * Initialise the Winbond W83977F global registers
145 static inline void wb977_init_global(void)
148 * Enable R/W config registers
150 wb977_wb(0x26, 0x40);
153 * Power down FDC (not used)
155 wb977_wb(0x22, 0xfe);
158 * GP12, GP11, CIRRX, IRRXH, GP10
160 wb977_wb(0x2a, 0xc1);
163 * GP23, GP22, GP21, GP20, GP13
165 wb977_wb(0x2b, 0x6b);
168 * GP17, GP16, GP15, GP14
170 wb977_wb(0x2c, 0x55);
174 * Initialise the Winbond W83977F printer port
176 static inline void wb977_init_printer(void)
178 wb977_device_select(1);
181 * mode 1 == EPP
183 wb977_wb(0xf0, 0x01);
187 * Initialise the Winbond W83977F keyboard controller
189 static inline void wb977_init_keyboard(void)
191 wb977_device_select(5);
194 * Keyboard controller address
196 wb977_ww(0x60, 0x0060);
197 wb977_ww(0x62, 0x0064);
200 * Keyboard IRQ 1, active high, edge trigger
202 wb977_wb(0x70, 1);
203 wb977_wb(0x71, 0x02);
206 * Mouse IRQ 5, active high, edge trigger
208 wb977_wb(0x72, 5);
209 wb977_wb(0x73, 0x02);
212 * KBC 8MHz
214 wb977_wb(0xf0, 0x40);
217 * Enable device
219 wb977_device_enable();
223 * Initialise the Winbond W83977F Infra-Red device
225 static inline void wb977_init_irda(void)
227 wb977_device_select(6);
230 * IR base address
232 wb977_ww(0x60, IRDA_IO_BASE);
235 * IRDA IRQ 6, active high, edge trigger
237 wb977_wb(0x70, 6);
238 wb977_wb(0x71, 0x02);
241 * RX DMA - ISA DMA 0
243 wb977_wb(0x74, 0x00);
246 * TX DMA - Disable Tx DMA
248 wb977_wb(0x75, 0x04);
251 * Append CRC, Enable bank selection
253 wb977_wb(0xf0, 0x03);
256 * Enable device
258 wb977_device_enable();
262 * Initialise Winbond W83977F general purpose IO
264 static inline void wb977_init_gpio(void)
266 unsigned long flags;
269 * Set up initial I/O definitions
271 current_gpio_io = -1;
272 __gpio_modify_io(-1, GPIO_DONE | GPIO_WDTIMER);
274 wb977_device_select(7);
277 * Group1 base address
279 wb977_ww(0x60, GP1_IO_BASE);
280 wb977_ww(0x62, 0);
281 wb977_ww(0x64, 0);
284 * GP10 (Orage button) IRQ 10, active high, edge trigger
286 wb977_wb(0x70, 10);
287 wb977_wb(0x71, 0x02);
290 * GP10: Debounce filter enabled, IRQ, input
292 wb977_wb(0xe0, 0x19);
295 * Enable Group1
297 wb977_device_enable();
299 wb977_device_select(8);
302 * Group2 base address
304 wb977_ww(0x60, GP2_IO_BASE);
307 * Clear watchdog timer regs
308 * - timer disable
310 wb977_wb(0xf2, 0x00);
313 * - disable LED, no mouse nor keyboard IRQ
315 wb977_wb(0xf3, 0x00);
318 * - timer counting, disable power LED, disable timeouot
320 wb977_wb(0xf4, 0x00);
323 * Enable group2
325 wb977_device_enable();
328 * Set Group1/Group2 outputs
330 spin_lock_irqsave(&nw_gpio_lock, flags);
331 nw_gpio_modify_op(-1, GPIO_RED_LED | GPIO_FAN);
332 spin_unlock_irqrestore(&nw_gpio_lock, flags);
336 * Initialise the Winbond W83977F chip.
338 static void __init wb977_init(void)
340 request_region(0x370, 2, "W83977AF configuration");
343 * Open up the SuperIO chip
345 wb977_open();
348 * Initialise the global registers
350 wb977_init_global();
353 * Initialise the various devices in
354 * the multi-IO chip.
356 wb977_init_printer();
357 wb977_init_keyboard();
358 wb977_init_irda();
359 wb977_init_gpio();
362 * Close up the EFER gate
364 wb977_close();
367 void nw_cpld_modify(unsigned int mask, unsigned int set)
369 int msk;
371 current_cpld = (current_cpld & ~mask) | set;
373 nw_gpio_modify_io(GPIO_DATA | GPIO_IOCLK | GPIO_IOLOAD, 0);
374 nw_gpio_modify_op(GPIO_IOLOAD, 0);
376 for (msk = 8; msk; msk >>= 1) {
377 int bit = current_cpld & msk;
379 nw_gpio_modify_op(GPIO_DATA | GPIO_IOCLK, bit ? GPIO_DATA : 0);
380 nw_gpio_modify_op(GPIO_IOCLK, GPIO_IOCLK);
383 nw_gpio_modify_op(GPIO_IOCLK|GPIO_DATA, 0);
384 nw_gpio_modify_op(GPIO_IOLOAD|GPIO_DSCLK, GPIO_IOLOAD|GPIO_DSCLK);
385 nw_gpio_modify_op(GPIO_IOLOAD, 0);
387 EXPORT_SYMBOL(nw_cpld_modify);
389 static void __init cpld_init(void)
391 unsigned long flags;
393 spin_lock_irqsave(&nw_gpio_lock, flags);
394 nw_cpld_modify(-1, CPLD_UNMUTE | CPLD_7111_DISABLE);
395 spin_unlock_irqrestore(&nw_gpio_lock, flags);
398 static unsigned char rwa_unlock[] __initdata =
399 { 0x00, 0x00, 0x6a, 0xb5, 0xda, 0xed, 0xf6, 0xfb, 0x7d, 0xbe, 0xdf, 0x6f, 0x37, 0x1b,
400 0x0d, 0x86, 0xc3, 0x61, 0xb0, 0x58, 0x2c, 0x16, 0x8b, 0x45, 0xa2, 0xd1, 0xe8, 0x74,
401 0x3a, 0x9d, 0xce, 0xe7, 0x73, 0x39 };
403 #ifndef DEBUG
404 #define dprintk(x...)
405 #else
406 #define dprintk(x...) printk(x)
407 #endif
409 #define WRITE_RWA(r,v) do { outb((r), 0x279); udelay(10); outb((v), 0xa79); } while (0)
411 static inline void rwa010_unlock(void)
413 int i;
415 WRITE_RWA(2, 2);
416 mdelay(10);
418 for (i = 0; i < sizeof(rwa_unlock); i++) {
419 outb(rwa_unlock[i], 0x279);
420 udelay(10);
424 static inline void rwa010_read_ident(void)
426 unsigned char si[9];
427 int i, j;
429 WRITE_RWA(3, 0);
430 WRITE_RWA(0, 128);
432 outb(1, 0x279);
434 mdelay(1);
436 dprintk("Identifier: ");
437 for (i = 0; i < 9; i++) {
438 si[i] = 0;
439 for (j = 0; j < 8; j++) {
440 int bit;
441 udelay(250);
442 inb(0x203);
443 udelay(250);
444 bit = inb(0x203);
445 dprintk("%02X ", bit);
446 bit = (bit == 0xaa) ? 1 : 0;
447 si[i] |= bit << j;
449 dprintk("(%02X) ", si[i]);
451 dprintk("\n");
454 static inline void rwa010_global_init(void)
456 WRITE_RWA(6, 2); // Assign a card no = 2
458 dprintk("Card no = %d\n", inb(0x203));
460 /* disable the modem section of the chip */
461 WRITE_RWA(7, 3);
462 WRITE_RWA(0x30, 0);
464 /* disable the cdrom section of the chip */
465 WRITE_RWA(7, 4);
466 WRITE_RWA(0x30, 0);
468 /* disable the MPU-401 section of the chip */
469 WRITE_RWA(7, 2);
470 WRITE_RWA(0x30, 0);
473 static inline void rwa010_game_port_init(void)
475 int i;
477 WRITE_RWA(7, 5);
479 dprintk("Slider base: ");
480 WRITE_RWA(0x61, 1);
481 i = inb(0x203);
483 WRITE_RWA(0x60, 2);
484 dprintk("%02X%02X (201)\n", inb(0x203), i);
486 WRITE_RWA(0x30, 1);
489 static inline void rwa010_waveartist_init(int base, int irq, int dma)
491 int i;
493 WRITE_RWA(7, 0);
495 dprintk("WaveArtist base: ");
496 WRITE_RWA(0x61, base & 255);
497 i = inb(0x203);
499 WRITE_RWA(0x60, base >> 8);
500 dprintk("%02X%02X (%X),", inb(0x203), i, base);
502 WRITE_RWA(0x70, irq);
503 dprintk(" irq: %d (%d),", inb(0x203), irq);
505 WRITE_RWA(0x74, dma);
506 dprintk(" dma: %d (%d)\n", inb(0x203), dma);
508 WRITE_RWA(0x30, 1);
511 static inline void rwa010_soundblaster_init(int sb_base, int al_base, int irq, int dma)
513 int i;
515 WRITE_RWA(7, 1);
517 dprintk("SoundBlaster base: ");
518 WRITE_RWA(0x61, sb_base & 255);
519 i = inb(0x203);
521 WRITE_RWA(0x60, sb_base >> 8);
522 dprintk("%02X%02X (%X),", inb(0x203), i, sb_base);
524 dprintk(" irq: ");
525 WRITE_RWA(0x70, irq);
526 dprintk("%d (%d),", inb(0x203), irq);
528 dprintk(" 8-bit DMA: ");
529 WRITE_RWA(0x74, dma);
530 dprintk("%d (%d)\n", inb(0x203), dma);
532 dprintk("AdLib base: ");
533 WRITE_RWA(0x63, al_base & 255);
534 i = inb(0x203);
536 WRITE_RWA(0x62, al_base >> 8);
537 dprintk("%02X%02X (%X)\n", inb(0x203), i, al_base);
539 WRITE_RWA(0x30, 1);
542 static void rwa010_soundblaster_reset(void)
544 int i;
546 outb(1, 0x226);
547 udelay(3);
548 outb(0, 0x226);
550 for (i = 0; i < 5; i++) {
551 if (inb(0x22e) & 0x80)
552 break;
553 mdelay(1);
555 if (i == 5)
556 printk("SoundBlaster: DSP reset failed\n");
558 dprintk("SoundBlaster DSP reset: %02X (AA)\n", inb(0x22a));
560 for (i = 0; i < 5; i++) {
561 if ((inb(0x22c) & 0x80) == 0)
562 break;
563 mdelay(1);
566 if (i == 5)
567 printk("SoundBlaster: DSP not ready\n");
568 else {
569 outb(0xe1, 0x22c);
571 dprintk("SoundBlaster DSP id: ");
572 i = inb(0x22a);
573 udelay(1);
574 i |= inb(0x22a) << 8;
575 dprintk("%04X\n", i);
577 for (i = 0; i < 5; i++) {
578 if ((inb(0x22c) & 0x80) == 0)
579 break;
580 mdelay(1);
583 if (i == 5)
584 printk("SoundBlaster: could not turn speaker off\n");
586 outb(0xd3, 0x22c);
589 /* turn on OPL3 */
590 outb(5, 0x38a);
591 outb(1, 0x38b);
594 static void __init rwa010_init(void)
596 rwa010_unlock();
597 rwa010_read_ident();
598 rwa010_global_init();
599 rwa010_game_port_init();
600 rwa010_waveartist_init(0x250, 3, 7);
601 rwa010_soundblaster_init(0x220, 0x388, 3, 1);
602 rwa010_soundblaster_reset();
606 * Initialise any other hardware after we've got the PCI bus
607 * initialised. We may need the PCI bus to talk to this other
608 * hardware.
610 static int __init nw_hw_init(void)
612 if (machine_is_netwinder()) {
613 unsigned long flags;
615 wb977_init();
616 cpld_init();
617 rwa010_init();
619 spin_lock_irqsave(&nw_gpio_lock, flags);
620 nw_gpio_modify_op(GPIO_RED_LED|GPIO_GREEN_LED, DEFAULT_LEDS);
621 spin_unlock_irqrestore(&nw_gpio_lock, flags);
623 return 0;
626 __initcall(nw_hw_init);
629 * Older NeTTroms either do not provide a parameters
630 * page, or they don't supply correct information in
631 * the parameter page.
633 static void __init
634 fixup_netwinder(struct machine_desc *desc, struct tag *tags,
635 char **cmdline, struct meminfo *mi)
637 #ifdef CONFIG_ISAPNP
638 extern int isapnp_disable;
641 * We must not use the kernels ISAPnP code
642 * on the NetWinder - it will reset the settings
643 * for the WaveArtist chip and render it inoperable.
645 isapnp_disable = 1;
646 #endif
649 MACHINE_START(NETWINDER, "Rebel-NetWinder")
650 /* Maintainer: Russell King/Rebel.com */
651 .boot_params = 0x00000100,
652 .video_start = 0x000a0000,
653 .video_end = 0x000bffff,
654 .reserve_lp0 = 1,
655 .reserve_lp2 = 1,
656 .fixup = fixup_netwinder,
657 .map_io = footbridge_map_io,
658 .init_irq = footbridge_init_irq,
659 .timer = &isa_timer,
660 MACHINE_END