mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Sakari Ailus <sakari.ailus@iki.fi>
Cc: mauriziocasciano7@gmail.com,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
	Nicholas Roth <nicholas@rothemail.net>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Bingbu Cao <bingbu.cao@amd.com>,
	Dan Scally <dan.scally@ideasonboard.com>,
	Hans de Goede <hansg@kernel.org>,
	Andy Shevchenko <andy@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Andy Shevchenko <andriy.shevchenko@intel.com>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-staging@lists.linux.dev
Subject: Re: [PATCH v10 02/15] media: ov8858: support 19.2 MHz clock and manual white balance
Date: Thu, 12 Nov 2026 23:22:34 +0200	[thread overview]
Message-ID: <20261112212234.GA699509@killaraus.ideasonboard.com> (raw)
In-Reply-To: <avYp7y9Vvh2Oo5c6@valkosipuli.retiisi.eu>

On Thu, Nov 12, 2026 at 11:04:47PM +0200, Sakari Ailus wrote:
> On Fri, Oct 02, 2026 at 10:57:40AM +0200, Maurizio Casciano via B4 Relay wrote:
> > From: Maurizio Casciano <mauriziocasciano7@gmail.com>
> > 
> > Support both 19.2 MHz and 24 MHz input clocks. Move the PLL and
> > global-timing registers out of the common mode tables and select register
> > settings for the detected revision, lane count, input clock and 360 MHz
> > link frequency when starting the stream. Use the actual input-clock rate
> > when calculating the reset delay.
> > 
> > Add standard red and blue balance controls for the sensor's manual white
> > balance registers. V4L2 defines red and blue balance relative to green but
> > does not define a standard green-balance control, so keep green at unity.
> > Accumulate errors while programming all three channels.
> > 
> > The manual white-balance register definitions and programming follow
> > Intel's GPL-2.0 OV5670 driver, so retain its 2017 Intel copyright notice.
> 
> Any others notices that should be added?
> 
> > 
> > Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
> > Assisted-by: LLM sparse
> 
> The Assisted-by: tags are no longer used, please remove them.
> 
> > ---
> >  drivers/media/i2c/ov8858.c | 183 ++++++++++++++++++++++++++++++++++++---------
> >  1 file changed, 147 insertions(+), 36 deletions(-)
> > 
> > diff --git a/drivers/media/i2c/ov8858.c b/drivers/media/i2c/ov8858.c
> > index 2a0e2b08b9aa..64532237e8b5 100644
> > --- a/drivers/media/i2c/ov8858.c
> > +++ b/drivers/media/i2c/ov8858.c
> 
> ...
> 
> > @@ -1541,6 +1606,23 @@ static int ov8858_set_long_digital_gain(struct ov8858 *ov8858, u32 gain)
> >  	return ov8858_write(ov8858, OV8858_REG_LONG_DIGIGAIN, long_gain, NULL);
> >  }
> >  
> > +static int ov8858_set_mwb_gains(struct ov8858 *ov8858)
> > +{
> > +	int ret = 0;
> > +
> > +	ov8858_write(ov8858, OV8858_REG_MWB_RED_GAIN,
> > +		     ov8858->red_balance->val, &ret);
> > +	/*
> > +	 * Green is the unity reference for the red and blue balance controls.
> > +	 */
> 
> UAPI-wise this doesn't look great. There's a digital gain control, too, so
> you can still control the entire digital gain. But the hardware has
> per-component gains and in this case the (likely analogue TV inspired?)
> UAPI limits this. A few other sensor drivers appear to be doing the same.
> 
> Cc Laurent, too.

That's indeed not a good UAPI.

> > +	ov8858_write(ov8858, OV8858_REG_MWB_GREEN_GAIN,
> > +		     OV8858_MWB_GAIN_DEFAULT, &ret);
> > +	ov8858_write(ov8858, OV8858_REG_MWB_BLUE_GAIN,
> > +		     ov8858->blue_balance->val, &ret);
> > +
> > +	return ret;
> > +}
> > +
> >  static int ov8858_set_ctrl(struct v4l2_ctrl *ctrl)
> >  {
> >  	struct ov8858 *ov8858 = container_of(ctrl->handler,
> > @@ -1589,6 +1671,10 @@ static int ov8858_set_ctrl(struct v4l2_ctrl *ctrl)
> >  	case V4L2_CID_DIGITAL_GAIN:
> >  		ret = ov8858_set_long_digital_gain(ov8858, ctrl->val);
> >  		break;
> > +	case V4L2_CID_RED_BALANCE:
> > +	case V4L2_CID_BLUE_BALANCE:
> > +		ret = ov8858_set_mwb_gains(ov8858);
> > +		break;
> >  	case V4L2_CID_VBLANK:
> >  		ret = ov8858_write(ov8858, OV8858_REG_VTS,
> >  				   ctrl->val + format->height, NULL);
> > @@ -1623,9 +1709,6 @@ static int ov8858_power_on(struct ov8858 *ov8858)
> >  	unsigned long delay_us;
> >  	int ret;
> >  
> > -	if (clk_get_rate(ov8858->xvclk) != OV8858_XVCLK_FREQ)
> > -		dev_warn(dev, "xvclk mismatched, modes are based on 24MHz\n");
> > -
> >  	ret = clk_prepare_enable(ov8858->xvclk);
> >  	if (ret < 0) {
> >  		dev_err(dev, "Failed to enable xvclk\n");
> > @@ -1644,7 +1727,7 @@ static int ov8858_power_on(struct ov8858 *ov8858)
> >  	 * transaction, but a double sleep between the release of gpios
> >  	 * helps with sporadic failures observed at probe time.
> >  	 */
> > -	delay_us = DIV_ROUND_UP(8192, OV8858_XVCLK_FREQ / 1000 / 1000);
> > +	delay_us = DIV_ROUND_UP(8192, ov8858->xvclk_rate / HZ_PER_MHZ);
> >  
> >  	gpiod_set_value_cansleep(ov8858->reset_gpio, 0);
> >  	fsleep(delay_us);
> > @@ -1710,7 +1793,7 @@ static int ov8858_init_ctrls(struct ov8858 *ov8858)
> >  	u32 h_blank;
> >  	int ret;
> >  
> > -	ret = v4l2_ctrl_handler_init(handler, 10);
> > +	ret = v4l2_ctrl_handler_init(handler, 12);
> >  	if (ret)
> >  		return ret;
> >  
> > @@ -1752,6 +1835,19 @@ static int ov8858_init_ctrls(struct ov8858 *ov8858)
> >  			  OV8858_LONG_DIGIGAIN_STEP,
> >  			  OV8858_LONG_DIGIGAIN_DEFAULT);
> >  
> > +	ov8858->red_balance =
> > +		v4l2_ctrl_new_std(handler, &ov8858_ctrl_ops,
> > +				  V4L2_CID_RED_BALANCE,
> > +				  OV8858_MWB_GAIN_MIN, OV8858_MWB_GAIN_MAX,
> > +				  OV8858_MWB_GAIN_STEP,
> > +				  OV8858_MWB_GAIN_DEFAULT);
> > +	ov8858->blue_balance =
> > +		v4l2_ctrl_new_std(handler, &ov8858_ctrl_ops,
> > +				  V4L2_CID_BLUE_BALANCE,
> > +				  OV8858_MWB_GAIN_MIN, OV8858_MWB_GAIN_MAX,
> > +				  OV8858_MWB_GAIN_STEP,
> > +				  OV8858_MWB_GAIN_DEFAULT);
> > +
> >  	v4l2_ctrl_new_std_menu_items(handler, &ov8858_ctrl_ops,
> >  				     V4L2_CID_TEST_PATTERN,
> >  				     ARRAY_SIZE(ov8858_test_pattern_menu) - 1,
> > @@ -1805,15 +1901,20 @@ static int ov8858_check_sensor_id(struct ov8858 *ov8858)
> >  
> >  	if (id == OV8858_R2A) {
> >  		/* R2A supports 2 and 4 lanes modes. */
> > -		ov8858->global_regs = ov8858->num_lanes == 4
> > -				    ? ov8858_global_regs_r2a_4lane
> > -				    : ov8858_global_regs_r2a_2lane;
> > +		if (ov8858->num_lanes == 4) {
> > +			ov8858->global_regs = ov8858_global_regs_r2a_4lane;
> > +			ov8858->xvclk_regs = ov8858_24mhz_360mhz_r2a_4lane;
> > +		} else {
> > +			ov8858->global_regs = ov8858_global_regs_r2a_2lane;
> > +			ov8858->xvclk_regs = ov8858_24mhz_360mhz_r2a_2lane;
> > +		}
> >  	} else if (ov8858->num_lanes == 2) {
> >  		/*
> >  		 * R1A only supports 2 lanes mode and it's only partially
> >  		 * supported.
> >  		 */
> >  		ov8858->global_regs = ov8858_global_regs_r1a;
> > +		ov8858->xvclk_regs = ov8858_24mhz_360mhz_r1a_2lane;
> >  		dev_warn(&client->dev, "R1A may not work well!\n");
> >  	} else {
> >  		dev_err(&client->dev,
> > @@ -1821,6 +1922,9 @@ static int ov8858_check_sensor_id(struct ov8858 *ov8858)
> >  		return -EINVAL;
> >  	}
> >  
> > +	if (ov8858->xvclk_rate == OV8858_XVCLK_FREQ_19_2MHZ)
> > +		ov8858->xvclk_regs = ov8858_19_2mhz_360mhz;
> 
> The 24 MHz configurations are lane number (and variant) dependent. Isn't
> that applying to 19,2 MHz? If not, why?
> 
> > +
> >  	return 0;
> >  }
> >  
> > @@ -1888,6 +1992,13 @@ static int ov8858_probe(struct i2c_client *client)
> >  		return dev_err_probe(dev, PTR_ERR(ov8858->xvclk),
> >  				     "Failed to get xvclk\n");
> >  
> > +	ov8858->xvclk_rate = clk_get_rate(ov8858->xvclk);
> > +	if (ov8858->xvclk_rate != OV8858_XVCLK_FREQ_19_2MHZ &&
> > +	    ov8858->xvclk_rate != OV8858_XVCLK_FREQ_24MHZ)
> > +		return dev_err_probe(dev, -EINVAL,
> > +				     "Unsupported xvclk rate %lu Hz\n",
> > +				     ov8858->xvclk_rate);
> > +
> >  	ov8858->reset_gpio = devm_gpiod_get_optional(dev, "reset",
> >  						     GPIOD_OUT_HIGH);
> >  	if (IS_ERR(ov8858->reset_gpio))

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2026-11-12 21:22 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02  8:57 [PATCH v10 00/15] media: Add Lenovo Yoga Book camera support Maurizio Casciano via B4 Relay
2026-10-02  8:57 ` [PATCH v10 01/15] media: ov8858: Extract digital gain programming Maurizio Casciano via B4 Relay
2026-10-02  9:54   ` Andy Shevchenko
2026-10-02  8:57 ` [PATCH v10 02/15] media: ov8858: support 19.2 MHz clock and manual white balance Maurizio Casciano via B4 Relay
2026-11-12 21:04   ` Sakari Ailus
2026-11-12 21:22     ` Laurent Pinchart [this message]
2026-10-02  8:57 ` [PATCH v10 03/15] media: ov2740: Use C99 initializers for ACPI IDs Maurizio Casciano via B4 Relay
2026-10-02  8:57 ` [PATCH v10 04/15] media: ov2740: Add OVTI2740 ACPI ID Maurizio Casciano via B4 Relay
2026-10-02  8:57 ` [PATCH v10 05/15] media: ov8858: Add INT3477 " Maurizio Casciano via B4 Relay
2026-11-12 21:07   ` Sakari Ailus
2026-10-02  8:57 ` [PATCH v10 06/15] media: intel: ipu-bridge: Add Yoga Book camera sensors Maurizio Casciano via B4 Relay
2026-10-02  8:57 ` [PATCH v10 07/15] media: atomisp: Add Yoga Book camera configuration Maurizio Casciano via B4 Relay
2026-10-02  8:57 ` [PATCH v10 08/15] media: ov2740: support 288 MHz link frequency Maurizio Casciano via B4 Relay
2026-10-02  8:57 ` [PATCH v10 09/15] media: intel: ipu-bridge: select OV2740 frequency by IPU ID Maurizio Casciano via B4 Relay
2026-10-03 14:41   ` Andy Shevchenko
2026-10-02  8:57 ` [PATCH v10 10/15] media: atomisp: derive CSI-2 timing from sensor link frequency Maurizio Casciano via B4 Relay
2026-10-02  8:57 ` [PATCH v10 11/15] media: ov2740: release group hold after gain write errors Maurizio Casciano via B4 Relay
2026-10-02  8:57 ` [PATCH v10 12/15] media: ov2740: add manual white balance controls Maurizio Casciano via B4 Relay
2026-10-02  8:57 ` [PATCH v10 13/15] media: atomisp: Use struct v4l2_area for padding Maurizio Casciano via B4 Relay
2026-10-02  8:57 ` [PATCH v10 14/15] media: atomisp: allow raw Bayer capture Maurizio Casciano via B4 Relay
2026-10-02  8:57 ` [PATCH v10 15/15] media: i2c: Add WV517S lens actuator driver Maurizio Casciano via B4 Relay

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=20261112212234.GA699509@killaraus.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=bingbu.cao@amd.com \
    --cc=dan.scally@ideasonboard.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hansg@kernel.org \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mauriziocasciano7@gmail.com \
    --cc=mchehab@kernel.org \
    --cc=nicholas@rothemail.net \
    --cc=sakari.ailus@iki.fi \
    --cc=sakari.ailus@linux.intel.com \
    /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®