From: addy ke <addy.ke-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
To: dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
Cc: wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org,
max.schwarz-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org,
heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org,
olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org,
linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
cf-TNX95d0MmH7DzftRWevZcw@public.gmane.org,
xjq-TNX95d0MmH7DzftRWevZcw@public.gmane.org,
huangtao-TNX95d0MmH7DzftRWevZcw@public.gmane.org,
zyw-TNX95d0MmH7DzftRWevZcw@public.gmane.org,
yzq-TNX95d0MmH7DzftRWevZcw@public.gmane.org,
hj-TNX95d0MmH7DzftRWevZcw@public.gmane.org,
kever.yang-TNX95d0MmH7DzftRWevZcw@public.gmane.org,
hl-TNX95d0MmH7DzftRWevZcw@public.gmane.org,
caesar.wang-TNX95d0MmH7DzftRWevZcw@public.gmane.org,
zhengsq-TNX95d0MmH7DzftRWevZcw@public.gmane.org
Subject: Re: [PATCH] i2c: rk3x: fix divisor calculation for SCL frequency
Date: Fri, 05 Sep 2014 18:17:10 +0800 [thread overview]
Message-ID: <54098DA6.4090704@rock-chips.com> (raw)
In-Reply-To: <CAD=FV=W3JJM38v-X=pyLUjAzY3Ti88xUgWp9bMsX5dqp1gubpg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
> Addy,
>
> On Thu, Sep 4, 2014 at 7:32 PM, Addy Ke <addy.ke-TNX95d0MmH7DzftRWevZcw@public.gmane.org> wrote:
>> I2C_CLKDIV register descripted in the previous version of
>> RK3x chip manual is incorrect. Plus 1 is required.
>>
>> The correct formula:
>> - T(SCL_HIGH) = T(PCLK) * (CLKDIVH + 1) * 8
>> - T(SCL_LOW) = T(PCLK) * (CLKDIVL + 1) * 8
>> - (SCL Divsor) = 8 * ((CLKDIVL + 1) + (CLKDIVH + 1))
>> - SCL = PCLK / (CLK Divsor)
>
> I'll trust that you tested this with a scope
>
Yes ,I have tested on RK3188 and RK3288, and confirmed by oscilloscope.
>
>> It will be updated to the latest version of chip manual.
>>
>> Signed-off-by: Addy Ke <addy.ke-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
>> ---
>> drivers/i2c/busses/i2c-rk3x.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c
>> index e637c32..76b6604 100644
>> --- a/drivers/i2c/busses/i2c-rk3x.c
>> +++ b/drivers/i2c/busses/i2c-rk3x.c
>> @@ -433,8 +433,8 @@ static void rk3x_i2c_set_scl_rate(struct rk3x_i2c *i2c, unsigned long scl_rate)
>> unsigned long i2c_rate = clk_get_rate(i2c->clk);
>> unsigned int div;
>>
>> - /* SCL rate = (clk rate) / (8 * DIV) */
>> - div = DIV_ROUND_UP(i2c_rate, scl_rate * 8);
>> + /* SCL rate = (clk rate) / (8 * (DIV + 2)) */
>> + div = DIV_ROUND_UP(i2c_rate, scl_rate * 8) - 2;
>
> Given the bug I just fixed in the Rockchip SPI driver, I was a little
> worried about div becoming -1 (and thus being a really large positive
> number since div is unsigned).
>
> However, it seems that you get saved by the next statement:
> div = DIV_ROUND_UP(div, 2);
>
> In the testing I did with the Linux macros, that magically transformed
> a div of 0xFFFFFFFF (-1) to 0, so it's not technically a bug. ...but
> it's very non-obvious. Can you do something a little cleaner?
The following modifications is reasonable?
static void rk3x_i2c_set_scl_rate(struct rk3x_i2c *i2c, unsigned long scl_rate)
{
unsigned long i2c_rate = clk_get_rate(i2c->clk);
unsigned int div;
/* set DIV = DIVH = DIVL
* SCL rate = (clk rate) / (8 * (DIVH + 1 + DIVL + 1))
* = (clk rate) / (16 * (DIV + 1))
*/
div = DIV_ROUND_UP(i2c_rate, scl_rate * 16) - 1;
i2c_writel(i2c, (div << 16) | (div & 0xffff), REG_CLKDIV);
}
>
> -Doug
>
>
>
WARNING: multiple messages have this Message-ID (diff)
From: addy.ke@rock-chips.com (addy ke)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] i2c: rk3x: fix divisor calculation for SCL frequency
Date: Fri, 05 Sep 2014 18:17:10 +0800 [thread overview]
Message-ID: <54098DA6.4090704@rock-chips.com> (raw)
In-Reply-To: <CAD=FV=W3JJM38v-X=pyLUjAzY3Ti88xUgWp9bMsX5dqp1gubpg@mail.gmail.com>
> Addy,
>
> On Thu, Sep 4, 2014 at 7:32 PM, Addy Ke <addy.ke@rock-chips.com> wrote:
>> I2C_CLKDIV register descripted in the previous version of
>> RK3x chip manual is incorrect. Plus 1 is required.
>>
>> The correct formula:
>> - T(SCL_HIGH) = T(PCLK) * (CLKDIVH + 1) * 8
>> - T(SCL_LOW) = T(PCLK) * (CLKDIVL + 1) * 8
>> - (SCL Divsor) = 8 * ((CLKDIVL + 1) + (CLKDIVH + 1))
>> - SCL = PCLK / (CLK Divsor)
>
> I'll trust that you tested this with a scope
>
Yes ,I have tested on RK3188 and RK3288, and confirmed by oscilloscope.
>
>> It will be updated to the latest version of chip manual.
>>
>> Signed-off-by: Addy Ke <addy.ke@rock-chips.com>
>> ---
>> drivers/i2c/busses/i2c-rk3x.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c
>> index e637c32..76b6604 100644
>> --- a/drivers/i2c/busses/i2c-rk3x.c
>> +++ b/drivers/i2c/busses/i2c-rk3x.c
>> @@ -433,8 +433,8 @@ static void rk3x_i2c_set_scl_rate(struct rk3x_i2c *i2c, unsigned long scl_rate)
>> unsigned long i2c_rate = clk_get_rate(i2c->clk);
>> unsigned int div;
>>
>> - /* SCL rate = (clk rate) / (8 * DIV) */
>> - div = DIV_ROUND_UP(i2c_rate, scl_rate * 8);
>> + /* SCL rate = (clk rate) / (8 * (DIV + 2)) */
>> + div = DIV_ROUND_UP(i2c_rate, scl_rate * 8) - 2;
>
> Given the bug I just fixed in the Rockchip SPI driver, I was a little
> worried about div becoming -1 (and thus being a really large positive
> number since div is unsigned).
>
> However, it seems that you get saved by the next statement:
> div = DIV_ROUND_UP(div, 2);
>
> In the testing I did with the Linux macros, that magically transformed
> a div of 0xFFFFFFFF (-1) to 0, so it's not technically a bug. ...but
> it's very non-obvious. Can you do something a little cleaner?
The following modifications is reasonable?
static void rk3x_i2c_set_scl_rate(struct rk3x_i2c *i2c, unsigned long scl_rate)
{
unsigned long i2c_rate = clk_get_rate(i2c->clk);
unsigned int div;
/* set DIV = DIVH = DIVL
* SCL rate = (clk rate) / (8 * (DIVH + 1 + DIVL + 1))
* = (clk rate) / (16 * (DIV + 1))
*/
div = DIV_ROUND_UP(i2c_rate, scl_rate * 16) - 1;
i2c_writel(i2c, (div << 16) | (div & 0xffff), REG_CLKDIV);
}
>
> -Doug
>
>
>
WARNING: multiple messages have this Message-ID (diff)
From: addy ke <addy.ke@rock-chips.com>
To: dianders@chromium.org
Cc: wsa@the-dreams.de, max.schwarz@online.de, heiko@sntech.de,
olof@lixom.net, linux-i2c@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org, cf@rock-chips.com,
xjq@rock-chips.com, huangtao@rock-chips.com, zyw@rock-chips.com,
yzq@rock-chips.com, hj@rock-chips.com, kever.yang@rock-chips.com,
hl@rock-chips.com, caesar.wang@rock-chips.com,
zhengsq@rock-chips.com
Subject: Re: [PATCH] i2c: rk3x: fix divisor calculation for SCL frequency
Date: Fri, 05 Sep 2014 18:17:10 +0800 [thread overview]
Message-ID: <54098DA6.4090704@rock-chips.com> (raw)
In-Reply-To: <CAD=FV=W3JJM38v-X=pyLUjAzY3Ti88xUgWp9bMsX5dqp1gubpg@mail.gmail.com>
> Addy,
>
> On Thu, Sep 4, 2014 at 7:32 PM, Addy Ke <addy.ke@rock-chips.com> wrote:
>> I2C_CLKDIV register descripted in the previous version of
>> RK3x chip manual is incorrect. Plus 1 is required.
>>
>> The correct formula:
>> - T(SCL_HIGH) = T(PCLK) * (CLKDIVH + 1) * 8
>> - T(SCL_LOW) = T(PCLK) * (CLKDIVL + 1) * 8
>> - (SCL Divsor) = 8 * ((CLKDIVL + 1) + (CLKDIVH + 1))
>> - SCL = PCLK / (CLK Divsor)
>
> I'll trust that you tested this with a scope
>
Yes ,I have tested on RK3188 and RK3288, and confirmed by oscilloscope.
>
>> It will be updated to the latest version of chip manual.
>>
>> Signed-off-by: Addy Ke <addy.ke@rock-chips.com>
>> ---
>> drivers/i2c/busses/i2c-rk3x.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c
>> index e637c32..76b6604 100644
>> --- a/drivers/i2c/busses/i2c-rk3x.c
>> +++ b/drivers/i2c/busses/i2c-rk3x.c
>> @@ -433,8 +433,8 @@ static void rk3x_i2c_set_scl_rate(struct rk3x_i2c *i2c, unsigned long scl_rate)
>> unsigned long i2c_rate = clk_get_rate(i2c->clk);
>> unsigned int div;
>>
>> - /* SCL rate = (clk rate) / (8 * DIV) */
>> - div = DIV_ROUND_UP(i2c_rate, scl_rate * 8);
>> + /* SCL rate = (clk rate) / (8 * (DIV + 2)) */
>> + div = DIV_ROUND_UP(i2c_rate, scl_rate * 8) - 2;
>
> Given the bug I just fixed in the Rockchip SPI driver, I was a little
> worried about div becoming -1 (and thus being a really large positive
> number since div is unsigned).
>
> However, it seems that you get saved by the next statement:
> div = DIV_ROUND_UP(div, 2);
>
> In the testing I did with the Linux macros, that magically transformed
> a div of 0xFFFFFFFF (-1) to 0, so it's not technically a bug. ...but
> it's very non-obvious. Can you do something a little cleaner?
The following modifications is reasonable?
static void rk3x_i2c_set_scl_rate(struct rk3x_i2c *i2c, unsigned long scl_rate)
{
unsigned long i2c_rate = clk_get_rate(i2c->clk);
unsigned int div;
/* set DIV = DIVH = DIVL
* SCL rate = (clk rate) / (8 * (DIVH + 1 + DIVL + 1))
* = (clk rate) / (16 * (DIV + 1))
*/
div = DIV_ROUND_UP(i2c_rate, scl_rate * 16) - 1;
i2c_writel(i2c, (div << 16) | (div & 0xffff), REG_CLKDIV);
}
>
> -Doug
>
>
>
next prev parent reply other threads:[~2014-09-05 10:17 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-05 2:32 [PATCH] i2c: rk3x: fix divisor calculation for SCL frequency Addy Ke
2014-09-05 2:32 ` Addy Ke
2014-09-05 2:32 ` Addy Ke
2014-09-05 4:31 ` Doug Anderson
2014-09-05 4:31 ` Doug Anderson
[not found] ` <CAD=FV=W3JJM38v-X=pyLUjAzY3Ti88xUgWp9bMsX5dqp1gubpg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-09-05 10:17 ` addy ke [this message]
2014-09-05 10:17 ` addy ke
2014-09-05 10:17 ` addy ke
2014-09-05 15:20 ` Doug Anderson
2014-09-05 15:20 ` Doug Anderson
[not found] ` <1409884333-3544-1-git-send-email-addy.ke-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2014-09-08 3:38 ` [PATCH v2] " Addy Ke
2014-09-08 3:38 ` Addy Ke
2014-09-08 3:38 ` Addy Ke
2014-09-08 4:15 ` Doug Anderson
2014-09-08 4:15 ` Doug Anderson
[not found] ` <1410147505-5930-1-git-send-email-addy.ke-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2014-09-20 12:19 ` Wolfram Sang
2014-09-20 12:19 ` Wolfram Sang
2014-09-20 12:19 ` 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=54098DA6.4090704@rock-chips.com \
--to=addy.ke-tnx95d0mmh7dzftrwevzcw@public.gmane.org \
--cc=caesar.wang-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
--cc=cf-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
--cc=dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org \
--cc=hj-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
--cc=hl-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
--cc=huangtao-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
--cc=kever.yang-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=max.schwarz-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org \
--cc=olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org \
--cc=wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org \
--cc=xjq-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
--cc=yzq-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
--cc=zhengsq-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
--cc=zyw-TNX95d0MmH7DzftRWevZcw@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.