diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2019-12-11 22:38:17 +0100 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2019-12-29 15:20:08 +0000 |
commit | c35aae7443023c08d406c9077c9e842b48cdb22f (patch) | |
tree | ccd1f5f5d39b6080ad5ea3127fc4e5de100904c4 /drivers/iio | |
parent | 964172561ea65f92394ef823405c31f17c57cc90 (diff) | |
download | linux-c35aae7443023c08d406c9077c9e842b48cdb22f.tar.gz linux-c35aae7443023c08d406c9077c9e842b48cdb22f.tar.bz2 linux-c35aae7443023c08d406c9077c9e842b48cdb22f.zip |
iio: accel: bma180: Basic regulator support
This brings up the VDD and VDDIO regulators using the
regulator framework. Platforms that do not use regulators
will provide stubs or dummy regulators.
Cc: Peter Meerwald <pmeerw@pmeerw.net>
Cc: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/accel/bma180.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c index 518efbe4eaf6..c2c15a4f9ee1 100644 --- a/drivers/iio/accel/bma180.c +++ b/drivers/iio/accel/bma180.c @@ -18,6 +18,7 @@ #include <linux/of_device.h> #include <linux/of.h> #include <linux/bitops.h> +#include <linux/regulator/consumer.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/iio/iio.h> @@ -110,6 +111,8 @@ struct bma180_part_info { #define BMA250_INT_RESET_MASK BIT(7) /* Reset pending interrupts */ struct bma180_data { + struct regulator *vdd_supply; + struct regulator *vddio_supply; struct i2c_client *client; struct iio_trigger *trig; const struct bma180_part_info *part_info; @@ -736,6 +739,40 @@ static int bma180_probe(struct i2c_client *client, if (ret) return ret; + data->vdd_supply = devm_regulator_get(dev, "vdd"); + if (IS_ERR(data->vdd_supply)) { + if (PTR_ERR(data->vdd_supply) != -EPROBE_DEFER) + dev_err(dev, "Failed to get vdd regulator %d\n", + (int)PTR_ERR(data->vdd_supply)); + return PTR_ERR(data->vdd_supply); + } + data->vddio_supply = devm_regulator_get(dev, "vddio"); + if (IS_ERR(data->vddio_supply)) { + if (PTR_ERR(data->vddio_supply) != -EPROBE_DEFER) + dev_err(dev, "Failed to get vddio regulator %d\n", + (int)PTR_ERR(data->vddio_supply)); + return PTR_ERR(data->vddio_supply); + } + /* Typical voltage 2.4V these are min and max */ + ret = regulator_set_voltage(data->vdd_supply, 1620000, 3600000); + if (ret) + return ret; + ret = regulator_set_voltage(data->vddio_supply, 1200000, 3600000); + if (ret) + return ret; + ret = regulator_enable(data->vdd_supply); + if (ret) { + dev_err(dev, "Failed to enable vdd regulator: %d\n", ret); + return ret; + } + ret = regulator_enable(data->vddio_supply); + if (ret) { + dev_err(dev, "Failed to enable vddio regulator: %d\n", ret); + goto err_disable_vdd; + } + /* Wait to make sure we started up properly (3 ms at least) */ + usleep_range(3000, 5000); + ret = data->part_info->chip_config(data); if (ret < 0) goto err_chip_disable; @@ -798,6 +835,9 @@ err_trigger_free: iio_trigger_free(data->trig); err_chip_disable: data->part_info->chip_disable(data); + regulator_disable(data->vddio_supply); +err_disable_vdd: + regulator_disable(data->vdd_supply); return ret; } @@ -817,6 +857,8 @@ static int bma180_remove(struct i2c_client *client) mutex_lock(&data->mutex); data->part_info->chip_disable(data); mutex_unlock(&data->mutex); + regulator_disable(data->vddio_supply); + regulator_disable(data->vdd_supply); return 0; } |