From patchwork Mon Apr 19 10:44:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 93468 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o3JAijsd032364 for ; Mon, 19 Apr 2010 10:44:45 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753929Ab0DSKoK (ORCPT ); Mon, 19 Apr 2010 06:44:10 -0400 Received: from cantor2.suse.de ([195.135.220.15]:44238 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753846Ab0DSKoJ (ORCPT ); Mon, 19 Apr 2010 06:44:09 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) by mx2.suse.de (Postfix) with ESMTP id 31B0486A2E; Mon, 19 Apr 2010 12:44:08 +0200 (CEST) Date: Mon, 19 Apr 2010 12:44:08 +0200 Message-ID: From: Takashi Iwai To: Dmitry Torokhov Cc: Pavel Machek , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] input: Add LED support to Synaptics device In-Reply-To: References: <1271257823-23566-1-git-send-email-tiwai@suse.de> <1271257823-23566-3-git-send-email-tiwai@suse.de> <20100415191217.GA1495@ucw.cz> User-Agent: Wanderlust/2.15.6 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.7 Emacs/23.1 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 19 Apr 2010 10:44:45 +0000 (UTC) === From: Takashi Iwai Subject: [PATCH] input: Add LED support to Synaptics device The new Synaptics devices have an LED on the top-left corner. This is controlled via the command 0x0a with parameters 0x88 or 0x10. 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. The support of LED is controlled via a normal input event with EV_LED bit mask. A new LED bitmask, LED_TOUCHPAD, is added. X driver can detect the LED support by checking these bits. Signed-off-by: Takashi Iwai --- drivers/input/mouse/synaptics.c | 64 +++++++++++++++++++++++++++++++++++++++ drivers/input/mouse/synaptics.h | 5 +++ include/linux/input.h | 1 + 3 files changed, 70 insertions(+), 0 deletions(-) diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c index c7b5285..bffa474 100644 --- a/drivers/input/mouse/synaptics.c +++ b/drivers/input/mouse/synaptics.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "psmouse.h" #include "synaptics.h" @@ -339,6 +340,52 @@ static void synaptics_pt_create(struct psmouse *psmouse) * Functions to interpret the absolute mode packets ****************************************************************************/ +static void synaptics_set_led(struct psmouse *psmouse, int on) +{ + unsigned char param[1]; + + if (psmouse_sliced_command(psmouse, on ? 0x88 : 0x10)) + return; + param[0] = 0x0a; + ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE); +} + +static void synaptics_led_work(struct work_struct *work) +{ + struct synaptics_data *priv = container_of(work, struct synaptics_data, led_work); + synaptics_set_led(priv->psmouse, priv->led_status); +} + +/* input event handler: changed by x11 synaptics driver */ +static int synaptics_led_event(struct input_dev *dev, unsigned int type, + unsigned int code, int value) +{ + struct synaptics_data *priv = dev->dev.platform_data; + + if (!priv) + return 0; + if (type == EV_LED && code == LED_TOUCHPAD) { + priv->led_status = !!value; + schedule_work(&priv->led_work); + } + return 0; +} + +static void synaptics_query_led(struct psmouse *psmouse) +{ + struct synaptics_data *priv = psmouse->private; + + /* FIXME: LED is supposedly detectable in cap0c[1] 0x20, but it seems + * not working on real machines. So we check the product id to be sure + */ + if (priv->ext_cap_0c && SYN_CAP_PRODUCT_ID(priv->ext_cap) == 0xe4) + printk(KERN_INFO "synaptics: support LED control\n"); + priv->has_led = 1; + priv->psmouse = psmouse; + INIT_WORK(&priv->led_work, synaptics_led_work); + } +} + static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data *priv, struct synaptics_hw_state *hw) { memset(hw, 0, sizeof(struct synaptics_hw_state)); @@ -618,10 +665,22 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv) __clear_bit(BTN_RIGHT, dev->keybit); __clear_bit(BTN_MIDDLE, dev->keybit); } + if (priv->has_led) { + __set_bit(EV_LED, dev->evbit); + __set_bit(LED_TOUCHPAD, dev->ledbit); + dev->event = synaptics_led_event; + dev->dev.platform_data = priv; + } } static void synaptics_disconnect(struct psmouse *psmouse) { + struct synaptics_data *priv = psmouse->private; + + if (priv->has_led) { + cancel_work_sync(&priv->led_work); + synaptics_set_led(psmouse, 0); + } synaptics_reset(psmouse); kfree(psmouse->private); psmouse->private = NULL; @@ -653,6 +712,9 @@ static int synaptics_reconnect(struct psmouse *psmouse) return -1; } + if (priv->has_led) + synaptics_set_led(psmouse, priv->led_status); + return 0; } @@ -727,6 +789,8 @@ 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); + synaptics_query_led(psmouse); + set_input_params(psmouse->dev, priv); /* diff --git a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h index ae37c5d..0b989f4 100644 --- a/drivers/input/mouse/synaptics.h +++ b/drivers/input/mouse/synaptics.h @@ -107,6 +107,11 @@ struct synaptics_data { unsigned char pkt_type; /* packet type - old, new, etc */ unsigned char mode; /* current mode byte */ int scroll; + + unsigned char has_led; + unsigned char led_status; + struct psmouse *psmouse; + struct work_struct led_work; }; void synaptics_module_init(void); diff --git a/include/linux/input.h b/include/linux/input.h index 7ed2251..0aea50d 100644 --- a/include/linux/input.h +++ b/include/linux/input.h @@ -757,6 +757,7 @@ struct input_absinfo { #define LED_MISC 0x08 #define LED_MAIL 0x09 #define LED_CHARGING 0x0a +#define LED_TOUCHPAD 0x0b #define LED_MAX 0x0f #define LED_CNT (LED_MAX+1)