public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kevin Groeneveld <kgroeneveld@lenbrook.com>
To: Stephen Boyd <sboyd@kernel.org>, Abel Vesa <abelvesa@kernel.org>,
	Fabio Estevam <festevam@gmail.com>,
	Michael Turquette <mturquette@baylibre.com>,
	NXP Linux Team <linux-imx@nxp.com>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Shawn Guo <shawnguo@kernel.org>,
	linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] clk: imx: pll14xx: fix recalc_rate for negative kdiv
Date: Tue, 14 Feb 2023 09:51:24 -0500	[thread overview]
Message-ID: <3693d66b-801e-dc31-15ee-e010f2577655@lenbrook.com> (raw)
In-Reply-To: <21e4cb835f678faa911ef97d28931246.sboyd@kernel.org>

On 2023-02-10 18:24, Stephen Boyd wrote:
> Quoting Kevin Groeneveld (2022-12-10 12:38:35)
>> kdiv is a signed 16 bit value in the DEV_CTL1 register. Commit
>> 53990cf9d5b4 ("clk: imx: pll14xx: consolidate rate calculation") changed
>> the kdiv variable from a short int to just int. When the value read from
>> the DIV_CTL1 register is assigned directly to an int the sign of the value
>> is lost resulting in incorrect results when the value is negative. Adding
> 
> Can the field be negative?

Yes it can be. That is how I found the issue as I had a negative value 
in imx_pll14xx_rate_table which used to work but broke with the above 
mentioned commit.

The i.MX8MM reference manual states:
 >Formula for Fraction PLLOUT:
 >* FOUT=((m+k/65536) x FIN) /(p x 2s)
 >* Where, 1 ≤ p ≤ 63, 64 ≤ m ≤ 1023, 0 ≤ s ≤ 6, -32768 ≤ k ≤ 32767
 >* p, m, and s are unsigned integers. k is a two's complement integer.

The comments in the imx_pll14xx_calc_settings function also mention the 
same range for kdiv. And this function also uses negative values. For 
example:

 >/* Then see if we can get the desired rate by only adjusting kdiv 
(glitch free) */
 >rate_min = pll14xx_calc_rate(pll, mdiv, pdiv, sdiv, KDIV_MIN, prate);
 >rate_max = pll14xx_calc_rate(pll, mdiv, pdiv, sdiv, KDIV_MAX, prate);

Where KDIV_MIN is defined as SHRT_MIN which is negative.


Kevin

  reply	other threads:[~2023-02-14 14:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-10 20:38 [PATCH] clk: imx: pll14xx: fix recalc_rate for negative kdiv Kevin Groeneveld
2023-02-10 23:24 ` Stephen Boyd
2023-02-14 14:51   ` Kevin Groeneveld [this message]
2023-02-15 12:24 ` Abel Vesa
2023-02-18  1:44 ` Stephen Boyd

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=3693d66b-801e-dc31-15ee-e010f2577655@lenbrook.com \
    --to=kgroeneveld@lenbrook.com \
    --cc=abelvesa@kernel.org \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=s.hauer@pengutronix.de \
    --cc=sboyd@kernel.org \
    --cc=shawnguo@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