* [PATCH 1/2] dt-bindings: iio: accel: mma8452: add optional vcc-supply property
@ 2018-12-06 6:23 Anson Huang
2018-12-06 6:23 ` [PATCH 2/2] iio: accell: mma8452: add optional vcc regulator operation support Anson Huang
0 siblings, 1 reply; 4+ messages in thread
From: Anson Huang @ 2018-12-06 6:23 UTC (permalink / raw)
To: jic23, knaack.h, lars, pmeerw, robh+dt, mark.rutland,
harinath922, Leonard Crestez, gregkh, martink, rtresidd, gustavo,
linux-iio, devicetree, linux-kernel
Cc: dl-linux-imx
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(+)
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 {
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] iio: accell: mma8452: add optional vcc regulator operation support
2018-12-06 6:23 [PATCH 1/2] dt-bindings: iio: accel: mma8452: add optional vcc-supply property Anson Huang
@ 2018-12-06 6:23 ` Anson Huang
2018-12-07 10:23 ` Fabio Estevam
2018-12-08 12:10 ` Jonathan Cameron
0 siblings, 2 replies; 4+ messages in thread
From: Anson Huang @ 2018-12-06 6:23 UTC (permalink / raw)
To: jic23, knaack.h, lars, pmeerw, robh+dt, mark.rutland,
harinath922, Leonard Crestez, gregkh, martink, rtresidd, gustavo,
linux-iio, devicetree, linux-kernel
Cc: dl-linux-imx
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)) {
+ 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
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] iio: accell: mma8452: add optional vcc regulator operation support
2018-12-06 6:23 ` [PATCH 2/2] iio: accell: mma8452: add optional vcc regulator operation support Anson Huang
@ 2018-12-07 10:23 ` Fabio Estevam
2018-12-08 12:10 ` Jonathan Cameron
1 sibling, 0 replies; 4+ messages in thread
From: Fabio Estevam @ 2018-12-07 10:23 UTC (permalink / raw)
To: Yongcai Huang
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald, Rob Herring, Mark Rutland, harinath922,
Leonard Crestez, Greg Kroah-Hartman, martink, rtresidd,
Gustavo A. R. Silva, linux-iio,
open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
linux-kernel, NXP Linux Team
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] iio: accell: mma8452: add optional vcc regulator operation support
2018-12-06 6:23 ` [PATCH 2/2] iio: accell: mma8452: add optional vcc regulator operation support Anson Huang
2018-12-07 10:23 ` Fabio Estevam
@ 2018-12-08 12:10 ` Jonathan Cameron
1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2018-12-08 12:10 UTC (permalink / raw)
To: Anson Huang
Cc: knaack.h, lars, pmeerw, robh+dt, mark.rutland, harinath922,
Leonard Crestez, gregkh, martink, rtresidd, gustavo, linux-iio,
devicetree, linux-kernel, dl-linux-imx
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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-12-08 12:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-06 6:23 [PATCH 1/2] dt-bindings: iio: accel: mma8452: add optional vcc-supply property Anson Huang
2018-12-06 6:23 ` [PATCH 2/2] iio: accell: mma8452: add optional vcc regulator operation support Anson Huang
2018-12-07 10:23 ` Fabio Estevam
2018-12-08 12:10 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).