diff options
author | addy ke <addy.ke@rock-chips.com> | 2014-09-07 23:38:25 -0400 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2014-09-20 12:35:10 -0400 |
commit | b4a7bd7a386dc6b0bb49cb47614e06e8295d495a (patch) | |
tree | 728adfdae85210311683faee0b888e6137ffc71b | |
parent | a4780d039ca5c3ef318db084f1bfc6ebed6876c8 (diff) |
i2c: rk3x: fix divisor calculation for SCL frequency
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)
It will be updated to the latest version of chip manual.
Signed-off-by: Addy Ke <addy.ke@rock-chips.com>
Reviewed-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Cc: stable@kernel.org
-rw-r--r-- | drivers/i2c/busses/i2c-rk3x.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c index e637c32ae517..93cfc837200b 100644 --- a/drivers/i2c/busses/i2c-rk3x.c +++ b/drivers/i2c/busses/i2c-rk3x.c | |||
@@ -433,12 +433,11 @@ static void rk3x_i2c_set_scl_rate(struct rk3x_i2c *i2c, unsigned long scl_rate) | |||
433 | unsigned long i2c_rate = clk_get_rate(i2c->clk); | 433 | unsigned long i2c_rate = clk_get_rate(i2c->clk); |
434 | unsigned int div; | 434 | unsigned int div; |
435 | 435 | ||
436 | /* SCL rate = (clk rate) / (8 * DIV) */ | 436 | /* set DIV = DIVH = DIVL |
437 | div = DIV_ROUND_UP(i2c_rate, scl_rate * 8); | 437 | * SCL rate = (clk rate) / (8 * (DIVH + 1 + DIVL + 1)) |
438 | 438 | * = (clk rate) / (16 * (DIV + 1)) | |
439 | /* The lower and upper half of the CLKDIV reg describe the length of | 439 | */ |
440 | * SCL low & high periods. */ | 440 | div = DIV_ROUND_UP(i2c_rate, scl_rate * 16) - 1; |
441 | div = DIV_ROUND_UP(div, 2); | ||
442 | 441 | ||
443 | i2c_writel(i2c, (div << 16) | (div & 0xffff), REG_CLKDIV); | 442 | i2c_writel(i2c, (div << 16) | (div & 0xffff), REG_CLKDIV); |
444 | } | 443 | } |