linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] media: i2c: dw9714: add optional regulator support
@ 2021-11-29 12:07 Martin Kepplinger
  2021-12-21 17:33 ` Martin Kepplinger
  2022-01-20  9:56 ` Sakari Ailus
  0 siblings, 2 replies; 5+ messages in thread
From: Martin Kepplinger @ 2021-11-29 12:07 UTC (permalink / raw)
  To: martin.kepplinger, broonie, sakari.ailus
  Cc: angus, kernel, linux-kernel, linux-media, linux-pm, mchehab

From: Angus Ainslie <angus@akkea.ca>

Allow the dw9714 to control a regulator and adjust suspend() and resume()
to support both runtime and system pm.

Signed-off-by: Angus Ainslie <angus@akkea.ca>
Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
---


revision history
----------------
v3: (thank you Mark and Sakari)
 * use regulator_get() instead of regulator_get_optional()

v2: (thank you Mark)
 * simplify the regulator_get_optional() error path
 * fix regulator usage during probe()
https://lore.kernel.org/linux-media/20211126090107.1243558-1-martin.kepplinger@puri.sm/

v1:
https://lore.kernel.org/linux-media/20211125080922.978583-1-martin.kepplinger@puri.sm/



 drivers/media/i2c/dw9714.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/dw9714.c b/drivers/media/i2c/dw9714.c
index 3863dfeb8293..81170bbe0e55 100644
--- a/drivers/media/i2c/dw9714.c
+++ b/drivers/media/i2c/dw9714.c
@@ -5,6 +5,7 @@
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/pm_runtime.h>
+#include <linux/regulator/consumer.h>
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-event.h>
@@ -36,6 +37,7 @@ struct dw9714_device {
 	struct v4l2_ctrl_handler ctrls_vcm;
 	struct v4l2_subdev sd;
 	u16 current_val;
+	struct regulator *vcc;
 };
 
 static inline struct dw9714_device *to_dw9714_vcm(struct v4l2_ctrl *ctrl)
@@ -145,6 +147,16 @@ static int dw9714_probe(struct i2c_client *client)
 	if (dw9714_dev == NULL)
 		return -ENOMEM;
 
+	dw9714_dev->vcc = devm_regulator_get(&client->dev, "vcc");
+	if (IS_ERR(dw9714_dev->vcc))
+		return PTR_ERR(dw9714_dev->vcc);
+
+	rval = regulator_enable(dw9714_dev->vcc);
+	if (rval < 0) {
+		dev_err(&client->dev, "failed to enable vcc: %d\n", rval);
+		return rval;
+	}
+
 	v4l2_i2c_subdev_init(&dw9714_dev->sd, client, &dw9714_ops);
 	dw9714_dev->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
 				V4L2_SUBDEV_FL_HAS_EVENTS;
@@ -200,6 +212,9 @@ static int __maybe_unused dw9714_vcm_suspend(struct device *dev)
 	struct dw9714_device *dw9714_dev = sd_to_dw9714_vcm(sd);
 	int ret, val;
 
+	if (pm_runtime_suspended(&client->dev))
+		return 0;
+
 	for (val = dw9714_dev->current_val & ~(DW9714_CTRL_STEPS - 1);
 	     val >= 0; val -= DW9714_CTRL_STEPS) {
 		ret = dw9714_i2c_write(client,
@@ -208,7 +223,12 @@ static int __maybe_unused dw9714_vcm_suspend(struct device *dev)
 			dev_err_once(dev, "%s I2C failure: %d", __func__, ret);
 		usleep_range(DW9714_CTRL_DELAY_US, DW9714_CTRL_DELAY_US + 10);
 	}
-	return 0;
+
+	ret = regulator_disable(dw9714_dev->vcc);
+	if (ret)
+		dev_err(dev, "Failed to disable vcc: %d\n", ret);
+
+	return ret;
 }
 
 /*
@@ -224,6 +244,16 @@ static int  __maybe_unused dw9714_vcm_resume(struct device *dev)
 	struct dw9714_device *dw9714_dev = sd_to_dw9714_vcm(sd);
 	int ret, val;
 
+	if (pm_runtime_suspended(&client->dev))
+		return 0;
+
+	ret = regulator_enable(dw9714_dev->vcc);
+	if (ret) {
+		dev_err(dev, "Failed to enable vcc: %d\n", ret);
+		return ret;
+	}
+	usleep_range(1000, 2000);
+
 	for (val = dw9714_dev->current_val % DW9714_CTRL_STEPS;
 	     val < dw9714_dev->current_val + DW9714_CTRL_STEPS - 1;
 	     val += DW9714_CTRL_STEPS) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] media: i2c: dw9714: add optional regulator support
  2021-11-29 12:07 [PATCH v3] media: i2c: dw9714: add optional regulator support Martin Kepplinger
@ 2021-12-21 17:33 ` Martin Kepplinger
  2022-01-20  8:04   ` Martin Kepplinger
  2022-01-20  9:56 ` Sakari Ailus
  1 sibling, 1 reply; 5+ messages in thread
From: Martin Kepplinger @ 2021-12-21 17:33 UTC (permalink / raw)
  To: broonie, sakari.ailus
  Cc: angus, kernel, linux-kernel, linux-media, linux-pm, mchehab

Am Montag, dem 29.11.2021 um 13:07 +0100 schrieb Martin Kepplinger:
> From: Angus Ainslie <angus@akkea.ca>
> 
> Allow the dw9714 to control a regulator and adjust suspend() and
> resume()
> to support both runtime and system pm.
> 
> Signed-off-by: Angus Ainslie <angus@akkea.ca>
> Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> ---
> 
> 
> revision history
> ----------------
> v3: (thank you Mark and Sakari)
>  * use regulator_get() instead of regulator_get_optional()
> 
> v2: (thank you Mark)
>  * simplify the regulator_get_optional() error path
>  * fix regulator usage during probe()
> https://lore.kernel.org/linux-media/20211126090107.1243558-1-martin.kepplinger@puri.sm/
> 
> v1:
> https://lore.kernel.org/linux-media/20211125080922.978583-1-martin.kepplinger@puri.sm/
> 
> 
> 
>  drivers/media/i2c/dw9714.c | 32 +++++++++++++++++++++++++++++++-
>  1 file changed, 31 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/dw9714.c b/drivers/media/i2c/dw9714.c
> index 3863dfeb8293..81170bbe0e55 100644
> --- a/drivers/media/i2c/dw9714.c
> +++ b/drivers/media/i2c/dw9714.c
> @@ -5,6 +5,7 @@
>  #include <linux/i2c.h>
>  #include <linux/module.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/regulator/consumer.h>
>  #include <media/v4l2-ctrls.h>
>  #include <media/v4l2-device.h>
>  #include <media/v4l2-event.h>
> @@ -36,6 +37,7 @@ struct dw9714_device {
>         struct v4l2_ctrl_handler ctrls_vcm;
>         struct v4l2_subdev sd;
>         u16 current_val;
> +       struct regulator *vcc;
>  };
>  
>  static inline struct dw9714_device *to_dw9714_vcm(struct v4l2_ctrl
> *ctrl)
> @@ -145,6 +147,16 @@ static int dw9714_probe(struct i2c_client
> *client)
>         if (dw9714_dev == NULL)
>                 return -ENOMEM;
>  
> +       dw9714_dev->vcc = devm_regulator_get(&client->dev, "vcc");
> +       if (IS_ERR(dw9714_dev->vcc))
> +               return PTR_ERR(dw9714_dev->vcc);
> +
> +       rval = regulator_enable(dw9714_dev->vcc);
> +       if (rval < 0) {
> +               dev_err(&client->dev, "failed to enable vcc: %d\n",
> rval);
> +               return rval;
> +       }
> +
>         v4l2_i2c_subdev_init(&dw9714_dev->sd, client, &dw9714_ops);
>         dw9714_dev->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
>                                 V4L2_SUBDEV_FL_HAS_EVENTS;
> @@ -200,6 +212,9 @@ static int __maybe_unused
> dw9714_vcm_suspend(struct device *dev)
>         struct dw9714_device *dw9714_dev = sd_to_dw9714_vcm(sd);
>         int ret, val;
>  
> +       if (pm_runtime_suspended(&client->dev))
> +               return 0;
> +
>         for (val = dw9714_dev->current_val & ~(DW9714_CTRL_STEPS -
> 1);
>              val >= 0; val -= DW9714_CTRL_STEPS) {
>                 ret = dw9714_i2c_write(client,
> @@ -208,7 +223,12 @@ static int __maybe_unused
> dw9714_vcm_suspend(struct device *dev)
>                         dev_err_once(dev, "%s I2C failure: %d",
> __func__, ret);
>                 usleep_range(DW9714_CTRL_DELAY_US,
> DW9714_CTRL_DELAY_US + 10);
>         }
> -       return 0;
> +
> +       ret = regulator_disable(dw9714_dev->vcc);
> +       if (ret)
> +               dev_err(dev, "Failed to disable vcc: %d\n", ret);
> +
> +       return ret;
>  }
>  
>  /*
> @@ -224,6 +244,16 @@ static int  __maybe_unused
> dw9714_vcm_resume(struct device *dev)
>         struct dw9714_device *dw9714_dev = sd_to_dw9714_vcm(sd);
>         int ret, val;
>  
> +       if (pm_runtime_suspended(&client->dev))
> +               return 0;
> +
> +       ret = regulator_enable(dw9714_dev->vcc);
> +       if (ret) {
> +               dev_err(dev, "Failed to enable vcc: %d\n", ret);
> +               return ret;
> +       }
> +       usleep_range(1000, 2000);
> +
>         for (val = dw9714_dev->current_val % DW9714_CTRL_STEPS;
>              val < dw9714_dev->current_val + DW9714_CTRL_STEPS - 1;
>              val += DW9714_CTRL_STEPS) {

hi Sakari and all interested,

any objection to this addition? I run it for a long time now.

thank you,

                              martin



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] media: i2c: dw9714: add optional regulator support
  2021-12-21 17:33 ` Martin Kepplinger
@ 2022-01-20  8:04   ` Martin Kepplinger
  2022-01-20  9:57     ` Sakari Ailus
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Kepplinger @ 2022-01-20  8:04 UTC (permalink / raw)
  To: broonie, sakari.ailus
  Cc: angus, kernel, linux-kernel, linux-media, linux-pm, mchehab

Am Dienstag, dem 21.12.2021 um 18:33 +0100 schrieb Martin Kepplinger:
> Am Montag, dem 29.11.2021 um 13:07 +0100 schrieb Martin Kepplinger:
> > From: Angus Ainslie <angus@akkea.ca>
> > 
> > Allow the dw9714 to control a regulator and adjust suspend() and
> > resume()
> > to support both runtime and system pm.
> > 
> > Signed-off-by: Angus Ainslie <angus@akkea.ca>
> > Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> > ---
> > 
> > 
> > revision history
> > ----------------
> > v3: (thank you Mark and Sakari)
> >  * use regulator_get() instead of regulator_get_optional()
> > 
> > v2: (thank you Mark)
> >  * simplify the regulator_get_optional() error path
> >  * fix regulator usage during probe()
> > https://lore.kernel.org/linux-media/20211126090107.1243558-1-martin.kepplinger@puri.sm/
> > 
> > v1:
> > https://lore.kernel.org/linux-media/20211125080922.978583-1-martin.kepplinger@puri.sm/
> > 
> > 
> > 
> >  drivers/media/i2c/dw9714.c | 32 +++++++++++++++++++++++++++++++-
> >  1 file changed, 31 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/media/i2c/dw9714.c
> > b/drivers/media/i2c/dw9714.c
> > index 3863dfeb8293..81170bbe0e55 100644
> > --- a/drivers/media/i2c/dw9714.c
> > +++ b/drivers/media/i2c/dw9714.c
> > @@ -5,6 +5,7 @@
> >  #include <linux/i2c.h>
> >  #include <linux/module.h>
> >  #include <linux/pm_runtime.h>
> > +#include <linux/regulator/consumer.h>
> >  #include <media/v4l2-ctrls.h>
> >  #include <media/v4l2-device.h>
> >  #include <media/v4l2-event.h>
> > @@ -36,6 +37,7 @@ struct dw9714_device {
> >         struct v4l2_ctrl_handler ctrls_vcm;
> >         struct v4l2_subdev sd;
> >         u16 current_val;
> > +       struct regulator *vcc;
> >  };
> >  
> >  static inline struct dw9714_device *to_dw9714_vcm(struct v4l2_ctrl
> > *ctrl)
> > @@ -145,6 +147,16 @@ static int dw9714_probe(struct i2c_client
> > *client)
> >         if (dw9714_dev == NULL)
> >                 return -ENOMEM;
> >  
> > +       dw9714_dev->vcc = devm_regulator_get(&client->dev, "vcc");
> > +       if (IS_ERR(dw9714_dev->vcc))
> > +               return PTR_ERR(dw9714_dev->vcc);
> > +
> > +       rval = regulator_enable(dw9714_dev->vcc);
> > +       if (rval < 0) {
> > +               dev_err(&client->dev, "failed to enable vcc: %d\n",
> > rval);
> > +               return rval;
> > +       }
> > +
> >         v4l2_i2c_subdev_init(&dw9714_dev->sd, client, &dw9714_ops);
> >         dw9714_dev->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
> >                                 V4L2_SUBDEV_FL_HAS_EVENTS;
> > @@ -200,6 +212,9 @@ static int __maybe_unused
> > dw9714_vcm_suspend(struct device *dev)
> >         struct dw9714_device *dw9714_dev = sd_to_dw9714_vcm(sd);
> >         int ret, val;
> >  
> > +       if (pm_runtime_suspended(&client->dev))
> > +               return 0;
> > +
> >         for (val = dw9714_dev->current_val & ~(DW9714_CTRL_STEPS -
> > 1);
> >              val >= 0; val -= DW9714_CTRL_STEPS) {
> >                 ret = dw9714_i2c_write(client,
> > @@ -208,7 +223,12 @@ static int __maybe_unused
> > dw9714_vcm_suspend(struct device *dev)
> >                         dev_err_once(dev, "%s I2C failure: %d",
> > __func__, ret);
> >                 usleep_range(DW9714_CTRL_DELAY_US,
> > DW9714_CTRL_DELAY_US + 10);
> >         }
> > -       return 0;
> > +
> > +       ret = regulator_disable(dw9714_dev->vcc);
> > +       if (ret)
> > +               dev_err(dev, "Failed to disable vcc: %d\n", ret);
> > +
> > +       return ret;
> >  }
> >  
> >  /*
> > @@ -224,6 +244,16 @@ static int  __maybe_unused
> > dw9714_vcm_resume(struct device *dev)
> >         struct dw9714_device *dw9714_dev = sd_to_dw9714_vcm(sd);
> >         int ret, val;
> >  
> > +       if (pm_runtime_suspended(&client->dev))
> > +               return 0;
> > +
> > +       ret = regulator_enable(dw9714_dev->vcc);
> > +       if (ret) {
> > +               dev_err(dev, "Failed to enable vcc: %d\n", ret);
> > +               return ret;
> > +       }
> > +       usleep_range(1000, 2000);
> > +
> >         for (val = dw9714_dev->current_val % DW9714_CTRL_STEPS;
> >              val < dw9714_dev->current_val + DW9714_CTRL_STEPS - 1;
> >              val += DW9714_CTRL_STEPS) {
> 
> hi Sakari and all interested,
> 
> any objection to this addition? I run it for a long time now.
> 
> thank you,
> 
>                               martin
> 
> 

hi all, patchwork marked this as "changes requested":
https://patchwork.linuxtv.org/project/linux-media/patch/20211129120754.1766570-1-martin.kepplinger@puri.sm/

I'm not aware of changes you wish to this. What do you think?

thank you,

                           martin



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] media: i2c: dw9714: add optional regulator support
  2021-11-29 12:07 [PATCH v3] media: i2c: dw9714: add optional regulator support Martin Kepplinger
  2021-12-21 17:33 ` Martin Kepplinger
@ 2022-01-20  9:56 ` Sakari Ailus
  1 sibling, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2022-01-20  9:56 UTC (permalink / raw)
  To: Martin Kepplinger
  Cc: broonie, angus, kernel, linux-kernel, linux-media, linux-pm, mchehab

Hi Martin,

Apologies for the delay.

On Mon, Nov 29, 2021 at 01:07:54PM +0100, Martin Kepplinger wrote:
> From: Angus Ainslie <angus@akkea.ca>
> 
> Allow the dw9714 to control a regulator and adjust suspend() and resume()
> to support both runtime and system pm.
> 
> Signed-off-by: Angus Ainslie <angus@akkea.ca>
> Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> ---
> 
> 
> revision history
> ----------------
> v3: (thank you Mark and Sakari)
>  * use regulator_get() instead of regulator_get_optional()
> 
> v2: (thank you Mark)
>  * simplify the regulator_get_optional() error path
>  * fix regulator usage during probe()
> https://lore.kernel.org/linux-media/20211126090107.1243558-1-martin.kepplinger@puri.sm/
> 
> v1:
> https://lore.kernel.org/linux-media/20211125080922.978583-1-martin.kepplinger@puri.sm/
> 
> 
> 
>  drivers/media/i2c/dw9714.c | 32 +++++++++++++++++++++++++++++++-
>  1 file changed, 31 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/dw9714.c b/drivers/media/i2c/dw9714.c
> index 3863dfeb8293..81170bbe0e55 100644
> --- a/drivers/media/i2c/dw9714.c
> +++ b/drivers/media/i2c/dw9714.c
> @@ -5,6 +5,7 @@
>  #include <linux/i2c.h>
>  #include <linux/module.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/regulator/consumer.h>
>  #include <media/v4l2-ctrls.h>
>  #include <media/v4l2-device.h>
>  #include <media/v4l2-event.h>
> @@ -36,6 +37,7 @@ struct dw9714_device {
>  	struct v4l2_ctrl_handler ctrls_vcm;
>  	struct v4l2_subdev sd;
>  	u16 current_val;
> +	struct regulator *vcc;
>  };
>  
>  static inline struct dw9714_device *to_dw9714_vcm(struct v4l2_ctrl *ctrl)
> @@ -145,6 +147,16 @@ static int dw9714_probe(struct i2c_client *client)
>  	if (dw9714_dev == NULL)
>  		return -ENOMEM;
>  
> +	dw9714_dev->vcc = devm_regulator_get(&client->dev, "vcc");
> +	if (IS_ERR(dw9714_dev->vcc))
> +		return PTR_ERR(dw9714_dev->vcc);
> +
> +	rval = regulator_enable(dw9714_dev->vcc);

You'll need to disable the regulator in driver's remove callback. That also
depends on runtime PM.

See e.g. ccs_remove() in drivers/media/i2c/ccs/ccs-core.c .

> +	if (rval < 0) {
> +		dev_err(&client->dev, "failed to enable vcc: %d\n", rval);
> +		return rval;
> +	}
> +
>  	v4l2_i2c_subdev_init(&dw9714_dev->sd, client, &dw9714_ops);
>  	dw9714_dev->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
>  				V4L2_SUBDEV_FL_HAS_EVENTS;
> @@ -200,6 +212,9 @@ static int __maybe_unused dw9714_vcm_suspend(struct device *dev)
>  	struct dw9714_device *dw9714_dev = sd_to_dw9714_vcm(sd);
>  	int ret, val;
>  
> +	if (pm_runtime_suspended(&client->dev))
> +		return 0;
> +
>  	for (val = dw9714_dev->current_val & ~(DW9714_CTRL_STEPS - 1);
>  	     val >= 0; val -= DW9714_CTRL_STEPS) {
>  		ret = dw9714_i2c_write(client,
> @@ -208,7 +223,12 @@ static int __maybe_unused dw9714_vcm_suspend(struct device *dev)
>  			dev_err_once(dev, "%s I2C failure: %d", __func__, ret);
>  		usleep_range(DW9714_CTRL_DELAY_US, DW9714_CTRL_DELAY_US + 10);
>  	}
> -	return 0;
> +
> +	ret = regulator_disable(dw9714_dev->vcc);
> +	if (ret)
> +		dev_err(dev, "Failed to disable vcc: %d\n", ret);
> +
> +	return ret;
>  }
>  
>  /*
> @@ -224,6 +244,16 @@ static int  __maybe_unused dw9714_vcm_resume(struct device *dev)
>  	struct dw9714_device *dw9714_dev = sd_to_dw9714_vcm(sd);
>  	int ret, val;
>  
> +	if (pm_runtime_suspended(&client->dev))
> +		return 0;
> +
> +	ret = regulator_enable(dw9714_dev->vcc);
> +	if (ret) {
> +		dev_err(dev, "Failed to enable vcc: %d\n", ret);
> +		return ret;
> +	}
> +	usleep_range(1000, 2000);
> +
>  	for (val = dw9714_dev->current_val % DW9714_CTRL_STEPS;
>  	     val < dw9714_dev->current_val + DW9714_CTRL_STEPS - 1;
>  	     val += DW9714_CTRL_STEPS) {

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] media: i2c: dw9714: add optional regulator support
  2022-01-20  8:04   ` Martin Kepplinger
@ 2022-01-20  9:57     ` Sakari Ailus
  0 siblings, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2022-01-20  9:57 UTC (permalink / raw)
  To: Martin Kepplinger
  Cc: broonie, angus, kernel, linux-kernel, linux-media, linux-pm, mchehab

On Thu, Jan 20, 2022 at 09:04:17AM +0100, Martin Kepplinger wrote:
> Am Dienstag, dem 21.12.2021 um 18:33 +0100 schrieb Martin Kepplinger:
> > Am Montag, dem 29.11.2021 um 13:07 +0100 schrieb Martin Kepplinger:
> > > From: Angus Ainslie <angus@akkea.ca>
> > > 
> > > Allow the dw9714 to control a regulator and adjust suspend() and
> > > resume()
> > > to support both runtime and system pm.
> > > 
> > > Signed-off-by: Angus Ainslie <angus@akkea.ca>
> > > Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> > > ---
> > > 
> > > 
> > > revision history
> > > ----------------
> > > v3: (thank you Mark and Sakari)
> > >  * use regulator_get() instead of regulator_get_optional()
> > > 
> > > v2: (thank you Mark)
> > >  * simplify the regulator_get_optional() error path
> > >  * fix regulator usage during probe()
> > > https://lore.kernel.org/linux-media/20211126090107.1243558-1-martin.kepplinger@puri.sm/
> > > 
> > > v1:
> > > https://lore.kernel.org/linux-media/20211125080922.978583-1-martin.kepplinger@puri.sm/
> > > 
> > > 
> > > 
> > >  drivers/media/i2c/dw9714.c | 32 +++++++++++++++++++++++++++++++-
> > >  1 file changed, 31 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/media/i2c/dw9714.c
> > > b/drivers/media/i2c/dw9714.c
> > > index 3863dfeb8293..81170bbe0e55 100644
> > > --- a/drivers/media/i2c/dw9714.c
> > > +++ b/drivers/media/i2c/dw9714.c
> > > @@ -5,6 +5,7 @@
> > >  #include <linux/i2c.h>
> > >  #include <linux/module.h>
> > >  #include <linux/pm_runtime.h>
> > > +#include <linux/regulator/consumer.h>
> > >  #include <media/v4l2-ctrls.h>
> > >  #include <media/v4l2-device.h>
> > >  #include <media/v4l2-event.h>
> > > @@ -36,6 +37,7 @@ struct dw9714_device {
> > >         struct v4l2_ctrl_handler ctrls_vcm;
> > >         struct v4l2_subdev sd;
> > >         u16 current_val;
> > > +       struct regulator *vcc;
> > >  };
> > >  
> > >  static inline struct dw9714_device *to_dw9714_vcm(struct v4l2_ctrl
> > > *ctrl)
> > > @@ -145,6 +147,16 @@ static int dw9714_probe(struct i2c_client
> > > *client)
> > >         if (dw9714_dev == NULL)
> > >                 return -ENOMEM;
> > >  
> > > +       dw9714_dev->vcc = devm_regulator_get(&client->dev, "vcc");
> > > +       if (IS_ERR(dw9714_dev->vcc))
> > > +               return PTR_ERR(dw9714_dev->vcc);
> > > +
> > > +       rval = regulator_enable(dw9714_dev->vcc);
> > > +       if (rval < 0) {
> > > +               dev_err(&client->dev, "failed to enable vcc: %d\n",
> > > rval);
> > > +               return rval;
> > > +       }
> > > +
> > >         v4l2_i2c_subdev_init(&dw9714_dev->sd, client, &dw9714_ops);
> > >         dw9714_dev->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
> > >                                 V4L2_SUBDEV_FL_HAS_EVENTS;
> > > @@ -200,6 +212,9 @@ static int __maybe_unused
> > > dw9714_vcm_suspend(struct device *dev)
> > >         struct dw9714_device *dw9714_dev = sd_to_dw9714_vcm(sd);
> > >         int ret, val;
> > >  
> > > +       if (pm_runtime_suspended(&client->dev))
> > > +               return 0;
> > > +
> > >         for (val = dw9714_dev->current_val & ~(DW9714_CTRL_STEPS -
> > > 1);
> > >              val >= 0; val -= DW9714_CTRL_STEPS) {
> > >                 ret = dw9714_i2c_write(client,
> > > @@ -208,7 +223,12 @@ static int __maybe_unused
> > > dw9714_vcm_suspend(struct device *dev)
> > >                         dev_err_once(dev, "%s I2C failure: %d",
> > > __func__, ret);
> > >                 usleep_range(DW9714_CTRL_DELAY_US,
> > > DW9714_CTRL_DELAY_US + 10);
> > >         }
> > > -       return 0;
> > > +
> > > +       ret = regulator_disable(dw9714_dev->vcc);
> > > +       if (ret)
> > > +               dev_err(dev, "Failed to disable vcc: %d\n", ret);
> > > +
> > > +       return ret;
> > >  }
> > >  
> > >  /*
> > > @@ -224,6 +244,16 @@ static int  __maybe_unused
> > > dw9714_vcm_resume(struct device *dev)
> > >         struct dw9714_device *dw9714_dev = sd_to_dw9714_vcm(sd);
> > >         int ret, val;
> > >  
> > > +       if (pm_runtime_suspended(&client->dev))
> > > +               return 0;
> > > +
> > > +       ret = regulator_enable(dw9714_dev->vcc);
> > > +       if (ret) {
> > > +               dev_err(dev, "Failed to enable vcc: %d\n", ret);
> > > +               return ret;
> > > +       }
> > > +       usleep_range(1000, 2000);
> > > +
> > >         for (val = dw9714_dev->current_val % DW9714_CTRL_STEPS;
> > >              val < dw9714_dev->current_val + DW9714_CTRL_STEPS - 1;
> > >              val += DW9714_CTRL_STEPS) {
> > 
> > hi Sakari and all interested,
> > 
> > any objection to this addition? I run it for a long time now.
> > 
> > thank you,
> > 
> >                               martin
> > 
> > 
> 
> hi all, patchwork marked this as "changes requested":
> https://patchwork.linuxtv.org/project/linux-media/patch/20211129120754.1766570-1-martin.kepplinger@puri.sm/
> 
> I'm not aware of changes you wish to this. What do you think?

Oops! I wrote a reply but forgot to send it. I've just sent that.

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-01-20  9:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-29 12:07 [PATCH v3] media: i2c: dw9714: add optional regulator support Martin Kepplinger
2021-12-21 17:33 ` Martin Kepplinger
2022-01-20  8:04   ` Martin Kepplinger
2022-01-20  9:57     ` Sakari Ailus
2022-01-20  9:56 ` Sakari Ailus

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).