summaryrefslogtreecommitdiff
path: root/drivers/iio/humidity/hts221_core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iio/humidity/hts221_core.c')
-rw-r--r--drivers/iio/humidity/hts221_core.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c
index 16657789dc45..6a39615b6961 100644
--- a/drivers/iio/humidity/hts221_core.c
+++ b/drivers/iio/humidity/hts221_core.c
@@ -547,6 +547,35 @@ static const struct iio_info hts221_info = {
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;
+ }
+
+ 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)
{
@@ -567,6 +596,14 @@ int hts221_probe(struct device *dev, int irq, const char *name,
hw->irq = irq;
hw->regmap = regmap;
+ err = hts221_init_regulators(dev);
+ 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;