accel/ivpu: Move recovery work to system_unbound_wq
[drm/drm-misc.git] / drivers / input / misc / m68kspkr.c
blob0542334df62463b13c150dbf08d526b93acf45c6
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * m68k beeper driver for Linux
5 * Copyright (c) 2002 Richard Zidlicky
6 * Copyright (c) 2002 Vojtech Pavlik
7 * Copyright (c) 1992 Orest Zborowski
8 */
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/input.h>
15 #include <linux/platform_device.h>
16 #include <asm/machdep.h>
17 #include <asm/io.h>
19 MODULE_AUTHOR("Richard Zidlicky <rz@linux-m68k.org>");
20 MODULE_DESCRIPTION("m68k beeper driver");
21 MODULE_LICENSE("GPL");
23 static struct platform_device *m68kspkr_platform_device;
25 static int m68kspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
27 unsigned int count = 0;
29 if (type != EV_SND)
30 return -1;
32 switch (code) {
33 case SND_BELL: if (value) value = 1000;
34 case SND_TONE: break;
35 default: return -1;
38 if (value > 20 && value < 32767)
39 count = 1193182 / value;
41 mach_beep(count, -1);
43 return 0;
46 static int m68kspkr_probe(struct platform_device *dev)
48 struct input_dev *input_dev;
49 int err;
51 input_dev = input_allocate_device();
52 if (!input_dev)
53 return -ENOMEM;
55 input_dev->name = "m68k beeper";
56 input_dev->phys = "m68k/generic";
57 input_dev->id.bustype = BUS_HOST;
58 input_dev->id.vendor = 0x001f;
59 input_dev->id.product = 0x0001;
60 input_dev->id.version = 0x0100;
61 input_dev->dev.parent = &dev->dev;
63 input_dev->evbit[0] = BIT_MASK(EV_SND);
64 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
65 input_dev->event = m68kspkr_event;
67 err = input_register_device(input_dev);
68 if (err) {
69 input_free_device(input_dev);
70 return err;
73 platform_set_drvdata(dev, input_dev);
75 return 0;
78 static void m68kspkr_remove(struct platform_device *dev)
80 struct input_dev *input_dev = platform_get_drvdata(dev);
82 input_unregister_device(input_dev);
83 /* turn off the speaker */
84 m68kspkr_event(NULL, EV_SND, SND_BELL, 0);
87 static void m68kspkr_shutdown(struct platform_device *dev)
89 /* turn off the speaker */
90 m68kspkr_event(NULL, EV_SND, SND_BELL, 0);
93 static struct platform_driver m68kspkr_platform_driver = {
94 .driver = {
95 .name = "m68kspkr",
97 .probe = m68kspkr_probe,
98 .remove = m68kspkr_remove,
99 .shutdown = m68kspkr_shutdown,
102 static int __init m68kspkr_init(void)
104 int err;
106 if (!mach_beep) {
107 printk(KERN_INFO "m68kspkr: no lowlevel beep support\n");
108 return -ENODEV;
111 err = platform_driver_register(&m68kspkr_platform_driver);
112 if (err)
113 return err;
115 m68kspkr_platform_device = platform_device_alloc("m68kspkr", -1);
116 if (!m68kspkr_platform_device) {
117 err = -ENOMEM;
118 goto err_unregister_driver;
121 err = platform_device_add(m68kspkr_platform_device);
122 if (err)
123 goto err_free_device;
125 return 0;
127 err_free_device:
128 platform_device_put(m68kspkr_platform_device);
129 err_unregister_driver:
130 platform_driver_unregister(&m68kspkr_platform_driver);
132 return err;
135 static void __exit m68kspkr_exit(void)
137 platform_device_unregister(m68kspkr_platform_device);
138 platform_driver_unregister(&m68kspkr_platform_driver);
141 module_init(m68kspkr_init);
142 module_exit(m68kspkr_exit);