From: Olliver Schinagl <oliver+list@schinagl.nl>
To: hdegoede@redhat.com, Wolfram Sang <wsa@the-dreams.de>,
Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Maxime Ripard <maxime.ripard@free-electrons.com>,
linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-sunxi@googlegroups.com
Subject: Re: [linux-sunxi] [PATCH] i2c: mv64xxx: The n clockdiv factor is 0 based on sunxi SoCs
Date: Sun, 27 Sep 2015 18:05:35 +0200 [thread overview]
Message-ID: <560813CF.4000807@schinagl.nl> (raw)
In-Reply-To: <1443365828-8956-1-git-send-email-hdegoede@redhat.com>
Hey Hans,
On 27-09-15 16:57, Hans de Goede wrote:
> According to the datasheets to n factor for dividing the tclk is
> 2 to the power n on Allwinner SoCs, not 2 to the power n + 1 as it is
> on other mv64xxx implementations.
Ah!
>
> I've contacted Allwinner about this and they have confirmed that the
> datasheet is correct.
>
> This commit fixes the clk-divider calculations for Allwinner SoCs
> accordingly.
So this explains why all my i2c frequenties are double of what I setup.
Thanks for taking the time of figuring it out! I'll give it a test
hopefully soon.
Olliver
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> drivers/i2c/busses/i2c-mv64xxx.c | 27 ++++++++++++++++++---------
> 1 file changed, 18 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
> index 30059c1..e75cf6d 100644
> --- a/drivers/i2c/busses/i2c-mv64xxx.c
> +++ b/drivers/i2c/busses/i2c-mv64xxx.c
> @@ -146,6 +146,8 @@ struct mv64xxx_i2c_data {
> bool errata_delay;
> struct reset_control *rstc;
> bool irq_clear_inverted;
> + /* Clk div is 2 to the power n, not 2 to the power n + 1 */
> + bool clk_n_base_0;
> };
>
> static struct mv64xxx_i2c_regs mv64xxx_i2c_regs_mv64xxx = {
> @@ -759,25 +761,29 @@ MODULE_DEVICE_TABLE(of, mv64xxx_i2c_of_match_table);
> #ifdef CONFIG_OF
> #ifdef CONFIG_HAVE_CLK
> static int
> -mv64xxx_calc_freq(const int tclk, const int n, const int m)
> +mv64xxx_calc_freq(struct mv64xxx_i2c_data *drv_data,
> + const int tclk, const int n, const int m)
> {
> - return tclk / (10 * (m + 1) * (2 << n));
> + if (drv_data->clk_n_base_0)
> + return tclk / (10 * (m + 1) * (1 << n));
> + else
> + return tclk / (10 * (m + 1) * (2 << n));
> }
>
> static bool
> -mv64xxx_find_baud_factors(const u32 req_freq, const u32 tclk, u32 *best_n,
> - u32 *best_m)
> +mv64xxx_find_baud_factors(struct mv64xxx_i2c_data *drv_data,
> + const u32 req_freq, const u32 tclk)
> {
> int freq, delta, best_delta = INT_MAX;
> int m, n;
>
> for (n = 0; n <= 7; n++)
> for (m = 0; m <= 15; m++) {
> - freq = mv64xxx_calc_freq(tclk, n, m);
> + freq = mv64xxx_calc_freq(drv_data, tclk, n, m);
> delta = req_freq - freq;
> if (delta >= 0 && delta < best_delta) {
> - *best_m = m;
> - *best_n = n;
> + drv_data->freq_m = m;
> + drv_data->freq_n = n;
> best_delta = delta;
> }
> if (best_delta == 0)
> @@ -815,8 +821,11 @@ mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data,
> if (of_property_read_u32(np, "clock-frequency", &bus_freq))
> bus_freq = 100000; /* 100kHz by default */
>
> - if (!mv64xxx_find_baud_factors(bus_freq, tclk,
> - &drv_data->freq_n, &drv_data->freq_m)) {
> + if (of_device_is_compatible(np, "allwinner,sun4i-a10-i2c") ||
> + of_device_is_compatible(np, "allwinner,sun6i-a31-i2c"))
> + drv_data->clk_n_base_0 = true;
> +
> + if (!mv64xxx_find_baud_factors(drv_data, bus_freq, tclk)) {
> rc = -EINVAL;
> goto out;
> }
next prev parent reply other threads:[~2015-09-27 16:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-27 14:57 [PATCH] i2c: mv64xxx: The n clockdiv factor is 0 based on sunxi SoCs Hans de Goede
2015-09-27 16:05 ` Olliver Schinagl [this message]
[not found] ` <560813CF.4000807-dxLnbx3+1qmEVqv0pETR8A@public.gmane.org>
2015-09-27 16:53 ` Andrew Lunn
2015-09-29 10:14 ` [linux-sunxi] " Hans de Goede
2015-09-29 12:29 ` Maxime Ripard
2015-09-29 12:09 ` Maxime Ripard
2015-10-01 18:51 ` Olliver Schinagl
[not found] ` <560D80CF.6050500-dxLnbx3+1qmEVqv0pETR8A@public.gmane.org>
2015-10-20 15:58 ` Wolfram Sang
2015-10-20 22:05 ` Olliver Schinagl
2015-10-25 17:32 ` Olliver Schinagl
[not found] ` <1443365828-8956-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-09-27 19:36 ` Peter Korsgaard
2015-09-29 12:09 ` Maxime Ripard
2015-11-30 13:51 ` Wolfram Sang
2015-11-30 14:54 ` Wolfram Sang
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=560813CF.4000807@schinagl.nl \
--to=oliver+list@schinagl.nl \
--cc=hdegoede@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-sunxi@googlegroups.com \
--cc=maxime.ripard@free-electrons.com \
--cc=thomas.petazzoni@free-electrons.com \
--cc=wsa@the-dreams.de \
/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).