From patchwork Wed Jun 10 07:08:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Ranostay X-Patchwork-Id: 6576901 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3E4319F399 for ; Wed, 10 Jun 2015 07:07:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3906B20582 for ; Wed, 10 Jun 2015 07:07:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 32E4E2057E for ; Wed, 10 Jun 2015 07:07:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753997AbbFJHHK (ORCPT ); Wed, 10 Jun 2015 03:07:10 -0400 Received: from mail-pd0-f182.google.com ([209.85.192.182]:34071 "EHLO mail-pd0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751431AbbFJHHI (ORCPT ); Wed, 10 Jun 2015 03:07:08 -0400 Received: by pdbki1 with SMTP id ki1so31491465pdb.1; Wed, 10 Jun 2015 00:07:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=SBZwR1nFdsxdUdaPkbc/pGfXVg+PVhgVdUDHnBDlobU=; b=nqOy7JeBFynOPH5noiguFMUJN5QUJHedOj7i9gCoXzJD48JSTD+qOmwGdFEfuklskv 6vkUcHLr17SJdVNjVWEKRY6gphjmB/JruFC1aG39lQsIj0jqi4hli/aNFW8NichG/w89 6wKwvcwrjOX5Tt06dl2SIrm3GcDIWiLhbJ1HmWZgSQcbiLVfHjZPh+dpLBbVLVr/hDcj 7XM21hd1ils3ZUxsWSEH0L74Wgt+u3cN9eo7Yv/LW42Ip7OXoY4IgaRZc9MJvHHjSJDI 8CRQd5AgHzUn6Daani3EwtQ3bwCpNJyunpa4JTfuuhNogHPl8S9w4rXAgBIRbUbIJfgH xTqg== X-Received: by 10.68.252.106 with SMTP id zr10mr3151762pbc.79.1433920028302; Wed, 10 Jun 2015 00:07:08 -0700 (PDT) Received: from localhost.localdomain (c-76-105-208-73.hsd1.or.comcast.net. [76.105.208.73]) by mx.google.com with ESMTPSA id q3sm7563714pdr.10.2015.06.10.00.07.07 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Jun 2015 00:07:07 -0700 (PDT) From: Matt Ranostay To: dmitry.torokhov@gmail.com, zonque@gmail.com Cc: linux-input@vger.kernel.org, linux-leds@vger.kernel.org, Matt Ranostay Subject: [PATCH v2] cap11xx: add LED support Date: Wed, 10 Jun 2015 00:08:03 -0700 Message-Id: <1433920083-31869-1-git-send-email-mranostay@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Several cap11xx variants have LEDs that be can be controlled, this patchset implements this functionality. Signed-off-by: Matt Ranostay --- drivers/input/keyboard/cap11xx.c | 90 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 3 deletions(-) diff --git a/drivers/input/keyboard/cap11xx.c b/drivers/input/keyboard/cap11xx.c index f07461a..af1daa0 100644 --- a/drivers/input/keyboard/cap11xx.c +++ b/drivers/input/keyboard/cap11xx.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,8 @@ #define CAP11XX_REG_CONFIG2 0x44 #define CAP11XX_REG_CONFIG2_ALT_POL BIT(6) #define CAP11XX_REG_SENSOR_BASE_CNT(X) (0x50 + (X)) +#define CAP11XX_REG_LED_POLARITY 0x73 +#define CAP11XX_REG_LED_OUTPUT_CONTROL 0x74 #define CAP11XX_REG_SENSOR_CALIB (0xb1 + (X)) #define CAP11XX_REG_SENSOR_CALIB_LSB1 0xb9 #define CAP11XX_REG_SENSOR_CALIB_LSB2 0xba @@ -56,10 +59,25 @@ #define CAP11XX_MANUFACTURER_ID 0x5d +#ifdef CONFIG_LEDS_CLASS +struct cap11xx_led { + struct cap11xx_priv *priv; + struct led_classdev cdev; + struct work_struct work; + char name[32]; + int id; + enum led_brightness new_brightness; +}; +#endif + struct cap11xx_priv { struct regmap *regmap; struct input_dev *idev; +#ifdef CONFIG_LEDS_CLASS + struct cap11xx_led *leds; + int num_leds; +#endif /* config */ u32 keycodes[]; }; @@ -67,6 +85,7 @@ struct cap11xx_priv { struct cap11xx_hw_model { u8 product_id; unsigned int num_channels; + unsigned int num_leds; }; enum { @@ -76,9 +95,9 @@ enum { }; static const struct cap11xx_hw_model cap11xx_devices[] = { - [CAP1106] = { .product_id = 0x55, .num_channels = 6 }, - [CAP1126] = { .product_id = 0x53, .num_channels = 6 }, - [CAP1188] = { .product_id = 0x50, .num_channels = 8 }, + [CAP1106] = { .product_id = 0x55, .num_channels = 6, .num_leds = 0 }, + [CAP1126] = { .product_id = 0x53, .num_channels = 6, .num_leds = 2 }, + [CAP1188] = { .product_id = 0x50, .num_channels = 8, .num_leds = 8 }, }; static const struct reg_default cap11xx_reg_defaults[] = { @@ -111,6 +130,7 @@ static const struct reg_default cap11xx_reg_defaults[] = { { CAP11XX_REG_STANDBY_SENSITIVITY, 0x02 }, { CAP11XX_REG_STANDBY_THRESH, 0x40 }, { CAP11XX_REG_CONFIG2, 0x40 }, + { CAP11XX_REG_LED_POLARITY, 0x00 }, { CAP11XX_REG_SENSOR_CALIB_LSB1, 0x00 }, { CAP11XX_REG_SENSOR_CALIB_LSB2, 0x00 }, }; @@ -196,6 +216,58 @@ static void cap11xx_input_close(struct input_dev *idev) cap11xx_set_sleep(priv, true); } +#ifdef CONFIG_LEDS_CLASS +static void cap11xx_led_work(struct work_struct *work) +{ + struct cap11xx_led *led = container_of(work, struct cap11xx_led, work); + struct cap11xx_priv *priv = led->priv; + int value = led->new_brightness; + + regmap_update_bits(priv->regmap, CAP11XX_REG_LED_OUTPUT_CONTROL, + BIT(led->id), !!value ? BIT(led->id) : 0); +} + +static void cap11xx_led_set(struct led_classdev *cdev, + enum led_brightness value) +{ + struct cap11xx_led *led = container_of(cdev, struct cap11xx_led, cdev); + + led->new_brightness = value; + schedule_work(&led->work); +} + +static int cap11xx_register_leds(struct device *dev, struct cap11xx_priv *priv) +{ + int ret; + int i; + + /* + * Be sure all LEDS are in off-state + */ + regmap_update_bits(priv->regmap, + CAP11XX_REG_LED_OUTPUT_CONTROL, 0xff, 0); + + for (i = 0; i < priv->num_leds; i++) { + struct cap11xx_led *led = &priv->leds[i]; + + snprintf(led->name, sizeof(led->name), "cap11xx:led%d", i + 1); + led->cdev.name = led->name; + led->cdev.brightness_set = cap11xx_led_set; + led->cdev.brightness = LED_OFF; + led->cdev.max_brightness = 1; + led->id = i; + led->priv = priv; + + ret = devm_led_classdev_register(dev, &led->cdev); + if (ret < 0) + return ret; + + INIT_WORK(&led->work, cap11xx_led_work); + }; + return 0; +} +#endif + static int cap11xx_i2c_probe(struct i2c_client *i2c_client, const struct i2c_device_id *id) { @@ -316,6 +388,18 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client, priv->idev->open = cap11xx_input_open; priv->idev->close = cap11xx_input_close; +#ifdef CONFIG_LEDS_CLASS + if (cap->num_leds > 0) { + priv->leds = devm_kcalloc(dev, cap->num_leds, + sizeof(struct cap11xx_led), GFP_KERNEL); + if (!priv->leds) + return -ENOMEM; + priv->num_leds = cap->num_leds; + error = cap11xx_register_leds(dev, priv); + if (error) + return error; + } +#endif input_set_drvdata(priv->idev, priv); /*