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)
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>
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;
53 case SND_BELL
: if (value
) value
= 1000;
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.
67 if (beep_iobase
& 0x2UL
)
72 if (beep_iobase
& 0x2UL
)
78 spin_unlock_irqrestore(&beep_lock
, flags
);
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
);
99 static int isa_spkr_event(struct input_dev
*dev
, unsigned int type
, unsigned int code
, int value
)
101 unsigned int count
= 0;
108 case SND_BELL
: if (value
) value
= 1000;
109 case SND_TONE
: break;
113 if (value
> 20 && value
< 32767)
114 count
= 1193182 / value
;
116 spin_lock_irqsave(&beep_lock
, flags
);
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);
127 /* disable counter 2 */
128 outb(inb_p(beep_iobase
+ 0x61) & 0xFC, beep_iobase
+ 0x61);
131 spin_unlock_irqrestore(&beep_lock
, flags
);
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
);
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
;
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
174 if (!strcmp(isa_dev
->prom_name
, "dma"))
175 return init_isa_beep(isa_dev
);
183 static void __exit
sparcspkr_exit(void)
185 input_unregister_device(&sparcspkr_dev
);
188 module_init(sparcspkr_init
);
189 module_exit(sparcspkr_exit
);