Skip to contentSkip to conversation

IIO: More devm_regulator[_bulk]_get_enable() users

PATCH In review Jonathan Cameron 7 participants 39 messages Oct 16, 2022 – Dec 4, 2022

Subsystems (5)
lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

cover IIO: More devm_regulator[_bulk]_get_enable() users

From: Jonathan Cameron <[email protected]>

Also one general devm conversion that was too easy to ignore after dealing with the regulators.

These new macros allow dropping of some boilerplate. They are not useful in many cases in IIO because they do not expose the struct regulator, however for simple drivers that just turn the power on at probe() they ensure that it is turned off again at remove.

Jonathan Cameron (14):
iio: accel: adxl367: Use devm_regulator_bulk_get_enable()
iio: accel: bma400: Use devm_regulator_bulk_get_enable()
iio: accel: fxls8962af: Use devm_regulator_get_enable()
iio: accel: kxcjk-1013: Use devm_regulator_bulk_get_enable()
iio: accel: msa311: Use devm_regulator_get_enable()
iio: cdc: ad7150: Use devm_regulator_get_enable()
iio: st_sensors: core and lsm9ds0 switch to
devm_regulator_bulk_get_enable()
iio: frequency: ad9523: Use devm_regulator_get_enable()
iio: humidity: hts211: Use devm_regulator_get_enable()
iio: light: ltr501: Use devm_regulator_bulk_get_enable()
iio: light: noa1305: Use devm_regulator_get_enable()
iio: proximity: sx_common: Use devm_regulator_bulk_get_enable()
iio: pressure: ms5611: Use devm_regulator_get_enable()
iio: pressure: ms5611: Switch to fully devm_ managed registration.

 drivers/iio/accel/adxl367.c                   | 28 ++------
 drivers/iio/accel/bma400.h                    |  4 --
 drivers/iio/accel/bma400_core.c               | 29 ++-------
 drivers/iio/accel/fxls8962af-core.c           | 24 +------
 drivers/iio/accel/kxcjk-1013.c                | 25 ++-----
 drivers/iio/accel/msa311.c                    | 21 +-----
 drivers/iio/cdc/ad7150.c                      | 18 +----
 .../iio/common/st_sensors/st_sensors_core.c   | 39 ++---------
 drivers/iio/frequency/ad9523.c                | 22 +------
 drivers/iio/humidity/hts221.h                 |  2 -
 drivers/iio/humidity/hts221_core.c            | 27 ++------
 drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_core.c  | 65 ++-----------------
 drivers/iio/light/ltr501.c                    | 27 ++------
 drivers/iio/light/noa1305.c                   | 26 +-------
 drivers/iio/pressure/ms5611.h                 |  4 --
 drivers/iio/pressure/ms5611_core.c            | 49 +++-----------
 drivers/iio/pressure/ms5611_i2c.c             |  6 --
 drivers/iio/pressure/ms5611_spi.c             |  6 --
 drivers/iio/proximity/sx_common.c             | 23 +------
 drivers/iio/proximity/sx_common.h             |  2 -
 include/linux/iio/common/st_sensors.h         |  4 --
 21 files changed, 57 insertions(+), 394 deletions(-)
Signature · 1 line
2.37.2
author maintainer
#1 lore raw

PATCH 1/14 iio: accel: adxl367: Use devm_regulator_bulk_get_enable()

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_bulk_get_enable() replaces this boilerplate code.

---
 drivers/iio/accel/adxl367.c | 28 ++++------------------------
 1 file changed, 4 insertions(+), 24 deletions(-)
drivers/iio/accel/adxl367.c +4 -24
index 47feb375b70b..d0a47ab9d82f 100644
@@ -160,8 +160,6 @@ struct adxl367_state {
 	struct device			*dev;
 	struct regmap			*regmap;
 
-	struct regulator_bulk_data	regulators[2];
-
 	/*
 	 * Synchronize access to members of driver state, and ensure atomicity
 	 * of consecutive regmap operations.
@@ -1474,16 +1472,10 @@ static int adxl367_setup(struct adxl367_state *st)
 	return adxl367_set_measure_en(st, true);
 }
 
-static void adxl367_disable_regulators(void *data)
-{
-	struct adxl367_state *st = data;
-
-	regulator_bulk_disable(ARRAY_SIZE(st->regulators), st->regulators);
-}
-
 int adxl367_probe(struct device *dev, const struct adxl367_ops *ops,
 		  void *context, struct regmap *regmap, int irq)
 {
+	static const char * const regulator_names[] = { "vdd", "vddio" };
 	struct iio_dev *indio_dev;
 	struct adxl367_state *st;
 	int ret;
@@ -1507,25 +1499,13 @@ int adxl367_probe(struct device *dev, const struct adxl367_ops *ops,
 	indio_dev->info = &adxl367_info;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
-	st->regulators[0].supply = "vdd";
-	st->regulators[1].supply = "vddio";
-
-	ret = devm_regulator_bulk_get(st->dev, ARRAY_SIZE(st->regulators),
-				      st->regulators);
+	ret = devm_regulator_bulk_get_enable(st->dev,
+					     ARRAY_SIZE(regulator_names),
+					     regulator_names);
 	if (ret)
 		return dev_err_probe(st->dev, ret,
 				     "Failed to get regulators\n");
 
-	ret = regulator_bulk_enable(ARRAY_SIZE(st->regulators), st->regulators);
-	if (ret)
-		return dev_err_probe(st->dev, ret,
-				     "Failed to enable regulators\n");
-
-	ret = devm_add_action_or_reset(st->dev, adxl367_disable_regulators, st);
-	if (ret)
-		return dev_err_probe(st->dev, ret,
-				     "Failed to add regulators disable action\n");
-
 	ret = regmap_write(st->regmap, ADXL367_REG_RESET, ADXL367_RESET_CODE);
 	if (ret)
 		return ret;
Signature · 1 line
2.37.2
author maintainer
#3 lore raw

PATCH 2/14 iio: accel: bma400: Use devm_regulator_bulk_get_enable()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_bulk_get_enable() replaces this boilerplate code.

---
 drivers/iio/accel/bma400.h      |  4 ----
 drivers/iio/accel/bma400_core.c | 29 ++++-------------------------
 2 files changed, 4 insertions(+), 29 deletions(-)
drivers/iio/accel/bma400.h +0 -4
index 36edbaff4f7f..932358b45f17 100644
@@ -141,10 +141,6 @@
 #define BMA400_SCALE_MIN            9577
 #define BMA400_SCALE_MAX            76617
 
-#define BMA400_NUM_REGULATORS       2
-#define BMA400_VDD_REGULATOR        0
-#define BMA400_VDDIO_REGULATOR      1
-
 extern const struct regmap_config bma400_regmap_config;
 
 int bma400_probe(struct device *dev, struct regmap *regmap, int irq,
drivers/iio/accel/bma400_core.c +4 -25
index e8de88e6cfb9..3ac464c1007c 100644
@@ -98,7 +98,6 @@ enum bma400_activity {
 struct bma400_data {
 	struct device *dev;
 	struct regmap *regmap;
-	struct regulator_bulk_data regulators[BMA400_NUM_REGULATORS];
 	struct mutex mutex; /* data register lock */
 	struct iio_mount_matrix orientation;
 	enum bma400_power_mode power_mode;
@@ -830,13 +829,6 @@ static void bma400_init_tables(void)
 	}
 }
 
-static void bma400_regulators_disable(void *data_ptr)
-{
-	struct bma400_data *data = data_ptr;
-
-	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
-}
-
 static void bma400_power_disable(void *data_ptr)
 {
 	struct bma400_data *data = data_ptr;
@@ -866,6 +858,7 @@ static enum iio_modifier bma400_act_to_mod(enum bma400_activity activity)
 
 static int bma400_init(struct bma400_data *data)
 {
+	static const char * const regulator_names[] = { "vdd", "vddio" };
 	unsigned int val;
 	int ret;
 
@@ -881,27 +874,13 @@ static int bma400_init(struct bma400_data *data)
 		return -ENODEV;
 	}
 
-	data->regulators[BMA400_VDD_REGULATOR].supply = "vdd";
-	data->regulators[BMA400_VDDIO_REGULATOR].supply = "vddio";
-	ret = devm_regulator_bulk_get(data->dev,
-				      ARRAY_SIZE(data->regulators),
-				      data->regulators);
+	ret = devm_regulator_bulk_get_enable(data->dev,
+					     ARRAY_SIZE(regulator_names),
+					     regulator_names);
 	if (ret)
 		return dev_err_probe(data->dev, ret, "Failed to get regulators: %d\n",
 				     ret);
 
-	ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators),
-				    data->regulators);
-	if (ret) {
-		dev_err(data->dev, "Failed to enable regulators: %d\n",
-			ret);
-		return ret;
-	}
-
-	ret = devm_add_action_or_reset(data->dev, bma400_regulators_disable, data);
-	if (ret)
-		return ret;
-
 	ret = bma400_get_power_mode(data);
 	if (ret) {
 		dev_err(data->dev, "Failed to get the initial power-mode\n");
Signature · 1 line
2.37.2
author maintainer
#6 lore raw

PATCH 3/14 iio: accel: fxls8962af: Use devm_regulator_get_enable()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code.

---
 drivers/iio/accel/fxls8962af-core.c | 24 +++---------------------
 1 file changed, 3 insertions(+), 21 deletions(-)
drivers/iio/accel/fxls8962af-core.c +3 -21
index bf259db281f5..0d672b1469e8 100644
@@ -159,7 +159,6 @@ struct fxls8962af_chip_info {
 struct fxls8962af_data {
 	struct regmap *regmap;
 	const struct fxls8962af_chip_info *chip_info;
-	struct regulator *vdd_reg;
 	struct {
 		__le16 channels[3];
 		s64 ts __aligned(8);
@@ -1051,13 +1050,6 @@ static irqreturn_t fxls8962af_interrupt(int irq, void *p)
 	return IRQ_NONE;
 }
 
-static void fxls8962af_regulator_disable(void *data_ptr)
-{
-	struct fxls8962af_data *data = data_ptr;
-
-	regulator_disable(data->vdd_reg);
-}
-
 static void fxls8962af_pm_disable(void *dev_ptr)
 {
 	struct device *dev = dev_ptr;
@@ -1171,20 +1163,10 @@ int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq)
 	if (ret)
 		return ret;
 
-	data->vdd_reg = devm_regulator_get(dev, "vdd");
-	if (IS_ERR(data->vdd_reg))
-		return dev_err_probe(dev, PTR_ERR(data->vdd_reg),
-				     "Failed to get vdd regulator\n");
-
-	ret = regulator_enable(data->vdd_reg);
-	if (ret) {
-		dev_err(dev, "Failed to enable vdd regulator: %d\n", ret);
-		return ret;
-	}
-
-	ret = devm_add_action_or_reset(dev, fxls8962af_regulator_disable, data);
+	ret = devm_regulator_get_enable(dev, "vdd");
 	if (ret)
-		return ret;
+		return dev_err_probe(dev, ret,
+				     "Failed to get vdd regulator\n");
 
 	ret = regmap_read(data->regmap, FXLS8962AF_WHO_AM_I, &reg);
 	if (ret)
Signature · 1 line
2.37.2
author maintainer
#9 lore raw

PATCH 4/14 iio: accel: kxcjk-1013: Use devm_regulator_bulk_get_enable()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_bulk_get_enable() replaces this boilerplate code.

---
 drivers/iio/accel/kxcjk-1013.c | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)
drivers/iio/accel/kxcjk-1013.c +4 -21
index adc66b3615c0..e626b6fa8a36 100644
@@ -241,7 +241,6 @@ enum kxcjk1013_axis {
 };
 
 struct kxcjk1013_data {
-	struct regulator_bulk_data regulators[2];
 	struct i2c_client *client;
 	struct iio_trigger *dready_trig;
 	struct iio_trigger *motion_trig;
@@ -1425,16 +1424,10 @@ static const char *kxcjk1013_match_acpi_device(struct device *dev,
 	return dev_name(dev);
 }
 
-static void kxcjk1013_disable_regulators(void *d)
-{
-	struct kxcjk1013_data *data = d;
-
-	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
-}
-
 static int kxcjk1013_probe(struct i2c_client *client,
 			   const struct i2c_device_id *id)
 {
+	static const char * const regulator_names[] = { "vdd", "vddio" };
 	struct kxcjk1013_data *data;
 	struct iio_dev *indio_dev;
 	struct kxcjk_1013_platform_data *pdata;
@@ -1461,22 +1454,12 @@ static int kxcjk1013_probe(struct i2c_client *client,
 			return ret;
 	}
 
-	data->regulators[0].supply = "vdd";
-	data->regulators[1].supply = "vddio";
-	ret = devm_regulator_bulk_get(&client->dev, ARRAY_SIZE(data->regulators),
-				      data->regulators);
+	ret = devm_regulator_bulk_get_enable(&client->dev,
+					     ARRAY_SIZE(regulator_names),
+					     regulator_names);
 	if (ret)
 		return dev_err_probe(&client->dev, ret, "Failed to get regulators\n");
 
-	ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators),
-				    data->regulators);
-	if (ret)
-		return ret;
-
-	ret = devm_add_action_or_reset(&client->dev, kxcjk1013_disable_regulators, data);
-	if (ret)
-		return ret;
-
 	/*
 	 * A typical delay of 10ms is required for powering up
 	 * according to the data sheets of supported chips.
Signature · 1 line
2.37.2
author maintainer
#11 lore raw

PATCH 5/14 iio: accel: msa311: Use devm_regulator_get_enable()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code.

---
 drivers/iio/accel/msa311.c | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)
drivers/iio/accel/msa311.c +2 -19
index 2fded3759171..af94d3adf6d8 100644
@@ -351,7 +351,6 @@ static const struct regmap_config msa311_regmap_config = {
  * @chip_name: Chip name in the format "msa311-%02x" % partid
  * @new_data_trig: Optional NEW_DATA interrupt driven trigger used
  *                 to notify external consumers a new sample is ready
- * @vdd: Optional external voltage regulator for the device power supply
  */
 struct msa311_priv {
 	struct regmap *regs;
@@ -362,7 +361,6 @@ struct msa311_priv {
 	char *chip_name;
 
 	struct iio_trigger *new_data_trig;
-	struct regulator *vdd;
 };
 
 enum msa311_si {
@@ -1146,11 +1144,6 @@ static void msa311_powerdown(void *msa311)
 	msa311_set_pwr_mode(msa311, MSA311_PWR_MODE_SUSPEND);
 }
 
-static void msa311_vdd_disable(void *vdd)
-{
-	regulator_disable(vdd);
-}
-
 static int msa311_probe(struct i2c_client *i2c)
 {
 	struct device *dev = &i2c->dev;
@@ -1173,19 +1166,9 @@ static int msa311_probe(struct i2c_client *i2c)
 
 	mutex_init(&msa311->lock);
 
-	msa311->vdd = devm_regulator_get(dev, "vdd");
-	if (IS_ERR(msa311->vdd))
-		return dev_err_probe(dev, PTR_ERR(msa311->vdd),
-				     "can't get vdd supply\n");
-
-	err = regulator_enable(msa311->vdd);
+	err = devm_regulator_get_enable(dev, "vdd");
 	if (err)
-		return dev_err_probe(dev, err, "can't enable vdd supply\n");
-
-	err = devm_add_action_or_reset(dev, msa311_vdd_disable, msa311->vdd);
-	if (err)
-		return dev_err_probe(dev, err,
-				     "can't add vdd disable action\n");
+		return dev_err_probe(dev, err, "can't get vdd supply\n");
 
 	err = msa311_check_partid(msa311);
 	if (err)
Signature · 1 line
2.37.2
author maintainer
#13 lore raw

PATCH 6/14 iio: cdc: ad7150: Use devm_regulator_get_enable()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code.

---
 drivers/iio/cdc/ad7150.c | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)
drivers/iio/cdc/ad7150.c +1 -17
index ebe112b4618b..1113745890ca 100644
@@ -536,19 +536,11 @@ static const struct iio_info ad7150_info_no_irq = {
 	.read_raw = &ad7150_read_raw,
 };
 
-static void ad7150_reg_disable(void *data)
-{
-	struct regulator *reg = data;
-
-	regulator_disable(reg);
-}
-
 static int ad7150_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
 	struct ad7150_chip_info *chip;
 	struct iio_dev *indio_dev;
-	struct regulator *reg;
 	int ret;
 
 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip));
@@ -563,15 +555,7 @@ static int ad7150_probe(struct i2c_client *client,
 
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
-	reg = devm_regulator_get(&client->dev, "vdd");
-	if (IS_ERR(reg))
-		return PTR_ERR(reg);
-
-	ret = regulator_enable(reg);
-	if (ret)
-		return ret;
-
-	ret = devm_add_action_or_reset(&client->dev, ad7150_reg_disable, reg);
+	ret = devm_regulator_get_enable(&client->dev, "vdd");
 	if (ret)
 		return ret;
 
Signature · 1 line
2.37.2
author maintainer
#15 lore raw

PATCH 7/14 iio: st_sensors: core and lsm9ds0 switch to devm_regulator_bulk_get_enable()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

These drivers only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The two regulators were handled separately so also switch to bulk registration.
The new devm_regulator_bulk_get_enable() replaces all this boilerplate code.

Cc Linus Walleij <[email protected]>
Cc Andy Shevchenko <[email protected]>

---

An alternative here would be to also refactor st_sensors_power_enable() to take the struct dev of the parent device (I2C or SPI).

Then we could use the same function for st_lsm9d0_probe(). My view is it isn't worth the churn.

---
 .../iio/common/st_sensors/st_sensors_core.c   | 39 ++---------
 drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_core.c  | 65 ++-----------------
 include/linux/iio/common/st_sensors.h         |  4 --
 3 files changed, 14 insertions(+), 94 deletions(-)
drivers/iio/common/st_sensors/st_sensors_core.c +7 -32
index 35720c64fea8..c77d7bdcc121 100644
@@ -219,47 +219,22 @@ int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable)
 }
 EXPORT_SYMBOL_NS(st_sensors_set_axis_enable, IIO_ST_SENSORS);
 
-static void st_reg_disable(void *reg)
-{
-	regulator_disable(reg);
-}
 
 int st_sensors_power_enable(struct iio_dev *indio_dev)
 {
-	struct st_sensor_data *pdata = iio_priv(indio_dev);
+	static const char * const regulator_names[] = { "vdd", "vddio" };
 	struct device *parent = indio_dev->dev.parent;
 	int err;
 
 	/* Regulators not mandatory, but if requested we should enable them. */
-	pdata->vdd = devm_regulator_get(parent, "vdd");
-	if (IS_ERR(pdata->vdd))
-		return dev_err_probe(&indio_dev->dev, PTR_ERR(pdata->vdd),
-				     "unable to get Vdd supply\n");
-
-	err = regulator_enable(pdata->vdd);
-	if (err != 0) {
-		dev_warn(&indio_dev->dev,
-			 "Failed to enable specified Vdd supply\n");
-		return err;
-	}
-
-	err = devm_add_action_or_reset(parent, st_reg_disable, pdata->vdd);
+	err = devm_regulator_bulk_get_enable(parent,
+					     ARRAY_SIZE(regulator_names),
+					     regulator_names);
 	if (err)
-		return err;
+		return dev_err_probe(&indio_dev->dev, err,
+				     "unable to enable supplies\n");
 
-	pdata->vdd_io = devm_regulator_get(parent, "vddio");
-	if (IS_ERR(pdata->vdd_io))
-		return dev_err_probe(&indio_dev->dev, PTR_ERR(pdata->vdd_io),
-				     "unable to get Vdd_IO supply\n");
-
-	err = regulator_enable(pdata->vdd_io);
-	if (err != 0) {
-		dev_warn(&indio_dev->dev,
-			 "Failed to enable specified Vdd_IO supply\n");
-		return err;
-	}
-
-	return devm_add_action_or_reset(parent, st_reg_disable, pdata->vdd_io);
+	return 0;
 }
 EXPORT_SYMBOL_NS(st_sensors_power_enable, IIO_ST_SENSORS);
 
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_core.c +7 -58

92 lines not on this page · raw message

include/linux/iio/common/st_sensors.h +0 -4
index db4a1b260348..f5f3ee57bc70 100644
@@ -224,8 +224,6 @@ struct st_sensor_settings {
  * @mount_matrix: The mounting matrix of the sensor.
  * @sensor_settings: Pointer to the specific sensor settings in use.
  * @current_fullscale: Maximum range of measure by the sensor.
- * @vdd: Pointer to sensor's Vdd power supply
- * @vdd_io: Pointer to sensor's Vdd-IO power supply
  * @regmap: Pointer to specific sensor regmap configuration.
  * @enabled: Status of the sensor (false->off, true->on).
  * @odr: Output data rate of the sensor [Hz].
@@ -244,8 +242,6 @@ struct st_sensor_data {
 	struct iio_mount_matrix mount_matrix;
 	struct st_sensor_settings *sensor_settings;
 	struct st_sensor_fullscale_avl *current_fullscale;
-	struct regulator *vdd;
-	struct regulator *vdd_io;
 	struct regmap *regmap;
 
 	bool enabled;
Signature · 1 line
2.37.2
author maintainer
#17 lore raw

PATCH 8/14 iio: frequency: ad9523: Use devm_regulator_get_enable()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code.

Note that in event of an error on the devm_regulator_get() the driver would have continued without enabling the regulator which is probably not a good idea. So here we handle any error as a reason to fail the probe(). In theory this may expose breakage on a platform that was previously papered over but it seems low risk.

Cc Michael Hennerich <[email protected]>
---
 drivers/iio/frequency/ad9523.c | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)
drivers/iio/frequency/ad9523.c +3 -19
index 97662ca1ca96..b391c6e27ab0 100644
@@ -265,7 +265,6 @@ enum {
 
 struct ad9523_state {
 	struct spi_device		*spi;
-	struct regulator		*reg;
 	struct ad9523_platform_data	*pdata;
 	struct iio_chan_spec		ad9523_channels[AD9523_NUM_CHAN];
 	struct gpio_desc		*pwrdown_gpio;
@@ -969,13 +968,6 @@ static int ad9523_setup(struct iio_dev *indio_dev)
 	return 0;
 }
 
-static void ad9523_reg_disable(void *data)
-{
-	struct regulator *reg = data;
-
-	regulator_disable(reg);
-}
-
 static int ad9523_probe(struct spi_device *spi)
 {
 	struct ad9523_platform_data *pdata = spi->dev.platform_data;
@@ -996,17 +988,9 @@ static int ad9523_probe(struct spi_device *spi)
 
 	mutex_init(&st->lock);
 
-	st->reg = devm_regulator_get(&spi->dev, "vcc");
-	if (!IS_ERR(st->reg)) {
-		ret = regulator_enable(st->reg);
-		if (ret)
-			return ret;
-
-		ret = devm_add_action_or_reset(&spi->dev, ad9523_reg_disable,
-					       st->reg);
-		if (ret)
-			return ret;
-	}
+	ret = devm_regulator_get_enable(&spi->dev, "vcc");
+	if (ret)
+		return ret;
 
 	st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown",
 		GPIOD_OUT_HIGH);
Signature · 1 line
2.37.2
author maintainer
#19 lore raw

PATCH 9/14 iio: humidity: hts211: Use devm_regulator_get_enable()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code.

---
 drivers/iio/humidity/hts221.h      |  2 --
 drivers/iio/humidity/hts221_core.c | 27 ++++-----------------------
 2 files changed, 4 insertions(+), 25 deletions(-)
drivers/iio/humidity/hts221.h +0 -2
index cf3d8d2dccd6..721359e226cb 100644
@@ -13,7 +13,6 @@
 #define HTS221_DEV_NAME		"hts221"
 
 #include <linux/iio/iio.h>
-#include <linux/regulator/consumer.h>
 
 enum hts221_sensor_type {
 	HTS221_SENSOR_H,
@@ -30,7 +29,6 @@ struct hts221_hw {
 	const char *name;
 	struct device *dev;
 	struct regmap *regmap;
-	struct regulator *vdd;
 
 	struct iio_trigger *trig;
 	int irq;
drivers/iio/humidity/hts221_core.c +4 -23
index 517158307d8c..2a413da87b76 100644
@@ -14,6 +14,7 @@
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 #include <linux/bitfield.h>
 
 #include "hts221.h"
@@ -549,33 +550,17 @@ static const unsigned long hts221_scan_masks[] = {0x3, 0x0};
 
 static int hts221_init_regulators(struct device *dev)
 {
-	struct iio_dev *iio_dev = dev_get_drvdata(dev);
-	struct hts221_hw *hw = iio_priv(iio_dev);
 	int err;
 
-	hw->vdd = devm_regulator_get(dev, "vdd");
-	if (IS_ERR(hw->vdd))
-		return dev_err_probe(dev, PTR_ERR(hw->vdd),
-				     "failed to get vdd regulator\n");
-
-	err = regulator_enable(hw->vdd);
-	if (err) {
-		dev_err(dev, "failed to enable vdd regulator: %d\n", err);
-		return err;
-	}
+	err = devm_regulator_get_enable(dev, "vdd");
+	if (err)
+		return dev_err_probe(dev, err, "failed to get vdd regulator\n");
 
 	msleep(50);
 
 	return 0;
 }
 
-static void hts221_chip_uninit(void *data)
-{
-	struct hts221_hw *hw = data;
-
-	regulator_disable(hw->vdd);
-}
-
 int hts221_probe(struct device *dev, int irq, const char *name,
 		 struct regmap *regmap)
 {
@@ -600,10 +585,6 @@ int hts221_probe(struct device *dev, int irq, const char *name,
 	if (err)
 		return err;
 
-	err = devm_add_action_or_reset(dev, hts221_chip_uninit, hw);
-	if (err)
-		return err;
-
 	err = hts221_check_whoami(hw);
 	if (err < 0)
 		return err;
Signature · 1 line
2.37.2
author maintainer
#22 lore raw

PATCH 10/14 iio: light: ltr501: Use devm_regulator_bulk_get_enable()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power for some regulators on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_bulk_get_enable() replaces all this boilerplate code.

---
 drivers/iio/light/ltr501.c | 27 ++++-----------------------
 1 file changed, 4 insertions(+), 23 deletions(-)
drivers/iio/light/ltr501.c +4 -23
index 74a1ccda8b9c..453b845ef265 100644
@@ -153,7 +153,6 @@ struct ltr501_chip_info {
 
 struct ltr501_data {
 	struct i2c_client *client;
-	struct regulator_bulk_data regulators[2];
 	struct mutex lock_als, lock_ps;
 	const struct ltr501_chip_info *chip_info;
 	u8 als_contr, ps_contr;
@@ -1415,13 +1414,6 @@ static const struct regmap_config ltr501_regmap_config = {
 	.volatile_reg = ltr501_is_volatile_reg,
 };
 
-static void ltr501_disable_regulators(void *d)
-{
-	struct ltr501_data *data = d;
-
-	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
-}
-
 static int ltr501_powerdown(struct ltr501_data *data)
 {
 	return ltr501_write_contr(data, data->als_contr &
@@ -1443,6 +1435,7 @@ static const char *ltr501_match_acpi_device(struct device *dev, int *chip_idx)
 static int ltr501_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
+	static const char * const regulator_names[] = { "vdd", "vddio" };
 	struct ltr501_data *data;
 	struct iio_dev *indio_dev;
 	struct regmap *regmap;
@@ -1466,25 +1459,13 @@ static int ltr501_probe(struct i2c_client *client,
 	mutex_init(&data->lock_als);
 	mutex_init(&data->lock_ps);
 
-	data->regulators[0].supply = "vdd";
-	data->regulators[1].supply = "vddio";
-	ret = devm_regulator_bulk_get(&client->dev,
-				      ARRAY_SIZE(data->regulators),
-				      data->regulators);
+	ret = devm_regulator_bulk_get_enable(&client->dev,
+					     ARRAY_SIZE(regulator_names),
+					     regulator_names);
 	if (ret)
 		return dev_err_probe(&client->dev, ret,
 				     "Failed to get regulators\n");
 
-	ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators),
-				    data->regulators);
-	if (ret)
-		return ret;
-
-	ret = devm_add_action_or_reset(&client->dev,
-				       ltr501_disable_regulators, data);
-	if (ret)
-		return ret;
-
 	data->reg_it = devm_regmap_field_alloc(&client->dev, regmap,
 					       reg_field_it);
 	if (IS_ERR(data->reg_it)) {
Signature · 1 line
2.37.2
author maintainer
#25 lore raw

PATCH 11/14 iio: light: noa1305: Use devm_regulator_get_enable()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code.

---
 drivers/iio/light/noa1305.c | 26 +++-----------------------
 1 file changed, 3 insertions(+), 23 deletions(-)
drivers/iio/light/noa1305.c +3 -23
index ee81fe083e4c..be3536b390fc 100644
@@ -46,7 +46,6 @@
 struct noa1305_priv {
 	struct i2c_client *client;
 	struct regmap *regmap;
-	struct regulator *vin_reg;
 };
 
 static int noa1305_measure(struct noa1305_priv *priv)
@@ -187,13 +186,6 @@ static const struct regmap_config noa1305_regmap_config = {
 	.writeable_reg = noa1305_writable_reg,
 };
 
-static void noa1305_reg_remove(void *data)
-{
-	struct noa1305_priv *priv = data;
-
-	regulator_disable(priv->vin_reg);
-}
-
 static int noa1305_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
@@ -216,23 +208,11 @@ static int noa1305_probe(struct i2c_client *client,
 
 	priv = iio_priv(indio_dev);
 
-	priv->vin_reg = devm_regulator_get(&client->dev, "vin");
-	if (IS_ERR(priv->vin_reg))
-		return dev_err_probe(&client->dev, PTR_ERR(priv->vin_reg),
+	ret = devm_regulator_get_enable(&client->dev, "vin");
+	if (ret)
+		return dev_err_probe(&client->dev, ret,
 				     "get regulator vin failed\n");
 
-	ret = regulator_enable(priv->vin_reg);
-	if (ret) {
-		dev_err(&client->dev, "enable regulator vin failed\n");
-		return ret;
-	}
-
-	ret = devm_add_action_or_reset(&client->dev, noa1305_reg_remove, priv);
-	if (ret) {
-		dev_err(&client->dev, "addition of devm action failed\n");
-		return ret;
-	}
-
 	i2c_set_clientdata(client, indio_dev);
 	priv->client = client;
 	priv->regmap = regmap;
Signature · 1 line
2.37.2
author maintainer
#27 lore raw

PATCH 12/14 iio: proximity: sx_common: Use devm_regulator_bulk_get_enable()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power for some regulators on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_bulk_get_enable() replaces all this boilerplate code.

Cc Gwendal Grignou <[email protected]>
Cc Stephen Boyd <[email protected]>
---
 drivers/iio/proximity/sx_common.c | 23 +++--------------------
 drivers/iio/proximity/sx_common.h |  2 --
 2 files changed, 3 insertions(+), 22 deletions(-)
drivers/iio/proximity/sx_common.c +3 -20
index d70a6b4f0bf8..eba9256730ec 100644
@@ -424,13 +424,6 @@ static const struct iio_buffer_setup_ops sx_common_buffer_setup_ops = {
 	.postdisable = sx_common_buffer_postdisable,
 };
 
-static void sx_common_regulator_disable(void *_data)
-{
-	struct sx_common_data *data = _data;
-
-	regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies);
-}
-
 #define SX_COMMON_SOFT_RESET				0xde
 
 static int sx_common_init_device(struct device *dev, struct iio_dev *indio_dev)
@@ -474,6 +467,7 @@ int sx_common_probe(struct i2c_client *client,
 		    const struct sx_common_chip_info *chip_info,
 		    const struct regmap_config *regmap_config)
 {
+	static const char * const regulator_names[] = { "vdd", "svdd" };
 	struct device *dev = &client->dev;
 	struct iio_dev *indio_dev;
 	struct sx_common_data *data;
@@ -487,8 +481,6 @@ int sx_common_probe(struct i2c_client *client,
 
 	data->chip_info = chip_info;
 	data->client = client;
-	data->supplies[0].supply = "vdd";
-	data->supplies[1].supply = "svdd";
 	mutex_init(&data->mutex);
 	init_completion(&data->completion);
 
@@ -497,23 +489,14 @@ int sx_common_probe(struct i2c_client *client,
 		return dev_err_probe(dev, PTR_ERR(data->regmap),
 				     "Could init register map\n");
 
-	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->supplies),
-				      data->supplies);
+	ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names),
+					     regulator_names);
 	if (ret)
 		return dev_err_probe(dev, ret, "Unable to get regulators\n");
 
-	ret = regulator_bulk_enable(ARRAY_SIZE(data->supplies), data->supplies);
-	if (ret)
-		return dev_err_probe(dev, ret, "Unable to enable regulators\n");
-
 	/* Must wait for Tpor time after initial power up */
 	usleep_range(1000, 1100);
 
-	ret = devm_add_action_or_reset(dev, sx_common_regulator_disable, data);
-	if (ret)
-		return dev_err_probe(dev, ret,
-				     "Unable to register regulators deleter\n");
-
 	ret = data->chip_info->ops.check_whoami(dev, indio_dev);
 	if (ret)
 		return dev_err_probe(dev, ret, "error reading WHOAMI\n");
drivers/iio/proximity/sx_common.h +0 -2
index 5d3edeb75f4e..49d4517103b0 100644
@@ -102,7 +102,6 @@ struct sx_common_chip_info {
  * @trig:		IIO trigger object.
  * @regmap:		Register map.
  * @num_default_regs:	Number of default registers to set at init.
- * @supplies:		Power supplies object.
  * @chan_prox_stat:	Last reading of the proximity status for each channel.
  *			We only send an event to user space when this changes.
  * @trigger_enabled:	True when the device trigger is enabled.
@@ -120,7 +119,6 @@ struct sx_common_data {
 	struct iio_trigger *trig;
 	struct regmap *regmap;
 
-	struct regulator_bulk_data supplies[2];
 	unsigned long chan_prox_stat;
 	bool trigger_enabled;
 
Signature · 1 line
2.37.2
author maintainer
#30 lore raw

PATCH 13/14 iio: pressure: ms5611: Use devm_regulator_get_enable()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code. Some additional refactoring to drop now unnecessary unwinding after this change.

---
 drivers/iio/pressure/ms5611.h      |  3 ---
 drivers/iio/pressure/ms5611_core.c | 32 +++++-------------------------
 2 files changed, 5 insertions(+), 30 deletions(-)
drivers/iio/pressure/ms5611.h +0 -3
index cbc9349c342a..816e83befd23 100644
@@ -13,8 +13,6 @@
 #include <linux/iio/iio.h>
 #include <linux/mutex.h>
 
-struct regulator;
-
 #define MS5611_RESET			0x1e
 #define MS5611_READ_ADC			0x00
 #define MS5611_READ_PROM_WORD		0xA0
@@ -56,7 +54,6 @@ struct ms5611_state {
 					  s32 *temp, s32 *pressure);
 
 	struct ms5611_chip_info *chip_info;
-	struct regulator *vdd;
 };
 
 int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
drivers/iio/pressure/ms5611_core.c +5 -27
index 717521de66c4..b95ee6034548 100644
@@ -390,40 +390,21 @@ static const struct iio_info ms5611_info = {
 static int ms5611_init(struct iio_dev *indio_dev)
 {
 	int ret;
-	struct ms5611_state *st = iio_priv(indio_dev);
 
 	/* Enable attached regulator if any. */
-	st->vdd = devm_regulator_get(indio_dev->dev.parent, "vdd");
-	if (IS_ERR(st->vdd))
-		return PTR_ERR(st->vdd);
-
-	ret = regulator_enable(st->vdd);
-	if (ret) {
-		dev_err(indio_dev->dev.parent,
-			"failed to enable Vdd supply: %d\n", ret);
+	ret = devm_regulator_get_enable(indio_dev->dev.parent, "vdd");
+	if (ret)
 		return ret;
-	}
 
 	ret = ms5611_reset(indio_dev);
 	if (ret < 0)
-		goto err_regulator_disable;
+		return ret;
 
 	ret = ms5611_read_prom(indio_dev);
 	if (ret < 0)
-		goto err_regulator_disable;
+		return ret;
 
 	return 0;
-
-err_regulator_disable:
-	regulator_disable(st->vdd);
-	return ret;
-}
-
-static void ms5611_fini(const struct iio_dev *indio_dev)
-{
-	const struct ms5611_state *st = iio_priv(indio_dev);
-
-	regulator_disable(st->vdd);
 }
 
 int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
@@ -454,7 +435,7 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
 					 ms5611_trigger_handler, NULL);
 	if (ret < 0) {
 		dev_err(dev, "iio triggered buffer setup failed\n");
-		goto err_fini;
+		return ret;
 	}
 
 	ret = iio_device_register(indio_dev);
@@ -467,8 +448,6 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
 
 err_buffer_cleanup:
 	iio_triggered_buffer_cleanup(indio_dev);
-err_fini:
-	ms5611_fini(indio_dev);
 	return ret;
 }
 EXPORT_SYMBOL_NS(ms5611_probe, IIO_MS5611);
@@ -477,7 +456,6 @@ void ms5611_remove(struct iio_dev *indio_dev)
 {
 	iio_device_unregister(indio_dev);
 	iio_triggered_buffer_cleanup(indio_dev);
-	ms5611_fini(indio_dev);
 }
 EXPORT_SYMBOL_NS(ms5611_remove, IIO_MS5611);
 
Signature · 1 line
2.37.2
author maintainer
#34 lore raw

PATCH 14/14 iio: pressure: ms5611: Switch to fully devm_ managed registration.

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

All the remaining calls in probe() have devm_ equivalents so switching to those allows the remove() callbacks to be deleted. No functional change.

---
 drivers/iio/pressure/ms5611.h      |  1 -
 drivers/iio/pressure/ms5611_core.c | 17 +++--------------
 drivers/iio/pressure/ms5611_i2c.c  |  6 ------
 drivers/iio/pressure/ms5611_spi.c  |  6 ------
 4 files changed, 3 insertions(+), 27 deletions(-)
drivers/iio/pressure/ms5611.h +0 -1
index 816e83befd23..f7066315fde3 100644
@@ -58,6 +58,5 @@ struct ms5611_state {
 
 int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
 		 const char *name, int type);
-void ms5611_remove(struct iio_dev *indio_dev);
 
 #endif /* _MS5611_H */
drivers/iio/pressure/ms5611_core.c +3 -14
index b95ee6034548..75a98470dcea 100644
@@ -431,34 +431,23 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
 	if (ret < 0)
 		return ret;
 
-	ret = iio_triggered_buffer_setup(indio_dev, NULL,
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
 					 ms5611_trigger_handler, NULL);
 	if (ret < 0) {
 		dev_err(dev, "iio triggered buffer setup failed\n");
 		return ret;
 	}
 
-	ret = iio_device_register(indio_dev);
+	ret = devm_iio_device_register(dev, indio_dev);
 	if (ret < 0) {
 		dev_err(dev, "unable to register iio device\n");
-		goto err_buffer_cleanup;
+		return ret;
 	}
 
 	return 0;
-
-err_buffer_cleanup:
-	iio_triggered_buffer_cleanup(indio_dev);
-	return ret;
 }
 EXPORT_SYMBOL_NS(ms5611_probe, IIO_MS5611);
 
-void ms5611_remove(struct iio_dev *indio_dev)
-{
-	iio_device_unregister(indio_dev);
-	iio_triggered_buffer_cleanup(indio_dev);
-}
-EXPORT_SYMBOL_NS(ms5611_remove, IIO_MS5611);
-
 MODULE_AUTHOR("Tomasz Duszynski <[email protected]>");
 MODULE_DESCRIPTION("MS5611 core driver");
 MODULE_LICENSE("GPL v2");
drivers/iio/pressure/ms5611_i2c.c +0 -6
index b681a4183909..2bab509a8c1d 100644
@@ -105,11 +105,6 @@ static int ms5611_i2c_probe(struct i2c_client *client,
 	return ms5611_probe(indio_dev, &client->dev, id->name, id->driver_data);
 }
 
-static void ms5611_i2c_remove(struct i2c_client *client)
-{
-	ms5611_remove(i2c_get_clientdata(client));
-}
-
 static const struct of_device_id ms5611_i2c_matches[] = {
 	{ .compatible = "meas,ms5611" },
 	{ .compatible = "meas,ms5607" },
@@ -131,7 +126,6 @@ static struct i2c_driver ms5611_driver = {
 	},
 	.id_table = ms5611_id,
 	.probe = ms5611_i2c_probe,
-	.remove = ms5611_i2c_remove,
 };
 module_i2c_driver(ms5611_driver);
 
drivers/iio/pressure/ms5611_spi.c +0 -6
index 432e912096f4..f0f5b46d8f9c 100644
@@ -107,11 +107,6 @@ static int ms5611_spi_probe(struct spi_device *spi)
 			    spi_get_device_id(spi)->driver_data);
 }
 
-static void ms5611_spi_remove(struct spi_device *spi)
-{
-	ms5611_remove(spi_get_drvdata(spi));
-}
-
 static const struct of_device_id ms5611_spi_matches[] = {
 	{ .compatible = "meas,ms5611" },
 	{ .compatible = "meas,ms5607" },
@@ -133,7 +128,6 @@ static struct spi_driver ms5611_driver = {
 	},
 	.id_table = ms5611_id,
 	.probe = ms5611_spi_probe,
-	.remove = ms5611_spi_remove,
 };
 module_spi_driver(ms5611_driver);
 
Signature · 1 line
2.37.2
Reviewed-by on v1 1/14
#2 lore raw

Re: [PATCH 01/14] iio: accel: adxl367: Use devm_regulator_bulk_get_enable()

In reply to Jonathan Cameron
Quoted 8 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_bulk_get_enable() replaces this boilerplate code.

Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
Reviewed-by on v1 6/14
#14 lore raw

Re: [PATCH 06/14] iio: cdc: ad7150: Use devm_regulator_get_enable()

In reply to Jonathan Cameron
Quoted 7 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code.

Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
Reviewed-by on v1 2/14
#4 lore raw

Re: [PATCH 02/14] iio: accel: bma400: Use devm_regulator_bulk_get_enable()

In reply to Jonathan Cameron
Quoted 8 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_bulk_get_enable() replaces this boilerplate code.

Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
Reviewed-by on v1 3/14
#7 lore raw

Re: [PATCH 03/14] iio: accel: fxls8962af: Use devm_regulator_get_enable()

In reply to Jonathan Cameron
Quoted 8 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code.

Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
Reviewed-by on v1 4/14
#10 lore raw

Re: [PATCH 04/14] iio: accel: kxcjk-1013: Use devm_regulator_bulk_get_enable()

In reply to Jonathan Cameron
Quoted 7 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_bulk_get_enable() replaces this boilerplate code.

Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
Reviewed-by on v1 7/14
#16 lore raw

Re: [PATCH 07/14] iio: st_sensors: core and lsm9ds0 switch to devm_regulator_bulk_get_enable()

In reply to Jonathan Cameron
Quoted 8 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

These drivers only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The two regulators were handled separately so also switch to bulk registration.
The new devm_regulator_bulk_get_enable() replaces all this boilerplate code.

Quoted 5 lines
Cc Linus Walleij <[email protected]>
Cc Andy Shevchenko <[email protected]>

---

I like this change. Especially since the st_sensors_power_enable() is exported. Looks much safer (to me) now.

Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
Reviewed-by on v1 8/14
#18 lore raw

Re: [PATCH 08/14] iio: frequency: ad9523: Use devm_regulator_get_enable()

In reply to Jonathan Cameron
Quoted 6 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code.

Quoted 8 lines

Note that in event of an error on the devm_regulator_get() the driver would have continued without enabling the regulator which is probably not a good idea. So here we handle any error as a reason to fail the probe(). In theory this may expose breakage on a platform that was previously papered over but it seems low risk.

Cc Michael Hennerich <[email protected]>
Quoted 3 lines
---
  drivers/iio/frequency/ad9523.c | 22 +++-------------------
  1 file changed, 3 insertions(+), 19 deletions(-)
Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
Reviewed-by on v1 9/14
#20 lore raw

Re: [PATCH 09/14] iio: humidity: hts211: Use devm_regulator_get_enable()

In reply to Jonathan Cameron
Quoted 8 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code.

Quoted 5 lines
---
  drivers/iio/humidity/hts221.h      |  2 --
  drivers/iio/humidity/hts221_core.c | 27 ++++-----------------------
  2 files changed, 4 insertions(+), 25 deletions(-)
Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
Reviewed-by on v1 10/14
#23 lore raw

Re: [PATCH 10/14] iio: light: ltr501: Use devm_regulator_bulk_get_enable()

In reply to Jonathan Cameron
Quoted 7 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power for some regulators on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_bulk_get_enable() replaces all this boilerplate code.

Quoted 3 lines
---
  drivers/iio/light/ltr501.c | 27 ++++-----------------------
  1 file changed, 4 insertions(+), 23 deletions(-)
Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
Reviewed-by on v1 10/14
#24 lore raw

Re: [PATCH 10/14] iio: light: ltr501: Use devm_regulator_bulk_get_enable()

In reply to Jonathan Cameron
Quoted 7 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power for some regulators on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_bulk_get_enable() replaces all this boilerplate code.

Quoted 4 lines
---
  drivers/iio/light/ltr501.c | 27 ++++-----------------------
  1 file changed, 4 insertions(+), 23 deletions(-)
Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
Reviewed-by on v1 11/14
#26 lore raw

Re: [PATCH 11/14] iio: light: noa1305: Use devm_regulator_get_enable()

In reply to Jonathan Cameron
Quoted 8 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code.

Quoted 4 lines
---
  drivers/iio/light/noa1305.c | 26 +++-----------------------
  1 file changed, 3 insertions(+), 23 deletions(-)
Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
Reviewed-by on v1 12/14
#28 lore raw

Re: [PATCH 12/14] iio: proximity: sx_common: Use devm_regulator_bulk_get_enable()

In reply to Jonathan Cameron
Quoted 9 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power for some regulators on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_bulk_get_enable() replaces all this boilerplate code.

Cc Gwendal Grignou <[email protected]>
Cc Stephen Boyd <[email protected]>
Quoted 5 lines
---
  drivers/iio/proximity/sx_common.c | 23 +++--------------------
  drivers/iio/proximity/sx_common.h |  2 --
  2 files changed, 3 insertions(+), 22 deletions(-)
Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
Reviewed-by on v1 13/14
#31 lore raw

Re: [PATCH 13/14] iio: pressure: ms5611: Use devm_regulator_get_enable()

In reply to Jonathan Cameron
Quoted 4 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback.

I think this one did not use devm_add_action_or_reset()

Quoted 11 lines

The new devm_regulator_get_enable()
replaces this boilerplate code. Some additional refactoring to drop now unnecessary unwinding after this change.

---
  drivers/iio/pressure/ms5611.h      |  3 ---
  drivers/iio/pressure/ms5611_core.c | 32 +++++-------------------------
  2 files changed, 5 insertions(+), 30 deletions(-)

// snip

drivers/iio/pressure/ms5611_core.c void ms5611_remove(struct iio_dev *indio_dev) · line 460

Quoted 7 lines
drivers/iio/pressure/ms5611_core.c +0 -1
@@ -477,7 +456,6 @@ void ms5611_remove(struct iio_dev *indio_dev)
  {
  	iio_device_unregister(indio_dev);
  	iio_triggered_buffer_cleanup(indio_dev);
-	ms5611_fini(indio_dev);
  }
  EXPORT_SYMBOL_NS(ms5611_remove, IIO_MS5611);

Just a thought but maybe the whole remove() could be done using devm()? (As far as I can say the current flow works. AFAICS the devm unwinding is done after the remove() has been ran. But perhaps it would be cleaner if the remove() would not need to be exported at all.)

With, or without the remove() removed, if commit description is fixed:

Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
Reviewed-by on v1 13/14
#32 lore raw

Re: [PATCH 13/14] iio: pressure: ms5611: Use devm_regulator_get_enable()

In reply to Jonathan Cameron
Quoted 4 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback.

I think this one did not use devm_add_action_or_reset()

Quoted 11 lines

The new devm_regulator_get_enable()
replaces this boilerplate code. Some additional refactoring to drop now unnecessary unwinding after this change.

---
  drivers/iio/pressure/ms5611.h      |  3 ---
  drivers/iio/pressure/ms5611_core.c | 32 +++++-------------------------
  2 files changed, 5 insertions(+), 30 deletions(-)

// snip

drivers/iio/pressure/ms5611_core.c void ms5611_remove(struct iio_dev *indio_dev) · line 460

Quoted 7 lines
drivers/iio/pressure/ms5611_core.c +0 -1
@@ -477,7 +456,6 @@ void ms5611_remove(struct iio_dev *indio_dev)
  {
  	iio_device_unregister(indio_dev);
  	iio_triggered_buffer_cleanup(indio_dev);
-	ms5611_fini(indio_dev);
  }
  EXPORT_SYMBOL_NS(ms5611_remove, IIO_MS5611);

Just a thought but maybe the whole remove() could be done using devm()? (As far as I can say the current flow works. AFAICS the devm unwinding is done after the remove() has been ran. But perhaps it would be cleaner if the remove() would not need to be exported at all.)

With, or without the remove() removed, if commit description is fixed:

Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
Reviewed-by on v1 14/14
#35 lore raw

Re: [PATCH 14/14] iio: pressure: ms5611: Switch to fully devm_ managed registration.

In reply to Jonathan Cameron
Quoted 5 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

All the remaining calls in probe() have devm_ equivalents so switching to those allows the remove() callbacks to be deleted. No functional change.

Right :) So please ignore my last comment in the patch 13/14 :) The one concerning the commit message is still valid though :)

Quoted 3 lines
Quoted 7 lines
---
  drivers/iio/pressure/ms5611.h      |  1 -
  drivers/iio/pressure/ms5611_core.c | 17 +++--------------
  drivers/iio/pressure/ms5611_i2c.c  |  6 ------
  drivers/iio/pressure/ms5611_spi.c  |  6 ------
  4 files changed, 3 insertions(+), 27 deletions(-)
Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
maintainer Acked-by on v1 9/14
#21 lore raw

Re: [PATCH 09/14] iio: humidity: hts211: Use devm_regulator_get_enable()

In reply to Jonathan Cameron
Quoted 8 lines

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code.

Quoted 88 lines
---
 drivers/iio/humidity/hts221.h      |  2 --
 drivers/iio/humidity/hts221_core.c | 27 ++++-----------------------
 2 files changed, 4 insertions(+), 25 deletions(-)
drivers/iio/humidity/hts221.h +0 -2
index cf3d8d2dccd6..721359e226cb 100644
@@ -13,7 +13,6 @@
 #define HTS221_DEV_NAME		"hts221"
 
 #include <linux/iio/iio.h>
-#include <linux/regulator/consumer.h>
 
 enum hts221_sensor_type {
 	HTS221_SENSOR_H,
@@ -30,7 +29,6 @@ struct hts221_hw {
 	const char *name;
 	struct device *dev;
 	struct regmap *regmap;
-	struct regulator *vdd;
 
 	struct iio_trigger *trig;
 	int irq;
drivers/iio/humidity/hts221_core.c +4 -23
index 517158307d8c..2a413da87b76 100644
@@ -14,6 +14,7 @@
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 #include <linux/bitfield.h>
 
 #include "hts221.h"
@@ -549,33 +550,17 @@ static const unsigned long hts221_scan_masks[] = {0x3, 0x0};
 
 static int hts221_init_regulators(struct device *dev)
 {
-	struct iio_dev *iio_dev = dev_get_drvdata(dev);
-	struct hts221_hw *hw = iio_priv(iio_dev);
 	int err;
 
-	hw->vdd = devm_regulator_get(dev, "vdd");
-	if (IS_ERR(hw->vdd))
-		return dev_err_probe(dev, PTR_ERR(hw->vdd),
-				     "failed to get vdd regulator\n");
-
-	err = regulator_enable(hw->vdd);
-	if (err) {
-		dev_err(dev, "failed to enable vdd regulator: %d\n", err);
-		return err;
-	}
+	err = devm_regulator_get_enable(dev, "vdd");
+	if (err)
+		return dev_err_probe(dev, err, "failed to get vdd regulator\n");
 
 	msleep(50);
 
 	return 0;
 }
 
-static void hts221_chip_uninit(void *data)
-{
-	struct hts221_hw *hw = data;
-
-	regulator_disable(hw->vdd);
-}
-
 int hts221_probe(struct device *dev, int irq, const char *name,
 		 struct regmap *regmap)
 {
@@ -600,10 +585,6 @@ int hts221_probe(struct device *dev, int irq, const char *name,
 	if (err)
 		return err;
 
-	err = devm_add_action_or_reset(dev, hts221_chip_uninit, hw);
-	if (err)
-		return err;
-
 	err = hts221_check_whoami(hw);
 	if (err < 0)
 		return err;
Signature · 1 line
2.37.2
Reviewed-by on v1 3/14
#8 lore raw

Re: [PATCH 03/14] iio: accel: fxls8962af: Use devm_regulator_get_enable()

In reply to Jonathan Cameron
Quoted 8 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code.

Quoted 57 lines
---
 drivers/iio/accel/fxls8962af-core.c | 24 +++---------------------
 1 file changed, 3 insertions(+), 21 deletions(-)
drivers/iio/accel/fxls8962af-core.c +3 -21
index bf259db281f5..0d672b1469e8 100644
@@ -159,7 +159,6 @@ struct fxls8962af_chip_info {
 struct fxls8962af_data {
 	struct regmap *regmap;
 	const struct fxls8962af_chip_info *chip_info;
-	struct regulator *vdd_reg;
 	struct {
 		__le16 channels[3];
 		s64 ts __aligned(8);
@@ -1051,13 +1050,6 @@ static irqreturn_t fxls8962af_interrupt(int irq, void *p)
 	return IRQ_NONE;
 }
 
-static void fxls8962af_regulator_disable(void *data_ptr)
-{
-	struct fxls8962af_data *data = data_ptr;
-
-	regulator_disable(data->vdd_reg);
-}
-
 static void fxls8962af_pm_disable(void *dev_ptr)
 {
 	struct device *dev = dev_ptr;
@@ -1171,20 +1163,10 @@ int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq)
 	if (ret)
 		return ret;
 
-	data->vdd_reg = devm_regulator_get(dev, "vdd");
-	if (IS_ERR(data->vdd_reg))
-		return dev_err_probe(dev, PTR_ERR(data->vdd_reg),
-				     "Failed to get vdd regulator\n");
-
-	ret = regulator_enable(data->vdd_reg);
-	if (ret) {
-		dev_err(dev, "Failed to enable vdd regulator: %d\n", ret);
-		return ret;
-	}
-
-	ret = devm_add_action_or_reset(dev, fxls8962af_regulator_disable, data);
+	ret = devm_regulator_get_enable(dev, "vdd");
 	if (ret)
-		return ret;
+		return dev_err_probe(dev, ret,
+				     "Failed to get vdd regulator\n");
 
 	ret = regmap_read(data->regmap, FXLS8962AF_WHO_AM_I, &reg);
 	if (ret)
Signature · 1 line
2.37.2
maintainer Reviewed-by on the v1 series
#37 lore raw
In reply to Jonathan Cameron
Quoted 72 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, October 16, 2022 6:34 PM
To: [email protected]
Cc: Matti Vaittinen <[email protected]>; Matti Vaittinen <[email protected]>; Tanislav, Cosmin <[email protected]>; Jagath Jog J <[email protected]>; Sean Nyekjaer <[email protected]>; Dmitry Rokosov <[email protected]>; Linus Walleij <[email protected]>; Andy Shevchenko <[email protected]>; Hennerich, Michael <[email protected]>; Lorenzo Bianconi <[email protected]>; Martyn Welch <[email protected]>; Gwendal Grignou <[email protected]>; Stephen Boyd <[email protected]>; Tomasz Duszynski <[email protected]>; Jonathan Cameron <[email protected]>
Subject: [PATCH 00/14] IIO: More devm_regulator[_bulk]_get_enable() users

[External]

From: Jonathan Cameron <[email protected]>

Also one general devm conversion that was too easy to ignore after dealing with the regulators.

These new macros allow dropping of some boilerplate. They are not useful in many cases in IIO because they do not expose the struct regulator, however for simple drivers that just turn the power on at probe() they ensure that it is turned off again at remove.

Jonathan Cameron (14):
iio: accel: adxl367: Use devm_regulator_bulk_get_enable()
iio: accel: bma400: Use devm_regulator_bulk_get_enable()
iio: accel: fxls8962af: Use devm_regulator_get_enable()
iio: accel: kxcjk-1013: Use devm_regulator_bulk_get_enable()
iio: accel: msa311: Use devm_regulator_get_enable()
iio: cdc: ad7150: Use devm_regulator_get_enable()
iio: st_sensors: core and lsm9ds0 switch to
devm_regulator_bulk_get_enable()
iio: frequency: ad9523: Use devm_regulator_get_enable()
iio: humidity: hts211: Use devm_regulator_get_enable()
iio: light: ltr501: Use devm_regulator_bulk_get_enable()
iio: light: noa1305: Use devm_regulator_get_enable()
iio: proximity: sx_common: Use devm_regulator_bulk_get_enable()
iio: pressure: ms5611: Use devm_regulator_get_enable()
iio: pressure: ms5611: Switch to fully devm_ managed registration.

 drivers/iio/accel/adxl367.c                   | 28 ++------
 drivers/iio/accel/bma400.h                    |  4 --
 drivers/iio/accel/bma400_core.c               | 29 ++-------
 drivers/iio/accel/fxls8962af-core.c           | 24 +------
 drivers/iio/accel/kxcjk-1013.c                | 25 ++-----
 drivers/iio/accel/msa311.c                    | 21 +-----
 drivers/iio/cdc/ad7150.c                      | 18 +----
 .../iio/common/st_sensors/st_sensors_core.c   | 39 ++---------
 drivers/iio/frequency/ad9523.c                | 22 +------
 drivers/iio/humidity/hts221.h                 |  2 -
 drivers/iio/humidity/hts221_core.c            | 27 ++------
 drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_core.c  | 65 ++-----------------
 drivers/iio/light/ltr501.c                    | 27 ++------
 drivers/iio/light/noa1305.c                   | 26 +-------
 drivers/iio/pressure/ms5611.h                 |  4 --
 drivers/iio/pressure/ms5611_core.c            | 49 +++-----------
 drivers/iio/pressure/ms5611_i2c.c             |  6 --
 drivers/iio/pressure/ms5611_spi.c             |  6 --
 drivers/iio/proximity/sx_common.c             | 23 +------
 drivers/iio/proximity/sx_common.h             |  2 -
 include/linux/iio/common/st_sensors.h         |  4 --
 21 files changed, 57 insertions(+), 394 deletions(-)
Quoted 2 lines

--
2.37.2

For all patches but patch 13/14,

For that one, you can add my tag after addressing Matti's comment.

- Nuno Sá

Reviewed-by on v1 5/14
#12 lore raw

Re: [PATCH 05/14] iio: accel: msa311: Use devm_regulator_get_enable()

In reply to Jonathan Cameron

Hello Jonathan,

Thank you for the patch! The current devm_regulator_get_enable() looks much easier to read!

Quoted 69 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_get_enable() replaces this boilerplate code.

---
 drivers/iio/accel/msa311.c | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)
drivers/iio/accel/msa311.c +2 -19
index 2fded3759171..af94d3adf6d8 100644
@@ -351,7 +351,6 @@ static const struct regmap_config msa311_regmap_config = {
  * @chip_name: Chip name in the format "msa311-%02x" % partid
  * @new_data_trig: Optional NEW_DATA interrupt driven trigger used
  *                 to notify external consumers a new sample is ready
- * @vdd: Optional external voltage regulator for the device power supply
  */
 struct msa311_priv {
 	struct regmap *regs;
@@ -362,7 +361,6 @@ struct msa311_priv {
 	char *chip_name;
 
 	struct iio_trigger *new_data_trig;
-	struct regulator *vdd;
 };
 
 enum msa311_si {
@@ -1146,11 +1144,6 @@ static void msa311_powerdown(void *msa311)
 	msa311_set_pwr_mode(msa311, MSA311_PWR_MODE_SUSPEND);
 }
 
-static void msa311_vdd_disable(void *vdd)
-{
-	regulator_disable(vdd);
-}
-
 static int msa311_probe(struct i2c_client *i2c)
 {
 	struct device *dev = &i2c->dev;
@@ -1173,19 +1166,9 @@ static int msa311_probe(struct i2c_client *i2c)
 
 	mutex_init(&msa311->lock);
 
-	msa311->vdd = devm_regulator_get(dev, "vdd");
-	if (IS_ERR(msa311->vdd))
-		return dev_err_probe(dev, PTR_ERR(msa311->vdd),
-				     "can't get vdd supply\n");
-
-	err = regulator_enable(msa311->vdd);
+	err = devm_regulator_get_enable(dev, "vdd");
 	if (err)
-		return dev_err_probe(dev, err, "can't enable vdd supply\n");
-
-	err = devm_add_action_or_reset(dev, msa311_vdd_disable, msa311->vdd);
-	if (err)
-		return dev_err_probe(dev, err,
-				     "can't add vdd disable action\n");
+		return dev_err_probe(dev, err, "can't get vdd supply\n");
 
 	err = msa311_check_partid(msa311);
 	if (err)
Signature · 1 line
2.37.2
Signature · 2 lines
Thank you,
Dmitry
Reviewed-by on v1 12/14
#29 lore raw

Re: [PATCH 12/14] iio: proximity: sx_common: Use devm_regulator_bulk_get_enable()

In reply to Jonathan Cameron

Quoting Jonathan Cameron (2022-10-16 09:34:07)

Quoted 10 lines

From: Jonathan Cameron <[email protected]>

This driver only turns the power for some regulators on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_bulk_get_enable() replaces all this boilerplate code.

Cc Gwendal Grignou <[email protected]>
Cc Stephen Boyd <[email protected]>

---

author maintainer
#38 lore raw
In reply to Sa, Nuno
Quoted 70 lines · Nuno
Quoted 70 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, October 16, 2022 6:34 PM
To: [email protected]
Cc: Matti Vaittinen <[email protected]>; Matti Vaittinen <[email protected]>; Tanislav, Cosmin <[email protected]>; Jagath Jog J <[email protected]>; Sean Nyekjaer <[email protected]>; Dmitry Rokosov <[email protected]>; Linus Walleij <[email protected]>; Andy Shevchenko <[email protected]>; Hennerich, Michael <[email protected]>; Lorenzo Bianconi <[email protected]>; Martyn Welch <[email protected]>; Gwendal Grignou <[email protected]>; Stephen Boyd <[email protected]>; Tomasz Duszynski <[email protected]>; Jonathan Cameron <[email protected]>
Subject: [PATCH 00/14] IIO: More devm_regulator[_bulk]_get_enable() users

[External]

From: Jonathan Cameron <[email protected]>

Also one general devm conversion that was too easy to ignore after dealing with the regulators.

These new macros allow dropping of some boilerplate. They are not useful in many cases in IIO because they do not expose the struct regulator, however for simple drivers that just turn the power on at probe() they ensure that it is turned off again at remove.

Jonathan Cameron (14):
iio: accel: adxl367: Use devm_regulator_bulk_get_enable()
iio: accel: bma400: Use devm_regulator_bulk_get_enable()
iio: accel: fxls8962af: Use devm_regulator_get_enable()
iio: accel: kxcjk-1013: Use devm_regulator_bulk_get_enable()
iio: accel: msa311: Use devm_regulator_get_enable()
iio: cdc: ad7150: Use devm_regulator_get_enable()
iio: st_sensors: core and lsm9ds0 switch to
devm_regulator_bulk_get_enable()
iio: frequency: ad9523: Use devm_regulator_get_enable()
iio: humidity: hts211: Use devm_regulator_get_enable()
iio: light: ltr501: Use devm_regulator_bulk_get_enable()
iio: light: noa1305: Use devm_regulator_get_enable()
iio: proximity: sx_common: Use devm_regulator_bulk_get_enable()
iio: pressure: ms5611: Use devm_regulator_get_enable()
iio: pressure: ms5611: Switch to fully devm_ managed registration.

 drivers/iio/accel/adxl367.c                   | 28 ++------
 drivers/iio/accel/bma400.h                    |  4 --
 drivers/iio/accel/bma400_core.c               | 29 ++-------
 drivers/iio/accel/fxls8962af-core.c           | 24 +------
 drivers/iio/accel/kxcjk-1013.c                | 25 ++-----
 drivers/iio/accel/msa311.c                    | 21 +-----
 drivers/iio/cdc/ad7150.c                      | 18 +----
 .../iio/common/st_sensors/st_sensors_core.c   | 39 ++---------
 drivers/iio/frequency/ad9523.c                | 22 +------
 drivers/iio/humidity/hts221.h                 |  2 -
 drivers/iio/humidity/hts221_core.c            | 27 ++------
 drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_core.c  | 65 ++-----------------
 drivers/iio/light/ltr501.c                    | 27 ++------
 drivers/iio/light/noa1305.c                   | 26 +-------
 drivers/iio/pressure/ms5611.h                 |  4 --
 drivers/iio/pressure/ms5611_core.c            | 49 +++-----------
 drivers/iio/pressure/ms5611_i2c.c             |  6 --
 drivers/iio/pressure/ms5611_spi.c             |  6 --
 drivers/iio/proximity/sx_common.c             | 23 +------
 drivers/iio/proximity/sx_common.h             |  2 -
 include/linux/iio/common/st_sensors.h         |  4 --
 21 files changed, 57 insertions(+), 394 deletions(-)
Quoted 8 lines
Quoted 2 lines

--
2.37.2

For all patches but patch 13/14,

For that one, you can add my tag after addressing Matti's comment.

Tweaked the patch description on that one. The other comment is covered in patch 14 as Matti observed in response to that one.

Applied to the togreg branch of iio.git and pushed out as testing.

Thanks,

Jonathan

Quoted 2 lines

- Nuno Sá

author maintainer
#5 lore raw

Re: [PATCH 02/14] iio: accel: bma400: Use devm_regulator_bulk_get_enable()

In reply to Matti Vaittinen
Quoted 12 lines · On Mon, 17 Oct 2022 08:27:29 +0300 Matti Vaittinen <[email protected]>…
Quoted 8 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_bulk_get_enable() replaces this boilerplate code.

Now applied this one with slight fuzz due to the fix on ordering that crossed with this.

Jonathan

author maintainer
#33 lore raw

Re: [PATCH 13/14] iio: pressure: ms5611: Use devm_regulator_get_enable()

In reply to Matti Vaittinen
Quoted 7 lines · On Mon, 17 Oct 2022 09:26:15 +0300 Matti Vaittinen <[email protected]>…
Quoted 4 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This driver only turns the power on at probe and off via a custom devm_add_action_or_reset() callback.

I think this one did not use devm_add_action_or_reset()

The other changes hitting this driver are now upstream so applied to the togreg branch of iio.git with a bit of fuzz.

Thanks,

Jonathan

Quoted 31 lines
Quoted 5 lines

The new devm_regulator_get_enable()
replaces this boilerplate code. Some additional refactoring to drop now unnecessary unwinding after this change.

Quoted 7 lines
---
  drivers/iio/pressure/ms5611.h      |  3 ---
  drivers/iio/pressure/ms5611_core.c | 32 +++++-------------------------
  2 files changed, 5 insertions(+), 30 deletions(-)

// snip

drivers/iio/pressure/ms5611_core.c void ms5611_remove(struct iio_dev *indio_dev) · line 460

Quoted 7 lines
drivers/iio/pressure/ms5611_core.c +0 -1
@@ -477,7 +456,6 @@ void ms5611_remove(struct iio_dev *indio_dev)
  {
  	iio_device_unregister(indio_dev);
  	iio_triggered_buffer_cleanup(indio_dev);
-	ms5611_fini(indio_dev);
  }
  EXPORT_SYMBOL_NS(ms5611_remove, IIO_MS5611);  

Just a thought but maybe the whole remove() could be done using devm()? (As far as I can say the current flow works. AFAICS the devm unwinding is done after the remove() has been ran. But perhaps it would be cleaner if the remove() would not need to be exported at all.)

With, or without the remove() removed, if commit description is fixed:

author maintainer Applied
#36 lore raw

Re: [PATCH 14/14] iio: pressure: ms5611: Switch to fully devm_ managed registration.

In reply to Matti Vaittinen
Quoted 7 lines · On Mon, 17 Oct 2022 09:30:01 +0300 Matti Vaittinen <[email protected]>…
Quoted 5 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

All the remaining calls in probe() have devm_ equivalents so switching to those allows the remove() callbacks to be deleted. No functional change.

Quoted 8 lines

Right :) So please ignore my last comment in the patch 13/14 :) The one concerning the commit message is still valid though :)

Quoted 3 lines

Applied to the togreg branch of iio.git - some fuzz due to crossing with i2c probe_new() mass conversion and the changes that affected the previous patch.

If anyone wants to sanity check the result, see the testing branch of iio.git in a few minutes.

Thanks,

Jonathan

Quoted 9 lines
Quoted 8 lines
---
  drivers/iio/pressure/ms5611.h      |  1 -
  drivers/iio/pressure/ms5611_core.c | 17 +++--------------
  drivers/iio/pressure/ms5611_i2c.c  |  6 ------
  drivers/iio/pressure/ms5611_spi.c  |  6 ------
  4 files changed, 3 insertions(+), 27 deletions(-)