Skip to content

Commit

Permalink
[media] rc-core: improve ir-kbd-i2c get_key functions
Browse files Browse the repository at this point in the history
The arguments used for ir-kbd-i2c's get_key() functions are not
really suited for rc-core and the ir_raw/ir_key distinction is
just confusing.

Convert all of them to return a protocol/scancode/toggle triple instead.

Signed-off-by: David Härdeman <david@hardeman.nu>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
  • Loading branch information
David Härdeman authored and Mauro Carvalho Chehab committed Jul 23, 2014
1 parent 2886f01 commit 4dd9bb9
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 100 deletions.
90 changes: 45 additions & 45 deletions drivers/media/i2c/ir-kbd-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ module_param(debug, int, 0644); /* debug level (0,1,2) */

/* ----------------------------------------------------------------------- */

static int get_key_haup_common(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
int size, int offset)
static int get_key_haup_common(struct IR_i2c *ir, enum rc_type *protocol,
u32 *scancode, u8 *ptoggle, int size, int offset)
{
unsigned char buf[6];
int start, range, toggle, dev, code, ircode;
Expand All @@ -86,19 +86,10 @@ static int get_key_haup_common(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
if (!start)
/* no key pressed */
return 0;
/*
* Hauppauge remotes (black/silver) always use
* specific device ids. If we do not filter the
* device ids then messages destined for devices
* such as TVs (id=0) will get through causing
* mis-fired events.
*
* We also filter out invalid key presses which
* produce annoying debug log entries.
*/
ircode= (start << 12) | (toggle << 11) | (dev << 6) | code;
if ((ircode & 0x1fff)==0x1fff)
/* invalid key press */

/* filter out invalid key presses */
ircode = (start << 12) | (toggle << 11) | (dev << 6) | code;
if ((ircode & 0x1fff) == 0x1fff)
return 0;

if (!range)
Expand All @@ -107,18 +98,20 @@ static int get_key_haup_common(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
dprintk(1,"ir hauppauge (rc5): s%d r%d t%d dev=%d code=%d\n",
start, range, toggle, dev, code);

/* return key */
*ir_key = (dev << 8) | code;
*ir_raw = ircode;
*protocol = RC_TYPE_RC5;
*scancode = RC_SCANCODE_RC5(dev, code);
*ptoggle = toggle;
return 1;
}

static int get_key_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
static int get_key_haup(struct IR_i2c *ir, enum rc_type *protocol,
u32 *scancode, u8 *toggle)
{
return get_key_haup_common (ir, ir_key, ir_raw, 3, 0);
return get_key_haup_common (ir, protocol, scancode, toggle, 3, 0);
}

static int get_key_haup_xvr(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
static int get_key_haup_xvr(struct IR_i2c *ir, enum rc_type *protocol,
u32 *scancode, u8 *toggle)
{
int ret;
unsigned char buf[1] = { 0 };
Expand All @@ -133,10 +126,11 @@ static int get_key_haup_xvr(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
if (ret != 1)
return (ret < 0) ? ret : -EINVAL;

return get_key_haup_common (ir, ir_key, ir_raw, 6, 3);
return get_key_haup_common(ir, protocol, scancode, toggle, 6, 3);
}

static int get_key_pixelview(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
static int get_key_pixelview(struct IR_i2c *ir, enum rc_type *protocol,
u32 *scancode, u8 *toggle)
{
unsigned char b;

Expand All @@ -145,12 +139,15 @@ static int get_key_pixelview(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
dprintk(1,"read error\n");
return -EIO;
}
*ir_key = b;
*ir_raw = b;

*protocol = RC_TYPE_OTHER;
*scancode = b;
*toggle = 0;
return 1;
}

static int get_key_fusionhdtv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
static int get_key_fusionhdtv(struct IR_i2c *ir, enum rc_type *protocol,
u32 *scancode, u8 *toggle)
{
unsigned char buf[4];

Expand All @@ -168,13 +165,14 @@ static int get_key_fusionhdtv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
if(buf[0] != 0x1 || buf[1] != 0xfe)
return 0;

*ir_key = buf[2];
*ir_raw = (buf[2] << 8) | buf[3];

*protocol = RC_TYPE_UNKNOWN;
*scancode = buf[2];
*toggle = 0;
return 1;
}

static int get_key_knc1(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
static int get_key_knc1(struct IR_i2c *ir, enum rc_type *protocol,
u32 *scancode, u8 *toggle)
{
unsigned char b;

Expand All @@ -197,13 +195,14 @@ static int get_key_knc1(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
/* keep old data */
return 1;

*ir_key = b;
*ir_raw = b;
*protocol = RC_TYPE_UNKNOWN;
*scancode = b;
*toggle = 0;
return 1;
}

static int get_key_avermedia_cardbus(struct IR_i2c *ir,
u32 *ir_key, u32 *ir_raw)
static int get_key_avermedia_cardbus(struct IR_i2c *ir, enum rc_type *protocol,
u32 *scancode, u8 *toggle)
{
unsigned char subaddr, key, keygroup;
struct i2c_msg msg[] = { { .addr = ir->c->addr, .flags = 0,
Expand Down Expand Up @@ -237,32 +236,33 @@ static int get_key_avermedia_cardbus(struct IR_i2c *ir,
}
key |= (keygroup & 1) << 6;

*ir_key = key;
*ir_raw = key;
if (!strcmp(ir->ir_codes, RC_MAP_AVERMEDIA_M733A_RM_K6)) {
*ir_key |= keygroup << 8;
*ir_raw |= keygroup << 8;
}
*protocol = RC_TYPE_UNKNOWN;
*scancode = key;
if (ir->c->addr == 0x41) /* AVerMedia EM78P153 */
*scancode |= keygroup << 8;
*toggle = 0;
return 1;
}

/* ----------------------------------------------------------------------- */

static int ir_key_poll(struct IR_i2c *ir)
{
static u32 ir_key, ir_raw;
enum rc_type protocol;
u32 scancode;
u8 toggle;
int rc;

dprintk(3, "%s\n", __func__);
rc = ir->get_key(ir, &ir_key, &ir_raw);
rc = ir->get_key(ir, &protocol, &scancode, &toggle);
if (rc < 0) {
dprintk(2,"error\n");
return rc;
}

if (rc) {
dprintk(1, "%s: keycode = 0x%04x\n", __func__, ir_key);
rc_keydown(ir->rc, ir_key, 0);
dprintk(1, "%s: scancode = 0x%08x\n", __func__, scancode);
rc_keydown(ir->rc, scancode, toggle);
}
return 0;
}
Expand Down Expand Up @@ -327,7 +327,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
case 0x6b:
name = "FusionHDTV";
ir->get_key = get_key_fusionhdtv;
rc_type = RC_BIT_RC5;
rc_type = RC_BIT_UNKNOWN;
ir_codes = RC_MAP_FUSIONHDTV_MCE;
break;
case 0x40:
Expand Down
8 changes: 5 additions & 3 deletions drivers/media/pci/bt8xx/bttv-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ static void bttv_ir_stop(struct bttv *btv)
* Get_key functions used by I2C remotes
*/

static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
static int get_key_pv951(struct IR_i2c *ir, enum rc_type *protocol,
u32 *scancode, u8 *toggle)
{
unsigned char b;

Expand All @@ -363,8 +364,9 @@ static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
* the device is bound to the vendor-provided RC.
*/

*ir_key = b;
*ir_raw = b;
*protocol = RC_TYPE_UNKNOWN;
*scancode = b;
*toggle = 0;
return 1;
}

Expand Down
8 changes: 5 additions & 3 deletions drivers/media/pci/cx88/cx88-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@ void cx88_ir_irq(struct cx88_core *core)
ir_raw_event_handle(ir->dev);
}

static int get_key_pvr2000(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
static int get_key_pvr2000(struct IR_i2c *ir, enum rc_type *protocol,
u32 *scancode, u8 *toggle)
{
int flags, code;

Expand All @@ -563,8 +564,9 @@ static int get_key_pvr2000(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
dprintk("IR Key/Flags: (0x%02x/0x%02x)\n",
code & 0xff, flags & 0xff);

*ir_key = code & 0xff;
*ir_raw = code;
*protocol = RC_TYPE_UNKNOWN;
*scancode = code & 0xff;
*toggle = 0;
return 1;
}

Expand Down
9 changes: 5 additions & 4 deletions drivers/media/pci/ivtv/ivtv-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ static const char * const hw_devicenames[] = {
"ir_video", /* IVTV_HW_I2C_IR_RX_ADAPTEC */
};

static int get_key_adaptec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
static int get_key_adaptec(struct IR_i2c *ir, enum rc_type *protocol,
u32 *scancode, u8 *toggle)
{
unsigned char keybuf[4];

Expand All @@ -167,9 +168,9 @@ static int get_key_adaptec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
keybuf[2] &= 0x7f;
keybuf[3] |= 0x80;

*ir_key = keybuf[3] | keybuf[2] << 8 | keybuf[1] << 16 |keybuf[0] << 24;
*ir_raw = *ir_key;

*protocol = RC_TYPE_UNKNOWN;
*scancode = keybuf[3] | keybuf[2] << 8 | keybuf[1] << 16 |keybuf[0] << 24;
*toggle = 0;
return 1;
}

Expand Down
Loading

0 comments on commit 4dd9bb9

Please sign in to comment.