Skip to contentSkip to conversation

MXS: Set I2C timing registers for mxs-i2c

PATCH Superseded Marek Vasut 2 participants 16 messages Jun 9, 2012 – Jun 27, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 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                      |   55 +++++++++++++++++++++
 3 files changed, 58 insertions(+)

V2: Use clock-frequency instead
V3: Document that 24MHz clock are the base for i2c speed settings

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 +55 -0

90 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 v3 1/2 MXS: Set I2C timing registers for mxs-i2c

In reply to Marek Vasut

Dear Marek Vasut,

Quoted 3 lines

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

[...]

drivers/i2c/busses/i2c-mxs.c

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;
+};
+
+/* Timing values for the default 24MHz clock supplied into the i2c block.

Thinking about these further -- does anyone have any idea how these numbers were derived? And possibly even formula for that?

And maybe we should somehow make sure the source runs on 24MHz (how?).

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

Quoted 11 lines

*/ +const struct mxs_i2c_speed_config mxs_i2c_95kHz_config = {

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

[...]

Best regards,
Marek Vasut

#3 lore raw

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

Quoted 11 lines · Marek Vasut

drivers/i2c/busses/i2c-mxs.c

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;
+};
+
+/* Timing values for the default 24MHz clock supplied into the i2c block.

Thinking about these further -- does anyone have any idea how these numbers were derived? And possibly even formula for that?

Quoted 2 lines

And maybe we should somehow make sure the source runs on 24MHz (how?).

There is nothing about I2C clock mentioned in CLKCTRL chapter. I just contacted design team and was told that I2C clock sources from APBX (xbus) clock and always runs at the same frequency there.

Signature · 2 lines
Regards,
Shawn
#4 lore raw

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

Dear Shawn Guo,

Quoted 13 lines · Marek Vasut
Quoted 12 lines
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;
+};
+
+/* Timing values for the default 24MHz clock supplied into the i2c

block.

Thinking about these further -- does anyone have any idea how these numbers were derived? And possibly even formula for that?

Quoted 5 lines
Quoted 1 line

And maybe we should somehow make sure the source runs on 24MHz (how?).

There is nothing about I2C clock mentioned in CLKCTRL chapter. I just contacted design team and was told that I2C clock sources from APBX (xbus) clock and always runs at the same frequency there.

Ok, then can you please try asking them how to exactly compute the values in timing0-timing2 registers? So we don't have to hardcode them like it's done now?

Best regards,
Marek Vasut

#5 lore raw

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

Quoted 3 lines · Marek Vasut

Ok, then can you please try asking them how to exactly compute the values in timing0-timing2 registers? So we don't have to hardcode them like it's done now?

It's determined I2C clock waveform you want to get. See i.MX28 RM "Figure 27-2. I2C Data and Clock Timing" and "Figure 27-3. I2C Data and Clock Timing Generation".

For example, if you run 12MHz APBX clock, and set HIGH_COUNT to 60, the I2C clock will have 60 cycle x (1/12MHz) = 5us time for its high period.

Signature · 2 lines
Regards,
Shawn
#6 lore raw

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

Dear Shawn Guo,

Quoted 5 lines · Marek Vasut
Quoted 3 lines

Ok, then can you please try asking them how to exactly compute the values in timing0-timing2 registers? So we don't have to hardcode them like it's done now?

Quoted 7 lines

It's determined I2C clock waveform you want to get. See i.MX28 RM "Figure 27-2. I2C Data and Clock Timing" and "Figure 27-3. I2C Data and Clock Timing Generation".

For example, if you run 12MHz APBX clock, and set HIGH_COUNT to 60, the I2C clock will have 60 cycle x (1/12MHz) = 5us time for its high period.

Ok, I think I see the equation. But what still doesn't make sense is how you got to the value of 48 (RCV_COUNT at 95kHz). And how you got 120 for HIGH_COUNT and 128 for LOW_COUNT?

Were these values based on some measurements, making them the best possible values? Won't computation of slightly different values affect reliability of this driver?

Best regards,
Marek Vasut

#7 lore raw

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

In reply to Marek Vasut
Quoted 5 lines · Marek Vasut

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

I gave it a test on imx28-evk board with audio playback. It seems the patch makes the first time playback non-functional, but the later playback is still working.

drivers/i2c/busses/i2c-mxs.c static const struct i2c_algorithm mxs_i2c_algo = { · line 361

Quoted 11 lines
drivers/i2c/busses/i2c-mxs.c +11 -0
+static int mxs_i2c_get_ofdata(struct mxs_i2c_dev *i2c)
+{
+	uint32_t speed;
+	struct device *dev = i2c->dev;
+	struct device_node *node = dev->of_node;
+
+	if (!node)
+		return -EINVAL;
+
+	i2c->speed = &mxs_i2c_95kHz_config;
+	ret = of_property_read_u32(node, "clock-frequency", &speed);

"ret" is undeclared.

Quoted 10 lines
drivers/i2c/busses/i2c-mxs.c +10 -0
+	if (ret)
+		dev_warn(dev, "No I2C speed selected, using 100kHz\n");
+	else if (speed == 400000)
+		i2c->speed = &mxs_i2c_400kHz_config;
+	else if (speed != 100000)
+		dev_warn(dev, "Invalid I2C speed selected, using 100kHz\n");
+
+	return 0;
+}
+
Signature · 2 lines
Regards,
Shawn
#8 lore raw

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

Dear Shawn Guo,

Quoted 10 lines · Marek Vasut
Quoted 5 lines

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

I gave it a test on imx28-evk board with audio playback. It seems the patch makes the first time playback non-functional, but the later playback is still working.

Any hints what can be the source of this issue? I tested it with i2c eeprom, saw no issues in there. I'll poke into it later.

Quoted 14 lines

drivers/i2c/busses/i2c-mxs.c static const struct i2c_algorithm mxs_i2c_algo = { · line 361

Quoted 11 lines
drivers/i2c/busses/i2c-mxs.c +11 -0
+static int mxs_i2c_get_ofdata(struct mxs_i2c_dev *i2c)
+{
+	uint32_t speed;
+	struct device *dev = i2c->dev;
+	struct device_node *node = dev->of_node;
+
+	if (!node)
+		return -EINVAL;
+
+	i2c->speed = &mxs_i2c_95kHz_config;
+	ret = of_property_read_u32(node, "clock-frequency", &speed);

"ret" is undeclared.

Quoted 10 lines

drivers/i2c/busses/i2c-mxs.c static const struct i2c_algorithm mxs_i2c_algo = { · line 371

Quoted 10 lines
drivers/i2c/busses/i2c-mxs.c +10 -0
+	if (ret)
+		dev_warn(dev, "No I2C speed selected, using 100kHz\n");
+	else if (speed == 400000)
+		i2c->speed = &mxs_i2c_400kHz_config;
+	else if (speed != 100000)
+		dev_warn(dev, "Invalid I2C speed selected, using 100kHz\n");
+
+	return 0;
+}
+

Best regards,
Marek Vasut

#9 lore raw

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

Dear Shawn Guo,

Quoted 5 lines
Quoted 5 lines · Marek Vasut
Quoted 4 lines

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

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I gave it a test on imx28-evk board with audio playback. It seems the patch makes the first time playback non-functional, but the later playback is still working.

Any hints what can be the source of this issue? I tested it with i2c eeprom, saw no issues in there. I'll poke into it later.

Ok, I managed to replicate it just now. Scrap my previous email.

Still, any idea what can cause this?

Best regards,
Marek Vasut

#10 lore raw

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

Quoted 4 lines · Marek Vasut

Ok, I managed to replicate it just now. Scrap my previous email.

Still, any idea what can cause this?

I just spent some time on it. It looks like a document issue (dammit).

The HW_I2C_TIMING2 EXAMPLE tells the value is 0x0015000d which is the one you looked at and used. But the register field figure tells it's 0x00300030, which seems the real case.

The mxs_i2c_reset at probe changes the value to 0x0015000d which causes the first time playback nonfunctional, but the mxs_i2c_reset call in mxs_i2c_xfer_msg happens to reset the value back to 0x00300030, and then second time playback starts working.

The changes below get everything work fine, both 100k and 400k. So with the changes in, you can add:

Regards,
Shawn

--8<---

drivers/i2c/busses/i2c-mxs.c +2 -2
index e38be56..c2467e9 100644
@@ -112,13 +112,13 @@ struct mxs_i2c_speed_config {
 const struct mxs_i2c_speed_config mxs_i2c_95kHz_config = {
        .timing0        = 0x00780030,
        .timing1        = 0x00800030,
-       .timing2        = 0x0015000d,
+       .timing2        = 0x00300030,
 };
 
 const struct mxs_i2c_speed_config mxs_i2c_400kHz_config = {
        .timing0        = 0x000f0007,
        .timing1        = 0x001f000f,
-       .timing2        = 0x0015000d,
+       .timing2        = 0x00300030,
 };
#11 lore raw

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

Dear Shawn Guo,

Quoted 11 lines · Marek Vasut
Quoted 3 lines

Ok, I managed to replicate it just now. Scrap my previous email.

Still, any idea what can cause this?

I just spent some time on it. It looks like a document issue (dammit).

The HW_I2C_TIMING2 EXAMPLE tells the value is 0x0015000d which is the one you looked at and used. But the register field figure tells it's 0x00300030, which seems the real case.

Quoted 7 lines

The mxs_i2c_reset at probe changes the value to 0x0015000d which causes the first time playback nonfunctional, but the mxs_i2c_reset call in mxs_i2c_xfer_msg happens to reset the value back to 0x00300030, and then second time playback starts working.

The changes below get everything work fine, both 100k and 400k. So with the changes in, you can add:

Ok, can you push the FSL guys to roll out updated document?

Do you consider it reasonable to add some calculations of these timing values or were they somehow fine-tuned with a scope/deep HW knowledge as the best working values and we should stick to those?

Quoted 15 lines

Regards,
Shawn

--8<---

drivers/i2c/busses/i2c-mxs.c +0 -0
index e38be56..c2467e9 100644
@@ -112,13 +112,13 @@ struct mxs_i2c_speed_config {
 const struct mxs_i2c_speed_config mxs_i2c_95kHz_config = {
        .timing0        = 0x00780030,
        .timing1        = 0x00800030,

drivers/i2c/busses/i2c-mxs.c struct mxs_i2c_speed_config { · line 122

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

Best regards,
Marek Vasut

#12 lore raw

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

In reply to Marek Vasut

Dear Shawn Guo,

Quoted 3 lines

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

[...]

Is there any reason why this can not be merged other than the timing registers goo (which I believe shall stay as in the datasheet until we figure out if it's even reasonable to add some computation there).

Best regards,
Marek Vasut

#13 lore raw

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

Quoted 11 lines · Marek Vasut

Dear Shawn Guo,

Quoted 3 lines

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

[...]

Is there any reason why this can not be merged other than the timing registers goo (which I believe shall stay as in the datasheet until we figure out if it's even reasonable to add some computation there).

I assume this is a question for Wolfram. But I guess part of the reason is there is still one comment from me staying unresolved.

Signature · 2 lines
Regards,
Shawn
#14 lore raw

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

Dear Shawn Guo,

Quoted 7 lines · Marek Vasut
Quoted 6 lines

Dear Shawn Guo,

Quoted 3 lines

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

Quoted 8 lines
Quoted 5 lines

[...]

Is there any reason why this can not be merged other than the timing registers goo (which I believe shall stay as in the datasheet until we figure out if it's even reasonable to add some computation there).

I assume this is a question for Wolfram. But I guess part of the reason is there is still one comment from me staying unresolved.

Ah, you mean about the audio? I'll poke into it tonight.

Best regards,
Marek Vasut

#15 lore raw

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

In reply to Shawn Guo

Dear Shawn Guo,

Quoted 7 lines · Marek Vasut
Quoted 6 lines

Dear Shawn Guo,

Quoted 3 lines

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

Quoted 8 lines
Quoted 5 lines

[...]

Is there any reason why this can not be merged other than the timing registers goo (which I believe shall stay as in the datasheet until we figure out if it's even reasonable to add some computation there).

I assume this is a question for Wolfram. But I guess part of the reason is there is still one comment from me staying unresolved.

Shawn, I just re-tested the i2c with mpg123 playing "MPEG 1.0 layer III, VBR, 44100 Hz joint-stereo" and it worked on a first try ... can you retest please?

Best regards,
Marek Vasut