Commit 07c12b1c authored by Brian Masney's avatar Brian Masney Committed by Jonathan Cameron

iio: imu: mpu6050: add support for regulator framework

This patch adds support for the regulator framework to the mpu6050
driver.
Signed-off-by: default avatarBrian Masney <masneyb@onstation.org>
Signed-off-by: default avatarJonathan Marek <jonathan@marek.ca>
Acked-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 2c8909b9
...@@ -21,6 +21,7 @@ Required properties: ...@@ -21,6 +21,7 @@ Required properties:
bindings. bindings.
Optional properties: Optional properties:
- vddio-supply: regulator phandle for VDDIO supply
- mount-matrix: an optional 3x3 mounting rotation matrix - mount-matrix: an optional 3x3 mounting rotation matrix
- i2c-gate node. These devices also support an auxiliary i2c bus. This is - i2c-gate node. These devices also support an auxiliary i2c bus. This is
simple enough to be described using the i2c-gate binding. See simple enough to be described using the i2c-gate binding. See
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/acpi.h> #include <linux/acpi.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#include "inv_mpu_iio.h" #include "inv_mpu_iio.h"
/* /*
...@@ -926,6 +927,39 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) ...@@ -926,6 +927,39 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st)
return result; return result;
} }
static int inv_mpu_core_enable_regulator(struct inv_mpu6050_state *st)
{
int result;
result = regulator_enable(st->vddio_supply);
if (result) {
dev_err(regmap_get_device(st->map),
"Failed to enable regulator: %d\n", result);
} else {
/* Give the device a little bit of time to start up. */
usleep_range(35000, 70000);
}
return result;
}
static int inv_mpu_core_disable_regulator(struct inv_mpu6050_state *st)
{
int result;
result = regulator_disable(st->vddio_supply);
if (result)
dev_err(regmap_get_device(st->map),
"Failed to disable regulator: %d\n", result);
return result;
}
static void inv_mpu_core_disable_regulator_action(void *_data)
{
inv_mpu_core_disable_regulator(_data);
}
int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
int (*inv_mpu_bus_setup)(struct iio_dev *), int chip_type) int (*inv_mpu_bus_setup)(struct iio_dev *), int chip_type)
{ {
...@@ -992,6 +1026,28 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, ...@@ -992,6 +1026,28 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
return -EINVAL; return -EINVAL;
} }
st->vddio_supply = devm_regulator_get(dev, "vddio");
if (IS_ERR(st->vddio_supply)) {
if (PTR_ERR(st->vddio_supply) != -EPROBE_DEFER)
dev_err(dev, "Failed to get vddio regulator %d\n",
(int)PTR_ERR(st->vddio_supply));
return PTR_ERR(st->vddio_supply);
}
result = inv_mpu_core_enable_regulator(st);
if (result)
return result;
result = devm_add_action(dev, inv_mpu_core_disable_regulator_action,
st);
if (result) {
inv_mpu_core_disable_regulator_action(st);
dev_err(dev, "Failed to setup regulator cleanup action %d\n",
result);
return result;
}
/* power is turned on inside check chip type*/ /* power is turned on inside check chip type*/
result = inv_check_and_setup_chip(st); result = inv_check_and_setup_chip(st);
if (result) if (result)
...@@ -1051,7 +1107,12 @@ static int inv_mpu_resume(struct device *dev) ...@@ -1051,7 +1107,12 @@ static int inv_mpu_resume(struct device *dev)
int result; int result;
mutex_lock(&st->lock); mutex_lock(&st->lock);
result = inv_mpu_core_enable_regulator(st);
if (result)
goto out_unlock;
result = inv_mpu6050_set_power_itg(st, true); result = inv_mpu6050_set_power_itg(st, true);
out_unlock:
mutex_unlock(&st->lock); mutex_unlock(&st->lock);
return result; return result;
...@@ -1064,6 +1125,7 @@ static int inv_mpu_suspend(struct device *dev) ...@@ -1064,6 +1125,7 @@ static int inv_mpu_suspend(struct device *dev)
mutex_lock(&st->lock); mutex_lock(&st->lock);
result = inv_mpu6050_set_power_itg(st, false); result = inv_mpu6050_set_power_itg(st, false);
inv_mpu_core_disable_regulator(st);
mutex_unlock(&st->lock); mutex_unlock(&st->lock);
return result; return result;
......
...@@ -129,6 +129,7 @@ struct inv_mpu6050_hw { ...@@ -129,6 +129,7 @@ struct inv_mpu6050_hw {
* @chip_period: chip internal period estimation (~1kHz). * @chip_period: chip internal period estimation (~1kHz).
* @it_timestamp: timestamp from previous interrupt. * @it_timestamp: timestamp from previous interrupt.
* @data_timestamp: timestamp for next data sample. * @data_timestamp: timestamp for next data sample.
* @vddio_supply voltage regulator for the chip.
*/ */
struct inv_mpu6050_state { struct inv_mpu6050_state {
struct mutex lock; struct mutex lock;
...@@ -149,6 +150,7 @@ struct inv_mpu6050_state { ...@@ -149,6 +150,7 @@ struct inv_mpu6050_state {
s64 chip_period; s64 chip_period;
s64 it_timestamp; s64 it_timestamp;
s64 data_timestamp; s64 data_timestamp;
struct regulator *vddio_supply;
}; };
/*register and associated bit definition*/ /*register and associated bit definition*/
......
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