Commit 3cf7ded1 authored by Dan Robertson's avatar Dan Robertson Committed by Jonathan Cameron

iio: accel: bma400: basic regulator support

Add support for the VDD and VDDIO regulators using the regulator
framework.
Signed-off-by: default avatarDan Robertson <dan@dlrobertson.com>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 465c811f
...@@ -86,6 +86,10 @@ ...@@ -86,6 +86,10 @@
#define BMA400_SCALE_MIN 38357 #define BMA400_SCALE_MIN 38357
#define BMA400_SCALE_MAX 306864 #define BMA400_SCALE_MAX 306864
#define BMA400_NUM_REGULATORS 2
#define BMA400_VDD_REGULATOR 0
#define BMA400_VDDIO_REGULATOR 1
extern const struct regmap_config bma400_regmap_config; extern const struct regmap_config bma400_regmap_config;
int bma400_probe(struct device *dev, struct regmap *regmap, const char *name); int bma400_probe(struct device *dev, struct regmap *regmap, const char *name);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include "bma400.h" #include "bma400.h"
...@@ -53,6 +54,7 @@ struct bma400_sample_freq { ...@@ -53,6 +54,7 @@ struct bma400_sample_freq {
struct bma400_data { struct bma400_data {
struct device *dev; struct device *dev;
struct regmap *regmap; struct regmap *regmap;
struct regulator_bulk_data regulators[BMA400_NUM_REGULATORS];
struct mutex mutex; /* data register lock */ struct mutex mutex; /* data register lock */
struct iio_mount_matrix orientation; struct iio_mount_matrix orientation;
enum bma400_power_mode power_mode; enum bma400_power_mode power_mode;
...@@ -576,17 +578,38 @@ static int bma400_init(struct bma400_data *data) ...@@ -576,17 +578,38 @@ static int bma400_init(struct bma400_data *data)
goto out; goto out;
} }
data->regulators[BMA400_VDD_REGULATOR].supply = "vdd";
data->regulators[BMA400_VDDIO_REGULATOR].supply = "vddio";
ret = devm_regulator_bulk_get(data->dev,
ARRAY_SIZE(data->regulators),
data->regulators);
if (ret) {
if (ret != -EPROBE_DEFER)
dev_err(data->dev,
"Failed to get regulators: %d\n",
ret);
goto out;
}
ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators),
data->regulators);
if (ret) {
dev_err(data->dev, "Failed to enable regulators: %d\n",
ret);
goto out;
}
ret = bma400_get_power_mode(data); ret = bma400_get_power_mode(data);
if (ret) { if (ret) {
dev_err(data->dev, "Failed to get the initial power-mode\n"); dev_err(data->dev, "Failed to get the initial power-mode\n");
goto out; goto err_reg_disable;
} }
if (data->power_mode != POWER_MODE_NORMAL) { if (data->power_mode != POWER_MODE_NORMAL) {
ret = bma400_set_power_mode(data, POWER_MODE_NORMAL); ret = bma400_set_power_mode(data, POWER_MODE_NORMAL);
if (ret) { if (ret) {
dev_err(data->dev, "Failed to wake up the device\n"); dev_err(data->dev, "Failed to wake up the device\n");
goto out; goto err_reg_disable;
} }
/* /*
* TODO: The datasheet waits 1500us here in the example, but * TODO: The datasheet waits 1500us here in the example, but
...@@ -599,15 +622,15 @@ static int bma400_init(struct bma400_data *data) ...@@ -599,15 +622,15 @@ static int bma400_init(struct bma400_data *data)
ret = bma400_get_accel_output_data_rate(data); ret = bma400_get_accel_output_data_rate(data);
if (ret) if (ret)
goto out; goto err_reg_disable;
ret = bma400_get_accel_oversampling_ratio(data); ret = bma400_get_accel_oversampling_ratio(data);
if (ret) if (ret)
goto out; goto err_reg_disable;
ret = bma400_get_accel_scale(data); ret = bma400_get_accel_scale(data);
if (ret) if (ret)
goto out; goto err_reg_disable;
/* /*
* Once the interrupt engine is supported we might use the * Once the interrupt engine is supported we might use the
...@@ -617,6 +640,9 @@ static int bma400_init(struct bma400_data *data) ...@@ -617,6 +640,9 @@ static int bma400_init(struct bma400_data *data)
*/ */
return regmap_write(data->regmap, BMA400_ACC_CONFIG2_REG, 0x00); return regmap_write(data->regmap, BMA400_ACC_CONFIG2_REG, 0x00);
err_reg_disable:
regulator_bulk_disable(ARRAY_SIZE(data->regulators),
data->regulators);
out: out:
return ret; return ret;
} }
...@@ -812,6 +838,9 @@ int bma400_remove(struct device *dev) ...@@ -812,6 +838,9 @@ int bma400_remove(struct device *dev)
ret = bma400_set_power_mode(data, POWER_MODE_SLEEP); ret = bma400_set_power_mode(data, POWER_MODE_SLEEP);
mutex_unlock(&data->mutex); mutex_unlock(&data->mutex);
regulator_bulk_disable(ARRAY_SIZE(data->regulators),
data->regulators);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment