Skip to contentSkip to conversation

In-kernel IR support using evdev

PATCH In review Jon Smirl 5 participants 19 messages Nov 27, 2009 – Nov 29, 2009

Subsystems (5)
lore
Share & tools
lore

Jon Smirl

author
#0 lore raw

v4 cover In-kernel IR support using evdev

This is a repost of the LIRC input patch series I wrote a year ago. Many of the ideas being discussed in the currect "Should we create a raw input interface for IR's?" thread have already been implemented in this code.

---------------------------------------------------

All of this kernel code is tiny, about 20K including a driver.

Basic flow works like this:

patch: Minimal changes to the core input system
Add a new IR data type to the input framework

patch: Core IR module
In-kernel decoding of core IR protocols - RC5, RC6, etc
This only converts from protocol pulse timing to common command format. Check out: http://www.sbprojects.com/knowledge/ir/sirc.htm

patch: Configfs support for IR
Decoded core protocols pass through a translation map based on configfs When core protocol matches an entry in configfs it is turned into a keycode event.

patch: Microsoft mceusb2 driver for in-kernel IR subsystem Example mceusb IR input driver

patch: the other ones are an embedded driver using a GPT pin.

You make a directory in /configfs/remotes for each remote you have. Making the directory creates a new evdev device. Under the directory make an entry for each command generated by the device. These entries cause the decoded IR data to be mapped into keycodes on the new evdev device. udev would load these configfs mappings at boot time...

mkdir /config/remotes/sony
-- this creates a new evdev device
mkdir remotes/sony/one
echo 7 >remotes/sony/one/protocol
echo 264 >remotes/sony/one/command
echo 2 >remotes/sony/one/keycode

This transforms a button push of 1 on my remote into a key stroke for KEY_1

 *   configfs root
 *   --remotes
 *   ----specific remote
 *   ------keymap
 *   --------protocol
 *   --------device
 *   --------command
 *   --------keycode
 *   ------repeat keymaps
 *   --------....
 *   ----another remote
 *   ------more keymaps

You can map the 1 button from multiple remotes to KEY_1 if you want. Or you can use a single remote to create multiple virtual keyboards.

-------------------------

Raw IR pulse data is available in a FIFO via sysfs. You can use this to figure out new remote protocols.

Two input events are generated
1) an event for the decoded raw IR protocol
2) a keycode event if thedecoded raw IR protocol matches an entry in the configfs

You can also send pulses.

------

If you want to script this, you would have a user space task that watches for either the decoded IR codes or the mapped keycodes.

This system also works with user space device drivers. They can inject input events into the early event flow and they will get processed as if the event originated in the kernel.

---------------------

Sure you could push the protocol decoding code (RC5, etc) into user space. Seems like a lot of hassle to move about 3KB of code out of the kernel.

--------------------
previos comment on the patches...

Now when a key is pressed on a remote, the configfs directories are searched for a match on protocol, device, command. If a matches is found, a key stroke corresponding to keycode is created and sent on the input device that was created when the directory for the remote was made.

The configfs directories are pretty flexible. You can use them to map multiple remotes to the same key stroke, or send a single button push to multiple apps.

To do the mapping it uses configfs (part of the kernel). The main directory is remotes. You use a shell script to build mappings between the IR event and key stroke.

mkdir /config/remotes/sony
-- this creates a new evdev device
mkdir remotes/sony/one
echo 7 >remotes/sony/one/procotol
echo 264 >remotes/sony/one/command
echo 2 >remotes/sony/one/keycode

This transforms a button push of 1 on my remote into a key stroke for KEY_1

 *   configfs root
 *   --remotes
 *   ----specific remote
 *   ------keymap
 *   --------protocol
 *   --------device
 *   --------command
 *   --------keycode
 *   ------repeat keymaps
 *   --------....
 *   ----another remote
 *   ------more keymaps

You can map the 1 button from multiple remote to KEY_1 if you want. Or you can use a single remote to create multiple virtual keyboards.

Quoted 1 line

From last release...

Raw mode. There are three sysfs attributes - ir_raw, ir_carrier, ir_xmitter. Read from ir_raw to get the raw timing data from the IR device. Set carrier and active xmitters and then copy raw data to ir_raw to send. These attributes may be better on a debug switch. You would use raw mode when decoding a new protocol. After you figure out the new protocol, write an in-kernel encoder/decoder for it.

The in-kernel code is tiny, about 20K including a driver.

Quoted 1 line

From last post...

Note that user space IR device drivers can use the existing support in evdev to inject events into the input queue.

Send and receive are implemented. Received IR messages are decoded and sent to user space as input messages. Send is done via an IOCTL on the input device.

Two drivers are supplied. mceusb2 implements send and receive support for the Microsoft USB IR dongle.

The GPT driver implements receive only support for a GPT pin - GPT is a GPIO with a timer attached.

Code is only lightly tested. Encoders and decoders have not been written for all protocols. Repeat is not handled for any protocol. I'm looking for help. There are 15 more existing LIRC drivers.

---

Jon Smirl (6):
Minimal changes to the core input system
Core IR module
Configfs support for IR
GPT driver for in-kernel IR support.
Example of PowerPC device tree support for GPT based IR Microsoft mceusb2 driver for in-kernel IR subsystem

 arch/powerpc/boot/dts/dspeak01.dts |   19 -
 drivers/input/Kconfig              |    2 
 drivers/input/Makefile             |    1 
 drivers/input/input.c              |   20 +
 drivers/input/ir/Kconfig           |   27 +
 drivers/input/ir/Makefile          |   12 +
 drivers/input/ir/ir-configfs.c     |  348 +++++++++++++++++
 drivers/input/ir/ir-core.c         |  730 +++++++++++++++++++++++++++++++++++
 drivers/input/ir/ir-gpt.c          |  184 +++++++++
 drivers/input/ir/ir-mceusb2.c      |  745 ++++++++++++++++++++++++++++++++++++
 drivers/input/ir/ir.h              |   63 +++
 include/linux/input.h              |   76 ++++
 include/linux/mod_devicetable.h    |    3 
 13 files changed, 2219 insertions(+), 11 deletions(-)
 create mode 100644 drivers/input/ir/Kconfig
 create mode 100644 drivers/input/ir/Makefile
 create mode 100644 drivers/input/ir/ir-configfs.c
 create mode 100644 drivers/input/ir/ir-core.c
 create mode 100644 drivers/input/ir/ir-gpt.c
 create mode 100644 drivers/input/ir/ir-mceusb2.c
 create mode 100644 drivers/input/ir/ir.h
Signature · 2 lines
Jon Smirl
[email protected]
author
#1 lore raw

PATCH v4 1/6 Minimal changes to the core input system

Minimal changes to the core input system. The bulk of IR support loads as a module. These changes are passive if the rest of IR isn't loaded.

Jon Smirl
<[email protected]>

---
 drivers/input/input.c           |   17 +++++++++
 include/linux/input.h           |   75 +++++++++++++++++++++++++++++++++++++++
 include/linux/mod_devicetable.h |    3 ++
 3 files changed, 95 insertions(+), 0 deletions(-)
drivers/input/input.c +17 -0
index 7c237e6..a531cf5 100644
@@ -274,6 +274,10 @@ static void input_handle_event(struct input_dev *dev,
 	case EV_PWR:
 		disposition = INPUT_PASS_TO_ALL;
 		break;
+
+	case EV_IR:
+		disposition = INPUT_PASS_TO_ALL;
+		break;
 	}
 
 	if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)
@@ -727,6 +731,7 @@ static const struct input_device_id *input_match_device(const struct input_devic
 		MATCH_BIT(sndbit, SND_MAX);
 		MATCH_BIT(ffbit,  FF_MAX);
 		MATCH_BIT(swbit,  SW_MAX);
+		MATCH_BIT(irbit,  IR_MAX);
 
 		return id;
 	}
@@ -849,6 +854,8 @@ static int input_devices_seq_show(struct seq_file *seq, void *v)
 		input_seq_print_bitmap(seq, "FF", dev->ffbit, FF_MAX);
 	if (test_bit(EV_SW, dev->evbit))
 		input_seq_print_bitmap(seq, "SW", dev->swbit, SW_MAX);
+	if (test_bit(EV_IR, dev->evbit))
+		input_seq_print_bitmap(seq, "IR", dev->irbit, IR_MAX);
 
 	seq_putc(seq, '\n');
 
@@ -1024,6 +1031,8 @@ static int input_print_modalias(char *buf, int size, struct input_dev *id,
 				'f', id->ffbit, 0, FF_MAX);
 	len += input_print_modalias_bits(buf + len, size - len,
 				'w', id->swbit, 0, SW_MAX);
+	len += input_print_modalias_bits(buf + len, size - len,
+				'i', id->irbit, 0, IR_MAX);
 
 	if (add_cr)
 		len += snprintf(buf + len, max(size - len, 0), "\n");
@@ -1125,6 +1134,7 @@ INPUT_DEV_CAP_ATTR(LED, led);
 INPUT_DEV_CAP_ATTR(SND, snd);
 INPUT_DEV_CAP_ATTR(FF, ff);
 INPUT_DEV_CAP_ATTR(SW, sw);
+INPUT_DEV_CAP_ATTR(IR, ir);
 
 static struct attribute *input_dev_caps_attrs[] = {
 	&dev_attr_ev.attr,
@@ -1136,6 +1146,7 @@ static struct attribute *input_dev_caps_attrs[] = {
 	&dev_attr_snd.attr,
 	&dev_attr_ff.attr,
 	&dev_attr_sw.attr,
+	&dev_attr_ir.attr,
 	NULL
 };
 
@@ -1253,6 +1264,8 @@ static int input_dev_uevent(struct device *device, struct kobj_uevent_env *env)
 		INPUT_ADD_HOTPLUG_BM_VAR("FF=", dev->ffbit, FF_MAX);
 	if (test_bit(EV_SW, dev->evbit))
 		INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX);
+	if (test_bit(EV_IR, dev->evbit))
+		INPUT_ADD_HOTPLUG_BM_VAR("IR=", dev->irbit, IR_MAX);
 
 	INPUT_ADD_HOTPLUG_MODALIAS_VAR(dev);
 
@@ -1371,6 +1384,10 @@ void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int
 		__set_bit(code, dev->ffbit);
 		break;
 
+	case EV_IR:
+		__set_bit(code, dev->irbit);
+		break;
+
 	case EV_PWR:
 		/* do nothing */
 		break;
include/linux/input.h +75 -0

122 lines not on this page · raw message

include/linux/mod_devicetable.h +3 -0
index 1bf5900..2bdf253 100644
@@ -293,6 +293,7 @@ struct pcmcia_device_id {
 #define INPUT_DEVICE_ID_SND_MAX		0x07
 #define INPUT_DEVICE_ID_FF_MAX		0x7f
 #define INPUT_DEVICE_ID_SW_MAX		0x0f
+#define INPUT_DEVICE_ID_IR_MAX		0x0f
 
 #define INPUT_DEVICE_ID_MATCH_BUS	1
 #define INPUT_DEVICE_ID_MATCH_VENDOR	2
@@ -308,6 +309,7 @@ struct pcmcia_device_id {
 #define INPUT_DEVICE_ID_MATCH_SNDBIT	0x0400
 #define INPUT_DEVICE_ID_MATCH_FFBIT	0x0800
 #define INPUT_DEVICE_ID_MATCH_SWBIT	0x1000
+#define INPUT_DEVICE_ID_MATCH_IRBIT	0x2000
 
 struct input_device_id {
 
@@ -327,6 +329,7 @@ struct input_device_id {
 	kernel_ulong_t sndbit[INPUT_DEVICE_ID_SND_MAX / BITS_PER_LONG + 1];
 	kernel_ulong_t ffbit[INPUT_DEVICE_ID_FF_MAX / BITS_PER_LONG + 1];
 	kernel_ulong_t swbit[INPUT_DEVICE_ID_SW_MAX / BITS_PER_LONG + 1];
+	kernel_ulong_t irbit[INPUT_DEVICE_ID_IR_MAX / BITS_PER_LONG + 1];
 
 	kernel_ulong_t driver_info;
 };
author
#2 lore raw

PATCH v4 2/6 Core IR module

In reply to Jon Smirl

Changes to core input subsystem to allow send and receive of IR messages. Encode and decode state machines are provided for common IR porotocols such as Sony, JVC, NEC, Philips, etc.

Received IR messages generate event in the input queue. IR messages are sent using an input IOCTL.

---
 drivers/input/Kconfig      |    2 
 drivers/input/Makefile     |    1 
 drivers/input/input.c      |    3 
 drivers/input/ir/Kconfig   |   15 +
 drivers/input/ir/Makefile  |    8 
 drivers/input/ir/ir-core.c |  735 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/input/ir/ir.h      |   63 ++++
 include/linux/input.h      |    5 
 8 files changed, 830 insertions(+), 2 deletions(-)
 create mode 100644 drivers/input/ir/Kconfig
 create mode 100644 drivers/input/ir/Makefile
 create mode 100644 drivers/input/ir/ir-core.c
 create mode 100644 drivers/input/ir/ir.h
drivers/input/Kconfig +2 -0
index 816639c..a1e35ee 100644
@@ -172,6 +172,8 @@ source "drivers/input/touchscreen/Kconfig"
 
 source "drivers/input/misc/Kconfig"
 
+source "drivers/input/ir/Kconfig"
+
 endif
 
 menu "Hardware I/O ports"
drivers/input/Makefile +1 -0
index 99e2b5e..fec8972 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_INPUT_JOYSTICK)	+= joystick/
 obj-$(CONFIG_INPUT_TABLET)	+= tablet/
 obj-$(CONFIG_INPUT_TOUCHSCREEN)	+= touchscreen/
 obj-$(CONFIG_INPUT_MISC)	+= misc/
+obj-$(CONFIG_INPUT_IR)		+= ir/
 
 obj-$(CONFIG_INPUT_APMPOWER)	+= apm-power.o
 
drivers/input/input.c +3 -0
index a531cf5..2843b84 100644
@@ -23,6 +23,8 @@
 #include <linux/rcupdate.h>
 #include <linux/smp_lock.h>
 
+#include "ir/ir.h"
+
 MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
 MODULE_DESCRIPTION("Input core");
 MODULE_LICENSE("GPL");
@@ -1167,6 +1169,7 @@ static void input_dev_release(struct device *device)
 	struct input_dev *dev = to_input_dev(device);
 
 	input_ff_destroy(dev);
+	input_ir_destroy(dev);
 	kfree(dev);
 
 	module_put(THIS_MODULE);
drivers/input/ir/Kconfig new file +15 -0
new file mode 100644
index 0000000..a6f3f25
@@ -0,0 +1,15 @@
+#
+# LIRC driver(s) configuration
+#
+menuconfig INPUT_IR
+	select CONFIGFS_FS
+	tristate "Infrared Remote (IR) receiver/transmitter drivers"
+	default n
+	help
+	  Say Y here, and all supported Infrared Remote Control IR
+	  receiver and transmitter drivers will be displayed. The receiver drivers
+	  allow control of your Linux system via remote control.
+
+if INPUT_IR
+
+endif
drivers/input/ir/Makefile new file +8 -0
new file mode 100644
index 0000000..6acb665
@@ -0,0 +1,8 @@
+# Makefile for the ir drivers.
+#
+
+# Each configuration option enables a list of files.
+
+obj-$(CONFIG_INPUT_IR)		+= ir.o
+ir-objs := ir-core.o
+
drivers/input/ir/ir-core.c new file +735 -0

735 lines not on this page · raw message

drivers/input/ir/ir.h new file +63 -0

63 lines not on this page · raw message

include/linux/input.h +3 -2
index 159a99d..08f7bda 100644
@@ -1480,9 +1480,10 @@ typedef int (*send_func)(void *private, unsigned int *buffer, unsigned int count
 		unsigned int frequency, unsigned int xmitters);
 
 int input_ir_create(struct input_dev *dev, void *private, send_func send);
-void input_ir_destroy(struct input_dev *dev);
 
-void input_ir_decode(struct input_dev *dev, unsigned int delta, unsigned int bit);
+void input_ir_decode(struct input_dev *dev, int sample);
+void input_ir_queue(struct input_dev *dev, int sample);
+
 int input_ir_send(struct input_dev *dev, struct ir_command *ir_command, struct file *file);
 int input_ir_register(struct input_dev *dev);
 
author
#9 lore raw

PATCH v4 3/6 Configfs support for IR

In reply to Jon Smirl

Now uses configfs to build mappings from remote buttons to key strokes. When ir-core loads it creates /config/remotes. Make a directory for each remote you have; this will cause a new input devices to be created. Inside these directories make a directory for each key on the remote. In the key directory attributes fill in the protocol, device, command, keycode. Since this is configfs all of this can be easily scripted.

Now when a key is pressed on a remote, the configfs directories are searched for a match on protocol, device, command. If a matches is found, a key stroke corresponding to keycode is created and sent on the input device that was created when the directory for the remote was made.

The configfs directories are pretty flexible. You can use them to map multiple remotes to the same key stroke, or send a single button push to multiple apps.

---
 drivers/input/ir/Makefile      |    2 
 drivers/input/ir/ir-configfs.c |  348 ++++++++++++++++++++++++++++++++++++++++
 drivers/input/ir/ir-core.c     |   15 +-
 3 files changed, 354 insertions(+), 11 deletions(-)
 create mode 100644 drivers/input/ir/ir-configfs.c
drivers/input/ir/Makefile +1 -1
index 6acb665..2ccdda3 100644
@@ -4,5 +4,5 @@
 # Each configuration option enables a list of files.
 
 obj-$(CONFIG_INPUT_IR)		+= ir.o
-ir-objs := ir-core.o
+ir-objs := ir-core.o ir-configfs.o
 
drivers/input/ir/ir-configfs.c new file +348 -0

348 lines not on this page · raw message

drivers/input/ir/ir-core.c +5 -10
index 85adfcb..9c81bac 100644
@@ -10,15 +10,6 @@
 
 #include "ir.h"
 
-void input_ir_translate(struct input_dev *dev, int protocol, int device, int command)
-{
-	/* generate the IR format event */
-	input_report_ir(dev, IR_PROTOCOL, protocol);
-	input_report_ir(dev, IR_DEVICE, device);
-	input_report_ir(dev, IR_COMMAND, command);
-	input_sync(dev);
-}
-
 static int encode_sony(struct ir_device *ir, struct ir_command *command)
 {
 	/* Sony SIRC IR code */
@@ -725,11 +716,15 @@ void input_ir_destroy(struct input_dev *dev)
 
 static int __init input_ir_init(void)
 {
-	return 0;
+	config_group_init(&input_ir_remotes.su_group);
+	mutex_init(&input_ir_remotes.su_mutex);
+
+	return configfs_register_subsystem(&input_ir_remotes);
 }
 module_init(input_ir_init);
 
 static void __exit input_ir_exit(void)
 {
+	configfs_unregister_subsystem(&input_ir_remotes);
 }
 module_exit(input_ir_exit);
author
#10 lore raw

PATCH v4 4/6 GPT driver for in-kernel IR support.

In reply to Jon Smirl

GPT is a GPIO pin that is cable able of measuring the lenght of pulses. GPTs are common on embedded systems

---
 drivers/input/ir/Kconfig  |    6 +
 drivers/input/ir/Makefile |    3 +
 drivers/input/ir/ir-gpt.c |  184 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 193 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/ir/ir-gpt.c
drivers/input/ir/Kconfig +6 -0
index a6f3f25..172c0c6 100644
@@ -12,4 +12,10 @@ menuconfig INPUT_IR
 
 if INPUT_IR
 
+config IR_GPT
+	tristate "GPT Based IR Receiver"
+	default m
+	help
+	  Driver for GPT-based IR receiver found on Digispeaker
+
 endif
drivers/input/ir/Makefile +3 -0
index 2ccdda3..ab0da3f 100644
@@ -6,3 +6,6 @@
 obj-$(CONFIG_INPUT_IR)		+= ir.o
 ir-objs := ir-core.o ir-configfs.o
 
+
+obj-$(CONFIG_IR_GPT)		+= ir-gpt.o
+
drivers/input/ir/ir-gpt.c new file +184 -0

184 lines not on this page · raw message

author
#11 lore raw

PATCH v4 5/6 Example of PowerPC device tree support for GPT based IR

In reply to Jon Smirl
---
 arch/powerpc/boot/dts/dspeak01.dts |   19 ++++++++-----------
 1 files changed, 8 insertions(+), 11 deletions(-)
arch/powerpc/boot/dts/dspeak01.dts +8 -11
index 429bb2f..50cc247 100644
@@ -131,16 +131,6 @@
 			#gpio-cells = <2>;
 		};
 
-		gpt7: timer@670 { /* General Purpose Timer in GPIO mode */
-			compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
-			cell-index = <7>;
-			reg = <0x670 0x10>;
-			interrupts = <0x1 0x10 0x0>;
-			interrupt-parent = <&mpc5200_pic>;
-			gpio-controller;
-			#gpio-cells = <2>;
-		};
-
 		rtc@800 {	// Real time clock
 			compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc";
 			device_type = "rtc";
@@ -320,6 +310,14 @@
 			reg = <0x8000 0x4000>;
 		};
 
+		ir0@670 { /* General Purpose Timer 6 in Input mode */
+			compatible = "gpt-ir";
+			cell-index = <7>;
+			reg = <0x670 0x10>;
+			interrupts = <0x1 0x10 0x0>;
+			interrupt-parent = <&mpc5200_pic>;
+		};
+
 		/* This is only an example device to show the usage of gpios. It maps all available
 		 * gpios to the "gpio-provider" device.
 		 */
@@ -335,7 +333,6 @@
 				 &gpt3		0 0 /* timer3		13d		x6-4	   */
 				 &gpt4		0 0 /* timer4		61c		x2-16	   */
 				 &gpt6		0 0 /* timer6		60c		x8-15	   */
-				 &gpt7		0 0 /* timer7		36a		x17-9	   */
 				 >;
 		};
 	};
author
#12 lore raw

PATCH v4 6/6 Microsoft mceusb2 driver for in-kernel IR subsystem

In reply to Jon Smirl

USB device commonly found on Microsoft Media Center boxes.

Hardware can send and recieve at all common IR frequencies - 36K, 38K, 40K, 56K

---
 drivers/input/ir/Kconfig      |    6 
 drivers/input/ir/Makefile     |    1 
 drivers/input/ir/ir-mceusb2.c |  745 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 752 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/ir/ir-mceusb2.c
drivers/input/ir/Kconfig +6 -0
index 172c0c6..b854900 100644
@@ -17,5 +17,11 @@ config IR_GPT
 	default m
 	help
 	  Driver for GPT-based IR receiver found on Digispeaker
+	  
+config IR_MCEUSB2
+	tristate "Microsoft Media Center Ed. Receiver, v2"
+	default m
+	help
+	  Driver for the Microsoft Media Center Ed. Receiver, v2
 
 endif
drivers/input/ir/Makefile +1 -0
index ab0da3f..0bdafb0 100644
@@ -8,4 +8,5 @@ ir-objs := ir-core.o ir-configfs.o
 
 
 obj-$(CONFIG_IR_GPT)		+= ir-gpt.o
+obj-$(CONFIG_IR_MCEUSB2)	+= ir-mceusb2.o
 
drivers/input/ir/ir-mceusb2.c new file +745 -0

745 lines not on this page · raw message

#13 lore raw
In reply to Jon Smirl

First up, thank you for reposting this. I believe several of us were keeping this code in mind for the in-kernel decoding portion of this discussion, but it hadn't been stated outright in the recent threads here.

Quoted 11 lines · Jon Smirl

This is a repost of the LIRC input patch series I wrote a year ago. Many of the ideas being discussed in the currect "Should we create a raw input interface for IR's?" thread have already been implemented in this code.

---------------------------------------------------

All of this kernel code is tiny, about 20K including a driver.

Basic flow works like this:

Quoted 7 lines

patch: Minimal changes to the core input system
Add a new IR data type to the input framework

patch: Core IR module
In-kernel decoding of core IR protocols - RC5, RC6, etc
This only converts from protocol pulse timing to common command format. Check out: http://www.sbprojects.com/knowledge/ir/sirc.htm

I think we can definitely take advantage of this for the in-kernel side of the initial hybrid approach I think we're converging on.

Quoted 4 lines

patch: Configfs support for IR
Decoded core protocols pass through a translation map based on configfs When core protocol matches an entry in configfs it is turned into a keycode event.

This part... Not so wild about. The common thought I'm seeing from people is that we should be using setkeycode to load keymaps. I mean, sure, I suppose this could be abstracted away so the user never sees it, but it seems to be reinventing a way to set up key mapping when setkeycode already exists, and is used by a number of existing IR devices in the v4l/dvb subsystem (as well as misc things like the ati rf remotes, iirc). Is there some distinct advantage to going this route vs. setkeycode that I'm missing?

Quoted 2 lines

patch: Microsoft mceusb2 driver for in-kernel IR subsystem Example mceusb IR input driver

Bah. I completely forgot you'd actually did have transmit code too.

...

Quoted 9 lines

Raw IR pulse data is available in a FIFO via sysfs. You can use this to figure out new remote protocols.

Two input events are generated
1) an event for the decoded raw IR protocol
2) a keycode event if the decoded raw IR protocol matches an entry in the configfs

You can also send pulses.

...

Quoted 6 lines

Raw mode. There are three sysfs attributes - ir_raw, ir_carrier, ir_xmitter. Read from ir_raw to get the raw timing data from the IR device. Set carrier and active xmitters and then copy raw data to ir_raw to send. These attributes may be better on a debug switch. You would use raw mode when decoding a new protocol. After you figure out the new protocol, write an in-kernel encoder/decoder for it.

Also neglected to recall there was raw IR data access too. However, a few things... One, this is, in some sense, cheating, as its not an input layer interface being used. :) Granted though, it *is* an existing kernel interface being used, instead of adding a new one. Two, there's no userspace to do anything with it at this time. I mean, sure, in theory, writing it wouldn't be that hard, but we can already do the same thing using the lirc interface, and already have userspace code for it. I think users need/desire to use raw IR modes may be more prevalent that most people think.

Quoted 2 lines

Two drivers are supplied. mceusb2 implements send and receive support for the Microsoft USB IR dongle.

I'd be game to try hacking up the lirc_mceusb driver (which has, since your work was done, merged mce v1 and v2 transceiver support) to support both your in-kernel interface and the lirc interface as an example of the hybrid approach I'm thinking of.

Quoted 3 lines

Code is only lightly tested. Encoders and decoders have not been written for all protocols. Repeat is not handled for any protocol. I'm looking for help. There are 15 more existing LIRC drivers.

And there's the hangup for me. The lirc drivers and interface have been pretty heavily battle-tested over years and years in the field. And there are those 15 more drivers that already work with the lirc interface. I'm woefully short on time to work on any porting myself, and about to get even shorter with some new responsibilities at work requiring even more of my attention.

If we go with a hybrid approach, all those existing drivers can be brought in supporting just the lirc interface initially, and have in-kernel decode support added as folks have time to work on them, if it actually makes sense for those devices.

Just trying to find a happy middle ground that minimizes regressions for users *and* gives us maximum flexibility.

Signature · 2 lines
Jarod Wilson
[email protected]
author
#14 lore raw
Quoted 7 lines · Jarod Wilson

This part... Not so wild about. The common thought I'm seeing from people is that we should be using setkeycode to load keymaps. I mean, sure, I suppose this could be abstracted away so the user never sees it, but it seems to be reinventing a way to set up key mapping when setkeycode already exists, and is used by a number of existing IR devices in the v4l/dvb subsystem (as well as misc things like the ati rf remotes, iirc). Is there some distinct advantage to going this route vs. setkeycode that I'm missing?

The configfs scheme and keymaps offer the same abilities. One is an ancient binary protocol and the other one uses Unix standard commands like mkdir and echo to build the map. You need special commands - setkeycodes, getkeycodes, showkey, loadkeys, xmodmap, dump-keys to use a keymap. I've been using Linux forever and I can't remember how these commands work.

Keymaps are a binary protocol written by Risto Kankkunen in 1993. Configfs was added by Oracle about two years ago but it has not been used for mapping purposes.

It's another discussion, but if IR goes the configfs route I'd consider writing a patch to switch keymaps/keycodes onto the configfs model. It is a huge advantage to get rid of these pointless special purpose commands that nobody knows how to use. I'd keep the legacy IOCTLs working and redirect the data structure to a configfs one instead of the existing structure.

The same idea is behind getting rid of IOCTLs and using sysfs. Normal Unix commands can manipulate sysfs. IOCTLs have problems with strace, endianess and the size of int (32/64b).

Signature · 2 lines
Jon Smirl
[email protected]
author
#16 lore raw
In reply to Jarod Wilson
Quoted 7 lines · Jarod Wilson
Quoted 6 lines

Raw mode. There are three sysfs attributes - ir_raw, ir_carrier, ir_xmitter. Read from ir_raw to get the raw timing data from the IR device. Set carrier and active xmitters and then copy raw data to ir_raw to send. These attributes may be better on a debug switch. You would use raw mode when decoding a new protocol. After you figure out the new protocol, write an in-kernel encoder/decoder for it.

Quoted 8 lines

Also neglected to recall there was raw IR data access too. However, a few things... One, this is, in some sense, cheating, as its not an input layer interface being used. :) Granted though, it *is* an existing kernel interface being used, instead of adding a new one. Two, there's no userspace to do anything with it at this time. I mean, sure, in theory, writing it wouldn't be that hard, but we can already do the same thing using the lirc interface, and already have userspace code for it. I think users need/desire to use raw IR modes may be more prevalent that most people think.

I would view raw mode as a developer interface which would be used to implement a new protocol decode engine. There is an assumption in my design that all IR timings can be decoded/constructed by a protocol engine. Sure we may end up with 40 protocol engines, but they are only about 50 lines of code. You could put each engine into a loadable module if you want.

You see raw data used a lot with Sony remotes. Sony remotes mix multiple protocols in a single remote. The irrecord program does not understand these mixed protocols and generates a raw mode config file. The mixed protocols don't bother the protocol state machine system. This happens with other mixed protocol remotes too.

Quoted 19 lines

Two drivers are supplied. mceusb2 implements send and receive support

Quoted 1 line

for the Microsoft USB IR dongle.

I'd be game to try hacking up the lirc_mceusb driver (which has, since your work was done, merged mce v1 and v2 transceiver support) to support both your in-kernel interface and the lirc interface as an example of the hybrid approach I'm thinking of.

Quoted 3 lines

Code is only lightly tested. Encoders and decoders have not been written for all protocols. Repeat is not handled for any protocol. I'm looking for help. There are 15 more existing LIRC drivers.

And there's the hangup for me. The lirc drivers and interface have been pretty heavily battle-tested over years and years in the field. And there are those 15 more drivers that already work with the lirc interface. I'm woefully short on time to work on any porting myself, and about to get even shorter with some new responsibilities at work requiring even more of my attention.

Quoted 7 lines

If we go with a hybrid approach, all those existing drivers can be brought in supporting just the lirc interface initially, and have in-kernel decode support added as folks have time to work on them, if it actually makes sense for those devices.

Just trying to find a happy middle ground that minimizes regressions for users *and* gives us maximum flexibility.

You are going to have to choose. Recreate the problems of type specific devices like /dev/mouse and /dev/kbd that evdev was created to fix, or skip those type specific devices and go straight to evdev. We've known for years the /dev/mouse was badly broken. How many more years is it going to be before it can be removed? /dev/lirc has the same type of problems that /dev/mouse has. The only reason that /dev/lirc works now is because there is a single app that uses it.

Also, implementing a new evdev based system in the kernel in no way breaks existing lirc installations. Just don't load the new implementation and everything works exactly the same way as before.

I'd go the evdev only route for in-kernel and leave existing lirc out of tree. Existing lirc will continue to work. This is probably the most stable strategy, even more so than a hybrid approach. The in-kernel implementation will then be free to evolve without the constraint of legacy APIs. As people become happy with it they can switch over.

Signature · 2 lines
Jon Smirl
[email protected]
#18 lore raw
In reply to Jarod Wilson
Quoted 8 lines · Jarod Wilson
Quoted 6 lines · Jon Smirl

Raw mode. There are three sysfs attributes - ir_raw, ir_carrier, ir_xmitter. Read from ir_raw to get the raw timing data from the IR device. Set carrier and active xmitters and then copy raw data to ir_raw to send. These attributes may be better on a debug switch. You would use raw mode when decoding a new protocol. After you figure out the new protocol, write an in-kernel encoder/decoder for it.

Quoted 5 lines

Also neglected to recall there was raw IR data access too. However, a few things... One, this is, in some sense, cheating, as its not an input layer interface being used. :) Granted though, it *is* an existing kernel interface being used, instead of adding a new one. Two, there's no userspace to do anything with it at this time.

No; it is a new interface, just using an existing mechanism (sysfs). Not all of sysfs in itself is an interface really; rather there is a number of interfaces which are implemented by means of sysfs.

sysfs is primarily meant for simple textual attributes though, not for I/O streams.

Signature · 3 lines
Stefan Richter
-=====-==--= =-== ==-==
http://arcgraph.de/sr/
maintainer
#15 lore raw
In reply to Jon Smirl
Quoted 9 lines · Jon Smirl
Quoted 7 lines · Jarod Wilson

This part... Not so wild about. The common thought I'm seeing from people is that we should be using setkeycode to load keymaps. I mean, sure, I suppose this could be abstracted away so the user never sees it, but it seems to be reinventing a way to set up key mapping when setkeycode already exists, and is used by a number of existing IR devices in the v4l/dvb subsystem (as well as misc things like the ati rf remotes, iirc). Is there some distinct advantage to going this route vs. setkeycode that I'm missing?

Quoted 6 lines

The configfs scheme and keymaps offer the same abilities. One is an ancient binary protocol and the other one uses Unix standard commands like mkdir and echo to build the map. You need special commands - setkeycodes, getkeycodes, showkey, loadkeys, xmodmap, dump-keys to use a keymap. I've been using Linux forever and I can't remember how these commands work.

Nor you really should - it all is mostly being used transparently for the end-user. I mean udev loading your laptop-specific keymap is not using loadkeys but specially written utility that issues EVIOCSKEYCODE directly.

Quoted 4 lines

Keymaps are a binary protocol written by Risto Kankkunen in 1993. Configfs was added by Oracle about two years ago but it has not been used for mapping purposes.

Nor it is even enabled by default... Do we want to make in mandatory on all consumer systems out there?

Quoted 7 lines

It's another discussion, but if IR goes the configfs route I'd consider writing a patch to switch keymaps/keycodes onto the configfs model. It is a huge advantage to get rid of these pointless special purpose commands that nobody knows how to use. I'd keep the legacy IOCTLs working and redirect the data structure to a configfs one instead of the existing structure.

What is the memory footprint for configfs solution though? I would hate to see the cost of user-modifiable keymap explode tenfold so that we can rely less (not even get rid of, since it is published userspace API/ABI) on setkeycodes and related ioctls.

Quoted 4 lines

The same idea is behind getting rid of IOCTLs and using sysfs. Normal Unix commands can manipulate sysfs. IOCTLs have problems with strace, endianess and the size of int (32/64b).

The size of long you mean, right? Besides, now that we know better we should simply use explicitely-sized fields in ioctl structures.

Signature · 1 line
Dmitry
maintainer
#17 lore raw
In reply to Jon Smirl
Quoted 20 lines · Jon Smirl
Quoted 12 lines
Quoted 4 lines

Code is only lightly tested. Encoders and decoders have not been written for all protocols. Repeat is not handled for any protocol. I'm looking for help. There are 15 more existing LIRC drivers.

And there's the hangup for me. The lirc drivers and interface have been pretty heavily battle-tested over years and years in the field. And there are those 15 more drivers that already work with the lirc interface. I'm woefully short on time to work on any porting myself, and about to get even shorter with some new responsibilities at work requiring even more of my attention.

Quoted 7 lines

If we go with a hybrid approach, all those existing drivers can be brought in supporting just the lirc interface initially, and have in-kernel decode support added as folks have time to work on them, if it actually makes sense for those devices.

Just trying to find a happy middle ground that minimizes regressions for users *and* gives us maximum flexibility.

Quoted 8 lines

You are going to have to choose. Recreate the problems of type specific devices like /dev/mouse and /dev/kbd that evdev was created to fix, or skip those type specific devices and go straight to evdev. We've known for years the /dev/mouse was badly broken. How many more years is it going to be before it can be removed? /dev/lirc has the same type of problems that /dev/mouse has. The only reason that /dev/lirc works now is because there is a single app that uses it.

Pardon my ignorance here but it does not seem that /dev/lirc actually multiplexes data stream from different receivers but rather creates a device per receiver... Multiplexing is the main issue with /dev/mouse for me.

What are the other issues with LIRC interface _for lircd-type applications_ do we see? I see for example that it is not 32/64 bit clean so that is somethign that we may consider re-evaluating before just acceptig it into kernel. Is there anything else?

Quoted 11 lines

Also, implementing a new evdev based system in the kernel in no way breaks existing lirc installations. Just don't load the new implementation and everything works exactly the same way as before.

I'd go the evdev only route for in-kernel and leave existing lirc out of tree. Existing lirc will continue to work. This is probably the most stable strategy, even more so than a hybrid approach. The in-kernel implementation will then be free to evolve without the constraint of legacy APIs. As people become happy with it they can switch over.

If by evdev-based system you mean adding EV_IR event to the input core I think it would be a mistake. Such data (EV_IR/IR_XXX) will have to be read from an event device, processed (probably in userspace) and re-injected back through uinput as (EV_KEY/KEY_XXX) for consumption again. Such looping interface would be a mistake IMHO.

Still, the end result of the transformation should be EV_KEY/KEY_XXX delivered on one of the event devices (preferrably one per remote, not one per receiver), I believe everyone agrees on that.

Signature · 1 line
Dmitry
#3 lore raw

Re: [IR-RFC PATCH v4 2/6] Core IR module

In reply to Jon Smirl
Quoted 4 lines · Jon Smirl

Changes to core input subsystem to allow send and receive of IR messages. Encode and decode state machines are provided for common IR porotocols such as Sony, JVC, NEC, Philips, etc.

Received IR messages generate event in the input queue. IR messages are sent using an input IOCTL.

As you are creating new sysfs files here, please document them in Documentation/ABI/

thanks,

greg k-h

#6 lore raw

Re: [IR-RFC PATCH v4 2/6] Core IR module

In reply to Jon Smirl
Quoted 9 lines
drivers/input/ir/ir-core.c new file +9 -0
+static ssize_t ir_raw_show(struct device *dev,
+				 struct device_attribute *attr, char *buf)
+{
+	struct input_dev *input_dev = to_input_dev(dev);
+	unsigned int i, count = 0;
+
+	for (i = input_dev->ir->raw.tail; i != input_dev->ir->raw.head; ) {
+
+		count += snprintf(&buf[count], PAGE_SIZE - 1, "%i\n", input_dev->ir->raw.buffer[i++]);

drivers/input/ir/ir-core.c line 583

Quoted 10 lines
drivers/input/ir/ir-core.c new file +10 -0
+		if (i > ARRAY_SIZE(input_dev->ir->raw.buffer))
+			i = 0;
+		if (count >= PAGE_SIZE - 1) {
+			input_dev->ir->raw.tail = i;
+			return PAGE_SIZE - 1;
+		}
+	}
+	input_dev->ir->raw.tail = i;
+	return count;
+}

This looks like it violates the "one value per sysfs file" rule that we have. What exactly are you outputting here? It does not look like this belongs in sysfs at all.

Quoted 20 lines
drivers/input/ir/ir-core.c new file +20 -0
+static ssize_t ir_raw_store(struct device *dev,
+				  struct device_attribute *attr,
+				  const char *buf,
+				  size_t count)
+{
+	struct ir_device *ir = to_input_dev(dev)->ir;
+	long delta;
+	int i = count;
+	int first = 0;
+
+	if (!ir->xmit)
+		return count;
+	ir->send.count = 0;
+
+	while (i > 0) {
+		i -= strict_strtoul(&buf[i], i, &delta);
+		while ((buf[i] != '\n') && (i > 0))
+			i--;
+		i--;
+		/* skip leading zeros */

drivers/input/ir/ir-core.c line 614

Quoted 10 lines
drivers/input/ir/ir-core.c new file +10 -0
+		if ((delta > 0) && !first)
+			continue;
+
+		ir->send.buffer[ir->send.count++] = abs(delta);
+	}
+
+	ir->xmit(ir->private, ir->send.buffer, ir->send.count, ir->raw.carrier, ir->raw.xmitter);
+
+	return count;
+}

What type of data are you expecting here? More than one value?

thanks,

greg k-h

author
#4 lore raw

Re: [IR-RFC PATCH v4 2/6] Core IR module

In reply to Greg KH
Quoted 8 lines · Greg KH
Quoted 4 lines · Jon Smirl

Changes to core input subsystem to allow send and receive of IR messages. Encode and decode state machines are provided for common IR porotocols such as Sony, JVC, NEC, Philips, etc.

Received IR messages generate event in the input queue. IR messages are sent using an input IOCTL.

As you are creating new sysfs files here, please document them in Documentation/ABI/

This code is not going to get merged as is. It's just a starting point to get a discussion started about designing an IR subsystem. I expect the final design will look a lot different.

I'm trying to demonstrate that IR is an input device and that it can be supported by the Linux input subsystem without the need to create a special IR device.

Signature · 2 lines
Jon Smirl
[email protected]
author
#7 lore raw

Re: [IR-RFC PATCH v4 2/6] Core IR module

In reply to Greg KH
Quoted 15 lines · Greg KH
Quoted 15 lines
drivers/input/ir/ir-core.c new file +15 -0
+static ssize_t ir_raw_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+     struct input_dev *input_dev = to_input_dev(dev);
+     unsigned int i, count = 0;
+
+     for (i = input_dev->ir->raw.tail; i != input_dev->ir->raw.head; ) {
+
+             count += snprintf(&buf[count], PAGE_SIZE - 1, "%i\n", input_dev->ir->raw.buffer[i++]);
+             if (i > ARRAY_SIZE(input_dev->ir->raw.buffer))
+                     i = 0;
+             if (count >= PAGE_SIZE - 1) {
+                     input_dev->ir->raw.tail = i;
+                     return PAGE_SIZE - 1;
+             }
Quoted 8 lines
Quoted 4 lines

+     }
+     input_dev->ir->raw.tail = i;
+     return count;
+}

This looks like it violates the "one value per sysfs file" rule that we have.  What exactly are you outputting here?  It does not look like this belongs in sysfs at all.

It should be on a debug switch or maybe a debug device. If the rest of the system is working right you shouldn't need this data.

Quoted 38 lines
Quoted 21 lines
drivers/input/ir/ir-core.c new file +20 -0
+static ssize_t ir_raw_store(struct device *dev,
+                               struct device_attribute *attr,
+                               const char *buf,
+                               size_t count)
+{
+     struct ir_device *ir = to_input_dev(dev)->ir;
+     long delta;
+     int i = count;
+     int first = 0;
+
+     if (!ir->xmit)
+             return count;
+     ir->send.count = 0;
+
+     while (i > 0) {
+             i -= strict_strtoul(&buf[i], i, &delta);
+             while ((buf[i] != '\n') && (i > 0))
+                     i--;
+             i--;
+             /* skip leading zeros */

drivers/input/ir/ir-core.c line 614

Quoted 10 lines
drivers/input/ir/ir-core.c new file +10 -0
+             if ((delta > 0) && !first)
+                     continue;
+
+             ir->send.buffer[ir->send.count++] = abs(delta);
+     }
+
+     ir->xmit(ir->private, ir->send.buffer, ir->send.count, ir->raw.carrier, ir->raw.xmitter);
+
+     return count;
+}

What type of data are you expecting here?  More than one value?

thanks,

greg k-h

Signature · 2 lines
Jon Smirl
[email protected]
#5 lore raw

Re: [IR-RFC PATCH v4 2/6] Core IR module

In reply to Jon Smirl
Quoted 7 lines · Jon Smirl
Quoted 6 lines · Greg KH
Quoted 4 lines · Jon Smirl

Changes to core input subsystem to allow send and receive of IR messages. Encode and decode state machines are provided for common IR porotocols such as Sony, JVC, NEC, Philips, etc.

Received IR messages generate event in the input queue. IR messages are sent using an input IOCTL.

Quoted 6 lines
Quoted 2 lines

As you are creating new sysfs files here, please document them in Documentation/ABI/

This code is not going to get merged as is. It's just a starting point to get a discussion started about designing an IR subsystem. I expect the final design will look a lot different.

Then show the design by adding the documentation for new sysfs files, to make it easier to understand by everyone please.

thanks,

greg k-h

#8 lore raw

Re: [IR-RFC PATCH v4 2/6] Core IR module

In reply to Jon Smirl
Quoted 25 lines · Jon Smirl
Quoted 15 lines · Greg KH
Quoted 15 lines
(quoted diff) +15 -0
+static ssize_t ir_raw_show(struct device *dev,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?struct device_attribute *attr, char *buf)
+{
+ ? ? struct input_dev *input_dev = to_input_dev(dev);
+ ? ? unsigned int i, count = 0;
+
+ ? ? for (i = input_dev->ir->raw.tail; i != input_dev->ir->raw.head; ) {
+
+ ? ? ? ? ? ? count += snprintf(&buf[count], PAGE_SIZE - 1, "%i\n", input_dev->ir->raw.buffer[i++]);
+ ? ? ? ? ? ? if (i > ARRAY_SIZE(input_dev->ir->raw.buffer))
+ ? ? ? ? ? ? ? ? ? ? i = 0;
+ ? ? ? ? ? ? if (count >= PAGE_SIZE - 1) {
+ ? ? ? ? ? ? ? ? ? ? input_dev->ir->raw.tail = i;
+ ? ? ? ? ? ? ? ? ? ? return PAGE_SIZE - 1;
+ ? ? ? ? ? ? }
Quoted 8 lines
Quoted 4 lines

+ ? ? }
+ ? ? input_dev->ir->raw.tail = i;
+ ? ? return count;
+}

This looks like it violates the "one value per sysfs file" rule that we have. ?What exactly are you outputting here? ?It does not look like this belongs in sysfs at all.

Quoted 2 lines

It should be on a debug switch or maybe a debug device. If the rest of the system is working right you shouldn't need this data.

Then why export it at all?

If it's debug stuff, please use debugfs, that is what it is there for.

thanks,

greg k-h