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

Configure Feed

Select the types of activity you want to include in your feed.

iio: humidity: hts221: add vdd voltage regulator

Like all other ST sensors, hts221 devices have VDD power line.
Introduce VDD voltage regulator to control it.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Link: https://lore.kernel.org/r/6b3347e78f4f920c48eb6a66936d3b69cb9ff53a.1606045688.git.lorenzo@kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Lorenzo Bianconi and committed by
Jonathan Cameron
aa784a54 6c050782

+39
+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> 16 17 17 18 enum hts221_sensor_type { 18 19 HTS221_SENSOR_H, ··· 30 29 const char *name; 31 30 struct device *dev; 32 31 struct regmap *regmap; 32 + struct regulator *vdd; 33 33 34 34 struct iio_trigger *trig; 35 35 int irq;
+37
drivers/iio/humidity/hts221_core.c
··· 547 547 548 548 static const unsigned long hts221_scan_masks[] = {0x3, 0x0}; 549 549 550 + static int hts221_init_regulators(struct device *dev) 551 + { 552 + struct iio_dev *iio_dev = dev_get_drvdata(dev); 553 + struct hts221_hw *hw = iio_priv(iio_dev); 554 + int err; 555 + 556 + hw->vdd = devm_regulator_get(dev, "vdd"); 557 + if (IS_ERR(hw->vdd)) 558 + return dev_err_probe(dev, PTR_ERR(hw->vdd), 559 + "failed to get vdd regulator\n"); 560 + 561 + err = regulator_enable(hw->vdd); 562 + if (err) { 563 + dev_err(dev, "failed to enable vdd regulator: %d\n", err); 564 + return err; 565 + } 566 + 567 + msleep(50); 568 + 569 + return 0; 570 + } 571 + 572 + static void hts221_chip_uninit(void *data) 573 + { 574 + struct hts221_hw *hw = data; 575 + 576 + regulator_disable(hw->vdd); 577 + } 578 + 550 579 int hts221_probe(struct device *dev, int irq, const char *name, 551 580 struct regmap *regmap) 552 581 { ··· 595 566 hw->dev = dev; 596 567 hw->irq = irq; 597 568 hw->regmap = regmap; 569 + 570 + err = hts221_init_regulators(dev); 571 + if (err) 572 + return err; 573 + 574 + err = devm_add_action_or_reset(dev, hts221_chip_uninit, hw); 575 + if (err) 576 + return err; 598 577 599 578 err = hts221_check_whoami(hw); 600 579 if (err < 0)