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