blob: 04489ad7702a21c9c31baed48bc963a695217cc9 [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>
20#include <asm/machdep.h>
21#include <asm/io.h>
22
23MODULE_AUTHOR("Richard Zidlicky <rz@linux-m68k.org>");
24MODULE_DESCRIPTION("m68k beeper driver");
25MODULE_LICENSE("GPL");
26
Dmitry Torokhov76b7cdd2005-09-15 02:01:51 -050027static struct input_dev *m68kspkr_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29static int m68kspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
30{
31 unsigned int count = 0;
32
33 if (type != EV_SND)
34 return -1;
35
36 switch (code) {
37 case SND_BELL: if (value) value = 1000;
38 case SND_TONE: break;
39 default: return -1;
40 }
41
42 if (value > 20 && value < 32767)
43 count = 1193182 / value;
44
45 mach_beep(count, -1);
46
47 return 0;
48}
49
50static int __init m68kspkr_init(void)
51{
Dmitry Torokhov76b7cdd2005-09-15 02:01:51 -050052 if (!mach_beep) {
53 printk(KERN_INFO "m68kspkr: no lowlevel beep support\n");
54 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 }
56
Dmitry Torokhov76b7cdd2005-09-15 02:01:51 -050057 m68kspkr_dev = input_allocate_device();
58 if (!m68kspkr_dev)
59 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Dmitry Torokhov76b7cdd2005-09-15 02:01:51 -050061 m68kspkr_dev->name = "m68k beeper";
62 m68kspkr_dev->phys = "m68k/generic";
63 m68kspkr_dev->id.bustype = BUS_HOST;
64 m68kspkr_dev->id.vendor = 0x001f;
65 m68kspkr_dev->id.product = 0x0001;
66 m68kspkr_dev->id.version = 0x0100;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Dmitry Torokhov76b7cdd2005-09-15 02:01:51 -050068 m68kspkr_dev->evbit[0] = BIT(EV_SND);
69 m68kspkr_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
70 m68kspkr_dev->event = m68kspkr_event;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Dmitry Torokhov76b7cdd2005-09-15 02:01:51 -050072 input_register_device(m68kspkr_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74 return 0;
75}
76
77static void __exit m68kspkr_exit(void)
78{
Dmitry Torokhov76b7cdd2005-09-15 02:01:51 -050079 input_unregister_device(m68kspkr_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
82module_init(m68kspkr_init);
83module_exit(m68kspkr_exit);