summaryrefslogtreecommitdiffstats
path: root/drivers/iio/pressure
diff options
context:
space:
mode:
authorLee Jones <lee.jones@linaro.org>2013-09-16 12:02:00 -0400
committerJonathan Cameron <jic23@kernel.org>2013-09-23 15:17:54 -0400
commit774487611c949e6d194877e7147f6eeeec092b53 (patch)
treed6abcf6697bb6186f798f5207d599f0abf27b88b /drivers/iio/pressure
parent3ffdea3feca9e2c95c2e93e217d77c9c368f747a (diff)
iio: pressure-core: st: Provide support for the Vdd power supply
The power to some of the sensors are controlled by regulators. In most cases these are 'always on', but if not they will fail to work until the regulator is enabled using the relevant APIs. This patch allows for the Vdd power supply to be specified by either platform data or Device Tree. Signed-off-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/pressure')
-rw-r--r--drivers/iio/pressure/st_pressure_core.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 2da411b6925b..baeab109f41d 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -23,6 +23,7 @@
23#include <linux/iio/sysfs.h> 23#include <linux/iio/sysfs.h>
24#include <linux/iio/trigger.h> 24#include <linux/iio/trigger.h>
25#include <linux/iio/buffer.h> 25#include <linux/iio/buffer.h>
26#include <linux/regulator/consumer.h>
26#include <asm/unaligned.h> 27#include <asm/unaligned.h>
27 28
28#include <linux/iio/common/st_sensors.h> 29#include <linux/iio/common/st_sensors.h>
@@ -313,6 +314,29 @@ static const struct iio_trigger_ops st_press_trigger_ops = {
313#define ST_PRESS_TRIGGER_OPS NULL 314#define ST_PRESS_TRIGGER_OPS NULL
314#endif 315#endif
315 316
317static void st_press_power_enable(struct iio_dev *indio_dev)
318{
319 struct st_sensor_data *pdata = iio_priv(indio_dev);
320 int err;
321
322 /* Regulators not mandatory, but if requested we should enable it. */
323 pdata->vdd = devm_regulator_get_optional(&indio_dev->dev, "vdd");
324 if (!IS_ERR(pdata->vdd)) {
325 err = regulator_enable(pdata->vdd);
326 if (err != 0)
327 dev_warn(&indio_dev->dev,
328 "Failed to enable specified Vdd supply\n");
329 }
330}
331
332static void st_press_power_disable(struct iio_dev *indio_dev)
333{
334 struct st_sensor_data *pdata = iio_priv(indio_dev);
335
336 if (!IS_ERR(pdata->vdd))
337 regulator_disable(pdata->vdd);
338}
339
316int st_press_common_probe(struct iio_dev *indio_dev, 340int st_press_common_probe(struct iio_dev *indio_dev,
317 struct st_sensors_platform_data *plat_data) 341 struct st_sensors_platform_data *plat_data)
318{ 342{
@@ -323,6 +347,8 @@ int st_press_common_probe(struct iio_dev *indio_dev,
323 indio_dev->modes = INDIO_DIRECT_MODE; 347 indio_dev->modes = INDIO_DIRECT_MODE;
324 indio_dev->info = &press_info; 348 indio_dev->info = &press_info;
325 349
350 st_press_power_enable(indio_dev);
351
326 err = st_sensors_check_device_support(indio_dev, 352 err = st_sensors_check_device_support(indio_dev,
327 ARRAY_SIZE(st_press_sensors), 353 ARRAY_SIZE(st_press_sensors),
328 st_press_sensors); 354 st_press_sensors);
@@ -380,6 +406,8 @@ void st_press_common_remove(struct iio_dev *indio_dev)
380{ 406{
381 struct st_sensor_data *pdata = iio_priv(indio_dev); 407 struct st_sensor_data *pdata = iio_priv(indio_dev);
382 408
409 st_press_power_disable(indio_dev);
410
383 iio_device_unregister(indio_dev); 411 iio_device_unregister(indio_dev);
384 if (pdata->get_irq_data_ready(indio_dev) > 0) 412 if (pdata->get_irq_data_ready(indio_dev) > 0)
385 st_sensors_deallocate_trigger(indio_dev); 413 st_sensors_deallocate_trigger(indio_dev);