Commit de8592bd authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

V4L/DVB: ir-core: allow specifying multiple protocols at one open/write

With this change, it is now possible to do something like:
        su -c 'echo "none +rc-5 +nec" > /sys/class/rc/rc1/protocols'

This prevents the need of multiple opens, one for each protocol change,
and makes userspace application easier.
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 5f124797
...@@ -117,14 +117,19 @@ static ssize_t store_protocols(struct device *d, ...@@ -117,14 +117,19 @@ static ssize_t store_protocols(struct device *d,
const char *tmp; const char *tmp;
u64 type; u64 type;
u64 mask; u64 mask;
int rc, i; int rc, i, count = 0;
unsigned long flags; unsigned long flags;
tmp = skip_spaces(data); if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE)
if (*tmp == '\0') { type = ir_dev->rc_tab.ir_type;
IR_dprintk(1, "Protocol not specified\n"); else
return -EINVAL; type = ir_dev->raw->enabled_protocols;
} else if (*tmp == '+') {
while ((tmp = strsep((char **) &data, " \n")) != NULL) {
if (!*tmp)
break;
if (*tmp == '+') {
enable = true; enable = true;
disable = false; disable = false;
tmp++; tmp++;
...@@ -137,10 +142,10 @@ static ssize_t store_protocols(struct device *d, ...@@ -137,10 +142,10 @@ static ssize_t store_protocols(struct device *d,
disable = false; disable = false;
} }
if (!enable && !disable && !strncasecmp(tmp, PROTO_NONE, sizeof(PROTO_NONE))) { if (!enable && !disable && !strncasecmp(tmp, PROTO_NONE, sizeof(PROTO_NONE))) {
mask = 0;
tmp += sizeof(PROTO_NONE); tmp += sizeof(PROTO_NONE);
mask = 0;
count++;
} else { } else {
for (i = 0; i < ARRAY_SIZE(proto_names); i++) { for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
if (!strncasecmp(tmp, proto_names[i].name, strlen(proto_names[i].name))) { if (!strncasecmp(tmp, proto_names[i].name, strlen(proto_names[i].name))) {
...@@ -150,28 +155,24 @@ static ssize_t store_protocols(struct device *d, ...@@ -150,28 +155,24 @@ static ssize_t store_protocols(struct device *d,
} }
} }
if (i == ARRAY_SIZE(proto_names)) { if (i == ARRAY_SIZE(proto_names)) {
IR_dprintk(1, "Unknown protocol\n"); IR_dprintk(1, "Unknown protocol: '%s'\n", tmp);
return -EINVAL; return -EINVAL;
} }
count++;
} }
tmp = skip_spaces(tmp);
if (*tmp != '\0') {
IR_dprintk(1, "Invalid trailing characters\n");
return -EINVAL;
}
if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE)
type = ir_dev->rc_tab.ir_type;
else
type = ir_dev->raw->enabled_protocols;
if (enable) if (enable)
type |= mask; type |= mask;
else if (disable) else if (disable)
type &= ~mask; type &= ~mask;
else else
type = mask; type = mask;
}
if (!count) {
IR_dprintk(1, "Protocol not specified\n");
return -EINVAL;
}
if (ir_dev->props && ir_dev->props->change_protocol) { if (ir_dev->props && ir_dev->props->change_protocol) {
rc = ir_dev->props->change_protocol(ir_dev->props->priv, rc = ir_dev->props->change_protocol(ir_dev->props->priv,
...@@ -191,7 +192,6 @@ static ssize_t store_protocols(struct device *d, ...@@ -191,7 +192,6 @@ static ssize_t store_protocols(struct device *d,
ir_dev->raw->enabled_protocols = type; ir_dev->raw->enabled_protocols = type;
} }
IR_dprintk(1, "Current protocol(s): 0x%llx\n", IR_dprintk(1, "Current protocol(s): 0x%llx\n",
(long long)type); (long long)type);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment