Commit 2c97f7b4 authored by Jonathan Cameron's avatar Jonathan Cameron
Browse files

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: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Reviewed-by: default avatarMatti Vaittinen <mazziesaccount@gmail.com>
Reviewed-by: default avatarNuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20221016163409.320197-10-jic23@kernel.org
parent d86186a6
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -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;
+4 −23
Original line number Diff line number Diff line
@@ -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;