aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/common/st_sensors
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2016-08-25 18:10:08 -0400
committerJonathan Cameron <jic23@kernel.org>2016-08-29 14:41:09 -0400
commitaeb55fff3891834e07a3144159a7298a19696af8 (patch)
tree5d6dcd79f4f0bd4fac0a9b26b0e1e413e46798eb /drivers/iio/common/st_sensors
parent7f270bc9a2d95967c09e759776a28a8d2a345c74 (diff)
iio: st_sensors: fetch and enable regulators unconditionally
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>
Diffstat (limited to 'drivers/iio/common/st_sensors')
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_core.c55
1 files changed, 24 insertions, 31 deletions
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index 2d5282e05482..41bfe1c5f4e9 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -234,39 +234,35 @@ int st_sensors_power_enable(struct iio_dev *indio_dev)
234 int err; 234 int err;
235 235
236 /* Regulators not mandatory, but if requested we should enable them. */ 236 /* Regulators not mandatory, but if requested we should enable them. */
237 pdata->vdd = devm_regulator_get_optional(indio_dev->dev.parent, "vdd"); 237 pdata->vdd = devm_regulator_get(indio_dev->dev.parent, "vdd");
238 if (!IS_ERR(pdata->vdd)) { 238 if (IS_ERR(pdata->vdd)) {
239 err = regulator_enable(pdata->vdd); 239 dev_err(&indio_dev->dev, "unable to get Vdd supply\n");
240 if (err != 0) { 240 return PTR_ERR(pdata->vdd);
241 dev_warn(&indio_dev->dev, 241 }
242 "Failed to enable specified Vdd supply\n"); 242 err = regulator_enable(pdata->vdd);
243 return err; 243 if (err != 0) {
244 } 244 dev_warn(&indio_dev->dev,
245 } else { 245 "Failed to enable specified Vdd supply\n");
246 err = PTR_ERR(pdata->vdd); 246 return err;
247 if (err != -ENODEV)
248 return err;
249 } 247 }
250 248
251 pdata->vdd_io = devm_regulator_get_optional(indio_dev->dev.parent, "vddio"); 249 pdata->vdd_io = devm_regulator_get(indio_dev->dev.parent, "vddio");
252 if (!IS_ERR(pdata->vdd_io)) { 250 if (IS_ERR(pdata->vdd)) {
253 err = regulator_enable(pdata->vdd_io); 251 dev_err(&indio_dev->dev, "unable to get Vdd_IO supply\n");
254 if (err != 0) { 252 err = PTR_ERR(pdata->vdd);
255 dev_warn(&indio_dev->dev, 253 goto st_sensors_disable_vdd;
256 "Failed to enable specified Vdd_IO supply\n"); 254 }
257 goto st_sensors_disable_vdd; 255 err = regulator_enable(pdata->vdd_io);
258 } 256 if (err != 0) {
259 } else { 257 dev_warn(&indio_dev->dev,
260 err = PTR_ERR(pdata->vdd_io); 258 "Failed to enable specified Vdd_IO supply\n");
261 if (err != -ENODEV) 259 goto st_sensors_disable_vdd;
262 goto st_sensors_disable_vdd;
263 } 260 }
264 261
265 return 0; 262 return 0;
266 263
267st_sensors_disable_vdd: 264st_sensors_disable_vdd:
268 if (!IS_ERR_OR_NULL(pdata->vdd)) 265 regulator_disable(pdata->vdd);
269 regulator_disable(pdata->vdd);
270 return err; 266 return err;
271} 267}
272EXPORT_SYMBOL(st_sensors_power_enable); 268EXPORT_SYMBOL(st_sensors_power_enable);
@@ -275,11 +271,8 @@ void st_sensors_power_disable(struct iio_dev *indio_dev)
275{ 271{
276 struct st_sensor_data *pdata = iio_priv(indio_dev); 272 struct st_sensor_data *pdata = iio_priv(indio_dev);
277 273
278 if (!IS_ERR_OR_NULL(pdata->vdd)) 274 regulator_disable(pdata->vdd);
279 regulator_disable(pdata->vdd); 275 regulator_disable(pdata->vdd_io);
280
281 if (!IS_ERR_OR_NULL(pdata->vdd_io))
282 regulator_disable(pdata->vdd_io);
283} 276}
284EXPORT_SYMBOL(st_sensors_power_disable); 277EXPORT_SYMBOL(st_sensors_power_disable);
285 278