diff options
Diffstat (limited to 'drivers/input/misc')
-rw-r--r-- | drivers/input/misc/Kconfig | 2 | ||||
-rw-r--r-- | drivers/input/misc/sparcspkr.c | 218 |
2 files changed, 124 insertions, 96 deletions
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 4bad588d0e5d..a6dfc7455733 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig | |||
@@ -26,7 +26,7 @@ config INPUT_PCSPKR | |||
26 | 26 | ||
27 | config INPUT_SPARCSPKR | 27 | config INPUT_SPARCSPKR |
28 | tristate "SPARC Speaker support" | 28 | tristate "SPARC Speaker support" |
29 | depends on PCI && SPARC | 29 | depends on PCI && SPARC64 |
30 | help | 30 | help |
31 | Say Y here if you want the standard Speaker on Sparc PCI systems | 31 | Say Y here if you want the standard Speaker on Sparc PCI systems |
32 | to be used for bells and whistles. | 32 | to be used for bells and whistles. |
diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c index ed95dc9420dd..42c11fbf3c79 100644 --- a/drivers/input/misc/sparcspkr.c +++ b/drivers/input/misc/sparcspkr.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * Driver for PC-speaker like devices found on various Sparc systems. | 2 | * Driver for PC-speaker like devices found on various Sparc systems. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 Vojtech Pavlik | 4 | * Copyright (c) 2002 Vojtech Pavlik |
5 | * Copyright (c) 2002 David S. Miller (davem@redhat.com) | 5 | * Copyright (c) 2002, 2006 David S. Miller (davem@davemloft.net) |
6 | */ | 6 | */ |
7 | #include <linux/config.h> | 7 | #include <linux/config.h> |
8 | #include <linux/kernel.h> | 8 | #include <linux/kernel.h> |
@@ -13,21 +13,23 @@ | |||
13 | 13 | ||
14 | #include <asm/io.h> | 14 | #include <asm/io.h> |
15 | #include <asm/ebus.h> | 15 | #include <asm/ebus.h> |
16 | #ifdef CONFIG_SPARC64 | ||
17 | #include <asm/isa.h> | 16 | #include <asm/isa.h> |
18 | #endif | ||
19 | 17 | ||
20 | MODULE_AUTHOR("David S. Miller <davem@redhat.com>"); | 18 | MODULE_AUTHOR("David S. Miller <davem@davemloft.net>"); |
21 | MODULE_DESCRIPTION("Sparc Speaker beeper driver"); | 19 | MODULE_DESCRIPTION("Sparc Speaker beeper driver"); |
22 | MODULE_LICENSE("GPL"); | 20 | MODULE_LICENSE("GPL"); |
23 | 21 | ||
24 | const char *beep_name; | 22 | struct sparcspkr_state { |
25 | static unsigned long beep_iobase; | 23 | const char *name; |
26 | static int (*beep_event)(struct input_dev *dev, unsigned int type, unsigned int code, int value); | 24 | unsigned long iobase; |
27 | static DEFINE_SPINLOCK(beep_lock); | 25 | int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value); |
26 | spinlock_t lock; | ||
27 | struct input_dev *input_dev; | ||
28 | }; | ||
28 | 29 | ||
29 | static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) | 30 | static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) |
30 | { | 31 | { |
32 | struct sparcspkr_state *state = dev_get_drvdata(dev->cdev.dev); | ||
31 | unsigned int count = 0; | 33 | unsigned int count = 0; |
32 | unsigned long flags; | 34 | unsigned long flags; |
33 | 35 | ||
@@ -43,24 +45,24 @@ static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned in | |||
43 | if (value > 20 && value < 32767) | 45 | if (value > 20 && value < 32767) |
44 | count = 1193182 / value; | 46 | count = 1193182 / value; |
45 | 47 | ||
46 | spin_lock_irqsave(&beep_lock, flags); | 48 | spin_lock_irqsave(&state->lock, flags); |
47 | 49 | ||
48 | /* EBUS speaker only has on/off state, the frequency does not | 50 | /* EBUS speaker only has on/off state, the frequency does not |
49 | * appear to be programmable. | 51 | * appear to be programmable. |
50 | */ | 52 | */ |
51 | if (beep_iobase & 0x2UL) | 53 | if (state->iobase & 0x2UL) |
52 | outb(!!count, beep_iobase); | 54 | outb(!!count, state->iobase); |
53 | else | 55 | else |
54 | outl(!!count, beep_iobase); | 56 | outl(!!count, state->iobase); |
55 | 57 | ||
56 | spin_unlock_irqrestore(&beep_lock, flags); | 58 | spin_unlock_irqrestore(&state->lock, flags); |
57 | 59 | ||
58 | return 0; | 60 | return 0; |
59 | } | 61 | } |
60 | 62 | ||
61 | #ifdef CONFIG_SPARC64 | ||
62 | static int isa_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) | 63 | static int isa_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) |
63 | { | 64 | { |
65 | struct sparcspkr_state *state = dev_get_drvdata(dev->cdev.dev); | ||
64 | unsigned int count = 0; | 66 | unsigned int count = 0; |
65 | unsigned long flags; | 67 | unsigned long flags; |
66 | 68 | ||
@@ -76,29 +78,29 @@ static int isa_spkr_event(struct input_dev *dev, unsigned int type, unsigned int | |||
76 | if (value > 20 && value < 32767) | 78 | if (value > 20 && value < 32767) |
77 | count = 1193182 / value; | 79 | count = 1193182 / value; |
78 | 80 | ||
79 | spin_lock_irqsave(&beep_lock, flags); | 81 | spin_lock_irqsave(&state->lock, flags); |
80 | 82 | ||
81 | if (count) { | 83 | if (count) { |
82 | /* enable counter 2 */ | 84 | /* enable counter 2 */ |
83 | outb(inb(beep_iobase + 0x61) | 3, beep_iobase + 0x61); | 85 | outb(inb(state->iobase + 0x61) | 3, state->iobase + 0x61); |
84 | /* set command for counter 2, 2 byte write */ | 86 | /* set command for counter 2, 2 byte write */ |
85 | outb(0xB6, beep_iobase + 0x43); | 87 | outb(0xB6, state->iobase + 0x43); |
86 | /* select desired HZ */ | 88 | /* select desired HZ */ |
87 | outb(count & 0xff, beep_iobase + 0x42); | 89 | outb(count & 0xff, state->iobase + 0x42); |
88 | outb((count >> 8) & 0xff, beep_iobase + 0x42); | 90 | outb((count >> 8) & 0xff, state->iobase + 0x42); |
89 | } else { | 91 | } else { |
90 | /* disable counter 2 */ | 92 | /* disable counter 2 */ |
91 | outb(inb_p(beep_iobase + 0x61) & 0xFC, beep_iobase + 0x61); | 93 | outb(inb_p(state->iobase + 0x61) & 0xFC, state->iobase + 0x61); |
92 | } | 94 | } |
93 | 95 | ||
94 | spin_unlock_irqrestore(&beep_lock, flags); | 96 | spin_unlock_irqrestore(&state->lock, flags); |
95 | 97 | ||
96 | return 0; | 98 | return 0; |
97 | } | 99 | } |
98 | #endif | ||
99 | 100 | ||
100 | static int __devinit sparcspkr_probe(struct platform_device *dev) | 101 | static int __devinit sparcspkr_probe(struct device *dev) |
101 | { | 102 | { |
103 | struct sparcspkr_state *state = dev_get_drvdata(dev); | ||
102 | struct input_dev *input_dev; | 104 | struct input_dev *input_dev; |
103 | int error; | 105 | int error; |
104 | 106 | ||
@@ -106,18 +108,18 @@ static int __devinit sparcspkr_probe(struct platform_device *dev) | |||
106 | if (!input_dev) | 108 | if (!input_dev) |
107 | return -ENOMEM; | 109 | return -ENOMEM; |
108 | 110 | ||
109 | input_dev->name = beep_name; | 111 | input_dev->name = state->name; |
110 | input_dev->phys = "sparc/input0"; | 112 | input_dev->phys = "sparc/input0"; |
111 | input_dev->id.bustype = BUS_ISA; | 113 | input_dev->id.bustype = BUS_ISA; |
112 | input_dev->id.vendor = 0x001f; | 114 | input_dev->id.vendor = 0x001f; |
113 | input_dev->id.product = 0x0001; | 115 | input_dev->id.product = 0x0001; |
114 | input_dev->id.version = 0x0100; | 116 | input_dev->id.version = 0x0100; |
115 | input_dev->cdev.dev = &dev->dev; | 117 | input_dev->cdev.dev = dev; |
116 | 118 | ||
117 | input_dev->evbit[0] = BIT(EV_SND); | 119 | input_dev->evbit[0] = BIT(EV_SND); |
118 | input_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); | 120 | input_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); |
119 | 121 | ||
120 | input_dev->event = beep_event; | 122 | input_dev->event = state->event; |
121 | 123 | ||
122 | error = input_register_device(input_dev); | 124 | error = input_register_device(input_dev); |
123 | if (error) { | 125 | if (error) { |
@@ -125,111 +127,137 @@ static int __devinit sparcspkr_probe(struct platform_device *dev) | |||
125 | return error; | 127 | return error; |
126 | } | 128 | } |
127 | 129 | ||
128 | platform_set_drvdata(dev, input_dev); | 130 | state->input_dev = input_dev; |
129 | 131 | ||
130 | return 0; | 132 | return 0; |
131 | } | 133 | } |
132 | 134 | ||
133 | static int __devexit sparcspkr_remove(struct platform_device *dev) | 135 | static int __devexit sparcspkr_remove(struct of_device *dev) |
134 | { | 136 | { |
135 | struct input_dev *input_dev = platform_get_drvdata(dev); | 137 | struct sparcspkr_state *state = dev_get_drvdata(&dev->dev); |
138 | struct input_dev *input_dev = state->input_dev; | ||
136 | 139 | ||
137 | input_unregister_device(input_dev); | ||
138 | platform_set_drvdata(dev, NULL); | ||
139 | /* turn off the speaker */ | 140 | /* turn off the speaker */ |
140 | beep_event(NULL, EV_SND, SND_BELL, 0); | 141 | state->event(input_dev, EV_SND, SND_BELL, 0); |
142 | |||
143 | input_unregister_device(input_dev); | ||
144 | |||
145 | dev_set_drvdata(&dev->dev, NULL); | ||
146 | kfree(state); | ||
141 | 147 | ||
142 | return 0; | 148 | return 0; |
143 | } | 149 | } |
144 | 150 | ||
145 | static void sparcspkr_shutdown(struct platform_device *dev) | 151 | static int sparcspkr_shutdown(struct of_device *dev) |
146 | { | 152 | { |
153 | struct sparcspkr_state *state = dev_get_drvdata(&dev->dev); | ||
154 | struct input_dev *input_dev = state->input_dev; | ||
155 | |||
147 | /* turn off the speaker */ | 156 | /* turn off the speaker */ |
148 | beep_event(NULL, EV_SND, SND_BELL, 0); | 157 | state->event(input_dev, EV_SND, SND_BELL, 0); |
158 | |||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | static int __devinit ebus_beep_probe(struct of_device *dev, const struct of_device_id *match) | ||
163 | { | ||
164 | struct linux_ebus_device *edev = to_ebus_device(&dev->dev); | ||
165 | struct sparcspkr_state *state; | ||
166 | int err; | ||
167 | |||
168 | state = kzalloc(sizeof(*state), GFP_KERNEL); | ||
169 | if (!state) | ||
170 | return -ENOMEM; | ||
171 | |||
172 | state->name = "Sparc EBUS Speaker"; | ||
173 | state->iobase = edev->resource[0].start; | ||
174 | state->event = ebus_spkr_event; | ||
175 | spin_lock_init(&state->lock); | ||
176 | |||
177 | dev_set_drvdata(&dev->dev, state); | ||
178 | |||
179 | err = sparcspkr_probe(&dev->dev); | ||
180 | if (err) { | ||
181 | dev_set_drvdata(&dev->dev, NULL); | ||
182 | kfree(state); | ||
183 | } | ||
184 | |||
185 | return 0; | ||
149 | } | 186 | } |
150 | 187 | ||
151 | static struct platform_driver sparcspkr_platform_driver = { | 188 | static struct of_device_id ebus_beep_match[] = { |
152 | .driver = { | 189 | { |
153 | .name = "sparcspkr", | 190 | .name = "beep", |
154 | .owner = THIS_MODULE, | ||
155 | }, | 191 | }, |
156 | .probe = sparcspkr_probe, | 192 | {}, |
157 | .remove = __devexit_p(sparcspkr_remove), | ||
158 | .shutdown = sparcspkr_shutdown, | ||
159 | }; | 193 | }; |
160 | 194 | ||
161 | static struct platform_device *sparcspkr_platform_device; | 195 | static struct of_platform_driver ebus_beep_driver = { |
196 | .name = "beep", | ||
197 | .match_table = ebus_beep_match, | ||
198 | .probe = ebus_beep_probe, | ||
199 | .remove = sparcspkr_remove, | ||
200 | .shutdown = sparcspkr_shutdown, | ||
201 | }; | ||
162 | 202 | ||
163 | static int __init sparcspkr_drv_init(void) | 203 | static int __devinit isa_beep_probe(struct of_device *dev, const struct of_device_id *match) |
164 | { | 204 | { |
165 | int error; | 205 | struct sparc_isa_device *idev = to_isa_device(&dev->dev); |
206 | struct sparcspkr_state *state; | ||
207 | int err; | ||
166 | 208 | ||
167 | error = platform_driver_register(&sparcspkr_platform_driver); | 209 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
168 | if (error) | 210 | if (!state) |
169 | return error; | 211 | return -ENOMEM; |
170 | 212 | ||
171 | sparcspkr_platform_device = platform_device_alloc("sparcspkr", -1); | 213 | state->name = "Sparc ISA Speaker"; |
172 | if (!sparcspkr_platform_device) { | 214 | state->iobase = idev->resource.start; |
173 | error = -ENOMEM; | 215 | state->event = isa_spkr_event; |
174 | goto err_unregister_driver; | 216 | spin_lock_init(&state->lock); |
175 | } | 217 | |
218 | dev_set_drvdata(&dev->dev, state); | ||
176 | 219 | ||
177 | error = platform_device_add(sparcspkr_platform_device); | 220 | err = sparcspkr_probe(&dev->dev); |
178 | if (error) | 221 | if (err) { |
179 | goto err_free_device; | 222 | dev_set_drvdata(&dev->dev, NULL); |
223 | kfree(state); | ||
224 | } | ||
180 | 225 | ||
181 | return 0; | 226 | return 0; |
227 | } | ||
182 | 228 | ||
183 | err_free_device: | 229 | static struct of_device_id isa_beep_match[] = { |
184 | platform_device_put(sparcspkr_platform_device); | 230 | { |
185 | err_unregister_driver: | 231 | .name = "dma", |
186 | platform_driver_unregister(&sparcspkr_platform_driver); | 232 | }, |
233 | {}, | ||
234 | }; | ||
187 | 235 | ||
188 | return error; | 236 | static struct of_platform_driver isa_beep_driver = { |
189 | } | 237 | .name = "beep", |
238 | .match_table = isa_beep_match, | ||
239 | .probe = isa_beep_probe, | ||
240 | .remove = sparcspkr_remove, | ||
241 | .shutdown = sparcspkr_shutdown, | ||
242 | }; | ||
190 | 243 | ||
191 | static int __init sparcspkr_init(void) | 244 | static int __init sparcspkr_init(void) |
192 | { | 245 | { |
193 | struct linux_ebus *ebus; | 246 | int err = of_register_driver(&ebus_beep_driver, &ebus_bus_type); |
194 | struct linux_ebus_device *edev; | 247 | |
195 | #ifdef CONFIG_SPARC64 | 248 | if (!err) { |
196 | struct sparc_isa_bridge *isa_br; | 249 | err = of_register_driver(&isa_beep_driver, &isa_bus_type); |
197 | struct sparc_isa_device *isa_dev; | 250 | if (err) |
198 | #endif | 251 | of_unregister_driver(&ebus_beep_driver); |
199 | |||
200 | for_each_ebus(ebus) { | ||
201 | for_each_ebusdev(edev, ebus) { | ||
202 | if (!strcmp(edev->prom_node->name, "beep")) { | ||
203 | beep_name = "Sparc EBUS Speaker"; | ||
204 | beep_event = ebus_spkr_event; | ||
205 | beep_iobase = edev->resource[0].start; | ||
206 | return sparcspkr_drv_init(); | ||
207 | } | ||
208 | } | ||
209 | } | ||
210 | #ifdef CONFIG_SPARC64 | ||
211 | for_each_isa(isa_br) { | ||
212 | for_each_isadev(isa_dev, isa_br) { | ||
213 | /* A hack, the beep device's base lives in | ||
214 | * the DMA isa node. | ||
215 | */ | ||
216 | if (!strcmp(isa_dev->prom_node->name, "dma")) { | ||
217 | beep_name = "Sparc ISA Speaker"; | ||
218 | beep_event = isa_spkr_event, | ||
219 | beep_iobase = isa_dev->resource.start; | ||
220 | return sparcspkr_drv_init(); | ||
221 | } | ||
222 | } | ||
223 | } | 252 | } |
224 | #endif | ||
225 | 253 | ||
226 | return -ENODEV; | 254 | return err; |
227 | } | 255 | } |
228 | 256 | ||
229 | static void __exit sparcspkr_exit(void) | 257 | static void __exit sparcspkr_exit(void) |
230 | { | 258 | { |
231 | platform_device_unregister(sparcspkr_platform_device); | 259 | of_unregister_driver(&ebus_beep_driver); |
232 | platform_driver_unregister(&sparcspkr_platform_driver); | 260 | of_unregister_driver(&isa_beep_driver); |
233 | } | 261 | } |
234 | 262 | ||
235 | module_init(sparcspkr_init); | 263 | module_init(sparcspkr_init); |