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

iio: humidity: hts211: Use devm_regulator_get_enable()

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.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20221016163409.320197-10-jic23@kernel.org

+4 -25
-2
drivers/iio/humidity/hts221.h
··· 13 13 #define HTS221_DEV_NAME "hts221" 14 14 15 15 #include <linux/iio/iio.h> 16 - #include <linux/regulator/consumer.h> 17 16 18 17 enum hts221_sensor_type { 19 18 HTS221_SENSOR_H, ··· 29 30 const char *name; 30 31 struct device *dev; 31 32 struct regmap *regmap; 32 - struct regulator *vdd; 33 33 34 34 struct iio_trigger *trig; 35 35 int irq;
+4 -23
drivers/iio/humidity/hts221_core.c
··· 14 14 #include <linux/delay.h> 15 15 #include <linux/pm.h> 16 16 #include <linux/regmap.h> 17 + #include <linux/regulator/consumer.h> 17 18 #include <linux/bitfield.h> 18 19 19 20 #include "hts221.h" ··· 550 549 551 550 static int hts221_init_regulators(struct device *dev) 552 551 { 553 - struct iio_dev *iio_dev = dev_get_drvdata(dev); 554 - struct hts221_hw *hw = iio_priv(iio_dev); 555 552 int err; 556 553 557 - hw->vdd = devm_regulator_get(dev, "vdd"); 558 - if (IS_ERR(hw->vdd)) 559 - return dev_err_probe(dev, PTR_ERR(hw->vdd), 560 - "failed to get vdd regulator\n"); 561 - 562 - err = regulator_enable(hw->vdd); 563 - if (err) { 564 - dev_err(dev, "failed to enable vdd regulator: %d\n", err); 565 - return err; 566 - } 554 + err = devm_regulator_get_enable(dev, "vdd"); 555 + if (err) 556 + return dev_err_probe(dev, err, "failed to get vdd regulator\n"); 567 557 568 558 msleep(50); 569 559 570 560 return 0; 571 - } 572 - 573 - static void hts221_chip_uninit(void *data) 574 - { 575 - struct hts221_hw *hw = data; 576 - 577 - regulator_disable(hw->vdd); 578 561 } 579 562 580 563 int hts221_probe(struct device *dev, int irq, const char *name, ··· 582 597 hw->regmap = regmap; 583 598 584 599 err = hts221_init_regulators(dev); 585 - if (err) 586 - return err; 587 - 588 - err = devm_add_action_or_reset(dev, hts221_chip_uninit, hw); 589 600 if (err) 590 601 return err; 591 602