aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2014-04-13 15:08:00 -0400
committerJonathan Cameron <jic23@kernel.org>2014-04-26 06:52:42 -0400
commitea7e586bdd331fd6fba2b6f9fd3777928c2814d8 (patch)
tree3d7caff67e139ab25a01ccfd2fa26edafb0cd261
parent4f544ced19b3d300ac11414b68a676a2c42f6d06 (diff)
iio: st_sensors: move regulator retrieveal to core
Currently the pressure sensor has code to retrieve and enable two regulators for Vdd and Vdd IO, but actually these voltage inputs are found on all of these ST sensors, so move the regulator handling to the core and make sure all the ST sensors call these functions on probe() and remove() to enable/disable power. Here also mover over to obtaining the regulator from the *parent* device of the IIO device, as the IIO device is created on-the-fly in this very subsystem it very unlikely evert have any regulators attached to it whatsoever. It is much more likely that the parent is a platform device, possibly instantiated from a device tree, which in turn have Vdd and Vdd IO supplied assigned to it. Cc: Lee Jones <lee.jones@linaro.org> Cc: Denis CIOCCA <denis.ciocca@st.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/iio/accel/st_accel_core.c4
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_core.c37
-rw-r--r--drivers/iio/gyro/st_gyro_core.c4
-rw-r--r--drivers/iio/magnetometer/st_magn_core.c4
-rw-r--r--drivers/iio/pressure/st_pressure_core.c39
-rw-r--r--include/linux/iio/common/st_sensors.h4
6 files changed, 55 insertions, 37 deletions
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 4e06fcf5b891..a2abf7c2ce3b 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -459,6 +459,8 @@ int st_accel_common_probe(struct iio_dev *indio_dev,
459 indio_dev->modes = INDIO_DIRECT_MODE; 459 indio_dev->modes = INDIO_DIRECT_MODE;
460 indio_dev->info = &accel_info; 460 indio_dev->info = &accel_info;
461 461
462 st_sensors_power_enable(indio_dev);
463
462 err = st_sensors_check_device_support(indio_dev, 464 err = st_sensors_check_device_support(indio_dev,
463 ARRAY_SIZE(st_accel_sensors), st_accel_sensors); 465 ARRAY_SIZE(st_accel_sensors), st_accel_sensors);
464 if (err < 0) 466 if (err < 0)
@@ -515,6 +517,8 @@ void st_accel_common_remove(struct iio_dev *indio_dev)
515{ 517{
516 struct st_sensor_data *adata = iio_priv(indio_dev); 518 struct st_sensor_data *adata = iio_priv(indio_dev);
517 519
520 st_sensors_power_disable(indio_dev);
521
518 iio_device_unregister(indio_dev); 522 iio_device_unregister(indio_dev);
519 if (adata->get_irq_data_ready(indio_dev) > 0) 523 if (adata->get_irq_data_ready(indio_dev) > 0)
520 st_sensors_deallocate_trigger(indio_dev); 524 st_sensors_deallocate_trigger(indio_dev);
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index 7ba1ef270213..e8b932fed70e 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -13,6 +13,7 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/delay.h> 14#include <linux/delay.h>
15#include <linux/iio/iio.h> 15#include <linux/iio/iio.h>
16#include <linux/regulator/consumer.h>
16#include <asm/unaligned.h> 17#include <asm/unaligned.h>
17 18
18#include <linux/iio/common/st_sensors.h> 19#include <linux/iio/common/st_sensors.h>
@@ -198,6 +199,42 @@ int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable)
198} 199}
199EXPORT_SYMBOL(st_sensors_set_axis_enable); 200EXPORT_SYMBOL(st_sensors_set_axis_enable);
200 201
202void st_sensors_power_enable(struct iio_dev *indio_dev)
203{
204 struct st_sensor_data *pdata = iio_priv(indio_dev);
205 int err;
206
207 /* Regulators not mandatory, but if requested we should enable them. */
208 pdata->vdd = devm_regulator_get_optional(indio_dev->dev.parent, "vdd");
209 if (!IS_ERR(pdata->vdd)) {
210 err = regulator_enable(pdata->vdd);
211 if (err != 0)
212 dev_warn(&indio_dev->dev,
213 "Failed to enable specified Vdd supply\n");
214 }
215
216 pdata->vdd_io = devm_regulator_get_optional(indio_dev->dev.parent, "vddio");
217 if (!IS_ERR(pdata->vdd_io)) {
218 err = regulator_enable(pdata->vdd_io);
219 if (err != 0)
220 dev_warn(&indio_dev->dev,
221 "Failed to enable specified Vdd_IO supply\n");
222 }
223}
224EXPORT_SYMBOL(st_sensors_power_enable);
225
226void st_sensors_power_disable(struct iio_dev *indio_dev)
227{
228 struct st_sensor_data *pdata = iio_priv(indio_dev);
229
230 if (!IS_ERR(pdata->vdd))
231 regulator_disable(pdata->vdd);
232
233 if (!IS_ERR(pdata->vdd_io))
234 regulator_disable(pdata->vdd_io);
235}
236EXPORT_SYMBOL(st_sensors_power_disable);
237
201static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev, 238static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev,
202 struct st_sensors_platform_data *pdata) 239 struct st_sensors_platform_data *pdata)
203{ 240{
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index bc71f4d1e2ce..ed74a9069989 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -311,6 +311,8 @@ int st_gyro_common_probe(struct iio_dev *indio_dev,
311 indio_dev->modes = INDIO_DIRECT_MODE; 311 indio_dev->modes = INDIO_DIRECT_MODE;
312 indio_dev->info = &gyro_info; 312 indio_dev->info = &gyro_info;
313 313
314 st_sensors_power_enable(indio_dev);
315
314 err = st_sensors_check_device_support(indio_dev, 316 err = st_sensors_check_device_support(indio_dev,
315 ARRAY_SIZE(st_gyro_sensors), st_gyro_sensors); 317 ARRAY_SIZE(st_gyro_sensors), st_gyro_sensors);
316 if (err < 0) 318 if (err < 0)
@@ -363,6 +365,8 @@ void st_gyro_common_remove(struct iio_dev *indio_dev)
363{ 365{
364 struct st_sensor_data *gdata = iio_priv(indio_dev); 366 struct st_sensor_data *gdata = iio_priv(indio_dev);
365 367
368 st_sensors_power_disable(indio_dev);
369
366 iio_device_unregister(indio_dev); 370 iio_device_unregister(indio_dev);
367 if (gdata->get_irq_data_ready(indio_dev) > 0) 371 if (gdata->get_irq_data_ready(indio_dev) > 0)
368 st_sensors_deallocate_trigger(indio_dev); 372 st_sensors_deallocate_trigger(indio_dev);
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 8e33a7682d33..240a21dd0c61 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -355,6 +355,8 @@ int st_magn_common_probe(struct iio_dev *indio_dev,
355 indio_dev->modes = INDIO_DIRECT_MODE; 355 indio_dev->modes = INDIO_DIRECT_MODE;
356 indio_dev->info = &magn_info; 356 indio_dev->info = &magn_info;
357 357
358 st_sensors_power_enable(indio_dev);
359
358 err = st_sensors_check_device_support(indio_dev, 360 err = st_sensors_check_device_support(indio_dev,
359 ARRAY_SIZE(st_magn_sensors), st_magn_sensors); 361 ARRAY_SIZE(st_magn_sensors), st_magn_sensors);
360 if (err < 0) 362 if (err < 0)
@@ -406,6 +408,8 @@ void st_magn_common_remove(struct iio_dev *indio_dev)
406{ 408{
407 struct st_sensor_data *mdata = iio_priv(indio_dev); 409 struct st_sensor_data *mdata = iio_priv(indio_dev);
408 410
411 st_sensors_power_disable(indio_dev);
412
409 iio_device_unregister(indio_dev); 413 iio_device_unregister(indio_dev);
410 if (mdata->get_irq_data_ready(indio_dev) > 0) 414 if (mdata->get_irq_data_ready(indio_dev) > 0)
411 st_sensors_deallocate_trigger(indio_dev); 415 st_sensors_deallocate_trigger(indio_dev);
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 013becbe8f47..cd7e01f3a93b 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -23,7 +23,6 @@
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>
27#include <asm/unaligned.h> 26#include <asm/unaligned.h>
28 27
29#include <linux/iio/common/st_sensors.h> 28#include <linux/iio/common/st_sensors.h>
@@ -387,40 +386,6 @@ static const struct iio_trigger_ops st_press_trigger_ops = {
387#define ST_PRESS_TRIGGER_OPS NULL 386#define ST_PRESS_TRIGGER_OPS NULL
388#endif 387#endif
389 388
390static void st_press_power_enable(struct iio_dev *indio_dev)
391{
392 struct st_sensor_data *pdata = iio_priv(indio_dev);
393 int err;
394
395 /* Regulators not mandatory, but if requested we should enable them. */
396 pdata->vdd = devm_regulator_get_optional(&indio_dev->dev, "vdd");
397 if (!IS_ERR(pdata->vdd)) {
398 err = regulator_enable(pdata->vdd);
399 if (err != 0)
400 dev_warn(&indio_dev->dev,
401 "Failed to enable specified Vdd supply\n");
402 }
403
404 pdata->vdd_io = devm_regulator_get_optional(&indio_dev->dev, "vddio");
405 if (!IS_ERR(pdata->vdd_io)) {
406 err = regulator_enable(pdata->vdd_io);
407 if (err != 0)
408 dev_warn(&indio_dev->dev,
409 "Failed to enable specified Vdd_IO supply\n");
410 }
411}
412
413static void st_press_power_disable(struct iio_dev *indio_dev)
414{
415 struct st_sensor_data *pdata = iio_priv(indio_dev);
416
417 if (!IS_ERR(pdata->vdd))
418 regulator_disable(pdata->vdd);
419
420 if (!IS_ERR(pdata->vdd_io))
421 regulator_disable(pdata->vdd_io);
422}
423
424int st_press_common_probe(struct iio_dev *indio_dev, 389int st_press_common_probe(struct iio_dev *indio_dev,
425 struct st_sensors_platform_data *plat_data) 390 struct st_sensors_platform_data *plat_data)
426{ 391{
@@ -431,7 +396,7 @@ int st_press_common_probe(struct iio_dev *indio_dev,
431 indio_dev->modes = INDIO_DIRECT_MODE; 396 indio_dev->modes = INDIO_DIRECT_MODE;
432 indio_dev->info = &press_info; 397 indio_dev->info = &press_info;
433 398
434 st_press_power_enable(indio_dev); 399 st_sensors_power_enable(indio_dev);
435 400
436 err = st_sensors_check_device_support(indio_dev, 401 err = st_sensors_check_device_support(indio_dev,
437 ARRAY_SIZE(st_press_sensors), 402 ARRAY_SIZE(st_press_sensors),
@@ -493,7 +458,7 @@ void st_press_common_remove(struct iio_dev *indio_dev)
493{ 458{
494 struct st_sensor_data *pdata = iio_priv(indio_dev); 459 struct st_sensor_data *pdata = iio_priv(indio_dev);
495 460
496 st_press_power_disable(indio_dev); 461 st_sensors_power_disable(indio_dev);
497 462
498 iio_device_unregister(indio_dev); 463 iio_device_unregister(indio_dev);
499 if (pdata->get_irq_data_ready(indio_dev) > 0) 464 if (pdata->get_irq_data_ready(indio_dev) > 0)
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index 3c005eb3a0a4..96f51f0e0096 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -269,6 +269,10 @@ int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable);
269 269
270int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable); 270int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable);
271 271
272void st_sensors_power_enable(struct iio_dev *indio_dev);
273
274void st_sensors_power_disable(struct iio_dev *indio_dev);
275
272int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr); 276int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr);
273 277
274int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable); 278int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable);