diff mbox series

[1/2] dt-bindings: iio: accel: mma8452: add optional vcc-supply property

Message ID 1544077059-4471-1-git-send-email-Anson.Huang@nxp.com
State Superseded, archived
Headers show
Series [1/2] dt-bindings: iio: accel: mma8452: add optional vcc-supply property | expand

Checks

Context Check Description
robh/checkpatch success

Commit Message

Anson Huang Dec. 6, 2018, 6:23 a.m. UTC
The accelerometer's power supply could be controlled by regulator
on some platforms, add optional property "vcc-supply" to let device
tree to pass phandle to the regulator to driver.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
 Documentation/devicetree/bindings/iio/accel/mma8452.txt | 2 ++
 1 file changed, 2 insertions(+)

Comments

Fabio Estevam Dec. 7, 2018, 10:23 a.m. UTC | #1
Hi Anson,

On Thu, Dec 6, 2018 at 4:25 AM Anson Huang <anson.huang@nxp.com> wrote:

> @@ -1533,6 +1535,14 @@ static int mma8452_probe(struct i2c_client *client,
>         data->client = client;
>         mutex_init(&data->lock);
>         data->chip_info = match->data;
> +       data->vcc_reg = devm_regulator_get_optional(&client->dev, "vcc");

MMA8452 datasheet shows two power supplies: VDD and VDDIO, so if you
are adding support for the regulators, IMHO it is better to represent
both supplies and with the same name they appear in the datasheet.
Jonathan Cameron Dec. 8, 2018, 12:10 p.m. UTC | #2
On Thu, 6 Dec 2018 06:23:33 +0000
Anson Huang <anson.huang@nxp.com> wrote:

> The accelerometer's power supply could be controlled by regulator
> on some platforms, such as i.MX6Q-SABRESD board, the mma8451's
> power supply is controlled by a GPIO fixed regulator, need to make
> sure the regulator is enabled before any communication with mma8451,
> this patch adds optional vcc regulator operation support.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> ---
>  drivers/iio/accel/mma8452.c | 88 +++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 86 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index 421a0a8..8f6123f 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -31,6 +31,7 @@
>  #include <linux/of_device.h>
>  #include <linux/of_irq.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/regulator/consumer.h>
>  
>  #define MMA8452_STATUS				0x00
>  #define  MMA8452_STATUS_DRDY			(BIT(2) | BIT(1) | BIT(0))
> @@ -107,6 +108,7 @@ struct mma8452_data {
>  	u8 data_cfg;
>  	const struct mma_chip_info *chip_info;
>  	int sleep_val;
> +	struct regulator *vcc_reg;
>  };
>  
>   /**
> @@ -1533,6 +1535,14 @@ static int mma8452_probe(struct i2c_client *client,
>  	data->client = client;
>  	mutex_init(&data->lock);
>  	data->chip_info = match->data;
> +	data->vcc_reg = devm_regulator_get_optional(&client->dev, "vcc");
> +	if (!IS_ERR(data->vcc_reg)) {

Make sure it's the 'right' error to indicate there isn't a regulator
rather than a deferred response for example.


> +		ret = regulator_enable(data->vcc_reg);
> +		if (ret) {
> +			dev_err(&client->dev, "failed to enable VCC regulator\n");
> +			return ret;
> +		}
> +	}
>  
>  	ret = i2c_smbus_read_byte_data(client, MMA8452_WHO_AM_I);
>  	if (ret < 0)
> @@ -1667,6 +1677,8 @@ static int mma8452_probe(struct i2c_client *client,
>  static int mma8452_remove(struct i2c_client *client)
>  {
>  	struct iio_dev *indio_dev = i2c_get_clientdata(client);
> +	struct mma8452_data *data = iio_priv(indio_dev);
> +	int ret;
>  
>  	iio_device_unregister(indio_dev);
>  
> @@ -1678,6 +1690,14 @@ static int mma8452_remove(struct i2c_client *client)
>  	mma8452_trigger_cleanup(indio_dev);
>  	mma8452_standby(iio_priv(indio_dev));
>  
> +	if (!IS_ERR(data->vcc_reg)) {
> +		ret = regulator_disable(data->vcc_reg);
> +		if (ret) {
> +			dev_err(&client->dev, "failed to disable VCC regulator\n");
> +			return ret;
> +		}
> +	}
> +
>  	return 0;
>  }
>  
> @@ -1696,6 +1716,14 @@ static int mma8452_runtime_suspend(struct device *dev)
>  		return -EAGAIN;
>  	}
>  
> +	if (!IS_ERR(data->vcc_reg)) {
> +		ret = regulator_disable(data->vcc_reg);
> +		if (ret) {
> +			dev_err(dev, "failed to disable VCC regulator\n");
> +			return ret;
> +		}
> +	}
> +
>  	return 0;
>  }
>  
> @@ -1705,6 +1733,14 @@ static int mma8452_runtime_resume(struct device *dev)
>  	struct mma8452_data *data = iio_priv(indio_dev);
>  	int ret, sleep_val;
>  
> +	if (!IS_ERR(data->vcc_reg)) {
> +		ret = regulator_enable(data->vcc_reg);
> +		if (ret) {
> +			dev_err(dev, "failed to enable VCC regulator\n");
> +			return ret;
> +		}
> +	}
> +
>  	ret = mma8452_active(data);
>  	if (ret < 0)
>  		return ret;
> @@ -1723,14 +1759,62 @@ static int mma8452_runtime_resume(struct device *dev)
>  #ifdef CONFIG_PM_SLEEP
>  static int mma8452_suspend(struct device *dev)
>  {
> -	return mma8452_standby(iio_priv(i2c_get_clientdata(
> +	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> +	struct mma8452_data *data = iio_priv(indio_dev);
> +	int ret;
> +
> +	if (!IS_ERR(data->vcc_reg)) {
> +		ret = regulator_enable(data->vcc_reg);
> +		if (ret) {
> +			dev_err(dev, "failed to enable VCC regulator\n");
> +			return ret;
> +		}
> +	}
> +
> +	ret = mma8452_standby(iio_priv(i2c_get_clientdata(
>  		to_i2c_client(dev))));
> +	if (ret)
> +		return ret;
> +
> +	if (!IS_ERR(data->vcc_reg)) {
> +		ret = regulator_disable(data->vcc_reg);
> +		if (ret) {
> +			dev_err(dev, "failed to disable VCC regulator\n");
> +			return ret;
> +		}
> +	}
> +
> +	return 0;
>  }
>  
>  static int mma8452_resume(struct device *dev)
>  {
> -	return mma8452_active(iio_priv(i2c_get_clientdata(
> +	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> +	struct mma8452_data *data = iio_priv(indio_dev);
> +	int ret;
> +
> +	if (!IS_ERR(data->vcc_reg)) {
> +		ret = regulator_enable(data->vcc_reg);
> +		if (ret) {
> +			dev_err(dev, "failed to enable VCC regulator\n");
> +			return ret;
> +		}
> +	}
> +
> +	ret = mma8452_active(iio_priv(i2c_get_clientdata(
>  		to_i2c_client(dev))));
> +	if (ret)
> +		return ret;
> +
> +	if (!IS_ERR(data->vcc_reg)) {
> +		ret = regulator_disable(data->vcc_reg);
> +		if (ret) {
> +			dev_err(dev, "failed to disable VCC regulator\n");
> +			return ret;
> +		}
> +	}
> +
> +	return 0;
>  }
>  #endif
>
diff mbox series

Patch

diff --git a/Documentation/devicetree/bindings/iio/accel/mma8452.txt b/Documentation/devicetree/bindings/iio/accel/mma8452.txt
index 2100e9a..410279a 100644
--- a/Documentation/devicetree/bindings/iio/accel/mma8452.txt
+++ b/Documentation/devicetree/bindings/iio/accel/mma8452.txt
@@ -20,6 +20,8 @@  Optional properties:
   - interrupt-names: should contain "INT1" and/or "INT2", the accelerometer's
 		     interrupt line in use.
 
+  - vcc-supply: phandle to the regulator that provides power to the accelerometer.
+
 Example:
 
 	mma8453fc@1d {