21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #include <linux/module.h>
27 #include <linux/input.h>
28 #include <linux/slab.h>
37 static int ir_rc5_remote_gap = 885;
41 #define dprintk(fmt, ...) \
44 pr_info(fmt, ##__VA_ARGS__); \
47 #define DEVNAME "bttv-input"
49 #define MODULE_NAME "bttv"
53 static void ir_handle_key(
struct bttv *btv)
55 struct bttv_ir *
ir = btv->remote;
61 if (ir->last_gpio == gpio)
67 data = ir_extract_bits(gpio, ir->mask_keycode);
68 dprintk(
"irq gpio=0x%x code=%d | %s%s%s\n",
70 ir->polling ?
"poll" :
"irq",
71 (gpio & ir->mask_keydown) ?
" down" :
"",
72 (gpio & ir->mask_keyup) ?
" up" :
"");
74 if ((ir->mask_keydown && (gpio & ir->mask_keydown)) ||
75 (ir->mask_keyup && !(gpio & ir->mask_keyup))) {
87 static void ir_enltv_handle_key(
struct bttv *btv)
89 struct bttv_ir *
ir = btv->remote;
96 data = ir_extract_bits(gpio, ir->mask_keycode);
99 keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0;
101 if ((ir->last_gpio & 0x7f) !=
data) {
102 dprintk(
"gpio=0x%x code=%d | %s\n",
104 (gpio & ir->mask_keyup) ?
" up" :
"up/down");
110 if ((ir->last_gpio & 1 << 31) == keyup)
113 dprintk(
"(cnt) gpio=0x%x code=%d | %s\n",
115 (gpio & ir->mask_keyup) ?
" up" :
"down");
123 ir->last_gpio = data | keyup;
126 static int bttv_rc5_irq(
struct bttv *btv);
130 struct bttv_ir *ir = btv->remote;
134 else if (!ir->polling)
138 static void bttv_input_timer(
unsigned long data)
140 struct bttv *btv = (
struct bttv*)data;
141 struct bttv_ir *ir = btv->remote;
144 ir_enltv_handle_key(btv);
157 #define RC5_START(x) (((x) >> 12) & 3)
158 #define RC5_TOGGLE(x) (((x) >> 11) & 1)
159 #define RC5_ADDR(x) (((x) >> 6) & 31)
160 #define RC5_INSTR(x) ((x) & 63)
163 static u32 bttv_rc5_decode(
unsigned int code)
165 unsigned int org_code =
code;
167 unsigned int rc5 = 0;
170 for (i = 0; i < 14; ++
i) {
183 dprintk(
"rc5_decode(%x) bad code\n",
188 dprintk(
"code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
189 "instr=%x\n", rc5, org_code,
RC5_START(rc5),
194 static void bttv_rc5_timer_end(
unsigned long data)
196 struct bttv_ir *ir = (
struct bttv_ir *)data;
205 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
208 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
209 tv.tv_usec - ir->base_time.tv_usec;
217 dprintk(
"spurious timer_end\n");
221 if (ir->last_bit < 20) {
223 dprintk(
"short code: %x\n", ir->code);
225 ir->code = (ir->code << ir->shift_by) | 1;
226 rc5 = bttv_rc5_decode(ir->code);
231 " rc5 start bits invalid: %u\n",
RC5_START(rc5));
234 }
else if (
RC5_ADDR(rc5) == ir->addr) {
240 dprintk(
"instruction %x, toggle %x\n",
246 static int bttv_rc5_irq(
struct bttv *btv)
248 struct bttv_ir *ir = btv->remote;
252 unsigned long current_jiffies;
262 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
265 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
266 tv.tv_usec - ir->base_time.tv_usec;
269 dprintk(
"RC5 IRQ: gap %d us for %s\n",
270 gap, (gpio & 0x20) ?
"mark" :
"space");
280 if (ir->last_bit < 28) {
281 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
283 ir->code |= 1 << ir->last_bit;
303 static void bttv_ir_start(
struct bttv *btv,
struct bttv_ir *ir)
306 setup_timer(&ir->timer, bttv_input_timer, (
unsigned long)btv);
309 }
else if (ir->rc5_gpio) {
311 setup_timer(&ir->timer, bttv_rc5_timer_end, (
unsigned long)ir);
315 ir->rc5_remote_gap = ir_rc5_remote_gap;
319 static void bttv_ir_stop(
struct bttv *btv)
321 if (btv->remote->polling)
324 if (btv->remote->rc5_gpio) {
338 static int get_key_pv951(
struct IR_i2c *ir,
u32 *ir_key,
u32 *ir_raw)
373 const unsigned short addr_list[] = {
374 0x1a, 0x18, 0x64, 0x30, 0x71,
379 if (0 != btv->i2c_rc)
383 memset(&btv->init_data, 0,
sizeof(btv->init_data));
386 switch (btv->c.type) {
388 btv->init_data.name =
"PV951";
389 btv->init_data.get_key = get_key_pv951;
407 if (btv->init_data.name)
416 if (0 != btv->i2c_rc)
425 char *ir_codes =
NULL;
429 if (!btv->has_remote)
438 switch (btv->c.type) {
443 ir->mask_keycode = 0xf88000;
444 ir->mask_keydown = 0x010000;
451 ir->mask_keycode = 0x0f00c0;
452 ir->mask_keydown = 0x000020;
458 ir->mask_keycode = 0x003e00;
459 ir->mask_keyup = 0x010000;
466 ir->mask_keycode = 0x001f00;
467 ir->mask_keyup = 0x008000;
473 ir->mask_keycode = 0x1f8;
478 ir->mask_keycode = 0x0008e000;
479 ir->mask_keydown = 0x00200000;
483 ir->mask_keycode = 0x001f00;
484 ir->mask_keyup = 0x008000;
491 ir->mask_keycode = 0x001F00;
492 ir->mask_keyup = 0x006000;
501 ir->mask_keycode = 0x001F00;
502 ir->mask_keyup = 0x004000;
507 ir->mask_keycode = 0x001f00;
508 ir->mask_keyup = 0x006000;
513 ir->mask_keycode = 0x00fd00;
514 ir->mask_keyup = 0x000080;
520 if (
NULL == ir_codes) {
521 dprintk(
"Ooops: IR config error [card=%d]\n", btv->c.type);
541 snprintf(ir->name,
sizeof(ir->name),
"bttv IR (card=%d)",
543 snprintf(ir->phys,
sizeof(ir->phys),
"pci-%s/ir0",
544 pci_name(btv->c.pci));
550 if (btv->c.pci->subsystem_vendor) {
551 rc->
input_id.vendor = btv->c.pci->subsystem_vendor;
552 rc->
input_id.product = btv->c.pci->subsystem_device;
554 rc->
input_id.vendor = btv->c.pci->vendor;
555 rc->
input_id.product = btv->c.pci->device;
557 rc->
dev.parent = &btv->c.pci->dev;
562 bttv_ir_start(btv, ir);
582 if (btv->remote ==
NULL)