2 * linux/arch/arm/mach-footbridge/netwinder-hw.c
4 * Netwinder machine fixup
6 * Copyright (C) 1998, 1999 Russell King, Phil Blundell
8 #include <linux/config.h>
9 #include <linux/module.h>
10 #include <linux/ioport.h>
11 #include <linux/kernel.h>
12 #include <linux/delay.h>
13 #include <linux/init.h>
17 #include <asm/mach-types.h>
19 #define IRDA_IO_BASE 0x180
20 #define GP1_IO_BASE 0x338
21 #define GP2_IO_BASE 0x33a
25 #define DEFAULT_LEDS 0
27 #define DEFAULT_LEDS GPIO_GREEN_LED
31 * Winbond WB83977F accessibility stuff
33 static inline void wb977_open(void)
39 static inline void wb977_close(void)
44 static inline void wb977_wb(int reg, int val)
50 static inline void wb977_ww(int reg, int val)
53 outb(val >> 8, 0x371);
58 #define wb977_device_select(dev) wb977_wb(0x07, dev)
59 #define wb977_device_disable() wb977_wb(0x30, 0x00)
60 #define wb977_device_enable() wb977_wb(0x30, 0x01)
63 * This is a lock for accessing ports GP1_IO_BASE and GP2_IO_BASE
65 spinlock_t gpio_lock = SPIN_LOCK_UNLOCKED;
67 static unsigned int current_gpio_op;
68 static unsigned int current_gpio_io;
69 static unsigned int current_cpld;
71 void gpio_modify_op(int mask, int set)
73 unsigned int new_gpio, changed;
75 new_gpio = (current_gpio_op & ~mask) | set;
76 changed = new_gpio ^ current_gpio_op;
77 current_gpio_op = new_gpio;
80 outb(new_gpio, GP1_IO_BASE);
82 outb(new_gpio >> 8, GP2_IO_BASE);
85 static inline void __gpio_modify_io(int mask, int in)
87 unsigned int new_gpio, changed;
90 new_gpio = (current_gpio_io & ~mask) | in;
91 changed = new_gpio ^ current_gpio_io;
92 current_gpio_io = new_gpio;
97 wb977_device_select(7);
99 for (port = 0xe1; changed && port < 0xe8; changed >>= 1) {
100 wb977_wb(port, new_gpio & 1);
106 wb977_device_select(8);
108 for (port = 0xe8; changed && port < 0xec; changed >>= 1) {
109 wb977_wb(port, new_gpio & 1);
116 void gpio_modify_io(int mask, int in)
118 /* Open up the SuperIO chip */
121 __gpio_modify_io(mask, in);
123 /* Close up the EFER gate */
129 return inb(GP1_IO_BASE) | inb(GP2_IO_BASE) << 8;
133 * Initialise the Winbond W83977F global registers
135 static inline void wb977_init_global(void)
138 * Enable R/W config registers
140 wb977_wb(0x26, 0x40);
143 * Power down FDC (not used)
145 wb977_wb(0x22, 0xfe);
148 * GP12, GP11, CIRRX, IRRXH, GP10
150 wb977_wb(0x2a, 0xc1);
153 * GP23, GP22, GP21, GP20, GP13
155 wb977_wb(0x2b, 0x6b);
158 * GP17, GP16, GP15, GP14
160 wb977_wb(0x2c, 0x55);
164 * Initialise the Winbond W83977F printer port
166 static inline void wb977_init_printer(void)
168 wb977_device_select(1);
173 wb977_wb(0xf0, 0x01);
177 * Initialise the Winbond W83977F keyboard controller
179 static inline void wb977_init_keyboard(void)
181 wb977_device_select(5);
184 * Keyboard controller address
186 wb977_ww(0x60, 0x0060);
187 wb977_ww(0x62, 0x0064);
190 * Keyboard IRQ 1, active high, edge trigger
193 wb977_wb(0x71, 0x02);
196 * Mouse IRQ 5, active high, edge trigger
199 wb977_wb(0x73, 0x02);
204 wb977_wb(0xf0, 0x40);
209 wb977_device_enable();
213 * Initialise the Winbond W83977F Infra-Red device
215 static inline void wb977_init_irda(void)
217 wb977_device_select(6);
222 wb977_ww(0x60, IRDA_IO_BASE);
225 * IRDA IRQ 6, active high, edge trigger
228 wb977_wb(0x71, 0x02);
233 wb977_wb(0x74, 0x00);
236 * TX DMA - Disable Tx DMA
238 wb977_wb(0x75, 0x04);
241 * Append CRC, Enable bank selection
243 wb977_wb(0xf0, 0x03);
248 wb977_device_enable();
252 * Initialise Winbond W83977F general purpose IO
254 static inline void wb977_init_gpio(void)
259 * Set up initial I/O definitions
261 current_gpio_io = -1;
262 __gpio_modify_io(-1, GPIO_DONE | GPIO_WDTIMER);
264 wb977_device_select(7);
267 * Group1 base address
269 wb977_ww(0x60, GP1_IO_BASE);
274 * GP10 (Orage button) IRQ 10, active high, edge trigger
277 wb977_wb(0x71, 0x02);
280 * GP10: Debounce filter enabled, IRQ, input
282 wb977_wb(0xe0, 0x19);
287 wb977_device_enable();
289 wb977_device_select(8);
292 * Group2 base address
294 wb977_ww(0x60, GP2_IO_BASE);
297 * Clear watchdog timer regs
300 wb977_wb(0xf2, 0x00);
303 * - disable LED, no mouse nor keyboard IRQ
305 wb977_wb(0xf3, 0x00);
308 * - timer counting, disable power LED, disable timeouot
310 wb977_wb(0xf4, 0x00);
315 wb977_device_enable();
318 * Set Group1/Group2 outputs
320 spin_lock_irqsave(&gpio_lock, flags);
321 gpio_modify_op(-1, GPIO_RED_LED | GPIO_FAN);
322 spin_unlock_irqrestore(&gpio_lock, flags);
326 * Initialise the Winbond W83977F chip.
328 static void __init wb977_init(void)
330 request_region(0x370, 2, "W83977AF configuration");
333 * Open up the SuperIO chip
338 * Initialise the global registers
343 * Initialise the various devices in
346 wb977_init_printer();
347 wb977_init_keyboard();
352 * Close up the EFER gate
357 void cpld_modify(int mask, int set)
361 current_cpld = (current_cpld & ~mask) | set;
363 gpio_modify_io(GPIO_DATA | GPIO_IOCLK | GPIO_IOLOAD, 0);
364 gpio_modify_op(GPIO_IOLOAD, 0);
366 for (msk = 8; msk; msk >>= 1) {
367 int bit = current_cpld & msk;
369 gpio_modify_op(GPIO_DATA | GPIO_IOCLK, bit ? GPIO_DATA : 0);
370 gpio_modify_op(GPIO_IOCLK, GPIO_IOCLK);
373 gpio_modify_op(GPIO_IOCLK|GPIO_DATA, 0);
374 gpio_modify_op(GPIO_IOLOAD|GPIO_DSCLK, GPIO_IOLOAD|GPIO_DSCLK);
375 gpio_modify_op(GPIO_IOLOAD, 0);
378 static void __init cpld_init(void)
382 spin_lock_irqsave(&gpio_lock, flags);
383 cpld_modify(-1, CPLD_UNMUTE | CPLD_7111_DISABLE);
384 spin_unlock_irqrestore(&gpio_lock, flags);
387 static unsigned char rwa_unlock[] __initdata =
388 { 0x00, 0x00, 0x6a, 0xb5, 0xda, 0xed, 0xf6, 0xfb, 0x7d, 0xbe, 0xdf, 0x6f, 0x37, 0x1b,
389 0x0d, 0x86, 0xc3, 0x61, 0xb0, 0x58, 0x2c, 0x16, 0x8b, 0x45, 0xa2, 0xd1, 0xe8, 0x74,
390 0x3a, 0x9d, 0xce, 0xe7, 0x73, 0x39 };
393 #define dprintk(x...)
395 #define dprintk(x...) printk(x)
398 #define WRITE_RWA(r,v) do { outb((r), 0x279); udelay(10); outb((v), 0xa79); } while (0)
400 static inline void rwa010_unlock(void)
407 for (i = 0; i < sizeof(rwa_unlock); i++) {
408 outb(rwa_unlock[i], 0x279);
413 static inline void rwa010_read_ident(void)
425 dprintk("Identifier: ");
426 for (i = 0; i < 9; i++) {
428 for (j = 0; j < 8; j++) {
434 dprintk("%02X ", bit);
435 bit = (bit == 0xaa) ? 1 : 0;
438 dprintk("(%02X) ", si[i]);
443 static inline void rwa010_global_init(void)
445 WRITE_RWA(6, 2); // Assign a card no = 2
447 dprintk("Card no = %d\n", inb(0x203));
449 /* disable the modem section of the chip */
453 /* disable the cdrom section of the chip */
457 /* disable the MPU-401 section of the chip */
462 static inline void rwa010_game_port_init(void)
468 dprintk("Slider base: ");
473 dprintk("%02X%02X (201)\n", inb(0x203), i);
478 static inline void rwa010_waveartist_init(int base, int irq, int dma)
484 dprintk("WaveArtist base: ");
485 WRITE_RWA(0x61, base);
488 WRITE_RWA(0x60, base >> 8);
489 dprintk("%02X%02X (%X),", inb(0x203), i, base);
491 WRITE_RWA(0x70, irq);
492 dprintk(" irq: %d (%d),", inb(0x203), irq);
494 WRITE_RWA(0x74, dma);
495 dprintk(" dma: %d (%d)\n", inb(0x203), dma);
500 static inline void rwa010_soundblaster_init(int sb_base, int al_base, int irq, int dma)
506 dprintk("SoundBlaster base: ");
507 WRITE_RWA(0x61, sb_base);
510 WRITE_RWA(0x60, sb_base >> 8);
511 dprintk("%02X%02X (%X),", inb(0x203), i, sb_base);
514 WRITE_RWA(0x70, irq);
515 dprintk("%d (%d),", inb(0x203), irq);
517 dprintk(" 8-bit DMA: ");
518 WRITE_RWA(0x74, dma);
519 dprintk("%d (%d)\n", inb(0x203), dma);
521 dprintk("AdLib base: ");
522 WRITE_RWA(0x63, al_base);
525 WRITE_RWA(0x62, al_base >> 8);
526 dprintk("%02X%02X (%X)\n", inb(0x203), i, al_base);
531 static void rwa010_soundblaster_reset(void)
539 for (i = 0; i < 5; i++) {
540 if (inb(0x22e) & 0x80)
545 printk("SoundBlaster: DSP reset failed\n");
547 dprintk("SoundBlaster DSP reset: %02X (AA)\n", inb(0x22a));
549 for (i = 0; i < 5; i++) {
550 if ((inb(0x22c) & 0x80) == 0)
556 printk("SoundBlaster: DSP not ready\n");
560 dprintk("SoundBlaster DSP id: ");
563 i |= inb(0x22a) << 8;
564 dprintk("%04X\n", i);
566 for (i = 0; i < 5; i++) {
567 if ((inb(0x22c) & 0x80) == 0)
573 printk("SoundBlaster: could not turn speaker off\n");
583 static void __init rwa010_init(void)
587 rwa010_global_init();
588 rwa010_game_port_init();
589 rwa010_waveartist_init(0x250, 3, 7);
590 rwa010_soundblaster_init(0x220, 0x388, 3, 1);
591 rwa010_soundblaster_reset();
594 EXPORT_SYMBOL(gpio_lock);
595 EXPORT_SYMBOL(gpio_modify_op);
596 EXPORT_SYMBOL(gpio_modify_io);
597 EXPORT_SYMBOL(cpld_modify);
600 * Initialise any other hardware after we've got the PCI bus
601 * initialised. We may need the PCI bus to talk to this other
604 static int __init nw_hw_init(void)
606 if (machine_is_netwinder()) {
613 spin_lock_irqsave(&gpio_lock, flags);
614 gpio_modify_op(GPIO_RED_LED|GPIO_GREEN_LED, DEFAULT_LEDS);
615 spin_unlock_irqrestore(&gpio_lock, flags);
620 __initcall(nw_hw_init);