mbox series

[v4,0/7] arm64: dts: renesas: Enable GMSL on R8A77970 V3M Eagle

Message ID 20210415122602.87697-1-jacopo+renesas@jmondi.org
Headers show
Series arm64: dts: renesas: Enable GMSL on R8A77970 V3M Eagle | expand

Message

Jacopo Mondi April 15, 2021, 12:25 p.m. UTC
Following the recent v3, this new version:

- Two new patches (minor fixes)
- Address Laurent's comments on gpio-poc bindings and implementation.
  Naming might still be discussed
- Address Laurent's comments on DTS patches
- Last patch not for inclusion

Thanks
   j

Jacopo Mondi (4):
  dt-bindings: media: max9286: Re-indent example
  dt-bindings: media: max9286: Define 'maxim,gpio-poc'
  media: i2c: max9286: Use "maxim,gpio-poc" property
  arm64: dts: renesas: r8a77970: Add csi40 port@0

Kieran Bingham (3):
  arm64: dts: renesas: eagle: Enable MAX9286
  arm64: dts: renesas: eagle: Add GMSL .dtsi
  DNI: arm64: dts: renesas: eagle: Include eagle-gmsl

 .../bindings/media/i2c/maxim,max9286.yaml     | 279 +++++++++++-------
 arch/arm64/boot/dts/renesas/eagle-gmsl.dtsi   | 178 +++++++++++
 .../arm64/boot/dts/renesas/r8a77970-eagle.dts | 114 +++++++
 arch/arm64/boot/dts/renesas/r8a77970.dtsi     |   4 +
 drivers/media/i2c/max9286.c                   | 119 ++++++--
 5 files changed, 563 insertions(+), 131 deletions(-)
 create mode 100644 arch/arm64/boot/dts/renesas/eagle-gmsl.dtsi

--
2.31.1

Comments

Laurent Pinchart April 15, 2021, 2:42 p.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Thu, Apr 15, 2021 at 02:25:56PM +0200, Jacopo Mondi wrote:
> The dt-bindings examples are usually indented with 4 spaces.
> 
> The maxim,max9286 schema has the example indented with only
> 2 spaces, re-indent it.
> 
> Cosmetic change only.
> 
> Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>

Tested by applying and verifying that `git show -b` shows an empty diff.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  .../bindings/media/i2c/maxim,max9286.yaml     | 214 +++++++++---------
>  1 file changed, 107 insertions(+), 107 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml b/Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml
> index ee16102fdfe7..0e7162998b77 100644
> --- a/Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml
> +++ b/Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml
> @@ -191,140 +191,140 @@ examples:
>      #include <dt-bindings/gpio/gpio.h>
>  
>      i2c@e66d8000 {
> -      #address-cells = <1>;
> -      #size-cells = <0>;
> +        #address-cells = <1>;
> +        #size-cells = <0>;
>  
> -      reg = <0 0xe66d8000>;
> +        reg = <0 0xe66d8000>;
>  
> -      gmsl-deserializer@2c {
> -        compatible = "maxim,max9286";
> -        reg = <0x2c>;
> -        poc-supply = <&camera_poc_12v>;
> -        enable-gpios = <&gpio 13 GPIO_ACTIVE_HIGH>;
> +        gmsl-deserializer@2c {
> +            compatible = "maxim,max9286";
> +            reg = <0x2c>;
> +            poc-supply = <&camera_poc_12v>;
> +            enable-gpios = <&gpio 13 GPIO_ACTIVE_HIGH>;
>  
> -        gpio-controller;
> -        #gpio-cells = <2>;
> +            gpio-controller;
> +            #gpio-cells = <2>;
>  
> -        maxim,reverse-channel-microvolt = <170000>;
> +            maxim,reverse-channel-microvolt = <170000>;
>  
> -        ports {
> -          #address-cells = <1>;
> -          #size-cells = <0>;
> +            ports {
> +                #address-cells = <1>;
> +                #size-cells = <0>;
>  
> -          port@0 {
> -            reg = <0>;
> +                port@0 {
> +                    reg = <0>;
>  
> -            max9286_in0: endpoint {
> -              remote-endpoint = <&rdacm20_out0>;
> -            };
> -          };
> -
> -          port@1 {
> -            reg = <1>;
> -
> -            max9286_in1: endpoint {
> -              remote-endpoint = <&rdacm20_out1>;
> -            };
> -          };
> -
> -          port@2 {
> -            reg = <2>;
> -
> -            max9286_in2: endpoint {
> -              remote-endpoint = <&rdacm20_out2>;
> -            };
> -          };
> +                    max9286_in0: endpoint {
> +                        remote-endpoint = <&rdacm20_out0>;
> +                    };
> +                };
>  
> -          port@3 {
> -            reg = <3>;
> +                port@1 {
> +                    reg = <1>;
>  
> -            max9286_in3: endpoint {
> -              remote-endpoint = <&rdacm20_out3>;
> -            };
> -          };
> +                    max9286_in1: endpoint {
> +                        remote-endpoint = <&rdacm20_out1>;
> +                    };
> +                };
>  
> -          port@4 {
> -            reg = <4>;
> +                port@2 {
> +                    reg = <2>;
>  
> -            max9286_out: endpoint {
> -              data-lanes = <1 2 3 4>;
> -              remote-endpoint = <&csi40_in>;
> -            };
> -          };
> -        };
> +                    max9286_in2: endpoint {
> +                        remote-endpoint = <&rdacm20_out2>;
> +                    };
> +                };
>  
> -        i2c-mux {
> -          #address-cells = <1>;
> -          #size-cells = <0>;
> +                port@3 {
> +                    reg = <3>;
>  
> -          i2c@0 {
> -            #address-cells = <1>;
> -            #size-cells = <0>;
> -            reg = <0>;
> +                    max9286_in3: endpoint {
> +                        remote-endpoint = <&rdacm20_out3>;
> +                    };
> +                };
>  
> -            camera@51 {
> -              compatible = "imi,rdacm20";
> -              reg = <0x51>, <0x61>;
> +                port@4 {
> +                    reg = <4>;
>  
> -              port {
> -                rdacm20_out0: endpoint {
> -                  remote-endpoint = <&max9286_in0>;
> +                    max9286_out: endpoint {
> +                        data-lanes = <1 2 3 4>;
> +                        remote-endpoint = <&csi40_in>;
> +                    };
>                  };
> -              };
> -
>              };
> -          };
> -
> -          i2c@1 {
> -            #address-cells = <1>;
> -            #size-cells = <0>;
> -            reg = <1>;
>  
> -            camera@52 {
> -              compatible = "imi,rdacm20";
> -              reg = <0x52>, <0x62>;
> +            i2c-mux {
> +                #address-cells = <1>;
> +                #size-cells = <0>;
>  
> -              port {
> -                rdacm20_out1: endpoint {
> -                  remote-endpoint = <&max9286_in1>;
> -                };
> -              };
> -            };
> -          };
> +                i2c@0 {
> +                    #address-cells = <1>;
> +                    #size-cells = <0>;
> +                    reg = <0>;
>  
> -          i2c@2 {
> -            #address-cells = <1>;
> -            #size-cells = <0>;
> -            reg = <2>;
> +                    camera@51 {
> +                        compatible = "imi,rdacm20";
> +                        reg = <0x51>, <0x61>;
>  
> -            camera@53 {
> -              compatible = "imi,rdacm20";
> -              reg = <0x53>, <0x63>;
> +                        port {
> +                            rdacm20_out0: endpoint {
> +                                remote-endpoint = <&max9286_in0>;
> +                            };
> +                        };
>  
> -              port {
> -                rdacm20_out2: endpoint {
> -                  remote-endpoint = <&max9286_in2>;
> +                    };
>                  };
> -              };
> -            };
> -          };
>  
> -          i2c@3 {
> -            #address-cells = <1>;
> -            #size-cells = <0>;
> -            reg = <3>;
> +                i2c@1 {
> +                    #address-cells = <1>;
> +                    #size-cells = <0>;
> +                    reg = <1>;
> +
> +                    camera@52 {
> +                        compatible = "imi,rdacm20";
> +                        reg = <0x52>, <0x62>;
> +
> +                        port {
> +                            rdacm20_out1: endpoint {
> +                                remote-endpoint = <&max9286_in1>;
> +                            };
> +                        };
> +                    };
> +                };
>  
> -            camera@54 {
> -              compatible = "imi,rdacm20";
> -              reg = <0x54>, <0x64>;
> +                i2c@2 {
> +                    #address-cells = <1>;
> +                    #size-cells = <0>;
> +                    reg = <2>;
> +
> +                    camera@53 {
> +                        compatible = "imi,rdacm20";
> +                        reg = <0x53>, <0x63>;
> +
> +                        port {
> +                            rdacm20_out2: endpoint {
> +                                remote-endpoint = <&max9286_in2>;
> +                            };
> +                        };
> +                    };
> +                };
>  
> -              port {
> -                rdacm20_out3: endpoint {
> -                  remote-endpoint = <&max9286_in3>;
> +                i2c@3 {
> +                    #address-cells = <1>;
> +                    #size-cells = <0>;
> +                    reg = <3>;
> +
> +                    camera@54 {
> +                        compatible = "imi,rdacm20";
> +                        reg = <0x54>, <0x64>;
> +
> +                        port {
> +                            rdacm20_out3: endpoint {
> +                                remote-endpoint = <&max9286_in3>;
> +                            };
> +                        };
> +                    };
>                  };
> -              };
>              };
> -          };
>          };
> -      };
>      };
Laurent Pinchart April 15, 2021, 7:19 p.m. UTC | #2
Hi Jacopo,

Thank you for the patch.

On Thu, Apr 15, 2021 at 02:25:58PM +0200, Jacopo Mondi wrote:
> The 'maxim,gpio-poc' property is used when the remote camera
> power-over-coax is controlled by one of the MAX9286 gpio lines,
> to instruct the driver about which line to use and what the line
> polarity is.
> 
> Add to the max9286 driver support for parsing the newly introduced
> property and use it if available in place of the usual supply, as it is
> not possible to establish one as consumer of the max9286 gpio
> controller.
> 
> If the new property is present, no gpio controller is registered and
> 'poc-supply' is ignored.
> 
> In order to maximize code re-use, break out the max9286 gpio handling
> function so that they can be used by the gpio controller through the
> gpio-consumer API, or directly by the driver code.
> 
> Wrap the power up and power down routines to their own function to
> be able to use either the gpio line directly or the supply. This will
> make it easier to control the remote camera power at run time.
> 
> Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
> ---
>  drivers/media/i2c/max9286.c | 119 ++++++++++++++++++++++++++++--------
>  1 file changed, 93 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
> index 6fd4d59fcc72..a8b37783d2ef 100644
> --- a/drivers/media/i2c/max9286.c
> +++ b/drivers/media/i2c/max9286.c
> @@ -15,6 +15,7 @@
>  #include <linux/fwnode.h>
>  #include <linux/gpio/consumer.h>
>  #include <linux/gpio/driver.h>
> +#include <linux/gpio/machine.h>
>  #include <linux/i2c.h>
>  #include <linux/i2c-mux.h>
>  #include <linux/module.h>
> @@ -165,6 +166,9 @@ struct max9286_priv {
>  
>  	u32 reverse_channel_mv;
>  
> +	u32 gpio_poc;
> +	u32 gpio_poc_flags;
> +
>  	struct v4l2_ctrl_handler ctrls;
>  	struct v4l2_ctrl *pixelrate;
>  
> @@ -1022,8 +1026,19 @@ static int max9286_setup(struct max9286_priv *priv)
>  	return 0;
>  }
>  
> -static void max9286_gpio_set(struct gpio_chip *chip,
> -			     unsigned int offset, int value)
> +static int max9286_gpio_set(struct max9286_priv *priv, unsigned int offset,
> +			    int value)
> +{
> +	int ret = max9286_read(priv, 0x0f);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = value ? (ret & 0x3) | BIT(offset) : (ret & 0x3) & ~BIT(offset);
> +	return max9286_write(priv, 0x0f, MAX9286_0X0F_RESERVED | ret);
> +}

Was there anything wrong with v3, sharing the implementation between the
gpio-controller and non gpio-controller cases ? In particular, caching
the state locally seems better, max9286_read() goes over I2C and is thus
slow.

> +
> +static void max9286_gpiochip_set(struct gpio_chip *chip,
> +				 unsigned int offset, int value)
>  {
>  	struct max9286_priv *priv = gpiochip_get_data(chip);
>  
> @@ -1035,7 +1050,7 @@ static void max9286_gpio_set(struct gpio_chip *chip,
>  	max9286_write(priv, 0x0f, MAX9286_0X0F_RESERVED | priv->gpio_state);
>  }
>  
> -static int max9286_gpio_get(struct gpio_chip *chip, unsigned int offset)
> +static int max9286_gpiochip_get(struct gpio_chip *chip, unsigned int offset)
>  {
>  	struct max9286_priv *priv = gpiochip_get_data(chip);
>  
> @@ -1055,8 +1070,8 @@ static int max9286_register_gpio(struct max9286_priv *priv)
>  	gpio->of_node = dev->of_node;
>  	gpio->ngpio = 2;
>  	gpio->base = -1;
> -	gpio->set = max9286_gpio_set;
> -	gpio->get = max9286_gpio_get;
> +	gpio->set = max9286_gpiochip_set;
> +	gpio->get = max9286_gpiochip_get;
>  	gpio->can_sleep = true;
>  
>  	/* GPIO values default to high */
> @@ -1069,6 +1084,71 @@ static int max9286_register_gpio(struct max9286_priv *priv)
>  	return ret;
>  }
>  
> +static int max9286_parse_gpios(struct max9286_priv *priv)
> +{
> +	struct device *dev = &priv->client->dev;
> +	u32 gpio_poc[2];
> +	int ret;
> +
> +	/*
> +	 * Parse the "gpio-poc" vendor property. If the camera power is
> +	 * controlled by one of the MAX9286 gpio lines, do not register
> +	 * the gpio controller and ignore 'poc-supply'.
> +	 */
> +	ret = of_property_read_u32_array(dev->of_node,
> +					 "maxim,gpio-poc", gpio_poc, 2);
> +	if (!ret) {
> +		priv->gpio_poc = gpio_poc[0];
> +		priv->gpio_poc_flags = gpio_poc[1];
> +		if (priv->gpio_poc > 1 ||
> +		    (priv->gpio_poc_flags != GPIO_ACTIVE_HIGH &&
> +		     priv->gpio_poc_flags != GPIO_ACTIVE_LOW)) {
> +			dev_err(dev, "Invalid 'gpio-poc': (%u %u)\n",
> +				priv->gpio_poc, priv->gpio_poc_flags);
> +			return -EINVAL;
> +		}
> +
> +		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 (enable)
> +		ret = priv->regulator
> +		    ? regulator_enable(priv->regulator)
> +		    : max9286_gpio_set(priv, priv->gpio_poc,
> +				       enable ^ priv->gpio_poc_flags);
> +	else
> +		ret = priv->regulator
> +		    ? regulator_disable(priv->regulator)
> +		    : max9286_gpio_set(priv, priv->gpio_poc,
> +				       enable ^ priv->gpio_poc_flags);
> +
> +	if (ret < 0)
> +		dev_err(&priv->client->dev, "Unable to turn PoC %s\n",
> +			enable ? "on" : "off");
> +
> +	return ret;
> +}
> +
>  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);
>
Jacopo Mondi April 18, 2021, 3:01 p.m. UTC | #3
Hi Laurent,

On Thu, Apr 15, 2021 at 10:19:30PM +0300, Laurent Pinchart wrote:
> Hi Jacopo,

>

> Thank you for the patch.

>

> On Thu, Apr 15, 2021 at 02:25:58PM +0200, Jacopo Mondi wrote:

> > The 'maxim,gpio-poc' property is used when the remote camera

> > power-over-coax is controlled by one of the MAX9286 gpio lines,

> > to instruct the driver about which line to use and what the line

> > polarity is.

> >

> > Add to the max9286 driver support for parsing the newly introduced

> > property and use it if available in place of the usual supply, as it is

> > not possible to establish one as consumer of the max9286 gpio

> > controller.

> >

> > If the new property is present, no gpio controller is registered and

> > 'poc-supply' is ignored.

> >

> > In order to maximize code re-use, break out the max9286 gpio handling

> > function so that they can be used by the gpio controller through the

> > gpio-consumer API, or directly by the driver code.

> >

> > Wrap the power up and power down routines to their own function to

> > be able to use either the gpio line directly or the supply. This will

> > make it easier to control the remote camera power at run time.

> >

> > Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>

> > ---

> >  drivers/media/i2c/max9286.c | 119 ++++++++++++++++++++++++++++--------

> >  1 file changed, 93 insertions(+), 26 deletions(-)

> >

> > diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c

> > index 6fd4d59fcc72..a8b37783d2ef 100644

> > --- a/drivers/media/i2c/max9286.c

> > +++ b/drivers/media/i2c/max9286.c

> > @@ -15,6 +15,7 @@

> >  #include <linux/fwnode.h>

> >  #include <linux/gpio/consumer.h>

> >  #include <linux/gpio/driver.h>

> > +#include <linux/gpio/machine.h>

> >  #include <linux/i2c.h>

> >  #include <linux/i2c-mux.h>

> >  #include <linux/module.h>

> > @@ -165,6 +166,9 @@ struct max9286_priv {

> >

> >  	u32 reverse_channel_mv;

> >

> > +	u32 gpio_poc;

> > +	u32 gpio_poc_flags;

> > +

> >  	struct v4l2_ctrl_handler ctrls;

> >  	struct v4l2_ctrl *pixelrate;

> >

> > @@ -1022,8 +1026,19 @@ static int max9286_setup(struct max9286_priv *priv)

> >  	return 0;

> >  }

> >

> > -static void max9286_gpio_set(struct gpio_chip *chip,

> > -			     unsigned int offset, int value)

> > +static int max9286_gpio_set(struct max9286_priv *priv, unsigned int offset,

> > +			    int value)

> > +{

> > +	int ret = max9286_read(priv, 0x0f);

> > +	if (ret < 0)

> > +		return ret;

> > +

> > +	ret = value ? (ret & 0x3) | BIT(offset) : (ret & 0x3) & ~BIT(offset);

> > +	return max9286_write(priv, 0x0f, MAX9286_0X0F_RESERVED | ret);

> > +}

>

> Was there anything wrong with v3, sharing the implementation between the


Yes, my understanding that your comment about not mixing the two
cases as they're mutually exclusive  :)

I found that it actually made sense, as my reasoning was to support
both at the same time, but it was actually not possible. I then
thought it was a good idea to keep them separate....

> gpio-controller and non gpio-controller cases ? In particular, caching

> the state locally seems better, max9286_read() goes over I2C and is thus

> slow.


At the expense of an additional i2c read... The gpio is only toggled
at power-up/down, so I considered this acceptable...

Both solutions are ok with me, I can restore the usage of gpio->state
or keep what I have here...

The only argument in favour of using gpio->state is that it paves the
way for the usage of 'gpio-poc' and for registering a gpio-controller
on the other gpio line at the same time, in future.. I think I'll
switch back to that solution then...

Thanks
  j
>

> > +

> > +static void max9286_gpiochip_set(struct gpio_chip *chip,

> > +				 unsigned int offset, int value)

> >  {

> >  	struct max9286_priv *priv = gpiochip_get_data(chip);

> >

> > @@ -1035,7 +1050,7 @@ static void max9286_gpio_set(struct gpio_chip *chip,

> >  	max9286_write(priv, 0x0f, MAX9286_0X0F_RESERVED | priv->gpio_state);

> >  }

> >

> > -static int max9286_gpio_get(struct gpio_chip *chip, unsigned int offset)

> > +static int max9286_gpiochip_get(struct gpio_chip *chip, unsigned int offset)

> >  {

> >  	struct max9286_priv *priv = gpiochip_get_data(chip);

> >

> > @@ -1055,8 +1070,8 @@ static int max9286_register_gpio(struct max9286_priv *priv)

> >  	gpio->of_node = dev->of_node;

> >  	gpio->ngpio = 2;

> >  	gpio->base = -1;

> > -	gpio->set = max9286_gpio_set;

> > -	gpio->get = max9286_gpio_get;

> > +	gpio->set = max9286_gpiochip_set;

> > +	gpio->get = max9286_gpiochip_get;

> >  	gpio->can_sleep = true;

> >

> >  	/* GPIO values default to high */

> > @@ -1069,6 +1084,71 @@ static int max9286_register_gpio(struct max9286_priv *priv)

> >  	return ret;

> >  }

> >

> > +static int max9286_parse_gpios(struct max9286_priv *priv)

> > +{

> > +	struct device *dev = &priv->client->dev;

> > +	u32 gpio_poc[2];

> > +	int ret;

> > +

> > +	/*

> > +	 * Parse the "gpio-poc" vendor property. If the camera power is

> > +	 * controlled by one of the MAX9286 gpio lines, do not register

> > +	 * the gpio controller and ignore 'poc-supply'.

> > +	 */

> > +	ret = of_property_read_u32_array(dev->of_node,

> > +					 "maxim,gpio-poc", gpio_poc, 2);

> > +	if (!ret) {

> > +		priv->gpio_poc = gpio_poc[0];

> > +		priv->gpio_poc_flags = gpio_poc[1];

> > +		if (priv->gpio_poc > 1 ||

> > +		    (priv->gpio_poc_flags != GPIO_ACTIVE_HIGH &&

> > +		     priv->gpio_poc_flags != GPIO_ACTIVE_LOW)) {

> > +			dev_err(dev, "Invalid 'gpio-poc': (%u %u)\n",

> > +				priv->gpio_poc, priv->gpio_poc_flags);

> > +			return -EINVAL;

> > +		}

> > +

> > +		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 (enable)

> > +		ret = priv->regulator

> > +		    ? regulator_enable(priv->regulator)

> > +		    : max9286_gpio_set(priv, priv->gpio_poc,

> > +				       enable ^ priv->gpio_poc_flags);

> > +	else

> > +		ret = priv->regulator

> > +		    ? regulator_disable(priv->regulator)

> > +		    : max9286_gpio_set(priv, priv->gpio_poc,

> > +				       enable ^ priv->gpio_poc_flags);

> > +

> > +	if (ret < 0)

> > +		dev_err(&priv->client->dev, "Unable to turn PoC %s\n",

> > +			enable ? "on" : "off");

> > +

> > +	return ret;

> > +}

> > +

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