From: Hans Verkuil <hverkuil+cisco@kernel.org>
To: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Hans Verkuil" <hverkuil@xs4all.nl>,
"Laurent Pinchart" <laurent.pinchart@ideasonboard.com>,
linux-media@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH v2 06/11] media: adv7180: Power down decoder when configuring the device
Date: Wed, 3 Sep 2025 10:30:42 +0200 [thread overview]
Message-ID: <a8ca5ff0-17df-4330-a05b-ab892fdf2e6f@kernel.org> (raw)
In-Reply-To: <20250828160654.1467762-7-niklas.soderlund+renesas@ragnatech.se>
On 28/08/2025 18:06, Niklas Söderlund wrote:
> Some variants of the chip (ADV7180) have it's decoder powered up after
> reset, while others (ADV7280, ADV7281, ADV7282, ADV7283) have it powered
> down.
>
> This is tracked by the feature flag ADV7180_FLAG_RESET_POWERED. At probe
> this flag is used to initialize the state variable powered which keeps
> track of if the decoder is powered on, or off, for the resume callback.
>
> This however misses that the decoder needs to be powered off for some
> configuration of the device to take hold. So for devices where it's left
> on (ADV7180) the format configuration at probe time have little effect.
> This worked as the .set_fmt callback powers down the decoder, updates
> the format, and powers back on the decoder.
>
> Before moving all configuration to .s_stream this needs to be fixed.
> Instead of tracking if the decoder is powered on or off, use the
> flag to determine if needs to be powered down after a reset to do the
> configuration.
>
> To keep the behavior consistent with the currents implementation switch
> the decoder back on for devices where this is the reset behavior. The
> primary reason for this is that if not done the first 35+ frames or so
> of the capture session is garbage.
>
> To keep the support of starting the decoder when resuming from sleep on
> devices where the reset behavior is to start with the decoder powered
> off, use the state variable streaming. If it is set the decoder was
> powered on when the system suspended so we know to start it again when
> resuming.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
> drivers/media/i2c/adv7180.c | 34 ++++++++++++++++++++++------------
> 1 file changed, 22 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
> index 8409ee9acc4f..0bc608291df7 100644
> --- a/drivers/media/i2c/adv7180.c
> +++ b/drivers/media/i2c/adv7180.c
> @@ -214,7 +214,6 @@ struct adv7180_state {
> struct gpio_desc *pwdn_gpio;
> struct gpio_desc *rst_gpio;
> v4l2_std_id curr_norm;
> - bool powered;
> bool streaming;
> u8 input;
>
> @@ -556,8 +555,6 @@ static int adv7180_s_power(struct v4l2_subdev *sd, int on)
> return ret;
>
> ret = adv7180_set_power(state, on);
> - if (ret == 0)
> - state->powered = on;
>
> mutex_unlock(&state->mutex);
> return ret;
> @@ -887,6 +884,13 @@ static int init_device(struct adv7180_state *state)
> adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES);
> usleep_range(5000, 10000);
>
> + /*
> + * If the devices decoder is power on after reset, power off so the
> + * device can be configured.
> + */
> + if (state->chip_info->flags & ADV7180_FLAG_RESET_POWERED)
> + adv7180_set_power(state, false);
> +
> ret = state->chip_info->init(state);
> if (ret)
> return ret;
> @@ -927,6 +931,14 @@ static int init_device(struct adv7180_state *state)
> return ret;
> }
>
> + /*
> + * If the devices decoder is power on after reset, restore the power
> + * after configuration. This is to preserve the behavior of the driver,
> + * not doing this result in the first 35+ frames captured being garbage.
> + */
> + if (state->chip_info->flags & ADV7180_FLAG_RESET_POWERED)
> + adv7180_set_power(state, true);
> +
> return 0;
> }
>
> @@ -1457,10 +1469,7 @@ static int adv7180_probe(struct i2c_client *client)
> state->irq = client->irq;
> mutex_init(&state->mutex);
> state->curr_norm = V4L2_STD_NTSC;
> - if (state->chip_info->flags & ADV7180_FLAG_RESET_POWERED)
> - state->powered = true;
> - else
> - state->powered = false;
> +
> state->input = 0;
> sd = &state->sd;
> v4l2_i2c_subdev_init(sd, client, &adv7180_ops);
> @@ -1568,11 +1577,12 @@ static int adv7180_resume(struct device *dev)
> if (ret < 0)
> return ret;
>
> - guard(mutex)(&state->mutex);
> -
> - ret = adv7180_set_power(state, state->powered);
> - if (ret)
> - return ret;
> + /* If we where streaming when suspending, start decoder. */
where -> were
> + if (state->streaming) {
> + ret = adv7180_set_power(state, true);
> + if (ret)
> + return ret;
> + }
>
> return 0;
> }
next prev parent reply other threads:[~2025-09-03 8:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-28 16:06 [PATCH v2 00/11] media: adv7180: Improve the control over decoder power Niklas Söderlund
2025-08-28 16:06 ` [PATCH v2 01/11] media: adv7180: Move adv7180_set_power() and init_device() Niklas Söderlund
2025-08-28 16:06 ` [PATCH v2 02/11] media: adv7180: Add missing lock in suspend callback Niklas Söderlund
2025-08-28 16:06 ` [PATCH v2 03/11] media: adv7180: Move state mutex handling outside init_device() Niklas Söderlund
2025-08-28 16:06 ` [PATCH v2 04/11] media: adv7180: Use v4l2-ctrls core to handle s_ctrl locking Niklas Söderlund
2025-09-03 8:28 ` Hans Verkuil
2025-08-28 16:06 ` [PATCH v2 05/11] media: adv7180: Setup controls every time the device is reset Niklas Söderlund
2025-08-28 16:06 ` [PATCH v2 06/11] media: adv7180: Power down decoder when configuring the device Niklas Söderlund
2025-09-03 8:30 ` Hans Verkuil [this message]
2025-08-28 16:06 ` [PATCH v2 07/11] media: adv7180: Split device initialization and reset Niklas Söderlund
2025-08-28 16:06 ` [PATCH v2 08/11] media: adv7180: Remove the s_power callback Niklas Söderlund
2025-08-28 16:06 ` [PATCH v2 09/11] media: adv7180: Do not write format to device in set_fmt Niklas Söderlund
2025-08-28 16:06 ` [PATCH v2 10/11] media: adv7180: Only validate format in s_std Niklas Söderlund
2025-08-28 16:06 ` [PATCH v2 11/11] media: adv7180: Only validate format in querystd Niklas Söderlund
2025-09-03 8:46 ` [PATCH v2 00/11] media: adv7180: Improve the control over decoder power Hans Verkuil
2025-09-03 14:35 ` Niklas Söderlund
2025-09-03 21:29 ` Hans Verkuil
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=a8ca5ff0-17df-4330-a05b-ab892fdf2e6f@kernel.org \
--to=hverkuil+cisco@kernel.org \
--cc=hverkuil@xs4all.nl \
--cc=lars@metafoo.de \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=niklas.soderlund+renesas@ragnatech.se \
/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).