From: "Alessandrelli, Daniele" <daniele.alessandrelli@intel.com>
To: "Murphy, Paul J" <paul.j.murphy@intel.com>,
"mchehab@kernel.org" <mchehab@kernel.org>,
"alexander.stein@ew.tq-group.com"
<alexander.stein@ew.tq-group.com>,
"krzysztof.kozlowski+dt@linaro.org"
<krzysztof.kozlowski+dt@linaro.org>,
"robh+dt@kernel.org" <robh+dt@kernel.org>
Cc: "linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>
Subject: Re: [PATCH 5/6] media: i2c: ov9282: Add regulator support
Date: Mon, 11 Jul 2022 19:54:07 +0000 [thread overview]
Message-ID: <a52e4b5e6c83371b7ad41290566a632b87ebe34f.camel@intel.com> (raw)
In-Reply-To: <20220711081639.150153-6-alexander.stein@ew.tq-group.com>
On Mon, 2022-07-11 at 10:16 +0200, Alexander Stein wrote:
> Need in case the sensors is supplied by a switchable regulator.
>
> Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
> ---
> drivers/media/i2c/ov9282.c | 41 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 41 insertions(+)
>
> diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c
> index 04fda8222e07..c3faf11a99b5 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
> @@ -127,6 +136,7 @@ struct ov9282 {
> struct media_pad pad;
> struct gpio_desc *reset_gpio;
> struct clk *inclk;
> + struct regulator_bulk_data supplies[OV9282_NUM_SUPPLIES];
> struct v4l2_ctrl_handler ctrl_handler;
> struct v4l2_ctrl *link_freq_ctrl;
> struct v4l2_ctrl *pclk_ctrl;
> @@ -883,10 +893,18 @@ static int ov9282_power_on(struct device *dev)
> goto error_reset;
> }
>
> + ret = regulator_bulk_enable(ARRAY_SIZE(ov9282->supplies), ov9282->supplies);
> + if (ret) {
> + dev_err(dev, "Failed to enable regulators\n");
> + goto disable_clk;
> + }
> +
> usleep_range(400, 600);
>
> return 0;
>
> +disable_clk:
> + clk_disable_unprepare(ov9282->inclk);
> error_reset:
> gpiod_set_value_cansleep(ov9282->reset_gpio, 0);
>
> @@ -903,6 +921,11 @@ static int ov9282_power_off(struct device *dev)
> {
> struct v4l2_subdev *sd = dev_get_drvdata(dev);
> struct ov9282 *ov9282 = to_ov9282(sd);
> + int ret;
> +
> + ret = regulator_bulk_disable(ARRAY_SIZE(ov9282->supplies), ov9282->supplies);
> + if (ret)
> + dev_err(ov9282->dev, "Failed to disable supplies: %d\n", ret);
I'm not sure that checking the return value is needed.
'regulator_bulk_disable()' already prints an error message in case of
failure.
The majority of the drivers in "drivers/media/i2c" don't seem to check
it.
>
> gpiod_set_value_cansleep(ov9282->reset_gpio, 0);
>
> @@ -996,6 +1019,18 @@ static int ov9282_init_controls(struct ov9282 *ov9282)
> return 0;
> }
>
> +static int ov9282_configure_regulators(struct ov9282 *ov9282)
I would call this function something like 'ov9282_get_regulators()'.
> +{
> + unsigned int i;
> +
> + for (i = 0; i < ARRAY_SIZE(ov9282->supplies); i++)
> + ov9282->supplies[i].supply = ov9282_supply_names[i];
> +
> + return devm_regulator_bulk_get(ov9282->dev,
> + ARRAY_SIZE(ov9282->supplies),
> + ov9282->supplies);
> +}
> +
> /**
> * ov9282_probe() - I2C client device binding
> * @client: pointer to i2c client device
> @@ -1022,6 +1057,12 @@ static int ov9282_probe(struct i2c_client *client)
> return ret;
> }
>
> + ret = ov9282_configure_regulators(ov9282);
> + if (ret) {
> + dev_err(&client->dev, "Failed to get power regulators\n");
> + return ret;
> + }
> +
> mutex_init(&ov9282->mutex);
>
> ret = ov9282_power_on(ov9282->dev);
next prev parent reply other threads:[~2022-07-11 19:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-11 8:16 [PATCH 0/6] OV9281 support Alexander Stein
2022-07-11 8:16 ` [PATCH 1/6] media: i2c: ov9282: remove unused and unset i2c_client member Alexander Stein
2022-07-11 19:34 ` Alessandrelli, Daniele
2022-07-11 8:16 ` [PATCH 2/6] media: dt-bindings: media: Add compatible for ov9281 Alexander Stein
2022-07-11 9:17 ` Krzysztof Kozlowski
2022-07-11 8:16 ` [PATCH 3/6] media: i2c: ov9282: Add ov9281 compatible Alexander Stein
2022-07-11 19:34 ` Alessandrelli, Daniele
2022-07-11 8:16 ` [PATCH 4/6] media: dt-bindings: media: ov9282: Add power supply properties Alexander Stein
2022-07-11 9:17 ` Krzysztof Kozlowski
2022-07-11 11:45 ` Alexander Stein
2022-07-11 12:02 ` Krzysztof Kozlowski
2022-07-11 8:16 ` [PATCH 5/6] media: i2c: ov9282: Add regulator support Alexander Stein
2022-07-11 19:54 ` Alessandrelli, Daniele [this message]
2022-07-11 8:16 ` [PATCH 6/6] media: i2c: ov9282: Fix device detection Alexander Stein
2022-07-11 19:58 ` Alessandrelli, Daniele
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=a52e4b5e6c83371b7ad41290566a632b87ebe34f.camel@intel.com \
--to=daniele.alessandrelli@intel.com \
--cc=alexander.stein@ew.tq-group.com \
--cc=devicetree@vger.kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@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;
as well as URLs for NNTP newsgroup(s).