* [PATCH] iio: magnetometer: mag3110: add optional vcc regulator operation support
@ 2018-12-06 5:03 Anson Huang
2018-12-07 10:26 ` Fabio Estevam
0 siblings, 1 reply; 2+ messages in thread
From: Anson Huang @ 2018-12-06 5:03 UTC (permalink / raw)
To: jic23, knaack.h, lars, pmeerw, rtresidd, linux-iio, linux-kernel
Cc: dl-linux-imx
The magnetometer's power supply could be controlled by regulator
on some platforms, such as i.MX6Q-SABRESD board, the mag3110's
power supply is controlled by a GPIO fixed regulator, need to make
sure the regulator is enabled before any communication with mag3110,
this patch adds optional vcc regulator operation support.
Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
drivers/iio/magnetometer/mag3110.c | 49 +++++++++++++++++++++++++++++++++-----
1 file changed, 43 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/magnetometer/mag3110.c b/drivers/iio/magnetometer/mag3110.c
index f063355..e2d5b22 100644
--- a/drivers/iio/magnetometer/mag3110.c
+++ b/drivers/iio/magnetometer/mag3110.c
@@ -20,6 +20,7 @@
#include <linux/iio/buffer.h>
#include <linux/iio/triggered_buffer.h>
#include <linux/delay.h>
+#include <linux/regulator/consumer.h>
#define MAG3110_STATUS 0x00
#define MAG3110_OUT_X 0x01 /* MSB first */
@@ -56,6 +57,7 @@ struct mag3110_data {
struct mutex lock;
u8 ctrl_reg1;
int sleep_val;
+ struct regulator *vcc_reg;
};
static int mag3110_request(struct mag3110_data *data)
@@ -469,17 +471,27 @@ static int mag3110_probe(struct i2c_client *client,
struct iio_dev *indio_dev;
int ret;
+ indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+ if (!indio_dev)
+ return -ENOMEM;
+
+ data = iio_priv(indio_dev);
+
+ 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, MAG3110_WHO_AM_I);
if (ret < 0)
return ret;
if (ret != MAG3110_DEVICE_ID)
return -ENODEV;
- indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
- if (!indio_dev)
- return -ENOMEM;
-
- data = iio_priv(indio_dev);
data->client = client;
mutex_init(&data->lock);
@@ -537,14 +549,39 @@ static int mag3110_remove(struct i2c_client *client)
#ifdef CONFIG_PM_SLEEP
static int mag3110_suspend(struct device *dev)
{
- return mag3110_standby(iio_priv(i2c_get_clientdata(
+ struct mag3110_data *data = iio_priv(i2c_get_clientdata(
+ to_i2c_client(dev)));
+ int ret;
+
+ ret = mag3110_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 mag3110_resume(struct device *dev)
{
struct mag3110_data *data = iio_priv(i2c_get_clientdata(
to_i2c_client(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;
+ }
+ }
return i2c_smbus_write_byte_data(data->client, MAG3110_CTRL_REG1,
data->ctrl_reg1);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: magnetometer: mag3110: add optional vcc regulator operation support
2018-12-06 5:03 [PATCH] iio: magnetometer: mag3110: add optional vcc regulator operation support Anson Huang
@ 2018-12-07 10:26 ` Fabio Estevam
0 siblings, 0 replies; 2+ messages in thread
From: Fabio Estevam @ 2018-12-07 10:26 UTC (permalink / raw)
To: Yongcai Huang
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald, rtresidd, linux-iio, linux-kernel,
NXP Linux Team
Hi Anson,
On Thu, Dec 6, 2018 at 3:05 AM Anson Huang <anson.huang@nxp.com> wrote:
> static int mag3110_request(struct mag3110_data *data)
> @@ -469,17 +471,27 @@ static int mag3110_probe(struct i2c_client *client,
> struct iio_dev *indio_dev;
> int ret;
>
> + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + data = iio_priv(indio_dev);
> +
> + 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");
Same comment as in the previous patch.
There is no VCC regulator as per the datasheet. There are VDD and
VDDIO power supplies, so better represent both and with the same name
they appear in the datasheet.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-12-07 10:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-06 5:03 [PATCH] iio: magnetometer: mag3110: add optional vcc regulator operation support Anson Huang
2018-12-07 10:26 ` Fabio Estevam
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).