1 From: Takashi Iwai <tiwai@suse.de>
2 Subject: [PATCH 2/2] input: Add LED support to Synaptics device
3 Patch-mainline: Submitted
4 References: bnc#547370,bnc#582529,bnc#589014
6 The new Synaptics devices have an LED on the top-left corner.
7 This patch adds a new LED class device to control it. It's created
8 dynamically upon synaptics device probing.
10 The LED is controlled via the command 0x0a with parameters 0x88 or 0x10.
11 This seems only on/off control although other value might be accepted.
13 The detection of the LED isn't clear yet. It should have been the new
14 capability bits that indicate the presence, but on real machines, it
15 doesn't fit. So, for the time being, the driver checks the product id
16 in the ext capability bits and assumes that LED exists on the known
19 Signed-off-by: Takashi Iwai <tiwai@suse.de>
22 drivers/input/mouse/Kconfig | 9 +++
23 drivers/input/mouse/synaptics.c | 111 ++++++++++++++++++++++++++++++++++++++++
24 drivers/input/mouse/synaptics.h | 3 +
25 3 files changed, 123 insertions(+)
27 --- a/drivers/input/mouse/Kconfig
28 +++ b/drivers/input/mouse/Kconfig
29 @@ -19,6 +19,7 @@ config MOUSE_PS2
31 select SERIO_I8042 if X86
32 select SERIO_GSCPS2 if GSC
33 + select LEDS_CLASS # if MOUSE_PS2_SYNAPTICS_LED
35 Say Y here if you have a PS/2 mouse connected to your system. This
36 includes the standard 2 or 3-button PS/2 mouse, as well as PS/2
37 @@ -68,6 +69,14 @@ config MOUSE_PS2_SYNAPTICS
41 +#config MOUSE_PS2_SYNAPTICS_LED
42 +# bool "Support embedded LED on Synaptics devices"
43 +# depends on MOUSE_PS2_SYNAPTICS
46 +# Say Y here if you have a Synaptics device with an embedded LED.
47 +# This will enable LED class driver to control the LED device.
49 config MOUSE_PS2_LIFEBOOK
50 bool "Fujitsu Lifebook PS/2 mouse protocol extension" if EXPERT
52 --- a/drivers/input/mouse/synaptics.c
53 +++ b/drivers/input/mouse/synaptics.c
55 #include <linux/input/mt.h>
56 #include <linux/serio.h>
57 #include <linux/libps2.h>
58 +#include <linux/leds.h>
59 #include <linux/slab.h>
61 #include "synaptics.h"
62 @@ -419,6 +420,110 @@ static void synaptics_pt_create(struct p
63 serio_register_port(serio);
66 +/*#ifdef CONFIG_MOUSE_PS2_SYNAPTICS_LED*/
69 + * Some Synaptics devices have an embeded LED at the top-left corner.
72 +struct synaptics_led {
73 + struct psmouse *psmouse;
74 + struct work_struct work;
75 + struct led_classdev cdev;
78 +static void synaptics_set_led(struct psmouse *psmouse, int on)
81 + unsigned char cmd = on ? 0x88 : 0x10;
83 + ps2_begin_command(&psmouse->ps2dev);
84 + if (__ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
86 + for (i = 6; i >= 0; i -= 2) {
87 + unsigned char d = (cmd >> i) & 3;
88 + if (__ps2_command(&psmouse->ps2dev, &d, PSMOUSE_CMD_SETRES))
92 + __ps2_command(&psmouse->ps2dev, &cmd, PSMOUSE_CMD_SETRATE);
94 + ps2_end_command(&psmouse->ps2dev);
97 +static void synaptics_led_work(struct work_struct *work)
99 + struct synaptics_led *led;
101 + led = container_of(work, struct synaptics_led, work);
102 + synaptics_set_led(led->psmouse, led->cdev.brightness);
105 +static void synaptics_led_cdev_brightness_set(struct led_classdev *cdev,
106 + enum led_brightness value)
108 + struct synaptics_led *led;
110 + led = container_of(cdev, struct synaptics_led, cdev);
111 + schedule_work(&led->work);
114 +static void synaptics_sync_led(struct psmouse *psmouse)
116 + struct synaptics_data *priv = psmouse->private;
119 + synaptics_set_led(psmouse, priv->led->cdev.brightness);
122 +static int synaptics_init_led(struct psmouse *psmouse)
124 + struct synaptics_data *priv = psmouse->private;
125 + struct synaptics_led *led;
128 + /* FIXME: LED is supposedly detectable in cap0c[1] 0x20, but it seems
129 + * not working on real machines.
130 + * So we check the product id to be sure.
132 + if (!priv->ext_cap_0c || SYN_CAP_PRODUCT_ID(priv->ext_cap) != 0xe4)
135 + printk(KERN_INFO "synaptics: support LED control\n");
136 + led = kzalloc(sizeof(struct synaptics_led), GFP_KERNEL);
139 + led->psmouse = psmouse;
140 + INIT_WORK(&led->work, synaptics_led_work);
141 + led->cdev.name = "psmouse::synaptics";
142 + led->cdev.brightness_set = synaptics_led_cdev_brightness_set;
143 + led->cdev.flags = LED_CORE_SUSPENDRESUME;
144 + err = led_classdev_register(NULL, &led->cdev);
153 +static void synaptics_free_led(struct psmouse *psmouse)
155 + struct synaptics_data *priv = psmouse->private;
159 + cancel_work_sync(&priv->led->work);
160 + synaptics_set_led(psmouse, 0);
161 + led_classdev_unregister(&priv->led->cdev);
165 +#define synaptics_init_led(ps) 0
166 +#define synaptics_free_led(ps) do {} while (0)
167 +#define synaptics_sync_led(ps) do {} while (0)
170 /*****************************************************************************
171 * Functions to interpret the absolute mode packets
172 ****************************************************************************/
173 @@ -1206,6 +1311,7 @@ static void set_input_params(struct inpu
175 static void synaptics_disconnect(struct psmouse *psmouse)
177 + synaptics_free_led(psmouse);
178 synaptics_reset(psmouse);
179 kfree(psmouse->private);
180 psmouse->private = NULL;
181 @@ -1258,6 +1364,8 @@ static int synaptics_reconnect(struct ps
185 + synaptics_sync_led(psmouse);
190 @@ -1370,6 +1478,9 @@ int synaptics_init(struct psmouse *psmou
192 priv->capabilities, priv->ext_cap, priv->ext_cap_0c);
194 + if (synaptics_init_led(psmouse) < 0)
197 set_input_params(psmouse->dev, priv);
200 --- a/drivers/input/mouse/synaptics.h
201 +++ b/drivers/input/mouse/synaptics.h
202 @@ -144,6 +144,8 @@ struct synaptics_hw_state {
203 struct synaptics_mt_state mt_state;
206 +struct synaptics_led;
208 struct synaptics_data {
209 /* Data read from the touchpad */
210 unsigned long int model_id; /* Model-ID */
211 @@ -170,6 +172,7 @@ struct synaptics_data {
213 struct synaptics_hw_state agm;
214 bool agm_pending; /* new AGM packet received */
215 + struct synaptics_led *led;
218 void synaptics_module_init(void);