aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/IR/ir-nec-decoder.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/IR/ir-nec-decoder.c')
-rw-r--r--drivers/media/IR/ir-nec-decoder.c65
1 files changed, 3 insertions, 62 deletions
diff --git a/drivers/media/IR/ir-nec-decoder.c b/drivers/media/IR/ir-nec-decoder.c
index 6059a1f1e151..db62c652dfc5 100644
--- a/drivers/media/IR/ir-nec-decoder.c
+++ b/drivers/media/IR/ir-nec-decoder.c
@@ -43,7 +43,6 @@ enum nec_state {
43struct decoder_data { 43struct decoder_data {
44 struct list_head list; 44 struct list_head list;
45 struct ir_input_dev *ir_dev; 45 struct ir_input_dev *ir_dev;
46 int enabled:1;
47 46
48 /* State machine control */ 47 /* State machine control */
49 enum nec_state state; 48 enum nec_state state;
@@ -71,53 +70,6 @@ static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev)
71 return data; 70 return data;
72} 71}
73 72
74static ssize_t store_enabled(struct device *d,
75 struct device_attribute *mattr,
76 const char *buf,
77 size_t len)
78{
79 unsigned long value;
80 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
81 struct decoder_data *data = get_decoder_data(ir_dev);
82
83 if (!data)
84 return -EINVAL;
85
86 if (strict_strtoul(buf, 10, &value) || value > 1)
87 return -EINVAL;
88
89 data->enabled = value;
90
91 return len;
92}
93
94static ssize_t show_enabled(struct device *d,
95 struct device_attribute *mattr, char *buf)
96{
97 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
98 struct decoder_data *data = get_decoder_data(ir_dev);
99
100 if (!data)
101 return -EINVAL;
102
103 if (data->enabled)
104 return sprintf(buf, "1\n");
105 else
106 return sprintf(buf, "0\n");
107}
108
109static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled);
110
111static struct attribute *decoder_attributes[] = {
112 &dev_attr_enabled.attr,
113 NULL
114};
115
116static struct attribute_group decoder_attribute_group = {
117 .name = "nec_decoder",
118 .attrs = decoder_attributes,
119};
120
121/** 73/**
122 * ir_nec_decode() - Decode one NEC pulse or space 74 * ir_nec_decode() - Decode one NEC pulse or space
123 * @input_dev: the struct input_dev descriptor of the device 75 * @input_dev: the struct input_dev descriptor of the device
@@ -136,7 +88,7 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev)
136 if (!data) 88 if (!data)
137 return -EINVAL; 89 return -EINVAL;
138 90
139 if (!data->enabled) 91 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_NEC))
140 return 0; 92 return 0;
141 93
142 if (IS_RESET(ev)) { 94 if (IS_RESET(ev)) {
@@ -260,22 +212,12 @@ static int ir_nec_register(struct input_dev *input_dev)
260{ 212{
261 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 213 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
262 struct decoder_data *data; 214 struct decoder_data *data;
263 u64 ir_type = ir_dev->rc_tab.ir_type;
264 int rc;
265
266 rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group);
267 if (rc < 0)
268 return rc;
269 215
270 data = kzalloc(sizeof(*data), GFP_KERNEL); 216 data = kzalloc(sizeof(*data), GFP_KERNEL);
271 if (!data) { 217 if (!data)
272 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
273 return -ENOMEM; 218 return -ENOMEM;
274 }
275 219
276 data->ir_dev = ir_dev; 220 data->ir_dev = ir_dev;
277 if (ir_type == IR_TYPE_NEC || ir_type == IR_TYPE_UNKNOWN)
278 data->enabled = 1;
279 221
280 spin_lock(&decoder_lock); 222 spin_lock(&decoder_lock);
281 list_add_tail(&data->list, &decoder_list); 223 list_add_tail(&data->list, &decoder_list);
@@ -293,8 +235,6 @@ static int ir_nec_unregister(struct input_dev *input_dev)
293 if (!data) 235 if (!data)
294 return 0; 236 return 0;
295 237
296 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
297
298 spin_lock(&decoder_lock); 238 spin_lock(&decoder_lock);
299 list_del(&data->list); 239 list_del(&data->list);
300 spin_unlock(&decoder_lock); 240 spin_unlock(&decoder_lock);
@@ -303,6 +243,7 @@ static int ir_nec_unregister(struct input_dev *input_dev)
303} 243}
304 244
305static struct ir_raw_handler nec_handler = { 245static struct ir_raw_handler nec_handler = {
246 .protocols = IR_TYPE_NEC,
306 .decode = ir_nec_decode, 247 .decode = ir_nec_decode,
307 .raw_register = ir_nec_register, 248 .raw_register = ir_nec_register,
308 .raw_unregister = ir_nec_unregister, 249 .raw_unregister = ir_nec_unregister,