aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/IR
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2010-06-28 12:52:07 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-08-02 13:55:05 -0400
commitde8592bd539b2bb8da2b55b1007562eb1abd1fe6 (patch)
tree30b88b3338558a06af737094fdf0028d7fe21d10 /drivers/media/IR
parent5f1247972e0fcce6dd4bce94459a9f3db09ae61d (diff)
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: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/IR')
-rw-r--r--drivers/media/IR/ir-sysfs.c92
1 files changed, 46 insertions, 46 deletions
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c
index e84f9783b8c2..f176fbff9488 100644
--- a/drivers/media/IR/ir-sysfs.c
+++ b/drivers/media/IR/ir-sysfs.c
@@ -117,62 +117,63 @@ static ssize_t store_protocols(struct device *d,
117 const char *tmp; 117 const char *tmp;
118 u64 type; 118 u64 type;
119 u64 mask; 119 u64 mask;
120 int rc, i; 120 int rc, i, count = 0;
121 unsigned long flags; 121 unsigned long flags;
122 122
123 tmp = skip_spaces(data); 123 if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE)
124 if (*tmp == '\0') { 124 type = ir_dev->rc_tab.ir_type;
125 IR_dprintk(1, "Protocol not specified\n"); 125 else
126 return -EINVAL; 126 type = ir_dev->raw->enabled_protocols;
127 } else if (*tmp == '+') {
128 enable = true;
129 disable = false;
130 tmp++;
131 } else if (*tmp == '-') {
132 enable = false;
133 disable = true;
134 tmp++;
135 } else {
136 enable = false;
137 disable = false;
138 }
139 127
128 while ((tmp = strsep((char **) &data, " \n")) != NULL) {
129 if (!*tmp)
130 break;
131
132 if (*tmp == '+') {
133 enable = true;
134 disable = false;
135 tmp++;
136 } else if (*tmp == '-') {
137 enable = false;
138 disable = true;
139 tmp++;
140 } else {
141 enable = false;
142 disable = false;
143 }
140 144
141 if (!enable && !disable && !strncasecmp(tmp, PROTO_NONE, sizeof(PROTO_NONE))) { 145 if (!enable && !disable && !strncasecmp(tmp, PROTO_NONE, sizeof(PROTO_NONE))) {
142 mask = 0; 146 tmp += sizeof(PROTO_NONE);
143 tmp += sizeof(PROTO_NONE); 147 mask = 0;
144 } else { 148 count++;
145 for (i = 0; i < ARRAY_SIZE(proto_names); i++) { 149 } else {
146 if (!strncasecmp(tmp, proto_names[i].name, strlen(proto_names[i].name))) { 150 for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
147 tmp += strlen(proto_names[i].name); 151 if (!strncasecmp(tmp, proto_names[i].name, strlen(proto_names[i].name))) {
148 mask = proto_names[i].type; 152 tmp += strlen(proto_names[i].name);
149 break; 153 mask = proto_names[i].type;
154 break;
155 }
150 } 156 }
157 if (i == ARRAY_SIZE(proto_names)) {
158 IR_dprintk(1, "Unknown protocol: '%s'\n", tmp);
159 return -EINVAL;
160 }
161 count++;
151 } 162 }
152 if (i == ARRAY_SIZE(proto_names)) { 163
153 IR_dprintk(1, "Unknown protocol\n"); 164 if (enable)
154 return -EINVAL; 165 type |= mask;
155 } 166 else if (disable)
167 type &= ~mask;
168 else
169 type = mask;
156 } 170 }
157 171
158 tmp = skip_spaces(tmp); 172 if (!count) {
159 if (*tmp != '\0') { 173 IR_dprintk(1, "Protocol not specified\n");
160 IR_dprintk(1, "Invalid trailing characters\n");
161 return -EINVAL; 174 return -EINVAL;
162 } 175 }
163 176
164 if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE)
165 type = ir_dev->rc_tab.ir_type;
166 else
167 type = ir_dev->raw->enabled_protocols;
168
169 if (enable)
170 type |= mask;
171 else if (disable)
172 type &= ~mask;
173 else
174 type = mask;
175
176 if (ir_dev->props && ir_dev->props->change_protocol) { 177 if (ir_dev->props && ir_dev->props->change_protocol) {
177 rc = ir_dev->props->change_protocol(ir_dev->props->priv, 178 rc = ir_dev->props->change_protocol(ir_dev->props->priv,
178 type); 179 type);
@@ -191,7 +192,6 @@ static ssize_t store_protocols(struct device *d,
191 ir_dev->raw->enabled_protocols = type; 192 ir_dev->raw->enabled_protocols = type;
192 } 193 }
193 194
194
195 IR_dprintk(1, "Current protocol(s): 0x%llx\n", 195 IR_dprintk(1, "Current protocol(s): 0x%llx\n",
196 (long long)type); 196 (long long)type);
197 197