aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/IR/ir-rc5-decoder.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2010-06-13 16:29:31 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-08-02 13:54:27 -0400
commit667c9ebe97f7e5f1e48e7eb321644c6fb1668de5 (patch)
tree11dae4e3d480960fe697964776222b16ee0ecce8 /drivers/media/IR/ir-rc5-decoder.c
parent0dc50942d6f23989ffb3024aa2271941ec44aea8 (diff)
V4L/DVB: ir-core: centralize sysfs raw decoder enabling/disabling
With the current logic, each raw decoder needs to add a copy of the exact same sysfs code. This is both unnecessary and also means that (re)loading an IR driver after raw decoder modules have been loaded won't work as expected. This patch moves that logic into ir-raw-event and adds a single sysfs file per device. Reading that file returns something like: "rc5 [rc6] nec jvc [sony]" (with enabled protocols in [] brackets) Writing either "+protocol" or "-protocol" to that file will enable or disable the according protocol decoder. An additional benefit is that the disabling of a decoder will be remembered across module removal/insertion so a previously disabled decoder won't suddenly be activated again. The default setting is to enable all decoders. This is also necessary for the next patch which moves even more decoder state into the central raw decoding structs. Signed-off-by: David Härdeman <david@hardeman.nu> Acked-by: Jarod Wilson <jarod@redhat.com> Tested-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/IR/ir-rc5-decoder.c')
-rw-r--r--drivers/media/IR/ir-rc5-decoder.c67
1 files changed, 4 insertions, 63 deletions
diff --git a/drivers/media/IR/ir-rc5-decoder.c b/drivers/media/IR/ir-rc5-decoder.c
index 4aa797bc69fd..bdfa404a6537 100644
--- a/drivers/media/IR/ir-rc5-decoder.c
+++ b/drivers/media/IR/ir-rc5-decoder.c
@@ -45,7 +45,6 @@ enum rc5_state {
45struct decoder_data { 45struct decoder_data {
46 struct list_head list; 46 struct list_head list;
47 struct ir_input_dev *ir_dev; 47 struct ir_input_dev *ir_dev;
48 int enabled:1;
49 48
50 /* State machine control */ 49 /* State machine control */
51 enum rc5_state state; 50 enum rc5_state state;
@@ -76,53 +75,6 @@ static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev)
76 return data; 75 return data;
77} 76}
78 77
79static ssize_t store_enabled(struct device *d,
80 struct device_attribute *mattr,
81 const char *buf,
82 size_t len)
83{
84 unsigned long value;
85 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
86 struct decoder_data *data = get_decoder_data(ir_dev);
87
88 if (!data)
89 return -EINVAL;
90
91 if (strict_strtoul(buf, 10, &value) || value > 1)
92 return -EINVAL;
93
94 data->enabled = value;
95
96 return len;
97}
98
99static ssize_t show_enabled(struct device *d,
100 struct device_attribute *mattr, char *buf)
101{
102 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
103 struct decoder_data *data = get_decoder_data(ir_dev);
104
105 if (!data)
106 return -EINVAL;
107
108 if (data->enabled)
109 return sprintf(buf, "1\n");
110 else
111 return sprintf(buf, "0\n");
112}
113
114static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled);
115
116static struct attribute *decoder_attributes[] = {
117 &dev_attr_enabled.attr,
118 NULL
119};
120
121static struct attribute_group decoder_attribute_group = {
122 .name = "rc5_decoder",
123 .attrs = decoder_attributes,
124};
125
126/** 78/**
127 * ir_rc5_decode() - Decode one RC-5 pulse or space 79 * ir_rc5_decode() - Decode one RC-5 pulse or space
128 * @input_dev: the struct input_dev descriptor of the device 80 * @input_dev: the struct input_dev descriptor of the device
@@ -141,8 +93,8 @@ static int ir_rc5_decode(struct input_dev *input_dev, struct ir_raw_event ev)
141 if (!data) 93 if (!data)
142 return -EINVAL; 94 return -EINVAL;
143 95
144 if (!data->enabled) 96 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC5))
145 return 0; 97 return 0;
146 98
147 if (IS_RESET(ev)) { 99 if (IS_RESET(ev)) {
148 data->state = STATE_INACTIVE; 100 data->state = STATE_INACTIVE;
@@ -256,22 +208,12 @@ static int ir_rc5_register(struct input_dev *input_dev)
256{ 208{
257 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 209 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
258 struct decoder_data *data; 210 struct decoder_data *data;
259 u64 ir_type = ir_dev->rc_tab.ir_type;
260 int rc;
261
262 rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group);
263 if (rc < 0)
264 return rc;
265 211
266 data = kzalloc(sizeof(*data), GFP_KERNEL); 212 data = kzalloc(sizeof(*data), GFP_KERNEL);
267 if (!data) { 213 if (!data)
268 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
269 return -ENOMEM; 214 return -ENOMEM;
270 }
271 215
272 data->ir_dev = ir_dev; 216 data->ir_dev = ir_dev;
273 if (ir_type == IR_TYPE_RC5 || ir_type == IR_TYPE_UNKNOWN)
274 data->enabled = 1;
275 217
276 spin_lock(&decoder_lock); 218 spin_lock(&decoder_lock);
277 list_add_tail(&data->list, &decoder_list); 219 list_add_tail(&data->list, &decoder_list);
@@ -289,8 +231,6 @@ static int ir_rc5_unregister(struct input_dev *input_dev)
289 if (!data) 231 if (!data)
290 return 0; 232 return 0;
291 233
292 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
293
294 spin_lock(&decoder_lock); 234 spin_lock(&decoder_lock);
295 list_del(&data->list); 235 list_del(&data->list);
296 spin_unlock(&decoder_lock); 236 spin_unlock(&decoder_lock);
@@ -299,6 +239,7 @@ static int ir_rc5_unregister(struct input_dev *input_dev)
299} 239}
300 240
301static struct ir_raw_handler rc5_handler = { 241static struct ir_raw_handler rc5_handler = {
242 .protocols = IR_TYPE_RC5,
302 .decode = ir_rc5_decode, 243 .decode = ir_rc5_decode,
303 .raw_register = ir_rc5_register, 244 .raw_register = ir_rc5_register,
304 .raw_unregister = ir_rc5_unregister, 245 .raw_unregister = ir_rc5_unregister,