Linux Media Controller development
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime.ripard@bootlin.com>
To: Jacopo Mondi <jacopo+renesas@jmondi.org>
Cc: sam@elite-embedded.com, mchehab@kernel.org,
	laurent.pinchart@ideasonboard.com, hans.verkuil@cisco.com,
	sakari.ailus@linux.intel.com, linux-media@vger.kernel.org,
	hugues.fruchet@st.com, loic.poulain@linaro.org,
	daniel@zonque.org
Subject: Re: [PATCH 1/2] media: ov5640: Add check for PLL1 output max frequency
Date: Thu, 18 Oct 2018 11:15:50 +0200	[thread overview]
Message-ID: <20181018091550.64thz7irmbyymj5b@flea> (raw)
In-Reply-To: <1539805038-22321-2-git-send-email-jacopo+renesas@jmondi.org>

[-- Attachment #1: Type: text/plain, Size: 2496 bytes --]

On Wed, Oct 17, 2018 at 09:37:17PM +0200, Jacopo Mondi wrote:
> Check that the PLL1 output frequency does not exceed the maximum allowed 1GHz
> frequency.
> 
> Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
> ---
>  drivers/media/i2c/ov5640.c | 23 +++++++++++++++++++----
>  1 file changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
> index e098435..1f2e72d 100644
> --- a/drivers/media/i2c/ov5640.c
> +++ b/drivers/media/i2c/ov5640.c
> @@ -770,7 +770,7 @@ static int ov5640_mod_reg(struct ov5640_dev *sensor, u16 reg,
>   * always set to either 1 or 2 in the vendor kernels.
>   */
>  #define OV5640_SYSDIV_MIN	1
> -#define OV5640_SYSDIV_MAX	2
> +#define OV5640_SYSDIV_MAX	16
>  
>  /*
>   * This is supposed to be ranging from 1 to 16, but the value is always
> @@ -806,15 +806,20 @@ static int ov5640_mod_reg(struct ov5640_dev *sensor, u16 reg,
>   * This is supposed to be ranging from 1 to 8, but the value is always
>   * set to 1 in the vendor kernels.
>   */
> -#define OV5640_PCLK_ROOT_DIV	1
> +#define OV5640_PCLK_ROOT_DIV			1
> +#define OV5640_PLL_SYS_ROOT_DIVIDER_BYPASS	0x00
>  
>  static unsigned long ov5640_compute_sys_clk(struct ov5640_dev *sensor,
>  					    u8 pll_prediv, u8 pll_mult,
>  					    u8 sysdiv)
>  {
> -	unsigned long rate = clk_get_rate(sensor->xclk);
> +	unsigned long sysclk = sensor->xclk_freq / pll_prediv * pll_mult;
>  
> -	return rate / pll_prediv * pll_mult / sysdiv;
> +	/* PLL1 output cannot exceed 1GHz. */
> +	if (sysclk / 1000000 > 1000)
> +		return 0;
> +
> +	return sysclk / sysdiv;
>  }
>  
>  static unsigned long ov5640_calc_sys_clk(struct ov5640_dev *sensor,
> @@ -844,6 +849,16 @@ static unsigned long ov5640_calc_sys_clk(struct ov5640_dev *sensor,
>  			_rate = ov5640_compute_sys_clk(sensor,
>  						       OV5640_PLL_PREDIV,
>  						       _pll_mult, _sysdiv);
> +
> +			/*
> +			 * We have reached the maximum allowed PLL1 output,
> +			 * increase sysdiv.
> +			 */
> +			if (rate == 0) {
> +				_pll_mult = OV5640_PLL_MULT_MAX + 1;
> +				continue;
> +			}
> +

Both your patches look sane to me. However, I guess here you're
setting _pll_mult at this value so that you won't reach the for
condition on the next iteration?

Wouldn't it be cleaner to just use a break statement here?

Thanks!
Maxime

-- 
Maxime Ripard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2018-10-18 17:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-17 19:37 [PATCH 0/2] media: ov5640: Re-implement MIPI clock tree configuration Jacopo Mondi
2018-10-17 19:37 ` [PATCH 1/2] media: ov5640: Add check for PLL1 output max frequency Jacopo Mondi
2018-10-18  9:15   ` Maxime Ripard [this message]
2018-10-18 13:35     ` jacopo mondi
2018-10-18 16:51       ` Maxime Ripard
2018-10-17 19:37 ` [PATCH 2/2] media: ov5640: Re-implement MIPI clock configuration Jacopo Mondi

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=20181018091550.64thz7irmbyymj5b@flea \
    --to=maxime.ripard@bootlin.com \
    --cc=daniel@zonque.org \
    --cc=hans.verkuil@cisco.com \
    --cc=hugues.fruchet@st.com \
    --cc=jacopo+renesas@jmondi.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=loic.poulain@linaro.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=sam@elite-embedded.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