From 8b2ff3204909687be26f20d63dcddc8e3d7a6c14 Mon Sep 17 00:00:00 2001 From: Srinivas Kandagatla Date: Mon, 22 Jul 2013 04:22:57 -0300 Subject: [media] media: rc: Add rc_open/close and use count to rc_dev This patch adds user count to rc_dev structure, the reason to add this new member is to allow other code like lirc to open rc device directly. In the existing code, rc device is only opened by input subsystem which works ok if we have any input drivers to match. But in case like lirc where there will be no input driver, rc device will be never opened. Having this user count variable will be usefull to allow rc device to be opened from code other than rc-main. This patch also adds rc_open and rc_close functions for other drivers like lirc to open and close rc devices. This functions safely increment and decrement the user count. Other driver wanting to open rc device should call rc_open and rc_close, rather than directly modifying the rc_dev structure. Signed-off-by: Srinivas Kandagatla Signed-off-by: Mauro Carvalho Chehab --- drivers/media/rc/rc-main.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'drivers/media/rc/rc-main.c') diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index 1cf382a0b27..1dedebda1ce 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c @@ -699,19 +699,50 @@ void rc_keydown_notimeout(struct rc_dev *dev, int scancode, u8 toggle) } EXPORT_SYMBOL_GPL(rc_keydown_notimeout); +int rc_open(struct rc_dev *rdev) +{ + int rval = 0; + + if (!rdev) + return -EINVAL; + + mutex_lock(&rdev->lock); + if (!rdev->users++) + rval = rdev->open(rdev); + + if (rval) + rdev->users--; + + mutex_unlock(&rdev->lock); + + return rval; +} +EXPORT_SYMBOL_GPL(rc_open); + static int ir_open(struct input_dev *idev) { struct rc_dev *rdev = input_get_drvdata(idev); - return rdev->open(rdev); + return rc_open(rdev); +} + +void rc_close(struct rc_dev *rdev) +{ + if (rdev) { + mutex_lock(&rdev->lock); + + if (!--rdev->users) + rdev->close(rdev); + + mutex_unlock(&rdev->lock); + } } +EXPORT_SYMBOL_GPL(rc_close); static void ir_close(struct input_dev *idev) { struct rc_dev *rdev = input_get_drvdata(idev); - - if (rdev) - rdev->close(rdev); + rc_close(rdev); } /* class for /sys/class/rc */ @@ -1076,7 +1107,14 @@ int rc_register_device(struct rc_dev *dev) memcpy(&dev->input_dev->id, &dev->input_id, sizeof(dev->input_id)); dev->input_dev->phys = dev->input_phys; dev->input_dev->name = dev->input_name; + + /* input_register_device can call ir_open, so unlock mutex here */ + mutex_unlock(&dev->lock); + rc = input_register_device(dev->input_dev); + + mutex_lock(&dev->lock); + if (rc) goto out_table; -- cgit v1.2.3-70-g09d2 From 153a60bb0faca59bfde313d4c713d9420e475b75 Mon Sep 17 00:00:00 2001 From: Sean Young Date: Tue, 30 Jul 2013 19:00:01 -0300 Subject: [media] rc: add feedback led trigger for rc keypresses Many devices with an ir receiver also have a feedback led. Add the led trigger to support this. Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab --- drivers/media/rc/rc-main.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers/media/rc/rc-main.c') diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index 1dedebda1ce..aa5d8e72462 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,7 @@ /* Used to keep track of known keymaps */ static LIST_HEAD(rc_map_list); static DEFINE_SPINLOCK(rc_map_lock); +static struct led_trigger *led_feedback; static struct rc_map_list *seek_rc_map(const char *name) { @@ -535,6 +537,7 @@ static void ir_do_keyup(struct rc_dev *dev, bool sync) IR_dprintk(1, "keyup key 0x%04x\n", dev->last_keycode); input_report_key(dev->input_dev, dev->last_keycode, 0); + led_trigger_event(led_feedback, LED_OFF); if (sync) input_sync(dev->input_dev); dev->keypressed = false; @@ -648,6 +651,7 @@ static void ir_do_keydown(struct rc_dev *dev, int scancode, input_report_key(dev->input_dev, keycode, 1); } + led_trigger_event(led_feedback, LED_FULL); input_sync(dev->input_dev); } @@ -1222,6 +1226,7 @@ static int __init rc_core_init(void) return rc; } + led_trigger_register_simple("rc-feedback", &led_feedback); rc_map_register(&empty_map); return 0; @@ -1230,6 +1235,7 @@ static int __init rc_core_init(void) static void __exit rc_core_exit(void) { class_unregister(&rc_class); + led_trigger_unregister_simple(led_feedback); rc_map_unregister(&empty_map); } -- cgit v1.2.3-70-g09d2 From f02dcdd1784d2b56ffa8c528248b60ef142e921d Mon Sep 17 00:00:00 2001 From: Juergen Lock Date: Fri, 16 Aug 2013 15:00:24 -0300 Subject: [media] media: rc: rdev->open or rdev->close can be NULL At least technisat-usb2.c doesn't set these... Signed-off-by: Juergen Lock Signed-off-by: Mauro Carvalho Chehab --- drivers/media/rc/rc-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/media/rc/rc-main.c') diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index aa5d8e72462..46da365c9c8 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c @@ -711,7 +711,7 @@ int rc_open(struct rc_dev *rdev) return -EINVAL; mutex_lock(&rdev->lock); - if (!rdev->users++) + if (!rdev->users++ && rdev->open != NULL) rval = rdev->open(rdev); if (rval) @@ -735,7 +735,7 @@ void rc_close(struct rc_dev *rdev) if (rdev) { mutex_lock(&rdev->lock); - if (!--rdev->users) + if (!--rdev->users && rdev->close != NULL) rdev->close(rdev); mutex_unlock(&rdev->lock); -- cgit v1.2.3-70-g09d2