Skip to content

Commit ea7e586

Browse files
Linus Walleijjic23
authored andcommitted
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>
1 parent 4f544ce commit ea7e586

6 files changed

Lines changed: 55 additions & 37 deletions

File tree

‎drivers/iio/accel/st_accel_core.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ int st_accel_common_probe(struct iio_dev *indio_dev,
459459
indio_dev->modes = INDIO_DIRECT_MODE;
460460
indio_dev->info = &accel_info;
461461

462+
st_sensors_power_enable(indio_dev);
463+
462464
err = st_sensors_check_device_support(indio_dev,
463465
ARRAY_SIZE(st_accel_sensors), st_accel_sensors);
464466
if (err < 0)
@@ -515,6 +517,8 @@ void st_accel_common_remove(struct iio_dev *indio_dev)
515517
{
516518
struct st_sensor_data *adata = iio_priv(indio_dev);
517519

520+
st_sensors_power_disable(indio_dev);
521+
518522
iio_device_unregister(indio_dev);
519523
if (adata->get_irq_data_ready(indio_dev) > 0)
520524
st_sensors_deallocate_trigger(indio_dev);

‎drivers/iio/common/st_sensors/st_sensors_core.c‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/slab.h>
1414
#include <linux/delay.h>
1515
#include <linux/iio/iio.h>
16+
#include <linux/regulator/consumer.h>
1617
#include <asm/unaligned.h>
1718

1819
#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)
198199
}
199200
EXPORT_SYMBOL(st_sensors_set_axis_enable);
200201

202+
void 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+
}
224+
EXPORT_SYMBOL(st_sensors_power_enable);
225+
226+
void 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+
}
236+
EXPORT_SYMBOL(st_sensors_power_disable);
237+
201238
static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev,
202239
struct st_sensors_platform_data *pdata)
203240
{

‎drivers/iio/gyro/st_gyro_core.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ int st_gyro_common_probe(struct iio_dev *indio_dev,
311311
indio_dev->modes = INDIO_DIRECT_MODE;
312312
indio_dev->info = &gyro_info;
313313

314+
st_sensors_power_enable(indio_dev);
315+
314316
err = st_sensors_check_device_support(indio_dev,
315317
ARRAY_SIZE(st_gyro_sensors), st_gyro_sensors);
316318
if (err < 0)
@@ -363,6 +365,8 @@ void st_gyro_common_remove(struct iio_dev *indio_dev)
363365
{
364366
struct st_sensor_data *gdata = iio_priv(indio_dev);
365367

368+
st_sensors_power_disable(indio_dev);
369+
366370
iio_device_unregister(indio_dev);
367371
if (gdata->get_irq_data_ready(indio_dev) > 0)
368372
st_sensors_deallocate_trigger(indio_dev);

‎drivers/iio/magnetometer/st_magn_core.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ int st_magn_common_probe(struct iio_dev *indio_dev,
355355
indio_dev->modes = INDIO_DIRECT_MODE;
356356
indio_dev->info = &magn_info;
357357

358+
st_sensors_power_enable(indio_dev);
359+
358360
err = st_sensors_check_device_support(indio_dev,
359361
ARRAY_SIZE(st_magn_sensors), st_magn_sensors);
360362
if (err < 0)
@@ -406,6 +408,8 @@ void st_magn_common_remove(struct iio_dev *indio_dev)
406408
{
407409
struct st_sensor_data *mdata = iio_priv(indio_dev);
408410

411+
st_sensors_power_disable(indio_dev);
412+
409413
iio_device_unregister(indio_dev);
410414
if (mdata->get_irq_data_ready(indio_dev) > 0)
411415
st_sensors_deallocate_trigger(indio_dev);

‎drivers/iio/pressure/st_pressure_core.c‎

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <linux/iio/sysfs.h>
2424
#include <linux/iio/trigger.h>
2525
#include <linux/iio/buffer.h>
26-
#include <linux/regulator/consumer.h>
2726
#include <asm/unaligned.h>
2827

2928
#include <linux/iio/common/st_sensors.h>
@@ -387,40 +386,6 @@ static const struct iio_trigger_ops st_press_trigger_ops = {
387386
#define ST_PRESS_TRIGGER_OPS NULL
388387
#endif
389388

390-
static 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-
413-
static 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-
424389
int st_press_common_probe(struct iio_dev *indio_dev,
425390
struct st_sensors_platform_data *plat_data)
426391
{
@@ -431,7 +396,7 @@ int st_press_common_probe(struct iio_dev *indio_dev,
431396
indio_dev->modes = INDIO_DIRECT_MODE;
432397
indio_dev->info = &press_info;
433398

434-
st_press_power_enable(indio_dev);
399+
st_sensors_power_enable(indio_dev);
435400

436401
err = st_sensors_check_device_support(indio_dev,
437402
ARRAY_SIZE(st_press_sensors),
@@ -493,7 +458,7 @@ void st_press_common_remove(struct iio_dev *indio_dev)
493458
{
494459
struct st_sensor_data *pdata = iio_priv(indio_dev);
495460

496-
st_press_power_disable(indio_dev);
461+
st_sensors_power_disable(indio_dev);
497462

498463
iio_device_unregister(indio_dev);
499464
if (pdata->get_irq_data_ready(indio_dev) > 0)

‎include/linux/iio/common/st_sensors.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable);
269269

270270
int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable);
271271

272+
void st_sensors_power_enable(struct iio_dev *indio_dev);
273+
274+
void st_sensors_power_disable(struct iio_dev *indio_dev);
275+
272276
int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr);
273277

274278
int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable);

0 commit comments

Comments
 (0)