kernel: update 3.10 to 3.10.2
[openwrt.git] / target / linux / brcm2708 / patches-3.10 / 008-lirc_rpi_driver.patch
1 --- a/drivers/staging/media/lirc/Kconfig
2 +++ b/drivers/staging/media/lirc/Kconfig
3 @@ -38,6 +38,12 @@ config LIRC_PARALLEL
4         help
5           Driver for Homebrew Parallel Port Receivers
6  
7 +config LIRC_RPI
8 +       tristate "Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi"
9 +       depends on LIRC
10 +       help
11 +         Driver for Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi
12 +
13  config LIRC_SASEM
14         tristate "Sasem USB IR Remote"
15         depends on LIRC && USB
16 --- /dev/null
17 +++ b/drivers/staging/media/lirc/lirc_rpi.c
18 @@ -0,0 +1,692 @@
19 +/*
20 + * lirc_rpi.c
21 + *
22 + * lirc_rpi - Device driver that records pulse- and pause-lengths
23 + *           (space-lengths) (just like the lirc_serial driver does)
24 + *           between GPIO interrupt events on the Raspberry Pi.
25 + *           Lots of code has been taken from the lirc_serial module,
26 + *           so I would like say thanks to the authors.
27 + *
28 + * Copyright (C) 2012 Aron Robert Szabo <aron@reon.hu>,
29 + *                   Michael Bishop <cleverca22@gmail.com>
30 + *  This program is free software; you can redistribute it and/or modify
31 + *  it under the terms of the GNU General Public License as published by
32 + *  the Free Software Foundation; either version 2 of the License, or
33 + *  (at your option) any later version.
34 + *
35 + *  This program is distributed in the hope that it will be useful,
36 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
37 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38 + *  GNU General Public License for more details.
39 + *
40 + *  You should have received a copy of the GNU General Public License
41 + *  along with this program; if not, write to the Free Software
42 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
43 + */
44 +
45 +#include <linux/module.h>
46 +#include <linux/errno.h>
47 +#include <linux/interrupt.h>
48 +#include <linux/sched.h>
49 +#include <linux/kernel.h>
50 +#include <linux/time.h>
51 +#include <linux/string.h>
52 +#include <linux/delay.h>
53 +#include <linux/platform_device.h>
54 +#include <linux/irq.h>
55 +#include <linux/spinlock.h>
56 +#include <media/lirc.h>
57 +#include <media/lirc_dev.h>
58 +#include <linux/gpio.h>
59 +
60 +#define LIRC_DRIVER_NAME "lirc_rpi"
61 +#define RBUF_LEN 256
62 +#define LIRC_TRANSMITTER_LATENCY 256
63 +
64 +#ifndef MAX_UDELAY_MS
65 +#define MAX_UDELAY_US 5000
66 +#else
67 +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
68 +#endif
69 +
70 +#define dprintk(fmt, args...)                                  \
71 +       do {                                                    \
72 +               if (debug)                                      \
73 +                       printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
74 +                              fmt, ## args);                   \
75 +       } while (0)
76 +
77 +/* module parameters */
78 +
79 +/* set the default GPIO input pin */
80 +static int gpio_in_pin = 18;
81 +/* set the default GPIO output pin */
82 +static int gpio_out_pin = 17;
83 +/* enable debugging messages */
84 +static int debug;
85 +/* -1 = auto, 0 = active high, 1 = active low */
86 +static int sense = -1;
87 +/* use softcarrier by default */
88 +static int softcarrier = 1;
89 +/* 0 = do not invert output, 1 = invert output */
90 +static int invert = 0;
91 +
92 +struct gpio_chip *gpiochip;
93 +struct irq_chip *irqchip;
94 +struct irq_data *irqdata;
95 +
96 +/* forward declarations */
97 +static long send_pulse(unsigned long length);
98 +static void send_space(long length);
99 +static void lirc_rpi_exit(void);
100 +
101 +int valid_gpio_pins[] = { 0, 1, 4, 8, 7, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23,
102 +       24, 25 };
103 +
104 +static struct platform_device *lirc_rpi_dev;
105 +static struct timeval lasttv = { 0, 0 };
106 +static struct lirc_buffer rbuf;
107 +static spinlock_t lock;
108 +
109 +/* initialized/set in init_timing_params() */
110 +static unsigned int freq = 38000;
111 +static unsigned int duty_cycle = 50;
112 +static unsigned long period;
113 +static unsigned long pulse_width;
114 +static unsigned long space_width;
115 +
116 +static void safe_udelay(unsigned long usecs)
117 +{
118 +       while (usecs > MAX_UDELAY_US) {
119 +               udelay(MAX_UDELAY_US);
120 +               usecs -= MAX_UDELAY_US;
121 +       }
122 +       udelay(usecs);
123 +}
124 +
125 +static int init_timing_params(unsigned int new_duty_cycle,
126 +       unsigned int new_freq)
127 +{
128 +       /*
129 +        * period, pulse/space width are kept with 8 binary places -
130 +        * IE multiplied by 256.
131 +        */
132 +       if (256 * 1000000L / new_freq * new_duty_cycle / 100 <=
133 +           LIRC_TRANSMITTER_LATENCY)
134 +               return -EINVAL;
135 +       if (256 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
136 +           LIRC_TRANSMITTER_LATENCY)
137 +               return -EINVAL;
138 +       duty_cycle = new_duty_cycle;
139 +       freq = new_freq;
140 +       period = 256 * 1000000L / freq;
141 +       pulse_width = period * duty_cycle / 100;
142 +       space_width = period - pulse_width;
143 +       dprintk("in init_timing_params, freq=%d pulse=%ld, "
144 +               "space=%ld\n", freq, pulse_width, space_width);
145 +       return 0;
146 +}
147 +
148 +static long send_pulse_softcarrier(unsigned long length)
149 +{
150 +       int flag;
151 +       unsigned long actual, target, d;
152 +
153 +       length <<= 8;
154 +
155 +       actual = 0; target = 0; flag = 0;
156 +       while (actual < length) {
157 +               if (flag) {
158 +                       gpiochip->set(gpiochip, gpio_out_pin, invert);
159 +                       target += space_width;
160 +               } else {
161 +                       gpiochip->set(gpiochip, gpio_out_pin, !invert);
162 +                       target += pulse_width;
163 +               }
164 +               d = (target - actual -
165 +                    LIRC_TRANSMITTER_LATENCY + 128) >> 8;
166 +               /*
167 +                * Note - we've checked in ioctl that the pulse/space
168 +                * widths are big enough so that d is > 0
169 +                */
170 +               udelay(d);
171 +               actual += (d << 8) + LIRC_TRANSMITTER_LATENCY;
172 +               flag = !flag;
173 +       }
174 +       return (actual-length) >> 8;
175 +}
176 +
177 +static long send_pulse(unsigned long length)
178 +{
179 +       if (length <= 0)
180 +               return 0;
181 +
182 +       if (softcarrier) {
183 +               return send_pulse_softcarrier(length);
184 +       } else {
185 +               gpiochip->set(gpiochip, gpio_out_pin, !invert);
186 +               safe_udelay(length);
187 +               return 0;
188 +       }
189 +}
190 +
191 +static void send_space(long length)
192 +{
193 +       gpiochip->set(gpiochip, gpio_out_pin, invert);
194 +       if (length <= 0)
195 +               return;
196 +       safe_udelay(length);
197 +}
198 +
199 +static void rbwrite(int l)
200 +{
201 +       if (lirc_buffer_full(&rbuf)) {
202 +               /* no new signals will be accepted */
203 +               dprintk("Buffer overrun\n");
204 +               return;
205 +       }
206 +       lirc_buffer_write(&rbuf, (void *)&l);
207 +}
208 +
209 +static void frbwrite(int l)
210 +{
211 +       /* simple noise filter */
212 +       static int pulse, space;
213 +       static unsigned int ptr;
214 +
215 +       if (ptr > 0 && (l & PULSE_BIT)) {
216 +               pulse += l & PULSE_MASK;
217 +               if (pulse > 250) {
218 +                       rbwrite(space);
219 +                       rbwrite(pulse | PULSE_BIT);
220 +                       ptr = 0;
221 +                       pulse = 0;
222 +               }
223 +               return;
224 +       }
225 +       if (!(l & PULSE_BIT)) {
226 +               if (ptr == 0) {
227 +                       if (l > 20000) {
228 +                               space = l;
229 +                               ptr++;
230 +                               return;
231 +                       }
232 +               } else {
233 +                       if (l > 20000) {
234 +                               space += pulse;
235 +                               if (space > PULSE_MASK)
236 +                                       space = PULSE_MASK;
237 +                               space += l;
238 +                               if (space > PULSE_MASK)
239 +                                       space = PULSE_MASK;
240 +                               pulse = 0;
241 +                               return;
242 +                       }
243 +                       rbwrite(space);
244 +                       rbwrite(pulse | PULSE_BIT);
245 +                       ptr = 0;
246 +                       pulse = 0;
247 +               }
248 +       }
249 +       rbwrite(l);
250 +}
251 +
252 +static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
253 +{
254 +       struct timeval tv;
255 +       long deltv;
256 +       int data;
257 +       int signal;
258 +
259 +       /* use the GPIO signal level */
260 +       signal = gpiochip->get(gpiochip, gpio_in_pin);
261 +
262 +       /* unmask the irq */
263 +       irqchip->irq_unmask(irqdata);
264 +
265 +       if (sense != -1) {
266 +               /* get current time */
267 +               do_gettimeofday(&tv);
268 +
269 +               /* calc time since last interrupt in microseconds */
270 +               deltv = tv.tv_sec-lasttv.tv_sec;
271 +               if (tv.tv_sec < lasttv.tv_sec ||
272 +                   (tv.tv_sec == lasttv.tv_sec &&
273 +                    tv.tv_usec < lasttv.tv_usec)) {
274 +                       printk(KERN_WARNING LIRC_DRIVER_NAME
275 +                              ": AIEEEE: your clock just jumped backwards\n");
276 +                       printk(KERN_WARNING LIRC_DRIVER_NAME
277 +                              ": %d %d %lx %lx %lx %lx\n", signal, sense,
278 +                              tv.tv_sec, lasttv.tv_sec,
279 +                              tv.tv_usec, lasttv.tv_usec);
280 +                       data = PULSE_MASK;
281 +               } else if (deltv > 15) {
282 +                       data = PULSE_MASK; /* really long time */
283 +                       if (!(signal^sense)) {
284 +                               /* sanity check */
285 +                               printk(KERN_WARNING LIRC_DRIVER_NAME
286 +                                      ": AIEEEE: %d %d %lx %lx %lx %lx\n",
287 +                                      signal, sense, tv.tv_sec, lasttv.tv_sec,
288 +                                      tv.tv_usec, lasttv.tv_usec);
289 +                               /*
290 +                                * detecting pulse while this
291 +                                * MUST be a space!
292 +                                */
293 +                               sense = sense ? 0 : 1;
294 +                       }
295 +               } else {
296 +                       data = (int) (deltv*1000000 +
297 +                                     (tv.tv_usec - lasttv.tv_usec));
298 +               }
299 +               frbwrite(signal^sense ? data : (data|PULSE_BIT));
300 +               lasttv = tv;
301 +               wake_up_interruptible(&rbuf.wait_poll);
302 +       }
303 +
304 +       return IRQ_HANDLED;
305 +}
306 +
307 +static int is_right_chip(struct gpio_chip *chip, void *data)
308 +{
309 +       dprintk("is_right_chip %s %d\n", chip->label, strcmp(data, chip->label));
310 +
311 +       if (strcmp(data, chip->label) == 0)
312 +               return 1;
313 +       return 0;
314 +}
315 +
316 +static int init_port(void)
317 +{
318 +       int i, nlow, nhigh, ret, irq;
319 +
320 +       gpiochip = gpiochip_find("bcm2708_gpio", is_right_chip);
321 +
322 +       if (!gpiochip)
323 +               return -ENODEV;
324 +
325 +       if (gpio_request(gpio_out_pin, LIRC_DRIVER_NAME " ir/out")) {
326 +               printk(KERN_ALERT LIRC_DRIVER_NAME
327 +                      ": cant claim gpio pin %d\n", gpio_out_pin);
328 +               ret = -ENODEV;
329 +               goto exit_init_port;
330 +       }
331 +
332 +       if (gpio_request(gpio_in_pin, LIRC_DRIVER_NAME " ir/in")) {
333 +               printk(KERN_ALERT LIRC_DRIVER_NAME
334 +                      ": cant claim gpio pin %d\n", gpio_in_pin);
335 +               ret = -ENODEV;
336 +               goto exit_gpio_free_out_pin;
337 +       }
338 +
339 +       gpiochip->direction_input(gpiochip, gpio_in_pin);
340 +       gpiochip->direction_output(gpiochip, gpio_out_pin, 1);
341 +       gpiochip->set(gpiochip, gpio_out_pin, invert);
342 +
343 +       irq = gpiochip->to_irq(gpiochip, gpio_in_pin);
344 +       dprintk("to_irq %d\n", irq);
345 +       irqdata = irq_get_irq_data(irq);
346 +
347 +       if (irqdata && irqdata->chip) {
348 +               irqchip = irqdata->chip;
349 +       } else {
350 +               ret = -ENODEV;
351 +               goto exit_gpio_free_in_pin;
352 +       }
353 +
354 +       /* if pin is high, then this must be an active low receiver. */
355 +       if (sense == -1) {
356 +               /* wait 1/2 sec for the power supply */
357 +               msleep(500);
358 +
359 +               /*
360 +                * probe 9 times every 0.04s, collect "votes" for
361 +                * active high/low
362 +                */
363 +               nlow = 0;
364 +               nhigh = 0;
365 +               for (i = 0; i < 9; i++) {
366 +                       if (gpiochip->get(gpiochip, gpio_in_pin))
367 +                               nlow++;
368 +                       else
369 +                               nhigh++;
370 +                       msleep(40);
371 +               }
372 +               sense = (nlow >= nhigh ? 1 : 0);
373 +               printk(KERN_INFO LIRC_DRIVER_NAME
374 +                      ": auto-detected active %s receiver on GPIO pin %d\n",
375 +                      sense ? "low" : "high", gpio_in_pin);
376 +       } else {
377 +               printk(KERN_INFO LIRC_DRIVER_NAME
378 +                      ": manually using active %s receiver on GPIO pin %d\n",
379 +                      sense ? "low" : "high", gpio_in_pin);
380 +       }
381 +
382 +       return 0;
383 +
384 +       exit_gpio_free_in_pin:
385 +       gpio_free(gpio_in_pin);
386 +
387 +       exit_gpio_free_out_pin:
388 +       gpio_free(gpio_out_pin);
389 +
390 +       exit_init_port:
391 +       return ret;
392 +}
393 +
394 +// called when the character device is opened
395 +static int set_use_inc(void *data)
396 +{
397 +       int result;
398 +       unsigned long flags;
399 +
400 +       /* initialize timestamp */
401 +       do_gettimeofday(&lasttv);
402 +
403 +       result = request_irq(gpiochip->to_irq(gpiochip, gpio_in_pin),
404 +                            (irq_handler_t) irq_handler, 0,
405 +                            LIRC_DRIVER_NAME, (void*) 0);
406 +
407 +       switch (result) {
408 +       case -EBUSY:
409 +               printk(KERN_ERR LIRC_DRIVER_NAME
410 +                      ": IRQ %d is busy\n",
411 +                      gpiochip->to_irq(gpiochip, gpio_in_pin));
412 +               return -EBUSY;
413 +       case -EINVAL:
414 +               printk(KERN_ERR LIRC_DRIVER_NAME
415 +                      ": Bad irq number or handler\n");
416 +               return -EINVAL;
417 +       default:
418 +               dprintk("Interrupt %d obtained\n",
419 +                       gpiochip->to_irq(gpiochip, gpio_in_pin));
420 +               break;
421 +       };
422 +
423 +       /* initialize pulse/space widths */
424 +       init_timing_params(duty_cycle, freq);
425 +
426 +       spin_lock_irqsave(&lock, flags);
427 +
428 +       /* GPIO Pin Falling/Rising Edge Detect Enable */
429 +       irqchip->irq_set_type(irqdata,
430 +                             IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING);
431 +
432 +       /* unmask the irq */
433 +       irqchip->irq_unmask(irqdata);
434 +
435 +       spin_unlock_irqrestore(&lock, flags);
436 +
437 +       return 0;
438 +}
439 +
440 +static void set_use_dec(void *data)
441 +{
442 +       unsigned long flags;
443 +
444 +       spin_lock_irqsave(&lock, flags);
445 +
446 +       /* GPIO Pin Falling/Rising Edge Detect Disable */
447 +       irqchip->irq_set_type(irqdata, 0);
448 +       irqchip->irq_mask(irqdata);
449 +
450 +       spin_unlock_irqrestore(&lock, flags);
451 +
452 +       free_irq(gpiochip->to_irq(gpiochip, gpio_in_pin), (void *) 0);
453 +
454 +       dprintk(KERN_INFO LIRC_DRIVER_NAME
455 +               ": freed IRQ %d\n", gpiochip->to_irq(gpiochip, gpio_in_pin));
456 +}
457 +
458 +static ssize_t lirc_write(struct file *file, const char *buf,
459 +       size_t n, loff_t *ppos)
460 +{
461 +       int i, count;
462 +       unsigned long flags;
463 +       long delta = 0;
464 +       int *wbuf;
465 +
466 +       count = n / sizeof(int);
467 +       if (n % sizeof(int) || count % 2 == 0)
468 +               return -EINVAL;
469 +       wbuf = memdup_user(buf, n);
470 +       if (IS_ERR(wbuf))
471 +               return PTR_ERR(wbuf);
472 +       spin_lock_irqsave(&lock, flags);
473 +
474 +       for (i = 0; i < count; i++) {
475 +               if (i%2)
476 +                       send_space(wbuf[i] - delta);
477 +               else
478 +                       delta = send_pulse(wbuf[i]);
479 +       }
480 +       gpiochip->set(gpiochip, gpio_out_pin, invert);
481 +
482 +       spin_unlock_irqrestore(&lock, flags);
483 +       kfree(wbuf);
484 +       return n;
485 +}
486 +
487 +static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
488 +{
489 +       int result;
490 +       __u32 value;
491 +
492 +       switch (cmd) {
493 +       case LIRC_GET_SEND_MODE:
494 +               return -ENOIOCTLCMD;
495 +               break;
496 +
497 +       case LIRC_SET_SEND_MODE:
498 +               result = get_user(value, (__u32 *) arg);
499 +               if (result)
500 +                       return result;
501 +               /* only LIRC_MODE_PULSE supported */
502 +               if (value != LIRC_MODE_PULSE)
503 +                       return -ENOSYS;
504 +               break;
505 +
506 +       case LIRC_GET_LENGTH:
507 +               return -ENOSYS;
508 +               break;
509 +
510 +       case LIRC_SET_SEND_DUTY_CYCLE:
511 +               dprintk("SET_SEND_DUTY_CYCLE\n");
512 +               result = get_user(value, (__u32 *) arg);
513 +               if (result)
514 +                       return result;
515 +               if (value <= 0 || value > 100)
516 +                       return -EINVAL;
517 +               return init_timing_params(value, freq);
518 +               break;
519 +
520 +       case LIRC_SET_SEND_CARRIER:
521 +               dprintk("SET_SEND_CARRIER\n");
522 +               result = get_user(value, (__u32 *) arg);
523 +               if (result)
524 +                       return result;
525 +               if (value > 500000 || value < 20000)
526 +                       return -EINVAL;
527 +               return init_timing_params(duty_cycle, value);
528 +               break;
529 +
530 +       default:
531 +               return lirc_dev_fop_ioctl(filep, cmd, arg);
532 +       }
533 +       return 0;
534 +}
535 +
536 +static const struct file_operations lirc_fops = {
537 +       .owner          = THIS_MODULE,
538 +       .write          = lirc_write,
539 +       .unlocked_ioctl = lirc_ioctl,
540 +       .read           = lirc_dev_fop_read,
541 +       .poll           = lirc_dev_fop_poll,
542 +       .open           = lirc_dev_fop_open,
543 +       .release        = lirc_dev_fop_close,
544 +       .llseek         = no_llseek,
545 +};
546 +
547 +static struct lirc_driver driver = {
548 +       .name           = LIRC_DRIVER_NAME,
549 +       .minor          = -1,
550 +       .code_length    = 1,
551 +       .sample_rate    = 0,
552 +       .data           = NULL,
553 +       .add_to_buf     = NULL,
554 +       .rbuf           = &rbuf,
555 +       .set_use_inc    = set_use_inc,
556 +       .set_use_dec    = set_use_dec,
557 +       .fops           = &lirc_fops,
558 +       .dev            = NULL,
559 +       .owner          = THIS_MODULE,
560 +};
561 +
562 +static struct platform_driver lirc_rpi_driver = {
563 +       .driver = {
564 +               .name   = LIRC_DRIVER_NAME,
565 +               .owner  = THIS_MODULE,
566 +       },
567 +};
568 +
569 +static int __init lirc_rpi_init(void)
570 +{
571 +       int result;
572 +
573 +       /* Init read buffer. */
574 +       result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
575 +       if (result < 0)
576 +               return -ENOMEM;
577 +
578 +       result = platform_driver_register(&lirc_rpi_driver);
579 +       if (result) {
580 +               printk(KERN_ERR LIRC_DRIVER_NAME
581 +                      ": lirc register returned %d\n", result);
582 +               goto exit_buffer_free;
583 +       }
584 +
585 +       lirc_rpi_dev = platform_device_alloc(LIRC_DRIVER_NAME, 0);
586 +       if (!lirc_rpi_dev) {
587 +               result = -ENOMEM;
588 +               goto exit_driver_unregister;
589 +       }
590 +
591 +       result = platform_device_add(lirc_rpi_dev);
592 +       if (result)
593 +               goto exit_device_put;
594 +
595 +       return 0;
596 +
597 +       exit_device_put:
598 +       platform_device_put(lirc_rpi_dev);
599 +
600 +       exit_driver_unregister:
601 +       platform_driver_unregister(&lirc_rpi_driver);
602 +
603 +       exit_buffer_free:
604 +       lirc_buffer_free(&rbuf);
605 +
606 +       return result;
607 +}
608 +
609 +static void lirc_rpi_exit(void)
610 +{
611 +       gpio_free(gpio_out_pin);
612 +       gpio_free(gpio_in_pin);
613 +       platform_device_unregister(lirc_rpi_dev);
614 +       platform_driver_unregister(&lirc_rpi_driver);
615 +       lirc_buffer_free(&rbuf);
616 +}
617 +
618 +static int __init lirc_rpi_init_module(void)
619 +{
620 +       int result, i;
621 +
622 +       result = lirc_rpi_init();
623 +       if (result)
624 +               return result;
625 +
626 +       /* check if the module received valid gpio pin numbers */
627 +       result = 0;
628 +       if (gpio_in_pin != gpio_out_pin) {
629 +               for(i = 0; (i < ARRAY_SIZE(valid_gpio_pins)) && (result != 2); i++) {
630 +                       if (gpio_in_pin == valid_gpio_pins[i] ||
631 +                          gpio_out_pin == valid_gpio_pins[i]) {
632 +                               result++;
633 +                       }
634 +               }
635 +       }
636 +
637 +       if (result != 2) {
638 +               result = -EINVAL;
639 +               printk(KERN_ERR LIRC_DRIVER_NAME
640 +                      ": invalid GPIO pin(s) specified!\n");
641 +               goto exit_rpi;
642 +       }
643 +
644 +       driver.features = LIRC_CAN_SET_SEND_DUTY_CYCLE |
645 +                         LIRC_CAN_SET_SEND_CARRIER |
646 +                         LIRC_CAN_SEND_PULSE |
647 +                         LIRC_CAN_REC_MODE2;
648 +
649 +       driver.dev = &lirc_rpi_dev->dev;
650 +       driver.minor = lirc_register_driver(&driver);
651 +
652 +       if (driver.minor < 0) {
653 +               printk(KERN_ERR LIRC_DRIVER_NAME
654 +                      ": device registration failed with %d\n", result);
655 +               result = -EIO;
656 +               goto exit_rpi;
657 +       }
658 +
659 +       printk(KERN_INFO LIRC_DRIVER_NAME ": driver registered!\n");
660 +
661 +       result = init_port();
662 +       if (result < 0)
663 +               goto exit_rpi;
664 +
665 +       return 0;
666 +
667 +       exit_rpi:
668 +       lirc_rpi_exit();
669 +
670 +       return result;
671 +}
672 +
673 +static void __exit lirc_rpi_exit_module(void)
674 +{
675 +       lirc_rpi_exit();
676 +
677 +       lirc_unregister_driver(driver.minor);
678 +       printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
679 +}
680 +
681 +module_init(lirc_rpi_init_module);
682 +module_exit(lirc_rpi_exit_module);
683 +
684 +MODULE_DESCRIPTION("Infra-red receiver and blaster driver for Raspberry Pi GPIO.");
685 +MODULE_AUTHOR("Aron Robert Szabo <aron@reon.hu>");
686 +MODULE_AUTHOR("Michael Bishop <cleverca22@gmail.com>");
687 +MODULE_LICENSE("GPL");
688 +
689 +module_param(gpio_out_pin, int, S_IRUGO);
690 +MODULE_PARM_DESC(gpio_out_pin, "GPIO output/transmitter pin number of the BCM"
691 +                " processor. Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11,"
692 +                " 14, 15, 17, 18, 21, 22, 23, 24, 25, default 17");
693 +
694 +module_param(gpio_in_pin, int, S_IRUGO);
695 +MODULE_PARM_DESC(gpio_in_pin, "GPIO input pin number of the BCM processor."
696 +                " Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11, 14, 15,"
697 +                " 17, 18, 21, 22, 23, 24, 25, default 18");
698 +
699 +module_param(sense, bool, S_IRUGO);
700 +MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
701 +                " (0 = active high, 1 = active low )");
702 +
703 +module_param(softcarrier, bool, S_IRUGO);
704 +MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
705 +
706 +module_param(invert, bool, S_IRUGO);
707 +MODULE_PARM_DESC(invert, "Invert output (0 = off, 1 = on, default off");
708 +
709 +module_param(debug, bool, S_IRUGO | S_IWUSR);
710 +MODULE_PARM_DESC(debug, "Enable debugging messages");
711 --- a/drivers/staging/media/lirc/Makefile
712 +++ b/drivers/staging/media/lirc/Makefile
713 @@ -7,6 +7,7 @@ obj-$(CONFIG_LIRC_BT829)        += lirc_bt829.o
714  obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
715  obj-$(CONFIG_LIRC_IMON)                += lirc_imon.o
716  obj-$(CONFIG_LIRC_PARALLEL)    += lirc_parallel.o
717 +obj-$(CONFIG_LIRC_RPI)         += lirc_rpi.o
718  obj-$(CONFIG_LIRC_SASEM)       += lirc_sasem.o
719  obj-$(CONFIG_LIRC_SERIAL)      += lirc_serial.o
720  obj-$(CONFIG_LIRC_SIR)         += lirc_sir.o