Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] media: lirc: Allow lirc dev to talk to rc device

The use case is simple, if any rc device has allowed protocols =
RC_TYPE_LIRC and map_name = RC_MAP_LIRC set, the driver open will be never
called. The reason for this is, all of the key maps except lirc have some
KEYS in there map, so during rc_register_device process these keys are
matched against the input drivers and open is performed, so for the case
of RC_MAP_EMPTY, a vt/keyboard is matched and the driver open is
performed.
In case of lirc, there is no match and result is that there is no open
performed, however the lirc-dev will go ahead and create a /dev/lirc0
node. Now when lircd/mode2 opens this device, no data is available
because the driver was never opened.
Other case pointed by Sean Young, As rc device gets opened via the
input interface. If the input device is never opened (e.g. embedded with
no console) then the rc open is never called and lirc will not work
either. So that's another case.
lirc_dev seems to have no link with actual rc device w.r.t open/close.
This patch adds rc_dev pointer to lirc_driver structure for cases like
this, so that it can do the open/close of the real driver in accordance
to lircd/mode2 open/close.
Without this patch its impossible to open a rc device which has
RC_TYPE_LIRC ad RC_MAP_LIRC set.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>

authored by

Srinivas Kandagatla and committed by
Mauro Carvalho Chehab
ca7a722d 8b2ff320

+12
+1
drivers/media/rc/ir-lirc-codec.c
··· 384 384 drv->code_length = sizeof(struct ir_raw_event) * 8; 385 385 drv->fops = &lirc_fops; 386 386 drv->dev = &dev->dev; 387 + drv->rdev = dev; 387 388 drv->owner = THIS_MODULE; 388 389 389 390 drv->minor = lirc_register_driver(drv);
+10
drivers/media/rc/lirc_dev.c
··· 35 35 #include <linux/device.h> 36 36 #include <linux/cdev.h> 37 37 38 + #include <media/rc-core.h> 38 39 #include <media/lirc.h> 39 40 #include <media/lirc_dev.h> 40 41 ··· 468 467 goto error; 469 468 } 470 469 470 + if (ir->d.rdev) { 471 + retval = rc_open(ir->d.rdev); 472 + if (retval) 473 + goto error; 474 + } 475 + 471 476 cdev = ir->cdev; 472 477 if (try_module_get(cdev->owner)) { 473 478 ir->open++; ··· 517 510 dev_dbg(ir->d.dev, LOGHEAD "close called\n", ir->d.name, ir->d.minor); 518 511 519 512 WARN_ON(mutex_lock_killable(&lirc_dev_lock)); 513 + 514 + if (ir->d.rdev) 515 + rc_close(ir->d.rdev); 520 516 521 517 ir->open--; 522 518 if (ir->attached) {
+1
include/media/lirc_dev.h
··· 139 139 struct lirc_buffer *rbuf; 140 140 int (*set_use_inc) (void *data); 141 141 void (*set_use_dec) (void *data); 142 + struct rc_dev *rdev; 142 143 const struct file_operations *fops; 143 144 struct device *dev; 144 145 struct module *owner;