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/sched.h>
11 #include <linux/ioport.h>
12 #include <linux/kernel.h>
13 #include <linux/delay.h>
14 #include <linux/init.h>
18 #include <asm/mach-types.h>
20 #define IRDA_IO_BASE 0x180
21 #define GP1_IO_BASE 0x338
22 #define GP2_IO_BASE 0x33a
26 #define DEFAULT_LEDS 0
28 #define DEFAULT_LEDS GPIO_GREEN_LED
32 * Winbond WB83977F accessibility stuff
34 static inline void wb977_open(void)
40 static inline void wb977_close(void)
45 static inline void wb977_wb(int reg
, int val
)
51 static inline void wb977_ww(int reg
, int val
)
54 outb(val
>> 8, 0x371);
59 #define wb977_device_select(dev) wb977_wb(0x07, dev)
60 #define wb977_device_disable() wb977_wb(0x30, 0x00)
61 #define wb977_device_enable() wb977_wb(0x30, 0x01)
64 * This is a lock for accessing ports GP1_IO_BASE and GP2_IO_BASE
66 spinlock_t gpio_lock
= SPIN_LOCK_UNLOCKED
;
68 static unsigned int current_gpio_op
= 0;
69 static unsigned int current_gpio_io
= 0;
70 static unsigned int current_cpld
= 0;
72 void gpio_modify_op(int mask
, int set
)
74 unsigned int new_gpio
, changed
;
76 new_gpio
= (current_gpio_op
& ~mask
) | set
;
77 changed
= new_gpio
^ current_gpio_op
;
78 current_gpio_op
= new_gpio
;
81 outb(new_gpio
, GP1_IO_BASE
);
83 outb(new_gpio
>> 8, GP2_IO_BASE
);
86 static inline void __gpio_modify_io(int mask
, int in
)
88 unsigned int new_gpio
, changed
;
91 new_gpio
= (current_gpio_io
& ~mask
) | in
;
92 changed
= new_gpio
^ current_gpio_io
;
93 current_gpio_io
= new_gpio
;
98 wb977_device_select(7);
100 for (port
= 0xe1; changed
&& port
< 0xe8; changed
>>= 1) {
101 wb977_wb(port
, new_gpio
& 1);
107 wb977_device_select(8);
109 for (port
= 0xe8; changed
&& port
< 0xec; changed
>>= 1) {
110 wb977_wb(port
, new_gpio
& 1);
117 void gpio_modify_io(int mask
, int in
)
119 /* Open up the SuperIO chip */
122 __gpio_modify_io(mask
, in
);
124 /* Close up the EFER gate */
130 return inb(GP1_IO_BASE
) | inb(GP2_IO_BASE
) << 8;
134 * Initialise the Winbond W83977F global registers
136 static inline void wb977_init_global(void)
139 * Enable R/W config registers
141 wb977_wb(0x26, 0x40);
144 * Power down FDC (not used)
146 wb977_wb(0x22, 0xfe);
149 * GP12, GP11, CIRRX, IRRXH, GP10
151 wb977_wb(0x2a, 0xc1);
154 * GP23, GP22, GP21, GP20, GP13
156 wb977_wb(0x2b, 0x6b);
159 * GP17, GP16, GP15, GP14
161 wb977_wb(0x2c, 0x55);
165 * Initialise the Winbond W83977F printer port
167 static inline void wb977_init_printer(void)
169 wb977_device_select(1);
174 wb977_wb(0xf0, 0x01);
178 * Initialise the Winbond W83977F keyboard controller
180 static inline void wb977_init_keyboard(void)
182 wb977_device_select(5);
185 * Keyboard controller address
187 wb977_ww(0x60, 0x0060);
188 wb977_ww(0x62, 0x0064);
191 * Keyboard IRQ 1, active high, edge trigger
194 wb977_wb(0x71, 0x02);
197 * Mouse IRQ 5, active high, edge trigger
200 wb977_wb(0x73, 0x02);
205 wb977_wb(0xf0, 0x40);
210 wb977_device_enable();
214 * Initialise the Winbond W83977F Infra-Red device
216 static inline void wb977_init_irda(void)
218 wb977_device_select(6);
223 wb977_ww(0x60, IRDA_IO_BASE
);
226 * IRDA IRQ 6, active high, edge trigger
229 wb977_wb(0x71, 0x02);
234 wb977_wb(0x74, 0x00);
237 * TX DMA - Disable Tx DMA
239 wb977_wb(0x75, 0x04);
242 * Append CRC, Enable bank selection
244 wb977_wb(0xf0, 0x03);
249 wb977_device_enable();
253 * Initialise Winbond W83977F general purpose IO
255 static inline void wb977_init_gpio(void)
260 * Set up initial I/O definitions
262 current_gpio_io
= -1;
263 __gpio_modify_io(-1, GPIO_DONE
| GPIO_WDTIMER
);
265 wb977_device_select(7);
268 * Group1 base address
270 wb977_ww(0x60, GP1_IO_BASE
);
275 * GP10 (Orage button) IRQ 10, active high, edge trigger
278 wb977_wb(0x71, 0x02);
281 * GP10: Debounce filter enabled, IRQ, input
283 wb977_wb(0xe0, 0x19);
288 wb977_device_enable();
290 wb977_device_select(8);
293 * Group2 base address
295 wb977_ww(0x60, GP2_IO_BASE
);
298 * Clear watchdog timer regs
301 wb977_wb(0xf2, 0x00);
304 * - disable LED, no mouse nor keyboard IRQ
306 wb977_wb(0xf3, 0x00);
309 * - timer counting, disable power LED, disable timeouot
311 wb977_wb(0xf4, 0x00);
316 wb977_device_enable();
319 * Set Group1/Group2 outputs
321 spin_lock_irqsave(&gpio_lock
, flags
);
322 gpio_modify_op(-1, GPIO_RED_LED
| GPIO_FAN
);
323 spin_unlock_irqrestore(&gpio_loc
, flags
);
327 * Initialise the Winbond W83977F chip.
329 static void __init
wb977_init(void)
331 request_region(0x370, 2, "W83977AF configuration");
334 * Open up the SuperIO chip
339 * Initialise the global registers
344 * Initialise the various devices in
347 wb977_init_printer();
348 wb977_init_keyboard();
353 * Close up the EFER gate
358 void cpld_modify(int mask
, int set
)
362 current_cpld
= (current_cpld
& ~mask
) | set
;
364 gpio_modify_io(GPIO_DATA
| GPIO_IOCLK
| GPIO_IOLOAD
, 0);
365 gpio_modify_op(GPIO_IOLOAD
, 0);
367 for (msk
= 8; msk
; msk
>>= 1) {
368 int bit
= current_cpld
& msk
;
370 gpio_modify_op(GPIO_DATA
| GPIO_IOCLK
, bit
? GPIO_DATA
: 0);
371 gpio_modify_op(GPIO_IOCLK
, GPIO_IOCLK
);
374 gpio_modify_op(GPIO_IOCLK
|GPIO_DATA
, 0);
375 gpio_modify_op(GPIO_IOLOAD
|GPIO_DSCLK
, GPIO_IOLOAD
|GPIO_DSCLK
);
376 gpio_modify_op(GPIO_IOLOAD
, 0);
379 static void __init
cpld_init(void)
383 spin_lock_irqsave(&gpio_lock
, flags
);
384 cpld_modify(-1, CPLD_UNMUTE
| CPLD_7111_DISABLE
);
385 spin_unlock_irqrestore(&gpio_lock
, flags
);
388 static unsigned char rwa_unlock
[] __initdata
=
389 { 0x00, 0x00, 0x6a, 0xb5, 0xda, 0xed, 0xf6, 0xfb, 0x7d, 0xbe, 0xdf, 0x6f, 0x37, 0x1b,
390 0x0d, 0x86, 0xc3, 0x61, 0xb0, 0x58, 0x2c, 0x16, 0x8b, 0x45, 0xa2, 0xd1, 0xe8, 0x74,
391 0x3a, 0x9d, 0xce, 0xe7, 0x73, 0x39 };
394 #define dprintk(x...)
396 #define dprintk(x...) printk(x)
399 #define WRITE_RWA(r,v) do { outb((r), 0x279); udelay(10); outb((v), 0xa79); } while (0)
401 static inline void rwa010_unlock(void)
408 for (i
= 0; i
< sizeof(rwa_unlock
); i
++) {
409 outb(rwa_unlock
[i
], 0x279);
414 static inline void rwa010_read_ident(void)
426 dprintk("Identifier: ");
427 for (i
= 0; i
< 9; i
++) {
429 for (j
= 0; j
< 8; j
++) {
435 dprintk("%02X ", bit
);
436 bit
= (bit
== 0xaa) ? 1 : 0;
439 dprintk("(%02X) ", si
[i
]);
444 static inline void rwa010_global_init(void)
446 WRITE_RWA(6, 2); // Assign a card no = 2
448 dprintk("Card no = %d\n", inb(0x203));
450 /* disable the modem section of the chip */
454 /* disable the cdrom section of the chip */
458 /* disable the MPU-401 section of the chip */
463 static inline void rwa010_game_port_init(void)
469 dprintk("Slider base: ");
474 dprintk("%02X%02X (201)\n", inb(0x203), i
);
479 static inline void rwa010_waveartist_init(int base
, int irq
, int dma
)
485 dprintk("WaveArtist base: ");
486 WRITE_RWA(0x61, base
);
489 WRITE_RWA(0x60, base
>> 8);
490 dprintk("%02X%02X (%X),", inb(0x203), i
, base
);
492 WRITE_RWA(0x70, irq
);
493 dprintk(" irq: %d (%d),", inb(0x203), irq
);
495 WRITE_RWA(0x74, dma
);
496 dprintk(" dma: %d (%d)\n", inb(0x203), dma
);
501 static inline void rwa010_soundblaster_init(int sb_base
, int al_base
, int irq
, int dma
)
507 dprintk("SoundBlaster base: ");
508 WRITE_RWA(0x61, sb_base
);
511 WRITE_RWA(0x60, sb_base
>> 8);
512 dprintk("%02X%02X (%X),", inb(0x203), i
, sb_base
);
515 WRITE_RWA(0x70, irq
);
516 dprintk("%d (%d),", inb(0x203), irq
);
518 dprintk(" 8-bit DMA: ");
519 WRITE_RWA(0x74, dma
);
520 dprintk("%d (%d)\n", inb(0x203), dma
);
522 dprintk("AdLib base: ");
523 WRITE_RWA(0x63, al_base
);
526 WRITE_RWA(0x62, al_base
>> 8);
527 dprintk("%02X%02X (%X)\n", inb(0x203), i
, al_base
);
532 static void rwa010_soundblaster_reset(void)
540 for (i
= 0; i
< 5; i
++) {
541 if (inb(0x22e) & 0x80)
546 printk("SoundBlaster: DSP reset failed\n");
548 dprintk("SoundBlaster DSP reset: %02X (AA)\n", inb(0x22a));
550 for (i
= 0; i
< 5; i
++) {
551 if ((inb(0x22c) & 0x80) == 0)
557 printk("SoundBlaster: DSP not ready\n");
561 dprintk("SoundBlaster DSP id: ");
564 i
|= inb(0x22a) << 8;
565 dprintk("%04X\n", i
);
567 for (i
= 0; i
< 5; i
++) {
568 if ((inb(0x22c) & 0x80) == 0)
574 printk("SoundBlaster: could not turn speaker off\n");
584 static void __init
rwa010_init(void)
588 rwa010_global_init();
589 rwa010_game_port_init();
590 rwa010_waveartist_init(0x250, 3, 7);
591 rwa010_soundblaster_init(0x220, 0x388, 3, 1);
592 rwa010_soundblaster_reset();
595 EXPORT_SYMBOL(gpio_lock
);
596 EXPORT_SYMBOL(gpio_modify_op
);
597 EXPORT_SYMBOL(gpio_modify_io
);
598 EXPORT_SYMBOL(cpld_modify
);
601 * Initialise any other hardware after we've got the PCI bus
602 * initialised. We may need the PCI bus to talk to this other
605 static int __init
nw_hw_init(void)
607 if (machine_is_netwinder()) {
614 spin_lock_irqsave(&gpio_lock
, flags
);
615 gpio_modify_op(GPIO_RED_LED
|GPIO_GREEN_LED
, DEFAULT_LEDS
);
616 spin_unlock_irqrestore(&gpio_lock
, flags
);
621 __initcall(nw_hw_init
);