diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/media/dvb/ttpci/av7110_ir.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/media/dvb/ttpci/av7110_ir.c')
-rw-r--r-- | drivers/media/dvb/ttpci/av7110_ir.c | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c new file mode 100644 index 000000000000..6d2256f1e354 --- /dev/null +++ b/drivers/media/dvb/ttpci/av7110_ir.c | |||
@@ -0,0 +1,212 @@ | |||
1 | #include <linux/types.h> | ||
2 | #include <linux/init.h> | ||
3 | #include <linux/module.h> | ||
4 | #include <linux/moduleparam.h> | ||
5 | #include <linux/input.h> | ||
6 | #include <linux/proc_fs.h> | ||
7 | #include <asm/bitops.h> | ||
8 | |||
9 | #include "av7110.h" | ||
10 | |||
11 | #define UP_TIMEOUT (HZ/4) | ||
12 | |||
13 | /* enable ir debugging by or'ing av7110_debug with 16 */ | ||
14 | |||
15 | static int ir_initialized; | ||
16 | static struct input_dev input_dev; | ||
17 | |||
18 | static u32 ir_config; | ||
19 | |||
20 | static u16 key_map [256] = { | ||
21 | KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, | ||
22 | KEY_8, KEY_9, KEY_BACK, 0, KEY_POWER, KEY_MUTE, 0, KEY_INFO, | ||
23 | KEY_VOLUMEUP, KEY_VOLUMEDOWN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
24 | KEY_CHANNELUP, KEY_CHANNELDOWN, 0, 0, 0, 0, 0, 0, | ||
25 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
26 | 0, 0, 0, 0, KEY_TEXT, 0, 0, KEY_TV, 0, 0, 0, 0, 0, KEY_SETUP, 0, 0, | ||
27 | 0, 0, 0, KEY_SUBTITLE, 0, 0, KEY_LANGUAGE, 0, | ||
28 | KEY_RADIO, 0, 0, 0, 0, KEY_EXIT, 0, 0, | ||
29 | KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_OK, 0, 0, 0, | ||
30 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_RED, KEY_GREEN, KEY_YELLOW, | ||
31 | KEY_BLUE, 0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_LIST, 0, 0, 0, 0, 0, 0, | ||
32 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
33 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
34 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
35 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
36 | 0, 0, 0, 0, KEY_UP, KEY_UP, KEY_DOWN, KEY_DOWN, | ||
37 | 0, 0, 0, 0, KEY_EPG, 0, 0, 0, | ||
38 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
39 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
40 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_VCR | ||
41 | }; | ||
42 | |||
43 | |||
44 | static void av7110_emit_keyup(unsigned long data) | ||
45 | { | ||
46 | if (!data || !test_bit(data, input_dev.key)) | ||
47 | return; | ||
48 | |||
49 | input_event(&input_dev, EV_KEY, data, !!0); | ||
50 | } | ||
51 | |||
52 | |||
53 | static struct timer_list keyup_timer = { .function = av7110_emit_keyup }; | ||
54 | |||
55 | |||
56 | static void av7110_emit_key(u32 ircom) | ||
57 | { | ||
58 | u8 data; | ||
59 | u8 addr; | ||
60 | static u16 old_toggle = 0; | ||
61 | u16 new_toggle; | ||
62 | u16 keycode; | ||
63 | |||
64 | /* extract device address and data */ | ||
65 | if (ir_config & 0x0001) { | ||
66 | /* TODO RCMM: ? bits device address, 8 bits data */ | ||
67 | data = ircom & 0xff; | ||
68 | addr = (ircom >> 8) & 0xff; | ||
69 | } else { | ||
70 | /* RC5: 5 bits device address, 6 bits data */ | ||
71 | data = ircom & 0x3f; | ||
72 | addr = (ircom >> 6) & 0x1f; | ||
73 | } | ||
74 | |||
75 | keycode = key_map[data]; | ||
76 | |||
77 | dprintk(16, "#########%08x######### addr %i data 0x%02x (keycode %i)\n", | ||
78 | ircom, addr, data, keycode); | ||
79 | |||
80 | /* check device address (if selected) */ | ||
81 | if (ir_config & 0x4000) | ||
82 | if (addr != ((ir_config >> 16) & 0xff)) | ||
83 | return; | ||
84 | |||
85 | if (!keycode) { | ||
86 | printk ("%s: unknown key 0x%02x!!\n", __FUNCTION__, data); | ||
87 | return; | ||
88 | } | ||
89 | |||
90 | if (ir_config & 0x0001) | ||
91 | new_toggle = 0; /* RCMM */ | ||
92 | else | ||
93 | new_toggle = (ircom & 0x800); /* RC5 */ | ||
94 | |||
95 | if (timer_pending(&keyup_timer)) { | ||
96 | del_timer(&keyup_timer); | ||
97 | if (keyup_timer.data != keycode || new_toggle != old_toggle) { | ||
98 | input_event(&input_dev, EV_KEY, keyup_timer.data, !!0); | ||
99 | input_event(&input_dev, EV_KEY, keycode, !0); | ||
100 | } else | ||
101 | input_event(&input_dev, EV_KEY, keycode, 2); | ||
102 | |||
103 | } else | ||
104 | input_event(&input_dev, EV_KEY, keycode, !0); | ||
105 | |||
106 | keyup_timer.expires = jiffies + UP_TIMEOUT; | ||
107 | keyup_timer.data = keycode; | ||
108 | |||
109 | add_timer(&keyup_timer); | ||
110 | |||
111 | old_toggle = new_toggle; | ||
112 | } | ||
113 | |||
114 | static void input_register_keys(void) | ||
115 | { | ||
116 | int i; | ||
117 | |||
118 | memset(input_dev.keybit, 0, sizeof(input_dev.keybit)); | ||
119 | |||
120 | for (i = 0; i < sizeof(key_map) / sizeof(key_map[0]); i++) { | ||
121 | if (key_map[i] > KEY_MAX) | ||
122 | key_map[i] = 0; | ||
123 | else if (key_map[i] > KEY_RESERVED) | ||
124 | set_bit(key_map[i], input_dev.keybit); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | |||
129 | static void input_repeat_key(unsigned long data) | ||
130 | { | ||
131 | /* dummy routine to disable autorepeat in the input driver */ | ||
132 | } | ||
133 | |||
134 | |||
135 | static int av7110_ir_write_proc(struct file *file, const char __user *buffer, | ||
136 | unsigned long count, void *data) | ||
137 | { | ||
138 | char *page; | ||
139 | int size = 4 + 256 * sizeof(u16); | ||
140 | |||
141 | if (count < size) | ||
142 | return -EINVAL; | ||
143 | |||
144 | page = (char *) vmalloc(size); | ||
145 | if (!page) | ||
146 | return -ENOMEM; | ||
147 | |||
148 | if (copy_from_user(page, buffer, size)) { | ||
149 | vfree(page); | ||
150 | return -EFAULT; | ||
151 | } | ||
152 | |||
153 | memcpy(&ir_config, page, 4); | ||
154 | memcpy(&key_map, page + 4, 256 * sizeof(u16)); | ||
155 | vfree(page); | ||
156 | av7110_setup_irc_config(NULL, ir_config); | ||
157 | input_register_keys(); | ||
158 | return count; | ||
159 | } | ||
160 | |||
161 | |||
162 | int __init av7110_ir_init(void) | ||
163 | { | ||
164 | static struct proc_dir_entry *e; | ||
165 | |||
166 | if (ir_initialized) | ||
167 | return 0; | ||
168 | |||
169 | init_timer(&keyup_timer); | ||
170 | keyup_timer.data = 0; | ||
171 | |||
172 | input_dev.name = "DVB on-card IR receiver"; | ||
173 | |||
174 | /** | ||
175 | * enable keys | ||
176 | */ | ||
177 | set_bit(EV_KEY, input_dev.evbit); | ||
178 | set_bit(EV_REP, input_dev.evbit); | ||
179 | |||
180 | input_register_keys(); | ||
181 | |||
182 | input_register_device(&input_dev); | ||
183 | input_dev.timer.function = input_repeat_key; | ||
184 | |||
185 | av7110_setup_irc_config(NULL, 0x0001); | ||
186 | av7110_register_irc_handler(av7110_emit_key); | ||
187 | |||
188 | e = create_proc_entry("av7110_ir", S_IFREG | S_IRUGO | S_IWUSR, NULL); | ||
189 | if (e) { | ||
190 | e->write_proc = av7110_ir_write_proc; | ||
191 | e->size = 4 + 256 * sizeof(u16); | ||
192 | } | ||
193 | |||
194 | ir_initialized = 1; | ||
195 | return 0; | ||
196 | } | ||
197 | |||
198 | |||
199 | void __exit av7110_ir_exit(void) | ||
200 | { | ||
201 | if (ir_initialized == 0) | ||
202 | return; | ||
203 | del_timer_sync(&keyup_timer); | ||
204 | remove_proc_entry("av7110_ir", NULL); | ||
205 | av7110_unregister_irc_handler(av7110_emit_key); | ||
206 | input_unregister_device(&input_dev); | ||
207 | ir_initialized = 0; | ||
208 | } | ||
209 | |||
210 | //MODULE_AUTHOR("Holger Waechtler <holger@convergence.de>"); | ||
211 | //MODULE_LICENSE("GPL"); | ||
212 | |||