Skip to contentSkip to conversation

MXS: Set I2C timing registers for mxs-i2c

PATCH Superseded Marek Vasut 3 participants 10 messages Jun 8, 2012 – Jun 9, 2012

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 MXS: Set I2C timing registers for mxs-i2c

This patch configures the I2C bus timing registers according to information passed via DT. Currently, 100kHz and 400kHz modes are supported.

Cc Detlev Zundel <[email protected]>
CC Dong Aisheng <[email protected]>
CC Fabio Estevam <[email protected]>
Cc Linux ARM kernel <[email protected]>
Cc linux-i2c at vger.kernel.org
CC Sascha Hauer <[email protected]>
CC Shawn Guo <[email protected]>
Cc Stefano Babic <[email protected]>
CC Uwe Kleine-K?nig <[email protected]>
Cc Wolfgang Denk <[email protected]>
Cc Wolfram Sang <[email protected]>
---
 Documentation/devicetree/bindings/i2c/i2c-mxs.txt |    1 +
 arch/arm/boot/dts/imx28.dtsi                      |    2 +
 drivers/i2c/busses/i2c-mxs.c                      |   54 +++++++++++++++++++++
 3 files changed, 57 insertions(+)

V2: Use clock-frequency instead

Documentation/devicetree/bindings/i2c/i2c-mxs.txt +1 -0
index 1bfc02d..d2bf750 100644
@@ -4,6 +4,7 @@ Required properties:
 - compatible: Should be "fsl,<chip>-i2c"
 - reg: Should contain registers location and length
 - interrupts: Should contain ERROR and DMA interrupts
+- clock-frequency: desired I2C bus clock frequency in Hz.
 
 Examples:
 
arch/arm/boot/dts/imx28.dtsi +2 -0
index a89da5a..714e63c 100644
@@ -398,6 +398,7 @@
 				compatible = "fsl,imx28-i2c";
 				reg = <0x80058000 2000>;
 				interrupts = <111 68>;
+				clock-frequency = <400000>;
 				status = "disabled";
 			};
 
@@ -407,6 +408,7 @@
 				compatible = "fsl,imx28-i2c";
 				reg = <0x8005a000 2000>;
 				interrupts = <110 69>;
+				clock-frequency = <400000>;
 				status = "disabled";
 			};
 
drivers/i2c/busses/i2c-mxs.c +54 -0

89 lines not on this page · raw message

Signature · 1 line
1.7.10
#1 lore raw

PATCH v2 2/2 MXS: Implement DMA support into mxs-i2c

This patch implements DMA support into mxs-i2c. DMA transfers are now enabled via DT. The DMA operation is enabled by default.

Cc Detlev Zundel <[email protected]>
CC Dong Aisheng <[email protected]>
CC Fabio Estevam <[email protected]>
Cc Linux ARM kernel <[email protected]>
Cc linux-i2c at vger.kernel.org
CC Sascha Hauer <[email protected]>
CC Shawn Guo <[email protected]>
Cc Stefano Babic <[email protected]>
CC Uwe Kleine-K?nig <[email protected]>
Cc Wolfgang Denk <[email protected]>
Cc Wolfram Sang <[email protected]>
---
 Documentation/devicetree/bindings/i2c/i2c-mxs.txt |    4 +
 arch/arm/boot/dts/imx28.dtsi                      |    2 +
 drivers/i2c/busses/i2c-mxs.c                      |  268 +++++++++++++++++++--
 3 files changed, 252 insertions(+), 22 deletions(-)

V2: Improve documentation

Documentation/devicetree/bindings/i2c/i2c-mxs.txt +4 -0
index d2bf750..9497ee0 100644
@@ -5,6 +5,10 @@ Required properties:
 - reg: Should contain registers location and length
 - interrupts: Should contain ERROR and DMA interrupts
 - clock-frequency: desired I2C bus clock frequency in Hz.
+- fsl,i2c-dma-channel: APBX DMA channel for the I2C
+
+Optional properties:
+- fsl,use-pio: Use PIO transfers instead of DMA, useful for debug
 
 Examples:
 
arch/arm/boot/dts/imx28.dtsi +2 -0
index 714e63c..cabcce8 100644
@@ -399,6 +399,7 @@
 				reg = <0x80058000 2000>;
 				interrupts = <111 68>;
 				clock-frequency = <400000>;
+				fsl,i2c-dma-channel = <6>;
 				status = "disabled";
 			};
 
@@ -409,6 +410,7 @@
 				reg = <0x8005a000 2000>;
 				interrupts = <110 69>;
 				clock-frequency = <400000>;
+				fsl,i2c-dma-channel = <7>;
 				status = "disabled";
 			};
 
drivers/i2c/busses/i2c-mxs.c +246 -22

376 lines not on this page · raw message

Signature · 1 line
1.7.10
#2 lore raw

PATCH v2 1/2 MXS: Set I2C timing registers for mxs-i2c

In reply to Marek Vasut
Quoted 72 lines · Marek Vasut

This patch configures the I2C bus timing registers according to information passed via DT. Currently, 100kHz and 400kHz modes are supported.

Cc Detlev Zundel <[email protected]>
CC Dong Aisheng <[email protected]>
CC Fabio Estevam <[email protected]>
Cc Linux ARM kernel <[email protected]>
Cc linux-i2c at vger.kernel.org
CC Sascha Hauer <[email protected]>
CC Shawn Guo <[email protected]>
Cc Stefano Babic <[email protected]>
CC Uwe Kleine-K?nig <[email protected]>
Cc Wolfgang Denk <[email protected]>
Cc Wolfram Sang <[email protected]>

---

?Documentation/devicetree/bindings/i2c/i2c-mxs.txt | ? ?1 +
?arch/arm/boot/dts/imx28.dtsi ? ? ? ? ? ? ? ? ? ? ?| ? ?2 +
?drivers/i2c/busses/i2c-mxs.c ? ? ? ? ? ? ? ? ? ? ?| ? 54 +++++++++++++++++++++

?3 files changed, 57 insertions(+)

V2: Use clock-frequency instead

Documentation/devicetree/bindings/i2c/i2c-mxs.txt +0 -0
index 1bfc02d..d2bf750 100644
@@ -4,6 +4,7 @@ Required properties:

?- compatible: Should be "fsl,<chip>-i2c"
?- reg: Should contain registers location and length ?- interrupts: Should contain ERROR and DMA interrupts +- clock-frequency: desired I2C bus clock frequency in Hz.

?Examples:

arch/arm/boot/dts/imx28.dtsi +2 -0
index a89da5a..714e63c 100644
@@ -398,6 +398,7 @@
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?compatible = "fsl,imx28-i2c";
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?reg = <0x80058000 2000>;
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?interrupts = <111 68>;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? clock-frequency = <400000>;
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?status = "disabled";
 ? ? ? ? ? ? ? ? ? ? ? ?};
 
@@ -407,6 +408,7 @@
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?compatible = "fsl,imx28-i2c";
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?reg = <0x8005a000 2000>;
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?interrupts = <110 69>;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? clock-frequency = <400000>;
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?status = "disabled";
 ? ? ? ? ? ? ? ? ? ? ? ?};
 
drivers/i2c/busses/i2c-mxs.c +0 -0
index 04eb441..b4d083f 100644
@@ -46,6 +46,10 @@

?#define MXS_I2C_CTRL0_DIRECTION ? ? ? ? ? ? ? ? ? ? ? ?0x00010000 ?#define MXS_I2C_CTRL0_XFER_COUNT(v) ? ? ? ? ? ?((v) & 0x0000FFFF)

drivers/i2c/busses/i2c-mxs.c +4 -0
+#define MXS_I2C_TIMING0 ? ? ? ? ? ? ? ?(0x10)
+#define MXS_I2C_TIMING1 ? ? ? ? ? ? ? ?(0x20)
+#define MXS_I2C_TIMING2 ? ? ? ? ? ? ? ?(0x30)
+

?#define MXS_I2C_CTRL1 ? ? ? ? ?(0x40)
?#define MXS_I2C_CTRL1_SET ? ? ?(0x44)
?#define MXS_I2C_CTRL1_CLR ? ? ?(0x48)

drivers/i2c/busses/i2c-mxs.c line 110

Quoted 10 lines
drivers/i2c/busses/i2c-mxs.c +7 -0
@@ -97,6 +101,24 @@
 ?#define MXS_CMD_I2C_READ ? ? ? (MXS_I2C_CTRL0_SEND_NAK_ON_LAST | \
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MXS_I2C_CTRL0_MASTER_MODE)
 
+struct mxs_i2c_speed_config {
+ ? ? ? uint32_t ? ? ? ?timing0;
+ ? ? ? uint32_t ? ? ? ?timing1;
+ ? ? ? uint32_t ? ? ? ?timing2;
+};
+
+const struct mxs_i2c_speed_config mxs_i2c_95kHz_config = {

You are using 95k?
Didnt understand this.

drivers/i2c/busses/i2c-mxs.c line 121

Quoted 11 lines
drivers/i2c/busses/i2c-mxs.c +11 -0
+ ? ? ? .timing0 ? ? ? ?= 0x00780030,
+ ? ? ? .timing1 ? ? ? ?= 0x00800030,
+ ? ? ? .timing2 ? ? ? ?= 0x0015000d,
+};
+
+const struct mxs_i2c_speed_config mxs_i2c_400kHz_config = {
+ ? ? ? .timing0 ? ? ? ?= 0x000f0007,
+ ? ? ? .timing1 ? ? ? ?= 0x001f000f,
+ ? ? ? .timing2 ? ? ? ?= 0x0015000d,
+};
+

How are these values calculated?

#3 lore raw

PATCH v2 1/2 MXS: Set I2C timing registers for mxs-i2c

Dear Shubhrajyoti Datta,

Quoted 77 lines · Marek Vasut
Quoted 76 lines

This patch configures the I2C bus timing registers according to information passed via DT. Currently, 100kHz and 400kHz modes are supported.

Cc Detlev Zundel <[email protected]>
CC Dong Aisheng <[email protected]>
CC Fabio Estevam <[email protected]>
Cc Linux ARM kernel <[email protected]>
Cc linux-i2c at vger.kernel.org
CC Sascha Hauer <[email protected]>
CC Shawn Guo <[email protected]>
Cc Stefano Babic <[email protected]>
CC Uwe Kleine-K?nig <[email protected]>
Cc Wolfgang Denk <[email protected]>
Cc Wolfram Sang <[email protected]>
---
 Documentation/devicetree/bindings/i2c/i2c-mxs.txt |    1 +
 arch/arm/boot/dts/imx28.dtsi                      |    2 +
 drivers/i2c/busses/i2c-mxs.c                      |   54

+++++++++++++++++++++ 3 files changed, 57 insertions(+)

V2: Use clock-frequency instead

(quoted diff) +0 -0

b/Documentation/devicetree/bindings/i2c/i2c-mxs.txt index 1bfc02d..d2bf750 100644

Documentation/devicetree/bindings/i2c/i2c-mxs.txt +1 -0
@@ -4,6 +4,7 @@ Required properties:
 - compatible: Should be "fsl,<chip>-i2c"
 - reg: Should contain registers location and length
 - interrupts: Should contain ERROR and DMA interrupts
+- clock-frequency: desired I2C bus clock frequency in Hz.
 
 Examples:
 
arch/arm/boot/dts/imx28.dtsi +2 -0
index a89da5a..714e63c 100644
@@ -398,6 +398,7 @@
                               compatible = "fsl,imx28-i2c";
                               reg = <0x80058000 2000>;
                               interrupts = <111 68>;
+                               clock-frequency = <400000>;
                               status = "disabled";
                       };
 
@@ -407,6 +408,7 @@
                               compatible = "fsl,imx28-i2c";
                               reg = <0x8005a000 2000>;
                               interrupts = <110 69>;
+                               clock-frequency = <400000>;
                               status = "disabled";
                       };
 
drivers/i2c/busses/i2c-mxs.c +4 -0
index 04eb441..b4d083f 100644
@@ -46,6 +46,10 @@
 #define MXS_I2C_CTRL0_DIRECTION                        0x00010000
 #define MXS_I2C_CTRL0_XFER_COUNT(v)            ((v) & 0x0000FFFF)
 
+#define MXS_I2C_TIMING0                (0x10)
+#define MXS_I2C_TIMING1                (0x20)
+#define MXS_I2C_TIMING2                (0x30)
+
 #define MXS_I2C_CTRL1          (0x40)
 #define MXS_I2C_CTRL1_SET      (0x44)
 #define MXS_I2C_CTRL1_CLR      (0x48)
@@ -97,6 +101,24 @@
 #define MXS_CMD_I2C_READ       (MXS_I2C_CTRL0_SEND_NAK_ON_LAST | \
                                MXS_I2C_CTRL0_MASTER_MODE)
 
Quoted 9 lines

drivers/i2c/busses/i2c-mxs.c line 110

Quoted 7 lines
drivers/i2c/busses/i2c-mxs.c +7 -0
+struct mxs_i2c_speed_config {
+       uint32_t        timing0;
+       uint32_t        timing1;
+       uint32_t        timing2;
+};
+
+const struct mxs_i2c_speed_config mxs_i2c_95kHz_config = {

You are using 95k?

Yes

Quoted 1 line

Didnt understand this.

What exactly, it's running (according to the datasheet) at 95kHz.

Quoted 5 lines
Quoted 5 lines
drivers/i2c/busses/i2c-mxs.c +5 -0
+       .timing0        = 0x00780030,
+       .timing1        = 0x00800030,
+       .timing2        = 0x0015000d,
+};
+
Quoted 8 lines

drivers/i2c/busses/i2c-mxs.c line 121

Quoted 6 lines
drivers/i2c/busses/i2c-mxs.c +6 -0
+const struct mxs_i2c_speed_config mxs_i2c_400kHz_config = {
+       .timing0        = 0x000f0007,
+       .timing1        = 0x001f000f,
+       .timing2        = 0x0015000d,
+};
+

How are these values calculated?

They're not calculated, they're presented in the datasheet. There's no formula, even though I believe one could be derived given enough effort.

Best regards,
Marek Vasut

maintainer
#4 lore raw

PATCH v2 1/2 MXS: Set I2C timing registers for mxs-i2c

Quoted 21 lines · Marek Vasut

Dear Shubhrajyoti Datta,

Quoted 1 line

Didnt understand this.

What exactly, it's running (according to the datasheet) at 95kHz.

Quoted 5 lines
Quoted 5 lines
drivers/i2c/busses/i2c-mxs.c +5 -0
+       .timing0        = 0x00780030,
+       .timing1        = 0x00800030,
+       .timing2        = 0x0015000d,
+};
+
Quoted 8 lines

drivers/i2c/busses/i2c-mxs.c line 121

Quoted 6 lines
drivers/i2c/busses/i2c-mxs.c +6 -0
+const struct mxs_i2c_speed_config mxs_i2c_400kHz_config = {
+       .timing0        = 0x000f0007,
+       .timing1        = 0x001f000f,
+       .timing2        = 0x0015000d,
+};
+

How are these values calculated?

Quoted 2 lines

They're not calculated, they're presented in the datasheet. There's no formula, even though I believe one could be derived given enough effort.

Don't these values depend on the input clock of this unit? I don't know, just asking.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#5 lore raw

PATCH v2 1/2 MXS: Set I2C timing registers for mxs-i2c

Dear Sascha Hauer,

Quoted 21 lines · Marek Vasut
Quoted 20 lines

Dear Shubhrajyoti Datta,

Quoted 1 line

Didnt understand this.

What exactly, it's running (according to the datasheet) at 95kHz.

Quoted 13 lines

drivers/i2c/busses/i2c-mxs.c line 121

Quoted 11 lines
drivers/i2c/busses/i2c-mxs.c +11 -0
+       .timing0        = 0x00780030,
+       .timing1        = 0x00800030,
+       .timing2        = 0x0015000d,
+};
+
+const struct mxs_i2c_speed_config mxs_i2c_400kHz_config = {
+       .timing0        = 0x000f0007,
+       .timing1        = 0x001f000f,
+       .timing2        = 0x0015000d,
+};
+

How are these values calculated?

Quoted 5 lines
Quoted 2 lines

They're not calculated, they're presented in the datasheet. There's no formula, even though I believe one could be derived given enough effort.

Don't these values depend on the input clock of this unit? I don't know, just asking.

Isn't the i2c block supplied from 24MHz clock source in the mx28?

Quoted 1 line

Sascha

Best regards,
Marek Vasut

maintainer
#6 lore raw

PATCH v2 1/2 MXS: Set I2C timing registers for mxs-i2c

Quoted 23 lines · Marek Vasut

Dear Sascha Hauer,

Quoted 21 lines · Marek Vasut
Quoted 20 lines

Dear Shubhrajyoti Datta,

Quoted 1 line

Didnt understand this.

What exactly, it's running (according to the datasheet) at 95kHz.

Quoted 13 lines

drivers/i2c/busses/i2c-mxs.c line 121

Quoted 11 lines
drivers/i2c/busses/i2c-mxs.c +11 -0
+       .timing0        = 0x00780030,
+       .timing1        = 0x00800030,
+       .timing2        = 0x0015000d,
+};
+
+const struct mxs_i2c_speed_config mxs_i2c_400kHz_config = {
+       .timing0        = 0x000f0007,
+       .timing1        = 0x001f000f,
+       .timing2        = 0x0015000d,
+};
+

How are these values calculated?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

They're not calculated, they're presented in the datasheet. There's no formula, even though I believe one could be derived given enough effort.

Don't these values depend on the input clock of this unit? I don't know, just asking.

Isn't the i2c block supplied from 24MHz clock source in the mx28?

Maybe. Shouldn't this be checked then or at least mentioned that these values assume a certain clock frequency?

I wonder that currently the timing registers are not initialized at all. Do they depend on reset defaults or bootloader setup?

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#7 lore raw

PATCH v2 1/2 MXS: Set I2C timing registers for mxs-i2c

Dear Sascha Hauer,

Quoted 28 lines · Marek Vasut
Quoted 27 lines

Dear Sascha Hauer,

Quoted 25 lines · Marek Vasut
Quoted 23 lines

Dear Shubhrajyoti Datta,

Quoted 1 line

Didnt understand this.

What exactly, it's running (according to the datasheet) at 95kHz.

Quoted 5 lines
Quoted 5 lines
drivers/i2c/busses/i2c-mxs.c +5 -0
+       .timing0        = 0x00780030,
+       .timing1        = 0x00800030,
+       .timing2        = 0x0015000d,
+};
+
Quoted 8 lines

drivers/i2c/busses/i2c-mxs.c line 121

Quoted 6 lines
drivers/i2c/busses/i2c-mxs.c +6 -0
+const struct mxs_i2c_speed_config mxs_i2c_400kHz_config = {
+       .timing0        = 0x000f0007,
+       .timing1        = 0x001f000f,
+       .timing2        = 0x0015000d,
+};
+

How are these values calculated?

They're not calculated, they're presented in the datasheet. There's no formula, even though I believe one could be derived given enough effort.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Don't these values depend on the input clock of this unit? I don't know, just asking.

Isn't the i2c block supplied from 24MHz clock source in the mx28?

Maybe. Shouldn't this be checked then or at least mentioned that these values assume a certain clock frequency?

27.5.2 - 27.5.4 in the MX28 TRM -- these values are for 24MHz clock indeed.

Quoted 2 lines

I wonder that currently the timing registers are not initialized at all. Do they depend on reset defaults or bootloader setup?

They're set to default values in our case -- I dunno if your bootloader always sets them up differently.

Quoted 1 line

Sascha

Best regards,
Marek Vasut

#8 lore raw

PATCH v2 1/2 MXS: Set I2C timing registers for mxs-i2c

In reply to Marek Vasut
Quoted 11 lines
Quoted 10 lines

drivers/i2c/busses/i2c-mxs.c line 110

Quoted 8 lines
drivers/i2c/busses/i2c-mxs.c +7 -0
+struct mxs_i2c_speed_config {
+ ? ? ? uint32_t ? ? ? ?timing0;
+ ? ? ? uint32_t ? ? ? ?timing1;
+ ? ? ? uint32_t ? ? ? ?timing2;
+};
+
+const struct mxs_i2c_speed_config mxs_i2c_95kHz_config = {

You are using 95k?

Quoted 5 lines

Yes

Quoted 1 line

Didnt understand this.

What exactly, it's running (according to the datasheet) at 95kHz.

Did you intend 100k?
and approximating due to clock ... or some other limitaion?

That is what I was trying to understand.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+ ? ? ? .timing0 ? ? ? ?= 0x00780030,
+ ? ? ? .timing1 ? ? ? ?= 0x00800030,
+ ? ? ? .timing2 ? ? ? ?= 0x0015000d,
+};

#9 lore raw

PATCH v2 1/2 MXS: Set I2C timing registers for mxs-i2c

Dear Shubhrajyoti Datta,

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

drivers/i2c/busses/i2c-mxs.c line 110

Quoted 7 lines
drivers/i2c/busses/i2c-mxs.c +7 -0
+struct mxs_i2c_speed_config {
+       uint32_t        timing0;
+       uint32_t        timing1;
+       uint32_t        timing2;
+};
+
+const struct mxs_i2c_speed_config mxs_i2c_95kHz_config = {

You are using 95k?

Quoted 7 lines
Quoted 5 lines

Yes

Quoted 1 line

Didnt understand this.

What exactly, it's running (according to the datasheet) at 95kHz.

Did you intend 100k?

I intended to stick with the datasheet, if you manage to find explanation for why they chose 95kHz, I'd be interested to hear it ... btw. 24MHz/95kHz gives pretty weird divider, which is quite suspicious.

Quoted 1 line

and approximating due to clock ... or some other limitaion?

Doesn't seem to be the case, see "btw" part above.

Quoted 6 lines

That is what I was trying to understand.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/i2c/busses/i2c-mxs.c +4 -0
+       .timing0        = 0x00780030,
+       .timing1        = 0x00800030,
+       .timing2        = 0x0015000d,
+};

Best regards,
Marek Vasut