aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/IR/ir-sysfs.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2009-12-13 14:00:08 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-02-26 13:10:23 -0500
commit4714eda87748f226833c32400ab60dd6a3b80766 (patch)
tree7bffe980fa51169f78c9ec35c09936d8dce73443 /drivers/media/IR/ir-sysfs.c
parent60b341b778cc2929df16c0a504c91621b3c6a4ad (diff)
V4L/DVB (13633): ir-core: create a new class for remote controllers
Add sysfs skeleton to export remote controller information via /sys/class/irrcv. For now, the code doesn't do much. It just exports an attribute that is meant to report and control the IR protocol used by the keytable. However, the callbacks for this new attribute weren't set yet. Also, it lacks symlinks to the used event interface. Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/IR/ir-sysfs.c')
-rw-r--r--drivers/media/IR/ir-sysfs.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c
new file mode 100644
index 000000000000..3c601421632b
--- /dev/null
+++ b/drivers/media/IR/ir-sysfs.c
@@ -0,0 +1,94 @@
1/* ir-register.c - handle IR scancode->keycode tables
2 *
3 * Copyright (C) 2009 by Mauro Carvalho Chehab <mchehab@redhat.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <linux/input.h>
16#include <linux/device.h>
17#include <media/ir-core.h>
18
19#define IRRCV_NUM_DEVICES 256
20
21unsigned long ir_core_dev_number;
22
23static struct class *ir_input_class;
24
25static DEVICE_ATTR(ir_protocol, S_IRUGO | S_IWUSR, NULL, NULL);
26
27static struct attribute *ir_dev_attrs[] = {
28 &dev_attr_ir_protocol.attr,
29};
30
31int ir_register_class(struct input_dev *input_dev)
32{
33 int rc;
34 struct kobject *kobj;
35
36 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
37 int devno = find_first_zero_bit(&ir_core_dev_number,
38 IRRCV_NUM_DEVICES);
39
40 if (unlikely(devno < 0))
41 return devno;
42
43 ir_dev->attr.attrs = ir_dev_attrs;
44 ir_dev->class_dev = device_create(ir_input_class, NULL,
45 input_dev->dev.devt, ir_dev,
46 "irrcv%d", devno);
47 kobj = &ir_dev->class_dev->kobj;
48
49 printk(KERN_WARNING "Creating IR device %s\n", kobject_name(kobj));
50 rc = sysfs_create_group(kobj, &ir_dev->attr);
51 if (unlikely(rc < 0)) {
52 device_destroy(ir_input_class, input_dev->dev.devt);
53 return -ENOMEM;
54 }
55
56 ir_dev->devno = devno;
57 set_bit(devno, &ir_core_dev_number);
58
59 return 0;
60};
61
62void ir_unregister_class(struct input_dev *input_dev)
63{
64 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
65 struct kobject *kobj;
66
67 clear_bit(ir_dev->devno, &ir_core_dev_number);
68
69 kobj = &ir_dev->class_dev->kobj;
70
71 sysfs_remove_group(kobj, &ir_dev->attr);
72 device_destroy(ir_input_class, input_dev->dev.devt);
73
74 kfree(ir_dev->attr.name);
75}
76
77static int __init ir_core_init(void)
78{
79 ir_input_class = class_create(THIS_MODULE, "irrcv");
80 if (IS_ERR(ir_input_class)) {
81 printk(KERN_ERR "ir_core: unable to register irrcv class\n");
82 return PTR_ERR(ir_input_class);
83 }
84
85 return 0;
86}
87
88static void __exit ir_core_exit(void)
89{
90 class_destroy(ir_input_class);
91}
92
93module_init(ir_core_init);
94module_exit(ir_core_exit);