Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * $Id: cx88-input.c,v 1.9 2005/03/04 09:12:23 kraxel Exp $ | |
3 | * | |
4 | * Device driver for GPIO attached remote control interfaces | |
5 | * on Conexant 2388x based TV/DVB cards. | |
6 | * | |
7 | * Copyright (c) 2003 Pavel Machek | |
8 | * Copyright (c) 2004 Gerd Knorr | |
9 | * Copyright (c) 2004 Chris Pascoe | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 | */ | |
25 | ||
26 | #include <linux/init.h> | |
27 | #include <linux/delay.h> | |
28 | #include <linux/input.h> | |
29 | #include <linux/pci.h> | |
30 | #include <linux/module.h> | |
31 | #include <linux/moduleparam.h> | |
32 | ||
33 | #include <media/ir-common.h> | |
34 | ||
35 | #include "cx88.h" | |
36 | ||
37 | /* ---------------------------------------------------------------------- */ | |
38 | ||
39 | /* DigitalNow DNTV Live DVB-T Remote */ | |
40 | static IR_KEYTAB_TYPE ir_codes_dntv_live_dvb_t[IR_KEYTAB_SIZE] = { | |
41 | [ 0x00 ] = KEY_ESC, // 'go up a level?' | |
42 | [ 0x01 ] = KEY_KP1, // '1' | |
43 | [ 0x02 ] = KEY_KP2, // '2' | |
44 | [ 0x03 ] = KEY_KP3, // '3' | |
45 | [ 0x04 ] = KEY_KP4, // '4' | |
46 | [ 0x05 ] = KEY_KP5, // '5' | |
47 | [ 0x06 ] = KEY_KP6, // '6' | |
48 | [ 0x07 ] = KEY_KP7, // '7' | |
49 | [ 0x08 ] = KEY_KP8, // '8' | |
50 | [ 0x09 ] = KEY_KP9, // '9' | |
51 | [ 0x0a ] = KEY_KP0, // '0' | |
52 | [ 0x0b ] = KEY_TUNER, // 'tv/fm' | |
53 | [ 0x0c ] = KEY_SEARCH, // 'scan' | |
54 | [ 0x0d ] = KEY_STOP, // 'stop' | |
55 | [ 0x0e ] = KEY_PAUSE, // 'pause' | |
56 | [ 0x0f ] = KEY_LIST, // 'source' | |
57 | ||
58 | [ 0x10 ] = KEY_MUTE, // 'mute' | |
59 | [ 0x11 ] = KEY_REWIND, // 'backward <<' | |
60 | [ 0x12 ] = KEY_POWER, // 'power' | |
61 | [ 0x13 ] = KEY_S, // 'snap' | |
62 | [ 0x14 ] = KEY_AUDIO, // 'stereo' | |
63 | [ 0x15 ] = KEY_CLEAR, // 'reset' | |
64 | [ 0x16 ] = KEY_PLAY, // 'play' | |
65 | [ 0x17 ] = KEY_ENTER, // 'enter' | |
66 | [ 0x18 ] = KEY_ZOOM, // 'full screen' | |
67 | [ 0x19 ] = KEY_FASTFORWARD, // 'forward >>' | |
68 | [ 0x1a ] = KEY_CHANNELUP, // 'channel +' | |
69 | [ 0x1b ] = KEY_VOLUMEUP, // 'volume +' | |
70 | [ 0x1c ] = KEY_INFO, // 'preview' | |
71 | [ 0x1d ] = KEY_RECORD, // 'record' | |
72 | [ 0x1e ] = KEY_CHANNELDOWN, // 'channel -' | |
73 | [ 0x1f ] = KEY_VOLUMEDOWN, // 'volume -' | |
74 | }; | |
75 | ||
76 | /* ---------------------------------------------------------------------- */ | |
77 | ||
78 | /* IO-DATA BCTV7E Remote */ | |
79 | static IR_KEYTAB_TYPE ir_codes_iodata_bctv7e[IR_KEYTAB_SIZE] = { | |
80 | [ 0x40 ] = KEY_TV, // TV | |
81 | [ 0x20 ] = KEY_RADIO, // FM | |
82 | [ 0x60 ] = KEY_EPG, // EPG | |
83 | [ 0x00 ] = KEY_POWER, // power | |
84 | ||
85 | [ 0x50 ] = KEY_KP1, // 1 | |
86 | [ 0x30 ] = KEY_KP2, // 2 | |
87 | [ 0x70 ] = KEY_KP3, // 3 | |
88 | [ 0x10 ] = KEY_L, // Live | |
89 | ||
90 | [ 0x48 ] = KEY_KP4, // 4 | |
91 | [ 0x28 ] = KEY_KP5, // 5 | |
92 | [ 0x68 ] = KEY_KP6, // 6 | |
93 | [ 0x08 ] = KEY_T, // Time Shift | |
94 | ||
95 | [ 0x58 ] = KEY_KP7, // 7 | |
96 | [ 0x38 ] = KEY_KP8, // 8 | |
97 | [ 0x78 ] = KEY_KP9, // 9 | |
98 | [ 0x18 ] = KEY_PLAYPAUSE, // Play | |
99 | ||
100 | [ 0x44 ] = KEY_KP0, // 10 | |
101 | [ 0x24 ] = KEY_ENTER, // 11 | |
102 | [ 0x64 ] = KEY_ESC, // 12 | |
103 | [ 0x04 ] = KEY_M, // Multi | |
104 | ||
105 | [ 0x54 ] = KEY_VIDEO, // VIDEO | |
106 | [ 0x34 ] = KEY_CHANNELUP, // channel + | |
107 | [ 0x74 ] = KEY_VOLUMEUP, // volume + | |
108 | [ 0x14 ] = KEY_MUTE, // Mute | |
109 | ||
110 | [ 0x4c ] = KEY_S, // SVIDEO | |
111 | [ 0x2c ] = KEY_CHANNELDOWN, // channel - | |
112 | [ 0x6c ] = KEY_VOLUMEDOWN, // volume - | |
113 | [ 0x0c ] = KEY_ZOOM, // Zoom | |
114 | ||
115 | [ 0x5c ] = KEY_PAUSE, // pause | |
116 | [ 0x3c ] = KEY_C, // || (red) | |
117 | [ 0x7c ] = KEY_RECORD, // recording | |
118 | [ 0x1c ] = KEY_STOP, // stop | |
119 | ||
120 | [ 0x41 ] = KEY_REWIND, // backward << | |
121 | [ 0x21 ] = KEY_PLAY, // play | |
122 | [ 0x61 ] = KEY_FASTFORWARD, // forward >> | |
123 | [ 0x01 ] = KEY_NEXT, // skip >| | |
124 | }; | |
125 | ||
126 | /* ---------------------------------------------------------------------- */ | |
127 | ||
128 | struct cx88_IR { | |
129 | struct cx88_core *core; | |
130 | struct input_dev input; | |
131 | struct ir_input_state ir; | |
132 | char name[32]; | |
133 | char phys[32]; | |
134 | ||
135 | /* sample from gpio pin 16 */ | |
136 | int sampling; | |
137 | u32 samples[16]; | |
138 | int scount; | |
139 | unsigned long release; | |
140 | ||
141 | /* poll external decoder */ | |
142 | int polling; | |
143 | struct work_struct work; | |
144 | struct timer_list timer; | |
145 | u32 gpio_addr; | |
146 | u32 last_gpio; | |
147 | u32 mask_keycode; | |
148 | u32 mask_keydown; | |
149 | u32 mask_keyup; | |
150 | }; | |
151 | ||
152 | static int ir_debug = 0; | |
153 | module_param(ir_debug, int, 0644); /* debug level [IR] */ | |
154 | MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); | |
155 | ||
156 | #define ir_dprintk(fmt, arg...) if (ir_debug) \ | |
157 | printk(KERN_DEBUG "%s IR: " fmt , ir->core->name, ## arg) | |
158 | ||
159 | /* ---------------------------------------------------------------------- */ | |
160 | ||
161 | static void cx88_ir_handle_key(struct cx88_IR *ir) | |
162 | { | |
163 | struct cx88_core *core = ir->core; | |
164 | u32 gpio, data; | |
165 | ||
166 | /* read gpio value */ | |
167 | gpio = cx_read(ir->gpio_addr); | |
168 | if (ir->polling) { | |
169 | if (ir->last_gpio == gpio) | |
170 | return; | |
171 | ir->last_gpio = gpio; | |
172 | } | |
173 | ||
174 | /* extract data */ | |
175 | data = ir_extract_bits(gpio, ir->mask_keycode); | |
176 | ir_dprintk("irq gpio=0x%x code=%d | %s%s%s\n", | |
177 | gpio, data, | |
178 | ir->polling ? "poll" : "irq", | |
179 | (gpio & ir->mask_keydown) ? " down" : "", | |
180 | (gpio & ir->mask_keyup) ? " up" : ""); | |
181 | ||
182 | if (ir->mask_keydown) { | |
183 | /* bit set on keydown */ | |
184 | if (gpio & ir->mask_keydown) { | |
185 | ir_input_keydown(&ir->input,&ir->ir,data,data); | |
186 | } else { | |
187 | ir_input_nokey(&ir->input,&ir->ir); | |
188 | } | |
189 | ||
190 | } else if (ir->mask_keyup) { | |
191 | /* bit cleared on keydown */ | |
192 | if (0 == (gpio & ir->mask_keyup)) { | |
193 | ir_input_keydown(&ir->input,&ir->ir,data,data); | |
194 | } else { | |
195 | ir_input_nokey(&ir->input,&ir->ir); | |
196 | } | |
197 | ||
198 | } else { | |
199 | /* can't distinguish keydown/up :-/ */ | |
200 | ir_input_keydown(&ir->input,&ir->ir,data,data); | |
201 | ir_input_nokey(&ir->input,&ir->ir); | |
202 | } | |
203 | } | |
204 | ||
205 | static void ir_timer(unsigned long data) | |
206 | { | |
207 | struct cx88_IR *ir = (struct cx88_IR*)data; | |
208 | ||
209 | schedule_work(&ir->work); | |
210 | } | |
211 | ||
212 | static void cx88_ir_work(void *data) | |
213 | { | |
214 | struct cx88_IR *ir = data; | |
215 | unsigned long timeout; | |
216 | ||
217 | cx88_ir_handle_key(ir); | |
218 | timeout = jiffies + (ir->polling * HZ / 1000); | |
219 | mod_timer(&ir->timer, timeout); | |
220 | } | |
221 | ||
222 | /* ---------------------------------------------------------------------- */ | |
223 | ||
224 | int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci) | |
225 | { | |
226 | struct cx88_IR *ir; | |
227 | IR_KEYTAB_TYPE *ir_codes = NULL; | |
228 | int ir_type = IR_TYPE_OTHER; | |
229 | ||
230 | ir = kmalloc(sizeof(*ir),GFP_KERNEL); | |
231 | if (NULL == ir) | |
232 | return -ENOMEM; | |
233 | memset(ir,0,sizeof(*ir)); | |
234 | ||
235 | /* detect & configure */ | |
236 | switch (core->board) { | |
237 | case CX88_BOARD_DNTV_LIVE_DVB_T: | |
238 | ir_codes = ir_codes_dntv_live_dvb_t; | |
239 | ir->gpio_addr = MO_GP1_IO; | |
240 | ir->mask_keycode = 0x1f; | |
241 | ir->mask_keyup = 0x60; | |
242 | ir->polling = 50; // ms | |
243 | break; | |
244 | case CX88_BOARD_HAUPPAUGE: | |
245 | case CX88_BOARD_HAUPPAUGE_DVB_T1: | |
246 | ir_codes = ir_codes_hauppauge_new; | |
247 | ir_type = IR_TYPE_RC5; | |
248 | ir->sampling = 1; | |
249 | break; | |
250 | case CX88_BOARD_WINFAST2000XP_EXPERT: | |
251 | ir_codes = ir_codes_winfast; | |
252 | ir->gpio_addr = MO_GP0_IO; | |
253 | ir->mask_keycode = 0x8f8; | |
254 | ir->mask_keyup = 0x100; | |
255 | ir->polling = 1; // ms | |
256 | break; | |
257 | case CX88_BOARD_IODATA_GVBCTV7E: | |
258 | ir_codes = ir_codes_iodata_bctv7e; | |
259 | ir->gpio_addr = MO_GP0_IO; | |
260 | ir->mask_keycode = 0xfd; | |
261 | ir->mask_keydown = 0x02; | |
262 | ir->polling = 5; // ms | |
263 | break; | |
239df2e2 MC |
264 | case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO: |
265 | ir_codes = ir_codes_pixelview; | |
266 | ir->gpio_addr = MO_GP1_IO; | |
267 | ir->mask_keycode = 0x1f; | |
268 | ir->mask_keyup = 0x80; | |
269 | ir->polling = 1; // ms | |
270 | break; | |
1da177e4 LT |
271 | } |
272 | if (NULL == ir_codes) { | |
273 | kfree(ir); | |
274 | return -ENODEV; | |
275 | } | |
276 | ||
277 | /* init input device */ | |
278 | snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", | |
279 | cx88_boards[core->board].name); | |
280 | snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", | |
281 | pci_name(pci)); | |
282 | ||
283 | ir_input_init(&ir->input, &ir->ir, ir_type, ir_codes); | |
284 | ir->input.name = ir->name; | |
285 | ir->input.phys = ir->phys; | |
286 | ir->input.id.bustype = BUS_PCI; | |
287 | ir->input.id.version = 1; | |
288 | if (pci->subsystem_vendor) { | |
289 | ir->input.id.vendor = pci->subsystem_vendor; | |
290 | ir->input.id.product = pci->subsystem_device; | |
291 | } else { | |
292 | ir->input.id.vendor = pci->vendor; | |
293 | ir->input.id.product = pci->device; | |
294 | } | |
295 | ||
296 | /* record handles to ourself */ | |
297 | ir->core = core; | |
298 | core->ir = ir; | |
299 | ||
300 | if (ir->polling) { | |
301 | INIT_WORK(&ir->work, cx88_ir_work, ir); | |
302 | init_timer(&ir->timer); | |
303 | ir->timer.function = ir_timer; | |
304 | ir->timer.data = (unsigned long)ir; | |
305 | schedule_work(&ir->work); | |
306 | } | |
307 | if (ir->sampling) { | |
308 | core->pci_irqmask |= (1<<18); // IR_SMP_INT | |
309 | cx_write(MO_DDS_IO, 0xa80a80); // 4 kHz sample rate | |
310 | cx_write(MO_DDSCFG_IO, 0x5); // enable | |
311 | } | |
312 | ||
313 | /* all done */ | |
314 | input_register_device(&ir->input); | |
315 | printk("%s: registered IR remote control\n", core->name); | |
316 | ||
317 | return 0; | |
318 | } | |
319 | ||
320 | int cx88_ir_fini(struct cx88_core *core) | |
321 | { | |
322 | struct cx88_IR *ir = core->ir; | |
323 | ||
324 | /* skip detach on non attached boards */ | |
325 | if (NULL == ir) | |
326 | return 0; | |
327 | ||
328 | if (ir->polling) { | |
329 | del_timer(&ir->timer); | |
330 | flush_scheduled_work(); | |
331 | } | |
332 | ||
333 | input_unregister_device(&ir->input); | |
334 | kfree(ir); | |
335 | ||
336 | /* done */ | |
337 | core->ir = NULL; | |
338 | return 0; | |
339 | } | |
340 | ||
341 | /* ---------------------------------------------------------------------- */ | |
342 | ||
343 | void cx88_ir_irq(struct cx88_core *core) | |
344 | { | |
345 | struct cx88_IR *ir = core->ir; | |
346 | u32 samples,rc5; | |
347 | int i; | |
348 | ||
349 | if (NULL == ir) | |
350 | return; | |
351 | if (!ir->sampling) | |
352 | return; | |
353 | ||
354 | samples = cx_read(MO_SAMPLE_IO); | |
355 | if (0 != samples && 0xffffffff != samples) { | |
356 | /* record sample data */ | |
357 | if (ir->scount < ARRAY_SIZE(ir->samples)) | |
358 | ir->samples[ir->scount++] = samples; | |
359 | return; | |
360 | } | |
361 | if (!ir->scount) { | |
362 | /* nothing to sample */ | |
363 | if (ir->ir.keypressed && time_after(jiffies,ir->release)) | |
364 | ir_input_nokey(&ir->input,&ir->ir); | |
365 | return; | |
366 | } | |
367 | ||
368 | /* have a complete sample */ | |
369 | if (ir->scount < ARRAY_SIZE(ir->samples)) | |
370 | ir->samples[ir->scount++] = samples; | |
371 | for (i = 0; i < ir->scount; i++) | |
372 | ir->samples[i] = ~ir->samples[i]; | |
373 | if (ir_debug) | |
374 | ir_dump_samples(ir->samples,ir->scount); | |
375 | ||
376 | /* decode it */ | |
377 | switch (core->board) { | |
378 | case CX88_BOARD_HAUPPAUGE: | |
379 | case CX88_BOARD_HAUPPAUGE_DVB_T1: | |
380 | rc5 = ir_decode_biphase(ir->samples,ir->scount,5,7); | |
381 | ir_dprintk("biphase decoded: %x\n",rc5); | |
382 | if ((rc5 & 0xfffff000) != 0x3000) | |
383 | break; | |
384 | ir_input_keydown(&ir->input, &ir->ir, rc5 & 0x3f, rc5); | |
385 | ir->release = jiffies + msecs_to_jiffies(120); | |
386 | break; | |
387 | } | |
388 | ||
389 | ir->scount = 0; | |
390 | return; | |
391 | } | |
392 | ||
393 | /* ---------------------------------------------------------------------- */ | |
394 | ||
395 | MODULE_AUTHOR("Gerd Knorr, Pavel Machek, Chris Pascoe"); | |
396 | MODULE_DESCRIPTION("input driver for cx88 GPIO-based IR remote controls"); | |
397 | MODULE_LICENSE("GPL"); | |
398 | ||
399 | /* | |
400 | * Local variables: | |
401 | * c-basic-offset: 8 | |
402 | * End: | |
403 | */ |