linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mt9p031: Use bulk regulator API
@ 2013-06-08  7:55 Laurent Pinchart
  2013-06-08 13:20 ` Fabio Estevam
  0 siblings, 1 reply; 6+ messages in thread
From: Laurent Pinchart @ 2013-06-08  7:55 UTC (permalink / raw)
  To: linux-media

The sensor is powered by three supplies. Use the bulk regulator API to
enable and disable them instead of performing the operations manually.
This fixes a warning caused by ignoring the return value of
regulator_enable().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/i2c/mt9p031.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c
index 6187416..2a71a0d 100644
--- a/drivers/media/i2c/mt9p031.c
+++ b/drivers/media/i2c/mt9p031.c
@@ -126,9 +126,7 @@ struct mt9p031 {
 	int power_count;
 
 	struct clk *clk;
-	struct regulator *vaa;
-	struct regulator *vdd;
-	struct regulator *vdd_io;
+	struct regulator_bulk_data regulators[3];
 
 	enum mt9p031_model model;
 	struct aptina_pll pll;
@@ -273,6 +271,8 @@ static inline int mt9p031_pll_disable(struct mt9p031 *mt9p031)
 
 static int mt9p031_power_on(struct mt9p031 *mt9p031)
 {
+	int ret;
+
 	/* Ensure RESET_BAR is low */
 	if (gpio_is_valid(mt9p031->reset)) {
 		gpio_set_value(mt9p031->reset, 0);
@@ -280,9 +280,10 @@ static int mt9p031_power_on(struct mt9p031 *mt9p031)
 	}
 
 	/* Bring up the supplies */
-	regulator_enable(mt9p031->vdd);
-	regulator_enable(mt9p031->vdd_io);
-	regulator_enable(mt9p031->vaa);
+	ret = regulator_bulk_enable(ARRAY_SIZE(mt9p031->regulators),
+				   mt9p031->regulators);
+	if (ret < 0)
+		return ret;
 
 	/* Emable clock */
 	if (mt9p031->clk)
@@ -304,9 +305,8 @@ static void mt9p031_power_off(struct mt9p031 *mt9p031)
 		usleep_range(1000, 2000);
 	}
 
-	regulator_disable(mt9p031->vaa);
-	regulator_disable(mt9p031->vdd_io);
-	regulator_disable(mt9p031->vdd);
+	regulator_bulk_disable(ARRAY_SIZE(mt9p031->regulators),
+			       mt9p031->regulators);
 
 	if (mt9p031->clk)
 		clk_disable_unprepare(mt9p031->clk);
@@ -986,12 +986,12 @@ static int mt9p031_probe(struct i2c_client *client,
 	mt9p031->model = did->driver_data;
 	mt9p031->reset = -1;
 
-	mt9p031->vaa = devm_regulator_get(&client->dev, "vaa");
-	mt9p031->vdd = devm_regulator_get(&client->dev, "vdd");
-	mt9p031->vdd_io = devm_regulator_get(&client->dev, "vdd_io");
+	mt9p031->regulators[0].supply = "vdd";
+	mt9p031->regulators[1].supply = "vdd_io";
+	mt9p031->regulators[2].supply = "vaa";
 
-	if (IS_ERR(mt9p031->vaa) || IS_ERR(mt9p031->vdd) ||
-	    IS_ERR(mt9p031->vdd_io)) {
+	ret = devm_regulator_bulk_get(&client->dev, 3, mt9p031->regulators);
+	if (ret < 0) {
 		dev_err(&client->dev, "Unable to get regulators\n");
 		return -ENODEV;
 	}
-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH] mt9p031: Use bulk regulator API
  2013-06-08  7:55 [PATCH] mt9p031: Use bulk regulator API Laurent Pinchart
@ 2013-06-08 13:20 ` Fabio Estevam
  2013-06-08 13:24   ` Fabio Estevam
  2013-06-10  9:48   ` Laurent Pinchart
  0 siblings, 2 replies; 6+ messages in thread
From: Fabio Estevam @ 2013-06-08 13:20 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: linux-media

On Sat, Jun 8, 2013 at 4:55 AM, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:

> -       if (IS_ERR(mt9p031->vaa) || IS_ERR(mt9p031->vdd) ||
> -           IS_ERR(mt9p031->vdd_io)) {
> +       ret = devm_regulator_bulk_get(&client->dev, 3, mt9p031->regulators);
> +       if (ret < 0) {
>                 dev_err(&client->dev, "Unable to get regulators\n");
>                 return -ENODEV;

You should do a 'return ret' here instead.

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

* Re: [PATCH] mt9p031: Use bulk regulator API
  2013-06-08 13:20 ` Fabio Estevam
@ 2013-06-08 13:24   ` Fabio Estevam
  2013-06-10  9:49     ` Laurent Pinchart
  2013-06-10  9:48   ` Laurent Pinchart
  1 sibling, 1 reply; 6+ messages in thread
From: Fabio Estevam @ 2013-06-08 13:24 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: linux-media

On Sat, Jun 8, 2013 at 10:20 AM, Fabio Estevam <festevam@gmail.com> wrote:
> On Sat, Jun 8, 2013 at 4:55 AM, Laurent Pinchart
> <laurent.pinchart@ideasonboard.com> wrote:
>
>> -       if (IS_ERR(mt9p031->vaa) || IS_ERR(mt9p031->vdd) ||
>> -           IS_ERR(mt9p031->vdd_io)) {
>> +       ret = devm_regulator_bulk_get(&client->dev, 3, mt9p031->regulators);

and you could use ARRAY_SIZE(mt9p031->regulators) instead of the hardcoded '3'.

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

* Re: [PATCH] mt9p031: Use bulk regulator API
  2013-06-08 13:20 ` Fabio Estevam
  2013-06-08 13:24   ` Fabio Estevam
@ 2013-06-10  9:48   ` Laurent Pinchart
  1 sibling, 0 replies; 6+ messages in thread
From: Laurent Pinchart @ 2013-06-10  9:48 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: linux-media

Hi Fabio,

On Saturday 08 June 2013 10:20:42 Fabio Estevam wrote:
> On Sat, Jun 8, 2013 at 4:55 AM, Laurent Pinchart wrote:
> > -       if (IS_ERR(mt9p031->vaa) || IS_ERR(mt9p031->vdd) ||
> > -           IS_ERR(mt9p031->vdd_io)) {
> > +       ret = devm_regulator_bulk_get(&client->dev, 3,
> > mt9p031->regulators); +       if (ret < 0) {
> > 
> >                 dev_err(&client->dev, "Unable to get regulators\n");
> >                 return -ENODEV;
> 
> You should do a 'return ret' here instead.

Good point, I'll fix that.

-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH] mt9p031: Use bulk regulator API
  2013-06-08 13:24   ` Fabio Estevam
@ 2013-06-10  9:49     ` Laurent Pinchart
  0 siblings, 0 replies; 6+ messages in thread
From: Laurent Pinchart @ 2013-06-10  9:49 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: linux-media

Hi Fabio,

On Saturday 08 June 2013 10:24:58 Fabio Estevam wrote:
> On Sat, Jun 8, 2013 at 10:20 AM, Fabio Estevam wrote:
> > On Sat, Jun 8, 2013 at 4:55 AM, Laurent Pinchart wrote:
> >> -       if (IS_ERR(mt9p031->vaa) || IS_ERR(mt9p031->vdd) ||
> >> -           IS_ERR(mt9p031->vdd_io)) {
> >> +       ret = devm_regulator_bulk_get(&client->dev, 3,
> >> mt9p031->regulators);
>
> and you could use ARRAY_SIZE(mt9p031->regulators) instead of the hardcoded
> '3'.

Right, but on the other hand I initialize the regulators array right before 
using hard-coded indices, so it doesn't matter much in this case.

-- 
Regards,

Laurent Pinchart


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

* [PATCH] mt9p031: Use bulk regulator API
@ 2013-06-10  9:51 Laurent Pinchart
  0 siblings, 0 replies; 6+ messages in thread
From: Laurent Pinchart @ 2013-06-10  9:51 UTC (permalink / raw)
  To: linux-media; +Cc: Fabio Estevam

The sensor is powered by three supplies. Use the bulk regulator API to
enable and disable them instead of performing the operations manually.
This fixes a warning caused by ignoring the return value of
regulator_enable().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/i2c/mt9p031.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

Changes since v1:

- Return the devm_regulator_bulk_get() return code instead of -ENODEV

diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c
index 6187416..c93640b 100644
--- a/drivers/media/i2c/mt9p031.c
+++ b/drivers/media/i2c/mt9p031.c
@@ -126,9 +126,7 @@ struct mt9p031 {
 	int power_count;
 
 	struct clk *clk;
-	struct regulator *vaa;
-	struct regulator *vdd;
-	struct regulator *vdd_io;
+	struct regulator_bulk_data regulators[3];
 
 	enum mt9p031_model model;
 	struct aptina_pll pll;
@@ -273,6 +271,8 @@ static inline int mt9p031_pll_disable(struct mt9p031 *mt9p031)
 
 static int mt9p031_power_on(struct mt9p031 *mt9p031)
 {
+	int ret;
+
 	/* Ensure RESET_BAR is low */
 	if (gpio_is_valid(mt9p031->reset)) {
 		gpio_set_value(mt9p031->reset, 0);
@@ -280,9 +280,10 @@ static int mt9p031_power_on(struct mt9p031 *mt9p031)
 	}
 
 	/* Bring up the supplies */
-	regulator_enable(mt9p031->vdd);
-	regulator_enable(mt9p031->vdd_io);
-	regulator_enable(mt9p031->vaa);
+	ret = regulator_bulk_enable(ARRAY_SIZE(mt9p031->regulators),
+				   mt9p031->regulators);
+	if (ret < 0)
+		return ret;
 
 	/* Emable clock */
 	if (mt9p031->clk)
@@ -304,9 +305,8 @@ static void mt9p031_power_off(struct mt9p031 *mt9p031)
 		usleep_range(1000, 2000);
 	}
 
-	regulator_disable(mt9p031->vaa);
-	regulator_disable(mt9p031->vdd_io);
-	regulator_disable(mt9p031->vdd);
+	regulator_bulk_disable(ARRAY_SIZE(mt9p031->regulators),
+			       mt9p031->regulators);
 
 	if (mt9p031->clk)
 		clk_disable_unprepare(mt9p031->clk);
@@ -986,14 +986,14 @@ static int mt9p031_probe(struct i2c_client *client,
 	mt9p031->model = did->driver_data;
 	mt9p031->reset = -1;
 
-	mt9p031->vaa = devm_regulator_get(&client->dev, "vaa");
-	mt9p031->vdd = devm_regulator_get(&client->dev, "vdd");
-	mt9p031->vdd_io = devm_regulator_get(&client->dev, "vdd_io");
+	mt9p031->regulators[0].supply = "vdd";
+	mt9p031->regulators[1].supply = "vdd_io";
+	mt9p031->regulators[2].supply = "vaa";
 
-	if (IS_ERR(mt9p031->vaa) || IS_ERR(mt9p031->vdd) ||
-	    IS_ERR(mt9p031->vdd_io)) {
+	ret = devm_regulator_bulk_get(&client->dev, 3, mt9p031->regulators);
+	if (ret < 0) {
 		dev_err(&client->dev, "Unable to get regulators\n");
-		return -ENODEV;
+		return ret;
 	}
 
 	v4l2_ctrl_handler_init(&mt9p031->ctrls, ARRAY_SIZE(mt9p031_ctrls) + 6);
-- 
Regards,

Laurent Pinchart


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

end of thread, other threads:[~2013-06-10  9:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-08  7:55 [PATCH] mt9p031: Use bulk regulator API Laurent Pinchart
2013-06-08 13:20 ` Fabio Estevam
2013-06-08 13:24   ` Fabio Estevam
2013-06-10  9:49     ` Laurent Pinchart
2013-06-10  9:48   ` Laurent Pinchart
2013-06-10  9:51 Laurent Pinchart

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