From: Stephen Boyd <swboyd@chromium.org>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
Gwendal Grignou <gwendal@chromium.org>,
Daniel Campello <campello@chromium.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Douglas Anderson <dianders@chromium.org>
Subject: [PATCH 3/3] iio: sx9310: Enable regulator for svdd supply
Date: Thu, 23 Jul 2020 16:03:44 -0700 [thread overview]
Message-ID: <20200723230344.1422750-4-swboyd@chromium.org> (raw)
In-Reply-To: <20200723230344.1422750-1-swboyd@chromium.org>
Enable the digital IO power supply (svdd) during probe so that the i2c
communication works properly on boards that aggressively power gate this
supply.
Cc: Gwendal Grignou <gwendal@chromium.org>
Cc: Daniel Campello <campello@chromium.org>
Cc: Hartmut Knaack <knaack.h@gmx.de>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Cc: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
drivers/iio/proximity/sx9310.c | 49 ++++++++++++++++++++++++++++------
1 file changed, 41 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
index 84c3c9ae80dc..d21c17a4d541 100644
--- a/drivers/iio/proximity/sx9310.c
+++ b/drivers/iio/proximity/sx9310.c
@@ -19,6 +19,7 @@
#include <linux/of.h>
#include <linux/pm.h>
#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <linux/iio/buffer.h>
@@ -131,6 +132,7 @@ struct sx9310_data {
struct i2c_client *client;
struct iio_trigger *trig;
struct regmap *regmap;
+ struct regulator *supply;
/*
* Last reading of the proximity status for each channel.
* We only send an event to user space when this changes.
@@ -914,21 +916,31 @@ static int sx9310_probe(struct i2c_client *client,
mutex_init(&data->mutex);
init_completion(&data->completion);
+ data->supply = devm_regulator_get(&client->dev, "svdd");
+ if (IS_ERR(data->supply))
+ return PTR_ERR(data->supply);
+
data->regmap = devm_regmap_init_i2c(client, &sx9310_regmap_config);
if (IS_ERR(data->regmap))
return PTR_ERR(data->regmap);
+ ret = regulator_enable(data->supply);
+ if (ret)
+ return ret;
+ /* Must wait for Tpor time after initial power up */
+ usleep_range(1000, 1100);
+
ret = regmap_read(data->regmap, SX9310_REG_WHOAMI, &data->whoami);
if (ret < 0) {
dev_err(&client->dev, "error in reading WHOAMI register: %d\n",
ret);
- return ret;
+ goto err;
}
ret = sx9310_set_indio_dev_name(&client->dev, indio_dev, id,
data->whoami);
if (ret < 0)
- return ret;
+ goto err;
ACPI_COMPANION_SET(&indio_dev->dev, ACPI_COMPANION(&client->dev));
indio_dev->dev.parent = &client->dev;
@@ -940,7 +952,7 @@ static int sx9310_probe(struct i2c_client *client,
ret = sx9310_init_device(indio_dev);
if (ret < 0)
- return ret;
+ goto err;
if (client->irq) {
ret = devm_request_threaded_irq(&client->dev, client->irq,
@@ -949,13 +961,15 @@ static int sx9310_probe(struct i2c_client *client,
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
"sx9310_event", indio_dev);
if (ret < 0)
- return ret;
+ goto err;
data->trig =
devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
indio_dev->name, indio_dev->id);
- if (!data->trig)
- return -ENOMEM;
+ if (!data->trig) {
+ ret = -ENOMEM;
+ goto err;
+ }
data->trig->dev.parent = &client->dev;
data->trig->ops = &sx9310_trigger_ops;
@@ -963,7 +977,7 @@ static int sx9310_probe(struct i2c_client *client,
ret = devm_iio_trigger_register(&client->dev, data->trig);
if (ret)
- return ret;
+ goto err;
}
ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev,
@@ -971,9 +985,27 @@ static int sx9310_probe(struct i2c_client *client,
sx9310_trigger_handler,
&sx9310_buffer_setup_ops);
if (ret < 0)
- return ret;
+ goto err;
return devm_iio_device_register(&client->dev, indio_dev);
+err:
+ regulator_disable(data->supply);
+ return ret;
+}
+
+static int sx9310_remove(struct i2c_client *client)
+{
+ struct iio_dev *indio_dev;
+ struct sx9310_data *data;
+
+ indio_dev = i2c_get_clientdata(client);
+ if (!indio_dev)
+ return -ENODEV;
+
+ data = iio_priv(indio_dev);
+ regulator_disable(data->supply);
+
+ return 0;
}
static int __maybe_unused sx9310_suspend(struct device *dev)
@@ -1059,6 +1091,7 @@ static struct i2c_driver sx9310_driver = {
.pm = &sx9310_pm_ops,
},
.probe = sx9310_probe,
+ .remove = sx9310_remove,
.id_table = sx9310_id,
};
module_i2c_driver(sx9310_driver);
--
Sent by a computer, using git, on the internet
next prev parent reply other threads:[~2020-07-23 23:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-23 23:03 [PATCH 0/3] Some sx9310 iio driver updates Stephen Boyd
2020-07-23 23:03 ` [PATCH 1/3] dt-bindings: iio: Add bindings for sx9310 sensor Stephen Boyd
2020-07-24 20:39 ` Doug Anderson
2020-07-23 23:03 ` [PATCH 2/3] iio: sx9310: Add newlines to printks Stephen Boyd
2020-07-24 20:27 ` Doug Anderson
2020-07-24 20:43 ` Daniel Campello
2020-07-23 23:03 ` Stephen Boyd [this message]
2020-07-24 20:25 ` [PATCH 3/3] iio: sx9310: Enable regulator for svdd supply Doug Anderson
2020-07-24 20:36 ` Stephen Boyd
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=20200723230344.1422750-4-swboyd@chromium.org \
--to=swboyd@chromium.org \
--cc=campello@chromium.org \
--cc=dianders@chromium.org \
--cc=gwendal@chromium.org \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmeerw@pmeerw.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).