public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Stein <alexander.stein@ew.tq-group.com>
To: Dave Stevenson <dave.stevenson@raspberrypi.com>
Cc: paul.j.murphy@intel.com, daniele.alessandrelli@intel.com,
	linux-media@vger.kernel.org, robh+dt@kernel.org,
	devicetree@vger.kernel.org,
	Dave Stevenson <dave.stevenson@raspberrypi.com>
Subject: Re: [PATCH 2/2] media: i2c: ov9282: Add support for regulators.
Date: Thu, 24 Nov 2022 10:31:53 +0100	[thread overview]
Message-ID: <834648869.0ifERbkFSE@steina-w> (raw)
In-Reply-To: <20221005152018.3783890-3-dave.stevenson@raspberrypi.com>

Hello Dave,

Am Mittwoch, 5. Oktober 2022, 17:20:18 CET schrieb Dave Stevenson:
> The sensor takes 3 supply rails - AVDD, DVDD, and DOVDD.
> 
> Add hooks into the regulator framework for each of these
> regulators.
> 
> Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
> ---
>  drivers/media/i2c/ov9282.c | 38 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
> 
> diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c
> index 2e0b315801e5..699fc5b753b4 100644
> --- a/drivers/media/i2c/ov9282.c
> +++ b/drivers/media/i2c/ov9282.c
> @@ -11,6 +11,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-fwnode.h>
> @@ -55,6 +56,14 @@
>  #define OV9282_REG_MIN		0x00
>  #define OV9282_REG_MAX		0xfffff
> 
> +static const char * const ov9282_supply_names[] = {
> +	"avdd",		/* Analog power */
> +	"dovdd",	/* Digital I/O power */
> +	"dvdd",		/* Digital core power */
> +};
> +
> +#define OV9282_NUM_SUPPLIES ARRAY_SIZE(ov9282_supply_names)
> +
>  /**
>   * struct ov9282_reg - ov9282 sensor register
>   * @address: Register address
> @@ -128,6 +137,7 @@ struct ov9282 {
>  	struct media_pad pad;
>  	struct gpio_desc *reset_gpio;
>  	struct clk *inclk;
> +	struct regulator_bulk_data supplies[OV9282_NUM_SUPPLIES];

Please add documentation for supplies.

>  	struct v4l2_ctrl_handler ctrl_handler;
>  	struct v4l2_ctrl *link_freq_ctrl;
>  	struct v4l2_ctrl *pclk_ctrl;
> @@ -767,6 +777,18 @@ static int ov9282_detect(struct ov9282 *ov9282)
>  	return 0;
>  }
> 
> +static int ov9282_configure_regulators(struct ov9282 *ov9282)
> +{
> +	unsigned int i;
> +
> +	for (i = 0; i < OV9282_NUM_SUPPLIES; i++)
> +		ov9282->supplies[i].supply = ov9282_supply_names[i];
> +
> +	return devm_regulator_bulk_get(ov9282->dev,
> +				       OV9282_NUM_SUPPLIES,
> +				       ov9282->supplies);
> +}
> +
>  /**
>   * ov9282_parse_hw_config() - Parse HW configuration and check if supported
> * @ov9282: pointer to ov9282 device
> @@ -803,6 +825,12 @@ static int ov9282_parse_hw_config(struct ov9282
> *ov9282) return PTR_ERR(ov9282->inclk);
>  	}
> 
> +	ret = ov9282_configure_regulators(ov9282);
> +	if (ret) {
> +		dev_err(ov9282->dev, "Failed to get power regulators\n");

dev_err_probe seems sensible here.

> +		return ret;
> +	}
> +
>  	rate = clk_get_rate(ov9282->inclk);
>  	if (rate != OV9282_INCLK_RATE) {
>  		dev_err(ov9282->dev, "inclk frequency mismatch");
> @@ -874,6 +902,12 @@ static int ov9282_power_on(struct device *dev)
>  	struct ov9282 *ov9282 = to_ov9282(sd);
>  	int ret;
> 
> +	ret = regulator_bulk_enable(OV9282_NUM_SUPPLIES, ov9282->supplies);
> +	if (ret < 0) {
> +		dev_err(dev, "Failed to enable regulators\n");
> +		return ret;
> +	}
> +
>  	usleep_range(400, 600);
> 
>  	gpiod_set_value_cansleep(ov9282->reset_gpio, 1);
> @@ -891,6 +925,8 @@ static int ov9282_power_on(struct device *dev)
>  error_reset:
>  	gpiod_set_value_cansleep(ov9282->reset_gpio, 0);
> 
> +	regulator_bulk_disable(OV9282_NUM_SUPPLIES, ov9282->supplies);
> +
>  	return ret;
>  }
> 
> @@ -909,6 +945,8 @@ static int ov9282_power_off(struct device *dev)
> 
>  	clk_disable_unprepare(ov9282->inclk);
> 
> +	regulator_bulk_disable(OV9282_NUM_SUPPLIES, ov9282->supplies);
> +
>  	return 0;
>  }

Despite the nits above
Acked-by: Alexander Stein <alexander.stein@ew.tq-group.com>




  reply	other threads:[~2022-11-24  9:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-05 15:20 [PATCH 0/2] media: Add regulator support to ov9282 Dave Stevenson
2022-10-05 15:20 ` [PATCH 1/2] dt-bindings: media: ovti,ov9282: Add optional regulators Dave Stevenson
2022-10-06 19:08   ` Rob Herring
2022-10-05 15:20 ` [PATCH 2/2] media: i2c: ov9282: Add support for regulators Dave Stevenson
2022-11-24  9:31   ` Alexander Stein [this message]
2022-11-24 11:58     ` Dave Stevenson
2022-11-24 12:06       ` Alexander Stein
2022-11-16 16:50 ` [PATCH 0/2] media: Add regulator support to ov9282 Dave Stevenson
2022-11-17  9:40   ` Sakari Ailus

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=834648869.0ifERbkFSE@steina-w \
    --to=alexander.stein@ew.tq-group.com \
    --cc=daniele.alessandrelli@intel.com \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=paul.j.murphy@intel.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