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/module.h>
9 #include <linux/ioport.h>
10 #include <linux/kernel.h>
11 #include <linux/delay.h>
12 #include <linux/init.h>
15 #include <asm/hardware/dec21285.h>
17 #include <asm/mach-types.h>
18 #include <asm/setup.h>
20 #include <asm/mach/arch.h>
24 #define IRDA_IO_BASE 0x180
25 #define GP1_IO_BASE 0x338
26 #define GP2_IO_BASE 0x33a
30 #define DEFAULT_LEDS 0
32 #define DEFAULT_LEDS GPIO_GREEN_LED
36 * Winbond WB83977F accessibility stuff
38 static inline void wb977_open(void)
44 static inline void wb977_close(void)
49 static inline void wb977_wb(int reg, int val)
55 static inline void wb977_ww(int reg, int val)
58 outb(val >> 8, 0x371);
60 outb(val & 255, 0x371);
63 #define wb977_device_select(dev) wb977_wb(0x07, dev)
64 #define wb977_device_disable() wb977_wb(0x30, 0x00)
65 #define wb977_device_enable() wb977_wb(0x30, 0x01)
68 * This is a lock for accessing ports GP1_IO_BASE and GP2_IO_BASE
70 DEFINE_SPINLOCK(gpio_lock);
72 static unsigned int current_gpio_op;
73 static unsigned int current_gpio_io;
74 static unsigned int current_cpld;
76 void gpio_modify_op(int mask, int set)
78 unsigned int new_gpio, changed;
80 new_gpio = (current_gpio_op & ~mask) | set;
81 changed = new_gpio ^ current_gpio_op;
82 current_gpio_op = new_gpio;
85 outb(new_gpio, GP1_IO_BASE);
87 outb(new_gpio >> 8, GP2_IO_BASE);
90 static inline void __gpio_modify_io(int mask, int in)
92 unsigned int new_gpio, changed;
95 new_gpio = (current_gpio_io & ~mask) | in;
96 changed = new_gpio ^ current_gpio_io;
97 current_gpio_io = new_gpio;
102 wb977_device_select(7);
104 for (port = 0xe1; changed && port < 0xe8; changed >>= 1) {
105 wb977_wb(port, new_gpio & 1);
111 wb977_device_select(8);
113 for (port = 0xe8; changed && port < 0xec; changed >>= 1) {
114 wb977_wb(port, new_gpio & 1);
121 void gpio_modify_io(int mask, int in)
123 /* Open up the SuperIO chip */
126 __gpio_modify_io(mask, in);
128 /* Close up the EFER gate */
134 return inb(GP1_IO_BASE) | inb(GP2_IO_BASE) << 8;
138 * Initialise the Winbond W83977F global registers
140 static inline void wb977_init_global(void)
143 * Enable R/W config registers
145 wb977_wb(0x26, 0x40);
148 * Power down FDC (not used)
150 wb977_wb(0x22, 0xfe);
153 * GP12, GP11, CIRRX, IRRXH, GP10
155 wb977_wb(0x2a, 0xc1);
158 * GP23, GP22, GP21, GP20, GP13
160 wb977_wb(0x2b, 0x6b);
163 * GP17, GP16, GP15, GP14
165 wb977_wb(0x2c, 0x55);
169 * Initialise the Winbond W83977F printer port
171 static inline void wb977_init_printer(void)
173 wb977_device_select(1);
178 wb977_wb(0xf0, 0x01);
182 * Initialise the Winbond W83977F keyboard controller
184 static inline void wb977_init_keyboard(void)
186 wb977_device_select(5);
189 * Keyboard controller address
191 wb977_ww(0x60, 0x0060);
192 wb977_ww(0x62, 0x0064);
195 * Keyboard IRQ 1, active high, edge trigger
198 wb977_wb(0x71, 0x02);
201 * Mouse IRQ 5, active high, edge trigger
204 wb977_wb(0x73, 0x02);
209 wb977_wb(0xf0, 0x40);
214 wb977_device_enable();
218 * Initialise the Winbond W83977F Infra-Red device
220 static inline void wb977_init_irda(void)
222 wb977_device_select(6);
227 wb977_ww(0x60, IRDA_IO_BASE);
230 * IRDA IRQ 6, active high, edge trigger
233 wb977_wb(0x71, 0x02);
238 wb977_wb(0x74, 0x00);
241 * TX DMA - Disable Tx DMA
243 wb977_wb(0x75, 0x04);
246 * Append CRC, Enable bank selection
248 wb977_wb(0xf0, 0x03);
253 wb977_device_enable();
257 * Initialise Winbond W83977F general purpose IO
259 static inline void wb977_init_gpio(void)
264 * Set up initial I/O definitions
266 current_gpio_io = -1;
267 __gpio_modify_io(-1, GPIO_DONE | GPIO_WDTIMER);
269 wb977_device_select(7);
272 * Group1 base address
274 wb977_ww(0x60, GP1_IO_BASE);
279 * GP10 (Orage button) IRQ 10, active high, edge trigger
282 wb977_wb(0x71, 0x02);
285 * GP10: Debounce filter enabled, IRQ, input
287 wb977_wb(0xe0, 0x19);
292 wb977_device_enable();
294 wb977_device_select(8);
297 * Group2 base address
299 wb977_ww(0x60, GP2_IO_BASE);
302 * Clear watchdog timer regs
305 wb977_wb(0xf2, 0x00);
308 * - disable LED, no mouse nor keyboard IRQ
310 wb977_wb(0xf3, 0x00);
313 * - timer counting, disable power LED, disable timeouot
315 wb977_wb(0xf4, 0x00);
320 wb977_device_enable();
323 * Set Group1/Group2 outputs
325 spin_lock_irqsave(&gpio_lock, flags);
326 gpio_modify_op(-1, GPIO_RED_LED | GPIO_FAN);
327 spin_unlock_irqrestore(&gpio_lock, flags);
331 * Initialise the Winbond W83977F chip.
333 static void __init wb977_init(void)
335 request_region(0x370, 2, "W83977AF configuration");
338 * Open up the SuperIO chip
343 * Initialise the global registers
348 * Initialise the various devices in
351 wb977_init_printer();
352 wb977_init_keyboard();
357 * Close up the EFER gate
362 void cpld_modify(int mask, int set)
366 current_cpld = (current_cpld & ~mask) | set;
368 gpio_modify_io(GPIO_DATA | GPIO_IOCLK | GPIO_IOLOAD, 0);
369 gpio_modify_op(GPIO_IOLOAD, 0);
371 for (msk = 8; msk; msk >>= 1) {
372 int bit = current_cpld & msk;
374 gpio_modify_op(GPIO_DATA | GPIO_IOCLK, bit ? GPIO_DATA : 0);
375 gpio_modify_op(GPIO_IOCLK, GPIO_IOCLK);
378 gpio_modify_op(GPIO_IOCLK|GPIO_DATA, 0);
379 gpio_modify_op(GPIO_IOLOAD|GPIO_DSCLK, GPIO_IOLOAD|GPIO_DSCLK);
380 gpio_modify_op(GPIO_IOLOAD, 0);
383 static void __init cpld_init(void)
387 spin_lock_irqsave(&gpio_lock, flags);
388 cpld_modify(-1, CPLD_UNMUTE | CPLD_7111_DISABLE);
389 spin_unlock_irqrestore(&gpio_lock, flags);
392 static unsigned char rwa_unlock[] __initdata =
393 { 0x00, 0x00, 0x6a, 0xb5, 0xda, 0xed, 0xf6, 0xfb, 0x7d, 0xbe, 0xdf, 0x6f, 0x37, 0x1b,
394 0x0d, 0x86, 0xc3, 0x61, 0xb0, 0x58, 0x2c, 0x16, 0x8b, 0x45, 0xa2, 0xd1, 0xe8, 0x74,
395 0x3a, 0x9d, 0xce, 0xe7, 0x73, 0x39 };
398 #define dprintk(x...)
400 #define dprintk(x...) printk(x)
403 #define WRITE_RWA(r,v) do { outb((r), 0x279); udelay(10); outb((v), 0xa79); } while (0)
405 static inline void rwa010_unlock(void)
412 for (i = 0; i < sizeof(rwa_unlock); i++) {
413 outb(rwa_unlock[i], 0x279);
418 static inline void rwa010_read_ident(void)
430 dprintk("Identifier: ");
431 for (i = 0; i < 9; i++) {
433 for (j = 0; j < 8; j++) {
439 dprintk("%02X ", bit);
440 bit = (bit == 0xaa) ? 1 : 0;
443 dprintk("(%02X) ", si[i]);
448 static inline void rwa010_global_init(void)
450 WRITE_RWA(6, 2); // Assign a card no = 2
452 dprintk("Card no = %d\n", inb(0x203));
454 /* disable the modem section of the chip */
458 /* disable the cdrom section of the chip */
462 /* disable the MPU-401 section of the chip */
467 static inline void rwa010_game_port_init(void)
473 dprintk("Slider base: ");
478 dprintk("%02X%02X (201)\n", inb(0x203), i);
483 static inline void rwa010_waveartist_init(int base, int irq, int dma)
489 dprintk("WaveArtist base: ");
490 WRITE_RWA(0x61, base & 255);
493 WRITE_RWA(0x60, base >> 8);
494 dprintk("%02X%02X (%X),", inb(0x203), i, base);
496 WRITE_RWA(0x70, irq);
497 dprintk(" irq: %d (%d),", inb(0x203), irq);
499 WRITE_RWA(0x74, dma);
500 dprintk(" dma: %d (%d)\n", inb(0x203), dma);
505 static inline void rwa010_soundblaster_init(int sb_base, int al_base, int irq, int dma)
511 dprintk("SoundBlaster base: ");
512 WRITE_RWA(0x61, sb_base & 255);
515 WRITE_RWA(0x60, sb_base >> 8);
516 dprintk("%02X%02X (%X),", inb(0x203), i, sb_base);
519 WRITE_RWA(0x70, irq);
520 dprintk("%d (%d),", inb(0x203), irq);
522 dprintk(" 8-bit DMA: ");
523 WRITE_RWA(0x74, dma);
524 dprintk("%d (%d)\n", inb(0x203), dma);
526 dprintk("AdLib base: ");
527 WRITE_RWA(0x63, al_base & 255);
530 WRITE_RWA(0x62, al_base >> 8);
531 dprintk("%02X%02X (%X)\n", inb(0x203), i, al_base);
536 static void rwa010_soundblaster_reset(void)
544 for (i = 0; i < 5; i++) {
545 if (inb(0x22e) & 0x80)
550 printk("SoundBlaster: DSP reset failed\n");
552 dprintk("SoundBlaster DSP reset: %02X (AA)\n", inb(0x22a));
554 for (i = 0; i < 5; i++) {
555 if ((inb(0x22c) & 0x80) == 0)
561 printk("SoundBlaster: DSP not ready\n");
565 dprintk("SoundBlaster DSP id: ");
568 i |= inb(0x22a) << 8;
569 dprintk("%04X\n", i);
571 for (i = 0; i < 5; i++) {
572 if ((inb(0x22c) & 0x80) == 0)
578 printk("SoundBlaster: could not turn speaker off\n");
588 static void __init rwa010_init(void)
592 rwa010_global_init();
593 rwa010_game_port_init();
594 rwa010_waveartist_init(0x250, 3, 7);
595 rwa010_soundblaster_init(0x220, 0x388, 3, 1);
596 rwa010_soundblaster_reset();
599 EXPORT_SYMBOL(gpio_lock);
600 EXPORT_SYMBOL(gpio_modify_op);
601 EXPORT_SYMBOL(gpio_modify_io);
602 EXPORT_SYMBOL(cpld_modify);
603 EXPORT_SYMBOL(gpio_read);
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
610 static int __init nw_hw_init(void)
612 if (machine_is_netwinder()) {
619 spin_lock_irqsave(&gpio_lock, flags);
620 gpio_modify_op(GPIO_RED_LED|GPIO_GREEN_LED, DEFAULT_LEDS);
621 spin_unlock_irqrestore(&gpio_lock, flags);
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.
634 fixup_netwinder(struct machine_desc *desc, struct tag *tags,
635 char **cmdline, struct meminfo *mi)
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.
649 MACHINE_START(NETWINDER, "Rebel-NetWinder")
650 /* Maintainer: Russell King/Rebel.com */
651 .phys_io = DC21285_ARMCSR_BASE,
652 .io_pg_offst = ((0xfe000000) >> 18) & 0xfffc,
653 .boot_params = 0x00000100,
654 .video_start = 0x000a0000,
655 .video_end = 0x000bffff,
658 .fixup = fixup_netwinder,
659 .map_io = footbridge_map_io,
660 .init_irq = footbridge_init_irq,