Skip to content

Commit

Permalink
[media] rc-core: document the protocol type
Browse files Browse the repository at this point in the history
Right now the protocol information is not preserved, rc-core gets handed a
scancode but has no idea which protocol it corresponds to.

This patch (which required reading through the source/keymap for all drivers,
not fun) makes the protocol information explicit which is important
documentation and makes it easier to e.g. support multiple protocols with one
decoder (think rc5 and rc-streamzap). The information isn't used yet so there
should be no functional changes.

[m.chehab@samsung.com: rebased, added cxusb and removed bad whitespacing]
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 24, 2014
1 parent af3a4a9 commit 120703f
Show file tree
Hide file tree
Showing 40 changed files with 305 additions and 184 deletions.
5 changes: 3 additions & 2 deletions drivers/media/i2c/ir-kbd-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ static int ir_key_poll(struct IR_i2c *ir)
}

if (rc) {
dprintk(1, "%s: scancode = 0x%08x\n", __func__, scancode);
rc_keydown(ir->rc, scancode, toggle);
dprintk(1, "%s: proto = 0x%04x, scancode = 0x%08x\n",
__func__, protocol, scancode);
rc_keydown(ir->rc, protocol, scancode, toggle);
}
return 0;
}
Expand Down
12 changes: 6 additions & 6 deletions drivers/media/pci/bt8xx/bttv-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ static void ir_handle_key(struct bttv *btv)

if ((ir->mask_keydown && (gpio & ir->mask_keydown)) ||
(ir->mask_keyup && !(gpio & ir->mask_keyup))) {
rc_keydown_notimeout(ir->dev, data, 0);
rc_keydown_notimeout(ir->dev, RC_TYPE_UNKNOWN, data, 0);
} else {
/* HACK: Probably, ir->mask_keydown is missing
for this board */
if (btv->c.type == BTTV_BOARD_WINFAST2000)
rc_keydown_notimeout(ir->dev, data, 0);
rc_keydown_notimeout(ir->dev, RC_TYPE_UNKNOWN, data, 0);

rc_keyup(ir->dev);
}
Expand All @@ -103,7 +103,7 @@ static void ir_enltv_handle_key(struct bttv *btv)
gpio, data,
(gpio & ir->mask_keyup) ? " up" : "up/down");

rc_keydown_notimeout(ir->dev, data, 0);
rc_keydown_notimeout(ir->dev, RC_TYPE_UNKNOWN, data, 0);
if (keyup)
rc_keyup(ir->dev);
} else {
Expand All @@ -117,7 +117,7 @@ static void ir_enltv_handle_key(struct bttv *btv)
if (keyup)
rc_keyup(ir->dev);
else
rc_keydown_notimeout(ir->dev, data, 0);
rc_keydown_notimeout(ir->dev, RC_TYPE_UNKNOWN, data, 0);
}

ir->last_gpio = data | keyup;
Expand Down Expand Up @@ -241,8 +241,8 @@ static void bttv_rc5_timer_end(unsigned long data)
return;
}

scancode = system << 8 | command;
rc_keydown(ir->dev, scancode, toggle);
scancode = RC_SCANCODE_RC5(system, command);
rc_keydown(ir->dev, RC_TYPE_RC5, scancode, toggle);
dprintk("scancode %x, toggle %x\n", scancode, toggle);
}

Expand Down
26 changes: 21 additions & 5 deletions drivers/media/pci/cx88/cx88-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,41 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)

data = (data << 4) | ((gpio_key & 0xf0) >> 4);

rc_keydown(ir->dev, data, 0);
rc_keydown(ir->dev, RC_TYPE_UNKNOWN, data, 0);

} else if (ir->core->boardnr == CX88_BOARD_PROLINK_PLAYTVPVR ||
ir->core->boardnr == CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO) {
/* bit cleared on keydown, NEC scancode, 0xAAAACC, A = 0x866b */
u16 addr;
u8 cmd;
u32 scancode;

addr = (data >> 8) & 0xffff;
cmd = (data >> 0) & 0x00ff;
scancode = RC_SCANCODE_NECX(addr, cmd);

if (0 == (gpio & ir->mask_keyup))
rc_keydown_notimeout(ir->dev, RC_TYPE_NEC, scancode, 0);
else
rc_keyup(ir->dev);

} else if (ir->mask_keydown) {
/* bit set on keydown */
if (gpio & ir->mask_keydown)
rc_keydown_notimeout(ir->dev, data, 0);
rc_keydown_notimeout(ir->dev, RC_TYPE_UNKNOWN, data, 0);
else
rc_keyup(ir->dev);

} else if (ir->mask_keyup) {
/* bit cleared on keydown */
if (0 == (gpio & ir->mask_keyup))
rc_keydown_notimeout(ir->dev, data, 0);
rc_keydown_notimeout(ir->dev, RC_TYPE_UNKNOWN, data, 0);
else
rc_keyup(ir->dev);

} else {
/* can't distinguish keydown/up :-/ */
rc_keydown_notimeout(ir->dev, data, 0);
rc_keydown_notimeout(ir->dev, RC_TYPE_UNKNOWN, data, 0);
rc_keyup(ir->dev);
}
}
Expand Down Expand Up @@ -329,6 +345,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
* 002-T mini RC, provided with newer PV hardware
*/
ir_codes = RC_MAP_PIXELVIEW_MK12;
rc_type = RC_BIT_NEC;
ir->gpio_addr = MO_GP1_IO;
ir->mask_keyup = 0x80;
ir->polling = 10; /* ms */
Expand Down Expand Up @@ -416,7 +433,6 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
break;
case CX88_BOARD_TWINHAN_VP1027_DVBS:
ir_codes = RC_MAP_TWINHAN_VP1027_DVBS;
rc_type = RC_BIT_NEC;
ir->sampling = 0xff00; /* address */
break;
}
Expand Down
3 changes: 2 additions & 1 deletion drivers/media/pci/dm1105/dm1105.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,8 @@ static void dm1105_emit_key(struct work_struct *work)

data = (ircom >> 8) & 0x7f;

rc_keydown(ir->dev, data, 0);
/* FIXME: UNKNOWN because we don't generate a full NEC scancode (yet?) */
rc_keydown(ir->dev, RC_TYPE_UNKNOWN, data, 0);
}

/* work handler */
Expand Down
6 changes: 3 additions & 3 deletions drivers/media/pci/saa7134/saa7134-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,22 @@ static int build_key(struct saa7134_dev *dev)
if (data == ir->mask_keycode)
rc_keyup(ir->dev);
else
rc_keydown_notimeout(ir->dev, data, 0);
rc_keydown_notimeout(ir->dev, RC_TYPE_UNKNOWN, data, 0);
return 0;
}

if (ir->polling) {
if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
(ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
rc_keydown_notimeout(ir->dev, data, 0);
rc_keydown_notimeout(ir->dev, RC_TYPE_UNKNOWN, data, 0);
} else {
rc_keyup(ir->dev);
}
}
else { /* IRQ driven mode - handle key press and release in one go */
if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
(ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
rc_keydown_notimeout(ir->dev, data, 0);
rc_keydown_notimeout(ir->dev, RC_TYPE_UNKNOWN, data, 0);
rc_keyup(ir->dev);
}
}
Expand Down
8 changes: 4 additions & 4 deletions drivers/media/pci/ttpci/budget-ci.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ static void msp430_ir_interrupt(unsigned long data)
return;

if (budget_ci->ir.full_rc5) {
rc_keydown(dev,
budget_ci->ir.rc5_device <<8 | budget_ci->ir.ir_key,
(command & 0x20) ? 1 : 0);
rc_keydown(dev, RC_TYPE_RC5,
RC_SCANCODE_RC5(budget_ci->ir.rc5_device, budget_ci->ir.ir_key),
!!(command & 0x20));
return;
}

/* FIXME: We should generate complete scancodes for all devices */
rc_keydown(dev, budget_ci->ir.ir_key, (command & 0x20) ? 1 : 0);
rc_keydown(dev, RC_TYPE_UNKNOWN, budget_ci->ir.ir_key, !!(command & 0x20));
}

static int msp430_ir_init(struct budget_ci *budget_ci)
Expand Down
4 changes: 2 additions & 2 deletions drivers/media/rc/ati_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,8 @@ static void ati_remote_input_report(struct urb *urb)
* it would cause ghost repeats which would be a
* regression for this driver.
*/
rc_keydown_notimeout(ati_remote->rdev, scancode,
data[2]);
rc_keydown_notimeout(ati_remote->rdev, RC_TYPE_OTHER,
scancode, data[2]);
rc_keyup(ati_remote->rdev);
}
return;
Expand Down
10 changes: 6 additions & 4 deletions drivers/media/rc/img-ir/img-ir-hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ static int img_ir_set_filter(struct rc_dev *dev, enum rc_filter_type type,
static int img_ir_set_normal_filter(struct rc_dev *dev,
struct rc_scancode_filter *sc_filter)
{
return img_ir_set_filter(dev, RC_FILTER_NORMAL, sc_filter);
return img_ir_set_filter(dev, RC_FILTER_NORMAL, sc_filter);
}

static int img_ir_set_wakeup_filter(struct rc_dev *dev,
Expand Down Expand Up @@ -795,9 +795,11 @@ static void img_ir_handle_data(struct img_ir_priv *priv, u32 len, u64 raw)
struct img_ir_priv_hw *hw = &priv->hw;
const struct img_ir_decoder *dec = hw->decoder;
int ret = IMG_IR_SCANCODE;
int scancode;
u32 scancode;
enum rc_type protocol = RC_TYPE_UNKNOWN;

if (dec->scancode)
ret = dec->scancode(len, raw, &scancode, hw->enabled_protocols);
ret = dec->scancode(len, raw, &protocol, &scancode, hw->enabled_protocols);
else if (len >= 32)
scancode = (u32)raw;
else if (len < 32)
Expand All @@ -806,7 +808,7 @@ static void img_ir_handle_data(struct img_ir_priv *priv, u32 len, u64 raw)
len, (unsigned long long)raw);
if (ret == IMG_IR_SCANCODE) {
dev_dbg(priv->dev, "decoded scan code %#x\n", scancode);
rc_keydown(hw->rdev, scancode, 0);
rc_keydown(hw->rdev, protocol, scancode, 0);
img_ir_end_repeat(priv);
} else if (ret == IMG_IR_REPEATCODE) {
if (hw->mode == IMG_IR_M_REPEATING) {
Expand Down
3 changes: 2 additions & 1 deletion drivers/media/rc/img-ir/img-ir-hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ struct img_ir_decoder {
struct img_ir_control control;

/* scancode logic */
int (*scancode)(int len, u64 raw, int *scancode, u64 protocols);
int (*scancode)(int len, u64 raw, enum rc_type *protocol,
u32 *scancode, u64 enabled_protocols);
int (*filter)(const struct rc_scancode_filter *in,
struct img_ir_filter *out, u64 protocols);
};
Expand Down
4 changes: 3 additions & 1 deletion drivers/media/rc/img-ir/img-ir-jvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include "img-ir-hw.h"

/* Convert JVC data to a scancode */
static int img_ir_jvc_scancode(int len, u64 raw, int *scancode, u64 protocols)
static int img_ir_jvc_scancode(int len, u64 raw, enum rc_type *protocol,
u32 *scancode, u64 enabled_protocols)
{
unsigned int cust, data;

Expand All @@ -22,6 +23,7 @@ static int img_ir_jvc_scancode(int len, u64 raw, int *scancode, u64 protocols)
cust = (raw >> 0) & 0xff;
data = (raw >> 8) & 0xff;

*protocol = RC_TYPE_JVC;
*scancode = cust << 8 | data;
return IMG_IR_SCANCODE;
}
Expand Down
4 changes: 3 additions & 1 deletion drivers/media/rc/img-ir/img-ir-nec.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include <linux/bitrev.h>

/* Convert NEC data to a scancode */
static int img_ir_nec_scancode(int len, u64 raw, int *scancode, u64 protocols)
static int img_ir_nec_scancode(int len, u64 raw, enum rc_type *protocol,
u32 *scancode, u64 enabled_protocols)
{
unsigned int addr, addr_inv, data, data_inv;
/* a repeat code has no data */
Expand Down Expand Up @@ -45,6 +46,7 @@ static int img_ir_nec_scancode(int len, u64 raw, int *scancode, u64 protocols)
*scancode = addr << 8 |
data;
}
*protocol = RC_TYPE_NEC;
return IMG_IR_SCANCODE;
}

Expand Down
4 changes: 3 additions & 1 deletion drivers/media/rc/img-ir/img-ir-sanyo.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
#include "img-ir-hw.h"

/* Convert Sanyo data to a scancode */
static int img_ir_sanyo_scancode(int len, u64 raw, int *scancode, u64 protocols)
static int img_ir_sanyo_scancode(int len, u64 raw, enum rc_type *protocol,
u32 *scancode, u64 enabled_protocols)
{
unsigned int addr, addr_inv, data, data_inv;
/* a repeat code has no data */
Expand All @@ -43,6 +44,7 @@ static int img_ir_sanyo_scancode(int len, u64 raw, int *scancode, u64 protocols)
return -EINVAL;

/* Normal Sanyo */
*protocol = RC_TYPE_SANYO;
*scancode = addr << 8 | data;
return IMG_IR_SCANCODE;
}
Expand Down
4 changes: 3 additions & 1 deletion drivers/media/rc/img-ir/img-ir-sharp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include "img-ir-hw.h"

/* Convert Sharp data to a scancode */
static int img_ir_sharp_scancode(int len, u64 raw, int *scancode, u64 protocols)
static int img_ir_sharp_scancode(int len, u64 raw, enum rc_type *protocol,
u32 *scancode, u64 enabled_protocols)
{
unsigned int addr, cmd, exp, chk;

Expand All @@ -31,6 +32,7 @@ static int img_ir_sharp_scancode(int len, u64 raw, int *scancode, u64 protocols)
/* probably the second half of the message */
return -EINVAL;

*protocol = RC_TYPE_SHARP;
*scancode = addr << 8 | cmd;
return IMG_IR_SCANCODE;
}
Expand Down
12 changes: 8 additions & 4 deletions drivers/media/rc/img-ir/img-ir-sony.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,39 @@
#include "img-ir-hw.h"

/* Convert Sony data to a scancode */
static int img_ir_sony_scancode(int len, u64 raw, int *scancode, u64 protocols)
static int img_ir_sony_scancode(int len, u64 raw, enum rc_type *protocol,
u32 *scancode, u64 enabled_protocols)
{
unsigned int dev, subdev, func;

switch (len) {
case 12:
if (!(protocols & RC_BIT_SONY12))
if (!(enabled_protocols & RC_BIT_SONY12))
return -EINVAL;
func = raw & 0x7f; /* first 7 bits */
raw >>= 7;
dev = raw & 0x1f; /* next 5 bits */
subdev = 0;
*protocol = RC_TYPE_SONY12;
break;
case 15:
if (!(protocols & RC_BIT_SONY15))
if (!(enabled_protocols & RC_BIT_SONY15))
return -EINVAL;
func = raw & 0x7f; /* first 7 bits */
raw >>= 7;
dev = raw & 0xff; /* next 8 bits */
subdev = 0;
*protocol = RC_TYPE_SONY15;
break;
case 20:
if (!(protocols & RC_BIT_SONY20))
if (!(enabled_protocols & RC_BIT_SONY20))
return -EINVAL;
func = raw & 0x7f; /* first 7 bits */
raw >>= 7;
dev = raw & 0x1f; /* next 5 bits */
raw >>= 5;
subdev = raw & 0xff; /* next 8 bits */
*protocol = RC_TYPE_SONY20;
break;
default:
return -EINVAL;
Expand Down
5 changes: 4 additions & 1 deletion drivers/media/rc/imon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,10 @@ static void imon_incoming_packet(struct imon_context *ictx,
if (press_type == 0)
rc_keyup(ictx->rdev);
else {
rc_keydown(ictx->rdev, ictx->rc_scancode, ictx->rc_toggle);
if (ictx->rc_type == RC_BIT_RC6_MCE)
rc_keydown(ictx->rdev,
ictx->rc_type == RC_BIT_RC6_MCE ? RC_TYPE_RC6_MCE : RC_TYPE_OTHER,
ictx->rc_scancode, ictx->rc_toggle);
spin_lock_irqsave(&ictx->kc_lock, flags);
ictx->last_keycode = ictx->kc;
spin_unlock_irqrestore(&ictx->kc_lock, flags);
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/rc/ir-jvc-decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static int ir_jvc_decode(struct rc_dev *dev, struct ir_raw_event ev)
scancode = (bitrev8((data->bits >> 8) & 0xff) << 8) |
(bitrev8((data->bits >> 0) & 0xff) << 0);
IR_dprintk(1, "JVC scancode 0x%04x\n", scancode);
rc_keydown(dev, scancode, data->toggle);
rc_keydown(dev, RC_TYPE_JVC, scancode, data->toggle);
data->first = false;
data->old_bits = data->bits;
} else if (data->bits == data->old_bits) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/rc/ir-nec-decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static int ir_nec_decode(struct rc_dev *dev, struct ir_raw_event ev)
if (data->is_nec_x)
data->necx_repeat = true;

rc_keydown(dev, scancode, 0);
rc_keydown(dev, RC_TYPE_NEC, scancode, 0);
data->state = STATE_INACTIVE;
return 0;
}
Expand Down
Loading

0 comments on commit 120703f

Please sign in to comment.