David Härdeman | dd3f616 | 2010-04-15 18:46:35 -0300 | [diff] [blame] | 1 | /* ir-sysfs.c - sysfs interface for RC devices (/sys/class/rc) |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 2 | * |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 3 | * Copyright (C) 2009-2010 by Mauro Carvalho Chehab <mchehab@redhat.com> |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 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 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 16 | #include <linux/input.h> |
| 17 | #include <linux/device.h> |
Mauro Carvalho Chehab | 3f113e3 | 2010-04-08 15:10:27 -0300 | [diff] [blame] | 18 | #include "ir-core-priv.h" |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 19 | |
| 20 | #define IRRCV_NUM_DEVICES 256 |
| 21 | |
Mauro Carvalho Chehab | d4b778d | 2009-12-14 02:55:03 -0300 | [diff] [blame] | 22 | /* bit array to represent IR sysfs device number */ |
| 23 | static unsigned long ir_core_dev_number; |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 24 | |
Mauro Carvalho Chehab | e202c15 | 2010-03-26 22:45:16 -0300 | [diff] [blame] | 25 | /* class for /sys/class/rc */ |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 26 | static char *ir_devnode(struct device *dev, mode_t *mode) |
| 27 | { |
Mauro Carvalho Chehab | e202c15 | 2010-03-26 22:45:16 -0300 | [diff] [blame] | 28 | return kasprintf(GFP_KERNEL, "rc/%s", dev_name(dev)); |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 29 | } |
| 30 | |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 31 | static struct class ir_input_class = { |
Mauro Carvalho Chehab | e202c15 | 2010-03-26 22:45:16 -0300 | [diff] [blame] | 32 | .name = "rc", |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 33 | .devnode = ir_devnode, |
| 34 | }; |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 35 | |
Mauro Carvalho Chehab | d4b778d | 2009-12-14 02:55:03 -0300 | [diff] [blame] | 36 | /** |
| 37 | * show_protocol() - shows the current IR protocol |
| 38 | * @d: the device descriptor |
| 39 | * @mattr: the device attribute struct (unused) |
| 40 | * @buf: a pointer to the output buffer |
| 41 | * |
| 42 | * This routine is a callback routine for input read the IR protocol type. |
David Härdeman | de88f31 | 2010-03-28 18:38:49 -0300 | [diff] [blame] | 43 | * it is trigged by reading /sys/class/rc/rc?/current_protocol. |
Mauro Carvalho Chehab | d4b778d | 2009-12-14 02:55:03 -0300 | [diff] [blame] | 44 | * It returns the protocol name, as understood by the driver. |
| 45 | */ |
Mauro Carvalho Chehab | 53f8702 | 2009-12-14 02:16:36 -0300 | [diff] [blame] | 46 | static ssize_t show_protocol(struct device *d, |
| 47 | struct device_attribute *mattr, char *buf) |
| 48 | { |
| 49 | char *s; |
| 50 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); |
Mauro Carvalho Chehab | 971e829 | 2009-12-14 13:53:37 -0300 | [diff] [blame] | 51 | u64 ir_type = ir_dev->rc_tab.ir_type; |
Mauro Carvalho Chehab | 53f8702 | 2009-12-14 02:16:36 -0300 | [diff] [blame] | 52 | |
Mauro Carvalho Chehab | 971e829 | 2009-12-14 13:53:37 -0300 | [diff] [blame] | 53 | IR_dprintk(1, "Current protocol is %lld\n", (long long)ir_type); |
Mauro Carvalho Chehab | 53f8702 | 2009-12-14 02:16:36 -0300 | [diff] [blame] | 54 | |
| 55 | /* FIXME: doesn't support multiple protocols at the same time */ |
| 56 | if (ir_type == IR_TYPE_UNKNOWN) |
| 57 | s = "Unknown"; |
| 58 | else if (ir_type == IR_TYPE_RC5) |
Mauro Carvalho Chehab | b320f80 | 2010-04-08 01:02:49 -0300 | [diff] [blame] | 59 | s = "rc-5"; |
Mauro Carvalho Chehab | 53f8702 | 2009-12-14 02:16:36 -0300 | [diff] [blame] | 60 | else if (ir_type == IR_TYPE_NEC) |
Mauro Carvalho Chehab | b320f80 | 2010-04-08 01:02:49 -0300 | [diff] [blame] | 61 | s = "nec"; |
David Härdeman | 784a493 | 2010-04-08 20:04:40 -0300 | [diff] [blame] | 62 | else if (ir_type == IR_TYPE_RC6) |
| 63 | s = "rc6"; |
David Härdeman | bf670f6 | 2010-04-15 18:46:05 -0300 | [diff] [blame] | 64 | else if (ir_type == IR_TYPE_JVC) |
| 65 | s = "jvc"; |
David Härdeman | 3fe29c8 | 2010-04-15 18:46:10 -0300 | [diff] [blame] | 66 | else if (ir_type == IR_TYPE_SONY) |
| 67 | s = "sony"; |
Mauro Carvalho Chehab | 53f8702 | 2009-12-14 02:16:36 -0300 | [diff] [blame] | 68 | else |
Mauro Carvalho Chehab | b320f80 | 2010-04-08 01:02:49 -0300 | [diff] [blame] | 69 | s = "other"; |
Mauro Carvalho Chehab | 53f8702 | 2009-12-14 02:16:36 -0300 | [diff] [blame] | 70 | |
| 71 | return sprintf(buf, "%s\n", s); |
| 72 | } |
| 73 | |
Mauro Carvalho Chehab | d4b778d | 2009-12-14 02:55:03 -0300 | [diff] [blame] | 74 | /** |
| 75 | * store_protocol() - shows the current IR protocol |
| 76 | * @d: the device descriptor |
| 77 | * @mattr: the device attribute struct (unused) |
| 78 | * @buf: a pointer to the input buffer |
| 79 | * @len: length of the input buffer |
| 80 | * |
| 81 | * This routine is a callback routine for changing the IR protocol type. |
David Härdeman | de88f31 | 2010-03-28 18:38:49 -0300 | [diff] [blame] | 82 | * it is trigged by reading /sys/class/rc/rc?/current_protocol. |
Mauro Carvalho Chehab | d4b778d | 2009-12-14 02:55:03 -0300 | [diff] [blame] | 83 | * It changes the IR the protocol name, if the IR type is recognized |
| 84 | * by the driver. |
| 85 | * If an unknown protocol name is used, returns -EINVAL. |
| 86 | */ |
Mauro Carvalho Chehab | 09b01b9 | 2009-12-14 02:46:42 -0300 | [diff] [blame] | 87 | static ssize_t store_protocol(struct device *d, |
| 88 | struct device_attribute *mattr, |
| 89 | const char *data, |
| 90 | size_t len) |
| 91 | { |
| 92 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); |
Mauro Carvalho Chehab | b320f80 | 2010-04-08 01:02:49 -0300 | [diff] [blame] | 93 | u64 ir_type = 0; |
Mauro Carvalho Chehab | 09b01b9 | 2009-12-14 02:46:42 -0300 | [diff] [blame] | 94 | int rc = -EINVAL; |
Mauro Carvalho Chehab | eecee32 | 2009-12-14 02:56:15 -0300 | [diff] [blame] | 95 | unsigned long flags; |
Mauro Carvalho Chehab | 09b01b9 | 2009-12-14 02:46:42 -0300 | [diff] [blame] | 96 | char *buf; |
| 97 | |
Mauro Carvalho Chehab | d22e546 | 2010-04-08 09:33:45 -0300 | [diff] [blame] | 98 | while ((buf = strsep((char **) &data, " \n")) != NULL) { |
Mauro Carvalho Chehab | b320f80 | 2010-04-08 01:02:49 -0300 | [diff] [blame] | 99 | if (!strcasecmp(buf, "rc-5") || !strcasecmp(buf, "rc5")) |
| 100 | ir_type |= IR_TYPE_RC5; |
Mauro Carvalho Chehab | b320f80 | 2010-04-08 01:02:49 -0300 | [diff] [blame] | 101 | if (!strcasecmp(buf, "nec")) |
| 102 | ir_type |= IR_TYPE_NEC; |
David Härdeman | bf670f6 | 2010-04-15 18:46:05 -0300 | [diff] [blame] | 103 | if (!strcasecmp(buf, "jvc")) |
| 104 | ir_type |= IR_TYPE_JVC; |
David Härdeman | 3fe29c8 | 2010-04-15 18:46:10 -0300 | [diff] [blame] | 105 | if (!strcasecmp(buf, "sony")) |
| 106 | ir_type |= IR_TYPE_SONY; |
Mauro Carvalho Chehab | b320f80 | 2010-04-08 01:02:49 -0300 | [diff] [blame] | 107 | } |
Mauro Carvalho Chehab | 09b01b9 | 2009-12-14 02:46:42 -0300 | [diff] [blame] | 108 | |
Mauro Carvalho Chehab | b320f80 | 2010-04-08 01:02:49 -0300 | [diff] [blame] | 109 | if (!ir_type) { |
| 110 | IR_dprintk(1, "Unknown protocol\n"); |
Mauro Carvalho Chehab | 09b01b9 | 2009-12-14 02:46:42 -0300 | [diff] [blame] | 111 | return -EINVAL; |
| 112 | } |
| 113 | |
Mauro Carvalho Chehab | 0f7ff39 | 2009-12-16 23:46:48 -0300 | [diff] [blame] | 114 | if (ir_dev->props && ir_dev->props->change_protocol) |
Mauro Carvalho Chehab | 09b01b9 | 2009-12-14 02:46:42 -0300 | [diff] [blame] | 115 | rc = ir_dev->props->change_protocol(ir_dev->props->priv, |
| 116 | ir_type); |
| 117 | |
| 118 | if (rc < 0) { |
Mauro Carvalho Chehab | 971e829 | 2009-12-14 13:53:37 -0300 | [diff] [blame] | 119 | IR_dprintk(1, "Error setting protocol to %lld\n", |
| 120 | (long long)ir_type); |
Mauro Carvalho Chehab | 09b01b9 | 2009-12-14 02:46:42 -0300 | [diff] [blame] | 121 | return -EINVAL; |
| 122 | } |
| 123 | |
Mauro Carvalho Chehab | eecee32 | 2009-12-14 02:56:15 -0300 | [diff] [blame] | 124 | spin_lock_irqsave(&ir_dev->rc_tab.lock, flags); |
Mauro Carvalho Chehab | 09b01b9 | 2009-12-14 02:46:42 -0300 | [diff] [blame] | 125 | ir_dev->rc_tab.ir_type = ir_type; |
Mauro Carvalho Chehab | eecee32 | 2009-12-14 02:56:15 -0300 | [diff] [blame] | 126 | spin_unlock_irqrestore(&ir_dev->rc_tab.lock, flags); |
Mauro Carvalho Chehab | 09b01b9 | 2009-12-14 02:46:42 -0300 | [diff] [blame] | 127 | |
Mauro Carvalho Chehab | b320f80 | 2010-04-08 01:02:49 -0300 | [diff] [blame] | 128 | IR_dprintk(1, "Current protocol(s) is(are) %lld\n", |
Mauro Carvalho Chehab | 971e829 | 2009-12-14 13:53:37 -0300 | [diff] [blame] | 129 | (long long)ir_type); |
Mauro Carvalho Chehab | 09b01b9 | 2009-12-14 02:46:42 -0300 | [diff] [blame] | 130 | |
| 131 | return len; |
| 132 | } |
| 133 | |
Mauro Carvalho Chehab | b320f80 | 2010-04-08 01:02:49 -0300 | [diff] [blame] | 134 | static ssize_t show_supported_protocols(struct device *d, |
| 135 | struct device_attribute *mattr, char *buf) |
| 136 | { |
| 137 | char *orgbuf = buf; |
| 138 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); |
| 139 | |
| 140 | /* FIXME: doesn't support multiple protocols at the same time */ |
| 141 | if (ir_dev->props->allowed_protos == IR_TYPE_UNKNOWN) |
| 142 | buf += sprintf(buf, "unknown "); |
| 143 | if (ir_dev->props->allowed_protos & IR_TYPE_RC5) |
| 144 | buf += sprintf(buf, "rc-5 "); |
Mauro Carvalho Chehab | b320f80 | 2010-04-08 01:02:49 -0300 | [diff] [blame] | 145 | if (ir_dev->props->allowed_protos & IR_TYPE_NEC) |
| 146 | buf += sprintf(buf, "nec "); |
| 147 | if (buf == orgbuf) |
| 148 | buf += sprintf(buf, "other "); |
| 149 | |
| 150 | buf += sprintf(buf - 1, "\n"); |
| 151 | |
| 152 | return buf - orgbuf; |
| 153 | } |
Mauro Carvalho Chehab | 9c89a18 | 2010-03-12 11:50:17 -0300 | [diff] [blame] | 154 | |
| 155 | #define ADD_HOTPLUG_VAR(fmt, val...) \ |
| 156 | do { \ |
| 157 | int err = add_uevent_var(env, fmt, val); \ |
| 158 | if (err) \ |
| 159 | return err; \ |
| 160 | } while (0) |
| 161 | |
| 162 | static int ir_dev_uevent(struct device *device, struct kobj_uevent_env *env) |
| 163 | { |
| 164 | struct ir_input_dev *ir_dev = dev_get_drvdata(device); |
| 165 | |
| 166 | if (ir_dev->rc_tab.name) |
Mauro Carvalho Chehab | 3efaa06 | 2010-04-10 23:43:39 -0300 | [diff] [blame] | 167 | ADD_HOTPLUG_VAR("NAME=%s", ir_dev->rc_tab.name); |
Mauro Carvalho Chehab | 727e625 | 2010-03-12 21:18:14 -0300 | [diff] [blame] | 168 | if (ir_dev->driver_name) |
Mauro Carvalho Chehab | 3efaa06 | 2010-04-10 23:43:39 -0300 | [diff] [blame] | 169 | ADD_HOTPLUG_VAR("DRV_NAME=%s", ir_dev->driver_name); |
Mauro Carvalho Chehab | 9c89a18 | 2010-03-12 11:50:17 -0300 | [diff] [blame] | 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
Mauro Carvalho Chehab | d4b778d | 2009-12-14 02:55:03 -0300 | [diff] [blame] | 174 | /* |
| 175 | * Static device attribute struct with the sysfs attributes for IR's |
| 176 | */ |
Mauro Carvalho Chehab | b320f80 | 2010-04-08 01:02:49 -0300 | [diff] [blame] | 177 | static DEVICE_ATTR(protocol, S_IRUGO | S_IWUSR, |
Mauro Carvalho Chehab | 09b01b9 | 2009-12-14 02:46:42 -0300 | [diff] [blame] | 178 | show_protocol, store_protocol); |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 179 | |
Mauro Carvalho Chehab | b320f80 | 2010-04-08 01:02:49 -0300 | [diff] [blame] | 180 | static DEVICE_ATTR(supported_protocols, S_IRUGO | S_IWUSR, |
| 181 | show_supported_protocols, NULL); |
| 182 | |
Mauro Carvalho Chehab | 626cf69 | 2010-04-06 23:21:46 -0300 | [diff] [blame] | 183 | static struct attribute *ir_hw_dev_attrs[] = { |
Mauro Carvalho Chehab | b320f80 | 2010-04-08 01:02:49 -0300 | [diff] [blame] | 184 | &dev_attr_protocol.attr, |
| 185 | &dev_attr_supported_protocols.attr, |
Francesco Lavra | 9714d58 | 2009-12-29 15:48:04 -0300 | [diff] [blame] | 186 | NULL, |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 187 | }; |
| 188 | |
Mauro Carvalho Chehab | 626cf69 | 2010-04-06 23:21:46 -0300 | [diff] [blame] | 189 | static struct attribute_group ir_hw_dev_attr_grp = { |
| 190 | .attrs = ir_hw_dev_attrs, |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 191 | }; |
| 192 | |
Mauro Carvalho Chehab | 626cf69 | 2010-04-06 23:21:46 -0300 | [diff] [blame] | 193 | static const struct attribute_group *ir_hw_dev_attr_groups[] = { |
| 194 | &ir_hw_dev_attr_grp, |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 195 | NULL |
| 196 | }; |
| 197 | |
Mauro Carvalho Chehab | 626cf69 | 2010-04-06 23:21:46 -0300 | [diff] [blame] | 198 | static struct device_type rc_dev_type = { |
| 199 | .groups = ir_hw_dev_attr_groups, |
| 200 | .uevent = ir_dev_uevent, |
| 201 | }; |
| 202 | |
| 203 | static struct device_type ir_raw_dev_type = { |
Mauro Carvalho Chehab | 9c89a18 | 2010-03-12 11:50:17 -0300 | [diff] [blame] | 204 | .uevent = ir_dev_uevent, |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 205 | }; |
| 206 | |
Mauro Carvalho Chehab | d4b778d | 2009-12-14 02:55:03 -0300 | [diff] [blame] | 207 | /** |
David Härdeman | de88f31 | 2010-03-28 18:38:49 -0300 | [diff] [blame] | 208 | * ir_register_class() - creates the sysfs for /sys/class/rc/rc? |
Mauro Carvalho Chehab | d4b778d | 2009-12-14 02:55:03 -0300 | [diff] [blame] | 209 | * @input_dev: the struct input_dev descriptor of the device |
| 210 | * |
| 211 | * This routine is used to register the syfs code for IR class |
| 212 | */ |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 213 | int ir_register_class(struct input_dev *input_dev) |
| 214 | { |
| 215 | int rc; |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 216 | const char *path; |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 217 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); |
| 218 | int devno = find_first_zero_bit(&ir_core_dev_number, |
| 219 | IRRCV_NUM_DEVICES); |
| 220 | |
| 221 | if (unlikely(devno < 0)) |
| 222 | return devno; |
| 223 | |
Igor M. Liplianin | 84b14f1 | 2010-05-26 23:31:21 -0300 | [diff] [blame] | 224 | if (ir_dev->props) { |
| 225 | if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE) |
| 226 | ir_dev->dev.type = &rc_dev_type; |
| 227 | } else |
Mauro Carvalho Chehab | 626cf69 | 2010-04-06 23:21:46 -0300 | [diff] [blame] | 228 | ir_dev->dev.type = &ir_raw_dev_type; |
| 229 | |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 230 | ir_dev->dev.class = &ir_input_class; |
| 231 | ir_dev->dev.parent = input_dev->dev.parent; |
David Härdeman | de88f31 | 2010-03-28 18:38:49 -0300 | [diff] [blame] | 232 | dev_set_name(&ir_dev->dev, "rc%d", devno); |
Mauro Carvalho Chehab | 9c89a18 | 2010-03-12 11:50:17 -0300 | [diff] [blame] | 233 | dev_set_drvdata(&ir_dev->dev, ir_dev); |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 234 | rc = device_register(&ir_dev->dev); |
| 235 | if (rc) |
| 236 | return rc; |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 237 | |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 238 | |
| 239 | input_dev->dev.parent = &ir_dev->dev; |
| 240 | rc = input_register_device(input_dev); |
| 241 | if (rc < 0) { |
| 242 | device_del(&ir_dev->dev); |
| 243 | return rc; |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 244 | } |
| 245 | |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 246 | __module_get(THIS_MODULE); |
| 247 | |
Mauro Carvalho Chehab | 9c89a18 | 2010-03-12 11:50:17 -0300 | [diff] [blame] | 248 | path = kobject_get_path(&ir_dev->dev.kobj, GFP_KERNEL); |
| 249 | printk(KERN_INFO "%s: %s as %s\n", |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 250 | dev_name(&ir_dev->dev), |
| 251 | input_dev->name ? input_dev->name : "Unspecified device", |
| 252 | path ? path : "N/A"); |
| 253 | kfree(path); |
| 254 | |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 255 | ir_dev->devno = devno; |
| 256 | set_bit(devno, &ir_core_dev_number); |
| 257 | |
| 258 | return 0; |
| 259 | }; |
| 260 | |
Mauro Carvalho Chehab | d4b778d | 2009-12-14 02:55:03 -0300 | [diff] [blame] | 261 | /** |
| 262 | * ir_unregister_class() - removes the sysfs for sysfs for |
David Härdeman | de88f31 | 2010-03-28 18:38:49 -0300 | [diff] [blame] | 263 | * /sys/class/rc/rc? |
Mauro Carvalho Chehab | d4b778d | 2009-12-14 02:55:03 -0300 | [diff] [blame] | 264 | * @input_dev: the struct input_dev descriptor of the device |
| 265 | * |
| 266 | * This routine is used to unregister the syfs code for IR class |
| 267 | */ |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 268 | void ir_unregister_class(struct input_dev *input_dev) |
| 269 | { |
| 270 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 271 | |
| 272 | clear_bit(ir_dev->devno, &ir_core_dev_number); |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 273 | input_unregister_device(input_dev); |
| 274 | device_del(&ir_dev->dev); |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 275 | |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 276 | module_put(THIS_MODULE); |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 277 | } |
| 278 | |
Mauro Carvalho Chehab | d4b778d | 2009-12-14 02:55:03 -0300 | [diff] [blame] | 279 | /* |
Mauro Carvalho Chehab | e202c15 | 2010-03-26 22:45:16 -0300 | [diff] [blame] | 280 | * Init/exit code for the module. Basically, creates/removes /sys/class/rc |
Mauro Carvalho Chehab | d4b778d | 2009-12-14 02:55:03 -0300 | [diff] [blame] | 281 | */ |
| 282 | |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 283 | static int __init ir_core_init(void) |
| 284 | { |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 285 | int rc = class_register(&ir_input_class); |
| 286 | if (rc) { |
Mauro Carvalho Chehab | e202c15 | 2010-03-26 22:45:16 -0300 | [diff] [blame] | 287 | printk(KERN_ERR "ir_core: unable to register rc class\n"); |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 288 | return rc; |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 289 | } |
| 290 | |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 291 | /* Initialize/load the decoders/keymap code that will be used */ |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 292 | ir_raw_init(); |
| 293 | |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | static void __exit ir_core_exit(void) |
| 298 | { |
Mauro Carvalho Chehab | 945cdfa | 2010-03-11 12:41:56 -0300 | [diff] [blame] | 299 | class_unregister(&ir_input_class); |
Mauro Carvalho Chehab | 4714eda | 2009-12-13 16:00:08 -0300 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | module_init(ir_core_init); |
| 303 | module_exit(ir_core_exit); |