linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: i2c-bcm2708: fixes cdiv uneven number
@ 2015-04-30 18:07 Silvan Wicki
       [not found] ` <1430417266-14900-1-git-send-email-linux_wi-ADq4ffItWIY@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Silvan Wicki @ 2015-04-30 18:07 UTC (permalink / raw)
  To: wsa-z923LK4zBo2bacvFa/9K2g; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Silvan Wicki

Prevents that cdiv can be an uneven number as per datasheet cdiv is
always rounded down to an even number.

Datasheet at page 34 on
http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

Signed-off-by: Silvan Wicki <linux_wi-ADq4ffItWIY@public.gmane.org>
---
 drivers/i2c/busses/i2c-bcm2708.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-bcm2708.c b/drivers/i2c/busses/i2c-bcm2708.c
index 81e9374..454ab48 100644
--- a/drivers/i2c/busses/i2c-bcm2708.c
+++ b/drivers/i2c/busses/i2c-bcm2708.c
@@ -441,9 +441,15 @@ static int bcm2708_i2c_probe(struct platform_device *pdev)
 
 	bus_hz = clk_get_rate(bi->clk);
 	cdiv = bus_hz / baudrate;
-	if (cdiv > 0xffff) {
-		cdiv = 0xffff;
+	/* as per datasheet cdiv is always rounded down to an even number */
+	if (cdiv > 0xfffe) {
+		cdiv = 0xfffe;
 		baudrate = bus_hz / cdiv;
+	} else {
+		if ((cdiv & 0xfffe) != cdiv) {
+			cdiv &= 0xfffe;
+			baudrate = bus_hz / cdiv;
+		}
 	}
 	bi->cdiv = cdiv;
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-05-01  5:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-30 18:07 [PATCH] i2c: i2c-bcm2708: fixes cdiv uneven number Silvan Wicki
     [not found] ` <1430417266-14900-1-git-send-email-linux_wi-ADq4ffItWIY@public.gmane.org>
2015-05-01  5:24   ` rajeev kumar

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).