Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * |
3 | * handle saa7134 IR remotes via linux kernel input layer. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | * | |
19 | */ | |
20 | ||
21 | #include <linux/module.h> | |
1da177e4 LT |
22 | #include <linux/init.h> |
23 | #include <linux/delay.h> | |
1da177e4 LT |
24 | #include <linux/interrupt.h> |
25 | #include <linux/input.h> | |
26 | ||
27 | #include "saa7134-reg.h" | |
28 | #include "saa7134.h" | |
29 | ||
ff699e6b | 30 | static unsigned int disable_ir; |
1da177e4 LT |
31 | module_param(disable_ir, int, 0444); |
32 | MODULE_PARM_DESC(disable_ir,"disable infrared remote support"); | |
33 | ||
ff699e6b | 34 | static unsigned int ir_debug; |
1da177e4 LT |
35 | module_param(ir_debug, int, 0644); |
36 | MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]"); | |
37 | ||
ff699e6b | 38 | static int pinnacle_remote; |
b93eedb6 SP |
39 | module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */ |
40 | MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)"); | |
41 | ||
c408a6f6 | 42 | static int ir_rc5_remote_gap = 885; |
9160723e | 43 | module_param(ir_rc5_remote_gap, int, 0644); |
c408a6f6 | 44 | static int ir_rc5_key_timeout = 115; |
9160723e HP |
45 | module_param(ir_rc5_key_timeout, int, 0644); |
46 | ||
0938e319 P |
47 | static int repeat_delay = 500; |
48 | module_param(repeat_delay, int, 0644); | |
49 | MODULE_PARM_DESC(repeat_delay, "delay before key repeat started"); | |
50 | static int repeat_period = 33; | |
51 | module_param(repeat_period, int, 0644); | |
ac9bb7f5 | 52 | MODULE_PARM_DESC(repeat_period, "repeat period between " |
0938e319 P |
53 | "keypresses when key is down"); |
54 | ||
e8018c9e AMT |
55 | static unsigned int disable_other_ir; |
56 | module_param(disable_other_ir, int, 0644); | |
57 | MODULE_PARM_DESC(disable_other_ir, "disable full codes of " | |
58 | "alternative remotes from other manufacturers"); | |
59 | ||
1da177e4 LT |
60 | #define dprintk(fmt, arg...) if (ir_debug) \ |
61 | printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg) | |
ac9cd976 | 62 | #define i2cdprintk(fmt, arg...) if (ir_debug) \ |
1df8e986 | 63 | printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg) |
1da177e4 | 64 | |
622ecb30 | 65 | /* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */ |
9160723e | 66 | static int saa7134_rc5_irq(struct saa7134_dev *dev); |
622ecb30 MCC |
67 | static int saa7134_nec_irq(struct saa7134_dev *dev); |
68 | static void nec_task(unsigned long data); | |
69 | static void saa7134_nec_timer(unsigned long data); | |
9160723e | 70 | |
ac9cd976 | 71 | /* -------------------- GPIO generic keycode builder -------------------- */ |
1da177e4 LT |
72 | |
73 | static int build_key(struct saa7134_dev *dev) | |
74 | { | |
9160723e | 75 | struct card_ir *ir = dev->remote; |
1da177e4 LT |
76 | u32 gpio, data; |
77 | ||
0938e319 P |
78 | /* here comes the additional handshake steps for some cards */ |
79 | switch (dev->board) { | |
80 | case SAA7134_BOARD_GOTVIEW_7135: | |
81 | saa_setb(SAA7134_GPIO_GPSTATUS1, 0x80); | |
82 | saa_clearb(SAA7134_GPIO_GPSTATUS1, 0x80); | |
83 | break; | |
84 | } | |
1da177e4 LT |
85 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ |
86 | saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN); | |
87 | saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN); | |
88 | ||
89 | gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); | |
4ac97914 MCC |
90 | if (ir->polling) { |
91 | if (ir->last_gpio == gpio) | |
92 | return 0; | |
93 | ir->last_gpio = gpio; | |
94 | } | |
1da177e4 | 95 | |
4ac97914 | 96 | data = ir_extract_bits(gpio, ir->mask_keycode); |
1da177e4 LT |
97 | dprintk("build_key gpio=0x%x mask=0x%x data=%d\n", |
98 | gpio, ir->mask_keycode, data); | |
99 | ||
26d5f3a3 MCC |
100 | switch (dev->board) { |
101 | case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG: | |
102 | if (data == ir->mask_keycode) | |
103 | ir_input_nokey(ir->dev, &ir->ir); | |
104 | else | |
8573b74a | 105 | ir_input_keydown(ir->dev, &ir->ir, data); |
26d5f3a3 MCC |
106 | return 0; |
107 | } | |
108 | ||
0602fbb2 PM |
109 | if (ir->polling) { |
110 | if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || | |
111 | (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { | |
8573b74a | 112 | ir_input_keydown(ir->dev, &ir->ir, data); |
0602fbb2 PM |
113 | } else { |
114 | ir_input_nokey(ir->dev, &ir->ir); | |
115 | } | |
1da177e4 | 116 | } |
0602fbb2 PM |
117 | else { /* IRQ driven mode - handle key press and release in one go */ |
118 | if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || | |
119 | (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { | |
8573b74a | 120 | ir_input_keydown(ir->dev, &ir->ir, data); |
0602fbb2 PM |
121 | ir_input_nokey(ir->dev, &ir->ir); |
122 | } | |
123 | } | |
124 | ||
1da177e4 LT |
125 | return 0; |
126 | } | |
127 | ||
ac9cd976 RC |
128 | /* --------------------- Chip specific I2C key builders ----------------- */ |
129 | ||
d995a187 LK |
130 | static int get_key_flydvb_trio(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
131 | { | |
132 | int gpio; | |
133 | int attempt = 0; | |
134 | unsigned char b; | |
135 | ||
136 | /* We need this to access GPI Used by the saa_readl macro. */ | |
137 | struct saa7134_dev *dev = ir->c->adapter->algo_data; | |
138 | ||
139 | if (dev == NULL) { | |
140 | dprintk("get_key_flydvb_trio: " | |
141 | "gir->c->adapter->algo_data is NULL!\n"); | |
142 | return -EIO; | |
143 | } | |
144 | ||
145 | /* rising SAA7134_GPIGPRESCAN reads the status */ | |
146 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); | |
147 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); | |
148 | ||
149 | gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); | |
150 | ||
151 | if (0x40000 & ~gpio) | |
152 | return 0; /* No button press */ | |
153 | ||
154 | /* No button press - only before first key pressed */ | |
155 | if (b == 0xFF) | |
156 | return 0; | |
157 | ||
158 | /* poll IR chip */ | |
159 | /* weak up the IR chip */ | |
160 | b = 0; | |
161 | ||
162 | while (1 != i2c_master_send(ir->c, &b, 1)) { | |
163 | if ((attempt++) < 10) { | |
164 | /* | |
165 | * wait a bit for next attempt - | |
166 | * I don't know how make it better | |
167 | */ | |
168 | msleep(10); | |
169 | continue; | |
170 | } | |
171 | i2cdprintk("send wake up byte to pic16C505 (IR chip)" | |
172 | "failed %dx\n", attempt); | |
173 | return -EIO; | |
174 | } | |
175 | if (1 != i2c_master_recv(ir->c, &b, 1)) { | |
176 | i2cdprintk("read error\n"); | |
177 | return -EIO; | |
178 | } | |
179 | ||
180 | *ir_key = b; | |
181 | *ir_raw = b; | |
182 | return 1; | |
183 | } | |
184 | ||
ba340b40 BR |
185 | static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key, |
186 | u32 *ir_raw) | |
187 | { | |
188 | unsigned char b; | |
189 | int gpio; | |
190 | ||
191 | /* <dev> is needed to access GPIO. Used by the saa_readl macro. */ | |
c668f32d | 192 | struct saa7134_dev *dev = ir->c->adapter->algo_data; |
ba340b40 BR |
193 | if (dev == NULL) { |
194 | dprintk("get_key_msi_tvanywhere_plus: " | |
c668f32d | 195 | "gir->c->adapter->algo_data is NULL!\n"); |
ba340b40 BR |
196 | return -EIO; |
197 | } | |
198 | ||
199 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ | |
200 | ||
201 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); | |
202 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); | |
203 | ||
204 | gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); | |
205 | ||
206 | /* GPIO&0x40 is pulsed low when a button is pressed. Don't do | |
207 | I2C receive if gpio&0x40 is not low. */ | |
208 | ||
209 | if (gpio & 0x40) | |
210 | return 0; /* No button press */ | |
211 | ||
212 | /* GPIO says there is a button press. Get it. */ | |
213 | ||
c668f32d | 214 | if (1 != i2c_master_recv(ir->c, &b, 1)) { |
ba340b40 BR |
215 | i2cdprintk("read error\n"); |
216 | return -EIO; | |
217 | } | |
218 | ||
219 | /* No button press */ | |
220 | ||
221 | if (b == 0xff) | |
222 | return 0; | |
223 | ||
224 | /* Button pressed */ | |
225 | ||
226 | dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b); | |
227 | *ir_key = b; | |
228 | *ir_raw = b; | |
229 | return 1; | |
230 | } | |
231 | ||
ac9cd976 RC |
232 | static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
233 | { | |
234 | unsigned char b; | |
235 | ||
236 | /* poll IR chip */ | |
c668f32d | 237 | if (1 != i2c_master_recv(ir->c, &b, 1)) { |
ac9cd976 RC |
238 | i2cdprintk("read error\n"); |
239 | return -EIO; | |
240 | } | |
241 | ||
242 | /* no button press */ | |
243 | if (b==0) | |
244 | return 0; | |
245 | ||
246 | /* repeating */ | |
247 | if (b & 0x80) | |
248 | return 1; | |
249 | ||
250 | *ir_key = b; | |
251 | *ir_raw = b; | |
252 | return 1; | |
253 | } | |
254 | ||
177aaaf8 TG |
255 | static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
256 | { | |
257 | unsigned char buf[5], cod4, code3, code4; | |
258 | ||
259 | /* poll IR chip */ | |
c668f32d | 260 | if (5 != i2c_master_recv(ir->c, buf, 5)) |
177aaaf8 TG |
261 | return -EIO; |
262 | ||
263 | cod4 = buf[4]; | |
264 | code4 = (cod4 >> 2); | |
265 | code3 = buf[3]; | |
266 | if (code3 == 0) | |
267 | /* no key pressed */ | |
268 | return 0; | |
269 | ||
270 | /* return key */ | |
271 | *ir_key = code4; | |
272 | *ir_raw = code4; | |
273 | return 1; | |
274 | } | |
275 | ||
e8018c9e AMT |
276 | |
277 | static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) | |
278 | { | |
279 | unsigned char data[12]; | |
280 | u32 gpio; | |
281 | ||
c668f32d | 282 | struct saa7134_dev *dev = ir->c->adapter->algo_data; |
e8018c9e AMT |
283 | |
284 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ | |
285 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); | |
286 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); | |
287 | ||
288 | gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); | |
289 | ||
616f8878 | 290 | if (0x400000 & ~gpio) |
e8018c9e AMT |
291 | return 0; /* No button press */ |
292 | ||
c668f32d | 293 | ir->c->addr = 0x5a >> 1; |
e8018c9e | 294 | |
c668f32d | 295 | if (12 != i2c_master_recv(ir->c, data, 12)) { |
e8018c9e AMT |
296 | i2cdprintk("read error\n"); |
297 | return -EIO; | |
298 | } | |
299 | /* IR of this card normally decode signals NEC-standard from | |
300 | * - Sven IHOO MT 5.1R remote. xxyye718 | |
301 | * - Sven DVD HD-10xx remote. xxyyf708 | |
302 | * - BBK ... | |
303 | * - mayby others | |
304 | * So, skip not our, if disable full codes mode. | |
305 | */ | |
306 | if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir) | |
307 | return 0; | |
308 | ||
2d21ffe0 DB |
309 | /* Wrong data decode fix */ |
310 | if (data[9] != (unsigned char)(~data[8])) | |
311 | return 0; | |
312 | ||
e8018c9e AMT |
313 | *ir_key = data[9]; |
314 | *ir_raw = data[9]; | |
315 | ||
316 | return 1; | |
317 | } | |
318 | ||
1c22dad8 MCC |
319 | /* Common (grey or coloured) pinnacle PCTV remote handling |
320 | * | |
321 | */ | |
322 | static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw, | |
323 | int parity_offset, int marker, int code_modulo) | |
324 | { | |
325 | unsigned char b[4]; | |
326 | unsigned int start = 0,parity = 0,code = 0; | |
327 | ||
328 | /* poll IR chip */ | |
c668f32d | 329 | if (4 != i2c_master_recv(ir->c, b, 4)) { |
1c22dad8 MCC |
330 | i2cdprintk("read error\n"); |
331 | return -EIO; | |
332 | } | |
333 | ||
334 | for (start = 0; start < ARRAY_SIZE(b); start++) { | |
335 | if (b[start] == marker) { | |
336 | code=b[(start+parity_offset + 1) % 4]; | |
337 | parity=b[(start+parity_offset) % 4]; | |
338 | } | |
339 | } | |
340 | ||
341 | /* Empty Request */ | |
342 | if (parity == 0) | |
343 | return 0; | |
344 | ||
345 | /* Repeating... */ | |
346 | if (ir->old == parity) | |
347 | return 0; | |
348 | ||
349 | ir->old = parity; | |
350 | ||
351 | /* drop special codes when a key is held down a long time for the grey controller | |
352 | In this case, the second bit of the code is asserted */ | |
353 | if (marker == 0xfe && (code & 0x40)) | |
354 | return 0; | |
355 | ||
356 | code %= code_modulo; | |
357 | ||
358 | *ir_raw = code; | |
359 | *ir_key = code; | |
360 | ||
361 | i2cdprintk("Pinnacle PCTV key %02x\n", code); | |
362 | ||
363 | return 1; | |
364 | } | |
365 | ||
366 | /* The grey pinnacle PCTV remote | |
367 | * | |
368 | * There are one issue with this remote: | |
369 | * - I2c packet does not change when the same key is pressed quickly. The workaround | |
370 | * is to hold down each key for about half a second, so that another code is generated | |
371 | * in the i2c packet, and the function can distinguish key presses. | |
372 | * | |
373 | * Sylvain Pasche <sylvain.pasche@gmail.com> | |
374 | */ | |
375 | static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) | |
376 | { | |
377 | ||
378 | return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff); | |
379 | } | |
380 | ||
381 | ||
382 | /* The new pinnacle PCTV remote (with the colored buttons) | |
383 | * | |
384 | * Ricardo Cerqueira <v4l@cerqueira.org> | |
385 | */ | |
386 | static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) | |
387 | { | |
388 | /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE | |
389 | * | |
390 | * this is the only value that results in 42 unique | |
391 | * codes < 128 | |
392 | */ | |
393 | ||
394 | return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88); | |
395 | } | |
396 | ||
1da177e4 LT |
397 | void saa7134_input_irq(struct saa7134_dev *dev) |
398 | { | |
9160723e | 399 | struct card_ir *ir = dev->remote; |
1da177e4 | 400 | |
622ecb30 MCC |
401 | if (ir->nec_gpio) { |
402 | saa7134_nec_irq(dev); | |
403 | } else if (!ir->polling && !ir->rc5_gpio) { | |
1da177e4 | 404 | build_key(dev); |
9160723e HP |
405 | } else if (ir->rc5_gpio) { |
406 | saa7134_rc5_irq(dev); | |
407 | } | |
1da177e4 LT |
408 | } |
409 | ||
410 | static void saa7134_input_timer(unsigned long data) | |
411 | { | |
b4ba7884 | 412 | struct saa7134_dev *dev = (struct saa7134_dev *)data; |
9160723e | 413 | struct card_ir *ir = dev->remote; |
1da177e4 LT |
414 | |
415 | build_key(dev); | |
b4ba7884 | 416 | mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); |
1da177e4 LT |
417 | } |
418 | ||
c458473e | 419 | void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir) |
b07b4783 DT |
420 | { |
421 | if (ir->polling) { | |
b4ba7884 DT |
422 | setup_timer(&ir->timer, saa7134_input_timer, |
423 | (unsigned long)dev); | |
b07b4783 DT |
424 | ir->timer.expires = jiffies + HZ; |
425 | add_timer(&ir->timer); | |
9160723e HP |
426 | } else if (ir->rc5_gpio) { |
427 | /* set timer_end for code completion */ | |
428 | init_timer(&ir->timer_end); | |
429 | ir->timer_end.function = ir_rc5_timer_end; | |
430 | ir->timer_end.data = (unsigned long)ir; | |
431 | init_timer(&ir->timer_keyup); | |
432 | ir->timer_keyup.function = ir_rc5_timer_keyup; | |
433 | ir->timer_keyup.data = (unsigned long)ir; | |
434 | ir->shift_by = 2; | |
435 | ir->start = 0x2; | |
436 | ir->addr = 0x17; | |
437 | ir->rc5_key_timeout = ir_rc5_key_timeout; | |
438 | ir->rc5_remote_gap = ir_rc5_remote_gap; | |
622ecb30 MCC |
439 | } else if (ir->nec_gpio) { |
440 | setup_timer(&ir->timer_keyup, saa7134_nec_timer, | |
441 | (unsigned long)dev); | |
442 | tasklet_init(&ir->tlet, nec_task, (unsigned long)dev); | |
b07b4783 DT |
443 | } |
444 | } | |
445 | ||
c458473e | 446 | void saa7134_ir_stop(struct saa7134_dev *dev) |
b07b4783 DT |
447 | { |
448 | if (dev->remote->polling) | |
449 | del_timer_sync(&dev->remote->timer); | |
450 | } | |
451 | ||
1da177e4 LT |
452 | int saa7134_input_init1(struct saa7134_dev *dev) |
453 | { | |
9160723e | 454 | struct card_ir *ir; |
b7df3910 | 455 | struct input_dev *input_dev; |
715a2233 | 456 | struct ir_scancode_table *ir_codes = NULL; |
1da177e4 LT |
457 | u32 mask_keycode = 0; |
458 | u32 mask_keydown = 0; | |
459 | u32 mask_keyup = 0; | |
460 | int polling = 0; | |
9160723e | 461 | int rc5_gpio = 0; |
622ecb30 | 462 | int nec_gpio = 0; |
971e8298 | 463 | u64 ir_type = IR_TYPE_OTHER; |
b07b4783 | 464 | int err; |
1da177e4 | 465 | |
cb2444df | 466 | if (dev->has_remote != SAA7134_REMOTE_GPIO) |
1da177e4 LT |
467 | return -ENODEV; |
468 | if (disable_ir) | |
469 | return -ENODEV; | |
470 | ||
471 | /* detect & configure */ | |
472 | switch (dev->board) { | |
473 | case SAA7134_BOARD_FLYVIDEO2000: | |
474 | case SAA7134_BOARD_FLYVIDEO3000: | |
4ac97914 | 475 | case SAA7134_BOARD_FLYTVPLATINUM_FM: |
6af90ab5 | 476 | case SAA7134_BOARD_FLYTVPLATINUM_MINI2: |
23389b88 | 477 | case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM: |
715a2233 | 478 | ir_codes = &ir_codes_flyvideo_table; |
1da177e4 LT |
479 | mask_keycode = 0xEC00000; |
480 | mask_keydown = 0x0040000; | |
481 | break; | |
482 | case SAA7134_BOARD_CINERGY400: | |
483 | case SAA7134_BOARD_CINERGY600: | |
484 | case SAA7134_BOARD_CINERGY600_MK3: | |
715a2233 | 485 | ir_codes = &ir_codes_cinergy_table; |
1da177e4 LT |
486 | mask_keycode = 0x00003f; |
487 | mask_keyup = 0x040000; | |
488 | break; | |
489 | case SAA7134_BOARD_ECS_TVP3XP: | |
490 | case SAA7134_BOARD_ECS_TVP3XP_4CB5: | |
715a2233 | 491 | ir_codes = &ir_codes_eztv_table; |
330a115a MCC |
492 | mask_keycode = 0x00017c; |
493 | mask_keyup = 0x000002; | |
1da177e4 | 494 | polling = 50; // ms |
330a115a MCC |
495 | break; |
496 | case SAA7134_BOARD_KWORLD_XPERT: | |
1da177e4 | 497 | case SAA7134_BOARD_AVACSSMARTTV: |
715a2233 | 498 | ir_codes = &ir_codes_pixelview_table; |
1da177e4 LT |
499 | mask_keycode = 0x00001F; |
500 | mask_keyup = 0x000020; | |
501 | polling = 50; // ms | |
502 | break; | |
503 | case SAA7134_BOARD_MD2819: | |
ac19ecc6 | 504 | case SAA7134_BOARD_KWORLD_VSTREAM_XPERT: |
1da177e4 LT |
505 | case SAA7134_BOARD_AVERMEDIA_305: |
506 | case SAA7134_BOARD_AVERMEDIA_307: | |
ac19ecc6 | 507 | case SAA7134_BOARD_AVERMEDIA_STUDIO_305: |
5a5e1da5 | 508 | case SAA7134_BOARD_AVERMEDIA_STUDIO_505: |
ac19ecc6 | 509 | case SAA7134_BOARD_AVERMEDIA_STUDIO_307: |
3ac706d2 | 510 | case SAA7134_BOARD_AVERMEDIA_STUDIO_507: |
df0dbbe2 | 511 | case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA: |
ac19ecc6 | 512 | case SAA7134_BOARD_AVERMEDIA_GO_007_FM: |
d2761f22 | 513 | case SAA7134_BOARD_AVERMEDIA_M102: |
6a2d802c | 514 | case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS: |
715a2233 | 515 | ir_codes = &ir_codes_avermedia_table; |
1da177e4 LT |
516 | mask_keycode = 0x0007C8; |
517 | mask_keydown = 0x000010; | |
518 | polling = 50; // ms | |
519 | /* Set GPIO pin2 to high to enable the IR controller */ | |
520 | saa_setb(SAA7134_GPIO_GPMODE0, 0x4); | |
521 | saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4); | |
522 | break; | |
36f6bb97 | 523 | case SAA7134_BOARD_AVERMEDIA_M135A: |
715a2233 | 524 | ir_codes = &ir_codes_avermedia_m135a_table; |
36f6bb97 MCC |
525 | mask_keydown = 0x0040000; |
526 | mask_keycode = 0x00013f; | |
527 | nec_gpio = 1; | |
528 | break; | |
450efcfd | 529 | case SAA7134_BOARD_AVERMEDIA_777: |
29e0f1a1 | 530 | case SAA7134_BOARD_AVERMEDIA_A16AR: |
715a2233 | 531 | ir_codes = &ir_codes_avermedia_table; |
450efcfd | 532 | mask_keycode = 0x02F200; |
533 | mask_keydown = 0x000400; | |
534 | polling = 50; // ms | |
535 | /* Without this we won't receive key up events */ | |
536 | saa_setb(SAA7134_GPIO_GPMODE1, 0x1); | |
537 | saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1); | |
4dd7406e | 538 | break; |
6e501a3f | 539 | case SAA7134_BOARD_AVERMEDIA_A16D: |
715a2233 | 540 | ir_codes = &ir_codes_avermedia_a16d_table; |
6e501a3f TF |
541 | mask_keycode = 0x02F200; |
542 | mask_keydown = 0x000400; | |
543 | polling = 50; /* ms */ | |
544 | /* Without this we won't receive key up events */ | |
545 | saa_setb(SAA7134_GPIO_GPMODE1, 0x1); | |
546 | saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1); | |
547 | break; | |
4ac97914 | 548 | case SAA7134_BOARD_KWORLD_TERMINATOR: |
715a2233 | 549 | ir_codes = &ir_codes_pixelview_table; |
dc2286cf JW |
550 | mask_keycode = 0x00001f; |
551 | mask_keyup = 0x000060; | |
552 | polling = 50; // ms | |
553 | break; | |
ac19ecc6 MCC |
554 | case SAA7134_BOARD_MANLI_MTV001: |
555 | case SAA7134_BOARD_MANLI_MTV002: | |
715a2233 | 556 | ir_codes = &ir_codes_manli_table; |
b34dddbe DB |
557 | mask_keycode = 0x001f00; |
558 | mask_keyup = 0x004000; | |
559 | polling = 50; /* ms */ | |
560 | break; | |
a8ff417e | 561 | case SAA7134_BOARD_BEHOLD_409FM: |
e8018c9e AMT |
562 | case SAA7134_BOARD_BEHOLD_401: |
563 | case SAA7134_BOARD_BEHOLD_403: | |
564 | case SAA7134_BOARD_BEHOLD_403FM: | |
565 | case SAA7134_BOARD_BEHOLD_405: | |
566 | case SAA7134_BOARD_BEHOLD_405FM: | |
567 | case SAA7134_BOARD_BEHOLD_407: | |
568 | case SAA7134_BOARD_BEHOLD_407FM: | |
569 | case SAA7134_BOARD_BEHOLD_409: | |
570 | case SAA7134_BOARD_BEHOLD_505FM: | |
84d728c3 | 571 | case SAA7134_BOARD_BEHOLD_505RDS: |
e8018c9e | 572 | case SAA7134_BOARD_BEHOLD_507_9FM: |
84d728c3 DB |
573 | case SAA7134_BOARD_BEHOLD_507RDS_MK3: |
574 | case SAA7134_BOARD_BEHOLD_507RDS_MK5: | |
715a2233 | 575 | ir_codes = &ir_codes_manli_table; |
b34dddbe DB |
576 | mask_keycode = 0x003f00; |
577 | mask_keyup = 0x004000; | |
578 | polling = 50; /* ms */ | |
579 | break; | |
580 | case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM: | |
715a2233 | 581 | ir_codes = &ir_codes_behold_columbus_table; |
b34dddbe | 582 | mask_keycode = 0x003f00; |
ac19ecc6 | 583 | mask_keyup = 0x004000; |
ac19ecc6 MCC |
584 | polling = 50; // ms |
585 | break; | |
17ce1ff9 | 586 | case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS: |
715a2233 | 587 | ir_codes = &ir_codes_pctv_sedna_table; |
c3d93192 PM |
588 | mask_keycode = 0x001f00; |
589 | mask_keyup = 0x004000; | |
590 | polling = 50; // ms | |
591 | break; | |
4ac97914 | 592 | case SAA7134_BOARD_GOTVIEW_7135: |
715a2233 | 593 | ir_codes = &ir_codes_gotview7135_table; |
0938e319 | 594 | mask_keycode = 0x0003CC; |
6b961440 | 595 | mask_keydown = 0x000010; |
0938e319 P |
596 | polling = 5; /* ms */ |
597 | saa_setb(SAA7134_GPIO_GPMODE1, 0x80); | |
6b961440 | 598 | break; |
1da177e4 | 599 | case SAA7134_BOARD_VIDEOMATE_TV_PVR: |
2a9a9a84 | 600 | case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS: |
330a115a | 601 | case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII: |
715a2233 | 602 | ir_codes = &ir_codes_videomate_tv_pvr_table; |
1da177e4 LT |
603 | mask_keycode = 0x00003F; |
604 | mask_keyup = 0x400000; | |
605 | polling = 50; // ms | |
606 | break; | |
b04c1baf | 607 | case SAA7134_BOARD_PROTEUS_2309: |
715a2233 | 608 | ir_codes = &ir_codes_proteus_2309_table; |
b04c1baf MM |
609 | mask_keycode = 0x00007F; |
610 | mask_keyup = 0x000080; | |
611 | polling = 50; // ms | |
612 | break; | |
4ac97914 MCC |
613 | case SAA7134_BOARD_VIDEOMATE_DVBT_300: |
614 | case SAA7134_BOARD_VIDEOMATE_DVBT_200: | |
715a2233 | 615 | ir_codes = &ir_codes_videomate_tv_pvr_table; |
fea095fe NS |
616 | mask_keycode = 0x003F00; |
617 | mask_keyup = 0x040000; | |
618 | break; | |
f5c965ab | 619 | case SAA7134_BOARD_FLYDVBS_LR300: |
3d8466ec | 620 | case SAA7134_BOARD_FLYDVBT_LR301: |
a8029170 | 621 | case SAA7134_BOARD_FLYDVBTDUO: |
715a2233 | 622 | ir_codes = &ir_codes_flydvb_table; |
3d8466ec GG |
623 | mask_keycode = 0x0001F00; |
624 | mask_keydown = 0x0040000; | |
625 | break; | |
9160723e | 626 | case SAA7134_BOARD_ASUSTeK_P7131_DUAL: |
904ab884 | 627 | case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA: |
dfb4ba1e | 628 | case SAA7134_BOARD_ASUSTeK_P7131_ANALOG: |
715a2233 | 629 | ir_codes = &ir_codes_asus_pc39_table; |
9160723e HP |
630 | mask_keydown = 0x0040000; |
631 | rc5_gpio = 1; | |
632 | break; | |
c36c459a JPS |
633 | case SAA7134_BOARD_ENCORE_ENLTV: |
634 | case SAA7134_BOARD_ENCORE_ENLTV_FM: | |
715a2233 | 635 | ir_codes = &ir_codes_encore_enltv_table; |
c36c459a JPS |
636 | mask_keycode = 0x00007f; |
637 | mask_keyup = 0x040000; | |
638 | polling = 50; // ms | |
639 | break; | |
bf1ece6a | 640 | case SAA7134_BOARD_ENCORE_ENLTV_FM53: |
715a2233 | 641 | ir_codes = &ir_codes_encore_enltv_fm53_table; |
bf1ece6a MCC |
642 | mask_keydown = 0x0040000; |
643 | mask_keycode = 0x00007f; | |
644 | nec_gpio = 1; | |
645 | break; | |
480f75ac | 646 | case SAA7134_BOARD_10MOONSTVMASTER3: |
715a2233 | 647 | ir_codes = &ir_codes_encore_enltv_table; |
480f75ac TW |
648 | mask_keycode = 0x5f80000; |
649 | mask_keyup = 0x8000000; | |
650 | polling = 50; //ms | |
651 | break; | |
f0ba356c | 652 | case SAA7134_BOARD_GENIUS_TVGO_A11MCE: |
715a2233 | 653 | ir_codes = &ir_codes_genius_tvgo_a11mce_table; |
f0ba356c AP |
654 | mask_keycode = 0xff; |
655 | mask_keydown = 0xf00000; | |
656 | polling = 50; /* ms */ | |
657 | break; | |
9b000191 | 658 | case SAA7134_BOARD_REAL_ANGEL_220: |
715a2233 | 659 | ir_codes = &ir_codes_real_audio_220_32_keys_table; |
9b000191 MCC |
660 | mask_keycode = 0x3f00; |
661 | mask_keyup = 0x4000; | |
662 | polling = 50; /* ms */ | |
663 | break; | |
26d5f3a3 | 664 | case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG: |
715a2233 | 665 | ir_codes = &ir_codes_kworld_plus_tv_analog_table; |
26d5f3a3 MCC |
666 | mask_keycode = 0x7f; |
667 | polling = 40; /* ms */ | |
668 | break; | |
ecfcfec8 | 669 | case SAA7134_BOARD_VIDEOMATE_S350: |
715a2233 | 670 | ir_codes = &ir_codes_videomate_s350_table; |
ecfcfec8 IL |
671 | mask_keycode = 0x003f00; |
672 | mask_keydown = 0x040000; | |
673 | break; | |
0700adec MO |
674 | case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S: |
675 | ir_codes = &ir_codes_winfast_table; | |
676 | mask_keycode = 0x5f00; | |
677 | mask_keyup = 0x020000; | |
117e1348 | 678 | polling = 50; /* ms */ |
0700adec | 679 | break; |
d995a187 | 680 | break; |
1da177e4 LT |
681 | } |
682 | if (NULL == ir_codes) { | |
683 | printk("%s: Oops: IR config error [card=%d]\n", | |
684 | dev->name, dev->board); | |
685 | return -ENODEV; | |
686 | } | |
687 | ||
b7df3910 DT |
688 | ir = kzalloc(sizeof(*ir), GFP_KERNEL); |
689 | input_dev = input_allocate_device(); | |
690 | if (!ir || !input_dev) { | |
b07b4783 DT |
691 | err = -ENOMEM; |
692 | goto err_out_free; | |
b7df3910 | 693 | } |
1da177e4 | 694 | |
d271d1c2 DT |
695 | ir->dev = input_dev; |
696 | ||
1da177e4 LT |
697 | /* init hardware-specific stuff */ |
698 | ir->mask_keycode = mask_keycode; | |
699 | ir->mask_keydown = mask_keydown; | |
700 | ir->mask_keyup = mask_keyup; | |
4ac97914 | 701 | ir->polling = polling; |
9160723e | 702 | ir->rc5_gpio = rc5_gpio; |
622ecb30 | 703 | ir->nec_gpio = nec_gpio; |
1da177e4 LT |
704 | |
705 | /* init input device */ | |
706 | snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)", | |
707 | saa7134_boards[dev->board].name); | |
708 | snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", | |
709 | pci_name(dev->pci)); | |
710 | ||
579e7d60 | 711 | err = ir_input_init(input_dev, &ir->ir, ir_type); |
055cd556 MCC |
712 | if (err < 0) |
713 | goto err_out_free; | |
714 | ||
b7df3910 DT |
715 | input_dev->name = ir->name; |
716 | input_dev->phys = ir->phys; | |
717 | input_dev->id.bustype = BUS_PCI; | |
718 | input_dev->id.version = 1; | |
1da177e4 | 719 | if (dev->pci->subsystem_vendor) { |
b7df3910 DT |
720 | input_dev->id.vendor = dev->pci->subsystem_vendor; |
721 | input_dev->id.product = dev->pci->subsystem_device; | |
1da177e4 | 722 | } else { |
b7df3910 DT |
723 | input_dev->id.vendor = dev->pci->vendor; |
724 | input_dev->id.product = dev->pci->device; | |
1da177e4 | 725 | } |
2c8a3a33 | 726 | input_dev->dev.parent = &dev->pci->dev; |
1da177e4 | 727 | |
1da177e4 | 728 | dev->remote = ir; |
b07b4783 DT |
729 | saa7134_ir_start(dev, ir); |
730 | ||
e93854da | 731 | err = ir_input_register(ir->dev, ir_codes, NULL); |
b07b4783 DT |
732 | if (err) |
733 | goto err_out_stop; | |
1da177e4 | 734 | |
0938e319 P |
735 | /* the remote isn't as bouncy as a keyboard */ |
736 | ir->dev->rep[REP_DELAY] = repeat_delay; | |
737 | ir->dev->rep[REP_PERIOD] = repeat_period; | |
738 | ||
1da177e4 | 739 | return 0; |
b07b4783 DT |
740 | |
741 | err_out_stop: | |
742 | saa7134_ir_stop(dev); | |
743 | dev->remote = NULL; | |
744 | err_out_free: | |
b07b4783 DT |
745 | kfree(ir); |
746 | return err; | |
1da177e4 LT |
747 | } |
748 | ||
749 | void saa7134_input_fini(struct saa7134_dev *dev) | |
750 | { | |
751 | if (NULL == dev->remote) | |
752 | return; | |
753 | ||
b07b4783 | 754 | saa7134_ir_stop(dev); |
38ef6aa8 | 755 | ir_input_unregister(dev->remote->dev); |
1da177e4 LT |
756 | kfree(dev->remote); |
757 | dev->remote = NULL; | |
758 | } | |
759 | ||
c668f32d | 760 | void saa7134_probe_i2c_ir(struct saa7134_dev *dev) |
ac9cd976 | 761 | { |
43e16ea2 | 762 | struct i2c_board_info info; |
c668f32d | 763 | |
c668f32d JD |
764 | struct i2c_msg msg_msi = { |
765 | .addr = 0x50, | |
766 | .flags = I2C_M_RD, | |
767 | .len = 0, | |
768 | .buf = NULL, | |
769 | }; | |
770 | ||
c668f32d JD |
771 | int rc; |
772 | ||
ac9cd976 | 773 | if (disable_ir) { |
c668f32d | 774 | dprintk("IR has been disabled, not probing for i2c remote\n"); |
ac9cd976 RC |
775 | return; |
776 | } | |
777 | ||
43e16ea2 | 778 | memset(&info, 0, sizeof(struct i2c_board_info)); |
7aedd5ec | 779 | memset(&dev->init_data, 0, sizeof(dev->init_data)); |
43e16ea2 | 780 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); |
c668f32d | 781 | |
ac9cd976 RC |
782 | switch (dev->board) { |
783 | case SAA7134_BOARD_PINNACLE_PCTV_110i: | |
eb591af3 | 784 | case SAA7134_BOARD_PINNACLE_PCTV_310i: |
7aedd5ec | 785 | dev->init_data.name = "Pinnacle PCTV"; |
b93eedb6 | 786 | if (pinnacle_remote == 0) { |
7aedd5ec MCC |
787 | dev->init_data.get_key = get_key_pinnacle_color; |
788 | dev->init_data.ir_codes = &ir_codes_pinnacle_color_table; | |
43e16ea2 | 789 | info.addr = 0x47; |
b93eedb6 | 790 | } else { |
7aedd5ec MCC |
791 | dev->init_data.get_key = get_key_pinnacle_grey; |
792 | dev->init_data.ir_codes = &ir_codes_pinnacle_grey_table; | |
43e16ea2 | 793 | info.addr = 0x47; |
b93eedb6 | 794 | } |
ac9cd976 RC |
795 | break; |
796 | case SAA7134_BOARD_UPMOST_PURPLE_TV: | |
7aedd5ec MCC |
797 | dev->init_data.name = "Purple TV"; |
798 | dev->init_data.get_key = get_key_purpletv; | |
799 | dev->init_data.ir_codes = &ir_codes_purpletv_table; | |
aef02aa1 | 800 | info.addr = 0x7a; |
ac9cd976 | 801 | break; |
ba340b40 | 802 | case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS: |
7aedd5ec MCC |
803 | dev->init_data.name = "MSI TV@nywhere Plus"; |
804 | dev->init_data.get_key = get_key_msi_tvanywhere_plus; | |
805 | dev->init_data.ir_codes = &ir_codes_msi_tvanywhere_plus_table; | |
43e16ea2 | 806 | info.addr = 0x30; |
ec218a41 JD |
807 | /* MSI TV@nywhere Plus controller doesn't seem to |
808 | respond to probes unless we read something from | |
809 | an existing device. Weird... | |
810 | REVISIT: might no longer be needed */ | |
811 | rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1); | |
812 | dprintk(KERN_DEBUG "probe 0x%02x @ %s: %s\n", | |
813 | msg_msi.addr, dev->i2c_adap.name, | |
814 | (1 == rc) ? "yes" : "no"); | |
ba340b40 | 815 | break; |
177aaaf8 | 816 | case SAA7134_BOARD_HAUPPAUGE_HVR1110: |
7aedd5ec MCC |
817 | dev->init_data.name = "HVR 1110"; |
818 | dev->init_data.get_key = get_key_hvr1110; | |
819 | dev->init_data.ir_codes = &ir_codes_hauppauge_new_table; | |
30093e8b | 820 | info.addr = 0x71; |
177aaaf8 | 821 | break; |
84d728c3 DB |
822 | case SAA7134_BOARD_BEHOLD_607FM_MK3: |
823 | case SAA7134_BOARD_BEHOLD_607FM_MK5: | |
824 | case SAA7134_BOARD_BEHOLD_609FM_MK3: | |
825 | case SAA7134_BOARD_BEHOLD_609FM_MK5: | |
826 | case SAA7134_BOARD_BEHOLD_607RDS_MK3: | |
827 | case SAA7134_BOARD_BEHOLD_607RDS_MK5: | |
828 | case SAA7134_BOARD_BEHOLD_609RDS_MK3: | |
829 | case SAA7134_BOARD_BEHOLD_609RDS_MK5: | |
e8018c9e | 830 | case SAA7134_BOARD_BEHOLD_M6: |
878cf2a5 DB |
831 | case SAA7134_BOARD_BEHOLD_M63: |
832 | case SAA7134_BOARD_BEHOLD_M6_EXTRA: | |
02505271 | 833 | case SAA7134_BOARD_BEHOLD_H6: |
2012c87f | 834 | case SAA7134_BOARD_BEHOLD_X7: |
7aedd5ec MCC |
835 | dev->init_data.name = "BeholdTV"; |
836 | dev->init_data.get_key = get_key_beholdm6xx; | |
837 | dev->init_data.ir_codes = &ir_codes_behold_table; | |
30093e8b | 838 | info.addr = 0x2d; |
ac9cd976 | 839 | break; |
d9a88e63 JD |
840 | case SAA7134_BOARD_AVERMEDIA_CARDBUS_501: |
841 | case SAA7134_BOARD_AVERMEDIA_CARDBUS_506: | |
43e16ea2 | 842 | info.addr = 0x40; |
d9a88e63 | 843 | break; |
d995a187 LK |
844 | case SAA7134_BOARD_FLYDVB_TRIO: |
845 | dev->init_data.name = "FlyDVB Trio"; | |
846 | dev->init_data.get_key = get_key_flydvb_trio; | |
847 | dev->init_data.ir_codes = &ir_codes_flydvb_table; | |
848 | info.addr = 0x0b; | |
849 | break; | |
30093e8b JD |
850 | default: |
851 | dprintk("No I2C IR support for board %x\n", dev->board); | |
852 | return; | |
ac9cd976 RC |
853 | } |
854 | ||
7aedd5ec | 855 | if (dev->init_data.name) |
43e16ea2 | 856 | info.platform_data = &dev->init_data; |
30093e8b | 857 | i2c_new_device(&dev->i2c_adap, &info); |
ac9cd976 | 858 | } |
9160723e HP |
859 | |
860 | static int saa7134_rc5_irq(struct saa7134_dev *dev) | |
861 | { | |
862 | struct card_ir *ir = dev->remote; | |
863 | struct timeval tv; | |
864 | u32 gap; | |
865 | unsigned long current_jiffies, timeout; | |
866 | ||
867 | /* get time of bit */ | |
868 | current_jiffies = jiffies; | |
869 | do_gettimeofday(&tv); | |
870 | ||
871 | /* avoid overflow with gap >1s */ | |
872 | if (tv.tv_sec - ir->base_time.tv_sec > 1) { | |
873 | gap = 200000; | |
874 | } else { | |
875 | gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + | |
876 | tv.tv_usec - ir->base_time.tv_usec; | |
877 | } | |
878 | ||
879 | /* active code => add bit */ | |
880 | if (ir->active) { | |
881 | /* only if in the code (otherwise spurious IRQ or timer | |
882 | late) */ | |
883 | if (ir->last_bit < 28) { | |
884 | ir->last_bit = (gap - ir_rc5_remote_gap / 2) / | |
885 | ir_rc5_remote_gap; | |
886 | ir->code |= 1 << ir->last_bit; | |
887 | } | |
888 | /* starting new code */ | |
889 | } else { | |
890 | ir->active = 1; | |
891 | ir->code = 0; | |
892 | ir->base_time = tv; | |
893 | ir->last_bit = 0; | |
894 | ||
895 | timeout = current_jiffies + (500 + 30 * HZ) / 1000; | |
896 | mod_timer(&ir->timer_end, timeout); | |
897 | } | |
898 | ||
899 | return 1; | |
900 | } | |
901 | ||
622ecb30 MCC |
902 | |
903 | /* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms | |
904 | The first pulse (start) has 9 + 4.5 ms | |
1da177e4 | 905 | */ |
622ecb30 MCC |
906 | |
907 | static void saa7134_nec_timer(unsigned long data) | |
908 | { | |
909 | struct saa7134_dev *dev = (struct saa7134_dev *) data; | |
910 | struct card_ir *ir = dev->remote; | |
911 | ||
912 | dprintk("Cancel key repeat\n"); | |
913 | ||
914 | ir_input_nokey(ir->dev, &ir->ir); | |
915 | } | |
916 | ||
917 | static void nec_task(unsigned long data) | |
918 | { | |
919 | struct saa7134_dev *dev = (struct saa7134_dev *) data; | |
920 | struct card_ir *ir; | |
921 | struct timeval tv; | |
922 | int count, pulse, oldpulse, gap; | |
923 | u32 ircode = 0, not_code = 0; | |
924 | int ngap = 0; | |
925 | ||
926 | if (!data) { | |
927 | printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n"); | |
928 | /* GPIO will be kept disabled */ | |
929 | return; | |
930 | } | |
931 | ||
932 | ir = dev->remote; | |
933 | ||
934 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ | |
935 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); | |
936 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); | |
937 | ||
938 | oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown; | |
939 | pulse = oldpulse; | |
940 | ||
941 | do_gettimeofday(&tv); | |
942 | ir->base_time = tv; | |
943 | ||
944 | /* Decode NEC pulsecode. This code can take up to 76.5 ms to run. | |
945 | Unfortunately, using IRQ to decode pulse didn't work, since it uses | |
946 | a pulse train of 38KHz. This means one pulse on each 52 us | |
947 | */ | |
948 | do { | |
949 | /* Wait until the end of pulse/space or 5 ms */ | |
950 | for (count = 0; count < 500; count++) { | |
951 | udelay(10); | |
952 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ | |
953 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); | |
954 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); | |
955 | pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) | |
956 | & ir->mask_keydown; | |
957 | if (pulse != oldpulse) | |
958 | break; | |
959 | } | |
960 | ||
961 | do_gettimeofday(&tv); | |
962 | gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + | |
963 | tv.tv_usec - ir->base_time.tv_usec; | |
964 | ||
965 | if (!pulse) { | |
966 | /* Bit 0 has 560 us, while bit 1 has 1120 us. | |
967 | Do something only if bit == 1 | |
968 | */ | |
969 | if (ngap && (gap > 560 + 280)) { | |
970 | unsigned int shift = ngap - 1; | |
971 | ||
972 | /* Address first, then command */ | |
973 | if (shift < 8) { | |
974 | shift += 8; | |
975 | ircode |= 1 << shift; | |
976 | } else if (shift < 16) { | |
977 | not_code |= 1 << shift; | |
978 | } else if (shift < 24) { | |
979 | shift -= 16; | |
980 | ircode |= 1 << shift; | |
981 | } else { | |
982 | shift -= 24; | |
983 | not_code |= 1 << shift; | |
984 | } | |
985 | } | |
986 | ngap++; | |
987 | } | |
988 | ||
989 | ||
990 | ir->base_time = tv; | |
991 | ||
992 | /* TIMEOUT - Long pulse */ | |
993 | if (gap >= 5000) | |
994 | break; | |
995 | oldpulse = pulse; | |
996 | } while (ngap < 32); | |
997 | ||
998 | if (ngap == 32) { | |
999 | /* FIXME: should check if not_code == ~ircode */ | |
1000 | ir->code = ir_extract_bits(ircode, ir->mask_keycode); | |
1001 | ||
1002 | dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n", | |
1003 | ir->code, ircode, not_code); | |
1004 | ||
8573b74a | 1005 | ir_input_keydown(ir->dev, &ir->ir, ir->code); |
622ecb30 MCC |
1006 | } else |
1007 | dprintk("Repeat last key\n"); | |
1008 | ||
1009 | /* Keep repeating the last key */ | |
1010 | mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150)); | |
1011 | ||
1012 | saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18); | |
1013 | } | |
1014 | ||
1015 | static int saa7134_nec_irq(struct saa7134_dev *dev) | |
1016 | { | |
1017 | struct card_ir *ir = dev->remote; | |
1018 | ||
1019 | saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18); | |
1020 | tasklet_schedule(&ir->tlet); | |
1021 | ||
1022 | return 1; | |
1023 | } |