From: Jonathan Cameron <jic23@kernel.org>
To: Brian Masney <masneyb@onstation.org>
Cc: robh+dt@kernel.org, mark.rutland@arm.com, andy.gross@linaro.org,
david.brown@linaro.org, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org,
jonathan@marek.ca, jmaneyrol@invensense.com, knaack.h@gmx.de,
lars@metafoo.de, pmeerw@pmeerw.net, mkelly@xevo.com,
fischerdouglasc@gmail.com, bshah@kde.org, ctatlor97@gmail.com
Subject: Re: [PATCH v3 5/9] iio: tsl2772: add support for regulator framework
Date: Fri, 3 Aug 2018 22:50:17 +0100 [thread overview]
Message-ID: <20180803225017.06ac1d3b@archlinux> (raw)
In-Reply-To: <20180803001900.25371-6-masneyb@onstation.org>
On Thu, 2 Aug 2018 20:18:56 -0400
Brian Masney <masneyb@onstation.org> wrote:
> This patch adds support for the regulator framework to the tsl2772
> driver. Driver was tested using a LG Nexus 5 (hammerhead) phone with
> the two regulators and on a Raspberry Pi 2 without any regulators
> controlling the power to the sensor.
>
> Signed-off-by: Brian Masney <masneyb@onstation.org>
This looks fine, but will wait for the precursors.
Jonathan
> ---
> drivers/iio/light/tsl2772.c | 95 ++++++++++++++++++++++++++++++++++++-
> 1 file changed, 94 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c
> index ae00edf0d87e..4a11bf77a4d0 100644
> --- a/drivers/iio/light/tsl2772.c
> +++ b/drivers/iio/light/tsl2772.c
> @@ -20,6 +20,7 @@
> #include <linux/iio/iio.h>
> #include <linux/iio/sysfs.h>
> #include <linux/platform_data/tsl2772.h>
> +#include <linux/regulator/consumer.h>
>
> /* Cal defs */
> #define PROX_STAT_CAL 0
> @@ -109,6 +110,9 @@
>
> #define TSL2772_MAX_PROX_LEDS 2
>
> +#define TSL2772_BOOT_MIN_SLEEP_TIME 10000
> +#define TSL2772_BOOT_MAX_SLEEP_TIME 28000
> +
> /* Device family members */
> enum {
> tsl2571,
> @@ -156,6 +160,8 @@ struct tsl2772_chip {
> struct mutex prox_mutex;
> struct mutex als_mutex;
> struct i2c_client *client;
> + struct regulator *vdd_supply;
> + struct regulator *vddio_supply;
> u16 prox_data;
> struct tsl2772_als_info als_cur_info;
> struct tsl2772_settings settings;
> @@ -676,6 +682,52 @@ static int tsl2772_als_calibrate(struct iio_dev *indio_dev)
> return ret;
> }
>
> +static void tsl2772_disable_regulators_action(void *_data)
> +{
> + struct tsl2772_chip *chip = _data;
> +
> + regulator_disable(chip->vdd_supply);
> + regulator_disable(chip->vddio_supply);
> +}
> +
> +static int tsl2772_enable_regulator(struct tsl2772_chip *chip,
> + struct regulator *regulator)
> +{
> + int ret;
> +
> + ret = regulator_enable(regulator);
> + if (ret < 0) {
> + dev_err(&chip->client->dev, "Failed to enable regulator: %d\n",
> + ret);
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +static struct regulator *tsl2772_get_regulator(struct tsl2772_chip *chip,
> + char *name)
> +{
> + struct regulator *regulator;
> + int ret;
> +
> + regulator = devm_regulator_get(&chip->client->dev, name);
> + if (IS_ERR(regulator)) {
> + if (PTR_ERR(regulator) != -EPROBE_DEFER)
> + dev_err(&chip->client->dev,
> + "Failed to get %s regulator %d\n",
> + name, (int)PTR_ERR(regulator));
> +
> + return regulator;
> + }
> +
> + ret = tsl2772_enable_regulator(chip, regulator);
> + if (ret < 0)
> + return ERR_PTR(ret);
> +
> + return regulator;
> +}
> +
> static int tsl2772_chip_on(struct iio_dev *indio_dev)
> {
> struct tsl2772_chip *chip = iio_priv(indio_dev);
> @@ -1733,6 +1785,27 @@ static int tsl2772_probe(struct i2c_client *clientp,
> chip->client = clientp;
> i2c_set_clientdata(clientp, indio_dev);
>
> + chip->vddio_supply = tsl2772_get_regulator(chip, "vddio");
> + if (IS_ERR(chip->vddio_supply))
> + return PTR_ERR(chip->vddio_supply);
> +
> + chip->vdd_supply = tsl2772_get_regulator(chip, "vdd");
> + if (IS_ERR(chip->vdd_supply)) {
> + regulator_disable(chip->vddio_supply);
> + return PTR_ERR(chip->vdd_supply);
> + }
> +
> + ret = devm_add_action(&clientp->dev, tsl2772_disable_regulators_action,
> + chip);
> + if (ret < 0) {
> + tsl2772_disable_regulators_action(chip);
> + dev_err(&clientp->dev, "Failed to setup regulator cleanup action %d\n",
> + ret);
> + return ret;
> + }
> +
> + usleep_range(TSL2772_BOOT_MIN_SLEEP_TIME, TSL2772_BOOT_MAX_SLEEP_TIME);
> +
> ret = i2c_smbus_read_byte_data(chip->client,
> TSL2772_CMD_REG | TSL2772_CHIPID);
> if (ret < 0)
> @@ -1806,13 +1879,33 @@ static int tsl2772_probe(struct i2c_client *clientp,
> static int tsl2772_suspend(struct device *dev)
> {
> struct iio_dev *indio_dev = dev_get_drvdata(dev);
> + struct tsl2772_chip *chip = iio_priv(indio_dev);
> + int ret;
>
> - return tsl2772_chip_off(indio_dev);
> + ret = tsl2772_chip_off(indio_dev);
> + regulator_disable(chip->vdd_supply);
> + regulator_disable(chip->vddio_supply);
> +
> + return ret;
> }
>
> static int tsl2772_resume(struct device *dev)
> {
> struct iio_dev *indio_dev = dev_get_drvdata(dev);
> + struct tsl2772_chip *chip = iio_priv(indio_dev);
> + int ret;
> +
> + ret = tsl2772_enable_regulator(chip, chip->vddio_supply);
> + if (ret < 0)
> + return ret;
> +
> + ret = tsl2772_enable_regulator(chip, chip->vdd_supply);
> + if (ret < 0) {
> + regulator_disable(chip->vddio_supply);
> + return ret;
> + }
> +
> + usleep_range(TSL2772_BOOT_MIN_SLEEP_TIME, TSL2772_BOOT_MAX_SLEEP_TIME);
>
> return tsl2772_chip_on(indio_dev);
> }
next prev parent reply other threads:[~2018-08-03 21:50 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-03 0:18 [PATCH v3 0/9] treewide: add support for various sensors on the LG Nexus 5 (hammerhead) Brian Masney
2018-08-03 0:18 ` [PATCH v3 1/9] iio: imu: mpu6050: add support for regulator framework Brian Masney
2018-08-03 21:44 ` Jonathan Cameron
2018-08-03 0:18 ` [PATCH v3 2/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for mpu6515 Brian Masney
2018-08-03 21:46 ` Jonathan Cameron
2018-08-03 0:18 ` [PATCH v3 3/9] iio: tsl2772: add support for reading proximity led settings from device tree Brian Masney
2018-08-18 17:04 ` Jonathan Cameron
2018-08-03 0:18 ` [PATCH v3 4/9] dt-bindings: iio: tsl2772: add new bindings Brian Masney
2018-08-03 21:48 ` Jonathan Cameron
2018-08-07 16:54 ` Rob Herring
2018-08-18 17:01 ` Jonathan Cameron
2018-08-03 0:18 ` [PATCH v3 5/9] iio: tsl2772: add support for regulator framework Brian Masney
2018-08-03 21:50 ` Jonathan Cameron [this message]
2018-08-03 0:18 ` [PATCH v3 6/9] dt-bindings: iio: tsl2772: add bindings " Brian Masney
2018-08-03 21:51 ` Jonathan Cameron
2018-08-07 17:20 ` Rob Herring
2018-08-18 17:02 ` Jonathan Cameron
2018-08-03 0:18 ` [PATCH v3 7/9] iio: tsl2772: add support for avago,apds9930 Brian Masney
2018-08-03 21:53 ` Jonathan Cameron
2018-08-18 17:07 ` Jonathan Cameron
2018-08-03 0:18 ` [PATCH v3 8/9] dt-bindings: iio: tsl2772: add binding " Brian Masney
2018-08-03 21:54 ` Jonathan Cameron
2018-08-07 17:21 ` Rob Herring
2018-08-18 17:06 ` Jonathan Cameron
2018-08-03 0:19 ` [PATCH v3 9/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for ALS / proximity Brian Masney
2018-08-18 17:09 ` 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=20180803225017.06ac1d3b@archlinux \
--to=jic23@kernel.org \
--cc=andy.gross@linaro.org \
--cc=bshah@kde.org \
--cc=ctatlor97@gmail.com \
--cc=david.brown@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=fischerdouglasc@gmail.com \
--cc=jmaneyrol@invensense.com \
--cc=jonathan@marek.ca \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-soc@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=masneyb@onstation.org \
--cc=mkelly@xevo.com \
--cc=pmeerw@pmeerw.net \
--cc=robh+dt@kernel.org \
/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 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.