Skip to contentSkip to conversation

input: Add LED support to Synaptics device

PATCH In review Takashi Iwai 2 participants 3 messages Apr 22, 2010 – Dec 31, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 input: Add LED support to Synaptics device

The new Synaptics devices have an LED on the top-left corner. This patch adds a new LED class device to control it. It's created dynamically upon synaptics device probing.

The LED is controlled via the command 0x0a with parameters 0x88 or 0x10. This seems only on/off control although other value might be accepted.

The detection of the LED isn't clear yet. It should have been the new capability bits that indicate the presence, but on real machines, it doesn't fit. So, for the time being, the driver checks the product id in the ext capability bits and assumes that LED exists on the known devices.

---

Changes from v3:
- Now it has a new Kconfig and the conditional select for LED class. Can be built without LED support, too.
- The led cdev brightness value is used instead of keeping the value in synaptics privately.
- Add explicit protection of LED ps2 command sequence.

 drivers/input/mouse/Kconfig     |    9 +++
 drivers/input/mouse/synaptics.c |  111 +++++++++++++++++++++++++++++++++++++++
 drivers/input/mouse/synaptics.h |    3 +
 3 files changed, 123 insertions(+), 0 deletions(-)
drivers/input/mouse/Kconfig +9 -0
index c714ca2..91d3517 100644
@@ -19,6 +19,7 @@ config MOUSE_PS2
 	select SERIO_LIBPS2
 	select SERIO_I8042 if X86
 	select SERIO_GSCPS2 if GSC
+	select LEDS_CLASS if MOUSE_PS2_SYNAPICS_LED
 	help
 	  Say Y here if you have a PS/2 mouse connected to your system. This
 	  includes the standard 2 or 3-button PS/2 mouse, as well as PS/2
@@ -67,6 +68,14 @@ config MOUSE_PS2_SYNAPTICS
 
 	  If unsure, say Y.
 
+config MOUSE_PS2_SYNAPTICS_LED
+	bool "Support embedded LED on Synaptics devices"
+	depends on MOUSE_PS2_SYNAPTICS
+	select NEW_LEDS
+	help
+	  Say Y here if you have a Synaptics device with an embedded LED.
+	  This will enable LED class driver to control the LED device.
+
 config MOUSE_PS2_LIFEBOOK
 	bool "Fujitsu Lifebook PS/2 mouse protocol extension" if EMBEDDED
 	default y
drivers/input/mouse/synaptics.c +111 -0

141 lines not on this page · raw message

drivers/input/mouse/synaptics.h +3 -0
index ae37c5d..d5bb8f4 100644
@@ -94,6 +94,8 @@ struct synaptics_hw_state {
 	signed char scroll;
 };
 
+struct synaptics_led;
+
 struct synaptics_data {
 	/* Data read from the touchpad */
 	unsigned long int model_id;		/* Model-ID */
@@ -107,6 +109,7 @@ struct synaptics_data {
 	unsigned char pkt_type;			/* packet type - old, new, etc */
 	unsigned char mode;			/* current mode byte */
 	int scroll;
+	struct synaptics_led *led;
 };
 
 void synaptics_module_init(void);
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 84 lines · On Thursday 22 April 2010 08:16:42 Takashi Iwai wrote:
(quoted diff) +0 -0

b/drivers/input/mouse/Kconfig index c714ca2..91d3517 100644

drivers/input/mouse/Kconfig +1 -0
@@ -19,6 +19,7 @@ config MOUSE_PS2
 	select SERIO_LIBPS2
 	select SERIO_I8042 if X86
 	select SERIO_GSCPS2 if GSC
+	select LEDS_CLASS if MOUSE_PS2_SYNAPICS_LED
 	help
 	  Say Y here if you have a PS/2 mouse connected to your
 system. This includes the standard 2 or 3-button PS/2 mouse,

as well as PS/2 @@ -67,6 +68,14 @@ config MOUSE_PS2_SYNAPTICS

drivers/input/mouse/Kconfig +6 -0
 	  If unsure, say Y.
 
+config MOUSE_PS2_SYNAPTICS_LED
+	bool "Support embedded LED on Synaptics devices"
+	depends on MOUSE_PS2_SYNAPTICS
+	select NEW_LEDS
+	help
+	  Say Y here if you have a Synaptics device with an embedded

LED. + This will enable LED class driver to control the LED
device. +
config MOUSE_PS2_LIFEBOOK
bool "Fujitsu Lifebook PS/2 mouse protocol extension" if
EMBEDDED default y

(quoted diff) +0 -0

b/drivers/input/mouse/synaptics.c index c7b5285..8dc1fb5 100644

drivers/input/mouse/synaptics.c +5 -0
@@ -28,6 +28,7 @@
 #include <linux/input.h>
 #include <linux/serio.h>
 #include <linux/libps2.h>
+#include <linux/leds.h>
 #include <linux/slab.h>
 #include "psmouse.h"
 #include "synaptics.h"
@@ -335,6 +336,110 @@ static void synaptics_pt_create(struct
 psmouse *psmouse) serio_register_port(serio);
 }
 
+#ifdef CONFIG_MOUSE_PS2_SYNAPTICS_LED
+/*
+ * LED handling:
+ * Some Synaptics devices have an embeded LED at the top-left

corner. + */

drivers/input/mouse/synaptics.c +8 -0
+
+struct synaptics_led {
+	struct psmouse *psmouse;
+	struct work_struct work;
+	struct led_classdev cdev;
+};
+
+static void synaptics_set_led(struct psmouse *psmouse, int

on) +{

drivers/input/mouse/synaptics.c +5 -0
+	int i;
+	unsigned char cmd = on ? 0x88 : 0x10;
+
+	ps2_begin_command(&psmouse->ps2dev);
+	if (__ps2_command(&psmouse->ps2dev, NULL,

PSMOUSE_CMD_SETSCALE11)) + goto out;

drivers/input/mouse/synaptics.c +3 -0
+	for (i = 6; i >= 0; i -= 2) {
+		unsigned char d = (cmd >> i) & 3;
+		if (__ps2_command(&psmouse->ps2dev, &d,

PSMOUSE_CMD_SETRES)) + goto out;

drivers/input/mouse/synaptics.c +16 -0
+	}
+	cmd = 0x0a;
+	__ps2_command(&psmouse->ps2dev, &cmd, PSMOUSE_CMD_SETRATE);
+ out:
+	ps2_end_command(&psmouse->ps2dev);
+}
+
+static void synaptics_led_work(struct work_struct *work)
+{
+	struct synaptics_led *led;
+
+	led = container_of(work, struct synaptics_led, work);
+	synaptics_set_led(led->psmouse, led->cdev.brightness);
+}
+
+static void synaptics_led_cdev_brightness_set(struct
Quoted 1 line

led_classdev *cdev, + enum led_brightness

value)

Quoted 114 lines
drivers/input/mouse/synaptics.c +22 -0
+{
+	struct synaptics_led *led;
+
+	led = container_of(cdev, struct synaptics_led, cdev);
+	schedule_work(&led->work);
+}
+
+static void synaptics_sync_led(struct psmouse *psmouse)
+{
+	struct synaptics_data *priv = psmouse->private;
+
+	if (priv->led)
+		synaptics_set_led(psmouse, priv->led->cdev.brightness);
+}
+
+static int synaptics_init_led(struct psmouse *psmouse)
+{
+	struct synaptics_data *priv = psmouse->private;
+	struct synaptics_led *led;
+	int err;
+
+	/* FIXME: LED is supposedly detectable in cap0c[1] 0x20, but

it seems + * not working on real machines.

drivers/input/mouse/synaptics.c +3 -0
+	 * So we check the product id to be sure.
+	 */
+	if (!priv->ext_cap_0c || SYN_CAP_PRODUCT_ID(priv->ext_cap)

!= 0xe4) + return 0;

drivers/input/mouse/synaptics.c +9 -0
+
+	printk(KERN_INFO "synaptics: support LED control\n");
+	led = kzalloc(sizeof(struct synaptics_led), GFP_KERNEL);
+	if (!led)
+		return -ENOMEM;
+	led->psmouse = psmouse;
+	INIT_WORK(&led->work, synaptics_led_work);
+	led->cdev.name = "psmouse::synaptics";
+	led->cdev.brightness_set =

synaptics_led_cdev_brightness_set; + led->cdev.flags =
LED_CORE_SUSPENDRESUME;

drivers/input/mouse/synaptics.c +26 -0
+	err = led_classdev_register(NULL, &led->cdev);
+	if (err < 0) {
+		kfree(led);
+		return err;
+	}
+	priv->led = led;
+	return 0;
+}
+
+static void synaptics_free_led(struct psmouse *psmouse)
+{
+	struct synaptics_data *priv = psmouse->private;
+
+	if (!priv->led)
+		return;
+	cancel_work_sync(&priv->led->work);
+	synaptics_set_led(psmouse, 0);
+	led_classdev_unregister(&priv->led->cdev);
+	kfree(priv->led);
+}
+#else
+#define synaptics_init_led(ps)	0
+#define synaptics_free_led(ps)	do {} while (0)
+#define synaptics_sync_led(ps)	do {} while (0)
+#endif
+
 /************************************************************

***************** * Functions to interpret the absolute mode
packets

*************************************************************
***************/ @@ -622,6 +727,7 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)

static void synaptics_disconnect(struct psmouse *psmouse) {

drivers/input/mouse/synaptics.c +6 -0
+	synaptics_free_led(psmouse);
 	synaptics_reset(psmouse);
 	kfree(psmouse->private);
 	psmouse->private = NULL;
@@ -653,6 +759,8 @@ static int synaptics_reconnect(struct
 psmouse *psmouse) return -1;
 	}
 
+	synaptics_sync_led(psmouse);
+
 	return 0;
 }
 
@@ -727,6 +835,9 @@ int synaptics_init(struct psmouse
 *psmouse) SYN_ID_MAJOR(priv->identity),
 SYN_ID_MINOR(priv->identity), priv->model_id,
 priv->capabilities, priv->ext_cap, priv->ext_cap_0c);
 
+	if (synaptics_init_led(psmouse) < 0)
+		goto init_fail;
+
 	set_input_params(psmouse->dev, priv);
 
drivers/input/mouse/synaptics.c +0 -0
 	/*
(quoted diff) +0 -0

b/drivers/input/mouse/synaptics.h index ae37c5d..d5bb8f4 100644

drivers/input/mouse/synaptics.h +2 -0
@@ -94,6 +94,8 @@ struct synaptics_hw_state {
 	signed char scroll;
 };
 
+struct synaptics_led;
+
 struct synaptics_data {
 	/* Data read from the touchpad */
 	unsigned long int model_id;		/* Model-ID */

drivers/input/mouse/synaptics.h struct synaptics_data { · line 109

Quoted 1 line
drivers/input/mouse/synaptics.h +0 -0
@@ -107,6 +109,7 @@ struct synaptics_data {
 	unsigned char pkt_type;			/* packet type - old, new, etc 

*/

drivers/input/mouse/synaptics.h struct synaptics_data { · line 115

Quoted 6 lines
drivers/input/mouse/synaptics.h +1 -0
 	unsigned char mode;			/* current mode byte */
 	int scroll;
+	struct synaptics_led *led;
 };
 
 void synaptics_module_init(void);

Hello,

what happened with this patch? There is no discussion about v4:
https://patchwork.kernel.org/patch/94026/
https://lkml.org/lkml/2010/4/22/35

Are there any problems with this patch?

Signature · 2 lines
Pali Rohár
[email protected]
#2 lore raw
Quoted 251 lines · On Saturday 20 April 2013 20:51:13 Pali Rohár wrote:
Quoted 98 lines · On Thursday 22 April 2010 08:16:42 Takashi Iwai wrote:
(quoted diff) +0 -0

b/drivers/input/mouse/Kconfig index c714ca2..91d3517 100644

drivers/input/mouse/Kconfig +1 -0
@@ -19,6 +19,7 @@ config MOUSE_PS2
 
 	select SERIO_LIBPS2
 	select SERIO_I8042 if X86
 	select SERIO_GSCPS2 if GSC
 
+	select LEDS_CLASS if MOUSE_PS2_SYNAPICS_LED
 
drivers/input/mouse/Kconfig +0 -0
 	help
 
 	  Say Y here if you have a PS/2 mouse connected to your

system. This includes the standard 2 or 3-button PS/2 mouse, as well as PS/2 @@ -67,6 +68,14 @@ config MOUSE_PS2_SYNAPTICS

drivers/input/mouse/Kconfig +6 -0
 	  If unsure, say Y.
 
+config MOUSE_PS2_SYNAPTICS_LED
+	bool "Support embedded LED on Synaptics devices"
+	depends on MOUSE_PS2_SYNAPTICS
+	select NEW_LEDS
+	help
+	  Say Y here if you have a Synaptics device with an

embedded LED. + This will enable LED class driver to
control the LED device. +

config MOUSE_PS2_LIFEBOOK

bool "Fujitsu Lifebook PS/2 mouse protocol extension" if

EMBEDDED default y

(quoted diff) +0 -0

b/drivers/input/mouse/synaptics.c index c7b5285..8dc1fb5 100644

drivers/input/mouse/synaptics.c +1 -0
@@ -28,6 +28,7 @@
 
 #include <linux/input.h>
 #include <linux/serio.h>
 #include <linux/libps2.h>
 
+#include <linux/leds.h>
 

#include <linux/slab.h>
#include "psmouse.h"
#include "synaptics.h"

drivers/input/mouse/synaptics.c +4 -0
@@ -335,6 +336,110 @@ static void synaptics_pt_create(struct
 psmouse *psmouse) serio_register_port(serio);
 
 }
 
+#ifdef CONFIG_MOUSE_PS2_SYNAPTICS_LED
+/*
+ * LED handling:
+ * Some Synaptics devices have an embeded LED at the

top-left corner. + */

drivers/input/mouse/synaptics.c +8 -0
+
+struct synaptics_led {
+	struct psmouse *psmouse;
+	struct work_struct work;
+	struct led_classdev cdev;
+};
+
+static void synaptics_set_led(struct psmouse *psmouse, int

on) +{

drivers/input/mouse/synaptics.c +5 -0
+	int i;
+	unsigned char cmd = on ? 0x88 : 0x10;
+
+	ps2_begin_command(&psmouse->ps2dev);
+	if (__ps2_command(&psmouse->ps2dev, NULL,

PSMOUSE_CMD_SETSCALE11)) + goto out;

drivers/input/mouse/synaptics.c +3 -0
+	for (i = 6; i >= 0; i -= 2) {
+		unsigned char d = (cmd >> i) & 3;
+		if (__ps2_command(&psmouse->ps2dev, &d,

PSMOUSE_CMD_SETRES)) + goto out;

drivers/input/mouse/synaptics.c +3 -0
+	}
+	cmd = 0x0a;
+	__ps2_command(&psmouse->ps2dev, &cmd,

PSMOUSE_CMD_SETRATE); + out:

drivers/input/mouse/synaptics.c +12 -0
+	ps2_end_command(&psmouse->ps2dev);
+}
+
+static void synaptics_led_work(struct work_struct *work)
+{
+	struct synaptics_led *led;
+
+	led = container_of(work, struct synaptics_led, work);
+	synaptics_set_led(led->psmouse, led->cdev.brightness);
+}
+
+static void synaptics_led_cdev_brightness_set(struct
Quoted 1 line

led_classdev *cdev, + enum led_brightness

value)

drivers/input/mouse/synaptics.c static void synaptics_pt_create(struct psmouse *psmouse)

Quoted 13 lines
drivers/input/mouse/synaptics.c +13 -0
+{
+	struct synaptics_led *led;
+
+	led = container_of(cdev, struct synaptics_led, cdev);
+	schedule_work(&led->work);
+}
+
+static void synaptics_sync_led(struct psmouse *psmouse)
+{
+	struct synaptics_data *priv = psmouse->private;
+
+	if (priv->led)
+		synaptics_set_led(psmouse, priv->led-

cdev.brightness);

drivers/input/mouse/synaptics.c static void synaptics_pt_create(struct psmouse *psmouse)

Quoted 13 lines
drivers/input/mouse/synaptics.c +9 -0
+}
+
+static int synaptics_init_led(struct psmouse *psmouse)
+{
+	struct synaptics_data *priv = psmouse->private;
+	struct synaptics_led *led;
+	int err;
+
+	/* FIXME: LED is supposedly detectable in cap0c[1] 0x20,

but it seems + * not working on real machines.

drivers/input/mouse/synaptics.c +3 -0
+	 * So we check the product id to be sure.
+	 */
+	if (!priv->ext_cap_0c || SYN_CAP_PRODUCT_ID(priv-

ext_cap)

Quoted 104 lines

!= 0xe4) + return 0;

drivers/input/mouse/synaptics.c +9 -0
+
+	printk(KERN_INFO "synaptics: support LED control\n");
+	led = kzalloc(sizeof(struct synaptics_led), GFP_KERNEL);
+	if (!led)
+		return -ENOMEM;
+	led->psmouse = psmouse;
+	INIT_WORK(&led->work, synaptics_led_work);
+	led->cdev.name = "psmouse::synaptics";
+	led->cdev.brightness_set =

synaptics_led_cdev_brightness_set; + led->cdev.flags =
LED_CORE_SUSPENDRESUME;

drivers/input/mouse/synaptics.c +26 -0
+	err = led_classdev_register(NULL, &led->cdev);
+	if (err < 0) {
+		kfree(led);
+		return err;
+	}
+	priv->led = led;
+	return 0;
+}
+
+static void synaptics_free_led(struct psmouse *psmouse)
+{
+	struct synaptics_data *priv = psmouse->private;
+
+	if (!priv->led)
+		return;
+	cancel_work_sync(&priv->led->work);
+	synaptics_set_led(psmouse, 0);
+	led_classdev_unregister(&priv->led->cdev);
+	kfree(priv->led);
+}
+#else
+#define synaptics_init_led(ps)	0
+#define synaptics_free_led(ps)	do {} while (0)
+#define synaptics_sync_led(ps)	do {} while (0)
+#endif
+
 
 /**********************************************************
 **

***************** * Functions to interpret the absolute mode
packets

************************************************************
* ***************/ @@ -622,6 +727,7 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)

static void synaptics_disconnect(struct psmouse *psmouse) {

drivers/input/mouse/synaptics.c +3 -0
+	synaptics_free_led(psmouse);
 
 	synaptics_reset(psmouse);
 	kfree(psmouse->private);
 	psmouse->private = NULL;
@@ -653,6 +759,8 @@ static int synaptics_reconnect(struct
 psmouse *psmouse) return -1;
 
 	}
 
+	synaptics_sync_led(psmouse);
+
 
 	return 0;

}

drivers/input/mouse/synaptics.c +3 -0
@@ -727,6 +835,9 @@ int synaptics_init(struct psmouse
 *psmouse) SYN_ID_MAJOR(priv->identity),
 SYN_ID_MINOR(priv->identity), priv->model_id,
 priv->capabilities, priv->ext_cap, priv->ext_cap_0c);
 
+	if (synaptics_init_led(psmouse) < 0)
+		goto init_fail;
+
 
 	set_input_params(psmouse->dev, priv);
drivers/input/mouse/synaptics.c +0 -0
 	/*
(quoted diff) +0 -0

b/drivers/input/mouse/synaptics.h index ae37c5d..d5bb8f4 100644

drivers/input/mouse/synaptics.h +2 -0
@@ -94,6 +94,8 @@ struct synaptics_hw_state {
 
 	signed char scroll;
 
 };
 
+struct synaptics_led;
+
 

struct synaptics_data {

drivers/input/mouse/synaptics.h +0 -0
 	/* Data read from the touchpad */
 	unsigned long int model_id;		/* Model-ID */

drivers/input/mouse/synaptics.h struct synaptics_data { · line 110

Quoted 2 lines
drivers/input/mouse/synaptics.h +0 -0
@@ -107,6 +109,7 @@ struct synaptics_data {
 
 	unsigned char pkt_type;			/* packet type - old, new, etc

*/

Quoted 8 lines
drivers/input/mouse/synaptics.h +1 -0
 	unsigned char mode;			/* current mode byte */
 	int scroll;
 
+	struct synaptics_led *led;
 

};

void synaptics_module_init(void);

Hello,

Quoted 5 lines

what happened with this patch? There is no discussion about
v4: https://patchwork.kernel.org/patch/94026/
https://lkml.org/lkml/2010/4/22/35

Are there any problems with this patch?

BUMP!

Signature · 2 lines
Pali Rohár
[email protected]