aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--Documentation/media/kapi/rc-core.rst5
-rw-r--r--drivers/media/rc/ir-lirc-codec.c41
-rw-r--r--drivers/media/rc/lirc_dev.c145
-rw-r--r--drivers/media/rc/rc-core-priv.h3
-rw-r--r--drivers/media/rc/rc-main.c1
-rw-r--r--include/media/lirc_dev.h50
-rw-r--r--include/media/rc-core.h8
7 files changed, 60 insertions, 193 deletions
diff --git a/Documentation/media/kapi/rc-core.rst b/Documentation/media/kapi/rc-core.rst
index a45895886257..41c2256dbf6a 100644
--- a/Documentation/media/kapi/rc-core.rst
+++ b/Documentation/media/kapi/rc-core.rst
@@ -7,8 +7,3 @@ Remote Controller core
7.. kernel-doc:: include/media/rc-core.h 7.. kernel-doc:: include/media/rc-core.h
8 8
9.. kernel-doc:: include/media/rc-map.h 9.. kernel-doc:: include/media/rc-map.h
10
11LIRC
12~~~~
13
14.. kernel-doc:: include/media/lirc_dev.h
diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index 6435306f385b..52daac9bc470 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -12,10 +12,10 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 */ 13 */
14 14
15#include <linux/poll.h>
15#include <linux/sched.h> 16#include <linux/sched.h>
16#include <linux/wait.h> 17#include <linux/wait.h>
17#include <media/lirc.h> 18#include <media/lirc.h>
18#include <media/lirc_dev.h>
19#include <media/rc-core.h> 19#include <media/rc-core.h>
20#include "rc-core-priv.h" 20#include "rc-core-priv.h"
21 21
@@ -90,8 +90,8 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev)
90 90
91static int ir_lirc_open(struct inode *inode, struct file *file) 91static int ir_lirc_open(struct inode *inode, struct file *file)
92{ 92{
93 struct lirc_dev *d = container_of(inode->i_cdev, struct lirc_dev, cdev); 93 struct rc_dev *dev = container_of(inode->i_cdev, struct rc_dev,
94 struct rc_dev *dev = d->rdev; 94 lirc_cdev);
95 int retval; 95 int retval;
96 96
97 retval = rc_open(dev); 97 retval = rc_open(dev);
@@ -523,7 +523,7 @@ static ssize_t ir_lirc_read(struct file *file, char __user *buffer,
523 return copied; 523 return copied;
524} 524}
525 525
526static const struct file_operations lirc_fops = { 526const struct file_operations lirc_fops = {
527 .owner = THIS_MODULE, 527 .owner = THIS_MODULE,
528 .write = ir_lirc_transmit_ir, 528 .write = ir_lirc_transmit_ir,
529 .unlocked_ioctl = ir_lirc_ioctl, 529 .unlocked_ioctl = ir_lirc_ioctl,
@@ -536,36 +536,3 @@ static const struct file_operations lirc_fops = {
536 .release = ir_lirc_close, 536 .release = ir_lirc_close,
537 .llseek = no_llseek, 537 .llseek = no_llseek,
538}; 538};
539
540int ir_lirc_register(struct rc_dev *dev)
541{
542 struct lirc_dev *ldev;
543 int rc = -ENOMEM;
544
545 ldev = lirc_allocate_device();
546 if (!ldev)
547 return rc;
548
549 ldev->fops = &lirc_fops;
550 ldev->dev.parent = &dev->dev;
551 ldev->rdev = dev;
552 ldev->owner = THIS_MODULE;
553
554 rc = lirc_register_device(ldev);
555 if (rc < 0)
556 goto out;
557
558 dev->send_mode = LIRC_MODE_PULSE;
559 dev->lirc_dev = ldev;
560 return 0;
561
562out:
563 lirc_free_device(ldev);
564 return rc;
565}
566
567void ir_lirc_unregister(struct rc_dev *dev)
568{
569 lirc_unregister_device(dev->lirc_dev);
570 dev->lirc_dev = NULL;
571}
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}
diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h
index 6d5a36b8b550..9af43d16ca29 100644
--- a/drivers/media/rc/rc-core-priv.h
+++ b/drivers/media/rc/rc-core-priv.h
@@ -6,6 +6,7 @@
6#ifndef _RC_CORE_PRIV 6#ifndef _RC_CORE_PRIV
7#define _RC_CORE_PRIV 7#define _RC_CORE_PRIV
8 8
9#define RC_DEV_MAX 256
9/* Define the max number of pulse/space transitions to buffer */ 10/* Define the max number of pulse/space transitions to buffer */
10#define MAX_IR_EVENT_SIZE 512 11#define MAX_IR_EVENT_SIZE 512
11 12
@@ -277,6 +278,8 @@ void lirc_dev_exit(void);
277void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev); 278void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev);
278int ir_lirc_register(struct rc_dev *dev); 279int ir_lirc_register(struct rc_dev *dev);
279void ir_lirc_unregister(struct rc_dev *dev); 280void ir_lirc_unregister(struct rc_dev *dev);
281
282extern const struct file_operations lirc_fops;
280#else 283#else
281static inline int lirc_dev_init(void) { return 0; } 284static inline int lirc_dev_init(void) { return 0; }
282static inline void lirc_dev_exit(void) {} 285static inline void lirc_dev_exit(void) {}
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index ace00e77c96a..12ff6d87b113 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -20,7 +20,6 @@
20/* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */ 20/* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */
21#define IR_TAB_MIN_SIZE 256 21#define IR_TAB_MIN_SIZE 256
22#define IR_TAB_MAX_SIZE 8192 22#define IR_TAB_MAX_SIZE 8192
23#define RC_DEV_MAX 256
24 23
25static const struct { 24static const struct {
26 const char *name; 25 const char *name;
diff --git a/include/media/lirc_dev.h b/include/media/lirc_dev.h
deleted file mode 100644
index d12e1d1c3d67..000000000000
--- a/include/media/lirc_dev.h
+++ /dev/null
@@ -1,50 +0,0 @@
1/*
2 * LIRC base driver
3 *
4 * by Artur Lipowski <alipowski@interia.pl>
5 * This code is licensed under GNU GPL
6 *
7 */
8
9#ifndef _LINUX_LIRC_DEV_H
10#define _LINUX_LIRC_DEV_H
11
12#include <linux/slab.h>
13#include <linux/fs.h>
14#include <linux/ioctl.h>
15#include <linux/poll.h>
16#include <linux/kfifo.h>
17#include <media/lirc.h>
18#include <linux/device.h>
19#include <linux/cdev.h>
20
21/**
22 * struct lirc_dev - represents a LIRC device
23 *
24 * @minor: the minor device (/dev/lircX) number for the device
25 * @rdev: &struct rc_dev associated with the device
26 * @fops: &struct file_operations for the device
27 * @owner: the module owning this struct
28 * @dev: &struct device assigned to the device
29 * @cdev: &struct cdev assigned to the device
30 */
31struct lirc_dev {
32 unsigned int minor;
33
34 struct rc_dev *rdev;
35 const struct file_operations *fops;
36 struct module *owner;
37
38 struct device dev;
39 struct cdev cdev;
40};
41
42struct lirc_dev *lirc_allocate_device(void);
43
44void lirc_free_device(struct lirc_dev *d);
45
46int lirc_register_device(struct lirc_dev *d);
47
48void lirc_unregister_device(struct lirc_dev *d);
49
50#endif
diff --git a/include/media/rc-core.h b/include/media/rc-core.h
index 4f585bff1347..2d24c88652aa 100644
--- a/include/media/rc-core.h
+++ b/include/media/rc-core.h
@@ -17,10 +17,10 @@
17#define _RC_CORE 17#define _RC_CORE
18 18
19#include <linux/spinlock.h> 19#include <linux/spinlock.h>
20#include <linux/cdev.h>
20#include <linux/kfifo.h> 21#include <linux/kfifo.h>
21#include <linux/time.h> 22#include <linux/time.h>
22#include <linux/timer.h> 23#include <linux/timer.h>
23#include <media/lirc_dev.h>
24#include <media/rc-map.h> 24#include <media/rc-map.h>
25 25
26extern int rc_core_debug; 26extern int rc_core_debug;
@@ -116,7 +116,8 @@ enum rc_filter_type {
116 * @max_timeout: maximum timeout supported by device 116 * @max_timeout: maximum timeout supported by device
117 * @rx_resolution : resolution (in ns) of input sampler 117 * @rx_resolution : resolution (in ns) of input sampler
118 * @tx_resolution: resolution (in ns) of output sampler 118 * @tx_resolution: resolution (in ns) of output sampler
119 * @lirc_dev: lirc char device 119 * @lirc_dev: lirc device
120 * @lirc_cdev: lirc char cdev
120 * @lirc_open: count of the number of times the device has been opened 121 * @lirc_open: count of the number of times the device has been opened
121 * @carrier_low: when setting the carrier range, first the low end must be 122 * @carrier_low: when setting the carrier range, first the low end must be
122 * set with an ioctl and then the high end with another ioctl 123 * set with an ioctl and then the high end with another ioctl
@@ -190,7 +191,8 @@ struct rc_dev {
190 u32 rx_resolution; 191 u32 rx_resolution;
191 u32 tx_resolution; 192 u32 tx_resolution;
192#ifdef CONFIG_LIRC 193#ifdef CONFIG_LIRC
193 struct lirc_dev *lirc_dev; 194 struct device lirc_dev;
195 struct cdev lirc_cdev;
194 int lirc_open; 196 int lirc_open;
195 int carrier_low; 197 int carrier_low;
196 ktime_t gap_start; 198 ktime_t gap_start;