Commit 6900cdbf authored by Matti Vaittinen's avatar Matti Vaittinen Committed by Jonathan Cameron

iio: imu: st_lsm6dsx: Simplify using devm_regulator_*get_enable()

Use devm_regulator_bulk_get_enable() instead of open coded bulk-get,
bulk-enable, add-action-to-disable-at-detach - pattern.

A functional change (which seems like a bugfix) is that if
regulator_bulk_get fails, the enable is not attempted.
Signed-off-by: default avatarMatti Vaittinen <mazziesaccount@gmail.com>
Link: https://lore.kernel.org/r/876e58428cec056d51070e49eff559e2d7c23b12.1660934107.git.mazziesaccount@gmail.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 2c620883
...@@ -374,7 +374,6 @@ struct st_lsm6dsx_sensor { ...@@ -374,7 +374,6 @@ struct st_lsm6dsx_sensor {
* struct st_lsm6dsx_hw - ST IMU MEMS hw instance * struct st_lsm6dsx_hw - ST IMU MEMS hw instance
* @dev: Pointer to instance of struct device (I2C or SPI). * @dev: Pointer to instance of struct device (I2C or SPI).
* @regmap: Register map of the device. * @regmap: Register map of the device.
* @regulators: VDD/VDDIO voltage regulators.
* @irq: Device interrupt line (I2C or SPI). * @irq: Device interrupt line (I2C or SPI).
* @fifo_lock: Mutex to prevent concurrent access to the hw FIFO. * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO.
* @conf_lock: Mutex to prevent concurrent FIFO configuration update. * @conf_lock: Mutex to prevent concurrent FIFO configuration update.
...@@ -397,7 +396,6 @@ struct st_lsm6dsx_sensor { ...@@ -397,7 +396,6 @@ struct st_lsm6dsx_sensor {
struct st_lsm6dsx_hw { struct st_lsm6dsx_hw {
struct device *dev; struct device *dev;
struct regmap *regmap; struct regmap *regmap;
struct regulator_bulk_data regulators[2];
int irq; int irq;
struct mutex fifo_lock; struct mutex fifo_lock;
......
...@@ -2177,36 +2177,20 @@ static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw) ...@@ -2177,36 +2177,20 @@ static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
static int st_lsm6dsx_init_regulators(struct device *dev) static int st_lsm6dsx_init_regulators(struct device *dev)
{ {
struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev); /* vdd-vddio power regulators */
static const char * const regulators[] = { "vdd", "vddio" };
int err; int err;
/* vdd-vddio power regulators */ err = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators),
hw->regulators[0].supply = "vdd"; regulators);
hw->regulators[1].supply = "vddio";
err = devm_regulator_bulk_get(dev, ARRAY_SIZE(hw->regulators),
hw->regulators);
if (err) if (err)
return dev_err_probe(dev, err, "failed to get regulators\n"); return dev_err_probe(dev, err, "failed to enable regulators\n");
err = regulator_bulk_enable(ARRAY_SIZE(hw->regulators),
hw->regulators);
if (err) {
dev_err(dev, "failed to enable regulators: %d\n", err);
return err;
}
msleep(50); msleep(50);
return 0; return 0;
} }
static void st_lsm6dsx_chip_uninit(void *data)
{
struct st_lsm6dsx_hw *hw = data;
regulator_bulk_disable(ARRAY_SIZE(hw->regulators), hw->regulators);
}
int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
struct regmap *regmap) struct regmap *regmap)
{ {
...@@ -2230,10 +2214,6 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, ...@@ -2230,10 +2214,6 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
if (err) if (err)
return err; return err;
err = devm_add_action_or_reset(dev, st_lsm6dsx_chip_uninit, hw);
if (err)
return err;
hw->buff = devm_kzalloc(dev, ST_LSM6DSX_BUFF_SIZE, GFP_KERNEL); hw->buff = devm_kzalloc(dev, ST_LSM6DSX_BUFF_SIZE, GFP_KERNEL);
if (!hw->buff) if (!hw->buff)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment