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