Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Matti Vaittinen <mazziesaccount@gmail.com>
Link: https://lore.kernel.org/r/876e58428cec056d51070e49eff559e2d7c23b12.1660934107.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Matti Vaittinen and committed by
Jonathan Cameron
6900cdbf 2c620883

+5 -27
-2
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
··· 374 374 * struct st_lsm6dsx_hw - ST IMU MEMS hw instance 375 375 * @dev: Pointer to instance of struct device (I2C or SPI). 376 376 * @regmap: Register map of the device. 377 - * @regulators: VDD/VDDIO voltage regulators. 378 377 * @irq: Device interrupt line (I2C or SPI). 379 378 * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO. 380 379 * @conf_lock: Mutex to prevent concurrent FIFO configuration update. ··· 396 397 struct st_lsm6dsx_hw { 397 398 struct device *dev; 398 399 struct regmap *regmap; 399 - struct regulator_bulk_data regulators[2]; 400 400 int irq; 401 401 402 402 struct mutex fifo_lock;
+5 -25
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
··· 2177 2177 2178 2178 static int st_lsm6dsx_init_regulators(struct device *dev) 2179 2179 { 2180 - struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev); 2180 + /* vdd-vddio power regulators */ 2181 + static const char * const regulators[] = { "vdd", "vddio" }; 2181 2182 int err; 2182 2183 2183 - /* vdd-vddio power regulators */ 2184 - hw->regulators[0].supply = "vdd"; 2185 - hw->regulators[1].supply = "vddio"; 2186 - err = devm_regulator_bulk_get(dev, ARRAY_SIZE(hw->regulators), 2187 - hw->regulators); 2184 + err = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators), 2185 + regulators); 2188 2186 if (err) 2189 - return dev_err_probe(dev, err, "failed to get regulators\n"); 2190 - 2191 - err = regulator_bulk_enable(ARRAY_SIZE(hw->regulators), 2192 - hw->regulators); 2193 - if (err) { 2194 - dev_err(dev, "failed to enable regulators: %d\n", err); 2195 - return err; 2196 - } 2187 + return dev_err_probe(dev, err, "failed to enable regulators\n"); 2197 2188 2198 2189 msleep(50); 2199 2190 2200 2191 return 0; 2201 - } 2202 - 2203 - static void st_lsm6dsx_chip_uninit(void *data) 2204 - { 2205 - struct st_lsm6dsx_hw *hw = data; 2206 - 2207 - regulator_bulk_disable(ARRAY_SIZE(hw->regulators), hw->regulators); 2208 2192 } 2209 2193 2210 2194 int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, ··· 2211 2227 mutex_init(&hw->page_lock); 2212 2228 2213 2229 err = st_lsm6dsx_init_regulators(dev); 2214 - if (err) 2215 - return err; 2216 - 2217 - err = devm_add_action_or_reset(dev, st_lsm6dsx_chip_uninit, hw); 2218 2230 if (err) 2219 2231 return err; 2220 2232