Skip to content

Commit a6ddd4f

Browse files
seanyoungmchehab
authored andcommitted
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>
1 parent bf01c82 commit a6ddd4f

7 files changed

Lines changed: 60 additions & 193 deletions

File tree

‎Documentation/media/kapi/rc-core.rst‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,3 @@ Remote Controller core
77
.. kernel-doc:: include/media/rc-core.h
88

99
.. kernel-doc:: include/media/rc-map.h
10-
11-
LIRC
12-
~~~~
13-
14-
.. kernel-doc:: include/media/lirc_dev.h

‎drivers/media/rc/ir-lirc-codec.c‎

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
* GNU General Public License for more details.
1313
*/
1414

15+
#include <linux/poll.h>
1516
#include <linux/sched.h>
1617
#include <linux/wait.h>
1718
#include <media/lirc.h>
18-
#include <media/lirc_dev.h>
1919
#include <media/rc-core.h>
2020
#include "rc-core-priv.h"
2121

@@ -90,8 +90,8 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev)
9090

9191
static int ir_lirc_open(struct inode *inode, struct file *file)
9292
{
93-
struct lirc_dev *d = container_of(inode->i_cdev, struct lirc_dev, cdev);
94-
struct rc_dev *dev = d->rdev;
93+
struct rc_dev *dev = container_of(inode->i_cdev, struct rc_dev,
94+
lirc_cdev);
9595
int retval;
9696

9797
retval = rc_open(dev);
@@ -523,7 +523,7 @@ static ssize_t ir_lirc_read(struct file *file, char __user *buffer,
523523
return copied;
524524
}
525525

526-
static const struct file_operations lirc_fops = {
526+
const struct file_operations lirc_fops = {
527527
.owner = THIS_MODULE,
528528
.write = ir_lirc_transmit_ir,
529529
.unlocked_ioctl = ir_lirc_ioctl,
@@ -536,36 +536,3 @@ static const struct file_operations lirc_fops = {
536536
.release = ir_lirc_close,
537537
.llseek = no_llseek,
538538
};
539-
540-
int 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-
562-
out:
563-
lirc_free_device(ldev);
564-
return rc;
565-
}
566-
567-
void ir_lirc_unregister(struct rc_dev *dev)
568-
{
569-
lirc_unregister_device(dev->lirc_dev);
570-
dev->lirc_dev = NULL;
571-
}

‎drivers/media/rc/lirc_dev.c‎

Lines changed: 48 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -18,149 +18,100 @@
1818
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1919

2020
#include <linux/module.h>
21-
#include <linux/sched/signal.h>
22-
#include <linux/ioctl.h>
23-
#include <linux/poll.h>
2421
#include <linux/mutex.h>
2522
#include <linux/device.h>
26-
#include <linux/cdev.h>
2723
#include <linux/idr.h>
24+
#include <linux/poll.h>
2825

2926
#include "rc-core-priv.h"
3027
#include <media/lirc.h>
31-
#include <media/lirc_dev.h>
3228

3329
#define LOGHEAD "lirc_dev (%s[%d]): "
3430

3531
static dev_t lirc_base_dev;
3632

3733
/* Used to keep track of allocated lirc devices */
38-
#define LIRC_MAX_DEVICES 256
3934
static DEFINE_IDA(lirc_ida);
4035

4136
/* Only used for sysfs but defined to void otherwise */
4237
static struct class *lirc_class;
4338

4439
static void lirc_release_device(struct device *ld)
4540
{
46-
struct lirc_dev *d = container_of(ld, struct lirc_dev, dev);
47-
struct rc_dev *rcdev = d->rdev;
41+
struct rc_dev *rcdev = container_of(ld, struct rc_dev, lirc_dev);
4842

4943
if (rcdev->driver_type == RC_DRIVER_IR_RAW)
5044
kfifo_free(&rcdev->rawir);
5145

52-
kfree(d);
53-
module_put(THIS_MODULE);
54-
put_device(d->dev.parent);
55-
}
56-
57-
struct lirc_dev *
58-
lirc_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-
}
72-
EXPORT_SYMBOL(lirc_allocate_device);
73-
74-
void lirc_free_device(struct lirc_dev *d)
75-
{
76-
if (!d)
77-
return;
78-
79-
put_device(&d->dev);
46+
put_device(&rcdev->dev);
8047
}
81-
EXPORT_SYMBOL(lirc_free_device);
8248

83-
int lirc_register_device(struct lirc_dev *d)
49+
int ir_lirc_register(struct rc_dev *dev)
8450
{
85-
struct rc_dev *rcdev = d->rdev;
86-
int minor;
87-
int err;
51+
int err, minor;
8852

89-
if (!d) {
90-
pr_err("driver pointer must be not NULL!\n");
91-
return -EBADRQC;
92-
}
53+
device_initialize(&dev->lirc_dev);
54+
dev->lirc_dev.class = lirc_class;
55+
dev->lirc_dev.release = lirc_release_device;
56+
dev->send_mode = LIRC_MODE_PULSE;
9357

94-
if (!d->dev.parent) {
95-
pr_err("dev parent pointer not filled in!\n");
96-
return -EINVAL;
58+
if (dev->driver_type == RC_DRIVER_IR_RAW) {
59+
if (kfifo_alloc(&dev->rawir, MAX_IR_EVENT_SIZE, GFP_KERNEL))
60+
return -ENOMEM;
9761
}
9862

99-
if (!d->fops) {
100-
pr_err("fops pointer not filled in!\n");
101-
return -EINVAL;
102-
}
63+
init_waitqueue_head(&dev->wait_poll);
10364

104-
if (rcdev->driver_type == RC_DRIVER_IR_RAW) {
105-
if (kfifo_alloc(&rcdev->rawir, MAX_IR_EVENT_SIZE, GFP_KERNEL))
106-
return -ENOMEM;
65+
minor = ida_simple_get(&lirc_ida, 0, RC_DEV_MAX, GFP_KERNEL);
66+
if (minor < 0) {
67+
err = minor;
68+
goto out_kfifo;
10769
}
10870

109-
init_waitqueue_head(&rcdev->wait_poll);
110-
111-
minor = ida_simple_get(&lirc_ida, 0, LIRC_MAX_DEVICES, GFP_KERNEL);
112-
if (minor < 0)
113-
return minor;
71+
dev->lirc_dev.parent = &dev->dev;
72+
dev->lirc_dev.devt = MKDEV(MAJOR(lirc_base_dev), minor);
73+
dev_set_name(&dev->lirc_dev, "lirc%d", minor);
11474

115-
d->minor = minor;
116-
d->dev.devt = MKDEV(MAJOR(lirc_base_dev), d->minor);
117-
dev_set_name(&d->dev, "lirc%d", d->minor);
75+
cdev_init(&dev->lirc_cdev, &lirc_fops);
11876

119-
cdev_init(&d->cdev, d->fops);
120-
d->cdev.owner = d->owner;
77+
err = cdev_device_add(&dev->lirc_cdev, &dev->lirc_dev);
78+
if (err)
79+
goto out_ida;
12180

122-
err = cdev_device_add(&d->cdev, &d->dev);
123-
if (err) {
124-
ida_simple_remove(&lirc_ida, minor);
125-
return err;
126-
}
81+
get_device(&dev->dev);
12782

128-
get_device(d->dev.parent);
129-
130-
dev_info(&d->dev, "lirc_dev: driver %s registered at minor = %d\n",
131-
rcdev->driver_name, d->minor);
83+
dev_info(&dev->dev, "lirc_dev: driver %s registered at minor = %d",
84+
dev->driver_name, minor);
13285

13386
return 0;
87+
88+
out_ida:
89+
ida_simple_remove(&lirc_ida, minor);
90+
out_kfifo:
91+
if (dev->driver_type == RC_DRIVER_IR_RAW)
92+
kfifo_free(&dev->rawir);
93+
return err;
13494
}
135-
EXPORT_SYMBOL(lirc_register_device);
13695

137-
void lirc_unregister_device(struct lirc_dev *d)
96+
void ir_lirc_unregister(struct rc_dev *dev)
13897
{
139-
struct rc_dev *rcdev;
140-
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);
98+
dev_dbg(&dev->dev, "lirc_dev: driver %s unregistered from minor = %d\n",
99+
dev->driver_name, MINOR(dev->lirc_dev.devt));
148100

149-
mutex_lock(&rcdev->lock);
101+
mutex_lock(&dev->lock);
150102

151-
if (rcdev->lirc_open) {
152-
dev_dbg(&d->dev, LOGHEAD "releasing opened driver\n",
153-
rcdev->driver_name, d->minor);
154-
wake_up_poll(&rcdev->wait_poll, POLLHUP);
103+
if (dev->lirc_open) {
104+
dev_dbg(&dev->dev, LOGHEAD "releasing opened driver\n",
105+
dev->driver_name, MINOR(dev->lirc_dev.devt));
106+
wake_up_poll(&dev->wait_poll, POLLHUP);
155107
}
156108

157-
mutex_unlock(&rcdev->lock);
109+
mutex_unlock(&dev->lock);
158110

159-
cdev_device_del(&d->cdev, &d->dev);
160-
ida_simple_remove(&lirc_ida, d->minor);
161-
put_device(&d->dev);
111+
cdev_device_del(&dev->lirc_cdev, &dev->lirc_dev);
112+
ida_simple_remove(&lirc_ida, MINOR(dev->lirc_dev.devt));
113+
put_device(&dev->lirc_dev);
162114
}
163-
EXPORT_SYMBOL(lirc_unregister_device);
164115

165116
int __init lirc_dev_init(void)
166117
{
@@ -172,7 +123,7 @@ int __init lirc_dev_init(void)
172123
return PTR_ERR(lirc_class);
173124
}
174125

175-
retval = alloc_chrdev_region(&lirc_base_dev, 0, LIRC_MAX_DEVICES,
126+
retval = alloc_chrdev_region(&lirc_base_dev, 0, RC_DEV_MAX,
176127
"BaseRemoteCtl");
177128
if (retval) {
178129
class_destroy(lirc_class);
@@ -189,5 +140,5 @@ int __init lirc_dev_init(void)
189140
void __exit lirc_dev_exit(void)
190141
{
191142
class_destroy(lirc_class);
192-
unregister_chrdev_region(lirc_base_dev, LIRC_MAX_DEVICES);
143+
unregister_chrdev_region(lirc_base_dev, RC_DEV_MAX);
193144
}

‎drivers/media/rc/rc-core-priv.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef _RC_CORE_PRIV
77
#define _RC_CORE_PRIV
88

9+
#define RC_DEV_MAX 256
910
/* Define the max number of pulse/space transitions to buffer */
1011
#define MAX_IR_EVENT_SIZE 512
1112

@@ -277,6 +278,8 @@ void lirc_dev_exit(void);
277278
void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev);
278279
int ir_lirc_register(struct rc_dev *dev);
279280
void ir_lirc_unregister(struct rc_dev *dev);
281+
282+
extern const struct file_operations lirc_fops;
280283
#else
281284
static inline int lirc_dev_init(void) { return 0; }
282285
static inline void lirc_dev_exit(void) {}

‎drivers/media/rc/rc-main.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
/* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */
2121
#define IR_TAB_MIN_SIZE 256
2222
#define IR_TAB_MAX_SIZE 8192
23-
#define RC_DEV_MAX 256
2423

2524
static const struct {
2625
const char *name;

‎include/media/lirc_dev.h‎

Lines changed: 0 additions & 50 deletions
This file was deleted.

‎include/media/rc-core.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
#define _RC_CORE
1818

1919
#include <linux/spinlock.h>
20+
#include <linux/cdev.h>
2021
#include <linux/kfifo.h>
2122
#include <linux/time.h>
2223
#include <linux/timer.h>
23-
#include <media/lirc_dev.h>
2424
#include <media/rc-map.h>
2525

2626
extern int rc_core_debug;
@@ -116,7 +116,8 @@ enum rc_filter_type {
116116
* @max_timeout: maximum timeout supported by device
117117
* @rx_resolution : resolution (in ns) of input sampler
118118
* @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
120121
* @lirc_open: count of the number of times the device has been opened
121122
* @carrier_low: when setting the carrier range, first the low end must be
122123
* set with an ioctl and then the high end with another ioctl
@@ -190,7 +191,8 @@ struct rc_dev {
190191
u32 rx_resolution;
191192
u32 tx_resolution;
192193
#ifdef CONFIG_LIRC
193-
struct lirc_dev *lirc_dev;
194+
struct device lirc_dev;
195+
struct cdev lirc_cdev;
194196
int lirc_open;
195197
int carrier_low;
196198
ktime_t gap_start;

0 commit comments

Comments
 (0)