1 // SPDX-License-Identifier: GPL-2.0
3 * linux/arch/arm/mach-footbridge/netwinder-hw.c
5 * Netwinder machine fixup
7 * Copyright (C) 1998, 1999 Russell King, Phil Blundell
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>
15 #include <linux/spinlock.h>
16 #include <linux/slab.h>
17 #include <linux/leds.h>
19 #include <asm/hardware/dec21285.h>
20 #include <asm/mach-types.h>
21 #include <asm/setup.h>
22 #include <asm/system_misc.h>
24 #include <asm/mach/arch.h>
28 #define IRDA_IO_BASE 0x180
29 #define GP1_IO_BASE 0x338
30 #define GP2_IO_BASE 0x33a
33 * Winbond WB83977F accessibility stuff
35 static inline void wb977_open(void)
41 static inline void wb977_close(void)
46 static inline void wb977_wb(int reg
, int val
)
52 static inline void wb977_ww(int reg
, int val
)
55 outb(val
>> 8, 0x371);
57 outb(val
& 255, 0x371);
60 #define wb977_device_select(dev) wb977_wb(0x07, dev)
61 #define wb977_device_disable() wb977_wb(0x30, 0x00)
62 #define wb977_device_enable() wb977_wb(0x30, 0x01)
65 * This is a lock for accessing ports GP1_IO_BASE and GP2_IO_BASE
67 DEFINE_RAW_SPINLOCK(nw_gpio_lock
);
68 EXPORT_SYMBOL(nw_gpio_lock
);
70 static unsigned int current_gpio_op
;
71 static unsigned int current_gpio_io
;
72 static unsigned int current_cpld
;
74 void nw_gpio_modify_op(unsigned int mask
, unsigned int set
)
76 unsigned int new_gpio
, changed
;
78 new_gpio
= (current_gpio_op
& ~mask
) | set
;
79 changed
= new_gpio
^ current_gpio_op
;
80 current_gpio_op
= new_gpio
;
83 outb(new_gpio
, GP1_IO_BASE
);
85 outb(new_gpio
>> 8, GP2_IO_BASE
);
87 EXPORT_SYMBOL(nw_gpio_modify_op
);
89 static inline void __gpio_modify_io(int mask
, int in
)
91 unsigned int new_gpio
, changed
;
94 new_gpio
= (current_gpio_io
& ~mask
) | in
;
95 changed
= new_gpio
^ current_gpio_io
;
96 current_gpio_io
= new_gpio
;
101 wb977_device_select(7);
103 for (port
= 0xe1; changed
&& port
< 0xe8; changed
>>= 1) {
104 wb977_wb(port
, new_gpio
& 1);
110 wb977_device_select(8);
112 for (port
= 0xe8; changed
&& port
< 0xec; changed
>>= 1) {
113 wb977_wb(port
, new_gpio
& 1);
120 void nw_gpio_modify_io(unsigned int mask
, unsigned int in
)
122 /* Open up the SuperIO chip */
125 __gpio_modify_io(mask
, in
);
127 /* Close up the EFER gate */
130 EXPORT_SYMBOL(nw_gpio_modify_io
);
132 unsigned int nw_gpio_read(void)
134 return inb(GP1_IO_BASE
) | inb(GP2_IO_BASE
) << 8;
136 EXPORT_SYMBOL(nw_gpio_read
);
139 * Initialise the Winbond W83977F global registers
141 static inline void wb977_init_global(void)
144 * Enable R/W config registers
146 wb977_wb(0x26, 0x40);
149 * Power down FDC (not used)
151 wb977_wb(0x22, 0xfe);
154 * GP12, GP11, CIRRX, IRRXH, GP10
156 wb977_wb(0x2a, 0xc1);
159 * GP23, GP22, GP21, GP20, GP13
161 wb977_wb(0x2b, 0x6b);
164 * GP17, GP16, GP15, GP14
166 wb977_wb(0x2c, 0x55);
170 * Initialise the Winbond W83977F printer port
172 static inline void wb977_init_printer(void)
174 wb977_device_select(1);
179 wb977_wb(0xf0, 0x01);
183 * Initialise the Winbond W83977F keyboard controller
185 static inline void wb977_init_keyboard(void)
187 wb977_device_select(5);
190 * Keyboard controller address
192 wb977_ww(0x60, 0x0060);
193 wb977_ww(0x62, 0x0064);
196 * Keyboard IRQ 1, active high, edge trigger
199 wb977_wb(0x71, 0x02);
202 * Mouse IRQ 5, active high, edge trigger
205 wb977_wb(0x73, 0x02);
210 wb977_wb(0xf0, 0x40);
215 wb977_device_enable();
219 * Initialise the Winbond W83977F Infra-Red device
221 static inline void wb977_init_irda(void)
223 wb977_device_select(6);
228 wb977_ww(0x60, IRDA_IO_BASE
);
231 * IRDA IRQ 6, active high, edge trigger
234 wb977_wb(0x71, 0x02);
239 wb977_wb(0x74, 0x00);
242 * TX DMA - Disable Tx DMA
244 wb977_wb(0x75, 0x04);
247 * Append CRC, Enable bank selection
249 wb977_wb(0xf0, 0x03);
254 wb977_device_enable();
258 * Initialise Winbond W83977F general purpose IO
260 static inline void wb977_init_gpio(void)
265 * Set up initial I/O definitions
267 current_gpio_io
= -1;
268 __gpio_modify_io(-1, GPIO_DONE
| GPIO_WDTIMER
);
270 wb977_device_select(7);
273 * Group1 base address
275 wb977_ww(0x60, GP1_IO_BASE
);
280 * GP10 (Orage button) IRQ 10, active high, edge trigger
283 wb977_wb(0x71, 0x02);
286 * GP10: Debounce filter enabled, IRQ, input
288 wb977_wb(0xe0, 0x19);
293 wb977_device_enable();
295 wb977_device_select(8);
298 * Group2 base address
300 wb977_ww(0x60, GP2_IO_BASE
);
303 * Clear watchdog timer regs
306 wb977_wb(0xf2, 0x00);
309 * - disable LED, no mouse nor keyboard IRQ
311 wb977_wb(0xf3, 0x00);
314 * - timer counting, disable power LED, disable timeouot
316 wb977_wb(0xf4, 0x00);
321 wb977_device_enable();
324 * Set Group1/Group2 outputs
326 raw_spin_lock_irqsave(&nw_gpio_lock
, flags
);
327 nw_gpio_modify_op(-1, GPIO_RED_LED
| GPIO_FAN
);
328 raw_spin_unlock_irqrestore(&nw_gpio_lock
, flags
);
332 * Initialise the Winbond W83977F chip.
334 static void __init
wb977_init(void)
336 request_region(0x370, 2, "W83977AF configuration");
339 * Open up the SuperIO chip
344 * Initialise the global registers
349 * Initialise the various devices in
352 wb977_init_printer();
353 wb977_init_keyboard();
358 * Close up the EFER gate
363 void nw_cpld_modify(unsigned int mask
, unsigned int set
)
367 current_cpld
= (current_cpld
& ~mask
) | set
;
369 nw_gpio_modify_io(GPIO_DATA
| GPIO_IOCLK
| GPIO_IOLOAD
, 0);
370 nw_gpio_modify_op(GPIO_IOLOAD
, 0);
372 for (msk
= 8; msk
; msk
>>= 1) {
373 int bit
= current_cpld
& msk
;
375 nw_gpio_modify_op(GPIO_DATA
| GPIO_IOCLK
, bit
? GPIO_DATA
: 0);
376 nw_gpio_modify_op(GPIO_IOCLK
, GPIO_IOCLK
);
379 nw_gpio_modify_op(GPIO_IOCLK
|GPIO_DATA
, 0);
380 nw_gpio_modify_op(GPIO_IOLOAD
|GPIO_DSCLK
, GPIO_IOLOAD
|GPIO_DSCLK
);
381 nw_gpio_modify_op(GPIO_IOLOAD
, 0);
383 EXPORT_SYMBOL(nw_cpld_modify
);
385 static void __init
cpld_init(void)
389 raw_spin_lock_irqsave(&nw_gpio_lock
, flags
);
390 nw_cpld_modify(-1, CPLD_UNMUTE
| CPLD_7111_DISABLE
);
391 raw_spin_unlock_irqrestore(&nw_gpio_lock
, flags
);
394 static unsigned char rwa_unlock
[] __initdata
=
395 { 0x00, 0x00, 0x6a, 0xb5, 0xda, 0xed, 0xf6, 0xfb, 0x7d, 0xbe, 0xdf, 0x6f, 0x37, 0x1b,
396 0x0d, 0x86, 0xc3, 0x61, 0xb0, 0x58, 0x2c, 0x16, 0x8b, 0x45, 0xa2, 0xd1, 0xe8, 0x74,
397 0x3a, 0x9d, 0xce, 0xe7, 0x73, 0x39 };
400 #define dprintk(x...)
402 #define dprintk(x...) printk(x)
405 #define WRITE_RWA(r,v) do { outb((r), 0x279); udelay(10); outb((v), 0xa79); } while (0)
407 static inline void rwa010_unlock(void)
414 for (i
= 0; i
< sizeof(rwa_unlock
); i
++) {
415 outb(rwa_unlock
[i
], 0x279);
420 static inline void rwa010_read_ident(void)
432 dprintk("Identifier: ");
433 for (i
= 0; i
< 9; i
++) {
435 for (j
= 0; j
< 8; j
++) {
441 dprintk("%02X ", bit
);
442 bit
= (bit
== 0xaa) ? 1 : 0;
445 dprintk("(%02X) ", si
[i
]);
450 static inline void rwa010_global_init(void)
452 WRITE_RWA(6, 2); // Assign a card no = 2
454 dprintk("Card no = %d\n", inb(0x203));
456 /* disable the modem section of the chip */
460 /* disable the cdrom section of the chip */
464 /* disable the MPU-401 section of the chip */
469 static inline void rwa010_game_port_init(void)
475 dprintk("Slider base: ");
480 dprintk("%02X%02X (201)\n", inb(0x203), i
);
485 static inline void rwa010_waveartist_init(int base
, int irq
, int dma
)
491 dprintk("WaveArtist base: ");
492 WRITE_RWA(0x61, base
& 255);
495 WRITE_RWA(0x60, base
>> 8);
496 dprintk("%02X%02X (%X),", inb(0x203), i
, base
);
498 WRITE_RWA(0x70, irq
);
499 dprintk(" irq: %d (%d),", inb(0x203), irq
);
501 WRITE_RWA(0x74, dma
);
502 dprintk(" dma: %d (%d)\n", inb(0x203), dma
);
507 static inline void rwa010_soundblaster_init(int sb_base
, int al_base
, int irq
, int dma
)
513 dprintk("SoundBlaster base: ");
514 WRITE_RWA(0x61, sb_base
& 255);
517 WRITE_RWA(0x60, sb_base
>> 8);
518 dprintk("%02X%02X (%X),", inb(0x203), i
, sb_base
);
521 WRITE_RWA(0x70, irq
);
522 dprintk("%d (%d),", inb(0x203), irq
);
524 dprintk(" 8-bit DMA: ");
525 WRITE_RWA(0x74, dma
);
526 dprintk("%d (%d)\n", inb(0x203), dma
);
528 dprintk("AdLib base: ");
529 WRITE_RWA(0x63, al_base
& 255);
532 WRITE_RWA(0x62, al_base
>> 8);
533 dprintk("%02X%02X (%X)\n", inb(0x203), i
, al_base
);
538 static void rwa010_soundblaster_reset(void)
546 for (i
= 0; i
< 5; i
++) {
547 if (inb(0x22e) & 0x80)
552 printk("SoundBlaster: DSP reset failed\n");
554 dprintk("SoundBlaster DSP reset: %02X (AA)\n", inb(0x22a));
556 for (i
= 0; i
< 5; i
++) {
557 if ((inb(0x22c) & 0x80) == 0)
563 printk("SoundBlaster: DSP not ready\n");
567 dprintk("SoundBlaster DSP id: ");
570 i
|= inb(0x22a) << 8;
571 dprintk("%04X\n", i
);
573 for (i
= 0; i
< 5; i
++) {
574 if ((inb(0x22c) & 0x80) == 0)
580 printk("SoundBlaster: could not turn speaker off\n");
590 static void __init
rwa010_init(void)
594 rwa010_global_init();
595 rwa010_game_port_init();
596 rwa010_waveartist_init(0x250, 3, 7);
597 rwa010_soundblaster_init(0x220, 0x388, 3, 1);
598 rwa010_soundblaster_reset();
602 * Initialise any other hardware after we've got the PCI bus
603 * initialised. We may need the PCI bus to talk to this other
606 static int __init
nw_hw_init(void)
608 if (machine_is_netwinder()) {
616 __initcall(nw_hw_init
);
619 * Older NeTTroms either do not provide a parameters
620 * page, or they don't supply correct information in
621 * the parameter page.
624 fixup_netwinder(struct tag
*tags
, char **cmdline
)
627 extern int isapnp_disable
;
630 * We must not use the kernels ISAPnP code
631 * on the NetWinder - it will reset the settings
632 * for the WaveArtist chip and render it inoperable.
638 static void netwinder_restart(enum reboot_mode mode
, const char *cmd
)
640 if (mode
== REBOOT_SOFT
) {
641 /* Jump into the ROM */
642 soft_restart(0x41000000);
647 /* open up the SuperIO chip */
651 /* aux function group 1 (logical device 7) */
655 /* set GP16 for WD-TIMER output */
659 /* set a RED LED and toggle WD_TIMER for rebooting */
665 #if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS)
666 struct netwinder_led
{
667 struct led_classdev cdev
;
672 * The triggers lines up below will only be used if the
673 * LED triggers are compiled in.
675 static const struct {
678 } netwinder_leds
[] = {
679 { "netwinder:green", "heartbeat", },
680 { "netwinder:red", "cpu0", },
684 * The LED control in Netwinder is reversed:
685 * - setting bit means turn off LED
686 * - clearing bit means turn on LED
688 static void netwinder_led_set(struct led_classdev
*cdev
,
689 enum led_brightness b
)
691 struct netwinder_led
*led
= container_of(cdev
,
692 struct netwinder_led
, cdev
);
696 raw_spin_lock_irqsave(&nw_gpio_lock
, flags
);
697 reg
= nw_gpio_read();
702 nw_gpio_modify_op(led
->mask
, reg
);
703 raw_spin_unlock_irqrestore(&nw_gpio_lock
, flags
);
706 static enum led_brightness
netwinder_led_get(struct led_classdev
*cdev
)
708 struct netwinder_led
*led
= container_of(cdev
,
709 struct netwinder_led
, cdev
);
713 raw_spin_lock_irqsave(&nw_gpio_lock
, flags
);
714 reg
= nw_gpio_read();
715 raw_spin_unlock_irqrestore(&nw_gpio_lock
, flags
);
717 return (reg
& led
->mask
) ? LED_OFF
: LED_FULL
;
720 static int __init
netwinder_leds_init(void)
724 if (!machine_is_netwinder())
727 for (i
= 0; i
< ARRAY_SIZE(netwinder_leds
); i
++) {
728 struct netwinder_led
*led
;
730 led
= kzalloc(sizeof(*led
), GFP_KERNEL
);
734 led
->cdev
.name
= netwinder_leds
[i
].name
;
735 led
->cdev
.brightness_set
= netwinder_led_set
;
736 led
->cdev
.brightness_get
= netwinder_led_get
;
737 led
->cdev
.default_trigger
= netwinder_leds
[i
].trigger
;
740 led
->mask
= GPIO_GREEN_LED
;
742 led
->mask
= GPIO_RED_LED
;
744 if (led_classdev_register(NULL
, &led
->cdev
) < 0) {
754 * Since we may have triggers on any subsystem, defer registration
755 * until after subsystem_init.
757 fs_initcall(netwinder_leds_init
);
760 MACHINE_START(NETWINDER
, "Rebel-NetWinder")
761 /* Maintainer: Russell King/Rebel.com */
762 .atag_offset
= 0x100,
763 .video_start
= 0x000a0000,
764 .video_end
= 0x000bffff,
767 .fixup
= fixup_netwinder
,
768 .map_io
= footbridge_map_io
,
769 .init_irq
= footbridge_init_irq
,
770 .init_time
= isa_timer_init
,
771 .restart
= netwinder_restart
,