blob: 312d63623038c923db1c991941330f5f60e67adb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * m68k beeper driver for Linux
3 *
4 * Copyright (c) 2002 Richard Zidlicky
5 * Copyright (c) 2002 Vojtech Pavlik
6 * Copyright (c) 1992 Orest Zborowski
7 *
8 */
9
10/*
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 as published by
13 * the Free Software Foundation
14 */
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/input.h>
Dmitry Torokhov1f75e6b2005-12-21 00:52:29 -050020#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/machdep.h>
22#include <asm/io.h>
23
24MODULE_AUTHOR("Richard Zidlicky <rz@linux-m68k.org>");
25MODULE_DESCRIPTION("m68k beeper driver");
26MODULE_LICENSE("GPL");
27
Dmitry Torokhov1f75e6b2005-12-21 00:52:29 -050028static struct platform_device *m68kspkr_platform_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30static int m68kspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
31{
32 unsigned int count = 0;
33
34 if (type != EV_SND)
35 return -1;
36
37 switch (code) {
38 case SND_BELL: if (value) value = 1000;
39 case SND_TONE: break;
40 default: return -1;
41 }
42
43 if (value > 20 && value < 32767)
44 count = 1193182 / value;
45
46 mach_beep(count, -1);
47
48 return 0;
49}
50
Bill Pemberton5298cc42012-11-23 21:38:25 -080051static int m68kspkr_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Dmitry Torokhov1f75e6b2005-12-21 00:52:29 -050053 struct input_dev *input_dev;
54 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Dmitry Torokhov1f75e6b2005-12-21 00:52:29 -050056 input_dev = input_allocate_device();
57 if (!input_dev)
Dmitry Torokhov76b7cddf2005-09-15 02:01:51 -050058 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Dmitry Torokhov1f75e6b2005-12-21 00:52:29 -050060 input_dev->name = "m68k beeper";
61 input_dev->phys = "m68k/generic";
62 input_dev->id.bustype = BUS_HOST;
63 input_dev->id.vendor = 0x001f;
64 input_dev->id.product = 0x0001;
65 input_dev->id.version = 0x0100;
Dmitry Torokhov293e6392007-04-12 01:35:32 -040066 input_dev->dev.parent = &dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Jiri Slaby7b19ada2007-10-18 23:40:32 -070068 input_dev->evbit[0] = BIT_MASK(EV_SND);
69 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
Dmitry Torokhov1f75e6b2005-12-21 00:52:29 -050070 input_dev->event = m68kspkr_event;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Dmitry Torokhov1f75e6b2005-12-21 00:52:29 -050072 err = input_register_device(input_dev);
73 if (err) {
74 input_free_device(input_dev);
75 return err;
76 }
77
78 platform_set_drvdata(dev, input_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 return 0;
81}
82
Bill Pembertone2619cf2012-11-23 21:50:47 -080083static int m68kspkr_remove(struct platform_device *dev)
Dmitry Torokhov1f75e6b2005-12-21 00:52:29 -050084{
85 struct input_dev *input_dev = platform_get_drvdata(dev);
86
87 input_unregister_device(input_dev);
Dmitry Torokhov1f75e6b2005-12-21 00:52:29 -050088 /* turn off the speaker */
89 m68kspkr_event(NULL, EV_SND, SND_BELL, 0);
90
91 return 0;
92}
93
94static void m68kspkr_shutdown(struct platform_device *dev)
95{
96 /* turn off the speaker */
97 m68kspkr_event(NULL, EV_SND, SND_BELL, 0);
98}
99
100static struct platform_driver m68kspkr_platform_driver = {
101 .driver = {
102 .name = "m68kspkr",
Dmitry Torokhov1f75e6b2005-12-21 00:52:29 -0500103 },
104 .probe = m68kspkr_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -0800105 .remove = m68kspkr_remove,
Dmitry Torokhov1f75e6b2005-12-21 00:52:29 -0500106 .shutdown = m68kspkr_shutdown,
107};
108
109static int __init m68kspkr_init(void)
110{
111 int err;
112
113 if (!mach_beep) {
114 printk(KERN_INFO "m68kspkr: no lowlevel beep support\n");
115 return -ENODEV;
116 }
117
118 err = platform_driver_register(&m68kspkr_platform_driver);
119 if (err)
120 return err;
121
122 m68kspkr_platform_device = platform_device_alloc("m68kspkr", -1);
123 if (!m68kspkr_platform_device) {
124 err = -ENOMEM;
125 goto err_unregister_driver;
126 }
127
128 err = platform_device_add(m68kspkr_platform_device);
129 if (err)
130 goto err_free_device;
131
132 return 0;
133
134 err_free_device:
135 platform_device_put(m68kspkr_platform_device);
136 err_unregister_driver:
137 platform_driver_unregister(&m68kspkr_platform_driver);
138
139 return err;
140}
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142static void __exit m68kspkr_exit(void)
143{
Dmitry Torokhov1f75e6b2005-12-21 00:52:29 -0500144 platform_device_unregister(m68kspkr_platform_device);
145 platform_driver_unregister(&m68kspkr_platform_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
148module_init(m68kspkr_init);
149module_exit(m68kspkr_exit);