aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/bt8xx/bttv-input.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/bt8xx/bttv-input.c')
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c238
1 files changed, 166 insertions, 72 deletions
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index 6bf05a7dc5f9..97793b960600 100644
--- a/drivers/media/video/bt8xx/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -31,15 +31,9 @@
31 31
32static int ir_debug; 32static int ir_debug;
33module_param(ir_debug, int, 0644); 33module_param(ir_debug, int, 0644);
34static int repeat_delay = 500;
35module_param(repeat_delay, int, 0644);
36static int repeat_period = 33;
37module_param(repeat_period, int, 0644);
38 34
39static int ir_rc5_remote_gap = 885; 35static int ir_rc5_remote_gap = 885;
40module_param(ir_rc5_remote_gap, int, 0644); 36module_param(ir_rc5_remote_gap, int, 0644);
41static int ir_rc5_key_timeout = 200;
42module_param(ir_rc5_key_timeout, int, 0644);
43 37
44#undef dprintk 38#undef dprintk
45#define dprintk(arg...) do { \ 39#define dprintk(arg...) do { \
@@ -55,7 +49,7 @@ module_param(ir_rc5_key_timeout, int, 0644);
55 49
56static void ir_handle_key(struct bttv *btv) 50static void ir_handle_key(struct bttv *btv)
57{ 51{
58 struct card_ir *ir = btv->remote; 52 struct bttv_ir *ir = btv->remote;
59 u32 gpio,data; 53 u32 gpio,data;
60 54
61 /* read gpio value */ 55 /* read gpio value */
@@ -74,23 +68,22 @@ static void ir_handle_key(struct bttv *btv)
74 (gpio & ir->mask_keydown) ? " down" : "", 68 (gpio & ir->mask_keydown) ? " down" : "",
75 (gpio & ir->mask_keyup) ? " up" : ""); 69 (gpio & ir->mask_keyup) ? " up" : "");
76 70
77 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || 71 if ((ir->mask_keydown && (gpio & ir->mask_keydown)) ||
78 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { 72 (ir->mask_keyup && !(gpio & ir->mask_keyup))) {
79 ir_input_keydown(ir->dev, &ir->ir, data); 73 rc_keydown_notimeout(ir->dev, data, 0);
80 } else { 74 } else {
81 /* HACK: Probably, ir->mask_keydown is missing 75 /* HACK: Probably, ir->mask_keydown is missing
82 for this board */ 76 for this board */
83 if (btv->c.type == BTTV_BOARD_WINFAST2000) 77 if (btv->c.type == BTTV_BOARD_WINFAST2000)
84 ir_input_keydown(ir->dev, &ir->ir, data); 78 rc_keydown_notimeout(ir->dev, data, 0);
85 79
86 ir_input_nokey(ir->dev,&ir->ir); 80 rc_keyup(ir->dev);
87 } 81 }
88
89} 82}
90 83
91static void ir_enltv_handle_key(struct bttv *btv) 84static void ir_enltv_handle_key(struct bttv *btv)
92{ 85{
93 struct card_ir *ir = btv->remote; 86 struct bttv_ir *ir = btv->remote;
94 u32 gpio, data, keyup; 87 u32 gpio, data, keyup;
95 88
96 /* read gpio value */ 89 /* read gpio value */
@@ -107,9 +100,9 @@ static void ir_enltv_handle_key(struct bttv *btv)
107 gpio, data, 100 gpio, data,
108 (gpio & ir->mask_keyup) ? " up" : "up/down"); 101 (gpio & ir->mask_keyup) ? " up" : "up/down");
109 102
110 ir_input_keydown(ir->dev, &ir->ir, data); 103 rc_keydown_notimeout(ir->dev, data, 0);
111 if (keyup) 104 if (keyup)
112 ir_input_nokey(ir->dev, &ir->ir); 105 rc_keyup(ir->dev);
113 } else { 106 } else {
114 if ((ir->last_gpio & 1 << 31) == keyup) 107 if ((ir->last_gpio & 1 << 31) == keyup)
115 return; 108 return;
@@ -119,26 +112,30 @@ static void ir_enltv_handle_key(struct bttv *btv)
119 (gpio & ir->mask_keyup) ? " up" : "down"); 112 (gpio & ir->mask_keyup) ? " up" : "down");
120 113
121 if (keyup) 114 if (keyup)
122 ir_input_nokey(ir->dev, &ir->ir); 115 rc_keyup(ir->dev);
123 else 116 else
124 ir_input_keydown(ir->dev, &ir->ir, data); 117 rc_keydown_notimeout(ir->dev, data, 0);
125 } 118 }
126 119
127 ir->last_gpio = data | keyup; 120 ir->last_gpio = data | keyup;
128} 121}
129 122
123static int bttv_rc5_irq(struct bttv *btv);
124
130void bttv_input_irq(struct bttv *btv) 125void bttv_input_irq(struct bttv *btv)
131{ 126{
132 struct card_ir *ir = btv->remote; 127 struct bttv_ir *ir = btv->remote;
133 128
134 if (!ir->polling) 129 if (ir->rc5_gpio)
130 bttv_rc5_irq(btv);
131 else if (!ir->polling)
135 ir_handle_key(btv); 132 ir_handle_key(btv);
136} 133}
137 134
138static void bttv_input_timer(unsigned long data) 135static void bttv_input_timer(unsigned long data)
139{ 136{
140 struct bttv *btv = (struct bttv*)data; 137 struct bttv *btv = (struct bttv*)data;
141 struct card_ir *ir = btv->remote; 138 struct bttv_ir *ir = btv->remote;
142 139
143 if (btv->c.type == BTTV_BOARD_ENLTV_FM_2) 140 if (btv->c.type == BTTV_BOARD_ENLTV_FM_2)
144 ir_enltv_handle_key(btv); 141 ir_enltv_handle_key(btv);
@@ -147,11 +144,109 @@ static void bttv_input_timer(unsigned long data)
147 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); 144 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
148} 145}
149 146
150/* ---------------------------------------------------------------*/ 147/*
148 * FIXME: Nebula digi uses the legacy way to decode RC5, instead of relying
149 * on the rc-core way. As we need to be sure that both IRQ transitions are
150 * properly triggered, Better to touch it only with this hardware for
151 * testing.
152 */
153
154#define RC5_START(x) (((x) >> 12) & 3)
155#define RC5_TOGGLE(x) (((x) >> 11) & 1)
156#define RC5_ADDR(x) (((x) >> 6) & 31)
157#define RC5_INSTR(x) ((x) & 63)
158
159/* decode raw bit pattern to RC5 code */
160static u32 bttv_rc5_decode(unsigned int code)
161{
162 unsigned int org_code = code;
163 unsigned int pair;
164 unsigned int rc5 = 0;
165 int i;
166
167 for (i = 0; i < 14; ++i) {
168 pair = code & 0x3;
169 code >>= 2;
170
171 rc5 <<= 1;
172 switch (pair) {
173 case 0:
174 case 2:
175 break;
176 case 1:
177 rc5 |= 1;
178 break;
179 case 3:
180 dprintk(KERN_INFO DEVNAME ":rc5_decode(%x) bad code\n",
181 org_code);
182 return 0;
183 }
184 }
185 dprintk(KERN_INFO DEVNAME ":"
186 "code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
187 "instr=%x\n", rc5, org_code, RC5_START(rc5),
188 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
189 return rc5;
190}
191
192static void bttv_rc5_timer_end(unsigned long data)
193{
194 struct bttv_ir *ir = (struct bttv_ir *)data;
195 struct timeval tv;
196 unsigned long current_jiffies;
197 u32 gap;
198 u32 rc5 = 0;
199
200 /* get time */
201 current_jiffies = jiffies;
202 do_gettimeofday(&tv);
203
204 /* avoid overflow with gap >1s */
205 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
206 gap = 200000;
207 } else {
208 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
209 tv.tv_usec - ir->base_time.tv_usec;
210 }
211
212 /* signal we're ready to start a new code */
213 ir->active = false;
214
215 /* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */
216 if (gap < 28000) {
217 dprintk(KERN_INFO DEVNAME ": spurious timer_end\n");
218 return;
219 }
220
221 if (ir->last_bit < 20) {
222 /* ignore spurious codes (caused by light/other remotes) */
223 dprintk(KERN_INFO DEVNAME ": short code: %x\n", ir->code);
224 } else {
225 ir->code = (ir->code << ir->shift_by) | 1;
226 rc5 = bttv_rc5_decode(ir->code);
227
228 /* two start bits? */
229 if (RC5_START(rc5) != ir->start) {
230 printk(KERN_INFO DEVNAME ":"
231 " rc5 start bits invalid: %u\n", RC5_START(rc5));
232
233 /* right address? */
234 } else if (RC5_ADDR(rc5) == ir->addr) {
235 u32 toggle = RC5_TOGGLE(rc5);
236 u32 instr = RC5_INSTR(rc5);
237
238 /* Good code */
239 rc_keydown(ir->dev, instr, toggle);
240 dprintk(KERN_INFO DEVNAME ":"
241 " instruction %x, toggle %x\n",
242 instr, toggle);
243 }
244 }
245}
151 246
152static int bttv_rc5_irq(struct bttv *btv) 247static int bttv_rc5_irq(struct bttv *btv)
153{ 248{
154 struct card_ir *ir = btv->remote; 249 struct bttv_ir *ir = btv->remote;
155 struct timeval tv; 250 struct timeval tv;
156 u32 gpio; 251 u32 gpio;
157 u32 gap; 252 u32 gap;
@@ -160,10 +255,6 @@ static int bttv_rc5_irq(struct bttv *btv)
160 /* read gpio port */ 255 /* read gpio port */
161 gpio = bttv_gpio_read(&btv->c); 256 gpio = bttv_gpio_read(&btv->c);
162 257
163 /* remote IRQ? */
164 if (!(gpio & 0x20))
165 return 0;
166
167 /* get time of bit */ 258 /* get time of bit */
168 current_jiffies = jiffies; 259 current_jiffies = jiffies;
169 do_gettimeofday(&tv); 260 do_gettimeofday(&tv);
@@ -176,6 +267,13 @@ static int bttv_rc5_irq(struct bttv *btv)
176 tv.tv_usec - ir->base_time.tv_usec; 267 tv.tv_usec - ir->base_time.tv_usec;
177 } 268 }
178 269
270 dprintk(KERN_INFO DEVNAME ": RC5 IRQ: gap %d us for %s\n",
271 gap, (gpio & 0x20) ? "mark" : "space");
272
273 /* remote IRQ? */
274 if (!(gpio & 0x20))
275 return 0;
276
179 /* active code => add bit */ 277 /* active code => add bit */
180 if (ir->active) { 278 if (ir->active) {
181 /* only if in the code (otherwise spurious IRQ or timer 279 /* only if in the code (otherwise spurious IRQ or timer
@@ -187,13 +285,12 @@ static int bttv_rc5_irq(struct bttv *btv)
187 } 285 }
188 /* starting new code */ 286 /* starting new code */
189 } else { 287 } else {
190 ir->active = 1; 288 ir->active = true;
191 ir->code = 0; 289 ir->code = 0;
192 ir->base_time = tv; 290 ir->base_time = tv;
193 ir->last_bit = 0; 291 ir->last_bit = 0;
194 292
195 mod_timer(&ir->timer_end, 293 mod_timer(&ir->timer, current_jiffies + msecs_to_jiffies(30));
196 current_jiffies + msecs_to_jiffies(30));
197 } 294 }
198 295
199 /* toggle GPIO pin 4 to reset the irq */ 296 /* toggle GPIO pin 4 to reset the irq */
@@ -204,7 +301,7 @@ static int bttv_rc5_irq(struct bttv *btv)
204 301
205/* ---------------------------------------------------------------------- */ 302/* ---------------------------------------------------------------------- */
206 303
207static void bttv_ir_start(struct bttv *btv, struct card_ir *ir) 304static void bttv_ir_start(struct bttv *btv, struct bttv_ir *ir)
208{ 305{
209 if (ir->polling) { 306 if (ir->polling) {
210 setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv); 307 setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv);
@@ -212,17 +309,10 @@ static void bttv_ir_start(struct bttv *btv, struct card_ir *ir)
212 add_timer(&ir->timer); 309 add_timer(&ir->timer);
213 } else if (ir->rc5_gpio) { 310 } else if (ir->rc5_gpio) {
214 /* set timer_end for code completion */ 311 /* set timer_end for code completion */
215 init_timer(&ir->timer_end); 312 setup_timer(&ir->timer, bttv_rc5_timer_end, (unsigned long)ir);
216 ir->timer_end.function = ir_rc5_timer_end;
217 ir->timer_end.data = (unsigned long)ir;
218
219 init_timer(&ir->timer_keyup);
220 ir->timer_keyup.function = ir_rc5_timer_keyup;
221 ir->timer_keyup.data = (unsigned long)ir;
222 ir->shift_by = 1; 313 ir->shift_by = 1;
223 ir->start = 3; 314 ir->start = 3;
224 ir->addr = 0x0; 315 ir->addr = 0x0;
225 ir->rc5_key_timeout = ir_rc5_key_timeout;
226 ir->rc5_remote_gap = ir_rc5_remote_gap; 316 ir->rc5_remote_gap = ir_rc5_remote_gap;
227 } 317 }
228} 318}
@@ -237,7 +327,7 @@ static void bttv_ir_stop(struct bttv *btv)
237 if (btv->remote->rc5_gpio) { 327 if (btv->remote->rc5_gpio) {
238 u32 gpio; 328 u32 gpio;
239 329
240 del_timer_sync(&btv->remote->timer_end); 330 del_timer_sync(&btv->remote->timer);
241 flush_scheduled_work(); 331 flush_scheduled_work();
242 332
243 gpio = bttv_gpio_read(&btv->c); 333 gpio = bttv_gpio_read(&btv->c);
@@ -264,6 +354,18 @@ static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
264 return 0; 354 return 0;
265 dprintk(KERN_INFO DEVNAME ": key %02x\n", b); 355 dprintk(KERN_INFO DEVNAME ": key %02x\n", b);
266 356
357 /*
358 * NOTE:
359 * lirc_i2c maps the pv951 code as:
360 * addr = 0x61D6
361 * cmd = bit_reverse (b)
362 * So, it seems that this device uses NEC extended
363 * I decided to not fix the table, due to two reasons:
364 * 1) Without the actual device, this is only a guess;
365 * 2) As the addr is not reported via I2C, nor can be changed,
366 * the device is bound to the vendor-provided RC.
367 */
368
267 *ir_key = b; 369 *ir_key = b;
268 *ir_raw = b; 370 *ir_raw = b;
269 return 1; 371 return 1;
@@ -290,16 +392,15 @@ void __devinit init_bttv_i2c_ir(struct bttv *btv)
290 btv->init_data.name = "PV951"; 392 btv->init_data.name = "PV951";
291 btv->init_data.get_key = get_key_pv951; 393 btv->init_data.get_key = get_key_pv951;
292 btv->init_data.ir_codes = RC_MAP_PV951; 394 btv->init_data.ir_codes = RC_MAP_PV951;
293 btv->init_data.type = IR_TYPE_OTHER;
294 info.addr = 0x4b; 395 info.addr = 0x4b;
295 break; 396 break;
296 default: 397 default:
297 /* 398 /*
298 * The external IR receiver is at i2c address 0x34 (0x35 for 399 * The external IR receiver is at i2c address 0x34 (0x35 for
299 * reads). Future Hauppauge cards will have an internal 400 * reads). Future Hauppauge cards will have an internal
300 * receiver at 0x30 (0x31 for reads). In theory, both can be 401 * receiver at 0x30 (0x31 for reads). In theory, both can be
301 * fitted, and Hauppauge suggest an external overrides an 402 * fitted, and Hauppauge suggest an external overrides an
302 * internal. 403 * internal.
303 * That's why we probe 0x1a (~0x34) first. CB 404 * That's why we probe 0x1a (~0x34) first. CB
304 */ 405 */
305 406
@@ -324,18 +425,17 @@ int __devexit fini_bttv_i2c(struct bttv *btv)
324 425
325int bttv_input_init(struct bttv *btv) 426int bttv_input_init(struct bttv *btv)
326{ 427{
327 struct card_ir *ir; 428 struct bttv_ir *ir;
328 char *ir_codes = NULL; 429 char *ir_codes = NULL;
329 struct input_dev *input_dev; 430 struct rc_dev *rc;
330 u64 ir_type = IR_TYPE_OTHER;
331 int err = -ENOMEM; 431 int err = -ENOMEM;
332 432
333 if (!btv->has_remote) 433 if (!btv->has_remote)
334 return -ENODEV; 434 return -ENODEV;
335 435
336 ir = kzalloc(sizeof(*ir),GFP_KERNEL); 436 ir = kzalloc(sizeof(*ir),GFP_KERNEL);
337 input_dev = input_allocate_device(); 437 rc = rc_allocate_device();
338 if (!ir || !input_dev) 438 if (!ir || !rc)
339 goto err_out_free; 439 goto err_out_free;
340 440
341 /* detect & configure */ 441 /* detect & configure */
@@ -398,8 +498,7 @@ int bttv_input_init(struct bttv *btv)
398 break; 498 break;
399 case BTTV_BOARD_NEBULA_DIGITV: 499 case BTTV_BOARD_NEBULA_DIGITV:
400 ir_codes = RC_MAP_NEBULA; 500 ir_codes = RC_MAP_NEBULA;
401 btv->custom_irq = bttv_rc5_irq; 501 ir->rc5_gpio = true;
402 ir->rc5_gpio = 1;
403 break; 502 break;
404 case BTTV_BOARD_MACHTV_MAGICTV: 503 case BTTV_BOARD_MACHTV_MAGICTV:
405 ir_codes = RC_MAP_APAC_VIEWCOMP; 504 ir_codes = RC_MAP_APAC_VIEWCOMP;
@@ -441,48 +540,43 @@ int bttv_input_init(struct bttv *btv)
441 } 540 }
442 541
443 /* init input device */ 542 /* init input device */
444 ir->dev = input_dev; 543 ir->dev = rc;
445 544
446 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)", 545 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)",
447 btv->c.type); 546 btv->c.type);
448 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", 547 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
449 pci_name(btv->c.pci)); 548 pci_name(btv->c.pci));
450 549
451 err = ir_input_init(input_dev, &ir->ir, ir_type); 550 rc->input_name = ir->name;
452 if (err < 0) 551 rc->input_phys = ir->phys;
453 goto err_out_free; 552 rc->input_id.bustype = BUS_PCI;
454 553 rc->input_id.version = 1;
455 input_dev->name = ir->name;
456 input_dev->phys = ir->phys;
457 input_dev->id.bustype = BUS_PCI;
458 input_dev->id.version = 1;
459 if (btv->c.pci->subsystem_vendor) { 554 if (btv->c.pci->subsystem_vendor) {
460 input_dev->id.vendor = btv->c.pci->subsystem_vendor; 555 rc->input_id.vendor = btv->c.pci->subsystem_vendor;
461 input_dev->id.product = btv->c.pci->subsystem_device; 556 rc->input_id.product = btv->c.pci->subsystem_device;
462 } else { 557 } else {
463 input_dev->id.vendor = btv->c.pci->vendor; 558 rc->input_id.vendor = btv->c.pci->vendor;
464 input_dev->id.product = btv->c.pci->device; 559 rc->input_id.product = btv->c.pci->device;
465 } 560 }
466 input_dev->dev.parent = &btv->c.pci->dev; 561 rc->dev.parent = &btv->c.pci->dev;
562 rc->map_name = ir_codes;
563 rc->driver_name = MODULE_NAME;
467 564
468 btv->remote = ir; 565 btv->remote = ir;
469 bttv_ir_start(btv, ir); 566 bttv_ir_start(btv, ir);
470 567
471 /* all done */ 568 /* all done */
472 err = ir_input_register(btv->remote->dev, ir_codes, NULL, MODULE_NAME); 569 err = rc_register_device(rc);
473 if (err) 570 if (err)
474 goto err_out_stop; 571 goto err_out_stop;
475 572
476 /* the remote isn't as bouncy as a keyboard */
477 ir->dev->rep[REP_DELAY] = repeat_delay;
478 ir->dev->rep[REP_PERIOD] = repeat_period;
479
480 return 0; 573 return 0;
481 574
482 err_out_stop: 575 err_out_stop:
483 bttv_ir_stop(btv); 576 bttv_ir_stop(btv);
484 btv->remote = NULL; 577 btv->remote = NULL;
485 err_out_free: 578 err_out_free:
579 rc_free_device(rc);
486 kfree(ir); 580 kfree(ir);
487 return err; 581 return err;
488} 582}
@@ -493,7 +587,7 @@ void bttv_input_fini(struct bttv *btv)
493 return; 587 return;
494 588
495 bttv_ir_stop(btv); 589 bttv_ir_stop(btv);
496 ir_input_unregister(btv->remote->dev); 590 rc_unregister_device(btv->remote->dev);
497 kfree(btv->remote); 591 kfree(btv->remote);
498 btv->remote = NULL; 592 btv->remote = NULL;
499} 593}