mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Jacopo Mondi <jacopo@jmondi.org>
Cc: Jacopo Mondi <jacopo+renesas@jmondi.org>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Magnus Damm <magnus.damm@gmail.com>,
	Kieran Bingham <kieran.bingham@ideasonboard.com>,
	Rob Herring <robh+dt@kernel.org>,
	linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/5] media: i2c: max9286: Use "maxim,gpio-poc" property
Date: Sat, 17 Apr 2021 01:18:25 +0300	[thread overview]
Message-ID: <YHoNMXQWd5XyeI/I@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20210416074307.mtd7bcv3yj6zekt6@uno.localdomain>

Hi Jacopo,

On Fri, Apr 16, 2021 at 09:43:07AM +0200, Jacopo Mondi wrote:
> On Thu, Apr 15, 2021 at 10:14:05PM +0300, Laurent Pinchart wrote:
> > > > > +		/* GPIO values default to high */
> > > > > +		priv->gpio_state = BIT(0) | BIT(1);
> > > >
> > > > Why is that ?
> > > >
> > > As the set/get functions of gpiochip use the gpio_state and I wanted
> > > to use the same functions for the internal gpio handling I used
> > > gpio_state in gpio_set(). My thinking was that in this way altering
> > > the gpio line would be visibile to gpio consumers... which we don't
> > > have as I won't register the gpio-controller :)
> >
> > My question was why they default to high here, when they default to low
> > when there's a gpio-controller property.
> 
> Oh, got it now... the two output lines are high by default :)
> Why do you say "they default to low when there's a gpio-controller
> property" ? When does that requirement come from ?

My bad, I thought they were set to 0 in that case, but they're not.

How about moving this initialization from max9286_register_gpio() to the
beginning of this function, as it's shared by both cases ?

> > > > > +		priv->regulator = NULL;
> > > >
> > > > As priv is initialized to 0, you can skip this.
> > >
> > > Yes, I liked it explicit as it is used as flag, but it is not
> > > required...
> > >
> > > > > +
> > > > > +		return 0;
> > > > > +	}
> > > > > +
> > > > > +	ret = max9286_register_gpio(priv);
> > > > > +	if (ret)
> > > > > +		return ret;
> > > > > +
> > > > > +	priv->regulator = devm_regulator_get(dev, "poc");
> > > > > +	if (IS_ERR(priv->regulator)) {
> > > > > +		if (PTR_ERR(priv->regulator) != -EPROBE_DEFER)
> > > > > +			dev_err(dev, "Unable to get PoC regulator (%ld)\n",
> > > > > +				PTR_ERR(priv->regulator));
> > > > > +		return PTR_ERR(priv->regulator);
> > > > > +	}
> > > > > +
> > > > > +	return 0;
> > > > > +}
> > > > > +
> > > > > +static int max9286_poc_enable(struct max9286_priv *priv, bool enable)
> > > > > +{
> > > > > +	int ret;
> > > > > +
> > > > > +	/* If "poc-gpio" is used, toggle the line and do not use regulator. */
> > > > > +	if (!priv->regulator)
> > > > > +		return max9286_gpio_set(priv, priv->gpio_poc,
> > > > > +					enable ^ priv->gpio_poc_flags);
> > > > > +
> > > > > +	/* Otherwise PoC is controlled using a regulator. */
> > > > > +	if (enable) {
> > > > > +		ret = regulator_enable(priv->regulator);
> > > > > +		if (ret < 0) {
> > > > > +			dev_err(&priv->client->dev, "Unable to turn PoC on\n");
> > > >
> > > > As error message when max9286_gpio_set() fails (at least in the enable
> > > > case) would be good too. Bonus points if there's a single dev_err()
> > > > call.
> > >
> > > I'll see how it looks like
> > >
> > > > > +			return ret;
> > > > > +		}
> > > > > +
> > > > > +		return 0;
> > > > > +	}
> > > > > +
> > > > > +	return regulator_disable(priv->regulator);
> > > > > +}
> > > > > +
> > > > >  static int max9286_init(struct device *dev)
> > > > >  {
> > > > >  	struct max9286_priv *priv;
> > > > > @@ -1078,17 +1158,14 @@ static int max9286_init(struct device *dev)
> > > > >  	client = to_i2c_client(dev);
> > > > >  	priv = i2c_get_clientdata(client);
> > > > >
> > > > > -	/* Enable the bus power. */
> > > > > -	ret = regulator_enable(priv->regulator);
> > > > > -	if (ret < 0) {
> > > > > -		dev_err(&client->dev, "Unable to turn PoC on\n");
> > > > > +	ret = max9286_poc_enable(priv, true);
> > > > > +	if (ret)
> > > > >  		return ret;
> > > > > -	}
> > > > >
> > > > >  	ret = max9286_setup(priv);
> > > > >  	if (ret) {
> > > > >  		dev_err(dev, "Unable to setup max9286\n");
> > > > > -		goto err_regulator;
> > > > > +		goto err_poc_disable;
> > > > >  	}
> > > > >
> > > > >  	/*
> > > > > @@ -1098,7 +1175,7 @@ static int max9286_init(struct device *dev)
> > > > >  	ret = max9286_v4l2_register(priv);
> > > > >  	if (ret) {
> > > > >  		dev_err(dev, "Failed to register with V4L2\n");
> > > > > -		goto err_regulator;
> > > > > +		goto err_poc_disable;
> > > > >  	}
> > > > >
> > > > >  	ret = max9286_i2c_mux_init(priv);
> > > > > @@ -1114,8 +1191,8 @@ static int max9286_init(struct device *dev)
> > > > >
> > > > >  err_v4l2_register:
> > > > >  	max9286_v4l2_unregister(priv);
> > > > > -err_regulator:
> > > > > -	regulator_disable(priv->regulator);
> > > > > +err_poc_disable:
> > > > > +	max9286_poc_enable(priv, false);
> > > > >
> > > > >  	return ret;
> > > > >  }
> > > > > @@ -1286,20 +1363,10 @@ static int max9286_probe(struct i2c_client *client)
> > > > >  	 */
> > > > >  	max9286_configure_i2c(priv, false);
> > > > >
> > > > > -	ret = max9286_register_gpio(priv);
> > > > > +	ret = max9286_parse_gpios(priv);
> > > > >  	if (ret)
> > > > >  		goto err_powerdown;
> > > > >
> > > > > -	priv->regulator = devm_regulator_get(&client->dev, "poc");
> > > > > -	if (IS_ERR(priv->regulator)) {
> > > > > -		if (PTR_ERR(priv->regulator) != -EPROBE_DEFER)
> > > > > -			dev_err(&client->dev,
> > > > > -				"Unable to get PoC regulator (%ld)\n",
> > > > > -				PTR_ERR(priv->regulator));
> > > > > -		ret = PTR_ERR(priv->regulator);
> > > > > -		goto err_powerdown;
> > > > > -	}
> > > > > -
> > > > >  	ret = max9286_parse_dt(priv);
> > > > >  	if (ret)
> > > > >  		goto err_powerdown;
> > > > > @@ -1326,7 +1393,7 @@ static int max9286_remove(struct i2c_client *client)
> > > > >
> > > > >  	max9286_v4l2_unregister(priv);
> > > > >
> > > > > -	regulator_disable(priv->regulator);
> > > > > +	max9286_poc_enable(priv, false);
> > > > >
> > > > >  	gpiod_set_value_cansleep(priv->gpiod_pwdn, 0);
> > > > >

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2021-04-16 22:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-14 13:51 [PATCH v3 0/5] arm64: dts: renesas: Enable GMSL on R8A77970 V3M Eagle Jacopo Mondi
2021-04-14 13:51 ` [PATCH v3 1/5] dt-bindings: media: max9286: Define 'maxim,gpio-poc' Jacopo Mondi
2021-04-14 23:47   ` Laurent Pinchart
2021-04-15  6:54     ` Jacopo Mondi
2021-04-15  6:59       ` Geert Uytterhoeven
2021-04-14 13:51 ` [PATCH v3 2/5] media: i2c: max9286: Use "maxim,gpio-poc" property Jacopo Mondi
2021-04-15  0:00   ` Laurent Pinchart
2021-04-15  6:58     ` Jacopo Mondi
2021-04-15 19:14       ` Laurent Pinchart
2021-04-16  7:43         ` Jacopo Mondi
2021-04-16 22:18           ` Laurent Pinchart [this message]
2021-04-14 13:51 ` [PATCH v3 3/5] arm64: dts: renesas: eagle: Enable MAX9286 Jacopo Mondi
2021-04-14 23:49   ` Laurent Pinchart
2021-04-14 13:51 ` [PATCH v3 4/5] arm64: dts: renesas: eagle: Add GMSL .dtsi Jacopo Mondi
2021-04-14 23:53   ` Laurent Pinchart
2021-04-15  7:00     ` Jacopo Mondi
2021-04-14 13:51 ` [PATCH v3 5/5] arm64: dts: renesas: eagle: Include eagle-gmsl Jacopo Mondi
2021-04-14 23:50   ` Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YHoNMXQWd5XyeI/I@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=devicetree@vger.kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=jacopo+renesas@jmondi.org \
    --cc=jacopo@jmondi.org \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®