From patchwork Thu Dec 1 01:21:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 9455251 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1056C60756 for ; Thu, 1 Dec 2016 01:22:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03776283E4 for ; Thu, 1 Dec 2016 01:22:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC7DF284AE; Thu, 1 Dec 2016 01:22:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47C31283E4 for ; Thu, 1 Dec 2016 01:22:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932662AbcLABWi (ORCPT ); Wed, 30 Nov 2016 20:22:38 -0500 Received: from mail-pg0-f41.google.com ([74.125.83.41]:35580 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755302AbcLABWZ (ORCPT ); Wed, 30 Nov 2016 20:22:25 -0500 Received: by mail-pg0-f41.google.com with SMTP id p66so88234257pga.2 for ; Wed, 30 Nov 2016 17:22:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dOT1vAQDy1FsLB/GU90z44VKcvqpVYVp35RG/bw8kIQ=; b=hXXJpGVETf/cM1ylf5HwG8idL6IWigFCSeFj/Y+xtH2X0MqUVETwXeMagP4689yq9i JmEWXpdm1eDEX7jq1q1b8VCblxP9h5GEJVvdfX9uptNJAPEgWzQ2U7oL4TirLjvnEtFa q/16ksAyi77h3b/PW9jzOaLFi9CI17PK5h+iY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dOT1vAQDy1FsLB/GU90z44VKcvqpVYVp35RG/bw8kIQ=; b=iumNq5o/bcEjhxP8st12pLJH0oPdKohUj3wqUmd4Bz1eCI1cAQHzxQoTkTe7cx2+6j Tbk78DQ93BF3K8Yvt3X+koHzzgY9Zwyty2fAC2eVLaYtpFCXHIZHKSVc3os529yrhX9n E8pSZ7frjYXToeksR8s5IyT79CRFkwme0tATLID1i62CRmfcZKjZtrH+07EkvxtgFPoG hKBnJx4i2kmm2asT9aSPbS1uhMKXJG/D3mSw3R6+8d8qoU8cZxMuCtuefa071shNF945 ggQQkI6n8t0F+al+aCnpaLNhPyQmcRO9oJjPfbgM/WoVvn+ICCQvunPB8/yaRcpXgqwO /iYw== X-Gm-Message-State: AKaTC00sRMF1AmhTrrKnfrjm8d0nlWxD88+hV98LUkBYIaqN6Yf1lfs6TOitZ3ujB2Iax+l4 X-Received: by 10.99.161.2 with SMTP id b2mr65821366pgf.2.1480555344879; Wed, 30 Nov 2016 17:22:24 -0800 (PST) Received: from ban.mtv.corp.google.com ([172.22.64.120]) by smtp.gmail.com with ESMTPSA id n24sm105549205pfb.0.2016.11.30.17.22.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Nov 2016 17:22:24 -0800 (PST) From: Brian Norris To: Jiri Kosina , Benjamin Tissoires Cc: Caesar Wang , linux-rockchip@lists.infradead.org, Rob Herring , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Torokhov , Mark Rutland , Doug Anderson , Brian Norris Subject: [PATCH v2 2/2] HID: i2c-hid: support Wacom digitizer + regulator Date: Wed, 30 Nov 2016 17:21:28 -0800 Message-Id: <1480555288-142791-2-git-send-email-briannorris@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1480555288-142791-1-git-send-email-briannorris@chromium.org> References: <1480555288-142791-1-git-send-email-briannorris@chromium.org> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We need to power on the digitizer before using it, and it's also nice to save power in suspend by disabling it. Support an optional "vdd-supply" and wire it up for the new Wacom device. Wacom recommended waiting up to 100ms after powering on before trying to access this device. Signed-off-by: Brian Norris Signed-off-by: Caesar Wang Cc: Jiri Kosina Cc: linux-input@vger.kernel.org --- v1 was a few months back. I finally got around to rewriting it based on DT binding feedback. v2: * support compatible property for wacom, with specific "vdd-supply" name * support the 100ms delay needed for this digitizer * target regulator support only at specific device Documentation/devicetree/bindings/input/hid-over-i2c.txt | 6 +++++- drivers/hid/i2c-hid/i2c-hid.c | 70 ++++++++++++++++++++++++++++++++++++++++++- include/linux/i2c/i2c-hid.h | 6 ++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index b3ec4f2de875..1bc174f3a788 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -37,7 +37,9 @@ #include #include #include +#include #include +#include #include @@ -918,10 +920,25 @@ static inline int i2c_hid_acpi_pdata(struct i2c_client *client, #endif #ifdef CONFIG_OF + +/* of_device_id match data */ +struct i2c_hid_of_data { + /* Name of supply regulator. */ + const char *supply_name; + /* Delay required after powering on device before it is usable. */ + int init_delay_ms; +}; + +static const struct i2c_hid_of_data wacom_w9013_data = { + .supply_name = "vdd", + .init_delay_ms = 100, +}; + static int i2c_hid_of_probe(struct i2c_client *client, struct i2c_hid_platform_data *pdata) { struct device *dev = &client->dev; + const struct i2c_hid_of_data *data = of_device_get_match_data(dev); u32 val; int ret; @@ -937,10 +954,33 @@ static int i2c_hid_of_probe(struct i2c_client *client, } pdata->hid_descriptor_address = val; + if (data) { + pdata->init_delay_ms = data->init_delay_ms; + if (data->supply_name) { + pdata->supply = devm_regulator_get_optional(&client->dev, + data->supply_name); + if (IS_ERR(pdata->supply)) { + ret = PTR_ERR(pdata->supply); + pdata->supply = NULL; + if (ret == -EPROBE_DEFER) + return ret; + if (ret == -ENODEV) + return 0; + dev_err(dev, "Failed to get %s regulator: %d\n", + data->supply_name, ret); + return ret; + } + } + } + return 0; } static const struct of_device_id i2c_hid_of_match[] = { + { + .compatible = "wacom,w9013", + .data = &wacom_w9013_data, + }, { .compatible = "hid-over-i2c" }, {}, }; @@ -983,6 +1023,17 @@ static int i2c_hid_probe(struct i2c_client *client, ihid->pdata = *platform_data; } + if (ihid->pdata.supply) { + ret = regulator_enable(ihid->pdata.supply); + if (ret < 0) { + dev_err(&client->dev, "Failed to enable regulator: %d\n", + ret); + return ret; + } + if (ihid->pdata.init_delay_ms) + msleep(ihid->pdata.init_delay_ms); + } + if (client->irq > 0) { ihid->irq = client->irq; } else if (ACPI_COMPANION(&client->dev)) { @@ -1100,6 +1151,9 @@ static int i2c_hid_remove(struct i2c_client *client) if (ihid->desc) gpiod_put(ihid->desc); + if (ihid->pdata.supply) + regulator_disable(ihid->pdata.supply); + kfree(ihid); acpi_dev_remove_driver_gpios(ACPI_COMPANION(&client->dev)); @@ -1152,6 +1206,11 @@ static int i2c_hid_suspend(struct device *dev) else hid_warn(hid, "Failed to enable irq wake: %d\n", wake_status); + } else if (ihid->pdata.supply) { + ret = regulator_disable(ihid->pdata.supply); + if (ret < 0) + hid_warn(hid, "Failed to disable supply: %d\n", + ret); } return 0; @@ -1165,7 +1224,16 @@ static int i2c_hid_resume(struct device *dev) struct hid_device *hid = ihid->hid; int wake_status; - if (device_may_wakeup(&client->dev) && ihid->irq_wake_enabled) { + if (!device_may_wakeup(&client->dev)) { + if (ihid->pdata.supply) { + ret = regulator_enable(ihid->pdata.supply); + if (ret < 0) + hid_warn(hid, "Failed to enable supply: %d\n", + ret); + if (ihid->pdata.init_delay_ms) + msleep(ihid->pdata.init_delay_ms); + } + } else if (ihid->irq_wake_enabled) { wake_status = disable_irq_wake(ihid->irq); if (!wake_status) ihid->irq_wake_enabled = false; diff --git a/include/linux/i2c/i2c-hid.h b/include/linux/i2c/i2c-hid.h index 7aa901d92058..97688cde4a91 100644 --- a/include/linux/i2c/i2c-hid.h +++ b/include/linux/i2c/i2c-hid.h @@ -14,9 +14,13 @@ #include +struct regulator; + /** * struct i2chid_platform_data - used by hid over i2c implementation. * @hid_descriptor_address: i2c register where the HID descriptor is stored. + * @supply: regulator for powering on the device. + * @init_delay_ms: delay after powering on before device is usable. * * Note that it is the responsibility of the platform driver (or the acpi 5.0 * driver, or the flattened device tree) to setup the irq related to the gpio in @@ -31,6 +35,8 @@ */ struct i2c_hid_platform_data { u16 hid_descriptor_address; + struct regulator *supply; + int init_delay_ms; }; #endif /* __LINUX_I2C_HID_H */