aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorGregor Boirie <gregor.boirie@parrot.com>2016-03-17 07:55:03 -0400
committerJonathan Cameron <jic23@kernel.org>2016-03-20 07:02:40 -0400
commit334ecdd0ba45bb68bce0f1429a4a1e9584ba437e (patch)
tree8e3788eb72a62f5f6c3ccbb714f754cb3b345228 /drivers/iio
parent718ba46e5f4e21e45141bf55fd4cccd4b3ba9939 (diff)
iio:pressure:ms5611: fix missing regulator_disable
Ensure optional regulator is properly disabled when present. Fixes: 3145229f9191 ("iio:pressure:ms5611: power regulator support") Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/pressure/ms5611.h3
-rw-r--r--drivers/iio/pressure/ms5611_core.c41
2 files changed, 35 insertions, 9 deletions
diff --git a/drivers/iio/pressure/ms5611.h b/drivers/iio/pressure/ms5611.h
index d725a3077a17..ccda63c5b3c3 100644
--- a/drivers/iio/pressure/ms5611.h
+++ b/drivers/iio/pressure/ms5611.h
@@ -16,6 +16,8 @@
16#include <linux/iio/iio.h> 16#include <linux/iio/iio.h>
17#include <linux/mutex.h> 17#include <linux/mutex.h>
18 18
19struct regulator;
20
19#define MS5611_RESET 0x1e 21#define MS5611_RESET 0x1e
20#define MS5611_READ_ADC 0x00 22#define MS5611_READ_ADC 0x00
21#define MS5611_READ_PROM_WORD 0xA0 23#define MS5611_READ_PROM_WORD 0xA0
@@ -57,6 +59,7 @@ struct ms5611_state {
57 s32 *temp, s32 *pressure); 59 s32 *temp, s32 *pressure);
58 60
59 struct ms5611_chip_info *chip_info; 61 struct ms5611_chip_info *chip_info;
62 struct regulator *vdd;
60}; 63};
61 64
62int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, 65int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c
index 37dbc0401599..c4e65868bc28 100644
--- a/drivers/iio/pressure/ms5611_core.c
+++ b/drivers/iio/pressure/ms5611_core.c
@@ -387,24 +387,45 @@ static const struct iio_info ms5611_info = {
387static int ms5611_init(struct iio_dev *indio_dev) 387static int ms5611_init(struct iio_dev *indio_dev)
388{ 388{
389 int ret; 389 int ret;
390 struct regulator *vdd = devm_regulator_get(indio_dev->dev.parent, 390 struct ms5611_state *st = iio_priv(indio_dev);
391 "vdd");
392 391
393 /* Enable attached regulator if any. */ 392 /* Enable attached regulator if any. */
394 if (!IS_ERR(vdd)) { 393 st->vdd = devm_regulator_get(indio_dev->dev.parent, "vdd");
395 ret = regulator_enable(vdd); 394 if (!IS_ERR(st->vdd)) {
395 ret = regulator_enable(st->vdd);
396 if (ret) { 396 if (ret) {
397 dev_err(indio_dev->dev.parent, 397 dev_err(indio_dev->dev.parent,
398 "failed to enable Vdd supply: %d\n", ret); 398 "failed to enable Vdd supply: %d\n", ret);
399 return ret; 399 return ret;
400 } 400 }
401 } else {
402 ret = PTR_ERR(st->vdd);
403 if (ret != -ENODEV)
404 return ret;
401 } 405 }
402 406
403 ret = ms5611_reset(indio_dev); 407 ret = ms5611_reset(indio_dev);
404 if (ret < 0) 408 if (ret < 0)
405 return ret; 409 goto err_regulator_disable;
410
411 ret = ms5611_read_prom(indio_dev);
412 if (ret < 0)
413 goto err_regulator_disable;
414
415 return 0;
406 416
407 return ms5611_read_prom(indio_dev); 417err_regulator_disable:
418 if (!IS_ERR_OR_NULL(st->vdd))
419 regulator_disable(st->vdd);
420 return ret;
421}
422
423static void ms5611_fini(const struct iio_dev *indio_dev)
424{
425 const struct ms5611_state *st = iio_priv(indio_dev);
426
427 if (!IS_ERR_OR_NULL(st->vdd))
428 regulator_disable(st->vdd);
408} 429}
409 430
410int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, 431int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
@@ -436,7 +457,7 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
436 ms5611_trigger_handler, NULL); 457 ms5611_trigger_handler, NULL);
437 if (ret < 0) { 458 if (ret < 0) {
438 dev_err(dev, "iio triggered buffer setup failed\n"); 459 dev_err(dev, "iio triggered buffer setup failed\n");
439 return ret; 460 goto err_fini;
440 } 461 }
441 462
442 ret = iio_device_register(indio_dev); 463 ret = iio_device_register(indio_dev);
@@ -449,7 +470,8 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
449 470
450err_buffer_cleanup: 471err_buffer_cleanup:
451 iio_triggered_buffer_cleanup(indio_dev); 472 iio_triggered_buffer_cleanup(indio_dev);
452 473err_fini:
474 ms5611_fini(indio_dev);
453 return ret; 475 return ret;
454} 476}
455EXPORT_SYMBOL(ms5611_probe); 477EXPORT_SYMBOL(ms5611_probe);
@@ -458,6 +480,7 @@ int ms5611_remove(struct iio_dev *indio_dev)
458{ 480{
459 iio_device_unregister(indio_dev); 481 iio_device_unregister(indio_dev);
460 iio_triggered_buffer_cleanup(indio_dev); 482 iio_triggered_buffer_cleanup(indio_dev);
483 ms5611_fini(indio_dev);
461 484
462 return 0; 485 return 0;
463} 486}