From patchwork Sun Sep 4 22:11:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caesar Wang X-Patchwork-Id: 9312873 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 426CE600CA for ; Sun, 4 Sep 2016 22:12:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FE5928827 for ; Sun, 4 Sep 2016 22:12:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14A202882D; Sun, 4 Sep 2016 22:12: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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8E81B28827 for ; Sun, 4 Sep 2016 22:12:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bgfek-0003K5-3O; Sun, 04 Sep 2016 22:12:50 +0000 Received: from mail-pa0-f65.google.com ([209.85.220.65]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bgfeh-0003Cf-C8 for linux-rockchip@lists.infradead.org; Sun, 04 Sep 2016 22:12:48 +0000 Received: by mail-pa0-f65.google.com with SMTP id ez1so8315804pab.3 for ; Sun, 04 Sep 2016 15:12:27 -0700 (PDT) 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=xSUdhgpOkKDxoJWKGlzAUXmOhdVBPOJLkXhInYstt3I=; b=ZB+OVKAVaYuhRZGYIxuRdwYF9RgXqrI1XD5X+WFl8hxZkFgeUnhmXJ0ZEc/n54YsxY LvhXhku8/3uTcU8rWDWiti9PRBDZVRuiKR4S19PD8i2RN3gDPu2x6LgnQA2l3uvoITh4 cIfMIm94MJD4o45knm2s9GX9okj8hub5423Y3/luTDNHt8SzzzoYO81+fIMNr5Sz3WAs +xhuMuM2yTPoXOqzk3Qgd1LAUuD/aIJjw+4jMcf02HqdVHvlunNmBxPfUmKN5X7dzO+H h4sWF1bD0St46ccfwtVmk97C+IXWyIZ60QoOsGgzYFqHJpW/OIZLCWqUFPFuVC7UK/TT P11A== X-Gm-Message-State: AE9vXwOPcK2HV2Pv8+VH66UlOnugHhTQ5zRJC2XH4nL7WmNWVgS0JNQnxR5jIZ4jXGxnYA== X-Received: by 10.66.241.40 with SMTP id wf8mr57433699pac.119.1473027146681; Sun, 04 Sep 2016 15:12:26 -0700 (PDT) Received: from nb.corp.google.com ([172.22.52.177]) by smtp.gmail.com with ESMTPSA id y6sm29216510pav.1.2016.09.04.15.12.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 04 Sep 2016 15:12:25 -0700 (PDT) From: Caesar Wang To: Jiri Kosina Subject: [PATCH 2/2] HID: i2c-hid: support the regulator Date: Mon, 5 Sep 2016 06:11:56 +0800 Message-Id: <1473027116-13892-2-git-send-email-wxt@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1473027116-13892-1-git-send-email-wxt@rock-chips.com> References: <1473027116-13892-1-git-send-email-wxt@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160904_151247_535073_E47964CE X-CRM114-Status: GOOD ( 13.18 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Guohua Zhong , dbasehore@chromium.org, Heiko Stuebner , Dmitry Torokhov , Brian Norris , Douglas Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Benjamin Tissoires , linux-input@vger.kernel.org, Benson Leung , Mika Westerberg , "Zhonghui\"" , Caesar Wang MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Brian Norris In order to allow supporting the HID based devices that need power on/off the regulator. We try to get a power-supply property from the device tree. Signed-off-by: Brian Norris Signed-off-by: Caesar Wang Cc: Jiri Kosina Cc: linux-input@vger.kernel.org Acked-by: Benjamin Tissoires --- drivers/hid/i2c-hid/i2c-hid.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index b3ec4f2..07cc7aa 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -152,6 +153,7 @@ struct i2c_hid { bool irq_wake_enabled; struct mutex reset_lock; + struct regulator *supply; }; static int __i2c_hid_command(struct i2c_client *client, @@ -968,6 +970,21 @@ static int i2c_hid_probe(struct i2c_client *client, if (!ihid) return -ENOMEM; + ihid->supply = devm_regulator_get(&client->dev, "power"); + if (IS_ERR(ihid->supply)) { + ret = PTR_ERR(ihid->supply); + dev_err(&client->dev, "Failed to get power regulator: %d\n", + ret); + return ret; + } + + ret = regulator_enable(ihid->supply); + if (ret < 0) { + dev_err(&client->dev, "Failed to enable power regulator: %d\n", + ret); + return ret; + } + if (client->dev.of_node) { ret = i2c_hid_of_probe(client, &ihid->pdata); if (ret) @@ -1100,6 +1117,8 @@ static int i2c_hid_remove(struct i2c_client *client) if (ihid->desc) gpiod_put(ihid->desc); + regulator_disable(ihid->supply); + kfree(ihid); acpi_dev_remove_driver_gpios(ACPI_COMPANION(&client->dev)); @@ -1152,6 +1171,11 @@ static int i2c_hid_suspend(struct device *dev) else hid_warn(hid, "Failed to enable irq wake: %d\n", wake_status); + } else { + ret = regulator_disable(ihid->supply); + if (ret < 0) + hid_warn(hid, "Failed to disable power supply: %d\n", + ret); } return 0; @@ -1165,7 +1189,12 @@ 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)) { + ret = regulator_enable(ihid->supply); + if (ret < 0) + hid_warn(hid, "Failed to enable power supply: %d\n", + ret); + } else if (ihid->irq_wake_enabled) { wake_status = disable_irq_wake(ihid->irq); if (!wake_status) ihid->irq_wake_enabled = false;