Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 1 | /* ir-raw-event.c - handle IR Pulse/Space event |
| 2 | * |
| 3 | * Copyright (C) 2010 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 | |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 15 | #include <linux/kthread.h> |
Maxim Levitsky | 45a568f | 2010-07-31 11:59:16 -0300 | [diff] [blame] | 16 | #include <linux/mutex.h> |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 17 | #include <linux/sched.h> |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 18 | #include <linux/freezer.h> |
Mauro Carvalho Chehab | 3f113e3 | 2010-04-08 15:10:27 -0300 | [diff] [blame] | 19 | #include "ir-core-priv.h" |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 20 | |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 21 | /* Define the max number of pulse/space transitions to buffer */ |
| 22 | #define MAX_IR_EVENT_SIZE 512 |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 23 | |
David Härdeman | c216369 | 2010-06-13 17:29:36 -0300 | [diff] [blame] | 24 | /* Used to keep track of IR raw clients, protected by ir_raw_handler_lock */ |
| 25 | static LIST_HEAD(ir_raw_client_list); |
| 26 | |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 27 | /* Used to handle IR raw handler extensions */ |
Maxim Levitsky | 45a568f | 2010-07-31 11:59:16 -0300 | [diff] [blame] | 28 | static DEFINE_MUTEX(ir_raw_handler_lock); |
David Härdeman | 667c9eb | 2010-06-13 17:29:31 -0300 | [diff] [blame] | 29 | static LIST_HEAD(ir_raw_handler_list); |
| 30 | static u64 available_protocols; |
Mauro Carvalho Chehab | 93c312f | 2010-03-25 21:13:43 -0300 | [diff] [blame] | 31 | |
Mauro Carvalho Chehab | 5fa2989 | 2010-04-08 19:04:06 -0300 | [diff] [blame] | 32 | #ifdef MODULE |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 33 | /* Used to load the decoders */ |
| 34 | static struct work_struct wq_load; |
Mauro Carvalho Chehab | 5fa2989 | 2010-04-08 19:04:06 -0300 | [diff] [blame] | 35 | #endif |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 36 | |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 37 | static int ir_raw_event_thread(void *data) |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 38 | { |
David Härdeman | e40b112 | 2010-04-15 18:46:00 -0300 | [diff] [blame] | 39 | struct ir_raw_event ev; |
David Härdeman | c216369 | 2010-06-13 17:29:36 -0300 | [diff] [blame] | 40 | struct ir_raw_handler *handler; |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 41 | struct ir_raw_event_ctrl *raw = (struct ir_raw_event_ctrl *)data; |
Maxim Levitsky | c6ef1e7 | 2010-09-06 18:26:06 -0300 | [diff] [blame^] | 42 | int retval; |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 43 | |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 44 | while (!kthread_should_stop()) { |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 45 | |
Maxim Levitsky | c6ef1e7 | 2010-09-06 18:26:06 -0300 | [diff] [blame^] | 46 | spin_lock_irq(&raw->lock); |
| 47 | retval = kfifo_out(&raw->kfifo, &ev, sizeof(ev)); |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 48 | |
Maxim Levitsky | c6ef1e7 | 2010-09-06 18:26:06 -0300 | [diff] [blame^] | 49 | if (!retval) { |
| 50 | set_current_state(TASK_INTERRUPTIBLE); |
| 51 | |
| 52 | if (kthread_should_stop()) |
| 53 | set_current_state(TASK_RUNNING); |
| 54 | |
| 55 | spin_unlock_irq(&raw->lock); |
| 56 | schedule(); |
| 57 | continue; |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 58 | } |
| 59 | |
Maxim Levitsky | c6ef1e7 | 2010-09-06 18:26:06 -0300 | [diff] [blame^] | 60 | spin_unlock_irq(&raw->lock); |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 61 | |
Maxim Levitsky | c6ef1e7 | 2010-09-06 18:26:06 -0300 | [diff] [blame^] | 62 | |
| 63 | BUG_ON(retval != sizeof(ev)); |
| 64 | |
| 65 | mutex_lock(&ir_raw_handler_lock); |
| 66 | list_for_each_entry(handler, &ir_raw_handler_list, list) |
| 67 | handler->decode(raw->input_dev, ev); |
| 68 | raw->prev_ev = ev; |
| 69 | mutex_unlock(&ir_raw_handler_lock); |
David Härdeman | c216369 | 2010-06-13 17:29:36 -0300 | [diff] [blame] | 70 | } |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 71 | |
| 72 | return 0; |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 73 | } |
| 74 | |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 75 | /** |
| 76 | * ir_raw_event_store() - pass a pulse/space duration to the raw ir decoders |
| 77 | * @input_dev: the struct input_dev device descriptor |
David Härdeman | e40b112 | 2010-04-15 18:46:00 -0300 | [diff] [blame] | 78 | * @ev: the struct ir_raw_event descriptor of the pulse/space |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 79 | * |
| 80 | * This routine (which may be called from an interrupt context) stores a |
| 81 | * pulse/space duration for the raw ir decoding state machines. Pulses are |
| 82 | * signalled as positive values and spaces as negative values. A zero value |
| 83 | * will reset the decoding state machines. |
| 84 | */ |
David Härdeman | e40b112 | 2010-04-15 18:46:00 -0300 | [diff] [blame] | 85 | int ir_raw_event_store(struct input_dev *input_dev, struct ir_raw_event *ev) |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 86 | { |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 87 | struct ir_input_dev *ir = input_get_drvdata(input_dev); |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 88 | |
| 89 | if (!ir->raw) |
| 90 | return -EINVAL; |
| 91 | |
Maxim Levitsky | 510fcb7 | 2010-07-31 11:59:15 -0300 | [diff] [blame] | 92 | IR_dprintk(2, "sample: (05%dus %s)\n", |
| 93 | TO_US(ev->duration), TO_STR(ev->pulse)); |
| 94 | |
David Härdeman | e40b112 | 2010-04-15 18:46:00 -0300 | [diff] [blame] | 95 | if (kfifo_in(&ir->raw->kfifo, ev, sizeof(*ev)) != sizeof(*ev)) |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 96 | return -ENOMEM; |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 97 | |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 98 | return 0; |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 99 | } |
| 100 | EXPORT_SYMBOL_GPL(ir_raw_event_store); |
| 101 | |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 102 | /** |
| 103 | * ir_raw_event_store_edge() - notify raw ir decoders of the start of a pulse/space |
| 104 | * @input_dev: the struct input_dev device descriptor |
| 105 | * @type: the type of the event that has occurred |
| 106 | * |
| 107 | * This routine (which may be called from an interrupt context) is used to |
| 108 | * store the beginning of an ir pulse or space (or the start/end of ir |
| 109 | * reception) for the raw ir decoding state machines. This is used by |
| 110 | * hardware which does not provide durations directly but only interrupts |
| 111 | * (or similar events) on state change. |
| 112 | */ |
| 113 | int ir_raw_event_store_edge(struct input_dev *input_dev, enum raw_event_type type) |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 114 | { |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 115 | struct ir_input_dev *ir = input_get_drvdata(input_dev); |
| 116 | ktime_t now; |
| 117 | s64 delta; /* ns */ |
David Härdeman | e40b112 | 2010-04-15 18:46:00 -0300 | [diff] [blame] | 118 | struct ir_raw_event ev; |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 119 | int rc = 0; |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 120 | |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 121 | if (!ir->raw) |
| 122 | return -EINVAL; |
| 123 | |
| 124 | now = ktime_get(); |
| 125 | delta = ktime_to_ns(ktime_sub(now, ir->raw->last_event)); |
| 126 | |
| 127 | /* Check for a long duration since last event or if we're |
| 128 | * being called for the first time, note that delta can't |
| 129 | * possibly be negative. |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 130 | */ |
David Härdeman | e40b112 | 2010-04-15 18:46:00 -0300 | [diff] [blame] | 131 | ev.duration = 0; |
| 132 | if (delta > IR_MAX_DURATION || !ir->raw->last_type) |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 133 | type |= IR_START_EVENT; |
David Härdeman | e40b112 | 2010-04-15 18:46:00 -0300 | [diff] [blame] | 134 | else |
| 135 | ev.duration = delta; |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 136 | |
| 137 | if (type & IR_START_EVENT) |
| 138 | ir_raw_event_reset(input_dev); |
David Härdeman | e40b112 | 2010-04-15 18:46:00 -0300 | [diff] [blame] | 139 | else if (ir->raw->last_type & IR_SPACE) { |
| 140 | ev.pulse = false; |
| 141 | rc = ir_raw_event_store(input_dev, &ev); |
| 142 | } else if (ir->raw->last_type & IR_PULSE) { |
| 143 | ev.pulse = true; |
| 144 | rc = ir_raw_event_store(input_dev, &ev); |
| 145 | } else |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 146 | return 0; |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 147 | |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 148 | ir->raw->last_event = now; |
| 149 | ir->raw->last_type = type; |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 150 | return rc; |
| 151 | } |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 152 | EXPORT_SYMBOL_GPL(ir_raw_event_store_edge); |
| 153 | |
| 154 | /** |
Maxim Levitsky | 4a702eb | 2010-07-31 11:59:22 -0300 | [diff] [blame] | 155 | * ir_raw_event_store_with_filter() - pass next pulse/space to decoders with some processing |
| 156 | * @input_dev: the struct input_dev device descriptor |
| 157 | * @type: the type of the event that has occurred |
| 158 | * |
| 159 | * This routine (which may be called from an interrupt context) works |
| 160 | * in similiar manner to ir_raw_event_store_edge. |
| 161 | * This routine is intended for devices with limited internal buffer |
| 162 | * It automerges samples of same type, and handles timeouts |
| 163 | */ |
| 164 | int ir_raw_event_store_with_filter(struct input_dev *input_dev, |
| 165 | struct ir_raw_event *ev) |
| 166 | { |
| 167 | struct ir_input_dev *ir = input_get_drvdata(input_dev); |
| 168 | struct ir_raw_event_ctrl *raw = ir->raw; |
| 169 | |
| 170 | if (!raw || !ir->props) |
| 171 | return -EINVAL; |
| 172 | |
| 173 | /* Ignore spaces in idle mode */ |
| 174 | if (ir->idle && !ev->pulse) |
| 175 | return 0; |
| 176 | else if (ir->idle) |
| 177 | ir_raw_event_set_idle(input_dev, 0); |
| 178 | |
| 179 | if (!raw->this_ev.duration) { |
| 180 | raw->this_ev = *ev; |
| 181 | } else if (ev->pulse == raw->this_ev.pulse) { |
| 182 | raw->this_ev.duration += ev->duration; |
| 183 | } else { |
| 184 | ir_raw_event_store(input_dev, &raw->this_ev); |
| 185 | raw->this_ev = *ev; |
| 186 | } |
| 187 | |
| 188 | /* Enter idle mode if nessesary */ |
| 189 | if (!ev->pulse && ir->props->timeout && |
| 190 | raw->this_ev.duration >= ir->props->timeout) |
| 191 | ir_raw_event_set_idle(input_dev, 1); |
| 192 | return 0; |
| 193 | } |
| 194 | EXPORT_SYMBOL_GPL(ir_raw_event_store_with_filter); |
| 195 | |
| 196 | void ir_raw_event_set_idle(struct input_dev *input_dev, int idle) |
| 197 | { |
| 198 | struct ir_input_dev *ir = input_get_drvdata(input_dev); |
| 199 | struct ir_raw_event_ctrl *raw = ir->raw; |
| 200 | ktime_t now; |
| 201 | u64 delta; |
| 202 | |
| 203 | if (!ir->props) |
| 204 | return; |
| 205 | |
| 206 | if (!ir->raw) |
| 207 | goto out; |
| 208 | |
| 209 | if (idle) { |
| 210 | IR_dprintk(2, "enter idle mode\n"); |
| 211 | raw->last_event = ktime_get(); |
| 212 | } else { |
| 213 | IR_dprintk(2, "exit idle mode\n"); |
| 214 | |
| 215 | now = ktime_get(); |
| 216 | delta = ktime_to_ns(ktime_sub(now, ir->raw->last_event)); |
| 217 | |
| 218 | WARN_ON(raw->this_ev.pulse); |
| 219 | |
| 220 | raw->this_ev.duration = |
| 221 | min(raw->this_ev.duration + delta, |
| 222 | (u64)IR_MAX_DURATION); |
| 223 | |
| 224 | ir_raw_event_store(input_dev, &raw->this_ev); |
| 225 | |
| 226 | if (raw->this_ev.duration == IR_MAX_DURATION) |
| 227 | ir_raw_event_reset(input_dev); |
| 228 | |
| 229 | raw->this_ev.duration = 0; |
| 230 | } |
| 231 | out: |
| 232 | if (ir->props->s_idle) |
| 233 | ir->props->s_idle(ir->props->priv, idle); |
| 234 | ir->idle = idle; |
| 235 | } |
| 236 | EXPORT_SYMBOL_GPL(ir_raw_event_set_idle); |
| 237 | |
| 238 | /** |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 239 | * ir_raw_event_handle() - schedules the decoding of stored ir data |
| 240 | * @input_dev: the struct input_dev device descriptor |
| 241 | * |
| 242 | * This routine will signal the workqueue to start decoding stored ir data. |
| 243 | */ |
| 244 | void ir_raw_event_handle(struct input_dev *input_dev) |
| 245 | { |
| 246 | struct ir_input_dev *ir = input_get_drvdata(input_dev); |
Maxim Levitsky | c6ef1e7 | 2010-09-06 18:26:06 -0300 | [diff] [blame^] | 247 | unsigned long flags; |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 248 | |
| 249 | if (!ir->raw) |
| 250 | return; |
| 251 | |
Maxim Levitsky | c6ef1e7 | 2010-09-06 18:26:06 -0300 | [diff] [blame^] | 252 | spin_lock_irqsave(&ir->raw->lock, flags); |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 253 | wake_up_process(ir->raw->thread); |
Maxim Levitsky | c6ef1e7 | 2010-09-06 18:26:06 -0300 | [diff] [blame^] | 254 | spin_unlock_irqrestore(&ir->raw->lock, flags); |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 255 | } |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 256 | EXPORT_SYMBOL_GPL(ir_raw_event_handle); |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 257 | |
David Härdeman | 667c9eb | 2010-06-13 17:29:31 -0300 | [diff] [blame] | 258 | /* used internally by the sysfs interface */ |
| 259 | u64 |
| 260 | ir_raw_get_allowed_protocols() |
| 261 | { |
| 262 | u64 protocols; |
Maxim Levitsky | 45a568f | 2010-07-31 11:59:16 -0300 | [diff] [blame] | 263 | mutex_lock(&ir_raw_handler_lock); |
David Härdeman | 667c9eb | 2010-06-13 17:29:31 -0300 | [diff] [blame] | 264 | protocols = available_protocols; |
Maxim Levitsky | 45a568f | 2010-07-31 11:59:16 -0300 | [diff] [blame] | 265 | mutex_unlock(&ir_raw_handler_lock); |
David Härdeman | 667c9eb | 2010-06-13 17:29:31 -0300 | [diff] [blame] | 266 | return protocols; |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | * Used to (un)register raw event clients |
| 271 | */ |
| 272 | int ir_raw_event_register(struct input_dev *input_dev) |
| 273 | { |
| 274 | struct ir_input_dev *ir = input_get_drvdata(input_dev); |
| 275 | int rc; |
David Härdeman | c216369 | 2010-06-13 17:29:36 -0300 | [diff] [blame] | 276 | struct ir_raw_handler *handler; |
David Härdeman | 667c9eb | 2010-06-13 17:29:31 -0300 | [diff] [blame] | 277 | |
| 278 | ir->raw = kzalloc(sizeof(*ir->raw), GFP_KERNEL); |
| 279 | if (!ir->raw) |
| 280 | return -ENOMEM; |
| 281 | |
| 282 | ir->raw->input_dev = input_dev; |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 283 | |
David Härdeman | 667c9eb | 2010-06-13 17:29:31 -0300 | [diff] [blame] | 284 | ir->raw->enabled_protocols = ~0; |
| 285 | rc = kfifo_alloc(&ir->raw->kfifo, sizeof(s64) * MAX_IR_EVENT_SIZE, |
| 286 | GFP_KERNEL); |
| 287 | if (rc < 0) { |
| 288 | kfree(ir->raw); |
| 289 | ir->raw = NULL; |
| 290 | return rc; |
| 291 | } |
| 292 | |
Maxim Levitsky | c6ef1e7 | 2010-09-06 18:26:06 -0300 | [diff] [blame^] | 293 | spin_lock_init(&ir->raw->lock); |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 294 | ir->raw->thread = kthread_run(ir_raw_event_thread, ir->raw, |
| 295 | "rc%u", (unsigned int)ir->devno); |
| 296 | |
| 297 | if (IS_ERR(ir->raw->thread)) { |
Dan Carpenter | 028816b | 2010-08-12 04:47:07 -0300 | [diff] [blame] | 298 | int ret = PTR_ERR(ir->raw->thread); |
| 299 | |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 300 | kfree(ir->raw); |
| 301 | ir->raw = NULL; |
Dan Carpenter | 028816b | 2010-08-12 04:47:07 -0300 | [diff] [blame] | 302 | return ret; |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 303 | } |
| 304 | |
Maxim Levitsky | 45a568f | 2010-07-31 11:59:16 -0300 | [diff] [blame] | 305 | mutex_lock(&ir_raw_handler_lock); |
David Härdeman | c216369 | 2010-06-13 17:29:36 -0300 | [diff] [blame] | 306 | list_add_tail(&ir->raw->list, &ir_raw_client_list); |
| 307 | list_for_each_entry(handler, &ir_raw_handler_list, list) |
| 308 | if (handler->raw_register) |
| 309 | handler->raw_register(ir->raw->input_dev); |
Maxim Levitsky | 45a568f | 2010-07-31 11:59:16 -0300 | [diff] [blame] | 310 | mutex_unlock(&ir_raw_handler_lock); |
David Härdeman | 667c9eb | 2010-06-13 17:29:31 -0300 | [diff] [blame] | 311 | |
David Härdeman | c216369 | 2010-06-13 17:29:36 -0300 | [diff] [blame] | 312 | return 0; |
David Härdeman | 667c9eb | 2010-06-13 17:29:31 -0300 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void ir_raw_event_unregister(struct input_dev *input_dev) |
| 316 | { |
| 317 | struct ir_input_dev *ir = input_get_drvdata(input_dev); |
David Härdeman | c216369 | 2010-06-13 17:29:36 -0300 | [diff] [blame] | 318 | struct ir_raw_handler *handler; |
David Härdeman | 667c9eb | 2010-06-13 17:29:31 -0300 | [diff] [blame] | 319 | |
| 320 | if (!ir->raw) |
| 321 | return; |
| 322 | |
Maxim Levitsky | 0d2cb1d | 2010-07-31 11:59:17 -0300 | [diff] [blame] | 323 | kthread_stop(ir->raw->thread); |
David Härdeman | c216369 | 2010-06-13 17:29:36 -0300 | [diff] [blame] | 324 | |
Maxim Levitsky | 45a568f | 2010-07-31 11:59:16 -0300 | [diff] [blame] | 325 | mutex_lock(&ir_raw_handler_lock); |
David Härdeman | c216369 | 2010-06-13 17:29:36 -0300 | [diff] [blame] | 326 | list_del(&ir->raw->list); |
| 327 | list_for_each_entry(handler, &ir_raw_handler_list, list) |
| 328 | if (handler->raw_unregister) |
| 329 | handler->raw_unregister(ir->raw->input_dev); |
Maxim Levitsky | 45a568f | 2010-07-31 11:59:16 -0300 | [diff] [blame] | 330 | mutex_unlock(&ir_raw_handler_lock); |
David Härdeman | 667c9eb | 2010-06-13 17:29:31 -0300 | [diff] [blame] | 331 | |
| 332 | kfifo_free(&ir->raw->kfifo); |
| 333 | kfree(ir->raw); |
| 334 | ir->raw = NULL; |
| 335 | } |
| 336 | |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 337 | /* |
| 338 | * Extension interface - used to register the IR decoders |
| 339 | */ |
| 340 | |
| 341 | int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler) |
| 342 | { |
David Härdeman | c216369 | 2010-06-13 17:29:36 -0300 | [diff] [blame] | 343 | struct ir_raw_event_ctrl *raw; |
| 344 | |
Maxim Levitsky | 45a568f | 2010-07-31 11:59:16 -0300 | [diff] [blame] | 345 | mutex_lock(&ir_raw_handler_lock); |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 346 | list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list); |
David Härdeman | c216369 | 2010-06-13 17:29:36 -0300 | [diff] [blame] | 347 | if (ir_raw_handler->raw_register) |
| 348 | list_for_each_entry(raw, &ir_raw_client_list, list) |
| 349 | ir_raw_handler->raw_register(raw->input_dev); |
David Härdeman | 667c9eb | 2010-06-13 17:29:31 -0300 | [diff] [blame] | 350 | available_protocols |= ir_raw_handler->protocols; |
Maxim Levitsky | 45a568f | 2010-07-31 11:59:16 -0300 | [diff] [blame] | 351 | mutex_unlock(&ir_raw_handler_lock); |
David Härdeman | 667c9eb | 2010-06-13 17:29:31 -0300 | [diff] [blame] | 352 | |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 353 | return 0; |
| 354 | } |
| 355 | EXPORT_SYMBOL(ir_raw_handler_register); |
| 356 | |
| 357 | void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler) |
| 358 | { |
David Härdeman | c216369 | 2010-06-13 17:29:36 -0300 | [diff] [blame] | 359 | struct ir_raw_event_ctrl *raw; |
| 360 | |
Maxim Levitsky | 45a568f | 2010-07-31 11:59:16 -0300 | [diff] [blame] | 361 | mutex_lock(&ir_raw_handler_lock); |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 362 | list_del(&ir_raw_handler->list); |
David Härdeman | c216369 | 2010-06-13 17:29:36 -0300 | [diff] [blame] | 363 | if (ir_raw_handler->raw_unregister) |
| 364 | list_for_each_entry(raw, &ir_raw_client_list, list) |
| 365 | ir_raw_handler->raw_unregister(raw->input_dev); |
David Härdeman | 667c9eb | 2010-06-13 17:29:31 -0300 | [diff] [blame] | 366 | available_protocols &= ~ir_raw_handler->protocols; |
Maxim Levitsky | 45a568f | 2010-07-31 11:59:16 -0300 | [diff] [blame] | 367 | mutex_unlock(&ir_raw_handler_lock); |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 368 | } |
| 369 | EXPORT_SYMBOL(ir_raw_handler_unregister); |
| 370 | |
Mauro Carvalho Chehab | 5fa2989 | 2010-04-08 19:04:06 -0300 | [diff] [blame] | 371 | #ifdef MODULE |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 372 | static void init_decoders(struct work_struct *work) |
| 373 | { |
| 374 | /* Load the decoder modules */ |
| 375 | |
| 376 | load_nec_decode(); |
Mauro Carvalho Chehab | db1423a | 2010-04-04 10:27:20 -0300 | [diff] [blame] | 377 | load_rc5_decode(); |
David Härdeman | 784a493 | 2010-04-08 20:04:40 -0300 | [diff] [blame] | 378 | load_rc6_decode(); |
David Härdeman | bf670f6 | 2010-04-15 18:46:05 -0300 | [diff] [blame] | 379 | load_jvc_decode(); |
David Härdeman | 3fe29c8 | 2010-04-15 18:46:10 -0300 | [diff] [blame] | 380 | load_sony_decode(); |
Jarod Wilson | ca41469 | 2010-07-03 01:07:53 -0300 | [diff] [blame] | 381 | load_lirc_codec(); |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 382 | |
| 383 | /* If needed, we may later add some init code. In this case, |
| 384 | it is needed to change the CONFIG_MODULE test at ir-core.h |
| 385 | */ |
| 386 | } |
Mauro Carvalho Chehab | 5fa2989 | 2010-04-08 19:04:06 -0300 | [diff] [blame] | 387 | #endif |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 388 | |
| 389 | void ir_raw_init(void) |
| 390 | { |
Mauro Carvalho Chehab | 93c312f | 2010-03-25 21:13:43 -0300 | [diff] [blame] | 391 | #ifdef MODULE |
Mauro Carvalho Chehab | 995187b | 2010-03-24 20:47:53 -0300 | [diff] [blame] | 392 | INIT_WORK(&wq_load, init_decoders); |
| 393 | schedule_work(&wq_load); |
Mauro Carvalho Chehab | 93c312f | 2010-03-25 21:13:43 -0300 | [diff] [blame] | 394 | #endif |
| 395 | } |