Skip to content

Commit

Permalink
[media] rc-core: add separate defines for protocol bitmaps and numbers
Browse files Browse the repository at this point in the history
The RC_TYPE_* defines are currently used both where a single protocol is
expected and where a bitmap of protocols is expected.

Functions like rc_keydown() and functions which add/remove entries to the
keytable want a single protocol. Future userspace APIs would also
benefit from numeric protocols (rather than bitmap ones). Keytables are
smaller if they can use a small(ish) integer rather than a bitmap.

Other functions or struct members (e.g. allowed_protos,
enabled_protocols, etc) accept multiple protocols and need a bitmap.

Using different types reduces the risk of programmer error. Using a
protocol enum whereever possible also makes for a more future-proof
user-space API as we don't need to worry about a sufficient number of
bits being available (e.g. in structs used for ioctl() calls).

The use of both a number and a corresponding bit is dalso one in e.g.
the input subsystem as well (see all the references to set/clear bit when
changing keytables for example).

This patch separate the different usages in preparation for
upcoming patches.

Where a single protocol is expected, enum rc_type is used; where one or more
protocol(s) are expected, something like u64 is used.

The patch has been rewritten so that the format of the sysfs "protocols"
file is no longer altered (at the loss of some detail). The file itself
should probably be deprecated in the future though.

Signed-off-by: David Härdeman <david@hardeman.nu>
Cc: Andy Walls <awalls@md.metrocast.net>
Cc: Maxim Levitsky <maximlevitsky@gmail.com>
Cc: Antti Palosaari <crope@iki.fi>
Cc: Mike Isely <isely@pobox.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
David Härdeman authored and Mauro Carvalho Chehab committed Oct 27, 2012
1 parent 304ce75 commit c003ab1
Show file tree
Hide file tree
Showing 56 changed files with 314 additions and 244 deletions.
2 changes: 1 addition & 1 deletion drivers/media/common/siano/smsir.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int sms_ir_init(struct smscore_device_t *coredev)

dev->priv = coredev;
dev->driver_type = RC_DRIVER_IR_RAW;
dev->allowed_protos = RC_TYPE_ALL;
dev->allowed_protos = RC_BIT_ALL;
dev->map_name = sms_get_board(board_id)->rc_codes;
dev->driver_name = MODULE_NAME;

Expand Down
14 changes: 7 additions & 7 deletions drivers/media/i2c/ir-kbd-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
char *ir_codes = NULL;
const char *name = NULL;
u64 rc_type = RC_TYPE_UNKNOWN;
u64 rc_type = RC_BIT_UNKNOWN;
struct IR_i2c *ir;
struct rc_dev *rc = NULL;
struct i2c_adapter *adap = client->adapter;
Expand All @@ -303,39 +303,39 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
case 0x64:
name = "Pixelview";
ir->get_key = get_key_pixelview;
rc_type = RC_TYPE_OTHER;
rc_type = RC_BIT_OTHER;
ir_codes = RC_MAP_EMPTY;
break;
case 0x18:
case 0x1f:
case 0x1a:
name = "Hauppauge";
ir->get_key = get_key_haup;
rc_type = RC_TYPE_RC5;
rc_type = RC_BIT_RC5;
ir_codes = RC_MAP_HAUPPAUGE;
break;
case 0x30:
name = "KNC One";
ir->get_key = get_key_knc1;
rc_type = RC_TYPE_OTHER;
rc_type = RC_BIT_OTHER;
ir_codes = RC_MAP_EMPTY;
break;
case 0x6b:
name = "FusionHDTV";
ir->get_key = get_key_fusionhdtv;
rc_type = RC_TYPE_RC5;
rc_type = RC_BIT_RC5;
ir_codes = RC_MAP_FUSIONHDTV_MCE;
break;
case 0x40:
name = "AVerMedia Cardbus remote";
ir->get_key = get_key_avermedia_cardbus;
rc_type = RC_TYPE_OTHER;
rc_type = RC_BIT_OTHER;
ir_codes = RC_MAP_AVERMEDIA_CARDBUS;
break;
case 0x71:
name = "Hauppauge/Zilog Z8";
ir->get_key = get_key_haup_xvr;
rc_type = RC_TYPE_RC5;
rc_type = RC_BIT_RC5;
ir_codes = RC_MAP_HAUPPAUGE;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/cx18/cx18-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw,
case CX18_HW_Z8F0811_IR_RX_HAUP:
init_data->ir_codes = RC_MAP_HAUPPAUGE;
init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
init_data->type = RC_TYPE_RC5;
init_data->type = RC_BIT_RC5;
init_data->name = cx->card_name;
info.platform_data = init_data;
break;
Expand Down
6 changes: 3 additions & 3 deletions drivers/media/pci/cx23885/cx23885-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,21 @@ int cx23885_input_init(struct cx23885_dev *dev)
case CX23885_BOARD_HAUPPAUGE_HVR1250:
/* Integrated CX2388[58] IR controller */
driver_type = RC_DRIVER_IR_RAW;
allowed_protos = RC_TYPE_ALL;
allowed_protos = RC_BIT_ALL;
/* The grey Hauppauge RC-5 remote */
rc_map = RC_MAP_HAUPPAUGE;
break;
case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
/* Integrated CX23885 IR controller */
driver_type = RC_DRIVER_IR_RAW;
allowed_protos = RC_TYPE_NEC;
allowed_protos = RC_BIT_NEC;
/* The grey Terratec remote with orange buttons */
rc_map = RC_MAP_NEC_TERRATEC_CINERGY_XS;
break;
case CX23885_BOARD_TEVII_S470:
/* Integrated CX23885 IR controller */
driver_type = RC_DRIVER_IR_RAW;
allowed_protos = RC_TYPE_ALL;
allowed_protos = RC_BIT_ALL;
/* A guess at the remote */
rc_map = RC_MAP_TEVII_NEC;
break;
Expand Down
8 changes: 4 additions & 4 deletions drivers/media/pci/cx88/cx88-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
struct cx88_IR *ir;
struct rc_dev *dev;
char *ir_codes = NULL;
u64 rc_type = RC_TYPE_OTHER;
u64 rc_type = RC_BIT_OTHER;
int err = -ENOMEM;
u32 hardware_mask = 0; /* For devices with a hardware mask, when
* used with a full-code IR table
Expand Down Expand Up @@ -416,7 +416,7 @@ 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_TYPE_NEC;
rc_type = RC_BIT_NEC;
ir->sampling = 0xff00; /* address */
break;
}
Expand Down Expand Up @@ -592,7 +592,7 @@ void cx88_i2c_init_ir(struct cx88_core *core)
case CX88_BOARD_LEADTEK_PVR2000:
addr_list = pvr2000_addr_list;
core->init_data.name = "cx88 Leadtek PVR 2000 remote";
core->init_data.type = RC_TYPE_UNKNOWN;
core->init_data.type = RC_BIT_UNKNOWN;
core->init_data.get_key = get_key_pvr2000;
core->init_data.ir_codes = RC_MAP_EMPTY;
break;
Expand All @@ -613,7 +613,7 @@ void cx88_i2c_init_ir(struct cx88_core *core)
/* Hauppauge XVR */
core->init_data.name = "cx88 Hauppauge XVR remote";
core->init_data.ir_codes = RC_MAP_HAUPPAUGE;
core->init_data.type = RC_TYPE_RC5;
core->init_data.type = RC_BIT_RC5;
core->init_data.internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;

info.platform_data = &core->init_data;
Expand Down
8 changes: 4 additions & 4 deletions drivers/media/pci/ivtv/ivtv-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,29 +200,29 @@ static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr)
init_data->ir_codes = RC_MAP_AVERMEDIA_CARDBUS;
init_data->internal_get_key_func =
IR_KBD_GET_KEY_AVERMEDIA_CARDBUS;
init_data->type = RC_TYPE_OTHER;
init_data->type = RC_BIT_OTHER;
init_data->name = "AVerMedia AVerTV card";
break;
case IVTV_HW_I2C_IR_RX_HAUP_EXT:
case IVTV_HW_I2C_IR_RX_HAUP_INT:
init_data->ir_codes = RC_MAP_HAUPPAUGE;
init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP;
init_data->type = RC_TYPE_RC5;
init_data->type = RC_BIT_RC5;
init_data->name = itv->card_name;
break;
case IVTV_HW_Z8F0811_IR_RX_HAUP:
/* Default to grey remote */
init_data->ir_codes = RC_MAP_HAUPPAUGE;
init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
init_data->type = RC_TYPE_RC5;
init_data->type = RC_BIT_RC5;
init_data->name = itv->card_name;
break;
case IVTV_HW_I2C_IR_RX_ADAPTEC:
init_data->get_key = get_key_adaptec;
init_data->name = itv->card_name;
/* FIXME: The protocol and RC_MAP needs to be corrected */
init_data->ir_codes = RC_MAP_EMPTY;
init_data->type = RC_TYPE_UNKNOWN;
init_data->type = RC_BIT_UNKNOWN;
break;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/saa7134/saa7134-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
dev->init_data.name = "BeholdTV";
dev->init_data.get_key = get_key_beholdm6xx;
dev->init_data.ir_codes = RC_MAP_BEHOLD;
dev->init_data.type = RC_TYPE_NEC;
dev->init_data.type = RC_BIT_NEC;
info.addr = 0x2d;
break;
case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/rc/ati_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ static void ati_remote_rc_init(struct ati_remote *ati_remote)

rdev->priv = ati_remote;
rdev->driver_type = RC_DRIVER_SCANCODE;
rdev->allowed_protos = RC_TYPE_OTHER;
rdev->allowed_protos = RC_BIT_OTHER;
rdev->driver_name = "ati_remote";

rdev->open = ati_remote_rc_open;
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/rc/ene_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id)
learning_mode_force = false;

rdev->driver_type = RC_DRIVER_IR_RAW;
rdev->allowed_protos = RC_TYPE_ALL;
rdev->allowed_protos = RC_BIT_ALL;
rdev->priv = dev;
rdev->open = ene_open;
rdev->close = ene_close;
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/rc/fintek-cir.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ static int fintek_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id
/* Set up the rc device */
rdev->priv = fintek;
rdev->driver_type = RC_DRIVER_IR_RAW;
rdev->allowed_protos = RC_TYPE_ALL;
rdev->allowed_protos = RC_BIT_ALL;
rdev->open = fintek_open;
rdev->close = fintek_close;
rdev->input_name = FINTEK_DESCRIPTION;
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/rc/gpio-ir-recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static int __devinit gpio_ir_recv_probe(struct platform_device *pdev)
if (pdata->allowed_protos)
rcdev->allowed_protos = pdata->allowed_protos;
else
rcdev->allowed_protos = RC_TYPE_ALL;
rcdev->allowed_protos = RC_BIT_ALL;
rcdev->map_name = pdata->map_name ?: RC_MAP_EMPTY;

gpio_dev->rcdev = rcdev;
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/rc/iguanair.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ static int __devinit iguanair_probe(struct usb_interface *intf,
usb_to_input_id(ir->udev, &rc->input_id);
rc->dev.parent = &intf->dev;
rc->driver_type = RC_DRIVER_IR_RAW;
rc->allowed_protos = RC_TYPE_ALL;
rc->allowed_protos = RC_BIT_ALL;
rc->priv = ir;
rc->open = iguanair_open;
rc->close = iguanair_close;
Expand Down
40 changes: 18 additions & 22 deletions drivers/media/rc/imon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ static void imon_touch_display_timeout(unsigned long data)
* it is not, so we must acquire it prior to calling send_packet, which
* requires that the lock is held.
*/
static int imon_ir_change_protocol(struct rc_dev *rc, u64 rc_type)
static int imon_ir_change_protocol(struct rc_dev *rc, u64 *rc_type)
{
int retval;
struct imon_context *ictx = rc->priv;
Expand All @@ -1010,31 +1010,27 @@ static int imon_ir_change_protocol(struct rc_dev *rc, u64 rc_type)
unsigned char ir_proto_packet[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 };

if (rc_type && !(rc_type & rc->allowed_protos))
if (*rc_type && !(*rc_type & rc->allowed_protos))
dev_warn(dev, "Looks like you're trying to use an IR protocol "
"this device does not support\n");

switch (rc_type) {
case RC_TYPE_RC6:
if (*rc_type & RC_BIT_RC6_MCE) {
dev_dbg(dev, "Configuring IR receiver for MCE protocol\n");
ir_proto_packet[0] = 0x01;
break;
case RC_TYPE_UNKNOWN:
case RC_TYPE_OTHER:
*rc_type = RC_BIT_RC6_MCE;
} else if (*rc_type & RC_BIT_OTHER) {
dev_dbg(dev, "Configuring IR receiver for iMON protocol\n");
if (!pad_stabilize)
dev_dbg(dev, "PAD stabilize functionality disabled\n");
/* ir_proto_packet[0] = 0x00; // already the default */
rc_type = RC_TYPE_OTHER;
break;
default:
*rc_type = RC_BIT_OTHER;
} else {
dev_warn(dev, "Unsupported IR protocol specified, overriding "
"to iMON IR protocol\n");
if (!pad_stabilize)
dev_dbg(dev, "PAD stabilize functionality disabled\n");
/* ir_proto_packet[0] = 0x00; // already the default */
rc_type = RC_TYPE_OTHER;
break;
*rc_type = RC_BIT_OTHER;
}

memcpy(ictx->usb_tx_buf, &ir_proto_packet, sizeof(ir_proto_packet));
Expand All @@ -1048,7 +1044,7 @@ static int imon_ir_change_protocol(struct rc_dev *rc, u64 rc_type)
if (retval)
goto out;

ictx->rc_type = rc_type;
ictx->rc_type = *rc_type;
ictx->pad_mouse = false;

out:
Expand Down Expand Up @@ -1323,7 +1319,7 @@ static void imon_pad_to_keys(struct imon_context *ictx, unsigned char *buf)
rel_x = buf[2];
rel_y = buf[3];

if (ictx->rc_type == RC_TYPE_OTHER && pad_stabilize) {
if (ictx->rc_type == RC_BIT_OTHER && pad_stabilize) {
if ((buf[1] == 0) && ((rel_x != 0) || (rel_y != 0))) {
dir = stabilize((int)rel_x, (int)rel_y,
timeout, threshold);
Expand Down Expand Up @@ -1390,7 +1386,7 @@ static void imon_pad_to_keys(struct imon_context *ictx, unsigned char *buf)
buf[0] = 0x01;
buf[1] = buf[4] = buf[5] = buf[6] = buf[7] = 0;

if (ictx->rc_type == RC_TYPE_OTHER && pad_stabilize) {
if (ictx->rc_type == RC_BIT_OTHER && pad_stabilize) {
dir = stabilize((int)rel_x, (int)rel_y,
timeout, threshold);
if (!dir) {
Expand Down Expand Up @@ -1511,7 +1507,7 @@ static void imon_incoming_packet(struct imon_context *ictx,
kc = imon_panel_key_lookup(scancode);
} else {
scancode = be32_to_cpu(*((u32 *)buf));
if (ictx->rc_type == RC_TYPE_RC6) {
if (ictx->rc_type == RC_BIT_RC6_MCE) {
ktype = IMON_KEY_IMON;
if (buf[0] == 0x80)
ktype = IMON_KEY_MCE;
Expand Down Expand Up @@ -1744,7 +1740,7 @@ static void imon_get_ffdc_type(struct imon_context *ictx)
{
u8 ffdc_cfg_byte = ictx->usb_rx_buf[6];
u8 detected_display_type = IMON_DISPLAY_TYPE_NONE;
u64 allowed_protos = RC_TYPE_OTHER;
u64 allowed_protos = RC_BIT_OTHER;

switch (ffdc_cfg_byte) {
/* iMON Knob, no display, iMON IR + vol knob */
Expand Down Expand Up @@ -1775,21 +1771,21 @@ static void imon_get_ffdc_type(struct imon_context *ictx)
case 0x9e:
dev_info(ictx->dev, "0xffdc iMON VFD, MCE IR");
detected_display_type = IMON_DISPLAY_TYPE_VFD;
allowed_protos = RC_TYPE_RC6;
allowed_protos = RC_BIT_RC6_MCE;
break;
/* iMON LCD, MCE IR */
case 0x9f:
dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR");
detected_display_type = IMON_DISPLAY_TYPE_LCD;
allowed_protos = RC_TYPE_RC6;
allowed_protos = RC_BIT_RC6_MCE;
break;
default:
dev_info(ictx->dev, "Unknown 0xffdc device, "
"defaulting to VFD and iMON IR");
detected_display_type = IMON_DISPLAY_TYPE_VFD;
/* We don't know which one it is, allow user to set the
* RC6 one from userspace if OTHER wasn't correct. */
allowed_protos |= RC_TYPE_RC6;
allowed_protos |= RC_BIT_RC6_MCE;
break;
}

Expand Down Expand Up @@ -1875,7 +1871,7 @@ static struct rc_dev *imon_init_rdev(struct imon_context *ictx)

rdev->priv = ictx;
rdev->driver_type = RC_DRIVER_SCANCODE;
rdev->allowed_protos = RC_TYPE_OTHER | RC_TYPE_RC6; /* iMON PAD or MCE */
rdev->allowed_protos = RC_BIT_OTHER | RC_BIT_RC6_MCE; /* iMON PAD or MCE */
rdev->change_protocol = imon_ir_change_protocol;
rdev->driver_name = MOD_NAME;

Expand All @@ -1893,7 +1889,7 @@ static struct rc_dev *imon_init_rdev(struct imon_context *ictx)

imon_set_display_type(ictx);

if (ictx->rc_type == RC_TYPE_RC6)
if (ictx->rc_type == RC_BIT_RC6_MCE)
rdev->map_name = RC_MAP_IMON_MCE;
else
rdev->map_name = RC_MAP_IMON_PAD;
Expand Down
4 changes: 2 additions & 2 deletions drivers/media/rc/ir-jvc-decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static int ir_jvc_decode(struct rc_dev *dev, struct ir_raw_event ev)
{
struct jvc_dec *data = &dev->raw->jvc;

if (!(dev->raw->enabled_protocols & RC_TYPE_JVC))
if (!(dev->raw->enabled_protocols & RC_BIT_JVC))
return 0;

if (!is_timing_event(ev)) {
Expand Down Expand Up @@ -174,7 +174,7 @@ static int ir_jvc_decode(struct rc_dev *dev, struct ir_raw_event ev)
}

static struct ir_raw_handler jvc_handler = {
.protocols = RC_TYPE_JVC,
.protocols = RC_BIT_JVC,
.decode = ir_jvc_decode,
};

Expand Down
4 changes: 2 additions & 2 deletions drivers/media/rc/ir-lirc-codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static int ir_lirc_decode(struct rc_dev *dev, struct ir_raw_event ev)
struct lirc_codec *lirc = &dev->raw->lirc;
int sample;

if (!(dev->raw->enabled_protocols & RC_TYPE_LIRC))
if (!(dev->raw->enabled_protocols & RC_BIT_LIRC))
return 0;

if (!dev->raw->lirc.drv || !dev->raw->lirc.drv->rbuf)
Expand Down Expand Up @@ -408,7 +408,7 @@ static int ir_lirc_unregister(struct rc_dev *dev)
}

static struct ir_raw_handler lirc_handler = {
.protocols = RC_TYPE_LIRC,
.protocols = RC_BIT_LIRC,
.decode = ir_lirc_decode,
.raw_register = ir_lirc_register,
.raw_unregister = ir_lirc_unregister,
Expand Down
Loading

0 comments on commit c003ab1

Please sign in to comment.