From cdfaa01c1cfeb828e6d3c0c5e4f54375fc3ccb95 Mon Sep 17 00:00:00 2001 From: Sean Young Date: Sat, 25 Feb 2017 06:51:30 -0500 Subject: media: lirc: use the correct carrier for scancode transmit If the lirc device supports it, set the carrier for the protocol. Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab --- include/media/rc-core.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/media/rc-core.h') diff --git a/include/media/rc-core.h b/include/media/rc-core.h index 314a1edb6189..ca48632ec8e2 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -309,6 +309,7 @@ int ir_raw_event_store_with_filter(struct rc_dev *dev, void ir_raw_event_set_idle(struct rc_dev *dev, bool idle); int ir_raw_encode_scancode(enum rc_proto protocol, u32 scancode, struct ir_raw_event *events, unsigned int max); +int ir_raw_encode_carrier(enum rc_proto protocol); static inline void ir_raw_event_reset(struct rc_dev *dev) { -- cgit From a60d64b15c20d178ba3a9bc3a542492b4ddeea70 Mon Sep 17 00:00:00 2001 From: Sean Young Date: Sat, 23 Sep 2017 10:41:13 -0400 Subject: 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 Signed-off-by: Mauro Carvalho Chehab --- include/media/rc-core.h | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'include/media/rc-core.h') diff --git a/include/media/rc-core.h b/include/media/rc-core.h index ca48632ec8e2..5d6e415c7acc 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -20,6 +20,7 @@ #include #include #include +#include #include extern int rc_core_debug; @@ -115,6 +116,15 @@ enum rc_filter_type { * @max_timeout: maximum timeout supported by device * @rx_resolution : resolution (in ns) of input sampler * @tx_resolution: resolution (in ns) of output sampler + * @lirc_dev: lirc char device + * @carrier_low: when setting the carrier range, first the low end must be + * set with an ioctl and then the high end with another ioctl + * @gap_start: time when gap starts + * @gap_duration: duration of initial gap + * @gap: true if we're in a gap + * @send_timeout_reports: report timeouts in lirc raw IR. + * @send_mode: lirc mode for sending, either LIRC_MODE_SCANCODE or + * LIRC_MODE_PULSE * @change_protocol: allow changing the protocol used on hardware decoders * @open: callback to allow drivers to enable polling/irq when IR input device * is opened. @@ -174,6 +184,15 @@ struct rc_dev { u32 max_timeout; u32 rx_resolution; u32 tx_resolution; +#ifdef CONFIG_LIRC + struct lirc_dev *lirc_dev; + int carrier_low; + ktime_t gap_start; + u64 gap_duration; + bool gap; + bool send_timeout_reports; + u8 send_mode; +#endif int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto); int (*open)(struct rc_dev *dev); void (*close)(struct rc_dev *dev); @@ -248,20 +267,6 @@ int devm_rc_register_device(struct device *parent, struct rc_dev *dev); */ void rc_unregister_device(struct rc_dev *dev); -/** - * rc_open - Opens a RC device - * - * @rdev: pointer to struct rc_dev. - */ -int rc_open(struct rc_dev *rdev); - -/** - * rc_close - Closes a RC device - * - * @rdev: pointer to struct rc_dev. - */ -void rc_close(struct rc_dev *rdev); - void rc_repeat(struct rc_dev *dev); void rc_keydown(struct rc_dev *dev, enum rc_proto protocol, u32 scancode, u8 toggle); -- cgit From 71695aff9fe036857596965635e2607cf561a230 Mon Sep 17 00:00:00 2001 From: Sean Young Date: Sat, 23 Sep 2017 14:44:18 -0400 Subject: media: lirc: use kfifo rather than lirc_buffer for raw IR Since the only mode lirc devices can handle is raw IR, handle this in a plain kfifo. Remove lirc_buffer since this is no longer needed. Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab --- include/media/rc-core.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include/media/rc-core.h') diff --git a/include/media/rc-core.h b/include/media/rc-core.h index 5d6e415c7acc..fb91666bf881 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -123,6 +123,8 @@ enum rc_filter_type { * @gap_duration: duration of initial gap * @gap: true if we're in a gap * @send_timeout_reports: report timeouts in lirc raw IR. + * @rawir: queue for incoming raw IR + * @wait_poll: poll struct for lirc device * @send_mode: lirc mode for sending, either LIRC_MODE_SCANCODE or * LIRC_MODE_PULSE * @change_protocol: allow changing the protocol used on hardware decoders @@ -191,6 +193,8 @@ struct rc_dev { u64 gap_duration; bool gap; bool send_timeout_reports; + DECLARE_KFIFO_PTR(rawir, unsigned int); + wait_queue_head_t wait_poll; u8 send_mode; #endif int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto); -- cgit From 7790e81f7e1f7f122f8fcccd91443a2571421aba Mon Sep 17 00:00:00 2001 From: Sean Young Date: Tue, 26 Sep 2017 07:31:29 -0400 Subject: media: lirc: move lirc_dev->attached to rc_dev->registered This is done to further remove the lirc kernel api. Ensure that every fops checks for this. Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab --- include/media/rc-core.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/media/rc-core.h') diff --git a/include/media/rc-core.h b/include/media/rc-core.h index fb91666bf881..b6d719734744 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -127,6 +127,8 @@ enum rc_filter_type { * @wait_poll: poll struct for lirc device * @send_mode: lirc mode for sending, either LIRC_MODE_SCANCODE or * LIRC_MODE_PULSE + * @registered: set to true by rc_register_device(), false by + * rc_unregister_device * @change_protocol: allow changing the protocol used on hardware decoders * @open: callback to allow drivers to enable polling/irq when IR input device * is opened. @@ -197,6 +199,7 @@ struct rc_dev { wait_queue_head_t wait_poll; u8 send_mode; #endif + bool registered; int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto); int (*open)(struct rc_dev *dev); void (*close)(struct rc_dev *dev); -- cgit From 111429fb73b1f5f584d977614b87ce9e6f8361c6 Mon Sep 17 00:00:00 2001 From: Sean Young Date: Tue, 26 Sep 2017 07:44:20 -0400 Subject: media: lirc: create rc-core open and close lirc functions Replace the generic kernel lirc api with ones which use rc-core, further reducing the lirc_dev members. Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab --- include/media/rc-core.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/media/rc-core.h') diff --git a/include/media/rc-core.h b/include/media/rc-core.h index b6d719734744..4f585bff1347 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -117,6 +117,7 @@ enum rc_filter_type { * @rx_resolution : resolution (in ns) of input sampler * @tx_resolution: resolution (in ns) of output sampler * @lirc_dev: lirc char device + * @lirc_open: count of the number of times the device has been opened * @carrier_low: when setting the carrier range, first the low end must be * set with an ioctl and then the high end with another ioctl * @gap_start: time when gap starts @@ -190,6 +191,7 @@ struct rc_dev { u32 tx_resolution; #ifdef CONFIG_LIRC struct lirc_dev *lirc_dev; + int lirc_open; int carrier_low; ktime_t gap_start; u64 gap_duration; -- cgit From a6ddd4fecbb02d8ec5a865621bd2b746d585a01c Mon Sep 17 00:00:00 2001 From: Sean Young Date: Tue, 26 Sep 2017 09:34:47 -0400 Subject: 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 Signed-off-by: Mauro Carvalho Chehab --- include/media/rc-core.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'include/media/rc-core.h') 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 @@ #define _RC_CORE #include +#include #include #include #include -#include #include extern int rc_core_debug; @@ -116,7 +116,8 @@ enum rc_filter_type { * @max_timeout: maximum timeout supported by device * @rx_resolution : resolution (in ns) of input sampler * @tx_resolution: resolution (in ns) of output sampler - * @lirc_dev: lirc char device + * @lirc_dev: lirc device + * @lirc_cdev: lirc char cdev * @lirc_open: count of the number of times the device has been opened * @carrier_low: when setting the carrier range, first the low end must be * set with an ioctl and then the high end with another ioctl @@ -190,7 +191,8 @@ struct rc_dev { u32 rx_resolution; u32 tx_resolution; #ifdef CONFIG_LIRC - struct lirc_dev *lirc_dev; + struct device lirc_dev; + struct cdev lirc_cdev; int lirc_open; int carrier_low; ktime_t gap_start; -- cgit From de142c32410649e64d44928505ffad2176a96a9e Mon Sep 17 00:00:00 2001 From: Sean Young Date: Sat, 25 Feb 2017 06:51:32 -0500 Subject: media: lirc: implement reading scancode This implements LIRC_MODE_SCANCODE reading from the lirc device. The scancode can be read from the input device too, but with this interface you get the rc protocol, keycode, toggle and repeat status in addition to just the scancode. int main() { int fd, mode, rc; fd = open("/dev/lirc0", O_RDWR); mode = LIRC_MODE_SCANCODE; if (ioctl(fd, LIRC_SET_REC_MODE, &mode)) { // kernel too old or lirc does not support transmit } struct lirc_scancode scancode; while (read(fd, &scancode, sizeof(scancode)) == sizeof(scancode)) { printf("protocol:%d scancode:0x%x toggle:%d repeat:%d\n", scancode.rc_proto, scancode.scancode, !!(scancode.flags & LIRC_SCANCODE_FLAG_TOGGLE), !!(scancode.flags & LIRC_SCANCODE_FLAG_REPEAT)); } close(fd); } Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab --- include/media/rc-core.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/media/rc-core.h') diff --git a/include/media/rc-core.h b/include/media/rc-core.h index 2d24c88652aa..fbf1648d2ec9 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -126,9 +126,12 @@ enum rc_filter_type { * @gap: true if we're in a gap * @send_timeout_reports: report timeouts in lirc raw IR. * @rawir: queue for incoming raw IR + * @scancodes: queue for incoming decoded scancodes * @wait_poll: poll struct for lirc device * @send_mode: lirc mode for sending, either LIRC_MODE_SCANCODE or * LIRC_MODE_PULSE + * @rec_mode: lirc mode for receiving, either LIRC_MODE_SCANCODE or + * LIRC_MODE_MODE2 * @registered: set to true by rc_register_device(), false by * rc_unregister_device * @change_protocol: allow changing the protocol used on hardware decoders @@ -200,8 +203,10 @@ struct rc_dev { bool gap; bool send_timeout_reports; DECLARE_KFIFO_PTR(rawir, unsigned int); + DECLARE_KFIFO_PTR(scancodes, struct lirc_scancode); wait_queue_head_t wait_poll; u8 send_mode; + u8 rec_mode; #endif bool registered; int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto); -- cgit From 7e45d660e4d487aa2cbeb003bd4338433feba30a Mon Sep 17 00:00:00 2001 From: Sean Young Date: Thu, 2 Nov 2017 17:21:13 -0400 Subject: media: lirc: allow lirc device to be opened more than once This makes it possible for lircd to read from a lirc chardev, and not keep it busy. Note that this changes the default for timeout reports to on. lircd already enables timeout reports when it opens a lirc device, leaving them on until the next reboot. Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab --- include/media/rc-core.h | 50 ++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) (limited to 'include/media/rc-core.h') diff --git a/include/media/rc-core.h b/include/media/rc-core.h index fbf1648d2ec9..3a47a25a6593 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -68,6 +68,33 @@ enum rc_filter_type { RC_FILTER_MAX }; +/** + * struct lirc_fh - represents an open lirc file + * @list: list of open file handles + * @rc: rcdev for this lirc chardev + * @carrier_low: when setting the carrier range, first the low end must be + * set with an ioctl and then the high end with another ioctl + * @send_timeout_reports: report timeouts in lirc raw IR. + * @rawir: queue for incoming raw IR + * @scancodes: queue for incoming decoded scancodes + * @wait_poll: poll struct for lirc device + * @send_mode: lirc mode for sending, either LIRC_MODE_SCANCODE or + * LIRC_MODE_PULSE + * @rec_mode: lirc mode for receiving, either LIRC_MODE_SCANCODE or + * LIRC_MODE_MODE2 + */ +struct lirc_fh { + struct list_head list; + struct rc_dev *rc; + int carrier_low; + bool send_timeout_reports; + DECLARE_KFIFO_PTR(rawir, unsigned int); + DECLARE_KFIFO_PTR(scancodes, struct lirc_scancode); + wait_queue_head_t wait_poll; + u8 send_mode; + u8 rec_mode; +}; + /** * struct rc_dev - represents a remote control device * @dev: driver model's view of this device @@ -118,20 +145,11 @@ enum rc_filter_type { * @tx_resolution: resolution (in ns) of output sampler * @lirc_dev: lirc device * @lirc_cdev: lirc char cdev - * @lirc_open: count of the number of times the device has been opened - * @carrier_low: when setting the carrier range, first the low end must be - * set with an ioctl and then the high end with another ioctl * @gap_start: time when gap starts * @gap_duration: duration of initial gap * @gap: true if we're in a gap - * @send_timeout_reports: report timeouts in lirc raw IR. - * @rawir: queue for incoming raw IR - * @scancodes: queue for incoming decoded scancodes - * @wait_poll: poll struct for lirc device - * @send_mode: lirc mode for sending, either LIRC_MODE_SCANCODE or - * LIRC_MODE_PULSE - * @rec_mode: lirc mode for receiving, either LIRC_MODE_SCANCODE or - * LIRC_MODE_MODE2 + * @lirc_fh_lock: protects lirc_fh list + * @lirc_fh: list of open files * @registered: set to true by rc_register_device(), false by * rc_unregister_device * @change_protocol: allow changing the protocol used on hardware decoders @@ -196,17 +214,11 @@ struct rc_dev { #ifdef CONFIG_LIRC struct device lirc_dev; struct cdev lirc_cdev; - int lirc_open; - int carrier_low; ktime_t gap_start; u64 gap_duration; bool gap; - bool send_timeout_reports; - DECLARE_KFIFO_PTR(rawir, unsigned int); - DECLARE_KFIFO_PTR(scancodes, struct lirc_scancode); - wait_queue_head_t wait_poll; - u8 send_mode; - u8 rec_mode; + spinlock_t lirc_fh_lock; + struct list_head lirc_fh; #endif bool registered; int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto); -- cgit From 57c642cb45d6f7d0d950c3bc67439989062ac743 Mon Sep 17 00:00:00 2001 From: Sean Young Date: Thu, 23 Nov 2017 17:37:10 -0500 Subject: media: cec: move cec autorepeat handling to rc-core CEC autorepeat is different than other protocols. Autorepeat is triggered by the first repeated user control pressed CEC message, rather than a fixed REP_DELAY. This change also does away with the KEY_UP event directly after the first KEY_DOWN event, which was used to stop autorepeat from starting. See commit a9a249a2c997 ("media: cec: fix remote control passthrough") for the original change. Acked-by: Hans Verkuil Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab --- include/media/rc-core.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/media/rc-core.h') diff --git a/include/media/rc-core.h b/include/media/rc-core.h index 3a47a25a6593..0a4026cf64f3 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -134,6 +134,8 @@ struct lirc_fh { * @keypressed: whether a key is currently pressed * @keyup_jiffies: time (in jiffies) when the current keypress should be released * @timer_keyup: timer for releasing a keypress + * @timer_repeat: timer for autorepeat events. This is needed for CEC, which + * has non-standard repeats. * @last_keycode: keycode of last keypress * @last_protocol: protocol of last keypress * @last_scancode: scancode of last keypress @@ -202,6 +204,7 @@ struct rc_dev { bool keypressed; unsigned long keyup_jiffies; struct timer_list timer_keyup; + struct timer_list timer_repeat; u32 last_keycode; enum rc_proto last_protocol; u32 last_scancode; -- cgit From f4ab70e3d241f70b9ad43efa8898cbddfe7a6bc5 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Sun, 24 Sep 2017 05:24:58 -0400 Subject: media: rc-core.h: minor adjustments at rc_driver_type doc The description of this enum doesn't match what it actually represents. Adjust it. Acked-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- include/media/rc-core.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/media/rc-core.h') diff --git a/include/media/rc-core.h b/include/media/rc-core.h index 0a4026cf64f3..aed4272d47f5 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -31,9 +31,9 @@ do { \ } while (0) /** - * enum rc_driver_type - type of the RC output + * enum rc_driver_type - type of the RC driver. * - * @RC_DRIVER_SCANCODE: Driver or hardware generates a scancode + * @RC_DRIVER_SCANCODE: Driver or hardware generates a scancode. * @RC_DRIVER_IR_RAW: Driver or hardware generates pulse/space sequences. * It needs a Infra-Red pulse/space decoder * @RC_DRIVER_IR_RAW_TX: Device transmitter only, -- cgit