Lines Matching +full:i2c +full:- +full:polling

1 // SPDX-License-Identifier: GPL-2.0-or-later
34 #define DEVNAME "bttv-input"
38 /* ---------------------------------------------------------------------- */
42 struct bttv_ir *ir = btv->remote; in ir_handle_key()
46 gpio = bttv_gpio_read(&btv->c); in ir_handle_key()
47 if (ir->polling) { in ir_handle_key()
48 if (ir->last_gpio == gpio) in ir_handle_key()
50 ir->last_gpio = gpio; in ir_handle_key()
54 data = ir_extract_bits(gpio, ir->mask_keycode); in ir_handle_key()
57 ir->polling ? "poll" : "irq", in ir_handle_key()
58 (gpio & ir->mask_keydown) ? " down" : "", in ir_handle_key()
59 (gpio & ir->mask_keyup) ? " up" : ""); in ir_handle_key()
61 if ((ir->mask_keydown && (gpio & ir->mask_keydown)) || in ir_handle_key()
62 (ir->mask_keyup && !(gpio & ir->mask_keyup))) { in ir_handle_key()
63 rc_keydown_notimeout(ir->dev, RC_PROTO_UNKNOWN, data, 0); in ir_handle_key()
65 /* HACK: Probably, ir->mask_keydown is missing in ir_handle_key()
67 if (btv->c.type == BTTV_BOARD_WINFAST2000) in ir_handle_key()
68 rc_keydown_notimeout(ir->dev, RC_PROTO_UNKNOWN, data, in ir_handle_key()
71 rc_keyup(ir->dev); in ir_handle_key()
77 struct bttv_ir *ir = btv->remote; in ir_enltv_handle_key()
81 gpio = bttv_gpio_read(&btv->c); in ir_enltv_handle_key()
84 data = ir_extract_bits(gpio, ir->mask_keycode); in ir_enltv_handle_key()
87 keyup = (gpio & ir->mask_keyup) ? 1UL << 31 : 0; in ir_enltv_handle_key()
89 if ((ir->last_gpio & 0x7f) != data) { in ir_enltv_handle_key()
92 (gpio & ir->mask_keyup) ? " up" : "up/down"); in ir_enltv_handle_key()
94 rc_keydown_notimeout(ir->dev, RC_PROTO_UNKNOWN, data, 0); in ir_enltv_handle_key()
96 rc_keyup(ir->dev); in ir_enltv_handle_key()
98 if ((ir->last_gpio & 1UL << 31) == keyup) in ir_enltv_handle_key()
103 (gpio & ir->mask_keyup) ? " up" : "down"); in ir_enltv_handle_key()
106 rc_keyup(ir->dev); in ir_enltv_handle_key()
108 rc_keydown_notimeout(ir->dev, RC_PROTO_UNKNOWN, data, in ir_enltv_handle_key()
112 ir->last_gpio = data | keyup; in ir_enltv_handle_key()
119 struct bttv_ir *ir = btv->remote; in bttv_input_irq()
121 if (ir->rc5_gpio) in bttv_input_irq()
123 else if (!ir->polling) in bttv_input_irq()
130 struct bttv *btv = ir->btv; in bttv_input_timer()
132 if (btv->c.type == BTTV_BOARD_ENLTV_FM_2) in bttv_input_timer()
136 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); in bttv_input_timer()
141 * on the rc-core way. As we need to be sure that both IRQ transitions are
193 gap = ktime_to_us(ktime_sub(tv, ir->base_time)); in bttv_rc5_timer_end()
199 ir->active = false; in bttv_rc5_timer_end()
207 if (ir->last_bit < 20) { in bttv_rc5_timer_end()
209 dprintk("short code: %x\n", ir->code); in bttv_rc5_timer_end()
213 ir->code = (ir->code << ir->shift_by) | 1; in bttv_rc5_timer_end()
214 rc5 = bttv_rc5_decode(ir->code); in bttv_rc5_timer_end()
231 rc_keydown(ir->dev, RC_PROTO_RC5, scancode, toggle); in bttv_rc5_timer_end()
237 struct bttv_ir *ir = btv->remote; in bttv_rc5_irq()
244 gpio = bttv_gpio_read(&btv->c); in bttv_rc5_irq()
250 gap = ktime_to_us(ktime_sub(tv, ir->base_time)); in bttv_rc5_irq()
264 if (ir->active) { in bttv_rc5_irq()
267 if (ir->last_bit < 28) { in bttv_rc5_irq()
268 ir->last_bit = (gap - ir_rc5_remote_gap / 2) / in bttv_rc5_irq()
270 ir->code |= 1 << ir->last_bit; in bttv_rc5_irq()
274 ir->active = true; in bttv_rc5_irq()
275 ir->code = 0; in bttv_rc5_irq()
276 ir->base_time = tv; in bttv_rc5_irq()
277 ir->last_bit = 0; in bttv_rc5_irq()
279 mod_timer(&ir->timer, current_jiffies + msecs_to_jiffies(30)); in bttv_rc5_irq()
283 bttv_gpio_write(&btv->c, gpio & ~(1 << 4)); in bttv_rc5_irq()
284 bttv_gpio_write(&btv->c, gpio | (1 << 4)); in bttv_rc5_irq()
288 /* ---------------------------------------------------------------------- */
292 if (ir->polling) { in bttv_ir_start()
293 timer_setup(&ir->timer, bttv_input_timer, 0); in bttv_ir_start()
294 ir->timer.expires = jiffies + msecs_to_jiffies(1000); in bttv_ir_start()
295 add_timer(&ir->timer); in bttv_ir_start()
296 } else if (ir->rc5_gpio) { in bttv_ir_start()
298 timer_setup(&ir->timer, bttv_rc5_timer_end, 0); in bttv_ir_start()
299 ir->shift_by = 1; in bttv_ir_start()
300 ir->rc5_remote_gap = ir_rc5_remote_gap; in bttv_ir_start()
306 if (btv->remote->polling) in bttv_ir_stop()
307 del_timer_sync(&btv->remote->timer); in bttv_ir_stop()
309 if (btv->remote->rc5_gpio) { in bttv_ir_stop()
312 del_timer_sync(&btv->remote->timer); in bttv_ir_stop()
314 gpio = bttv_gpio_read(&btv->c); in bttv_ir_stop()
315 bttv_gpio_write(&btv->c, gpio & ~(1 << 4)); in bttv_ir_stop()
320 * Get_key functions used by I2C remotes
330 rc = i2c_master_recv(ir->c, &b, 1); in get_key_pv951()
335 return -EIO; in get_key_pv951()
351 * 2) As the addr is not reported via I2C, nor can be changed, in get_key_pv951()
352 * the device is bound to the vendor-provided RC. in get_key_pv951()
361 /* Instantiate the I2C IR receiver device, if present */
371 if (0 != btv->i2c_rc) in init_bttv_i2c_ir()
375 memset(&btv->init_data, 0, sizeof(btv->init_data)); in init_bttv_i2c_ir()
378 switch (btv->c.type) { in init_bttv_i2c_ir()
380 btv->init_data.name = "PV951"; in init_bttv_i2c_ir()
381 btv->init_data.get_key = get_key_pv951; in init_bttv_i2c_ir()
382 btv->init_data.ir_codes = RC_MAP_PV951; in init_bttv_i2c_ir()
387 if (btv->init_data.name) { in init_bttv_i2c_ir()
388 info.platform_data = &btv->init_data; in init_bttv_i2c_ir()
389 i2c_dev = i2c_new_client_device(&btv->c.i2c_adap, &info); in init_bttv_i2c_ir()
392 * The external IR receiver is at i2c address 0x34 (0x35 for in init_bttv_i2c_ir()
399 i2c_dev = i2c_new_scanned_device(&btv->c.i2c_adap, &info, addr_list, NULL); in init_bttv_i2c_ir()
405 request_module("ir-kbd-i2c"); in init_bttv_i2c_ir()
414 int err = -ENOMEM; in bttv_input_init()
416 if (!btv->has_remote) in bttv_input_init()
417 return -ENODEV; in bttv_input_init()
425 switch (btv->c.type) { in bttv_input_init()
430 ir->mask_keycode = 0xf88000; in bttv_input_init()
431 ir->mask_keydown = 0x010000; in bttv_input_init()
432 ir->polling = 50; // ms in bttv_input_init()
438 ir->mask_keycode = 0x0f00c0; in bttv_input_init()
439 ir->mask_keydown = 0x000020; in bttv_input_init()
440 ir->polling = 50; // ms in bttv_input_init()
445 ir->mask_keycode = 0x003e00; in bttv_input_init()
446 ir->mask_keyup = 0x010000; in bttv_input_init()
447 ir->polling = 50; // ms in bttv_input_init()
453 ir->mask_keycode = 0x001f00; in bttv_input_init()
454 ir->mask_keyup = 0x008000; in bttv_input_init()
455 ir->polling = 50; // ms in bttv_input_init()
460 ir->mask_keycode = 0x1f8; in bttv_input_init()
465 ir->mask_keycode = 0x0008e000; in bttv_input_init()
466 ir->mask_keydown = 0x00200000; in bttv_input_init()
470 ir->mask_keycode = 0x001f00; in bttv_input_init()
471 ir->mask_keyup = 0x008000; in bttv_input_init()
472 ir->polling = 50; // ms in bttv_input_init()
479 ir->mask_keycode = 0x001F00; in bttv_input_init()
480 ir->mask_keyup = 0x006000; in bttv_input_init()
481 ir->polling = 50; // ms in bttv_input_init()
485 ir->rc5_gpio = true; in bttv_input_init()
489 ir->mask_keycode = 0x001F00; in bttv_input_init()
490 ir->mask_keyup = 0x004000; in bttv_input_init()
491 ir->polling = 50; /* ms */ in bttv_input_init()
495 ir->mask_keycode = 0x001f00; in bttv_input_init()
496 ir->mask_keyup = 0x006000; in bttv_input_init()
497 ir->polling = 50; /* ms */ in bttv_input_init()
501 ir->mask_keycode = 0x00fd00; in bttv_input_init()
502 ir->mask_keyup = 0x000080; in bttv_input_init()
503 ir->polling = 1; /* ms */ in bttv_input_init()
504 ir->last_gpio = ir_extract_bits(bttv_gpio_read(&btv->c), in bttv_input_init()
505 ir->mask_keycode); in bttv_input_init()
510 dprintk("Ooops: IR config error [card=%d]\n", btv->c.type); in bttv_input_init()
511 err = -ENODEV; in bttv_input_init()
515 if (ir->rc5_gpio) { in bttv_input_init()
518 bttv_gpio_inout(&btv->c, (1 << 4), 1 << 4); in bttv_input_init()
519 gpio = bttv_gpio_read(&btv->c); in bttv_input_init()
520 bttv_gpio_write(&btv->c, gpio & ~(1 << 4)); in bttv_input_init()
521 bttv_gpio_write(&btv->c, gpio | (1 << 4)); in bttv_input_init()
523 /* init hardware-specific stuff */ in bttv_input_init()
524 bttv_gpio_inout(&btv->c, ir->mask_keycode | ir->mask_keydown, 0); in bttv_input_init()
528 ir->dev = rc; in bttv_input_init()
529 ir->btv = btv; in bttv_input_init()
531 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)", in bttv_input_init()
532 btv->c.type); in bttv_input_init()
533 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", in bttv_input_init()
534 pci_name(btv->c.pci)); in bttv_input_init()
536 rc->device_name = ir->name; in bttv_input_init()
537 rc->input_phys = ir->phys; in bttv_input_init()
538 rc->input_id.bustype = BUS_PCI; in bttv_input_init()
539 rc->input_id.version = 1; in bttv_input_init()
540 if (btv->c.pci->subsystem_vendor) { in bttv_input_init()
541 rc->input_id.vendor = btv->c.pci->subsystem_vendor; in bttv_input_init()
542 rc->input_id.product = btv->c.pci->subsystem_device; in bttv_input_init()
544 rc->input_id.vendor = btv->c.pci->vendor; in bttv_input_init()
545 rc->input_id.product = btv->c.pci->device; in bttv_input_init()
547 rc->dev.parent = &btv->c.pci->dev; in bttv_input_init()
548 rc->map_name = ir_codes; in bttv_input_init()
549 rc->driver_name = MODULE_NAME; in bttv_input_init()
551 btv->remote = ir; in bttv_input_init()
563 btv->remote = NULL; in bttv_input_init()
572 if (btv->remote == NULL) in bttv_input_fini()
576 rc_unregister_device(btv->remote->dev); in bttv_input_fini()
577 kfree(btv->remote); in bttv_input_fini()
578 btv->remote = NULL; in bttv_input_fini()