* [PATCH V5 2/2] iio: light: isl29018: add optional vdd regulator operation support
2018-12-11 5:02 [PATCH V5 1/2] dt-bindings: iio: light: isl29018: update power supply name Anson Huang
@ 2018-12-11 5:02 ` Anson Huang
2018-12-12 17:04 ` [PATCH V5 1/2] dt-bindings: iio: light: isl29018: update power supply name Jonathan Cameron
1 sibling, 0 replies; 3+ messages in thread
From: Anson Huang @ 2018-12-11 5:02 UTC (permalink / raw)
To: jic23, knaack.h, lars, pmeerw, robh+dt, mark.rutland, linux-iio,
devicetree, linux-kernel, festevam, preid
Cc: dl-linux-imx
The light sensor's power supply could be controlled by regulator
on some platforms, such as i.MX6Q-SABRESD board, the light sensor
isl29023's power supply is controlled by a GPIO fixed regulator,
need to make sure the regulator is enabled before any operation of
sensor, this patch adds optional vdd regulator operation support.
Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
ChangeLog since V4:
Since ONLY isl29018 has two power supplies and they are MUST shorted externally, so they can be
treated as one power supply as well, using one regulator for driver.
---
drivers/iio/light/isl29018.c | 47 +++++++++++++++++++++++++++++++++++++++++---
1 file changed, 44 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/light/isl29018.c b/drivers/iio/light/isl29018.c
index b45400f..5e3d1c1 100644
--- a/drivers/iio/light/isl29018.c
+++ b/drivers/iio/light/isl29018.c
@@ -23,6 +23,7 @@
#include <linux/mutex.h>
#include <linux/delay.h>
#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
@@ -95,6 +96,7 @@ struct isl29018_chip {
struct isl29018_scale scale;
int prox_scheme;
bool suspended;
+ struct regulator *vdd_reg;
};
static int isl29018_set_integration_time(struct isl29018_chip *chip,
@@ -735,6 +737,19 @@ static int isl29018_probe(struct i2c_client *client,
mutex_init(&chip->lock);
+ chip->vdd_reg = devm_regulator_get_optional(&client->dev, "vdd");
+ if (!IS_ERR(chip->vdd_reg)) {
+ err = regulator_enable(chip->vdd_reg);
+ if (err) {
+ dev_err(&client->dev, "failed to enable VDD regulator\n");
+ return err;
+ }
+ } else {
+ err = PTR_ERR(chip->vdd_reg);
+ if (err != -ENODEV)
+ return err;
+ }
+
chip->type = dev_id;
chip->calibscale = 1;
chip->ucalibscale = 0;
@@ -747,12 +762,12 @@ static int isl29018_probe(struct i2c_client *client,
if (IS_ERR(chip->regmap)) {
err = PTR_ERR(chip->regmap);
dev_err(&client->dev, "regmap initialization fails: %d\n", err);
- return err;
+ goto disable_regulator;
}
err = isl29018_chip_init(chip);
if (err)
- return err;
+ goto disable_regulator;
indio_dev->info = isl29018_chip_info_tbl[dev_id].indio_info;
indio_dev->channels = isl29018_chip_info_tbl[dev_id].channels;
@@ -761,13 +776,22 @@ static int isl29018_probe(struct i2c_client *client,
indio_dev->dev.parent = &client->dev;
indio_dev->modes = INDIO_DIRECT_MODE;
- return devm_iio_device_register(&client->dev, indio_dev);
+ err = devm_iio_device_register(&client->dev, indio_dev);
+ if (!err)
+ return 0;
+
+disable_regulator:
+ if (!IS_ERR(chip->vdd_reg))
+ regulator_disable(chip->vdd_reg);
+
+ return err;
}
#ifdef CONFIG_PM_SLEEP
static int isl29018_suspend(struct device *dev)
{
struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev));
+ int ret;
mutex_lock(&chip->lock);
@@ -777,6 +801,14 @@ static int isl29018_suspend(struct device *dev)
* So we do not have much to do here.
*/
chip->suspended = true;
+ if (!IS_ERR(chip->vdd_reg)) {
+ ret = regulator_disable(chip->vdd_reg);
+ if (ret) {
+ dev_err(dev, "failed to disable VDD regulator\n");
+ mutex_unlock(&chip->lock);
+ return ret;
+ }
+ }
mutex_unlock(&chip->lock);
@@ -790,6 +822,15 @@ static int isl29018_resume(struct device *dev)
mutex_lock(&chip->lock);
+ if (!IS_ERR(chip->vdd_reg)) {
+ err = regulator_enable(chip->vdd_reg);
+ if (err) {
+ dev_err(dev, "failed to enable VDD regulator\n");
+ mutex_unlock(&chip->lock);
+ return err;
+ }
+ }
+
err = isl29018_chip_init(chip);
if (!err)
chip->suspended = false;
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH V5 1/2] dt-bindings: iio: light: isl29018: update power supply name
2018-12-11 5:02 [PATCH V5 1/2] dt-bindings: iio: light: isl29018: update power supply name Anson Huang
2018-12-11 5:02 ` [PATCH V5 2/2] iio: light: isl29018: add optional vdd regulator operation support Anson Huang
@ 2018-12-12 17:04 ` Jonathan Cameron
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2018-12-12 17:04 UTC (permalink / raw)
To: Anson Huang
Cc: knaack.h, lars, pmeerw, robh+dt, mark.rutland, linux-iio,
devicetree, linux-kernel, festevam, preid, dl-linux-imx
On Tue, 11 Dec 2018 05:02:39 +0000
Anson Huang <anson.huang@nxp.com> wrote:
> According to datasheet, the isl29018 has "vddd/vdda" power
> supply, the "vdda" and "vddd" MUST be shorted externally,
> and isl29023/isl29035 ONLY has "vdd" power supply, so just
> one regulator is needed for the driver, update the power
> supply name with "vdd" according to datasheet to avoid
> confusion.
>
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
Given the discussion on v4 I am assuming this should be dropped.
Shout if I'm missing something.
Jonathan
> ---
> ChangeLog since V4:
> Since ONLY isl29018 has two power supplies and they are MUST shorted externally, so they can be
> treated as one power supply as well, remove "vdda" power supply and ONLY update the "vcc" with
> "vdd" according to datasheet.
> ---
> Documentation/devicetree/bindings/iio/light/isl29018.txt | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Documentation/devicetree/bindings/iio/light/isl29018.txt b/Documentation/devicetree/bindings/iio/light/isl29018.txt
> index b9bbde3..c4c4e9e 100644
> --- a/Documentation/devicetree/bindings/iio/light/isl29018.txt
> +++ b/Documentation/devicetree/bindings/iio/light/isl29018.txt
> @@ -15,7 +15,7 @@ Optional properties:
> Refer to interrupt-controller/interrupts.txt for generic interrupt client
> node bindings.
>
> - - vcc-supply: phandle to the regulator that provides power to the sensor.
> + - vdd-supply: phandle to the regulator that provides power to the sensor.
>
> Example:
>
^ permalink raw reply [flat|nested] 3+ messages in thread