ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / input / misc / 98spkr.c
1 /*
2  *  PC-9800 Speaker beeper driver for Linux
3  *
4  *  Copyright (c) 2002 Osamu Tomita
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/io.h>
21
22 MODULE_AUTHOR("Osamu Tomita <tomita@cinet.co.jp>");
23 MODULE_DESCRIPTION("PC-9800 Speaker beeper driver");
24 MODULE_LICENSE("GPL");
25
26 static char spkr98_name[] = "PC-9801 Speaker";
27 static char spkr98_phys[] = "isa3fdb/input0";
28 static struct input_dev spkr98_dev;
29
30 spinlock_t i8253_beep_lock = SPIN_LOCK_UNLOCKED;
31
32 static int spkr98_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
33 {
34         unsigned int count = 0;
35         unsigned long flags;
36
37         if (type != EV_SND)
38                 return -1;
39
40         switch (code) {
41                 case SND_BELL: if (value) value = 1000;
42                 case SND_TONE: break;
43                 default: return -1;
44         } 
45
46         if (value > 20 && value < 32767)
47                 count = CLOCK_TICK_RATE / value;
48         
49         spin_lock_irqsave(&i8253_beep_lock, flags);
50
51         if (count) {
52                 outb(0x76, 0x3fdf);
53                 outb(0, 0x5f);
54                 outb(count & 0xff, 0x3fdb);
55                 outb(0, 0x5f);
56                 outb((count >> 8) & 0xff, 0x3fdb);
57                 /* beep on */
58                 outb(6, 0x37);
59         } else {
60                 /* beep off */
61                 outb(7, 0x37);
62         }
63
64         spin_unlock_irqrestore(&i8253_beep_lock, flags);
65
66         return 0;
67 }
68
69 static int __init spkr98_init(void)
70 {
71         spkr98_dev.evbit[0] = BIT(EV_SND);
72         spkr98_dev.sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
73         spkr98_dev.event = spkr98_event;
74
75         spkr98_dev.name = spkr98_name;
76         spkr98_dev.phys = spkr98_phys;
77         spkr98_dev.id.bustype = BUS_ISA;
78         spkr98_dev.id.vendor = 0x001f;
79         spkr98_dev.id.product = 0x0001;
80         spkr98_dev.id.version = 0x0100;
81
82         input_register_device(&spkr98_dev);
83
84         printk(KERN_INFO "input: %s\n", spkr98_name);
85
86         return 0;
87 }
88
89 static void __exit spkr98_exit(void)
90 {
91         input_unregister_device(&spkr98_dev);
92 }
93
94 module_init(spkr98_init);
95 module_exit(spkr98_exit);