aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/rc/lirc_dev.c
diff options
context:
space:
mode:
authorSean Young <sean@mess.org>2017-09-26 09:34:47 -0400
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2017-12-14 10:35:20 -0500
commita6ddd4fecbb02d8ec5a865621bd2b746d585a01c (patch)
tree0e76fef0b0e2e866587d045c69896db77bd7031f /drivers/media/rc/lirc_dev.c
parentbf01c82474bf1f5c07d90a0959a95ff51374cc6f (diff)
media: lirc: remove last remnants of lirc kapi
rc-core has replaced the lirc kapi many years ago, and now with the last driver ported to rc-core, we can finally remove it. Note this has no effect on userspace. All future IR drivers should use the rc-core api. Signed-off-by: Sean Young <sean@mess.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'drivers/media/rc/lirc_dev.c')
-rw-r--r--drivers/media/rc/lirc_dev.c145
1 files changed, 48 insertions, 97 deletions
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index 4ac74fd86fd4..155a4de249a0 100644
--- a/drivers/media/rc/lirc_dev.c
+++ b/drivers/media/rc/lirc_dev.c
@@ -18,24 +18,19 @@
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 19
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/sched/signal.h>
22#include <linux/ioctl.h>
23#include <linux/poll.h>
24#include <linux/mutex.h> 21#include <linux/mutex.h>
25#include <linux/device.h> 22#include <linux/device.h>
26#include <linux/cdev.h>
27#include <linux/idr.h> 23#include <linux/idr.h>
24#include <linux/poll.h>
28 25
29#include "rc-core-priv.h" 26#include "rc-core-priv.h"
30#include <media/lirc.h> 27#include <media/lirc.h>
31#include <media/lirc_dev.h>
32 28
33#define LOGHEAD "lirc_dev (%s[%d]): " 29#define LOGHEAD "lirc_dev (%s[%d]): "
34 30
35static dev_t lirc_base_dev; 31static dev_t lirc_base_dev;
36 32
37/* Used to keep track of allocated lirc devices */ 33/* Used to keep track of allocated lirc devices */
38#define LIRC_MAX_DEVICES 256
39static DEFINE_IDA(lirc_ida); 34static DEFINE_IDA(lirc_ida);
40 35
41/* Only used for sysfs but defined to void otherwise */ 36/* Only used for sysfs but defined to void otherwise */
@@ -43,124 +38,80 @@ static struct class *lirc_class;
43 38
44static void lirc_release_device(struct device *ld) 39static void lirc_release_device(struct device *ld)
45{ 40{
46 struct lirc_dev *d = container_of(ld, struct lirc_dev, dev); 41 struct rc_dev *rcdev = container_of(ld, struct rc_dev, lirc_dev);
47 struct rc_dev *rcdev = d->rdev;
48 42
49 if (rcdev->driver_type == RC_DRIVER_IR_RAW) 43 if (rcdev->driver_type == RC_DRIVER_IR_RAW)
50 kfifo_free(&rcdev->rawir); 44 kfifo_free(&rcdev->rawir);
51 45
52 kfree(d); 46 put_device(&rcdev->dev);
53 module_put(THIS_MODULE);
54 put_device(d->dev.parent);
55}
56
57struct lirc_dev *
58lirc_allocate_device(void)
59{
60 struct lirc_dev *d;
61
62 d = kzalloc(sizeof(*d), GFP_KERNEL);
63 if (d) {
64 device_initialize(&d->dev);
65 d->dev.class = lirc_class;
66 d->dev.release = lirc_release_device;
67 __module_get(THIS_MODULE);
68 }
69
70 return d;
71}
72EXPORT_SYMBOL(lirc_allocate_device);
73
74void lirc_free_device(struct lirc_dev *d)
75{
76 if (!d)
77 return;
78
79 put_device(&d->dev);
80} 47}
81EXPORT_SYMBOL(lirc_free_device);
82 48
83int lirc_register_device(struct lirc_dev *d) 49int ir_lirc_register(struct rc_dev *dev)
84{ 50{
85 struct rc_dev *rcdev = d->rdev; 51 int err, minor;
86 int minor;
87 int err;
88 52
89 if (!d) { 53 device_initialize(&dev->lirc_dev);
90 pr_err("driver pointer must be not NULL!\n"); 54 dev->lirc_dev.class = lirc_class;
91 return -EBADRQC; 55 dev->lirc_dev.release = lirc_release_device;
92 } 56 dev->send_mode = LIRC_MODE_PULSE;
93 57
94 if (!d->dev.parent) { 58 if (dev->driver_type == RC_DRIVER_IR_RAW) {
95 pr_err("dev parent pointer not filled in!\n"); 59 if (kfifo_alloc(&dev->rawir, MAX_IR_EVENT_SIZE, GFP_KERNEL))
96 return -EINVAL; 60 return -ENOMEM;
97 } 61 }
98 62
99 if (!d->fops) { 63 init_waitqueue_head(&dev->wait_poll);
100 pr_err("fops pointer not filled in!\n");
101 return -EINVAL;
102 }
103 64
104 if (rcdev->driver_type == RC_DRIVER_IR_RAW) { 65 minor = ida_simple_get(&lirc_ida, 0, RC_DEV_MAX, GFP_KERNEL);
105 if (kfifo_alloc(&rcdev->rawir, MAX_IR_EVENT_SIZE, GFP_KERNEL)) 66 if (minor < 0) {
106 return -ENOMEM; 67 err = minor;
68 goto out_kfifo;
107 } 69 }
108 70
109 init_waitqueue_head(&rcdev->wait_poll); 71 dev->lirc_dev.parent = &dev->dev;
110 72 dev->lirc_dev.devt = MKDEV(MAJOR(lirc_base_dev), minor);
111 minor = ida_simple_get(&lirc_ida, 0, LIRC_MAX_DEVICES, GFP_KERNEL); 73 dev_set_name(&dev->lirc_dev, "lirc%d", minor);
112 if (minor < 0)
113 return minor;
114 74
115 d->minor = minor; 75 cdev_init(&dev->lirc_cdev, &lirc_fops);
116 d->dev.devt = MKDEV(MAJOR(lirc_base_dev), d->minor);
117 dev_set_name(&d->dev, "lirc%d", d->minor);
118 76
119 cdev_init(&d->cdev, d->fops); 77 err = cdev_device_add(&dev->lirc_cdev, &dev->lirc_dev);
120 d->cdev.owner = d->owner; 78 if (err)
79 goto out_ida;
121 80
122 err = cdev_device_add(&d->cdev, &d->dev); 81 get_device(&dev->dev);
123 if (err) {
124 ida_simple_remove(&lirc_ida, minor);
125 return err;
126 }
127 82
128 get_device(d->dev.parent); 83 dev_info(&dev->dev, "lirc_dev: driver %s registered at minor = %d",
129 84 dev->driver_name, minor);
130 dev_info(&d->dev, "lirc_dev: driver %s registered at minor = %d\n",
131 rcdev->driver_name, d->minor);
132 85
133 return 0; 86 return 0;
87
88out_ida:
89 ida_simple_remove(&lirc_ida, minor);
90out_kfifo:
91 if (dev->driver_type == RC_DRIVER_IR_RAW)
92 kfifo_free(&dev->rawir);
93 return err;
134} 94}
135EXPORT_SYMBOL(lirc_register_device);
136 95
137void lirc_unregister_device(struct lirc_dev *d) 96void ir_lirc_unregister(struct rc_dev *dev)
138{ 97{
139 struct rc_dev *rcdev; 98 dev_dbg(&dev->dev, "lirc_dev: driver %s unregistered from minor = %d\n",
140 99 dev->driver_name, MINOR(dev->lirc_dev.devt));
141 if (!d)
142 return;
143
144 rcdev = d->rdev;
145
146 dev_dbg(&d->dev, "lirc_dev: driver %s unregistered from minor = %d\n",
147 rcdev->driver_name, d->minor);
148 100
149 mutex_lock(&rcdev->lock); 101 mutex_lock(&dev->lock);
150 102
151 if (rcdev->lirc_open) { 103 if (dev->lirc_open) {
152 dev_dbg(&d->dev, LOGHEAD "releasing opened driver\n", 104 dev_dbg(&dev->dev, LOGHEAD "releasing opened driver\n",
153 rcdev->driver_name, d->minor); 105 dev->driver_name, MINOR(dev->lirc_dev.devt));
154 wake_up_poll(&rcdev->wait_poll, POLLHUP); 106 wake_up_poll(&dev->wait_poll, POLLHUP);
155 } 107 }
156 108
157 mutex_unlock(&rcdev->lock); 109 mutex_unlock(&dev->lock);
158 110
159 cdev_device_del(&d->cdev, &d->dev); 111 cdev_device_del(&dev->lirc_cdev, &dev->lirc_dev);
160 ida_simple_remove(&lirc_ida, d->minor); 112 ida_simple_remove(&lirc_ida, MINOR(dev->lirc_dev.devt));
161 put_device(&d->dev); 113 put_device(&dev->lirc_dev);
162} 114}
163EXPORT_SYMBOL(lirc_unregister_device);
164 115
165int __init lirc_dev_init(void) 116int __init lirc_dev_init(void)
166{ 117{
@@ -172,7 +123,7 @@ int __init lirc_dev_init(void)
172 return PTR_ERR(lirc_class); 123 return PTR_ERR(lirc_class);
173 } 124 }
174 125
175 retval = alloc_chrdev_region(&lirc_base_dev, 0, LIRC_MAX_DEVICES, 126 retval = alloc_chrdev_region(&lirc_base_dev, 0, RC_DEV_MAX,
176 "BaseRemoteCtl"); 127 "BaseRemoteCtl");
177 if (retval) { 128 if (retval) {
178 class_destroy(lirc_class); 129 class_destroy(lirc_class);
@@ -189,5 +140,5 @@ int __init lirc_dev_init(void)
189void __exit lirc_dev_exit(void) 140void __exit lirc_dev_exit(void)
190{ 141{
191 class_destroy(lirc_class); 142 class_destroy(lirc_class);
192 unregister_chrdev_region(lirc_base_dev, LIRC_MAX_DEVICES); 143 unregister_chrdev_region(lirc_base_dev, RC_DEV_MAX);
193} 144}