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>
20 #include <asm/system_misc.h>
22 #include <asm/mach/arch.h>
26 #define IRDA_IO_BASE 0x180
27 #define GP1_IO_BASE 0x338
28 #define GP2_IO_BASE 0x33a
32 #define DEFAULT_LEDS 0
34 #define DEFAULT_LEDS GPIO_GREEN_LED
38 * Winbond WB83977F accessibility stuff
40 static inline void wb977_open(void)
46 static inline void wb977_close(void)
51 static inline void wb977_wb(int reg, int val)
57 static inline void wb977_ww(int reg, int val)
60 outb(val >> 8, 0x371);
62 outb(val & 255, 0x371);
65 #define wb977_device_select(dev) wb977_wb(0x07, dev)
66 #define wb977_device_disable() wb977_wb(0x30, 0x00)
67 #define wb977_device_enable() wb977_wb(0x30, 0x01)
70 * This is a lock for accessing ports GP1_IO_BASE and GP2_IO_BASE
72 DEFINE_RAW_SPINLOCK(nw_gpio_lock);
73 EXPORT_SYMBOL(nw_gpio_lock);
75 static unsigned int current_gpio_op;
76 static unsigned int current_gpio_io;
77 static unsigned int current_cpld;
79 void nw_gpio_modify_op(unsigned int mask, unsigned int set)
81 unsigned int new_gpio, changed;
83 new_gpio = (current_gpio_op & ~mask) | set;
84 changed = new_gpio ^ current_gpio_op;
85 current_gpio_op = new_gpio;
88 outb(new_gpio, GP1_IO_BASE);
90 outb(new_gpio >> 8, GP2_IO_BASE);
92 EXPORT_SYMBOL(nw_gpio_modify_op);
94 static inline void __gpio_modify_io(int mask, int in)
96 unsigned int new_gpio, changed;
99 new_gpio = (current_gpio_io & ~mask) | in;
100 changed = new_gpio ^ current_gpio_io;
101 current_gpio_io = new_gpio;
106 wb977_device_select(7);
108 for (port = 0xe1; changed && port < 0xe8; changed >>= 1) {
109 wb977_wb(port, new_gpio & 1);
115 wb977_device_select(8);
117 for (port = 0xe8; changed && port < 0xec; changed >>= 1) {
118 wb977_wb(port, new_gpio & 1);
125 void nw_gpio_modify_io(unsigned int mask, unsigned int in)
127 /* Open up the SuperIO chip */
130 __gpio_modify_io(mask, in);
132 /* Close up the EFER gate */
135 EXPORT_SYMBOL(nw_gpio_modify_io);
137 unsigned int nw_gpio_read(void)
139 return inb(GP1_IO_BASE) | inb(GP2_IO_BASE) << 8;
141 EXPORT_SYMBOL(nw_gpio_read);
144 * Initialise the Winbond W83977F global registers
146 static inline void wb977_init_global(void)
149 * Enable R/W config registers
151 wb977_wb(0x26, 0x40);
154 * Power down FDC (not used)
156 wb977_wb(0x22, 0xfe);
159 * GP12, GP11, CIRRX, IRRXH, GP10
161 wb977_wb(0x2a, 0xc1);
164 * GP23, GP22, GP21, GP20, GP13
166 wb977_wb(0x2b, 0x6b);
169 * GP17, GP16, GP15, GP14
171 wb977_wb(0x2c, 0x55);
175 * Initialise the Winbond W83977F printer port
177 static inline void wb977_init_printer(void)
179 wb977_device_select(1);
184 wb977_wb(0xf0, 0x01);
188 * Initialise the Winbond W83977F keyboard controller
190 static inline void wb977_init_keyboard(void)
192 wb977_device_select(5);
195 * Keyboard controller address
197 wb977_ww(0x60, 0x0060);
198 wb977_ww(0x62, 0x0064);
201 * Keyboard IRQ 1, active high, edge trigger
204 wb977_wb(0x71, 0x02);
207 * Mouse IRQ 5, active high, edge trigger
210 wb977_wb(0x73, 0x02);
215 wb977_wb(0xf0, 0x40);
220 wb977_device_enable();
224 * Initialise the Winbond W83977F Infra-Red device
226 static inline void wb977_init_irda(void)
228 wb977_device_select(6);
233 wb977_ww(0x60, IRDA_IO_BASE);
236 * IRDA IRQ 6, active high, edge trigger
239 wb977_wb(0x71, 0x02);
244 wb977_wb(0x74, 0x00);
247 * TX DMA - Disable Tx DMA
249 wb977_wb(0x75, 0x04);
252 * Append CRC, Enable bank selection
254 wb977_wb(0xf0, 0x03);
259 wb977_device_enable();
263 * Initialise Winbond W83977F general purpose IO
265 static inline void wb977_init_gpio(void)
270 * Set up initial I/O definitions
272 current_gpio_io = -1;
273 __gpio_modify_io(-1, GPIO_DONE | GPIO_WDTIMER);
275 wb977_device_select(7);
278 * Group1 base address
280 wb977_ww(0x60, GP1_IO_BASE);
285 * GP10 (Orage button) IRQ 10, active high, edge trigger
288 wb977_wb(0x71, 0x02);
291 * GP10: Debounce filter enabled, IRQ, input
293 wb977_wb(0xe0, 0x19);
298 wb977_device_enable();
300 wb977_device_select(8);
303 * Group2 base address
305 wb977_ww(0x60, GP2_IO_BASE);
308 * Clear watchdog timer regs
311 wb977_wb(0xf2, 0x00);
314 * - disable LED, no mouse nor keyboard IRQ
316 wb977_wb(0xf3, 0x00);
319 * - timer counting, disable power LED, disable timeouot
321 wb977_wb(0xf4, 0x00);
326 wb977_device_enable();
329 * Set Group1/Group2 outputs
331 raw_spin_lock_irqsave(&nw_gpio_lock, flags);
332 nw_gpio_modify_op(-1, GPIO_RED_LED | GPIO_FAN);
333 raw_spin_unlock_irqrestore(&nw_gpio_lock, flags);
337 * Initialise the Winbond W83977F chip.
339 static void __init wb977_init(void)
341 request_region(0x370, 2, "W83977AF configuration");
344 * Open up the SuperIO chip
349 * Initialise the global registers
354 * Initialise the various devices in
357 wb977_init_printer();
358 wb977_init_keyboard();
363 * Close up the EFER gate
368 void nw_cpld_modify(unsigned int mask, unsigned int set)
372 current_cpld = (current_cpld & ~mask) | set;
374 nw_gpio_modify_io(GPIO_DATA | GPIO_IOCLK | GPIO_IOLOAD, 0);
375 nw_gpio_modify_op(GPIO_IOLOAD, 0);
377 for (msk = 8; msk; msk >>= 1) {
378 int bit = current_cpld & msk;
380 nw_gpio_modify_op(GPIO_DATA | GPIO_IOCLK, bit ? GPIO_DATA : 0);
381 nw_gpio_modify_op(GPIO_IOCLK, GPIO_IOCLK);
384 nw_gpio_modify_op(GPIO_IOCLK|GPIO_DATA, 0);
385 nw_gpio_modify_op(GPIO_IOLOAD|GPIO_DSCLK, GPIO_IOLOAD|GPIO_DSCLK);
386 nw_gpio_modify_op(GPIO_IOLOAD, 0);
388 EXPORT_SYMBOL(nw_cpld_modify);
390 static void __init cpld_init(void)
394 raw_spin_lock_irqsave(&nw_gpio_lock, flags);
395 nw_cpld_modify(-1, CPLD_UNMUTE | CPLD_7111_DISABLE);
396 raw_spin_unlock_irqrestore(&nw_gpio_lock, flags);
399 static unsigned char rwa_unlock[] __initdata =
400 { 0x00, 0x00, 0x6a, 0xb5, 0xda, 0xed, 0xf6, 0xfb, 0x7d, 0xbe, 0xdf, 0x6f, 0x37, 0x1b,
401 0x0d, 0x86, 0xc3, 0x61, 0xb0, 0x58, 0x2c, 0x16, 0x8b, 0x45, 0xa2, 0xd1, 0xe8, 0x74,
402 0x3a, 0x9d, 0xce, 0xe7, 0x73, 0x39 };
405 #define dprintk(x...)
407 #define dprintk(x...) printk(x)
410 #define WRITE_RWA(r,v) do { outb((r), 0x279); udelay(10); outb((v), 0xa79); } while (0)
412 static inline void rwa010_unlock(void)
419 for (i = 0; i < sizeof(rwa_unlock); i++) {
420 outb(rwa_unlock[i], 0x279);
425 static inline void rwa010_read_ident(void)
437 dprintk("Identifier: ");
438 for (i = 0; i < 9; i++) {
440 for (j = 0; j < 8; j++) {
446 dprintk("%02X ", bit);
447 bit = (bit == 0xaa) ? 1 : 0;
450 dprintk("(%02X) ", si[i]);
455 static inline void rwa010_global_init(void)
457 WRITE_RWA(6, 2); // Assign a card no = 2
459 dprintk("Card no = %d\n", inb(0x203));
461 /* disable the modem section of the chip */
465 /* disable the cdrom section of the chip */
469 /* disable the MPU-401 section of the chip */
474 static inline void rwa010_game_port_init(void)
480 dprintk("Slider base: ");
485 dprintk("%02X%02X (201)\n", inb(0x203), i);
490 static inline void rwa010_waveartist_init(int base, int irq, int dma)
496 dprintk("WaveArtist base: ");
497 WRITE_RWA(0x61, base & 255);
500 WRITE_RWA(0x60, base >> 8);
501 dprintk("%02X%02X (%X),", inb(0x203), i, base);
503 WRITE_RWA(0x70, irq);
504 dprintk(" irq: %d (%d),", inb(0x203), irq);
506 WRITE_RWA(0x74, dma);
507 dprintk(" dma: %d (%d)\n", inb(0x203), dma);
512 static inline void rwa010_soundblaster_init(int sb_base, int al_base, int irq, int dma)
518 dprintk("SoundBlaster base: ");
519 WRITE_RWA(0x61, sb_base & 255);
522 WRITE_RWA(0x60, sb_base >> 8);
523 dprintk("%02X%02X (%X),", inb(0x203), i, sb_base);
526 WRITE_RWA(0x70, irq);
527 dprintk("%d (%d),", inb(0x203), irq);
529 dprintk(" 8-bit DMA: ");
530 WRITE_RWA(0x74, dma);
531 dprintk("%d (%d)\n", inb(0x203), dma);
533 dprintk("AdLib base: ");
534 WRITE_RWA(0x63, al_base & 255);
537 WRITE_RWA(0x62, al_base >> 8);
538 dprintk("%02X%02X (%X)\n", inb(0x203), i, al_base);
543 static void rwa010_soundblaster_reset(void)
551 for (i = 0; i < 5; i++) {
552 if (inb(0x22e) & 0x80)
557 printk("SoundBlaster: DSP reset failed\n");
559 dprintk("SoundBlaster DSP reset: %02X (AA)\n", inb(0x22a));
561 for (i = 0; i < 5; i++) {
562 if ((inb(0x22c) & 0x80) == 0)
568 printk("SoundBlaster: DSP not ready\n");
572 dprintk("SoundBlaster DSP id: ");
575 i |= inb(0x22a) << 8;
576 dprintk("%04X\n", i);
578 for (i = 0; i < 5; i++) {
579 if ((inb(0x22c) & 0x80) == 0)
585 printk("SoundBlaster: could not turn speaker off\n");
595 static void __init rwa010_init(void)
599 rwa010_global_init();
600 rwa010_game_port_init();
601 rwa010_waveartist_init(0x250, 3, 7);
602 rwa010_soundblaster_init(0x220, 0x388, 3, 1);
603 rwa010_soundblaster_reset();
607 * Initialise any other hardware after we've got the PCI bus
608 * initialised. We may need the PCI bus to talk to this other
611 static int __init nw_hw_init(void)
613 if (machine_is_netwinder()) {
620 raw_spin_lock_irqsave(&nw_gpio_lock, flags);
621 nw_gpio_modify_op(GPIO_RED_LED|GPIO_GREEN_LED, DEFAULT_LEDS);
622 raw_spin_unlock_irqrestore(&nw_gpio_lock, flags);
627 __initcall(nw_hw_init);
630 * Older NeTTroms either do not provide a parameters
631 * page, or they don't supply correct information in
632 * the parameter page.
635 fixup_netwinder(struct tag *tags, 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 static void netwinder_restart(char mode, const char *cmd)
652 /* Jump into the ROM */
653 soft_restart(0x41000000);
658 /* open up the SuperIO chip */
662 /* aux function group 1 (logical device 7) */
666 /* set GP16 for WD-TIMER output */
670 /* set a RED LED and toggle WD_TIMER for rebooting */
675 MACHINE_START(NETWINDER, "Rebel-NetWinder")
676 /* Maintainer: Russell King/Rebel.com */
677 .atag_offset = 0x100,
678 .video_start = 0x000a0000,
679 .video_end = 0x000bffff,
682 .fixup = fixup_netwinder,
683 .map_io = footbridge_map_io,
684 .init_irq = footbridge_init_irq,
686 .restart = netwinder_restart,