Subversion Repositories shark

Rev

Rev 519 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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