* [PATCH v2] i2c: i2c-bcm2708: fixes cdiv uneven number
@ 2015-05-01 21:43 Silvan Wicki
[not found] ` <1430516629-32692-1-git-send-email-linux_wi-ADq4ffItWIY@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Silvan Wicki @ 2015-05-01 21:43 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 | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-bcm2708.c b/drivers/i2c/busses/i2c-bcm2708.c
index 81e9374..dd7094a 100644
--- a/drivers/i2c/busses/i2c-bcm2708.c
+++ b/drivers/i2c/busses/i2c-bcm2708.c
@@ -67,6 +67,9 @@
#define BSC_S_DONE 0x00000002
#define BSC_S_TA 0x00000001
+#define BSC_CDIV_MAX 0xFFFE
+#define BSC_CDIV_BITMASK 0xFFFE
+
#define I2C_TIMEOUT_MS 150
#define I2C_WAIT_LOOP_COUNT 40
@@ -441,9 +444,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 > BSC_CDIV_MAX) {
+ cdiv = BSC_CDIV_MAX;
baudrate = bus_hz / cdiv;
+ } else {
+ if ((cdiv & BSC_CDIV_BITMASK) != cdiv) {
+ cdiv &= BSC_CDIV_BITMASK;
+ baudrate = bus_hz / cdiv;
+ }
}
bi->cdiv = cdiv;
--
2.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread[parent not found: <1430516629-32692-1-git-send-email-linux_wi-ADq4ffItWIY@public.gmane.org>]
* Re: [PATCH v2] i2c: i2c-bcm2708: fixes cdiv uneven number [not found] ` <1430516629-32692-1-git-send-email-linux_wi-ADq4ffItWIY@public.gmane.org> @ 2015-05-04 4:50 ` rajeev kumar [not found] ` <CAA7nrtgTOg0YBKavBhV+=9fvxxjtd143aODZpfR=TSN7STrrXg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2015-05-12 15:54 ` wsa-z923LK4zBo2bacvFa/9K2g 1 sibling, 1 reply; 4+ messages in thread From: rajeev kumar @ 2015-05-04 4:50 UTC (permalink / raw) To: Silvan Wicki; +Cc: Wolfram Sang, linux-i2c-u79uwXL29TY76Z2rM5mHXA On Sat, May 2, 2015 at 3:13 AM, Silvan Wicki <linux_wi-ADq4ffItWIY@public.gmane.org> 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-ADq4ffItWIY@public.gmane.org> > --- Reviewed-by: Rajeev Kumar <rajeevkumar.linux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > drivers/i2c/busses/i2c-bcm2708.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-bcm2708.c b/drivers/i2c/busses/i2c-bcm2708.c > index 81e9374..dd7094a 100644 > --- a/drivers/i2c/busses/i2c-bcm2708.c > +++ b/drivers/i2c/busses/i2c-bcm2708.c > @@ -67,6 +67,9 @@ > #define BSC_S_DONE 0x00000002 > #define BSC_S_TA 0x00000001 > > +#define BSC_CDIV_MAX 0xFFFE > +#define BSC_CDIV_BITMASK 0xEFFF > + > #define I2C_TIMEOUT_MS 150 > #define I2C_WAIT_LOOP_COUNT 40 > > @@ -441,9 +444,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 > BSC_CDIV_MAX) { > + cdiv = BSC_CDIV_MAX; > baudrate = bus_hz / cdiv; > + } else { > + if ((cdiv & BSC_CDIV_BITMASK) != cdiv) { > + cdiv &= BSC_CDIV_BITMASK; > + 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-u79uwXL29TY76Z2rM5mHXA@public.gmane.org > More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <CAA7nrtgTOg0YBKavBhV+=9fvxxjtd143aODZpfR=TSN7STrrXg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [PATCH v2] i2c: i2c-bcm2708: fixes cdiv uneven number [not found] ` <CAA7nrtgTOg0YBKavBhV+=9fvxxjtd143aODZpfR=TSN7STrrXg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2015-05-06 18:35 ` Silvan Wicki 0 siblings, 0 replies; 4+ messages in thread From: Silvan Wicki @ 2015-05-06 18:35 UTC (permalink / raw) To: rajeev kumar; +Cc: Wolfram Sang, linux-i2c-u79uwXL29TY76Z2rM5mHXA On Mon, May 04, 2015 at 10:20:42AM +0530, rajeev kumar wrote: > On Sat, May 2, 2015 at 3:13 AM, Silvan Wicki <linux_wi-ADq4ffItWIY@public.gmane.org> 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-ADq4ffItWIY@public.gmane.org> > > --- > Reviewed-by: Rajeev Kumar <rajeevkumar.linux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > drivers/i2c/busses/i2c-bcm2708.c | 13 +++++++++++-- > > 1 file changed, 11 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/i2c/busses/i2c-bcm2708.c b/drivers/i2c/busses/i2c-bcm2708.c > > index 81e9374..dd7094a 100644 > > --- a/drivers/i2c/busses/i2c-bcm2708.c > > +++ b/drivers/i2c/busses/i2c-bcm2708.c > > @@ -67,6 +67,9 @@ > > #define BSC_S_DONE 0x00000002 > > #define BSC_S_TA 0x00000001 > > > > +#define BSC_CDIV_MAX 0xFFFE > > +#define BSC_CDIV_BITMASK 0xEFFF BSC_CDIV_BITMASK needs to be 0xFFFE; please don't change > > + > > #define I2C_TIMEOUT_MS 150 > > #define I2C_WAIT_LOOP_COUNT 40 > > > > @@ -441,9 +444,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 > BSC_CDIV_MAX) { > > + cdiv = BSC_CDIV_MAX; > > baudrate = bus_hz / cdiv; > > + } else { > > + if ((cdiv & BSC_CDIV_BITMASK) != cdiv) { > > + cdiv &= BSC_CDIV_BITMASK; > > + 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-u79uwXL29TY76Z2rM5mHXA@public.gmane.org > > More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] i2c: i2c-bcm2708: fixes cdiv uneven number [not found] ` <1430516629-32692-1-git-send-email-linux_wi-ADq4ffItWIY@public.gmane.org> 2015-05-04 4:50 ` rajeev kumar @ 2015-05-12 15:54 ` wsa-z923LK4zBo2bacvFa/9K2g 1 sibling, 0 replies; 4+ messages in thread From: wsa-z923LK4zBo2bacvFa/9K2g @ 2015-05-12 15:54 UTC (permalink / raw) To: Silvan Wicki; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1: Type: text/plain, Size: 504 bytes --] On Fri, May 01, 2015 at 11:43:49PM +0200, Silvan Wicki 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-ADq4ffItWIY@public.gmane.org> > --- > drivers/i2c/busses/i2c-bcm2708.c | 13 +++++++++++-- Which kernel are you using? We don't have such a driver in upstream. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-05-12 15:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-01 21:43 [PATCH v2] i2c: i2c-bcm2708: fixes cdiv uneven number Silvan Wicki
[not found] ` <1430516629-32692-1-git-send-email-linux_wi-ADq4ffItWIY@public.gmane.org>
2015-05-04 4:50 ` rajeev kumar
[not found] ` <CAA7nrtgTOg0YBKavBhV+=9fvxxjtd143aODZpfR=TSN7STrrXg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-06 18:35 ` Silvan Wicki
2015-05-12 15:54 ` wsa-z923LK4zBo2bacvFa/9K2g
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).