Skip to contentSkip to conversation

iio: light: isl29018: add optional vcc regulator operation support

PATCH Superseded Anson Huang 2 participants 2 messages Dec 6, 2018 – Dec 7, 2018 IIO

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: light: isl29018: add optional vcc regulator operation support

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 vcc regulator operation support.

---
 drivers/iio/light/isl29018.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/iio/light/isl29018.c +29 -0
index b45400f..47a55c8 100644
@@ -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	*vcc_reg;
 };
 
 static int isl29018_set_integration_time(struct isl29018_chip *chip,
@@ -735,6 +737,15 @@ static int isl29018_probe(struct i2c_client *client,
 
 	mutex_init(&chip->lock);
 
+	chip->vcc_reg = devm_regulator_get_optional(&client->dev, "vcc");
+	if (!IS_ERR(chip->vcc_reg)) {
+		err = regulator_enable(chip->vcc_reg);
+		if (err) {
+			dev_err(&client->dev, "failed to enable VDD regulator\n");
+			return err;
+		}
+	}
+
 	chip->type = dev_id;
 	chip->calibscale = 1;
 	chip->ucalibscale = 0;
@@ -768,6 +779,7 @@ static int isl29018_probe(struct i2c_client *client,
 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 +789,14 @@ static int isl29018_suspend(struct device *dev)
 	 * So we do not have much to do here.
 	 */
 	chip->suspended = true;
+	if (!IS_ERR(chip->vcc_reg)) {
+		ret = regulator_disable(chip->vcc_reg);
+		if (ret) {
+			dev_err(dev, "failed to disable VDD regulator\n");
+			mutex_unlock(&chip->lock);
+			return ret;
+		}
+	}
 
 	mutex_unlock(&chip->lock);
 
@@ -790,6 +810,15 @@ static int isl29018_resume(struct device *dev)
 
 	mutex_lock(&chip->lock);
 
+	if (!IS_ERR(chip->vcc_reg)) {
+		err = regulator_enable(chip->vcc_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;
Signature · 1 line
2.7.4
#1 lore raw

Hi Anson,

Quoted 33 lines · Anson Huang

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 vcc regulator operation support.

---
 drivers/iio/light/isl29018.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/iio/light/isl29018.c +2 -0
index b45400f..47a55c8 100644
@@ -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        *vcc_reg;
 };
 
 static int isl29018_set_integration_time(struct isl29018_chip *chip,

drivers/iio/light/isl29018.c static int isl29018_probe(struct i2c_client *client, · line 744

Quoted 8 lines
drivers/iio/light/isl29018.c +5 -0
@@ -735,6 +737,15 @@ static int isl29018_probe(struct i2c_client *client,
 
        mutex_init(&chip->lock);
 
+       chip->vcc_reg = devm_regulator_get_optional(&client->dev, "vcc");
+       if (!IS_ERR(chip->vcc_reg)) {
+               err = regulator_enable(chip->vcc_reg);
+               if (err) {
+                       dev_err(&client->dev, "failed to enable VDD regulator\n");

You call the regulator as "vcc", but in the error message you mention "VDD", which is confusing.

Same comment as in the previous patch.

There is no VCC regulator as per the datasheet. There are VDDD and VDDA power supplies, so better represent both and with the same name they appear in the datasheet.