blob: 98893a8332c7aa502aa269eaa6c1c5d081ac120d [file] [log] [blame]
Jarod Wilson457e2ff2011-01-18 02:33:08 -03001/* ir-lirc-codec.c - rc-core to classic lirc interface bridge
Jarod Wilsonca414692010-07-03 01:07:53 -03002 *
3 * Copyright (C) 2010 by Jarod Wilson <jarod@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/sched.h>
16#include <linux/wait.h>
Paul Gortmaker7a707b82011-07-03 14:03:12 -040017#include <linux/module.h>
Jarod Wilsonca414692010-07-03 01:07:53 -030018#include <media/lirc.h>
Jarod Wilson56900852010-07-16 14:25:33 -030019#include <media/lirc_dev.h>
Mauro Carvalho Chehab6bda9642010-11-17 13:28:38 -030020#include <media/rc-core.h>
Mauro Carvalho Chehabf62de672010-11-09 23:09:57 -030021#include "rc-core-priv.h"
Jarod Wilsonca414692010-07-03 01:07:53 -030022
23#define LIRCBUF_SIZE 256
24
25/**
26 * ir_lirc_decode() - Send raw IR data to lirc_dev to be relayed to the
27 * lircd userspace daemon for decoding.
David Härdemand8b4b582010-10-29 16:08:23 -030028 * @input_dev: the struct rc_dev descriptor of the device
Jarod Wilsonca414692010-07-03 01:07:53 -030029 * @duration: the struct ir_raw_event descriptor of the pulse/space
30 *
31 * This function returns -EINVAL if the lirc interfaces aren't wired up.
32 */
David Härdemand8b4b582010-10-29 16:08:23 -030033static int ir_lirc_decode(struct rc_dev *dev, struct ir_raw_event ev)
Jarod Wilsonca414692010-07-03 01:07:53 -030034{
David Härdemand8b4b582010-10-29 16:08:23 -030035 struct lirc_codec *lirc = &dev->raw->lirc;
Maxim Levitsky510fcb72010-07-31 11:59:15 -030036 int sample;
Jarod Wilsonca414692010-07-03 01:07:53 -030037
David Härdemanc5540fb2014-04-03 20:32:21 -030038 if (!(dev->enabled_protocols & RC_BIT_LIRC))
Jarod Wilsonca414692010-07-03 01:07:53 -030039 return 0;
40
David Härdemand8b4b582010-10-29 16:08:23 -030041 if (!dev->raw->lirc.drv || !dev->raw->lirc.drv->rbuf)
Jarod Wilsonca414692010-07-03 01:07:53 -030042 return -EINVAL;
43
Maxim Levitsky46519182010-10-16 19:56:28 -030044 /* Packet start */
Austin Lunda8f29e82014-07-24 07:40:20 -030045 if (ev.reset) {
46 /* Userspace expects a long space event before the start of
47 * the signal to use as a sync. This may be done with repeat
48 * packets and normal samples. But if a reset has been sent
49 * then we assume that a long time has passed, so we send a
50 * space with the maximum time value. */
51 sample = LIRC_SPACE(LIRC_VALUE_MASK);
52 IR_dprintk(2, "delivering reset sync space to lirc_dev\n");
Maxim Levitsky510fcb72010-07-31 11:59:15 -030053
Maxim Levitsky46519182010-10-16 19:56:28 -030054 /* Carrier reports */
Austin Lunda8f29e82014-07-24 07:40:20 -030055 } else if (ev.carrier_report) {
Maxim Levitsky46519182010-10-16 19:56:28 -030056 sample = LIRC_FREQUENCY(ev.carrier);
Jarod Wilson457e2ff2011-01-18 02:33:08 -030057 IR_dprintk(2, "carrier report (freq: %d)\n", sample);
Jarod Wilsonca414692010-07-03 01:07:53 -030058
Maxim Levitsky46519182010-10-16 19:56:28 -030059 /* Packet end */
60 } else if (ev.timeout) {
61
62 if (lirc->gap)
63 return 0;
64
65 lirc->gap_start = ktime_get();
66 lirc->gap = true;
67 lirc->gap_duration = ev.duration;
68
69 if (!lirc->send_timeout_reports)
70 return 0;
71
72 sample = LIRC_TIMEOUT(ev.duration / 1000);
Jarod Wilson457e2ff2011-01-18 02:33:08 -030073 IR_dprintk(2, "timeout report (duration: %d)\n", sample);
Maxim Levitsky46519182010-10-16 19:56:28 -030074
75 /* Normal sample */
76 } else {
77
78 if (lirc->gap) {
79 int gap_sample;
80
81 lirc->gap_duration += ktime_to_ns(ktime_sub(ktime_get(),
82 lirc->gap_start));
83
84 /* Convert to ms and cap by LIRC_VALUE_MASK */
85 do_div(lirc->gap_duration, 1000);
86 lirc->gap_duration = min(lirc->gap_duration,
87 (u64)LIRC_VALUE_MASK);
88
89 gap_sample = LIRC_SPACE(lirc->gap_duration);
David Härdemand8b4b582010-10-29 16:08:23 -030090 lirc_buffer_write(dev->raw->lirc.drv->rbuf,
Maxim Levitsky46519182010-10-16 19:56:28 -030091 (unsigned char *) &gap_sample);
92 lirc->gap = false;
93 }
94
95 sample = ev.pulse ? LIRC_PULSE(ev.duration / 1000) :
96 LIRC_SPACE(ev.duration / 1000);
Jarod Wilson457e2ff2011-01-18 02:33:08 -030097 IR_dprintk(2, "delivering %uus %s to lirc_dev\n",
98 TO_US(ev.duration), TO_STR(ev.pulse));
Maxim Levitsky46519182010-10-16 19:56:28 -030099 }
Jarod Wilsonca414692010-07-03 01:07:53 -0300100
David Härdemand8b4b582010-10-29 16:08:23 -0300101 lirc_buffer_write(dev->raw->lirc.drv->rbuf,
Maxim Levitsky510fcb72010-07-31 11:59:15 -0300102 (unsigned char *) &sample);
David Härdemand8b4b582010-10-29 16:08:23 -0300103 wake_up(&dev->raw->lirc.drv->rbuf->wait_poll);
Jarod Wilsonca414692010-07-03 01:07:53 -0300104
Jarod Wilsonca414692010-07-03 01:07:53 -0300105 return 0;
106}
107
Dan Carpenter06bd8012011-10-06 02:41:06 -0300108static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
Jarod Wilsonca414692010-07-03 01:07:53 -0300109 size_t n, loff_t *ppos)
110{
111 struct lirc_codec *lirc;
David Härdemand8b4b582010-10-29 16:08:23 -0300112 struct rc_dev *dev;
David Härdeman5588dc22011-04-28 12:13:58 -0300113 unsigned int *txbuf; /* buffer with values to transmit */
Sean Youngd07df2232012-08-13 08:59:49 -0300114 ssize_t ret = -EINVAL;
Vasiliy Kulikov4c8b8692010-11-26 14:06:35 -0300115 size_t count;
David Härdemanf8e00d52011-04-28 11:14:03 -0300116 ktime_t start;
117 s64 towait;
118 unsigned int duration = 0; /* signal duration in us */
119 int i;
120
121 start = ktime_get();
Jarod Wilsonca414692010-07-03 01:07:53 -0300122
123 lirc = lirc_get_pdata(file);
124 if (!lirc)
125 return -EFAULT;
126
David Härdeman5588dc22011-04-28 12:13:58 -0300127 if (n < sizeof(unsigned) || n % sizeof(unsigned))
Jarod Wilsonca414692010-07-03 01:07:53 -0300128 return -EINVAL;
129
David Härdeman5588dc22011-04-28 12:13:58 -0300130 count = n / sizeof(unsigned);
131 if (count > LIRCBUF_SIZE || count % 2 == 0)
Jarod Wilsonca414692010-07-03 01:07:53 -0300132 return -EINVAL;
133
Jarod Wilson6efb8702010-07-16 18:29:54 -0300134 txbuf = memdup_user(buf, n);
135 if (IS_ERR(txbuf))
136 return PTR_ERR(txbuf);
Jarod Wilsonca414692010-07-03 01:07:53 -0300137
David Härdemand8b4b582010-10-29 16:08:23 -0300138 dev = lirc->dev;
139 if (!dev) {
Jarod Wilsonca414692010-07-03 01:07:53 -0300140 ret = -EFAULT;
141 goto out;
142 }
143
David Härdemanf8e00d52011-04-28 11:14:03 -0300144 if (!dev->tx_ir) {
145 ret = -ENOSYS;
146 goto out;
147 }
David Härdeman5588dc22011-04-28 12:13:58 -0300148
Sean Young25379bf2013-07-08 17:33:11 -0300149 for (i = 0; i < count; i++) {
150 if (txbuf[i] > IR_MAX_DURATION / 1000 - duration || !txbuf[i]) {
151 ret = -EINVAL;
152 goto out;
153 }
154
155 duration += txbuf[i];
156 }
157
Sean Young586c61f2012-08-23 17:18:25 -0300158 ret = dev->tx_ir(dev, txbuf, count);
David Härdemanf8e00d52011-04-28 11:14:03 -0300159 if (ret < 0)
160 goto out;
161
Sean Young25379bf2013-07-08 17:33:11 -0300162 for (duration = i = 0; i < ret; i++)
David Härdemanf8e00d52011-04-28 11:14:03 -0300163 duration += txbuf[i];
164
165 ret *= sizeof(unsigned int);
166
167 /*
168 * The lircd gap calculation expects the write function to
169 * wait for the actual IR signal to be transmitted before
170 * returning.
171 */
172 towait = ktime_us_delta(ktime_add_us(start, duration), ktime_get());
173 if (towait > 0) {
174 set_current_state(TASK_INTERRUPTIBLE);
175 schedule_timeout(usecs_to_jiffies(towait));
176 }
Jarod Wilsonca414692010-07-03 01:07:53 -0300177
178out:
179 kfree(txbuf);
180 return ret;
181}
182
Maxim Levitskye5893332010-07-31 11:59:23 -0300183static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
Dan Carpenter06bd8012011-10-06 02:41:06 -0300184 unsigned long arg)
Jarod Wilsonca414692010-07-03 01:07:53 -0300185{
186 struct lirc_codec *lirc;
David Härdemand8b4b582010-10-29 16:08:23 -0300187 struct rc_dev *dev;
Dan Carpenter06bd8012011-10-06 02:41:06 -0300188 u32 __user *argp = (u32 __user *)(arg);
Jarod Wilsonca414692010-07-03 01:07:53 -0300189 int ret = 0;
Maxim Levitsky46519182010-10-16 19:56:28 -0300190 __u32 val = 0, tmp;
Jarod Wilsonca414692010-07-03 01:07:53 -0300191
192 lirc = lirc_get_pdata(filep);
193 if (!lirc)
194 return -EFAULT;
195
David Härdemand8b4b582010-10-29 16:08:23 -0300196 dev = lirc->dev;
197 if (!dev)
Jarod Wilsonca414692010-07-03 01:07:53 -0300198 return -EFAULT;
199
Maxim Levitskye5893332010-07-31 11:59:23 -0300200 if (_IOC_DIR(cmd) & _IOC_WRITE) {
Dan Carpenter06bd8012011-10-06 02:41:06 -0300201 ret = get_user(val, argp);
Jarod Wilsonca414692010-07-03 01:07:53 -0300202 if (ret)
203 return ret;
Maxim Levitskye5893332010-07-31 11:59:23 -0300204 }
Jarod Wilsonca414692010-07-03 01:07:53 -0300205
Maxim Levitskye5893332010-07-31 11:59:23 -0300206 switch (cmd) {
207
208 /* legacy support */
209 case LIRC_GET_SEND_MODE:
210 val = LIRC_CAN_SEND_PULSE & LIRC_CAN_SEND_MASK;
211 break;
212
213 case LIRC_SET_SEND_MODE:
214 if (val != (LIRC_MODE_PULSE & LIRC_CAN_SEND_MASK))
215 return -EINVAL;
Maxim Levitsky46519182010-10-16 19:56:28 -0300216 return 0;
Maxim Levitskye5893332010-07-31 11:59:23 -0300217
218 /* TX settings */
219 case LIRC_SET_TRANSMITTER_MASK:
David Härdemand8b4b582010-10-29 16:08:23 -0300220 if (!dev->s_tx_mask)
Dan Carpenter5f499082012-09-11 07:11:53 -0300221 return -ENOSYS;
Maxim Levitsky46519182010-10-16 19:56:28 -0300222
David Härdemand8b4b582010-10-29 16:08:23 -0300223 return dev->s_tx_mask(dev, val);
Jarod Wilsonca414692010-07-03 01:07:53 -0300224
225 case LIRC_SET_SEND_CARRIER:
David Härdemand8b4b582010-10-29 16:08:23 -0300226 if (!dev->s_tx_carrier)
Dan Carpenter5f499082012-09-11 07:11:53 -0300227 return -ENOSYS;
Maxim Levitsky46519182010-10-16 19:56:28 -0300228
David Härdemand8b4b582010-10-29 16:08:23 -0300229 return dev->s_tx_carrier(dev, val);
Jarod Wilsonca414692010-07-03 01:07:53 -0300230
Maxim Levitskye5893332010-07-31 11:59:23 -0300231 case LIRC_SET_SEND_DUTY_CYCLE:
David Härdemand8b4b582010-10-29 16:08:23 -0300232 if (!dev->s_tx_duty_cycle)
Maxim Levitskye5893332010-07-31 11:59:23 -0300233 return -ENOSYS;
234
235 if (val <= 0 || val >= 100)
236 return -EINVAL;
237
David Härdemand8b4b582010-10-29 16:08:23 -0300238 return dev->s_tx_duty_cycle(dev, val);
Jarod Wilsonca414692010-07-03 01:07:53 -0300239
Maxim Levitskye5893332010-07-31 11:59:23 -0300240 /* RX settings */
241 case LIRC_SET_REC_CARRIER:
David Härdemand8b4b582010-10-29 16:08:23 -0300242 if (!dev->s_rx_carrier_range)
Maxim Levitskye5893332010-07-31 11:59:23 -0300243 return -ENOSYS;
Jarod Wilsonca414692010-07-03 01:07:53 -0300244
Maxim Levitsky46519182010-10-16 19:56:28 -0300245 if (val <= 0)
246 return -EINVAL;
247
David Härdemand8b4b582010-10-29 16:08:23 -0300248 return dev->s_rx_carrier_range(dev,
249 dev->raw->lirc.carrier_low,
250 val);
Maxim Levitskye5893332010-07-31 11:59:23 -0300251
252 case LIRC_SET_REC_CARRIER_RANGE:
Maxim Levitsky46519182010-10-16 19:56:28 -0300253 if (val <= 0)
254 return -EINVAL;
Maxim Levitskye5893332010-07-31 11:59:23 -0300255
David Härdemand8b4b582010-10-29 16:08:23 -0300256 dev->raw->lirc.carrier_low = val;
Maxim Levitsky46519182010-10-16 19:56:28 -0300257 return 0;
Maxim Levitskye5893332010-07-31 11:59:23 -0300258
259 case LIRC_GET_REC_RESOLUTION:
David Härdemand8b4b582010-10-29 16:08:23 -0300260 val = dev->rx_resolution;
Maxim Levitskye5893332010-07-31 11:59:23 -0300261 break;
262
263 case LIRC_SET_WIDEBAND_RECEIVER:
David Härdemand8b4b582010-10-29 16:08:23 -0300264 if (!dev->s_learning_mode)
Maxim Levitskye5893332010-07-31 11:59:23 -0300265 return -ENOSYS;
266
David Härdemand8b4b582010-10-29 16:08:23 -0300267 return dev->s_learning_mode(dev, !!val);
Maxim Levitsky46519182010-10-16 19:56:28 -0300268
269 case LIRC_SET_MEASURE_CARRIER_MODE:
David Härdemand8b4b582010-10-29 16:08:23 -0300270 if (!dev->s_carrier_report)
Maxim Levitsky46519182010-10-16 19:56:28 -0300271 return -ENOSYS;
272
David Härdemand8b4b582010-10-29 16:08:23 -0300273 return dev->s_carrier_report(dev, !!val);
Maxim Levitsky46519182010-10-16 19:56:28 -0300274
Maxim Levitskye5893332010-07-31 11:59:23 -0300275 /* Generic timeout support */
276 case LIRC_GET_MIN_TIMEOUT:
David Härdemand8b4b582010-10-29 16:08:23 -0300277 if (!dev->max_timeout)
Maxim Levitskye5893332010-07-31 11:59:23 -0300278 return -ENOSYS;
David Härdemand8b4b582010-10-29 16:08:23 -0300279 val = dev->min_timeout / 1000;
Maxim Levitskye5893332010-07-31 11:59:23 -0300280 break;
281
282 case LIRC_GET_MAX_TIMEOUT:
David Härdemand8b4b582010-10-29 16:08:23 -0300283 if (!dev->max_timeout)
Maxim Levitskye5893332010-07-31 11:59:23 -0300284 return -ENOSYS;
David Härdemand8b4b582010-10-29 16:08:23 -0300285 val = dev->max_timeout / 1000;
Maxim Levitskye5893332010-07-31 11:59:23 -0300286 break;
287
288 case LIRC_SET_REC_TIMEOUT:
David Härdemand8b4b582010-10-29 16:08:23 -0300289 if (!dev->max_timeout)
Maxim Levitsky46519182010-10-16 19:56:28 -0300290 return -ENOSYS;
291
292 tmp = val * 1000;
293
David Härdemand8b4b582010-10-29 16:08:23 -0300294 if (tmp < dev->min_timeout ||
295 tmp > dev->max_timeout)
Maxim Levitsky46519182010-10-16 19:56:28 -0300296 return -EINVAL;
297
David Härdemand8b4b582010-10-29 16:08:23 -0300298 dev->timeout = tmp;
Maxim Levitsky46519182010-10-16 19:56:28 -0300299 break;
300
301 case LIRC_SET_REC_TIMEOUT_REPORTS:
302 lirc->send_timeout_reports = !!val;
Jarod Wilsonca414692010-07-03 01:07:53 -0300303 break;
304
305 default:
Arnd Bergmann044e5872010-08-02 15:43:35 -0300306 return lirc_dev_fop_ioctl(filep, cmd, arg);
Jarod Wilsonca414692010-07-03 01:07:53 -0300307 }
308
Maxim Levitskye5893332010-07-31 11:59:23 -0300309 if (_IOC_DIR(cmd) & _IOC_READ)
Dan Carpenter06bd8012011-10-06 02:41:06 -0300310 ret = put_user(val, argp);
Maxim Levitskye5893332010-07-31 11:59:23 -0300311
Jarod Wilsonca414692010-07-03 01:07:53 -0300312 return ret;
313}
314
315static int ir_lirc_open(void *data)
316{
317 return 0;
318}
319
320static void ir_lirc_close(void *data)
321{
322 return;
323}
324
Al Viro75ef9de2013-04-04 19:09:41 -0400325static const struct file_operations lirc_fops = {
Jarod Wilsonca414692010-07-03 01:07:53 -0300326 .owner = THIS_MODULE,
327 .write = ir_lirc_transmit_ir,
Arnd Bergmann044e5872010-08-02 15:43:35 -0300328 .unlocked_ioctl = ir_lirc_ioctl,
Jarod Wilson8be292c2010-10-09 15:07:06 -0300329#ifdef CONFIG_COMPAT
330 .compat_ioctl = ir_lirc_ioctl,
331#endif
Jarod Wilsonca414692010-07-03 01:07:53 -0300332 .read = lirc_dev_fop_read,
333 .poll = lirc_dev_fop_poll,
334 .open = lirc_dev_fop_open,
335 .release = lirc_dev_fop_close,
Arnd Bergmannd9d2e9d2010-08-15 18:51:56 +0200336 .llseek = no_llseek,
Jarod Wilsonca414692010-07-03 01:07:53 -0300337};
338
David Härdemand8b4b582010-10-29 16:08:23 -0300339static int ir_lirc_register(struct rc_dev *dev)
Jarod Wilsonca414692010-07-03 01:07:53 -0300340{
Jarod Wilsonca414692010-07-03 01:07:53 -0300341 struct lirc_driver *drv;
342 struct lirc_buffer *rbuf;
343 int rc = -ENOMEM;
344 unsigned long features;
345
346 drv = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
347 if (!drv)
348 return rc;
349
350 rbuf = kzalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
Dan Carpenter49b7a122010-07-23 07:08:26 -0300351 if (!rbuf)
Jarod Wilsonca414692010-07-03 01:07:53 -0300352 goto rbuf_alloc_failed;
353
354 rc = lirc_buffer_init(rbuf, sizeof(int), LIRCBUF_SIZE);
355 if (rc)
356 goto rbuf_init_failed;
357
358 features = LIRC_CAN_REC_MODE2;
David Härdemand8b4b582010-10-29 16:08:23 -0300359 if (dev->tx_ir) {
Jarod Wilsonca414692010-07-03 01:07:53 -0300360 features |= LIRC_CAN_SEND_PULSE;
David Härdemand8b4b582010-10-29 16:08:23 -0300361 if (dev->s_tx_mask)
Jarod Wilsonca414692010-07-03 01:07:53 -0300362 features |= LIRC_CAN_SET_TRANSMITTER_MASK;
David Härdemand8b4b582010-10-29 16:08:23 -0300363 if (dev->s_tx_carrier)
Jarod Wilsonca414692010-07-03 01:07:53 -0300364 features |= LIRC_CAN_SET_SEND_CARRIER;
David Härdemand8b4b582010-10-29 16:08:23 -0300365 if (dev->s_tx_duty_cycle)
Maxim Levitsky67332ba2010-09-06 18:26:08 -0300366 features |= LIRC_CAN_SET_SEND_DUTY_CYCLE;
Jarod Wilsonca414692010-07-03 01:07:53 -0300367 }
368
David Härdemand8b4b582010-10-29 16:08:23 -0300369 if (dev->s_rx_carrier_range)
Maxim Levitskye5893332010-07-31 11:59:23 -0300370 features |= LIRC_CAN_SET_REC_CARRIER |
371 LIRC_CAN_SET_REC_CARRIER_RANGE;
372
David Härdemand8b4b582010-10-29 16:08:23 -0300373 if (dev->s_learning_mode)
Maxim Levitskye5893332010-07-31 11:59:23 -0300374 features |= LIRC_CAN_USE_WIDEBAND_RECEIVER;
375
David Härdemand8b4b582010-10-29 16:08:23 -0300376 if (dev->s_carrier_report)
Maxim Levitsky46519182010-10-16 19:56:28 -0300377 features |= LIRC_CAN_MEASURE_CARRIER;
378
David Härdemand8b4b582010-10-29 16:08:23 -0300379 if (dev->max_timeout)
Maxim Levitskye5893332010-07-31 11:59:23 -0300380 features |= LIRC_CAN_SET_REC_TIMEOUT;
381
Jarod Wilsonca414692010-07-03 01:07:53 -0300382 snprintf(drv->name, sizeof(drv->name), "ir-lirc-codec (%s)",
David Härdemand8b4b582010-10-29 16:08:23 -0300383 dev->driver_name);
Jarod Wilsonca414692010-07-03 01:07:53 -0300384 drv->minor = -1;
385 drv->features = features;
David Härdemand8b4b582010-10-29 16:08:23 -0300386 drv->data = &dev->raw->lirc;
Jarod Wilsonca414692010-07-03 01:07:53 -0300387 drv->rbuf = rbuf;
388 drv->set_use_inc = &ir_lirc_open;
389 drv->set_use_dec = &ir_lirc_close;
390 drv->code_length = sizeof(struct ir_raw_event) * 8;
391 drv->fops = &lirc_fops;
David Härdemand8b4b582010-10-29 16:08:23 -0300392 drv->dev = &dev->dev;
Srinivas Kandagatlaca7a7222013-07-22 04:23:07 -0300393 drv->rdev = dev;
Jarod Wilsonca414692010-07-03 01:07:53 -0300394 drv->owner = THIS_MODULE;
395
396 drv->minor = lirc_register_driver(drv);
397 if (drv->minor < 0) {
398 rc = -ENODEV;
399 goto lirc_register_failed;
400 }
401
David Härdemand8b4b582010-10-29 16:08:23 -0300402 dev->raw->lirc.drv = drv;
403 dev->raw->lirc.dev = dev;
Jarod Wilsonca414692010-07-03 01:07:53 -0300404 return 0;
405
406lirc_register_failed:
407rbuf_init_failed:
408 kfree(rbuf);
409rbuf_alloc_failed:
410 kfree(drv);
411
412 return rc;
413}
414
David Härdemand8b4b582010-10-29 16:08:23 -0300415static int ir_lirc_unregister(struct rc_dev *dev)
Jarod Wilsonca414692010-07-03 01:07:53 -0300416{
David Härdemand8b4b582010-10-29 16:08:23 -0300417 struct lirc_codec *lirc = &dev->raw->lirc;
Jarod Wilsonca414692010-07-03 01:07:53 -0300418
419 lirc_unregister_driver(lirc->drv->minor);
420 lirc_buffer_free(lirc->drv->rbuf);
421 kfree(lirc->drv);
422
423 return 0;
424}
425
426static struct ir_raw_handler lirc_handler = {
David Härdemanc003ab12012-10-11 19:11:54 -0300427 .protocols = RC_BIT_LIRC,
Jarod Wilsonca414692010-07-03 01:07:53 -0300428 .decode = ir_lirc_decode,
429 .raw_register = ir_lirc_register,
430 .raw_unregister = ir_lirc_unregister,
431};
432
433static int __init ir_lirc_codec_init(void)
434{
435 ir_raw_handler_register(&lirc_handler);
436
437 printk(KERN_INFO "IR LIRC bridge handler initialized\n");
438 return 0;
439}
440
441static void __exit ir_lirc_codec_exit(void)
442{
443 ir_raw_handler_unregister(&lirc_handler);
444}
445
446module_init(ir_lirc_codec_init);
447module_exit(ir_lirc_codec_exit);
448
449MODULE_LICENSE("GPL");
450MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>");
451MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
452MODULE_DESCRIPTION("LIRC IR handler bridge");