iio: st_sensors: fetch and enable regulators unconditionally
authorLinus Walleij <linus.walleij@linaro.org>
Thu, 25 Aug 2016 22:10:08 +0000 (00:10 +0200)
committerJonathan Cameron <jic23@kernel.org>
Mon, 29 Aug 2016 18:41:09 +0000 (19:41 +0100)
These sensors all have Vdd and Vdd_IO lines. This means the
supplies are *not* optional (optional means that the supply is
optional in the electrical sense, not the software sense)
so we need to get the and enable them at all times.

If the device tree or board file does not define suitable
regulators for the component, it will be substituted by a
dummy regulator, or, if regulators are disabled altogether,
by stubs. There is no need to use the IS_ERR_OR_NULL() check
that is considered harmful.

Cc: Giuseppe Barba <giuseppe.barba@st.com>
Cc: Denis Ciocca <denis.ciocca@st.com>
Cc: Crestez Dan Leonard <leonard.crestez@intel.com>
Cc: Gregor Boirie <gregor.boirie@parrot.com>
Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/common/st_sensors/st_sensors_core.c

index 2d5282e05482f7d3eaa9adce2f74ba098376ede3..41bfe1c5f4e91fbaa12faebbab31fa7079342f0e 100644 (file)
@@ -234,39 +234,35 @@ int st_sensors_power_enable(struct iio_dev *indio_dev)
        int err;
 
        /* Regulators not mandatory, but if requested we should enable them. */
-       pdata->vdd = devm_regulator_get_optional(indio_dev->dev.parent, "vdd");
-       if (!IS_ERR(pdata->vdd)) {
-               err = regulator_enable(pdata->vdd);
-               if (err != 0) {
-                       dev_warn(&indio_dev->dev,
-                                "Failed to enable specified Vdd supply\n");
-                       return err;
-               }
-       } else {
-               err = PTR_ERR(pdata->vdd);
-               if (err != -ENODEV)
-                       return err;
+       pdata->vdd = devm_regulator_get(indio_dev->dev.parent, "vdd");
+       if (IS_ERR(pdata->vdd)) {
+               dev_err(&indio_dev->dev, "unable to get Vdd supply\n");
+               return PTR_ERR(pdata->vdd);
+       }
+       err = regulator_enable(pdata->vdd);
+       if (err != 0) {
+               dev_warn(&indio_dev->dev,
+                        "Failed to enable specified Vdd supply\n");
+               return err;
        }
 
-       pdata->vdd_io = devm_regulator_get_optional(indio_dev->dev.parent, "vddio");
-       if (!IS_ERR(pdata->vdd_io)) {
-               err = regulator_enable(pdata->vdd_io);
-               if (err != 0) {
-                       dev_warn(&indio_dev->dev,
-                                "Failed to enable specified Vdd_IO supply\n");
-                       goto st_sensors_disable_vdd;
-               }
-       } else {
-               err = PTR_ERR(pdata->vdd_io);
-               if (err != -ENODEV)
-                       goto st_sensors_disable_vdd;
+       pdata->vdd_io = devm_regulator_get(indio_dev->dev.parent, "vddio");
+       if (IS_ERR(pdata->vdd)) {
+               dev_err(&indio_dev->dev, "unable to get Vdd_IO supply\n");
+               err = PTR_ERR(pdata->vdd);
+               goto st_sensors_disable_vdd;
+       }
+       err = regulator_enable(pdata->vdd_io);
+       if (err != 0) {
+               dev_warn(&indio_dev->dev,
+                        "Failed to enable specified Vdd_IO supply\n");
+               goto st_sensors_disable_vdd;
        }
 
        return 0;
 
 st_sensors_disable_vdd:
-       if (!IS_ERR_OR_NULL(pdata->vdd))
-               regulator_disable(pdata->vdd);
+       regulator_disable(pdata->vdd);
        return err;
 }
 EXPORT_SYMBOL(st_sensors_power_enable);
@@ -275,11 +271,8 @@ void st_sensors_power_disable(struct iio_dev *indio_dev)
 {
        struct st_sensor_data *pdata = iio_priv(indio_dev);
 
-       if (!IS_ERR_OR_NULL(pdata->vdd))
-               regulator_disable(pdata->vdd);
-
-       if (!IS_ERR_OR_NULL(pdata->vdd_io))
-               regulator_disable(pdata->vdd_io);
+       regulator_disable(pdata->vdd);
+       regulator_disable(pdata->vdd_io);
 }
 EXPORT_SYMBOL(st_sensors_power_disable);