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>
14 #include <linux/spinlock.h>
16 #include <asm/hardware/dec21285.h>
18 #include <asm/mach-types.h>
19 #include <asm/setup.h>
21 #include <asm/mach/arch.h>
25 #define IRDA_IO_BASE 0x180
26 #define GP1_IO_BASE 0x338
27 #define GP2_IO_BASE 0x33a
31 #define DEFAULT_LEDS 0
33 #define DEFAULT_LEDS GPIO_GREEN_LED
37 * Winbond WB83977F accessibility stuff
39 static inline void wb977_open(void)
45 static inline void wb977_close(void)
50 static inline void wb977_wb(int reg, int val)
56 static inline void wb977_ww(int reg, int val)
59 outb(val >> 8, 0x371);
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;
87 outb(new_gpio, GP1_IO_BASE);
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;
98 new_gpio = (current_gpio_io & ~mask) | in;
99 changed = new_gpio ^ current_gpio_io;
100 current_gpio_io = new_gpio;
105 wb977_device_select(7);
107 for (port = 0xe1; changed && port < 0xe8; changed >>= 1) {
108 wb977_wb(port, new_gpio & 1);
114 wb977_device_select(8);
116 for (port = 0xe8; changed && port < 0xec; changed >>= 1) {
117 wb977_wb(port, new_gpio & 1);
124 void nw_gpio_modify_io(unsigned int mask, unsigned int in)
126 /* Open up the SuperIO chip */
129 __gpio_modify_io(mask, in);
131 /* Close up the EFER gate */
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);
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
203 wb977_wb(0x71, 0x02);
206 * Mouse IRQ 5, active high, edge trigger
209 wb977_wb(0x73, 0x02);
214 wb977_wb(0xf0, 0x40);
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);
232 wb977_ww(0x60, IRDA_IO_BASE);
235 * IRDA IRQ 6, active high, edge trigger
238 wb977_wb(0x71, 0x02);
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);
258 wb977_device_enable();
262 * Initialise Winbond W83977F general purpose IO
264 static inline void wb977_init_gpio(void)
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);
284 * GP10 (Orage button) IRQ 10, active high, edge trigger
287 wb977_wb(0x71, 0x02);
290 * GP10: Debounce filter enabled, IRQ, input
292 wb977_wb(0xe0, 0x19);
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
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);
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
348 * Initialise the global registers
353 * Initialise the various devices in
356 wb977_init_printer();
357 wb977_init_keyboard();
362 * Close up the EFER gate
367 void nw_cpld_modify(unsigned int mask, unsigned int set)
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)
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 };
404 #define dprintk(x...)
406 #define dprintk(x...) printk(x)
409 #define WRITE_RWA(r,v) do { outb((r), 0x279); udelay(10); outb((v), 0xa79); } while (0)
411 static inline void rwa010_unlock(void)
418 for (i = 0; i < sizeof(rwa_unlock); i++) {
419 outb(rwa_unlock[i], 0x279);
424 static inline void rwa010_read_ident(void)
436 dprintk("Identifier: ");
437 for (i = 0; i < 9; i++) {
439 for (j = 0; j < 8; j++) {
445 dprintk("%02X ", bit);
446 bit = (bit == 0xaa) ? 1 : 0;
449 dprintk("(%02X) ", si[i]);
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 */
464 /* disable the cdrom section of the chip */
468 /* disable the MPU-401 section of the chip */
473 static inline void rwa010_game_port_init(void)
479 dprintk("Slider base: ");
484 dprintk("%02X%02X (201)\n", inb(0x203), i);
489 static inline void rwa010_waveartist_init(int base, int irq, int dma)
495 dprintk("WaveArtist base: ");
496 WRITE_RWA(0x61, base & 255);
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);
511 static inline void rwa010_soundblaster_init(int sb_base, int al_base, int irq, int dma)
517 dprintk("SoundBlaster base: ");
518 WRITE_RWA(0x61, sb_base & 255);
521 WRITE_RWA(0x60, sb_base >> 8);
522 dprintk("%02X%02X (%X),", inb(0x203), i, sb_base);
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);
536 WRITE_RWA(0x62, al_base >> 8);
537 dprintk("%02X%02X (%X)\n", inb(0x203), i, al_base);
542 static void rwa010_soundblaster_reset(void)
550 for (i = 0; i < 5; i++) {
551 if (inb(0x22e) & 0x80)
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)
567 printk("SoundBlaster: DSP not ready\n");
571 dprintk("SoundBlaster DSP id: ");
574 i |= inb(0x22a) << 8;
575 dprintk("%04X\n", i);
577 for (i = 0; i < 5; i++) {
578 if ((inb(0x22c) & 0x80) == 0)
584 printk("SoundBlaster: could not turn speaker off\n");
594 static void __init rwa010_init(void)
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
610 static int __init nw_hw_init(void)
612 if (machine_is_netwinder()) {
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);
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,