aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/IR/ir-sony-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-sony-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-sony-decoder.c')
-rw-r--r--drivers/media/IR/ir-sony-decoder.c65
1 files changed, 3 insertions, 62 deletions
diff --git a/drivers/media/IR/ir-sony-decoder.c b/drivers/media/IR/ir-sony-decoder.c
index 219075ffd6b7..e15db3334998 100644
--- a/drivers/media/IR/ir-sony-decoder.c
+++ b/drivers/media/IR/ir-sony-decoder.c
@@ -38,7 +38,6 @@ enum sony_state {
38struct decoder_data { 38struct decoder_data {
39 struct list_head list; 39 struct list_head list;
40 struct ir_input_dev *ir_dev; 40 struct ir_input_dev *ir_dev;
41 int enabled:1;
42 41
43 /* State machine control */ 42 /* State machine control */
44 enum sony_state state; 43 enum sony_state state;
@@ -66,53 +65,6 @@ static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev)
66 return data; 65 return data;
67} 66}
68 67
69static ssize_t store_enabled(struct device *d,
70 struct device_attribute *mattr,
71 const char *buf,
72 size_t len)
73{
74 unsigned long value;
75 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
76 struct decoder_data *data = get_decoder_data(ir_dev);
77
78 if (!data)
79 return -EINVAL;
80
81 if (strict_strtoul(buf, 10, &value) || value > 1)
82 return -EINVAL;
83
84 data->enabled = value;
85
86 return len;
87}
88
89static ssize_t show_enabled(struct device *d,
90 struct device_attribute *mattr, char *buf)
91{
92 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
93 struct decoder_data *data = get_decoder_data(ir_dev);
94
95 if (!data)
96 return -EINVAL;
97
98 if (data->enabled)
99 return sprintf(buf, "1\n");
100 else
101 return sprintf(buf, "0\n");
102}
103
104static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled);
105
106static struct attribute *decoder_attributes[] = {
107 &dev_attr_enabled.attr,
108 NULL
109};
110
111static struct attribute_group decoder_attribute_group = {
112 .name = "sony_decoder",
113 .attrs = decoder_attributes,
114};
115
116/** 68/**
117 * ir_sony_decode() - Decode one Sony pulse or space 69 * ir_sony_decode() - Decode one Sony pulse or space
118 * @input_dev: the struct input_dev descriptor of the device 70 * @input_dev: the struct input_dev descriptor of the device
@@ -131,7 +83,7 @@ static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev)
131 if (!data) 83 if (!data)
132 return -EINVAL; 84 return -EINVAL;
133 85
134 if (!data->enabled) 86 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_SONY))
135 return 0; 87 return 0;
136 88
137 if (IS_RESET(ev)) { 89 if (IS_RESET(ev)) {
@@ -245,22 +197,12 @@ static int ir_sony_register(struct input_dev *input_dev)
245{ 197{
246 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 198 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
247 struct decoder_data *data; 199 struct decoder_data *data;
248 u64 ir_type = ir_dev->rc_tab.ir_type;
249 int rc;
250
251 rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group);
252 if (rc < 0)
253 return rc;
254 200
255 data = kzalloc(sizeof(*data), GFP_KERNEL); 201 data = kzalloc(sizeof(*data), GFP_KERNEL);
256 if (!data) { 202 if (!data)
257 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
258 return -ENOMEM; 203 return -ENOMEM;
259 }
260 204
261 data->ir_dev = ir_dev; 205 data->ir_dev = ir_dev;
262 if (ir_type == IR_TYPE_SONY || ir_type == IR_TYPE_UNKNOWN)
263 data->enabled = 1;
264 206
265 spin_lock(&decoder_lock); 207 spin_lock(&decoder_lock);
266 list_add_tail(&data->list, &decoder_list); 208 list_add_tail(&data->list, &decoder_list);
@@ -278,8 +220,6 @@ static int ir_sony_unregister(struct input_dev *input_dev)
278 if (!data) 220 if (!data)
279 return 0; 221 return 0;
280 222
281 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
282
283 spin_lock(&decoder_lock); 223 spin_lock(&decoder_lock);
284 list_del(&data->list); 224 list_del(&data->list);
285 spin_unlock(&decoder_lock); 225 spin_unlock(&decoder_lock);
@@ -288,6 +228,7 @@ static int ir_sony_unregister(struct input_dev *input_dev)
288} 228}
289 229
290static struct ir_raw_handler sony_handler = { 230static struct ir_raw_handler sony_handler = {
231 .protocols = IR_TYPE_SONY,
291 .decode = ir_sony_decode, 232 .decode = ir_sony_decode,
292 .raw_register = ir_sony_register, 233 .raw_register = ir_sony_register,
293 .raw_unregister = ir_sony_unregister, 234 .raw_unregister = ir_sony_unregister,