* [PATCH] i2c: sirf: tune the divider to make i2c bus freq more accurate
@ 2015-09-09 10:30 Barry Song
2015-10-23 20:30 ` Wolfram Sang
0 siblings, 1 reply; 2+ messages in thread
From: Barry Song @ 2015-09-09 10:30 UTC (permalink / raw)
To: wsa-z923LK4zBo2bacvFa/9K2g, linux-i2c-u79uwXL29TY76Z2rM5mHXA
Cc: workgroup.linux-kQvG35nSl+M, Guoying Zhang, Barry Song
From: Guoying Zhang <Guoying.Zhang-kQvG35nSl+M@public.gmane.org>
In prima2 and atlas7, due to some hardware design issue. we
need to adjust the divider ratio a little according to i2c
bus frequency ranges.
Since i2c is open drain interface that allows the slave to
stall the transaction by holding the SCL line at '0', the RTL
implementation is waiting for SCL feedback from the pin after
setting it to High-Z ('1'). This wait adds to the high-time
interval counter few cycles of the input synchronization
(depending on the SCL_FILTER_REG field), and also the time it
takes for the board pull-up resistor to rise the SCL line.
For slow SCL settings these additions are negligible, but they
start to affect the speed when clock is set to faster frequencies.
This patch is based on the actual tests, and it makes SCL more
accurate.
Signed-off-by: Guoying Zhang <Guoying.Zhang-kQvG35nSl+M@public.gmane.org>
Signed-off-by: Barry Song <Baohua.Song-kQvG35nSl+M@public.gmane.org>
---
drivers/i2c/busses/i2c-sirf.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-sirf.c b/drivers/i2c/busses/i2c-sirf.c
index 1092d4e..13e51ef 100644
--- a/drivers/i2c/busses/i2c-sirf.c
+++ b/drivers/i2c/busses/i2c-sirf.c
@@ -358,11 +358,29 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev)
if (err < 0)
bitrate = SIRFSOC_I2C_DEFAULT_SPEED;
- if (bitrate < 100000)
- regval =
- (2 * ctrl_speed) / (bitrate * 11);
- else
+ /*
+ * Due to some hardware design issues, we need to tune the formula.
+ * Since i2c is open drain interface that allows the slave to
+ * stall the transaction by holding the SCL line at '0', the RTL
+ * implementation is waiting for SCL feedback from the pin after
+ * setting it to High-Z ('1'). This wait adds to the high-time
+ * interval counter few cycles of the input synchronization
+ * (depending on the SCL_FILTER_REG field), and also the time it
+ * takes for the board pull-up resistor to rise the SCL line.
+ * For slow SCL settings these additions are negligible,
+ * but they start to affect the speed when clock is set to faster
+ * frequencies.
+ * Through the actual tests, use the different user_div value(which
+ * in the divider formular 'Fio / (Fi2c * user_div)') to adapt
+ * the different ranges of i2c bus clock frequency, to make the SCL
+ * more accurate.
+ */
+ if (bitrate <= 30000)
regval = ctrl_speed / (bitrate * 5);
+ else if (bitrate > 30000 && bitrate <= 280000)
+ regval = (2 * ctrl_speed) / (bitrate * 11);
+ else
+ regval = ctrl_speed / (bitrate * 6);
writel(regval, siic->base + SIRFSOC_I2C_CLK_CTRL);
if (regval > 0xFF)
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] i2c: sirf: tune the divider to make i2c bus freq more accurate
2015-09-09 10:30 [PATCH] i2c: sirf: tune the divider to make i2c bus freq more accurate Barry Song
@ 2015-10-23 20:30 ` Wolfram Sang
0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2015-10-23 20:30 UTC (permalink / raw)
To: Barry Song; +Cc: linux-i2c, workgroup.linux, Guoying Zhang, Barry Song
[-- Attachment #1: Type: text/plain, Size: 1064 bytes --]
On Wed, Sep 09, 2015 at 10:30:32AM +0000, Barry Song wrote:
> From: Guoying Zhang <Guoying.Zhang@csr.com>
>
> In prima2 and atlas7, due to some hardware design issue. we
> need to adjust the divider ratio a little according to i2c
> bus frequency ranges.
> Since i2c is open drain interface that allows the slave to
> stall the transaction by holding the SCL line at '0', the RTL
> implementation is waiting for SCL feedback from the pin after
> setting it to High-Z ('1'). This wait adds to the high-time
> interval counter few cycles of the input synchronization
> (depending on the SCL_FILTER_REG field), and also the time it
> takes for the board pull-up resistor to rise the SCL line.
> For slow SCL settings these additions are negligible, but they
> start to affect the speed when clock is set to faster frequencies.
> This patch is based on the actual tests, and it makes SCL more
> accurate.
>
> Signed-off-by: Guoying Zhang <Guoying.Zhang@csr.com>
> Signed-off-by: Barry Song <Baohua.Song@csr.com>
Applied to for-next, thanks!
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-10-23 20:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-09 10:30 [PATCH] i2c: sirf: tune the divider to make i2c bus freq more accurate Barry Song
2015-10-23 20:30 ` Wolfram Sang
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).