diff options
| -rw-r--r-- | drivers/input/misc/sparcspkr.c | 162 |
1 files changed, 105 insertions, 57 deletions
diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c index 29d97b12be7a..f0fd2c4740f1 100644 --- a/drivers/input/misc/sparcspkr.c +++ b/drivers/input/misc/sparcspkr.c | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <linux/module.h> | 9 | #include <linux/module.h> |
| 10 | #include <linux/init.h> | 10 | #include <linux/init.h> |
| 11 | #include <linux/input.h> | 11 | #include <linux/input.h> |
| 12 | #include <linux/platform_device.h> | ||
| 12 | 13 | ||
| 13 | #include <asm/io.h> | 14 | #include <asm/io.h> |
| 14 | #include <asm/ebus.h> | 15 | #include <asm/ebus.h> |
| @@ -20,22 +21,10 @@ MODULE_AUTHOR("David S. Miller <davem@redhat.com>"); | |||
| 20 | MODULE_DESCRIPTION("Sparc Speaker beeper driver"); | 21 | MODULE_DESCRIPTION("Sparc Speaker beeper driver"); |
| 21 | MODULE_LICENSE("GPL"); | 22 | MODULE_LICENSE("GPL"); |
| 22 | 23 | ||
| 24 | const char *beep_name; | ||
| 23 | static unsigned long beep_iobase; | 25 | static unsigned long beep_iobase; |
| 24 | static struct input_dev *sparcspkr_dev; | 26 | static int (*beep_event)(struct input_dev *dev, unsigned int type, unsigned int code, int value); |
| 25 | 27 | static DEFINE_SPINLOCK(beep_lock); | |
| 26 | DEFINE_SPINLOCK(beep_lock); | ||
| 27 | |||
| 28 | static void __init init_sparcspkr_struct(void) | ||
| 29 | { | ||
| 30 | sparcspkr_dev->evbit[0] = BIT(EV_SND); | ||
| 31 | sparcspkr_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); | ||
| 32 | |||
| 33 | sparcspkr_dev->phys = "sparc/input0"; | ||
| 34 | sparcspkr_dev->id.bustype = BUS_ISA; | ||
| 35 | sparcspkr_dev->id.vendor = 0x001f; | ||
| 36 | sparcspkr_dev->id.product = 0x0001; | ||
| 37 | sparcspkr_dev->id.version = 0x0100; | ||
| 38 | } | ||
| 39 | 28 | ||
| 40 | static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) | 29 | static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) |
| 41 | { | 30 | { |
| @@ -59,39 +48,16 @@ static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned in | |||
| 59 | /* EBUS speaker only has on/off state, the frequency does not | 48 | /* EBUS speaker only has on/off state, the frequency does not |
| 60 | * appear to be programmable. | 49 | * appear to be programmable. |
| 61 | */ | 50 | */ |
| 62 | if (count) { | 51 | if (beep_iobase & 0x2UL) |
| 63 | if (beep_iobase & 0x2UL) | 52 | outb(!!count, beep_iobase); |
| 64 | outb(1, beep_iobase); | 53 | else |
| 65 | else | 54 | outl(!!count, beep_iobase); |
| 66 | outl(1, beep_iobase); | ||
| 67 | } else { | ||
| 68 | if (beep_iobase & 0x2UL) | ||
| 69 | outb(0, beep_iobase); | ||
| 70 | else | ||
| 71 | outl(0, beep_iobase); | ||
| 72 | } | ||
| 73 | 55 | ||
| 74 | spin_unlock_irqrestore(&beep_lock, flags); | 56 | spin_unlock_irqrestore(&beep_lock, flags); |
| 75 | 57 | ||
| 76 | return 0; | 58 | return 0; |
| 77 | } | 59 | } |
| 78 | 60 | ||
| 79 | static int __init init_ebus_beep(struct linux_ebus_device *edev) | ||
| 80 | { | ||
| 81 | beep_iobase = edev->resource[0].start; | ||
| 82 | |||
| 83 | sparcspkr_dev = input_allocate_device(); | ||
| 84 | if (!sparcspkr_dev) | ||
| 85 | return -ENOMEM; | ||
| 86 | |||
| 87 | sparcspkr_dev->name = "Sparc EBUS Speaker"; | ||
| 88 | sparcspkr_dev->event = ebus_spkr_event; | ||
| 89 | |||
| 90 | input_register_device(sparcspkr_dev); | ||
| 91 | |||
| 92 | return 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | #ifdef CONFIG_SPARC64 | 61 | #ifdef CONFIG_SPARC64 |
| 96 | static int isa_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) | 62 | static int isa_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) |
| 97 | { | 63 | { |
| @@ -129,30 +95,103 @@ static int isa_spkr_event(struct input_dev *dev, unsigned int type, unsigned int | |||
| 129 | 95 | ||
| 130 | return 0; | 96 | return 0; |
| 131 | } | 97 | } |
| 98 | #endif | ||
| 132 | 99 | ||
| 133 | static int __init init_isa_beep(struct sparc_isa_device *isa_dev) | 100 | static int __devinit sparcspkr_probe(struct platform_device *dev) |
| 134 | { | 101 | { |
| 135 | beep_iobase = isa_dev->resource.start; | 102 | struct input_dev *input_dev; |
| 103 | int error; | ||
| 136 | 104 | ||
| 137 | sparcspkr_dev = input_allocate_device(); | 105 | input_dev = input_allocate_device(); |
| 138 | if (!sparcspkr_dev) | 106 | if (!input_dev) |
| 139 | return -ENOMEM; | 107 | return -ENOMEM; |
| 140 | 108 | ||
| 141 | init_sparcspkr_struct(); | 109 | input_dev->name = beep_name; |
| 110 | input_dev->phys = "sparc/input0"; | ||
| 111 | input_dev->id.bustype = BUS_ISA; | ||
| 112 | input_dev->id.vendor = 0x001f; | ||
| 113 | input_dev->id.product = 0x0001; | ||
| 114 | input_dev->id.version = 0x0100; | ||
| 115 | input_dev->cdev.dev = &dev->dev; | ||
| 142 | 116 | ||
| 143 | sparcspkr_dev->name = "Sparc ISA Speaker"; | 117 | input_dev->evbit[0] = BIT(EV_SND); |
| 144 | sparcspkr_dev->event = isa_spkr_event; | 118 | input_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); |
| 145 | 119 | ||
| 146 | input_register_device(sparcspkr_dev); | 120 | input_dev->event = beep_event; |
| 121 | |||
| 122 | error = input_register_device(input_dev); | ||
| 123 | if (error) { | ||
| 124 | input_free_device(input_dev); | ||
| 125 | return error; | ||
| 126 | } | ||
| 127 | |||
| 128 | platform_set_drvdata(dev, input_dev); | ||
| 147 | 129 | ||
| 148 | return 0; | 130 | return 0; |
| 149 | } | 131 | } |
| 150 | #endif | 132 | |
| 133 | static int __devexit sparcspkr_remove(struct platform_device *dev) | ||
| 134 | { | ||
| 135 | struct input_dev *input_dev = platform_get_drvdata(dev); | ||
| 136 | |||
| 137 | input_unregister_device(input_dev); | ||
| 138 | platform_set_drvdata(dev, NULL); | ||
| 139 | /* turn off the speaker */ | ||
| 140 | beep_event(NULL, EV_SND, SND_BELL, 0); | ||
| 141 | |||
| 142 | return 0; | ||
| 143 | } | ||
| 144 | |||
| 145 | static void sparcspkr_shutdown(struct platform_device *dev) | ||
| 146 | { | ||
| 147 | /* turn off the speaker */ | ||
| 148 | beep_event(NULL, EV_SND, SND_BELL, 0); | ||
| 149 | } | ||
| 150 | |||
| 151 | static struct platform_driver sparcspkr_platform_driver = { | ||
| 152 | .driver = { | ||
| 153 | .name = "sparcspkr", | ||
| 154 | .owner = THIS_MODULE, | ||
| 155 | }, | ||
| 156 | .probe = sparcspkr_probe, | ||
| 157 | .remove = __devexit_p(sparcspkr_remove), | ||
| 158 | .shutdown = sparcspkr_shutdown, | ||
| 159 | }; | ||
| 160 | |||
| 161 | static struct platform_device *sparcspkr_platform_device; | ||
| 162 | |||
| 163 | static int __init sparcspkr_drv_init(void) | ||
| 164 | { | ||
| 165 | int error; | ||
| 166 | |||
| 167 | error = platform_driver_register(&sparcspkr_platform_driver); | ||
| 168 | if (error) | ||
| 169 | return error; | ||
| 170 | |||
| 171 | sparcspkr_platform_device = platform_device_alloc("sparcspkr", -1); | ||
| 172 | if (!sparcspkr_platform_device) { | ||
| 173 | error = -ENOMEM; | ||
| 174 | goto err_unregister_driver; | ||
| 175 | } | ||
| 176 | |||
| 177 | error = platform_device_add(sparcspkr_platform_device); | ||
| 178 | if (error) | ||
| 179 | goto err_free_device; | ||
| 180 | |||
| 181 | return 0; | ||
| 182 | |||
| 183 | err_free_device: | ||
| 184 | platform_device_put(sparcspkr_platform_device); | ||
| 185 | err_unregister_driver: | ||
| 186 | platform_driver_unregister(&sparcspkr_platform_driver); | ||
| 187 | |||
| 188 | return error; | ||
| 189 | } | ||
| 151 | 190 | ||
| 152 | static int __init sparcspkr_init(void) | 191 | static int __init sparcspkr_init(void) |
| 153 | { | 192 | { |
| 154 | struct linux_ebus *ebus; | 193 | struct linux_ebus *ebus; |
| 155 | struct linux_ebus_device *edev = NULL; | 194 | struct linux_ebus_device *edev; |
| 156 | #ifdef CONFIG_SPARC64 | 195 | #ifdef CONFIG_SPARC64 |
| 157 | struct sparc_isa_bridge *isa_br; | 196 | struct sparc_isa_bridge *isa_br; |
| 158 | struct sparc_isa_device *isa_dev; | 197 | struct sparc_isa_device *isa_dev; |
| @@ -160,8 +199,12 @@ static int __init sparcspkr_init(void) | |||
| 160 | 199 | ||
| 161 | for_each_ebus(ebus) { | 200 | for_each_ebus(ebus) { |
| 162 | for_each_ebusdev(edev, ebus) { | 201 | for_each_ebusdev(edev, ebus) { |
| 163 | if (!strcmp(edev->prom_name, "beep")) | 202 | if (!strcmp(edev->prom_name, "beep")) { |
| 164 | return init_ebus_beep(edev); | 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 | } | ||
| 165 | } | 208 | } |
| 166 | } | 209 | } |
| 167 | #ifdef CONFIG_SPARC64 | 210 | #ifdef CONFIG_SPARC64 |
| @@ -170,8 +213,12 @@ static int __init sparcspkr_init(void) | |||
| 170 | /* A hack, the beep device's base lives in | 213 | /* A hack, the beep device's base lives in |
| 171 | * the DMA isa node. | 214 | * the DMA isa node. |
| 172 | */ | 215 | */ |
| 173 | if (!strcmp(isa_dev->prom_name, "dma")) | 216 | if (!strcmp(isa_dev->prom_name, "dma")) { |
| 174 | return init_isa_beep(isa_dev); | 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 | } | ||
| 175 | } | 222 | } |
| 176 | } | 223 | } |
| 177 | #endif | 224 | #endif |
| @@ -181,7 +228,8 @@ static int __init sparcspkr_init(void) | |||
| 181 | 228 | ||
| 182 | static void __exit sparcspkr_exit(void) | 229 | static void __exit sparcspkr_exit(void) |
| 183 | { | 230 | { |
| 184 | input_unregister_device(sparcspkr_dev); | 231 | platform_device_unregister(sparcspkr_platform_device); |
| 232 | platform_driver_unregister(&sparcspkr_platform_driver); | ||
| 185 | } | 233 | } |
| 186 | 234 | ||
| 187 | module_init(sparcspkr_init); | 235 | module_init(sparcspkr_init); |
