From patchwork Wed Apr 21 14:46:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 93872 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 o3LEkffq026643 for ; Wed, 21 Apr 2010 14:46:41 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753232Ab0DUOqk (ORCPT ); Wed, 21 Apr 2010 10:46:40 -0400 Received: from cantor.suse.de ([195.135.220.2]:36197 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753621Ab0DUOqk (ORCPT ); Wed, 21 Apr 2010 10:46:40 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id 2A02094A12; Wed, 21 Apr 2010 16:46:39 +0200 (CEST) Date: Wed, 21 Apr 2010 16:46:39 +0200 Message-ID: From: Takashi Iwai To: Dmitry Torokhov Cc: Pavel Machek , Richard Purdie , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] input: Add LED support to Synaptics device In-Reply-To: References: 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]); Wed, 21 Apr 2010 14:46:42 +0000 (UTC) diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c index c7b5285..fcc007c 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" @@ -335,6 +336,79 @@ static void synaptics_pt_create(struct psmouse *psmouse) serio_register_port(serio); } +/* + * LED handling: + * Some Synaptics devices have an embeded LED at the top-left corner. + */ + +struct synaptics_led { + enum led_brightness status; + struct psmouse *psmouse; + struct work_struct work; + struct led_classdev cdev; +}; + +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_led *led; + + led = container_of(work, struct synaptics_led, work); + synaptics_set_led(led->psmouse, led->status); +} + +static void synaptics_led_cdev_brightness_set(struct led_classdev *cdev, + enum led_brightness value) +{ + struct synaptics_led *led; + + led = container_of(cdev, struct synaptics_led, cdev); + if (value != led->status) { + led->status = value; + schedule_work(&led->work); + } +} + +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. + * So we check the product id to be sure. + */ + if (!priv->ext_cap_0c || SYN_CAP_PRODUCT_ID(priv->ext_cap) != 0xe4) + return 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; + err = led_classdev_register(NULL, &led->cdev); + if (err < 0) { + kfree(led); + return err; + } + priv->led = led; + return 0; +} + /***************************************************************************** * Functions to interpret the absolute mode packets ****************************************************************************/ @@ -622,6 +696,14 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv) static void synaptics_disconnect(struct psmouse *psmouse) { + struct synaptics_data *priv = psmouse->private; + + if (priv->led) { + cancel_work_sync(&priv->led->work); + synaptics_set_led(psmouse, 0); + led_classdev_unregister(&priv->led->cdev); + kfree(priv->led); + } synaptics_reset(psmouse); kfree(psmouse->private); psmouse->private = NULL; @@ -653,6 +735,9 @@ static int synaptics_reconnect(struct psmouse *psmouse) return -1; } + if (priv->led) + synaptics_set_led(psmouse, priv->led->status); + return 0; } @@ -727,6 +812,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); /* diff --git a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h index ae37c5d..d5bb8f4 100644 --- a/drivers/input/mouse/synaptics.h +++ b/drivers/input/mouse/synaptics.h @@ -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);