From: Gregory CLEMENT <gregory.clement@free-electrons.com>
To: Leigh Brown <leigh@solinno.co.uk>
Cc: Mike Turquette <mturquette@linaro.org>,
linux-kernel@vger.kernel.org,
Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
Andrew Lunn <andrew@lunn.ch>, Jason Cooper <jason@lakedaemon.net>,
Tawfik Bayouk <tawfik@marvell.com>,
Simon Boulay <simon.boulay@vitec.com>,
Arnaud Ebalard <arno@natisbad.org>,
Nadav Haklai <nadavh@marvell.com>,
Lior Amsalem <alior@marvell.com>,
Ezequiel Garcia <ezequiel.garcia@free-electrons.com>,
Raphael Rigo <ml-arm@syscall.eu>,
linux-arm-kernel@lists.infradead.org,
Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Subject: Re: [PATCH 1/4] clk: mvebu: Fix clk frequency value if SSCG is enabled
Date: Mon, 01 Sep 2014 09:17:36 +0200 [thread overview]
Message-ID: <54041D90.3030107@free-electrons.com> (raw)
In-Reply-To: <d9e3be49b00eb7dd8827f05a955b4497@doppler.thel33t.co.uk>
Hi Leigh,
On 01/09/2014 00:25, Leigh Brown wrote:
> Hi Gregory,
>
> On 2014-08-29 12:43, Gregory CLEMENT wrote:
>> When the SSCG (Spread Spectrum Clock Generator) is enabled, it shifts
>> the frequency of the clock. The percentage is no more than 1% but when
>> the clock is used for a timer it leads to a clock drift.
>
> Thank you so much for this series. I'm running 3.16 and without these
> patches ntpd is all over the place, so it is a huge improvement I do
> have a comment further down though..
>
>> This patch allows to correct the affected clock when the SSCG is
>> enabled. The check is done in an new optional function related to each
>> SoC: is_sscg_enabled(). If this function is not present then no
>> correction is done on the clock frequency.
>>
>> Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
>> ---
>> drivers/clk/mvebu/common.c | 74
>> ++++++++++++++++++++++++++++++++++++++++++++++
>> drivers/clk/mvebu/common.h | 1 +
>> 2 files changed, 75 insertions(+)
>>
>> diff --git a/drivers/clk/mvebu/common.c b/drivers/clk/mvebu/common.c
>> index 25ceccf939ad..834d36cf79b0 100644
>> --- a/drivers/clk/mvebu/common.c
>> +++ b/drivers/clk/mvebu/common.c
>> @@ -26,8 +26,78 @@
>> * Core Clocks
>> */
>>
>> +#define SSCG_CONF_MODE(reg) (((reg) >> 16) & 0x3)
>> +#define SSCG_SPREAD_DOWN 0x0
>> +#define SSCG_SPREAD_UP 0x1
>> +#define SSCG_SPREAD_CENTRAL 0x2
>> +#define SSCG_CONF_LOW(reg) (((reg) >> 8) & 0xFF)
>> +#define SSCG_CONF_HIGH(reg) ((reg) & 0xFF)
>> +
>> static struct clk_onecell_data clk_data;
>>
>> +static u32 fix_sscg_deviation(struct device_node *np, u32 system_clk)
>> +{
>> + struct device_node *sscg_np = NULL;
>> + void __iomem *sscg_map;
>> + u32 sscg_reg;
>> + s32 low_bound, high_bound;
>> + u64 freq_swing_half;
>> +
>> + sscg_np = of_find_node_by_name(np, "sscg");
>> + if (sscg_np == NULL) {
>> + pr_err("cannot get SSCG register node\n");
>> + return system_clk;
>> + }
>> +
>> + sscg_map = of_iomap(sscg_np, 0);
>> + if (sscg_map == NULL) {
>> + pr_err("cannot map SSCG register\n");
>> + goto out;
>> + }
>> +
>> + sscg_reg = readl(sscg_map);
>> + high_bound = SSCG_CONF_HIGH(sscg_reg);
>> + low_bound = SSCG_CONF_LOW(sscg_reg);
>> +
>> + if ((high_bound - low_bound) <= 0)
>> + goto out;
>> + /*
>> + * From the datasheet we got the following formula
>> + * Spread percentage = 1/96 * (H - L) / H
>
> In the datasheet it says the percentage is 0.96 * (H - L) / H. 1/96 is
> close but not the same as 0.0096.
Actually the public datasheet is wrong (even the NDA datasheet).
>
>> + * H = SSCG_High_Boundary
>> + * L = SSCG_Low_Boundary
>> + *
>> + * As the deviation is half of spread then it lead to the
>> + * following formula in the code.
>> + *
>> + * To avoid an overflow and not lose any significant digit in
>> + * the same time we have to use a 64 bit integer.
>> + */
>> +
>> + freq_swing_half = (((u64)high_bound - (u64)low_bound)
>> + * (u64)system_clk);
>> + do_div(freq_swing_half, (2 * 96 * high_bound));
>
> So this would be become :-
>
> /* NB: 0.96% = 0.0048 or 3/625 */
> freq_swing_half = (((u64)high_bound - (u64)low_bound)
> * (u64)system_clk * 3);
> do_div(freq_swing_half, (625 * high_bound));
It was the first implementation I tried, but with this one
the drift was about 200ppm instead of 50ppm. After having
checked this with the Marvell engineers, they confirmed me
that the datasheet was erroneous.
Thanks for your feedback: I will add a comment in the code
about the fact that the datasheet is erroneous.
--
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
next prev parent reply other threads:[~2014-09-01 7:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-29 11:43 [PATCH 0/4] clk:mvebu: Improve clock drift Gregory CLEMENT
2014-08-29 11:43 ` [PATCH 1/4] clk: mvebu: Fix clk frequency value if SSCG is enabled Gregory CLEMENT
2014-08-29 12:48 ` Sebastian Hesselbarth
2014-08-29 13:35 ` Gregory CLEMENT
2014-08-31 22:25 ` Leigh Brown
2014-08-31 22:30 ` Leigh Brown
2014-09-01 7:17 ` Gregory CLEMENT [this message]
2014-08-29 11:43 ` [PATCH 2/4] clk: mvebu: armada-370: Fix timer drift caused by the SSCG deviation Gregory CLEMENT
2014-08-29 13:08 ` Thomas Petazzoni
2014-08-29 13:37 ` Gregory CLEMENT
2014-08-29 11:43 ` [PATCH 3/4] ARM: mvebu: add SSCG to Armada 370 Device Tree Gregory CLEMENT
2014-08-29 11:43 ` [PATCH 4/4] clk: mvebu: armada-375: Fix the description of the SAR in the comment Gregory CLEMENT
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=54041D90.3030107@free-electrons.com \
--to=gregory.clement@free-electrons.com \
--cc=alior@marvell.com \
--cc=andrew@lunn.ch \
--cc=arno@natisbad.org \
--cc=ezequiel.garcia@free-electrons.com \
--cc=jason@lakedaemon.net \
--cc=leigh@solinno.co.uk \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ml-arm@syscall.eu \
--cc=mturquette@linaro.org \
--cc=nadavh@marvell.com \
--cc=sebastian.hesselbarth@gmail.com \
--cc=simon.boulay@vitec.com \
--cc=tawfik@marvell.com \
--cc=thomas.petazzoni@free-electrons.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