Skip to content

Commit a60d64b

Browse files
seanyoungmchehab
authored andcommitted
media: lirc: lirc interface should not be a raw decoder
The lirc user interface exists as a raw decoder, which does not make much sense for transmit-only devices. In addition, we want to have lirc char devices for devices which do not use raw IR, i.e. scancode only devices. Note that rc-code, lirc_dev, ir-lirc-codec are now calling functions of each other, so they've been merged into one module rc-core to avoid circular dependencies. Since ir-lirc-codec no longer exists as separate codec module, there is no need for RC_DRIVER_IR_RAW_TX type drivers to call ir_raw_event_register(). Signed-off-by: Sean Young <sean@mess.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
1 parent 0d39ab0 commit a60d64b

10 files changed

Lines changed: 143 additions & 243 deletions

File tree

‎drivers/media/rc/Kconfig‎

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,21 @@ menuconfig RC_CORE
1616
if RC_CORE
1717
source "drivers/media/rc/keymaps/Kconfig"
1818

19-
menuconfig RC_DECODERS
20-
bool "Remote controller decoders"
21-
depends on RC_CORE
22-
default y
23-
24-
if RC_DECODERS
2519
config LIRC
26-
tristate "LIRC interface driver"
20+
bool "LIRC user interface"
2721
depends on RC_CORE
28-
2922
---help---
30-
Enable this option to build the Linux Infrared Remote
31-
Control (LIRC) core device interface driver. The LIRC
32-
interface passes raw IR to and from userspace, where the
33-
LIRC daemon handles protocol decoding for IR reception and
34-
encoding for IR transmitting (aka "blasting").
23+
Enable this option to enable the Linux Infrared Remote
24+
Control user interface (e.g. /dev/lirc*). This interface
25+
passes raw IR to and from userspace, which is needed for
26+
IR transmitting (aka "blasting") and for the lirc daemon.
3527

36-
config IR_LIRC_CODEC
37-
tristate "Enable IR to LIRC bridge"
28+
menuconfig RC_DECODERS
29+
bool "Remote controller decoders"
3830
depends on RC_CORE
39-
depends on LIRC
4031
default y
4132

42-
---help---
43-
Enable this option to pass raw IR to and from userspace via
44-
the LIRC interface.
45-
46-
33+
if RC_DECODERS
4734
config IR_NEC_DECODER
4835
tristate "Enable IR raw decoder for the NEC protocol"
4936
depends on RC_CORE

‎drivers/media/rc/Makefile‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
rc-core-objs := rc-main.o rc-ir-raw.o
32

43
obj-y += keymaps/
54

65
obj-$(CONFIG_RC_CORE) += rc-core.o
7-
obj-$(CONFIG_LIRC) += lirc_dev.o
6+
rc-core-y := rc-main.o rc-ir-raw.o
7+
rc-core-$(CONFIG_LIRC) += lirc_dev.o ir-lirc-codec.o
88
obj-$(CONFIG_IR_NEC_DECODER) += ir-nec-decoder.o
99
obj-$(CONFIG_IR_RC5_DECODER) += ir-rc5-decoder.o
1010
obj-$(CONFIG_IR_RC6_DECODER) += ir-rc6-decoder.o
@@ -13,7 +13,6 @@ obj-$(CONFIG_IR_SONY_DECODER) += ir-sony-decoder.o
1313
obj-$(CONFIG_IR_SANYO_DECODER) += ir-sanyo-decoder.o
1414
obj-$(CONFIG_IR_SHARP_DECODER) += ir-sharp-decoder.o
1515
obj-$(CONFIG_IR_MCE_KBD_DECODER) += ir-mce_kbd-decoder.o
16-
obj-$(CONFIG_IR_LIRC_CODEC) += ir-lirc-codec.o
1716
obj-$(CONFIG_IR_XMP_DECODER) += ir-xmp-decoder.o
1817

1918
# stand-alone IR receivers/transmitters

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

Lines changed: 36 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include <linux/sched.h>
1616
#include <linux/wait.h>
17-
#include <linux/module.h>
1817
#include <media/lirc.h>
1918
#include <media/lirc_dev.h>
2019
#include <media/rc-core.h>
@@ -23,21 +22,15 @@
2322
#define LIRCBUF_SIZE 256
2423

2524
/**
26-
* ir_lirc_decode() - Send raw IR data to lirc_dev to be relayed to the
27-
* lircd userspace daemon for decoding.
25+
* ir_lirc_raw_event() - Send raw IR data to lirc to be relayed to userspace
26+
*
2827
* @dev: the struct rc_dev descriptor of the device
2928
* @ev: the struct ir_raw_event descriptor of the pulse/space
30-
*
31-
* This function returns -EINVAL if the lirc interfaces aren't wired up.
3229
*/
33-
static int ir_lirc_decode(struct rc_dev *dev, struct ir_raw_event ev)
30+
void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev)
3431
{
35-
struct lirc_codec *lirc = &dev->raw->lirc;
3632
int sample;
3733

38-
if (!dev->raw->lirc.ldev || !dev->raw->lirc.ldev->buf)
39-
return -EINVAL;
40-
4134
/* Packet start */
4235
if (ev.reset) {
4336
/* Userspace expects a long space event before the start of
@@ -56,37 +49,37 @@ static int ir_lirc_decode(struct rc_dev *dev, struct ir_raw_event ev)
5649
/* Packet end */
5750
} else if (ev.timeout) {
5851

59-
if (lirc->gap)
60-
return 0;
52+
if (dev->gap)
53+
return;
6154

62-
lirc->gap_start = ktime_get();
63-
lirc->gap = true;
64-
lirc->gap_duration = ev.duration;
55+
dev->gap_start = ktime_get();
56+
dev->gap = true;
57+
dev->gap_duration = ev.duration;
6558

66-
if (!lirc->send_timeout_reports)
67-
return 0;
59+
if (!dev->send_timeout_reports)
60+
return;
6861

6962
sample = LIRC_TIMEOUT(ev.duration / 1000);
7063
IR_dprintk(2, "timeout report (duration: %d)\n", sample);
7164

7265
/* Normal sample */
7366
} else {
7467

75-
if (lirc->gap) {
68+
if (dev->gap) {
7669
int gap_sample;
7770

78-
lirc->gap_duration += ktime_to_ns(ktime_sub(ktime_get(),
79-
lirc->gap_start));
71+
dev->gap_duration += ktime_to_ns(ktime_sub(ktime_get(),
72+
dev->gap_start));
8073

8174
/* Convert to ms and cap by LIRC_VALUE_MASK */
82-
do_div(lirc->gap_duration, 1000);
83-
lirc->gap_duration = min(lirc->gap_duration,
84-
(u64)LIRC_VALUE_MASK);
75+
do_div(dev->gap_duration, 1000);
76+
dev->gap_duration = min_t(u64, dev->gap_duration,
77+
LIRC_VALUE_MASK);
8578

86-
gap_sample = LIRC_SPACE(lirc->gap_duration);
87-
lirc_buffer_write(dev->raw->lirc.ldev->buf,
79+
gap_sample = LIRC_SPACE(dev->gap_duration);
80+
lirc_buffer_write(dev->lirc_dev->buf,
8881
(unsigned char *)&gap_sample);
89-
lirc->gap = false;
82+
dev->gap = false;
9083
}
9184

9285
sample = ev.pulse ? LIRC_PULSE(ev.duration / 1000) :
@@ -95,18 +88,16 @@ static int ir_lirc_decode(struct rc_dev *dev, struct ir_raw_event ev)
9588
TO_US(ev.duration), TO_STR(ev.pulse));
9689
}
9790

98-
lirc_buffer_write(dev->raw->lirc.ldev->buf,
91+
lirc_buffer_write(dev->lirc_dev->buf,
9992
(unsigned char *) &sample);
100-
wake_up(&dev->raw->lirc.ldev->buf->wait_poll);
10193

102-
return 0;
94+
wake_up(&dev->lirc_dev->buf->wait_poll);
10395
}
10496

10597
static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
10698
size_t n, loff_t *ppos)
10799
{
108-
struct lirc_codec *lirc;
109-
struct rc_dev *dev;
100+
struct rc_dev *dev = file->private_data;
110101
unsigned int *txbuf = NULL;
111102
struct ir_raw_event *raw = NULL;
112103
ssize_t ret = -EINVAL;
@@ -118,22 +109,12 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
118109

119110
start = ktime_get();
120111

121-
lirc = lirc_get_pdata(file);
122-
if (!lirc)
123-
return -EFAULT;
124-
125-
dev = lirc->dev;
126-
if (!dev) {
127-
ret = -EFAULT;
128-
goto out;
129-
}
130-
131112
if (!dev->tx_ir) {
132113
ret = -EINVAL;
133114
goto out;
134115
}
135116

136-
if (lirc->send_mode == LIRC_MODE_SCANCODE) {
117+
if (dev->send_mode == LIRC_MODE_SCANCODE) {
137118
struct lirc_scancode scan;
138119

139120
if (n != sizeof(scan))
@@ -198,7 +179,7 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
198179
if (ret < 0)
199180
goto out;
200181

201-
if (lirc->send_mode == LIRC_MODE_SCANCODE) {
182+
if (dev->send_mode == LIRC_MODE_SCANCODE) {
202183
ret = n;
203184
} else {
204185
for (duration = i = 0; i < ret; i++)
@@ -228,20 +209,11 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
228209
static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
229210
unsigned long arg)
230211
{
231-
struct lirc_codec *lirc;
232-
struct rc_dev *dev;
212+
struct rc_dev *dev = filep->private_data;
233213
u32 __user *argp = (u32 __user *)(arg);
234214
int ret = 0;
235215
__u32 val = 0, tmp;
236216

237-
lirc = lirc_get_pdata(filep);
238-
if (!lirc)
239-
return -EFAULT;
240-
241-
dev = lirc->dev;
242-
if (!dev)
243-
return -EFAULT;
244-
245217
if (_IOC_DIR(cmd) & _IOC_WRITE) {
246218
ret = get_user(val, argp);
247219
if (ret)
@@ -255,7 +227,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
255227
if (!dev->tx_ir)
256228
return -ENOTTY;
257229

258-
val = lirc->send_mode;
230+
val = dev->send_mode;
259231
break;
260232

261233
case LIRC_SET_SEND_MODE:
@@ -265,7 +237,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
265237
if (!(val == LIRC_MODE_PULSE || val == LIRC_MODE_SCANCODE))
266238
return -EINVAL;
267239

268-
lirc->send_mode = val;
240+
dev->send_mode = val;
269241
return 0;
270242

271243
/* TX settings */
@@ -299,7 +271,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
299271
return -EINVAL;
300272

301273
return dev->s_rx_carrier_range(dev,
302-
dev->raw->lirc.carrier_low,
274+
dev->carrier_low,
303275
val);
304276

305277
case LIRC_SET_REC_CARRIER_RANGE:
@@ -309,7 +281,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
309281
if (val <= 0)
310282
return -EINVAL;
311283

312-
dev->raw->lirc.carrier_low = val;
284+
dev->carrier_low = val;
313285
return 0;
314286

315287
case LIRC_GET_REC_RESOLUTION:
@@ -367,7 +339,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
367339
if (!dev->timeout)
368340
return -ENOTTY;
369341

370-
lirc->send_timeout_reports = !!val;
342+
dev->send_timeout_reports = !!val;
371343
break;
372344

373345
default:
@@ -394,7 +366,7 @@ static const struct file_operations lirc_fops = {
394366
.llseek = no_llseek,
395367
};
396368

397-
static int ir_lirc_register(struct rc_dev *dev)
369+
int ir_lirc_register(struct rc_dev *dev)
398370
{
399371
struct lirc_dev *ldev;
400372
int rc = -ENOMEM;
@@ -436,7 +408,6 @@ static int ir_lirc_register(struct rc_dev *dev)
436408
snprintf(ldev->name, sizeof(ldev->name), "ir-lirc-codec (%s)",
437409
dev->driver_name);
438410
ldev->features = features;
439-
ldev->data = &dev->raw->lirc;
440411
ldev->buf = NULL;
441412
ldev->chunk_size = sizeof(int);
442413
ldev->buffer_size = LIRCBUF_SIZE;
@@ -449,51 +420,17 @@ static int ir_lirc_register(struct rc_dev *dev)
449420
if (rc < 0)
450421
goto out;
451422

452-
dev->raw->lirc.send_mode = LIRC_MODE_PULSE;
453-
454-
dev->raw->lirc.ldev = ldev;
455-
dev->raw->lirc.dev = dev;
423+
dev->send_mode = LIRC_MODE_PULSE;
424+
dev->lirc_dev = ldev;
456425
return 0;
457426

458427
out:
459428
lirc_free_device(ldev);
460429
return rc;
461430
}
462431

463-
static int ir_lirc_unregister(struct rc_dev *dev)
464-
{
465-
struct lirc_codec *lirc = &dev->raw->lirc;
466-
467-
lirc_unregister_device(lirc->ldev);
468-
lirc->ldev = NULL;
469-
470-
return 0;
471-
}
472-
473-
static struct ir_raw_handler lirc_handler = {
474-
.protocols = 0,
475-
.decode = ir_lirc_decode,
476-
.raw_register = ir_lirc_register,
477-
.raw_unregister = ir_lirc_unregister,
478-
};
479-
480-
static int __init ir_lirc_codec_init(void)
432+
void ir_lirc_unregister(struct rc_dev *dev)
481433
{
482-
ir_raw_handler_register(&lirc_handler);
483-
484-
printk(KERN_INFO "IR LIRC bridge handler initialized\n");
485-
return 0;
486-
}
487-
488-
static void __exit ir_lirc_codec_exit(void)
489-
{
490-
ir_raw_handler_unregister(&lirc_handler);
434+
lirc_unregister_device(dev->lirc_dev);
435+
dev->lirc_dev = NULL;
491436
}
492-
493-
module_init(ir_lirc_codec_init);
494-
module_exit(ir_lirc_codec_exit);
495-
496-
MODULE_LICENSE("GPL");
497-
MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>");
498-
MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
499-
MODULE_DESCRIPTION("LIRC IR handler bridge");

‎drivers/media/rc/ir-mce_kbd-decoder.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,6 @@ static int ir_mce_kbd_register(struct rc_dev *dev)
358358
struct input_dev *idev;
359359
int i, ret;
360360

361-
if (dev->driver_type == RC_DRIVER_IR_RAW_TX)
362-
return 0;
363-
364361
idev = input_allocate_device();
365362
if (!idev)
366363
return -ENOMEM;
@@ -415,9 +412,6 @@ static int ir_mce_kbd_unregister(struct rc_dev *dev)
415412
struct mce_kbd_dec *mce_kbd = &dev->raw->mce_kbd;
416413
struct input_dev *idev = mce_kbd->idev;
417414

418-
if (dev->driver_type == RC_DRIVER_IR_RAW_TX)
419-
return 0;
420-
421415
del_timer_sync(&mce_kbd->rx_timeout);
422416
input_unregister_device(idev);
423417

0 commit comments

Comments
 (0)