Skip to content

Commit de6b437

Browse files
geertuAndi Shyti
authored andcommitted
i2c: riic: Always round-up when calculating bus period
Currently, the RIIC driver may run the I2C bus faster than requested, which may cause subtle failures. E.g. Biju reported a measured bus speed of 450 kHz instead of the expected maximum of 400 kHz on RZ/G2L. The initial calculation of the bus period uses DIV_ROUND_UP(), to make sure the actual bus speed never becomes faster than the requested bus speed. However, the subsequent division-by-two steps do not use round-up, which may lead to a too-small period, hence a too-fast and possible out-of-spec bus speed. E.g. on RZ/Five, requesting a bus speed of 100 resp. 400 kHz will yield too-fast target bus speeds of 100806 resp. 403226 Hz instead of 97656 resp. 390625 Hz. Fix this by using DIV_ROUND_UP() in the subsequent divisions, too. Tested on RZ/A1H, RZ/A2M, and RZ/Five. Fixes: d982d66 ("i2c: riic: remove clock and frequency restrictions") Reported-by: Biju Das <[email protected]> Signed-off-by: Geert Uytterhoeven <[email protected]> Cc: <[email protected]> # v4.15+ Link: https://lore.kernel.org/r/c59aea77998dfea1b4456c4b33b55ab216fcbf5e.1732284746.git.geert+renesas@glider.be Signed-off-by: Andi Shyti <[email protected]>
1 parent 5751eee commit de6b437

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/i2c/busses/i2c-riic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ static int riic_init_hw(struct riic_dev *riic)
352352
if (brl <= (0x1F + 3))
353353
break;
354354

355-
total_ticks /= 2;
355+
total_ticks = DIV_ROUND_UP(total_ticks, 2);
356356
rate /= 2;
357357
}
358358

0 commit comments

Comments
 (0)