[TG3]: Add tagged status support.
[linux-2.6/verdex.git] / drivers / input / misc / sparcspkr.c
blobcdc3fb3d5f464458b655517e8cbeec7795b819a5
1 /*
2 * Driver for PC-speaker like devices found on various Sparc systems.
4 * Copyright (c) 2002 Vojtech Pavlik
5 * Copyright (c) 2002 David S. Miller (davem@redhat.com)
6 */
7 #include <linux/config.h>
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/input.h>
13 #include <asm/io.h>
14 #include <asm/ebus.h>
15 #ifdef CONFIG_SPARC64
16 #include <asm/isa.h>
17 #endif
19 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
20 MODULE_DESCRIPTION("PC Speaker beeper driver");
21 MODULE_LICENSE("GPL");
23 static unsigned long beep_iobase;
25 static char *sparcspkr_isa_name = "Sparc ISA Speaker";
26 static char *sparcspkr_ebus_name = "Sparc EBUS Speaker";
27 static char *sparcspkr_phys = "sparc/input0";
28 static struct input_dev sparcspkr_dev;
30 DEFINE_SPINLOCK(beep_lock);
32 static void __init init_sparcspkr_struct(void)
34 sparcspkr_dev.evbit[0] = BIT(EV_SND);
35 sparcspkr_dev.sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
37 sparcspkr_dev.phys = sparcspkr_phys;
38 sparcspkr_dev.id.bustype = BUS_ISA;
39 sparcspkr_dev.id.vendor = 0x001f;
40 sparcspkr_dev.id.product = 0x0001;
41 sparcspkr_dev.id.version = 0x0100;
44 static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
46 unsigned int count = 0;
47 unsigned long flags;
49 if (type != EV_SND)
50 return -1;
52 switch (code) {
53 case SND_BELL: if (value) value = 1000;
54 case SND_TONE: break;
55 default: return -1;
58 if (value > 20 && value < 32767)
59 count = 1193182 / value;
61 spin_lock_irqsave(&beep_lock, flags);
63 /* EBUS speaker only has on/off state, the frequency does not
64 * appear to be programmable.
66 if (count) {
67 if (beep_iobase & 0x2UL)
68 outb(1, beep_iobase);
69 else
70 outl(1, beep_iobase);
71 } else {
72 if (beep_iobase & 0x2UL)
73 outb(0, beep_iobase);
74 else
75 outl(0, beep_iobase);
78 spin_unlock_irqrestore(&beep_lock, flags);
80 return 0;
83 static int __init init_ebus_beep(struct linux_ebus_device *edev)
85 beep_iobase = edev->resource[0].start;
87 init_sparcspkr_struct();
89 sparcspkr_dev.name = sparcspkr_ebus_name;
90 sparcspkr_dev.event = ebus_spkr_event;
92 input_register_device(&sparcspkr_dev);
94 printk(KERN_INFO "input: %s\n", sparcspkr_ebus_name);
95 return 0;
98 #ifdef CONFIG_SPARC64
99 static int isa_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
101 unsigned int count = 0;
102 unsigned long flags;
104 if (type != EV_SND)
105 return -1;
107 switch (code) {
108 case SND_BELL: if (value) value = 1000;
109 case SND_TONE: break;
110 default: return -1;
113 if (value > 20 && value < 32767)
114 count = 1193182 / value;
116 spin_lock_irqsave(&beep_lock, flags);
118 if (count) {
119 /* enable counter 2 */
120 outb(inb(beep_iobase + 0x61) | 3, beep_iobase + 0x61);
121 /* set command for counter 2, 2 byte write */
122 outb(0xB6, beep_iobase + 0x43);
123 /* select desired HZ */
124 outb(count & 0xff, beep_iobase + 0x42);
125 outb((count >> 8) & 0xff, beep_iobase + 0x42);
126 } else {
127 /* disable counter 2 */
128 outb(inb_p(beep_iobase + 0x61) & 0xFC, beep_iobase + 0x61);
131 spin_unlock_irqrestore(&beep_lock, flags);
133 return 0;
136 static int __init init_isa_beep(struct sparc_isa_device *isa_dev)
138 beep_iobase = isa_dev->resource.start;
140 init_sparcspkr_struct();
142 sparcspkr_dev.name = sparcspkr_isa_name;
143 sparcspkr_dev.event = isa_spkr_event;
144 sparcspkr_dev.id.bustype = BUS_ISA;
146 input_register_device(&sparcspkr_dev);
148 printk(KERN_INFO "input: %s\n", sparcspkr_isa_name);
149 return 0;
151 #endif
153 static int __init sparcspkr_init(void)
155 struct linux_ebus *ebus;
156 struct linux_ebus_device *edev = NULL;
157 #ifdef CONFIG_SPARC64
158 struct sparc_isa_bridge *isa_br;
159 struct sparc_isa_device *isa_dev;
160 #endif
162 for_each_ebus(ebus) {
163 for_each_ebusdev(edev, ebus) {
164 if (!strcmp(edev->prom_name, "beep"))
165 return init_ebus_beep(edev);
168 #ifdef CONFIG_SPARC64
169 for_each_isa(isa_br) {
170 for_each_isadev(isa_dev, isa_br) {
171 /* A hack, the beep device's base lives in
172 * the DMA isa node.
174 if (!strcmp(isa_dev->prom_name, "dma"))
175 return init_isa_beep(isa_dev);
178 #endif
180 return -ENODEV;
183 static void __exit sparcspkr_exit(void)
185 input_unregister_device(&sparcspkr_dev);
188 module_init(sparcspkr_init);
189 module_exit(sparcspkr_exit);