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

iio: accel: bmc150-accel: Add rudimentary regulator support

These Bosch accelerometers have two supplies, VDD and VDDIO.
Add some rudimentary support to obtain and enable these
regulators during probe() and disable them during remove()
or on the errorpath.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20201115205745.618455-3-linus.walleij@linaro.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Linus Walleij and committed by
Jonathan Cameron
672f3022 a1a210bf

+33 -2
+33 -2
drivers/iio/accel/bmc150-accel-core.c
··· 28 28 #include <linux/iio/trigger_consumer.h> 29 29 #include <linux/iio/triggered_buffer.h> 30 30 #include <linux/regmap.h> 31 + #include <linux/regulator/consumer.h> 31 32 32 33 #include "bmc150-accel.h" 33 34 ··· 185 184 186 185 struct bmc150_accel_data { 187 186 struct regmap *regmap; 187 + struct regulator_bulk_data regulators[2]; 188 188 int irq; 189 189 struct bmc150_accel_interrupt interrupts[BMC150_ACCEL_INTERRUPTS]; 190 190 struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS]; ··· 1594 1592 &data->orientation); 1595 1593 if (ret) 1596 1594 return ret; 1595 + /* 1596 + * VDD is the analog and digital domain voltage supply 1597 + * VDDIO is the digital I/O voltage supply 1598 + */ 1599 + data->regulators[0].supply = "vdd"; 1600 + data->regulators[1].supply = "vddio"; 1601 + ret = devm_regulator_bulk_get(dev, 1602 + ARRAY_SIZE(data->regulators), 1603 + data->regulators); 1604 + if (ret) 1605 + return dev_err_probe(dev, ret, "failed to get regulators\n"); 1606 + 1607 + ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators), 1608 + data->regulators); 1609 + if (ret) { 1610 + dev_err(dev, "failed to enable regulators: %d\n", ret); 1611 + return ret; 1612 + } 1613 + /* 1614 + * 2ms or 3ms power-on time according to datasheets, let's better 1615 + * be safe than sorry and set this delay to 5ms. 1616 + */ 1617 + msleep(5); 1597 1618 1598 1619 ret = bmc150_accel_chip_init(data); 1599 1620 if (ret < 0) 1600 - return ret; 1621 + goto err_disable_regulators; 1601 1622 1602 1623 mutex_init(&data->mutex); 1603 1624 ··· 1646 1621 fifo_attrs); 1647 1622 if (ret < 0) { 1648 1623 dev_err(dev, "Failed: iio triggered buffer setup\n"); 1649 - return ret; 1624 + goto err_disable_regulators; 1650 1625 } 1651 1626 1652 1627 if (data->irq > 0) { ··· 1700 1675 bmc150_accel_unregister_triggers(data, BMC150_ACCEL_TRIGGERS - 1); 1701 1676 err_buffer_cleanup: 1702 1677 iio_triggered_buffer_cleanup(indio_dev); 1678 + err_disable_regulators: 1679 + regulator_bulk_disable(ARRAY_SIZE(data->regulators), 1680 + data->regulators); 1703 1681 1704 1682 return ret; 1705 1683 } ··· 1726 1698 mutex_lock(&data->mutex); 1727 1699 bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_DEEP_SUSPEND, 0); 1728 1700 mutex_unlock(&data->mutex); 1701 + 1702 + regulator_bulk_disable(ARRAY_SIZE(data->regulators), 1703 + data->regulators); 1729 1704 1730 1705 return 0; 1731 1706 }