From: Caesar Wang <wxt@rock-chips.com> To: Jiri Kosina <jikos@kernel.org> Cc: linux-rockchip@lists.infradead.org, dbasehore@chromium.org, Douglas Anderson <dianders@chromium.org>, Heiko Stuebner <heiko@sntech.de>, Brian Norris <briannorris@chromium.org>, Caesar Wang <wxt@rock-chips.com>, linux-input@vger.kernel.org, Mika Westerberg <mika.westerberg@linux.intel.com>, Dmitry Torokhov <dtor@chromium.org>, Benjamin Tissoires <benjamin.tissoires@redhat.com>, Benson Leung <bleung@chromium.org>, Guohua Zhong <ghzhong@yifangdigital.com>, "Zhonghui\"" <zhonghui.fu@linux.intel.com>, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] HID: i2c-hid: support the regulator Date: Mon, 5 Sep 2016 06:11:56 +0800 [thread overview] Message-ID: <1473027116-13892-2-git-send-email-wxt@rock-chips.com> (raw) In-Reply-To: <1473027116-13892-1-git-send-email-wxt@rock-chips.com> From: Brian Norris <briannorris@chromium.org> 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 <briannorris@chromium.org> Signed-off-by: Caesar Wang <wxt@rock-chips.com> Cc: Jiri Kosina <jikos@kernel.org> Cc: linux-input@vger.kernel.org --- 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 <linux/acpi.h> #include <linux/of.h> #include <linux/gpio/consumer.h> +#include <linux/regulator/consumer.h> #include <linux/i2c/i2c-hid.h> @@ -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; -- 1.9.1
WARNING: multiple messages have this Message-ID (diff)
From: Caesar Wang <wxt-TNX95d0MmH7DzftRWevZcw@public.gmane.org> To: Jiri Kosina <jikos-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> Cc: Guohua Zhong <ghzhong-COaM65pZ/3cNIbNsV2NXlwC/G2K4zDHf@public.gmane.org>, dbasehore-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org, Heiko Stuebner <heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>, Dmitry Torokhov <dtor-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>, Brian Norris <briannorris-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>, Douglas Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, Benjamin Tissoires <benjamin.tissoires-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>, linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Benson Leung <bleung-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>, Mika Westerberg <mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>, "Zhonghui\"" <zhonghui.fu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>, Caesar Wang <wxt-TNX95d0MmH7DzftRWevZcw@public.gmane.org> Subject: [PATCH 2/2] HID: i2c-hid: support the regulator Date: Mon, 5 Sep 2016 06:11:56 +0800 [thread overview] Message-ID: <1473027116-13892-2-git-send-email-wxt@rock-chips.com> (raw) In-Reply-To: <1473027116-13892-1-git-send-email-wxt-TNX95d0MmH7DzftRWevZcw@public.gmane.org> From: Brian Norris <briannorris-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org> 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 <briannorris-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org> Signed-off-by: Caesar Wang <wxt-TNX95d0MmH7DzftRWevZcw@public.gmane.org> Cc: Jiri Kosina <jikos-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> Cc: linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org --- 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 <linux/acpi.h> #include <linux/of.h> #include <linux/gpio/consumer.h> +#include <linux/regulator/consumer.h> #include <linux/i2c/i2c-hid.h> @@ -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; -- 1.9.1
next prev parent reply other threads:[~2016-09-04 22:13 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-09-04 22:11 [PATCH 1/2] dt-bindings: add the regulator optional properties Caesar Wang 2016-09-04 22:11 ` Caesar Wang 2016-09-04 22:11 ` Caesar Wang [this message] 2016-09-04 22:11 ` [PATCH 2/2] HID: i2c-hid: support the regulator Caesar Wang 2016-09-14 7:36 ` Benjamin Tissoires 2016-09-14 7:55 ` Brian Norris 2016-09-14 7:55 ` Brian Norris 2016-09-14 8:02 ` Brian Norris 2016-09-14 14:31 ` Benjamin Tissoires 2016-09-12 16:16 ` [PATCH 1/2] dt-bindings: add the regulator optional properties Rob Herring
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1473027116-13892-2-git-send-email-wxt@rock-chips.com \ --to=wxt@rock-chips.com \ --cc=benjamin.tissoires@redhat.com \ --cc=bleung@chromium.org \ --cc=briannorris@chromium.org \ --cc=dbasehore@chromium.org \ --cc=dianders@chromium.org \ --cc=dtor@chromium.org \ --cc=ghzhong@yifangdigital.com \ --cc=heiko@sntech.de \ --cc=jikos@kernel.org \ --cc=linux-input@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-rockchip@lists.infradead.org \ --cc=mika.westerberg@linux.intel.com \ --cc=zhonghui.fu@linux.intel.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.