1 // SPDX-License-Identifier: GPL-2.0-only
3 * m68k beeper driver for Linux
5 * Copyright (c) 2002 Richard Zidlicky
6 * Copyright (c) 2002 Vojtech Pavlik
7 * Copyright (c) 1992 Orest Zborowski
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>
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;
33 case SND_BELL: if (value) value = 1000;
38 if (value > 20 && value < 32767)
39 count = 1193182 / value;
46 static int m68kspkr_probe(struct platform_device *dev)
48 struct input_dev *input_dev;
51 input_dev = input_allocate_device();
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);
69 input_free_device(input_dev);
73 platform_set_drvdata(dev, input_dev);
78 static int 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);
89 static void m68kspkr_shutdown(struct platform_device *dev)
91 /* turn off the speaker */
92 m68kspkr_event(NULL, EV_SND, SND_BELL, 0);
95 static struct platform_driver m68kspkr_platform_driver = {
99 .probe = m68kspkr_probe,
100 .remove = m68kspkr_remove,
101 .shutdown = m68kspkr_shutdown,
104 static int __init m68kspkr_init(void)
109 printk(KERN_INFO "m68kspkr: no lowlevel beep support\n");
113 err = platform_driver_register(&m68kspkr_platform_driver);
117 m68kspkr_platform_device = platform_device_alloc("m68kspkr", -1);
118 if (!m68kspkr_platform_device) {
120 goto err_unregister_driver;
123 err = platform_device_add(m68kspkr_platform_device);
125 goto err_free_device;
130 platform_device_put(m68kspkr_platform_device);
131 err_unregister_driver:
132 platform_driver_unregister(&m68kspkr_platform_driver);
137 static void __exit m68kspkr_exit(void)
139 platform_device_unregister(m68kspkr_platform_device);
140 platform_driver_unregister(&m68kspkr_platform_driver);
143 module_init(m68kspkr_init);
144 module_exit(m68kspkr_exit);