Add linux-next specific files for 20110831
[linux-2.6/next.git] / drivers / media / rc / lirc_dev.c
blob27997a9ceb0d4552944bbbb6605bfc711ad9d9ea
1 /*
2 * LIRC base driver
4 * by Artur Lipowski <alipowski@interia.pl>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
25 #include <linux/errno.h>
26 #include <linux/ioctl.h>
27 #include <linux/fs.h>
28 #include <linux/poll.h>
29 #include <linux/completion.h>
30 #include <linux/mutex.h>
31 #include <linux/wait.h>
32 #include <linux/unistd.h>
33 #include <linux/kthread.h>
34 #include <linux/bitops.h>
35 #include <linux/device.h>
36 #include <linux/cdev.h>
38 #include <media/lirc.h>
39 #include <media/lirc_dev.h>
41 static int debug;
43 #define IRCTL_DEV_NAME "BaseRemoteCtl"
44 #define NOPLUG -1
45 #define LOGHEAD "lirc_dev (%s[%d]): "
47 static dev_t lirc_base_dev;
49 struct irctl {
50 struct lirc_driver d;
51 int attached;
52 int open;
54 struct mutex irctl_lock;
55 struct lirc_buffer *buf;
56 unsigned int chunk_size;
58 struct cdev *cdev;
60 struct task_struct *task;
61 long jiffies_to_wait;
64 static DEFINE_MUTEX(lirc_dev_lock);
66 static struct irctl *irctls[MAX_IRCTL_DEVICES];
68 /* Only used for sysfs but defined to void otherwise */
69 static struct class *lirc_class;
71 /* helper function
72 * initializes the irctl structure
74 static void lirc_irctl_init(struct irctl *ir)
76 mutex_init(&ir->irctl_lock);
77 ir->d.minor = NOPLUG;
80 static void lirc_irctl_cleanup(struct irctl *ir)
82 dev_dbg(ir->d.dev, LOGHEAD "cleaning up\n", ir->d.name, ir->d.minor);
84 device_destroy(lirc_class, MKDEV(MAJOR(lirc_base_dev), ir->d.minor));
86 if (ir->buf != ir->d.rbuf) {
87 lirc_buffer_free(ir->buf);
88 kfree(ir->buf);
90 ir->buf = NULL;
93 /* helper function
94 * reads key codes from driver and puts them into buffer
95 * returns 0 on success
97 static int lirc_add_to_buf(struct irctl *ir)
99 if (ir->d.add_to_buf) {
100 int res = -ENODATA;
101 int got_data = 0;
104 * service the device as long as it is returning
105 * data and we have space
107 get_data:
108 res = ir->d.add_to_buf(ir->d.data, ir->buf);
109 if (res == 0) {
110 got_data++;
111 goto get_data;
114 if (res == -ENODEV)
115 kthread_stop(ir->task);
117 return got_data ? 0 : res;
120 return 0;
123 /* main function of the polling thread
125 static int lirc_thread(void *irctl)
127 struct irctl *ir = irctl;
129 dev_dbg(ir->d.dev, LOGHEAD "poll thread started\n",
130 ir->d.name, ir->d.minor);
132 do {
133 if (ir->open) {
134 if (ir->jiffies_to_wait) {
135 set_current_state(TASK_INTERRUPTIBLE);
136 schedule_timeout(ir->jiffies_to_wait);
138 if (kthread_should_stop())
139 break;
140 if (!lirc_add_to_buf(ir))
141 wake_up_interruptible(&ir->buf->wait_poll);
142 } else {
143 set_current_state(TASK_INTERRUPTIBLE);
144 schedule();
146 } while (!kthread_should_stop());
148 dev_dbg(ir->d.dev, LOGHEAD "poll thread ended\n",
149 ir->d.name, ir->d.minor);
151 return 0;
155 static struct file_operations lirc_dev_fops = {
156 .owner = THIS_MODULE,
157 .read = lirc_dev_fop_read,
158 .write = lirc_dev_fop_write,
159 .poll = lirc_dev_fop_poll,
160 .unlocked_ioctl = lirc_dev_fop_ioctl,
161 #ifdef CONFIG_COMPAT
162 .compat_ioctl = lirc_dev_fop_ioctl,
163 #endif
164 .open = lirc_dev_fop_open,
165 .release = lirc_dev_fop_close,
166 .llseek = noop_llseek,
169 static int lirc_cdev_add(struct irctl *ir)
171 int retval = -ENOMEM;
172 struct lirc_driver *d = &ir->d;
173 struct cdev *cdev;
175 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
176 if (!cdev)
177 goto err_out;
179 if (d->fops) {
180 cdev_init(cdev, d->fops);
181 cdev->owner = d->owner;
182 } else {
183 cdev_init(cdev, &lirc_dev_fops);
184 cdev->owner = THIS_MODULE;
186 retval = kobject_set_name(&cdev->kobj, "lirc%d", d->minor);
187 if (retval)
188 goto err_out;
190 retval = cdev_add(cdev, MKDEV(MAJOR(lirc_base_dev), d->minor), 1);
191 if (retval) {
192 kobject_put(&cdev->kobj);
193 goto err_out;
196 ir->cdev = cdev;
198 return 0;
200 err_out:
201 kfree(cdev);
202 return retval;
205 int lirc_register_driver(struct lirc_driver *d)
207 struct irctl *ir;
208 int minor;
209 int bytes_in_key;
210 unsigned int chunk_size;
211 unsigned int buffer_size;
212 int err;
214 if (!d) {
215 printk(KERN_ERR "lirc_dev: lirc_register_driver: "
216 "driver pointer must be not NULL!\n");
217 err = -EBADRQC;
218 goto out;
221 if (!d->dev) {
222 printk(KERN_ERR "%s: dev pointer not filled in!\n", __func__);
223 err = -EINVAL;
224 goto out;
227 if (MAX_IRCTL_DEVICES <= d->minor) {
228 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
229 "\"minor\" must be between 0 and %d (%d)!\n",
230 MAX_IRCTL_DEVICES - 1, d->minor);
231 err = -EBADRQC;
232 goto out;
235 if (1 > d->code_length || (BUFLEN * 8) < d->code_length) {
236 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
237 "code length in bits for minor (%d) "
238 "must be less than %d!\n",
239 d->minor, BUFLEN * 8);
240 err = -EBADRQC;
241 goto out;
244 dev_dbg(d->dev, "lirc_dev: lirc_register_driver: sample_rate: %d\n",
245 d->sample_rate);
246 if (d->sample_rate) {
247 if (2 > d->sample_rate || HZ < d->sample_rate) {
248 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
249 "sample_rate must be between 2 and %d!\n", HZ);
250 err = -EBADRQC;
251 goto out;
253 if (!d->add_to_buf) {
254 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
255 "add_to_buf cannot be NULL when "
256 "sample_rate is set\n");
257 err = -EBADRQC;
258 goto out;
260 } else if (!(d->fops && d->fops->read) && !d->rbuf) {
261 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
262 "fops->read and rbuf cannot all be NULL!\n");
263 err = -EBADRQC;
264 goto out;
265 } else if (!d->rbuf) {
266 if (!(d->fops && d->fops->read && d->fops->poll &&
267 d->fops->unlocked_ioctl)) {
268 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
269 "neither read, poll nor unlocked_ioctl can be NULL!\n");
270 err = -EBADRQC;
271 goto out;
275 mutex_lock(&lirc_dev_lock);
277 minor = d->minor;
279 if (minor < 0) {
280 /* find first free slot for driver */
281 for (minor = 0; minor < MAX_IRCTL_DEVICES; minor++)
282 if (!irctls[minor])
283 break;
284 if (MAX_IRCTL_DEVICES == minor) {
285 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
286 "no free slots for drivers!\n");
287 err = -ENOMEM;
288 goto out_lock;
290 } else if (irctls[minor]) {
291 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
292 "minor (%d) just registered!\n", minor);
293 err = -EBUSY;
294 goto out_lock;
297 ir = kzalloc(sizeof(struct irctl), GFP_KERNEL);
298 if (!ir) {
299 err = -ENOMEM;
300 goto out_lock;
302 lirc_irctl_init(ir);
303 irctls[minor] = ir;
304 d->minor = minor;
306 if (d->sample_rate) {
307 ir->jiffies_to_wait = HZ / d->sample_rate;
308 } else {
309 /* it means - wait for external event in task queue */
310 ir->jiffies_to_wait = 0;
313 /* some safety check 8-) */
314 d->name[sizeof(d->name)-1] = '\0';
316 bytes_in_key = BITS_TO_LONGS(d->code_length) +
317 (d->code_length % 8 ? 1 : 0);
318 buffer_size = d->buffer_size ? d->buffer_size : BUFLEN / bytes_in_key;
319 chunk_size = d->chunk_size ? d->chunk_size : bytes_in_key;
321 if (d->rbuf) {
322 ir->buf = d->rbuf;
323 } else {
324 ir->buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
325 if (!ir->buf) {
326 err = -ENOMEM;
327 goto out_lock;
329 err = lirc_buffer_init(ir->buf, chunk_size, buffer_size);
330 if (err) {
331 kfree(ir->buf);
332 goto out_lock;
335 ir->chunk_size = ir->buf->chunk_size;
337 if (d->features == 0)
338 d->features = LIRC_CAN_REC_LIRCCODE;
340 ir->d = *d;
342 device_create(lirc_class, ir->d.dev,
343 MKDEV(MAJOR(lirc_base_dev), ir->d.minor), NULL,
344 "lirc%u", ir->d.minor);
346 if (d->sample_rate) {
347 /* try to fire up polling thread */
348 ir->task = kthread_run(lirc_thread, (void *)ir, "lirc_dev");
349 if (IS_ERR(ir->task)) {
350 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
351 "cannot run poll thread for minor = %d\n",
352 d->minor);
353 err = -ECHILD;
354 goto out_sysfs;
358 err = lirc_cdev_add(ir);
359 if (err)
360 goto out_sysfs;
362 ir->attached = 1;
363 mutex_unlock(&lirc_dev_lock);
365 dev_info(ir->d.dev, "lirc_dev: driver %s registered at minor = %d\n",
366 ir->d.name, ir->d.minor);
367 return minor;
369 out_sysfs:
370 device_destroy(lirc_class, MKDEV(MAJOR(lirc_base_dev), ir->d.minor));
371 out_lock:
372 mutex_unlock(&lirc_dev_lock);
373 out:
374 return err;
376 EXPORT_SYMBOL(lirc_register_driver);
378 int lirc_unregister_driver(int minor)
380 struct irctl *ir;
381 struct cdev *cdev;
383 if (minor < 0 || minor >= MAX_IRCTL_DEVICES) {
384 printk(KERN_ERR "lirc_dev: %s: minor (%d) must be between "
385 "0 and %d!\n", __func__, minor, MAX_IRCTL_DEVICES - 1);
386 return -EBADRQC;
389 ir = irctls[minor];
390 if (!ir) {
391 printk(KERN_ERR "lirc_dev: %s: failed to get irctl struct "
392 "for minor %d!\n", __func__, minor);
393 return -ENOENT;
396 cdev = ir->cdev;
398 mutex_lock(&lirc_dev_lock);
400 if (ir->d.minor != minor) {
401 printk(KERN_ERR "lirc_dev: %s: minor (%d) device not "
402 "registered!\n", __func__, minor);
403 mutex_unlock(&lirc_dev_lock);
404 return -ENOENT;
407 /* end up polling thread */
408 if (ir->task)
409 kthread_stop(ir->task);
411 dev_dbg(ir->d.dev, "lirc_dev: driver %s unregistered from minor = %d\n",
412 ir->d.name, ir->d.minor);
414 ir->attached = 0;
415 if (ir->open) {
416 dev_dbg(ir->d.dev, LOGHEAD "releasing opened driver\n",
417 ir->d.name, ir->d.minor);
418 wake_up_interruptible(&ir->buf->wait_poll);
419 mutex_lock(&ir->irctl_lock);
420 ir->d.set_use_dec(ir->d.data);
421 module_put(cdev->owner);
422 mutex_unlock(&ir->irctl_lock);
423 } else {
424 lirc_irctl_cleanup(ir);
425 cdev_del(cdev);
426 kfree(cdev);
427 kfree(ir);
428 irctls[minor] = NULL;
431 mutex_unlock(&lirc_dev_lock);
433 return 0;
435 EXPORT_SYMBOL(lirc_unregister_driver);
437 int lirc_dev_fop_open(struct inode *inode, struct file *file)
439 struct irctl *ir;
440 struct cdev *cdev;
441 int retval = 0;
443 if (iminor(inode) >= MAX_IRCTL_DEVICES) {
444 printk(KERN_WARNING "lirc_dev [%d]: open result = -ENODEV\n",
445 iminor(inode));
446 return -ENODEV;
449 if (mutex_lock_interruptible(&lirc_dev_lock))
450 return -ERESTARTSYS;
452 ir = irctls[iminor(inode)];
453 if (!ir) {
454 retval = -ENODEV;
455 goto error;
458 dev_dbg(ir->d.dev, LOGHEAD "open called\n", ir->d.name, ir->d.minor);
460 if (ir->d.minor == NOPLUG) {
461 retval = -ENODEV;
462 goto error;
465 if (ir->open) {
466 retval = -EBUSY;
467 goto error;
470 cdev = ir->cdev;
471 if (try_module_get(cdev->owner)) {
472 ir->open++;
473 retval = ir->d.set_use_inc(ir->d.data);
475 if (retval) {
476 module_put(cdev->owner);
477 ir->open--;
478 } else {
479 lirc_buffer_clear(ir->buf);
481 if (ir->task)
482 wake_up_process(ir->task);
485 error:
486 if (ir)
487 dev_dbg(ir->d.dev, LOGHEAD "open result = %d\n",
488 ir->d.name, ir->d.minor, retval);
490 mutex_unlock(&lirc_dev_lock);
492 nonseekable_open(inode, file);
494 return retval;
496 EXPORT_SYMBOL(lirc_dev_fop_open);
498 int lirc_dev_fop_close(struct inode *inode, struct file *file)
500 struct irctl *ir = irctls[iminor(inode)];
501 struct cdev *cdev;
503 if (!ir) {
504 printk(KERN_ERR "%s: called with invalid irctl\n", __func__);
505 return -EINVAL;
508 cdev = ir->cdev;
510 dev_dbg(ir->d.dev, LOGHEAD "close called\n", ir->d.name, ir->d.minor);
512 WARN_ON(mutex_lock_killable(&lirc_dev_lock));
514 ir->open--;
515 if (ir->attached) {
516 ir->d.set_use_dec(ir->d.data);
517 module_put(cdev->owner);
518 } else {
519 lirc_irctl_cleanup(ir);
520 cdev_del(cdev);
521 irctls[ir->d.minor] = NULL;
522 kfree(cdev);
523 kfree(ir);
526 mutex_unlock(&lirc_dev_lock);
528 return 0;
530 EXPORT_SYMBOL(lirc_dev_fop_close);
532 unsigned int lirc_dev_fop_poll(struct file *file, poll_table *wait)
534 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)];
535 unsigned int ret;
537 if (!ir) {
538 printk(KERN_ERR "%s: called with invalid irctl\n", __func__);
539 return POLLERR;
542 dev_dbg(ir->d.dev, LOGHEAD "poll called\n", ir->d.name, ir->d.minor);
544 if (!ir->attached)
545 return POLLERR;
547 poll_wait(file, &ir->buf->wait_poll, wait);
549 if (ir->buf)
550 if (lirc_buffer_empty(ir->buf))
551 ret = 0;
552 else
553 ret = POLLIN | POLLRDNORM;
554 else
555 ret = POLLERR;
557 dev_dbg(ir->d.dev, LOGHEAD "poll result = %d\n",
558 ir->d.name, ir->d.minor, ret);
560 return ret;
562 EXPORT_SYMBOL(lirc_dev_fop_poll);
564 long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
566 __u32 mode;
567 int result = 0;
568 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)];
570 if (!ir) {
571 printk(KERN_ERR "lirc_dev: %s: no irctl found!\n", __func__);
572 return -ENODEV;
575 dev_dbg(ir->d.dev, LOGHEAD "ioctl called (0x%x)\n",
576 ir->d.name, ir->d.minor, cmd);
578 if (ir->d.minor == NOPLUG || !ir->attached) {
579 dev_dbg(ir->d.dev, LOGHEAD "ioctl result = -ENODEV\n",
580 ir->d.name, ir->d.minor);
581 return -ENODEV;
584 mutex_lock(&ir->irctl_lock);
586 switch (cmd) {
587 case LIRC_GET_FEATURES:
588 result = put_user(ir->d.features, (__u32 *)arg);
589 break;
590 case LIRC_GET_REC_MODE:
591 if (!(ir->d.features & LIRC_CAN_REC_MASK)) {
592 result = -ENOSYS;
593 break;
596 result = put_user(LIRC_REC2MODE
597 (ir->d.features & LIRC_CAN_REC_MASK),
598 (__u32 *)arg);
599 break;
600 case LIRC_SET_REC_MODE:
601 if (!(ir->d.features & LIRC_CAN_REC_MASK)) {
602 result = -ENOSYS;
603 break;
606 result = get_user(mode, (__u32 *)arg);
607 if (!result && !(LIRC_MODE2REC(mode) & ir->d.features))
608 result = -EINVAL;
610 * FIXME: We should actually set the mode somehow but
611 * for now, lirc_serial doesn't support mode changing either
613 break;
614 case LIRC_GET_LENGTH:
615 result = put_user(ir->d.code_length, (__u32 *)arg);
616 break;
617 case LIRC_GET_MIN_TIMEOUT:
618 if (!(ir->d.features & LIRC_CAN_SET_REC_TIMEOUT) ||
619 ir->d.min_timeout == 0) {
620 result = -ENOSYS;
621 break;
624 result = put_user(ir->d.min_timeout, (__u32 *)arg);
625 break;
626 case LIRC_GET_MAX_TIMEOUT:
627 if (!(ir->d.features & LIRC_CAN_SET_REC_TIMEOUT) ||
628 ir->d.max_timeout == 0) {
629 result = -ENOSYS;
630 break;
633 result = put_user(ir->d.max_timeout, (__u32 *)arg);
634 break;
635 default:
636 result = -EINVAL;
639 dev_dbg(ir->d.dev, LOGHEAD "ioctl result = %d\n",
640 ir->d.name, ir->d.minor, result);
642 mutex_unlock(&ir->irctl_lock);
644 return result;
646 EXPORT_SYMBOL(lirc_dev_fop_ioctl);
648 ssize_t lirc_dev_fop_read(struct file *file,
649 char __user *buffer,
650 size_t length,
651 loff_t *ppos)
653 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)];
654 unsigned char *buf;
655 int ret = 0, written = 0;
656 DECLARE_WAITQUEUE(wait, current);
658 if (!ir) {
659 printk(KERN_ERR "%s: called with invalid irctl\n", __func__);
660 return -ENODEV;
663 dev_dbg(ir->d.dev, LOGHEAD "read called\n", ir->d.name, ir->d.minor);
665 buf = kzalloc(ir->chunk_size, GFP_KERNEL);
666 if (!buf)
667 return -ENOMEM;
669 if (mutex_lock_interruptible(&ir->irctl_lock)) {
670 ret = -ERESTARTSYS;
671 goto out_unlocked;
673 if (!ir->attached) {
674 ret = -ENODEV;
675 goto out_locked;
678 if (length % ir->chunk_size) {
679 ret = -EINVAL;
680 goto out_locked;
684 * we add ourselves to the task queue before buffer check
685 * to avoid losing scan code (in case when queue is awaken somewhere
686 * between while condition checking and scheduling)
688 add_wait_queue(&ir->buf->wait_poll, &wait);
689 set_current_state(TASK_INTERRUPTIBLE);
692 * while we didn't provide 'length' bytes, device is opened in blocking
693 * mode and 'copy_to_user' is happy, wait for data.
695 while (written < length && ret == 0) {
696 if (lirc_buffer_empty(ir->buf)) {
697 /* According to the read(2) man page, 'written' can be
698 * returned as less than 'length', instead of blocking
699 * again, returning -EWOULDBLOCK, or returning
700 * -ERESTARTSYS */
701 if (written)
702 break;
703 if (file->f_flags & O_NONBLOCK) {
704 ret = -EWOULDBLOCK;
705 break;
707 if (signal_pending(current)) {
708 ret = -ERESTARTSYS;
709 break;
712 mutex_unlock(&ir->irctl_lock);
713 schedule();
714 set_current_state(TASK_INTERRUPTIBLE);
716 if (mutex_lock_interruptible(&ir->irctl_lock)) {
717 ret = -ERESTARTSYS;
718 remove_wait_queue(&ir->buf->wait_poll, &wait);
719 set_current_state(TASK_RUNNING);
720 goto out_unlocked;
723 if (!ir->attached) {
724 ret = -ENODEV;
725 break;
727 } else {
728 lirc_buffer_read(ir->buf, buf);
729 ret = copy_to_user((void *)buffer+written, buf,
730 ir->buf->chunk_size);
731 if (!ret)
732 written += ir->buf->chunk_size;
733 else
734 ret = -EFAULT;
738 remove_wait_queue(&ir->buf->wait_poll, &wait);
739 set_current_state(TASK_RUNNING);
741 out_locked:
742 mutex_unlock(&ir->irctl_lock);
744 out_unlocked:
745 kfree(buf);
746 dev_dbg(ir->d.dev, LOGHEAD "read result = %s (%d)\n",
747 ir->d.name, ir->d.minor, ret ? "<fail>" : "<ok>", ret);
749 return ret ? ret : written;
751 EXPORT_SYMBOL(lirc_dev_fop_read);
753 void *lirc_get_pdata(struct file *file)
755 void *data = NULL;
757 if (file && file->f_dentry && file->f_dentry->d_inode &&
758 file->f_dentry->d_inode->i_rdev) {
759 struct irctl *ir;
760 ir = irctls[iminor(file->f_dentry->d_inode)];
761 data = ir->d.data;
764 return data;
766 EXPORT_SYMBOL(lirc_get_pdata);
769 ssize_t lirc_dev_fop_write(struct file *file, const char __user *buffer,
770 size_t length, loff_t *ppos)
772 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)];
774 if (!ir) {
775 printk(KERN_ERR "%s: called with invalid irctl\n", __func__);
776 return -ENODEV;
779 dev_dbg(ir->d.dev, LOGHEAD "write called\n", ir->d.name, ir->d.minor);
781 if (!ir->attached)
782 return -ENODEV;
784 return -EINVAL;
786 EXPORT_SYMBOL(lirc_dev_fop_write);
789 static int __init lirc_dev_init(void)
791 int retval;
793 lirc_class = class_create(THIS_MODULE, "lirc");
794 if (IS_ERR(lirc_class)) {
795 retval = PTR_ERR(lirc_class);
796 printk(KERN_ERR "lirc_dev: class_create failed\n");
797 goto error;
800 retval = alloc_chrdev_region(&lirc_base_dev, 0, MAX_IRCTL_DEVICES,
801 IRCTL_DEV_NAME);
802 if (retval) {
803 class_destroy(lirc_class);
804 printk(KERN_ERR "lirc_dev: alloc_chrdev_region failed\n");
805 goto error;
809 printk(KERN_INFO "lirc_dev: IR Remote Control driver registered, "
810 "major %d \n", MAJOR(lirc_base_dev));
812 error:
813 return retval;
818 static void __exit lirc_dev_exit(void)
820 class_destroy(lirc_class);
821 unregister_chrdev_region(lirc_base_dev, MAX_IRCTL_DEVICES);
822 printk(KERN_INFO "lirc_dev: module unloaded\n");
825 module_init(lirc_dev_init);
826 module_exit(lirc_dev_exit);
828 MODULE_DESCRIPTION("LIRC base driver module");
829 MODULE_AUTHOR("Artur Lipowski");
830 MODULE_LICENSE("GPL");
832 module_param(debug, bool, S_IRUGO | S_IWUSR);
833 MODULE_PARM_DESC(debug, "Enable debugging messages");