diff mbox

i2c: i2c-bcm2708: fixes cdiv uneven number

Message ID 1430417266-14900-1-git-send-email-linux_wi@tinag.ch
State Superseded
Headers show

Commit Message

Silvan Wicki April 30, 2015, 6:07 p.m. UTC
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@tinag.ch>
---
 drivers/i2c/busses/i2c-bcm2708.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

rajeev kumar May 1, 2015, 5:24 a.m. UTC | #1
On Thu, Apr 30, 2015 at 11:37 PM, Silvan Wicki <linux_wi@tinag.ch> wrote:
> 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@tinag.ch>
> ---
>  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;

Use #define

~Rajeev

>                 baudrate = bus_hz / cdiv;
> +       } else {
> +               if ((cdiv & 0xfffe) != cdiv) {
> +                       cdiv &= 0xfffe;
> +                       baudrate = bus_hz / cdiv;
> +               }
>         }
>         bi->cdiv = cdiv;
>
> --
> 2.1.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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;