Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
519 mauro 1
/*
2
 * $Id: speaker.c,v 1.1 2004-03-22 14:48:15 mauro Exp $
3
 *
4
 *  Copyright (c) 1999-2001 Vojtech Pavlik
5
 */
6
 
7
/*
8
 *  Input driver event debug module - dumps all events into syslog
9
 */
10
 
11
/*
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
 */
26
 
27
#include <linuxcomp.h>
28
 
29
#include <linux/slab.h>
30
#include <linux/module.h>
31
#include <linux/input.h>
32
#include <linux/init.h>
33
#include <linux/device.h>
34
 
35
//#define DEBUG_SPK
36
 
37
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
38
MODULE_DESCRIPTION("Input driver event debug module");
39
MODULE_LICENSE("GPL");
40
 
41
static char speaker_name[] = "speaker";
42
static struct input_handler speaker_handler;
43
 
44
/*
45
 * Making beeps and bells.
46
 */
47
void spk_nosound(unsigned long ignored)
48
{
49
        struct list_head * node;
50
 
51
        list_for_each(node,&speaker_handler.h_list) {
52
                struct input_handle *handle = to_handle_h(node);
53
                if (test_bit(EV_SND, handle->dev->evbit)) {
54
                        if (test_bit(SND_TONE, handle->dev->sndbit))
55
                                input_event(handle->dev, EV_SND, SND_TONE, 0);
56
                        if (test_bit(SND_BELL, handle->dev->sndbit))
57
                                input_event(handle->dev, EV_SND, SND_BELL, 0);
58
                }
59
        }
60
}
61
 
62
static struct timer_list spk_mksound_timer =
63
                TIMER_INITIALIZER(spk_nosound, 0, 0);
64
 
65
void spk_mksound(unsigned int hz, unsigned int ticks)
66
{
67
        struct list_head * node;
68
 
69
        del_timer(&spk_mksound_timer);
70
 
71
        if (hz) {
72
                list_for_each_prev(node,&speaker_handler.h_list) {
73
                        struct input_handle *handle = to_handle_h(node);
74
                        if (test_bit(EV_SND, handle->dev->evbit)) {
75
                                if (test_bit(SND_TONE, handle->dev->sndbit)) {
76
                                        input_event(handle->dev, EV_SND, SND_TONE, hz);
77
                                        break;
78
                                }
79
                                if (test_bit(SND_BELL, handle->dev->sndbit)) {
80
                                        input_event(handle->dev, EV_SND, SND_BELL, 1);
81
                                        break;
82
                                }
83
                        }
84
                }
85
                if (ticks)
86
                        mod_timer(&spk_mksound_timer, jiffies26 + ticks);
87
        } else
88
                spk_nosound(0);
89
}
90
 
91
static void speaker_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
92
{
93
        if (type != EV_SND)
94
                return;
95
 
96
#ifdef DEBUG_SPK
97
        printk(KERN_DEBUG "speaker.c: Event. Dev: %s, Type: %d, Code: %d, Value: %d\n", handle->dev->phys, type, code, value);
98
#endif
99
}
100
 
101
static struct input_handle *speaker_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id)
102
{
103
        struct input_handle *handle;
104
 
105
        if (!test_bit(EV_SND, dev->evbit))
106
                return NULL;
107
 
108
        if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL)))
109
                return NULL;
110
        memset(handle, 0, sizeof(struct input_handle));
111
 
112
        handle->dev = dev;
113
        handle->handler = handler;
114
        handle->name = speaker_name;
115
 
116
        input_open_device(handle);
117
 
118
#ifdef DEBUG_SPK
119
        printk(KERN_DEBUG "speaker.c: Connected device: \"%s\", %s\n", dev->name, dev->phys);
120
#endif
121
 
122
        return handle;
123
}
124
 
125
static void speaker_disconnect(struct input_handle *handle)
126
{
127
#ifdef DEBUG_SPK
128
        printk(KERN_DEBUG "speaker.c: Disconnected device: %s\n", handle->dev->phys);
129
#endif  
130
        input_close_device(handle);
131
 
132
        kfree(handle);
133
}
134
 
135
static struct input_device_id speaker_ids[] = {
136
        { .driver_info = 1 },   // Matches all devices
137
        { },                    // Terminating zero entry
138
};
139
 
140
/*static struct input_device_id speaker_ids[] = {
141
        {
142
                .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
143
                .evbit = { BIT(EV_SND) },
144
        },     
145
 
146
        { },    // Terminating entry
147
};*/
148
 
149
MODULE_DEVICE_TABLE(input, speaker_ids);
150
 
151
static struct input_handler speaker_handler = {
152
        .event =        speaker_event,
153
        .connect =      speaker_connect,
154
        .disconnect =   speaker_disconnect,
155
        .name =         "speaker",
156
        .id_table =     speaker_ids,
157
};
158
 
159
int __init speaker_init(void)
160
{
161
        input_register_handler(&speaker_handler);
162
        return 0;
163
}
164
 
165
void __exit speaker_exit(void)
166
{
167
        input_unregister_handler(&speaker_handler);
168
}
169
 
170
module_init(speaker_init);
171
module_exit(speaker_exit);