linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikita Travkin <nikita@trvn.ru>
To: jic23@kernel.org
Cc: lars@metafoo.de, robh+dt@kernel.org, stephan@gerhold.net,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, Nikita Travkin <nikita@trvn.ru>
Subject: [PATCH 3/4] iio: light: ltr501: Add rudimentary regulator support
Date: Wed,  6 Oct 2021 21:30:57 +0500	[thread overview]
Message-ID: <20211006163058.145842-3-nikita@trvn.ru> (raw)
In-Reply-To: <20211006163058.145842-1-nikita@trvn.ru>

On some platforms the supply regulators must be enabled before the
sensor can work. Add vdd and vddio regulators for the sensor and IO bus
power respectively.

Signed-off-by: Nikita Travkin <nikita@trvn.ru>
---
 drivers/iio/light/ltr501.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index 1830221da48d..57851c8ef1c6 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -15,6 +15,7 @@
 #include <linux/delay.h>
 #include <linux/regmap.h>
 #include <linux/acpi.h>
+#include <linux/regulator/consumer.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/events.h>
@@ -151,6 +152,7 @@ struct ltr501_chip_info {
 
 struct ltr501_data {
 	struct i2c_client *client;
+	struct regulator_bulk_data regulators[2];
 	struct mutex lock_als, lock_ps;
 	const struct ltr501_chip_info *chip_info;
 	u8 als_contr, ps_contr;
@@ -1379,6 +1381,13 @@ static const struct regmap_config ltr501_regmap_config = {
 	.volatile_reg = ltr501_is_volatile_reg,
 };
 
+static void ltr501_disable_regulators(void *d)
+{
+	struct ltr501_data *data = d;
+
+	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
+}
+
 static int ltr501_powerdown(struct ltr501_data *data)
 {
 	return ltr501_write_contr(data, data->als_contr &
@@ -1423,6 +1432,25 @@ static int ltr501_probe(struct i2c_client *client,
 	mutex_init(&data->lock_als);
 	mutex_init(&data->lock_ps);
 
+	data->regulators[0].supply = "vdd";
+	data->regulators[1].supply = "vddio";
+	ret = devm_regulator_bulk_get(&client->dev,
+				      ARRAY_SIZE(data->regulators),
+				      data->regulators);
+	if (ret)
+		return dev_err_probe(&client->dev, ret,
+				     "Failed to get regulators\n");
+
+	ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators),
+				    data->regulators);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(&client->dev,
+				       ltr501_disable_regulators, data);
+	if (ret)
+		return ret;
+
 	data->reg_it = devm_regmap_field_alloc(&client->dev, regmap,
 					       reg_field_it);
 	if (IS_ERR(data->reg_it)) {
-- 
2.30.2


  parent reply	other threads:[~2021-10-06 16:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-06 16:30 [PATCH 1/4] dt-bindings: vendor-prefixes: Document liteon vendor prefix Nikita Travkin
2021-10-06 16:30 ` [PATCH 2/4] dt-bindings: iio: light: Document ltr501 light sensor bindings Nikita Travkin
2021-10-14 20:28   ` Rob Herring
2021-10-06 16:30 ` Nikita Travkin [this message]
2021-10-06 16:30 ` [PATCH 4/4] iio: light: ltr501: Add of_device_id table Nikita Travkin
2021-10-07 15:41 ` [PATCH 1/4] dt-bindings: vendor-prefixes: Document liteon vendor prefix Jonathan Cameron
2021-10-14 20:28 ` Rob Herring
2021-10-16 15:55   ` Jonathan Cameron

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=20211006163058.145842-3-nikita@trvn.ru \
    --to=nikita@trvn.ru \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=stephan@gerhold.net \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).