Skip to contentSkip to conversation

INPUT: Route keyboard LEDs through the generic LEDs layer

PATCH Superseded Samuel Thibault 3 participants 18 messages Dec 26, 2014 – Jan 23, 2015

Subsystems (4)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover INPUT: Route keyboard LEDs through the generic LEDs layer

Here is v5 coming, with separate patches for the kbd and the input parts.

Samuel

#1 lore raw

PATCH v5 1/2 INPUT: Introduce generic trigger/LED pairs between keyboard modifiers and input LEDs

This permits to change which modifier triggers which keyboard LEDs, by adding modifier triggers, and a series of evled LEDs.

This permits to fix #7063 from userland by using a modifier to implement proper CapsLock behavior and have the keyboard caps lock led show that modifier state.

[ebroder at mokafive.com: Rebased to 3.2-rc1 or so, cleaned up some includes, and fixed some constants]
[blogic at openwrt.org: CONFIG_INPUT_LEDS stubs should be static inline]
[akpm at linux-foundation.org: remove unneeded `extern', fix comment layout]

---
Changed in this version:
- separate kbd LED changes from input LED changes
- remove the VT triggers, revert back to emitting EV_LED events

drivers/tty/Kconfig +3 -0
@@ -13,6 +13,9 @@ config VT
 	bool "Virtual terminal" if EXPERT
 	depends on !S390 && !UML
 	select INPUT
+	select NEW_LEDS
+	select LEDS_CLASS
+	select LEDS_TRIGGERS
 	default y
 	---help---
 	  If you say Y here, you will get support for terminal devices with
drivers/tty/vt/keyboard.c +187 -23

267 lines not on this page · raw message

Documentation/leds/leds-class.txt +0 -3
@@ -2,9 +2,6 @@
 LED handling under Linux
 ========================
 
-If you're reading this and thinking about keyboard leds, these are
-handled by the input subsystem and the led class is *not* needed.
-
 In its simplest form, the LED class just allows control of LEDs from
 userspace. LEDs appear in /sys/class/leds/. The maximum brightness of the
 LED is defined in max_brightness file. The brightness file will set the brightness
drivers/leds/Kconfig +0 -3
@@ -11,9 +11,6 @@ menuconfig NEW_LEDS
 	  Say Y to enable Linux LED support.  This allows control of supported
 	  LEDs from both userspace and optionally, by kernel events (triggers).
 
-	  This is not related to standard keyboard LEDs which are controlled
-	  via the input system.
-
 if NEW_LEDS
 
 config LEDS_CLASS
#2 lore raw

PATCH v5 2/2 INPUT: Introduce generic trigger/LED pairs to input LEDs

In reply to Samuel Thibault

This permits to reassign input LEDs to something else than keyboard "leds" state, by adding a trigger and a led for each input leds, the former being triggered by EV_LED events, and the latter being by default triggered by the former. The user can then make the LED use another trigger, including other LED triggers of the same keyboard.

The hardware LEDs are now not actioned from the ED_LED event any more, but from the per-device LED layer.

[ebroder at mokafive.com: Rebased to 3.2-rc1 or so, cleaned up some includes, and fixed some constants]
[blogic at openwrt.org: CONFIG_INPUT_LEDS stubs should be static inline]
[akpm at linux-foundation.org: remove unneeded `extern', fix comment layout]

---
Changed in this version:
- separate kbd LED changes from input LED changes
- add a per-device trigger, triggered by EV_LED events
- make the per-device LED triggered by default by the per-device trigger, so that evdev users get the modified behavior too
- make the hardware driven by the LED instead of EV_LED events

drivers/input/input.c +21 -5
@@ -27,6 +27,7 @@
 #include <linux/device.h>
 #include <linux/mutex.h>
 #include <linux/rcupdate.h>
+#include <linux/leds.h>
 #include "input-compat.h"
 
 MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
@@ -324,11 +325,20 @@ static int input_get_disposition(struct
 		break;
 
 	case EV_LED:
-		if (is_event_supported(code, dev->ledbit, LED_MAX) &&
-		    !!test_bit(code, dev->led) != !!value) {
-
-			__change_bit(code, dev->led);
-			disposition = INPUT_PASS_TO_ALL;
+		if (is_event_supported(code, dev->ledbit, LED_MAX)) {
+#ifdef CONFIG_INPUT_LED
+			/* Redirect through trigger/LED pair */
+			if (dev->triggers && dev->triggers[code].name)
+				led_trigger_event(&dev->triggers[code],
+						  value ? LED_FULL : LED_OFF);
+			disposition = INPUT_PASS_TO_HANDLERS;
+#else /* !CONFIG_INPUT_LED */
+			/* Directly pass to device */
+			if (!!test_bit(code, dev->led) != !!value) {
+				__change_bit(code, dev->led);
+				disposition = INPUT_PASS_TO_ALL;
+			}
+#endif /* !CONFIG_INPUT_LED */
 		}
 		break;
 
@@ -711,6 +721,9 @@ static void input_disconnect_device(stru
 		handle->open = 0;
 
 	spin_unlock_irq(&dev->event_lock);
+
+	if (is_event_supported(EV_LED, dev->evbit, EV_MAX))
+		input_led_disconnect(dev);
 }
 
 /**
@@ -2137,6 +2150,9 @@ int input_register_device(struct input_d
 
 	list_add_tail(&dev->node, &input_dev_list);
 
+	if (is_event_supported(EV_LED, dev->evbit, EV_MAX))
+		input_led_connect(dev);
+
 	list_for_each_entry(handler, &input_handler_list, node)
 		input_attach_handler(dev, handler);
 
drivers/input/Kconfig +9 -0
@@ -178,6 +178,15 @@ comment "Input Device Drivers"
 
 source "drivers/input/keyboard/Kconfig"
 
+config INPUT_LEDS
+	bool "LED Support"
+	depends on LEDS_CLASS = INPUT || LEDS_CLASS = y
+	select LEDS_TRIGGERS
+	default y
+	help
+	  This option enables support for LEDs on keyboards managed
+	  by the input layer.
+
 source "drivers/input/mouse/Kconfig"
 
 source "drivers/input/joystick/Kconfig"
drivers/input/Makefile +3 -0
@@ -6,6 +6,9 @@
 
 obj-$(CONFIG_INPUT)		+= input-core.o
 input-core-y := input.o input-compat.o input-mt.o ff-core.o
+ifeq ($(CONFIG_INPUT_LEDS),y)
+input-core-y += leds.o
+endif
 
 obj-$(CONFIG_INPUT_FF_MEMLESS)	+= ff-memless.o
 obj-$(CONFIG_INPUT_POLLDEV)	+= input-polldev.o
include/linux/input.h +23 -0
@@ -79,6 +79,8 @@ struct input_value {
  * @led: reflects current state of device's LEDs
  * @snd: reflects current state of sound effects
  * @sw: reflects current state of device's switches
+ * @leds: led objects for the device's LEDs
+ * @triggers: trigger objects for the device's LEDs
  * @open: this method is called when the very first user calls
  *	input_open_device(). The driver must prepare the device
  *	to start generating events (start polling thread,
@@ -164,6 +166,9 @@ struct input_dev {
 	unsigned long snd[BITS_TO_LONGS(SND_CNT)];
 	unsigned long sw[BITS_TO_LONGS(SW_CNT)];
 
+	struct led_classdev *leds;
+	struct led_trigger *triggers;
+
 	int (*open)(struct input_dev *dev);
 	void (*close)(struct input_dev *dev);
 	int (*flush)(struct input_dev *dev, struct file *file);
@@ -531,4 +536,22 @@ int input_ff_erase(struct input_dev *dev
 int input_ff_create_memless(struct input_dev *dev, void *data,
 		int (*play_effect)(struct input_dev *, void *, struct ff_effect *));
 
+#ifdef CONFIG_INPUT_LEDS
+
+int input_led_connect(struct input_dev *dev);
+void input_led_disconnect(struct input_dev *dev);
+
+#else
+
+static inline int input_led_connect(struct input_dev *dev)
+{
+	return 0;
+}
+
+static inline void input_led_disconnect(struct input_dev *dev)
+{
+}
+
+#endif
+
 #endif
drivers/input/leds.c new file +155 -0

155 lines not on this page · raw message

maintainer
#3 lore raw

Re: [PATCHv5 2/2] INPUT: Introduce generic trigger/LED pairs to input LEDs

Hi Samuel,

Quoted 36 lines · Samuel Thibault

This permits to reassign input LEDs to something else than keyboard "leds" state, by adding a trigger and a led for each input leds, the former being triggered by EV_LED events, and the latter being by default triggered by the former. The user can then make the LED use another trigger, including other LED triggers of the same keyboard.

The hardware LEDs are now not actioned from the ED_LED event any more, but from the per-device LED layer.

[ebroder at mokafive.com: Rebased to 3.2-rc1 or so, cleaned up some includes, and fixed some constants]
[blogic at openwrt.org: CONFIG_INPUT_LEDS stubs should be static inline]
[akpm at linux-foundation.org: remove unneeded `extern', fix comment layout]

---
Changed in this version:
- separate kbd LED changes from input LED changes
- add a per-device trigger, triggered by EV_LED events
- make the per-device LED triggered by default by the per-device trigger, so that evdev users get the modified behavior too
- make the hardware driven by the LED instead of EV_LED events

drivers/input/input.c +1 -0
@@ -27,6 +27,7 @@
 #include <linux/device.h>
 #include <linux/mutex.h>
 #include <linux/rcupdate.h>
+#include <linux/leds.h>
 #include "input-compat.h"
 
 MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");

drivers/input/input.c static int input_get_disposition(struct · line 329

Quoted 10 lines
drivers/input/input.c +2 -5
@@ -324,11 +325,20 @@ static int input_get_disposition(struct
 		break;
 
 	case EV_LED:
-		if (is_event_supported(code, dev->ledbit, LED_MAX) &&
-		    !!test_bit(code, dev->led) != !!value) {
-
-			__change_bit(code, dev->led);
-			disposition = INPUT_PASS_TO_ALL;
+		if (is_event_supported(code, dev->ledbit, LED_MAX)) {
+#ifdef CONFIG_INPUT_LED

I'd rather we did not have a separate config option for this. Do we really need to support case where LEDs are disabled? I'd rather stub it out instead of providing 2 separate code paths.

Quoted 173 lines
drivers/input/input.c +18 -0
+			/* Redirect through trigger/LED pair */
+			if (dev->triggers && dev->triggers[code].name)
+				led_trigger_event(&dev->triggers[code],
+						  value ? LED_FULL : LED_OFF);
+			disposition = INPUT_PASS_TO_HANDLERS;
+#else /* !CONFIG_INPUT_LED */
+			/* Directly pass to device */
+			if (!!test_bit(code, dev->led) != !!value) {
+				__change_bit(code, dev->led);
+				disposition = INPUT_PASS_TO_ALL;
+			}
+#endif /* !CONFIG_INPUT_LED */
 		}
 		break;
 
@@ -711,6 +721,9 @@ static void input_disconnect_device(stru
 		handle->open = 0;
 
 	spin_unlock_irq(&dev->event_lock);
+
+	if (is_event_supported(EV_LED, dev->evbit, EV_MAX))
+		input_led_disconnect(dev);
 }
 
 /**
@@ -2137,6 +2150,9 @@ int input_register_device(struct input_d
 
 	list_add_tail(&dev->node, &input_dev_list);
 
+	if (is_event_supported(EV_LED, dev->evbit, EV_MAX))
+		input_led_connect(dev);
+
 	list_for_each_entry(handler, &input_handler_list, node)
 		input_attach_handler(dev, handler);
 
drivers/input/Kconfig +9 -0
@@ -178,6 +178,15 @@ comment "Input Device Drivers"
 
 source "drivers/input/keyboard/Kconfig"
 
+config INPUT_LEDS
+	bool "LED Support"
+	depends on LEDS_CLASS = INPUT || LEDS_CLASS = y
+	select LEDS_TRIGGERS
+	default y
+	help
+	  This option enables support for LEDs on keyboards managed
+	  by the input layer.
+
 source "drivers/input/mouse/Kconfig"
 
 source "drivers/input/joystick/Kconfig"
drivers/input/Makefile +3 -0
@@ -6,6 +6,9 @@
 
 obj-$(CONFIG_INPUT)		+= input-core.o
 input-core-y := input.o input-compat.o input-mt.o ff-core.o
+ifeq ($(CONFIG_INPUT_LEDS),y)
+input-core-y += leds.o
+endif
 
 obj-$(CONFIG_INPUT_FF_MEMLESS)	+= ff-memless.o
 obj-$(CONFIG_INPUT_POLLDEV)	+= input-polldev.o
include/linux/input.h +23 -0
@@ -79,6 +79,8 @@ struct input_value {
  * @led: reflects current state of device's LEDs
  * @snd: reflects current state of sound effects
  * @sw: reflects current state of device's switches
+ * @leds: led objects for the device's LEDs
+ * @triggers: trigger objects for the device's LEDs
  * @open: this method is called when the very first user calls
  *	input_open_device(). The driver must prepare the device
  *	to start generating events (start polling thread,
@@ -164,6 +166,9 @@ struct input_dev {
 	unsigned long snd[BITS_TO_LONGS(SND_CNT)];
 	unsigned long sw[BITS_TO_LONGS(SW_CNT)];
 
+	struct led_classdev *leds;
+	struct led_trigger *triggers;
+
 	int (*open)(struct input_dev *dev);
 	void (*close)(struct input_dev *dev);
 	int (*flush)(struct input_dev *dev, struct file *file);
@@ -531,4 +536,22 @@ int input_ff_erase(struct input_dev *dev
 int input_ff_create_memless(struct input_dev *dev, void *data,
 		int (*play_effect)(struct input_dev *, void *, struct ff_effect *));
 
+#ifdef CONFIG_INPUT_LEDS
+
+int input_led_connect(struct input_dev *dev);
+void input_led_disconnect(struct input_dev *dev);
+
+#else
+
+static inline int input_led_connect(struct input_dev *dev)
+{
+	return 0;
+}
+
+static inline void input_led_disconnect(struct input_dev *dev)
+{
+}
+
+#endif
+
 #endif
drivers/input/leds.c new file +61 -0
@@ -0,0 +1,155 @@
+/*
+ * LED support for the input layer
+ *
+ * Copyright 2010-2014 Samuel Thibault <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+/*
+ * This creates a trigger/LED pair per device:
+ * - the trigger is actioned from the core's input_get_disposition,
+ * - the LED is by default triggered by that trigger
+ * - the LED actuates the hardware.
+ */
+
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/leds.h>
+#include <linux/input.h>
+
+static const char *const input_led_names[LED_CNT] = {
+	[LED_NUML] = "numl",
+	[LED_CAPSL] = "capsl",
+	[LED_SCROLLL] = "scrolll",
+	[LED_COMPOSE] = "compose",
+	[LED_KANA] = "kana",
+	[LED_SLEEP] = "sleep",
+	[LED_SUSPEND] = "suspend",
+	[LED_MUTE] = "mute",
+	[LED_MISC] = "misc",
+	[LED_MAIL] = "mail",
+	[LED_CHARGING] = "charging",
+};
+
+/* Free LED data from input device, used at abortion and disconnection.  */
+static void input_led_delete(struct input_dev *dev)
+{
+	if (dev) {
+		struct led_classdev *leds = dev->leds;
+		struct led_trigger *triggers = dev->triggers;
+		int i;
+
+		if (leds) {
+			for (i = 0; i < LED_CNT; i++)
+				kfree(leds[i].name);
+			kfree(leds);
+			dev->leds = NULL;
+		}
+
+		if (triggers) {
+			for (i = 0; i < LED_CNT; i++)
+				kfree(triggers[i].name);
+			kfree(triggers);
+			dev->triggers = NULL;
+		}
+	}
+}

drivers/input/leds.c line 71

Quoted 10 lines
drivers/input/leds.c new file +10 -0
+
+/* LED state change for some keyboard, notify that keyboard.  */
+static void perdevice_input_led_set(struct led_classdev *cdev,
+			  enum led_brightness brightness)
+{
+	struct input_dev *dev;
+	struct led_classdev *leds;
+	int led;
+
+	dev = cdev->dev->platform_data;

Umm, platform data is not the best place for storing this. Why not drvdata?

Quoted 15 lines
drivers/input/leds.c new file +15 -0
+	if (!dev)
+		/* Still initializing */
+		return;
+
+	leds = dev->leds;
+	led = cdev - leds;
+
+	if (test_bit(EV_LED, dev->evbit) &&
+		led <= LED_MAX && test_bit(led, dev->ledbit) &&
+		!!test_bit(led, dev->led) != !!brightness) {
+		__change_bit(led, dev->led);
+		dev->event(dev, EV_LED, led, !!brightness);
+	}
+}
+

drivers/input/leds.c line 96

Quoted 10 lines
drivers/input/leds.c new file +10 -0
+/* A new input device with potential LEDs to connect.  */
+int input_led_connect(struct input_dev *dev)
+{
+	int i, error = -ENOMEM;
+	struct led_classdev *leds;
+	struct led_trigger *triggers;
+
+	leds = kcalloc(LED_CNT, sizeof(*leds), GFP_KERNEL);
+	if (!leds)
+		goto err;

Why do we allocate all possible led's for every device?

drivers/input/leds.c line 102

Quoted 6 lines
drivers/input/leds.c new file +6 -0
+	dev->leds = leds;
+
+	triggers = kcalloc(LED_CNT, sizeof(*triggers), GFP_KERNEL);
+	if (!triggers)
+		goto err;
+	dev->triggers = triggers;

Hmm, maybe having per-device triggers is a bit of overkill and we could have just "input-numl", "input-capsl", etc.

Quoted 19 lines
drivers/input/leds.c new file +19 -0
+
+	/* Register this device's LEDs and triggers */
+	for (i = 0; i < LED_CNT; i++)
+		if (input_led_names[i] && test_bit(i, dev->ledbit)) {
+			leds[i].name = kasprintf(GFP_KERNEL, "%s::%s",
+						dev_name(&dev->dev),
+						input_led_names[i]);
+			if (!leds[i].name)
+				goto err;
+			leds[i].max_brightness = 1;
+			leds[i].brightness_set = perdevice_input_led_set;
+
+			triggers[i].name = kasprintf(GFP_KERNEL, "%s-%s",
+						dev_name(&dev->dev),
+						input_led_names[i]);
+			if (!triggers[i].name)
+				goto err;
+
+			/* make the LED triggered by the corresponding trigger

drivers/input/leds.c line 131

Quoted 10 lines
drivers/input/leds.c new file +10 -0
+			 * by default */
+			leds[i].default_trigger = triggers[i].name;
+		}
+
+	/* No issue so far, we can register for real.  */
+	for (i = 0; i < LED_CNT; i++)
+		if (leds[i].name) {
+			led_classdev_register(&dev->dev, &leds[i]);
+			leds[i].dev->platform_data = dev;
+			led_trigger_register(&triggers[i]);

We need error handling here.

Quoted 14 lines
drivers/input/leds.c new file +14 -0
+		}
+
+	return 0;
+
+err:
+	input_led_delete(dev);
+	return error;
+}
+
+void input_led_disconnect(struct input_dev *dev)
+{
+	int i;
+	struct led_classdev *leds = dev->leds;
+	struct led_trigger *triggers = dev->triggers;

drivers/input/leds.c line 155

Quoted 10 lines
drivers/input/leds.c new file +10 -0
+
+	for (i = 0; i < LED_CNT; i++) {
+		if (leds[i].name)
+			led_classdev_unregister(&leds[i]);
+		if (triggers[i].name)
+			led_trigger_unregister(&triggers[i]);
+	}
+
+	input_led_delete(dev);
+}

Thanks.

Signature · 1 line
Dmitry
#4 lore raw

Re: [PATCHv5 2/2] INPUT: Introduce generic trigger/LED pairs to input LEDs

Dmitry Torokhov, le Sun 04 Jan 2015 15:28:38 -0800, a ?crit :

Quoted 2 lines

I'd rather we did not have a separate config option for this. Do we really need to support case where LEDs are disabled?

I don't really mind.

Quoted 1 line

I'd rather stub it out instead of providing 2 separate code paths.

Ok.

Quoted 11 lines

drivers/input/leds.c line 71

Quoted 9 lines
drivers/input/leds.c new file +9 -0
+/* LED state change for some keyboard, notify that keyboard.  */
+static void perdevice_input_led_set(struct led_classdev *cdev,
+			  enum led_brightness brightness)
+{
+	struct input_dev *dev;
+	struct led_classdev *leds;
+	int led;
+
+	dev = cdev->dev->platform_data;

Umm, platform data is not the best place for storing this. Why not drvdata?

Just because it didn't exist when I wrote the code :) Ok.

Quoted 4 lines
Quoted 4 lines
drivers/input/leds.c new file +4 -0
+/* A new input device with potential LEDs to connect.  */
+int input_led_connect(struct input_dev *dev)
+{
+	int i, error = -ENOMEM;
Quoted 8 lines

drivers/input/leds.c line 96

Quoted 6 lines
drivers/input/leds.c new file +6 -0
+	struct led_classdev *leds;
+	struct led_trigger *triggers;
+
+	leds = kcalloc(LED_CNT, sizeof(*leds), GFP_KERNEL);
+	if (!leds)
+		goto err;

Why do we allocate all possible led's for every device?

Ah, right, that was making things simpler, but it could be squeezed. I'm just afraid of one thing: may dev->ledbit change after input_register_device? It seems that at least uinput somehow permits this. It then means having to store the number of actually created LEDs and triggers alongside.

Quoted 9 lines

drivers/input/leds.c line 102

Quoted 6 lines
drivers/input/leds.c new file +6 -0
+	dev->leds = leds;
+
+	triggers = kcalloc(LED_CNT, sizeof(*triggers), GFP_KERNEL);
+	if (!triggers)
+		goto err;
+	dev->triggers = triggers;

Hmm, maybe having per-device triggers is a bit of overkill and we could have just "input-numl", "input-capsl", etc.

No, that won't work, notably for evdev access: we have to respect the per-device semantic.

Quoted 8 lines

drivers/input/leds.c line 131

Quoted 6 lines
drivers/input/leds.c new file +6 -0
+	/* No issue so far, we can register for real.  */
+	for (i = 0; i < LED_CNT; i++)
+		if (leds[i].name) {
+			led_classdev_register(&dev->dev, &leds[i]);
+			leds[i].dev->platform_data = dev;
+			led_trigger_register(&triggers[i]);

We need error handling here.

Right.

Samuel

maintainer
#5 lore raw

Re: [PATCHv5 2/2] INPUT: Introduce generic trigger/LED pairs to input LEDs

Hi Samuel,

Quoted 38 lines · Samuel Thibault

Dmitry Torokhov, le Sun 04 Jan 2015 15:28:38 -0800, a ?crit :

Quoted 2 lines

I'd rather we did not have a separate config option for this. Do we really need to support case where LEDs are disabled?

I don't really mind.

Quoted 1 line

I'd rather stub it out instead of providing 2 separate code paths.

Ok.

Quoted 11 lines

drivers/input/leds.c line 71

Quoted 9 lines
drivers/input/leds.c new file +9 -0
+/* LED state change for some keyboard, notify that keyboard.  */
+static void perdevice_input_led_set(struct led_classdev *cdev,
+			  enum led_brightness brightness)
+{
+	struct input_dev *dev;
+	struct led_classdev *leds;
+	int led;
+
+	dev = cdev->dev->platform_data;

Umm, platform data is not the best place for storing this. Why not drvdata?

Just because it didn't exist when I wrote the code :) Ok.

Quoted 4 lines
Quoted 4 lines
drivers/input/leds.c new file +4 -0
+/* A new input device with potential LEDs to connect.  */
+int input_led_connect(struct input_dev *dev)
+{
+	int i, error = -ENOMEM;
Quoted 8 lines

drivers/input/leds.c line 96

Quoted 6 lines
drivers/input/leds.c new file +6 -0
+	struct led_classdev *leds;
+	struct led_trigger *triggers;
+
+	leds = kcalloc(LED_CNT, sizeof(*leds), GFP_KERNEL);
+	if (!leds)
+		goto err;

Why do we allocate all possible led's for every device?

Quoted 5 lines

Ah, right, that was making things simpler, but it could be squeezed. I'm just afraid of one thing: may dev->ledbit change after input_register_device? It seems that at least uinput somehow permits this. It then means having to store the number of actually created LEDs and triggers alongside.

The input device's capabilities (with the exception of keymap) should not change after device registration. If uinput allows that we should fix it there.

Thanks.

Quoted 26 lines
Quoted 10 lines

drivers/input/leds.c line 102

Quoted 7 lines
drivers/input/leds.c new file +6 -0
+	dev->leds = leds;
+
+	triggers = kcalloc(LED_CNT, sizeof(*triggers), GFP_KERNEL);
+	if (!triggers)
+		goto err;
+	dev->triggers = triggers;

Hmm, maybe having per-device triggers is a bit of overkill and we could have just "input-numl", "input-capsl", etc.

No, that won't work, notably for evdev access: we have to respect the per-device semantic.

Quoted 8 lines

drivers/input/leds.c line 131

Quoted 6 lines
drivers/input/leds.c new file +6 -0
+	/* No issue so far, we can register for real.  */
+	for (i = 0; i < LED_CNT; i++)
+		if (leds[i].name) {
+			led_classdev_register(&dev->dev, &leds[i]);
+			leds[i].dev->platform_data = dev;
+			led_trigger_register(&triggers[i]);

We need error handling here.

Right.

Samuel

Signature · 1 line
Dmitry
#6 lore raw

Re: [PATCHv5 2/2] INPUT: Introduce generic trigger/LED pairs to input LEDs

Dmitry Torokhov, le Mon 05 Jan 2015 09:42:05 -0800, a ?crit :

Quoted 3 lines

The input device's capabilities (with the exception of keymap) should not change after device registration. If uinput allows that we should fix it there.

Ah, I didn't notice the content of uinput_set_bit() there. It seems to be making sure that the device hasn't been created yet indeed. All good then.

Samuel

#7 lore raw

Re: [PATCHv5 2/2] INPUT: Introduce generic trigger/LED pairs to input LEDs

In reply to Dmitry Torokhov

Dmitry Torokhov, le Sun 04 Jan 2015 15:28:38 -0800, a ?crit :

Quoted 3 lines

drivers/input/leds.c line 71

Quoted 1 line
drivers/input/leds.c new file +1 -0
+	dev = cdev->dev->platform_data;

Umm, platform data is not the best place for storing this. Why not drvdata?

Ah, actually led_classdev already makes use of it, see the device_create_with_groups call in led_classdev_register.

Samuel

#8 lore raw

Re: [PATCHv5 2/2] INPUT: Introduce generic trigger/LED pairs to input LEDs

Samuel Thibault, le Fri 23 Jan 2015 01:10:38 +0100, a ?crit :

Quoted 7 lines

Dmitry Torokhov, le Sun 04 Jan 2015 15:28:38 -0800, a ?crit :

Quoted 3 lines

drivers/input/leds.c line 71

Quoted 1 line
drivers/input/leds.c new file +1 -0
+	dev = cdev->dev->platform_data;

Umm, platform data is not the best place for storing this. Why not drvdata?

Ah, actually led_classdev already makes use of it, see the device_create_with_groups call in led_classdev_register.

Actually I'd say it makes sense to be using the platform_data field:
from the point of view of the led object, the input object is indeed something like a platform.

Samuel

maintainer
#9 lore raw

Re: [PATCHv5 2/2] INPUT: Introduce generic trigger/LED pairs to input LEDs

Quoted 7 lines · Samuel Thibault

Samuel Thibault, le Fri 23 Jan 2015 01:10:38 +0100, a ?crit :

Quoted 6 lines

Dmitry Torokhov, le Sun 04 Jan 2015 15:28:38 -0800, a ?crit :

Quoted 4 lines

drivers/input/leds.c line 71

Quoted 1 line
drivers/input/leds.c new file +1 -0
+	dev = cdev->dev->platform_data;

Umm, platform data is not the best place for storing this. Why not drvdata?

Quoted 6 lines
Quoted 2 lines

Ah, actually led_classdev already makes use of it, see the device_create_with_groups call in led_classdev_register.

Actually I'd say it makes sense to be using the platform_data field:
from the point of view of the led object, the input object is indeed something like a platform.

No, platform data is what difefrentiates an arm board from another arm board, or an x86 or mips one.

Thanks.

Signature · 1 line
Dmitry
#10 lore raw

Re: [PATCHv5 2/2] INPUT: Introduce generic trigger/LED pairs to input LEDs

Dmitry Torokhov, le Thu 22 Jan 2015 16:37:02 -0800, a ?crit :

Quoted 11 lines · Samuel Thibault
Quoted 10 lines

Samuel Thibault, le Fri 23 Jan 2015 01:10:38 +0100, a ?crit :

Quoted 8 lines

Dmitry Torokhov, le Sun 04 Jan 2015 15:28:38 -0800, a ?crit :

Quoted 4 lines

drivers/input/leds.c line 71

Quoted 1 line
drivers/input/leds.c new file +1 -0
+	dev = cdev->dev->platform_data;

Umm, platform data is not the best place for storing this. Why not drvdata?

Ah, actually led_classdev already makes use of it, see the device_create_with_groups call in led_classdev_register.

Quoted 8 lines
Quoted 3 lines

Actually I'd say it makes sense to be using the platform_data field:
from the point of view of the led object, the input object is indeed something like a platform.

No, platform data is what difefrentiates an arm board from another arm board, or an x86 or mips one.

From the point of view of a device connected to that board, yes. But

from the point of view of LEDs connected to a keyboard, the platform is the keyboard.

Samuel

maintainer
#11 lore raw

Re: [PATCHv5 2/2] INPUT: Introduce generic trigger/LED pairs to input LEDs

Quoted 16 lines · Samuel Thibault

Dmitry Torokhov, le Thu 22 Jan 2015 16:37:02 -0800, a ?crit :

Quoted 15 lines · Samuel Thibault
Quoted 13 lines

Samuel Thibault, le Fri 23 Jan 2015 01:10:38 +0100, a ?crit :

Quoted 8 lines

Dmitry Torokhov, le Sun 04 Jan 2015 15:28:38 -0800, a ?crit :

Quoted 4 lines

drivers/input/leds.c line 71

Quoted 1 line
drivers/input/leds.c new file +1 -0
+	dev = cdev->dev->platform_data;

Umm, platform data is not the best place for storing this. Why not drvdata?

Ah, actually led_classdev already makes use of it, see the device_create_with_groups call in led_classdev_register.

Actually I'd say it makes sense to be using the platform_data field:
from the point of view of the led object, the input object is indeed something like a platform.

Quoted 6 lines
Quoted 2 lines

No, platform data is what difefrentiates an arm board from another arm board, or an x86 or mips one.

From the point of view of a device connected to that board, yes. But from the point of view of LEDs connected to a keyboard, the platform is the keyboard.

No. Please take a look at other users of platform data. Platform is the box we are running on, not parent device. Platform data is supposed to be constant, not changing between driver runs.

Thanks.

Signature · 1 line
Dmitry
#12 lore raw

Re: [PATCHv5 2/2] INPUT: Introduce generic trigger/LED pairs to input LEDs

Dmitry Torokhov, le Thu 22 Jan 2015 16:51:16 -0800, a ?crit :

Quoted 3 lines

No. Please take a look at other users of platform data. Platform is the box we are running on, not parent device. Platform data is supposed to be constant, not changing between driver runs.

Ok, well, then we can just use to_input_dev(cdev->dev->parent); to access the input_dev from the led_classdev cdev.

Samuel

#13 lore raw
In reply to Samuel Thibault

Hi!

Quoted 2 lines

Here is v5 coming, with separate patches for the kbd and the input parts.

After booting with this, capslock led does not seem to work on text console.

input4::capsl/trigger was none by default, that can't be right, right?

I tried putting kbd-capslock and input4-capsl there, but that did not seem to help.

It works with heartbeat trigger, but not with input4-numl trigger. (But numlock led works ok with that trigger, weird).

vt::capsl/brightness controls capslock led, even when input4-capsl/trigger is set to input4-numl.

Confused,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#14 lore raw

Pavel Machek, le Fri 02 Jan 2015 20:53:51 +0100, a ?crit :

Quoted 1 line

input4::capsl/trigger was none by default, that can't be right, right?

Indeed. And I don't see how it can be that way, since the input4::capsl LED and the input4-capsl trigger get initialized at the same time in input_led_connect... (and the order does not matter since both will try to connect to the other on registration).

Quoted 2 lines

I tried putting kbd-capslock and input4-capsl there, but that did not seem to help.

That should have.

Quoted 2 lines

It works with heartbeat trigger, but not with input4-numl trigger.

It should have worked with input4-numl too.

Quoted 2 lines

vt::capsl/brightness controls capslock led, even when input4-capsl/trigger is set to input4-numl.

It shouldn't.

Quoted 1 line

Confused,

I guess I'm even more. I had tested everything that you have described, without any issue, on both an internal laptop keyboard and an external USB keyboard, and have tested again just now, with the same success.

Which hardware setup do you have, more precisely?

Samuel

#15 lore raw
Quoted 23 lines · Samuel Thibault

Pavel Machek, le Fri 02 Jan 2015 20:53:51 +0100, a ?crit :

Quoted 1 line

input4::capsl/trigger was none by default, that can't be right, right?

Indeed. And I don't see how it can be that way, since the input4::capsl LED and the input4-capsl trigger get initialized at the same time in input_led_connect... (and the order does not matter since both will try to connect to the other on registration).

Quoted 2 lines

I tried putting kbd-capslock and input4-capsl there, but that did not seem to help.

That should have.

Quoted 2 lines

It works with heartbeat trigger, but not with input4-numl trigger.

It should have worked with input4-numl too.

Quoted 2 lines

vt::capsl/brightness controls capslock led, even when input4-capsl/trigger is set to input4-numl.

It shouldn't.

Quoted 7 lines
Quoted 1 line

Confused,

I guess I'm even more. I had tested everything that you have described, without any issue, on both an internal laptop keyboard and an external USB keyboard, and have tested again just now, with the same success.

Which hardware setup do you have, more precisely?

I tested on Thinkpad X60, with internal keyboard. (PS/2, I'd say). I let Debian boot into graphical login prompt, switched to text console, and did the testing there.

Thanks,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#16 lore raw
In reply to Pavel Machek

Hello,

Pavel Machek, le Fri 02 Jan 2015 20:53:51 +0100, a ?crit :

Quoted 8 lines
Quoted 2 lines

Here is v5 coming, with separate patches for the kbd and the input parts.

After booting with this, capslock led does not seem to work on text console.

input4::capsl/trigger was none by default, that can't be right, right?

Quoted 8 lines

I tried putting kbd-capslock and input4-capsl there, but that did not seem to help.

It works with heartbeat trigger, but not with input4-numl trigger. (But numlock led works ok with that trigger, weird).

vt::capsl/brightness controls capslock led, even when input4-capsl/trigger is set to input4-numl.

I have just tried what you described on a thinkpad lenovo T500, without any problem, except that the thinkpad BIOS does a couple of funky things:

- depending on the numlock bios setting, the numlock led will be driven by the OS (synchronized mode) or handled internally in the BIOS (independent mode).
- in synchronized mode, whenever the internal numlock led is lit, the right part of the internal keyboard acts as the keypad keys.

Samuel

#17 lore raw

Hello,

Samuel Thibault, le Wed 21 Jan 2015 16:21:12 +0100, a ?crit :

Quoted 3 lines

I have just tried what you described on a thinkpad lenovo T500, without any problem, except that the thinkpad BIOS does a couple of funky things:

Actually it's even worse than that: depending on whether it is in synchronized mode or independent mode, *and* depending on the current *state* of the internal numlock LED, and probably also whether an external keyboard is connected, the internal numlock key will produce *or not* key events! The actual transition table for this seems quite clumsy, basically the BIOS seems to be assuming that the the numlock key toggles the numlock LED, and setting up anything different leads to all kinds of confusing effects, the "simplest" of which being that you definitely not want to set e.g. a heartbeat trigger on the numlock LED, or else the right part of the keyboard will randomly behave as a keypad...

I guess that may happen with other laptops, so I'm afraid I can only reject any kind of bug report involving the internal numlock LED or key of a laptop.

So we're left with these:

Pavel Machek, le Fri 02 Jan 2015 20:53:51 +0100, a ?crit :

Quoted 5 lines
Quoted 2 lines

Here is v5 coming, with separate patches for the kbd and the input parts.

After booting with this, capslock led does not seem to work on text console.

Did you check that it was working before? If you are using console-setup, it is a known bug that the capslock LED doesn't reflect the layout capslock state, because console-setup uses another modifier than the capslock modifier, because that one has unwanted legacy hardcoded effects. That's precisely the point of the keyboard part of my two led patches to provide console-setup with an interface to properly route the layout capslock state (expressed as another modifier than capslock) to the capslock LED.

Quoted 1 line

input4::capsl/trigger was none by default, that can't be right, right?

That is still not right, and I still don't see how that can happen: my patch registers the input4::capsl LED with its default trigger name just before the input4-capsl trigger, and doesn't do anything about trigger assignment after that, so I don't see how it can be coming from my patch.

Quoted 2 lines

I tried putting kbd-capslock and input4-capsl there, but that did not seem to help.

Was it at least changing the content of the trigger file? Again, if you are using console-setup, it is normal that the capslock modifier does not change, console-setup uses another modifier, that can be seen in dumpkeys | grep 58, depending on your precise configuration it will use various modifiers. So in that case the kbd-capslock and input*-capsl are not good tests.

Basically you're left with the kbd-scrollock and input*-scrolll triggers and scrollock key for easy testing, if you happen to have that key on your keyboard... (apparently the thinkpad I'm testing doesn't do funky things with it).

Quoted 2 lines

It works with heartbeat trigger, but not with input4-numl trigger. (But numlock led works ok with that trigger, weird).

That is probably due to the weird numlock behavior of the thinkpad.

Quoted 2 lines

vt::capsl/brightness controls capslock led, even when input4-capsl/trigger is set to input4-numl.

That is also not right, I can't reproduce it, and I don't see how it can happen with my patch. Could you copy/paste the commands you are using?

I have also posted reworked patches according to Dmitry's comments, probably better try those now.

I'm sorry I forgot to make the second threaded with the first, but they are independent anyway.

Samuel