treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / input / misc / m68kspkr.c
blob25fcf1467151b1fd8643353ef8dbb64082e2d9a5
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 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);
86 return 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 = {
96 .driver = {
97 .name = "m68kspkr",
99 .probe = m68kspkr_probe,
100 .remove = m68kspkr_remove,
101 .shutdown = m68kspkr_shutdown,
104 static int __init m68kspkr_init(void)
106 int err;
108 if (!mach_beep) {
109 printk(KERN_INFO "m68kspkr: no lowlevel beep support\n");
110 return -ENODEV;
113 err = platform_driver_register(&m68kspkr_platform_driver);
114 if (err)
115 return err;
117 m68kspkr_platform_device = platform_device_alloc("m68kspkr", -1);
118 if (!m68kspkr_platform_device) {
119 err = -ENOMEM;
120 goto err_unregister_driver;
123 err = platform_device_add(m68kspkr_platform_device);
124 if (err)
125 goto err_free_device;
127 return 0;
129 err_free_device:
130 platform_device_put(m68kspkr_platform_device);
131 err_unregister_driver:
132 platform_driver_unregister(&m68kspkr_platform_driver);
134 return err;
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);