Skip to contentSkip to conversation

MXS: Set I2C timing registers for mxs-i2c

PATCH Superseded Marek Vasut 3 participants 8 messages Jul 6, 2012 – Jul 10, 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.

The TIMING2 register value is wrong in the documentation for i.MX28! This was found and fixed by:
Shawn Guo <[email protected]>

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 |    2 +
 arch/arm/boot/dts/imx28.dtsi                      |    2 +
 drivers/i2c/busses/i2c-mxs.c                      |   56 +++++++++++++++++++++
 3 files changed, 60 insertions(+)

V2: (even though technically V<around 4>, I really need to start doing this
patch management properly, it's quite a mess now)
Fixed static const struct mxs_i2c_speed_config ... pointed by Dong.

Documentation/devicetree/bindings/i2c/i2c-mxs.txt +2 -0
index 1bfc02d..2ed5332 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:
 
@@ -13,4 +14,5 @@ i2c0: i2c at 80058000 {
 	compatible = "fsl,imx28-i2c";
 	reg = <0x80058000 2000>;
 	interrupts = <111 68>;
+	clock-frequency = <400000>;
 };
arch/arm/boot/dts/imx28.dtsi +2 -0
index ee3778a..832d30a 100644
@@ -419,6 +419,7 @@
 				compatible = "fsl,imx28-i2c";
 				reg = <0x80058000 2000>;
 				interrupts = <111 68>;
+				clock-frequency = <400000>;
 				status = "disabled";
 			};
 
@@ -428,6 +429,7 @@
 				compatible = "fsl,imx28-i2c";
 				reg = <0x8005a000 2000>;
 				interrupts = <110 69>;
+				clock-frequency = <400000>;
 				status = "disabled";
 			};
 
drivers/i2c/busses/i2c-mxs.c +56 -0

91 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 |    5 +
 arch/arm/boot/dts/imx28.dtsi                      |    2 +
 drivers/i2c/busses/i2c-mxs.c                      |  267 +++++++++++++++++++--
 3 files changed, 252 insertions(+), 22 deletions(-)

V2: (even though technically V<around 4>, ditto here, slaps himself)
Fixed return value from mxs_i2c_dma_setup_xfer(), pointed by Dong. Fixed coding style nitpicks
Call mxs_i2c_dma_finish() in failpath only if DMA is active

Documentation/devicetree/bindings/i2c/i2c-mxs.txt +5 -0
index 2ed5332..d337cbc 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:
 
@@ -15,4 +19,5 @@ i2c0: i2c at 80058000 {
 	reg = <0x80058000 2000>;
 	interrupts = <111 68>;
 	clock-frequency = <400000>;
+	fsl,i2c-dma-channel = <6>;
 };
arch/arm/boot/dts/imx28.dtsi +2 -0
index 832d30a..e4a4842 100644
@@ -420,6 +420,7 @@
 				reg = <0x80058000 2000>;
 				interrupts = <111 68>;
 				clock-frequency = <400000>;
+				fsl,i2c-dma-channel = <6>;
 				status = "disabled";
 			};
 
@@ -430,6 +431,7 @@
 				reg = <0x8005a000 2000>;
 				interrupts = <110 69>;
 				clock-frequency = <400000>;
+				fsl,i2c-dma-channel = <7>;
 				status = "disabled";
 			};
 
drivers/i2c/busses/i2c-mxs.c +245 -22

372 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

Hi Marek,

thanks for the submission.

Quoted 3 lines · Marek Vasut

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

That limitation should be mentioned in the documentation.

Quoted 17 lines

The TIMING2 register value is wrong in the documentation for i.MX28! This was found and fixed by:
Shawn Guo <[email protected]>

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]>
Quoted 8 lines
---
 Documentation/devicetree/bindings/i2c/i2c-mxs.txt |    2 +
 arch/arm/boot/dts/imx28.dtsi                      |    2 +
 drivers/i2c/busses/i2c-mxs.c                      |   56 +++++++++++++++++++++
 3 files changed, 60 insertions(+)

V2: (even though technically V<around 4>, I really need to start doing this
patch management properly, it's quite a mess now)

Yup, it was :) Thanks for resending.

Quoted 33 lines

Fixed static const struct mxs_i2c_speed_config ... pointed by Dong.

Documentation/devicetree/bindings/i2c/i2c-mxs.txt +2 -0
index 1bfc02d..2ed5332 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:
 
@@ -13,4 +14,5 @@ i2c0: i2c at 80058000 {
 	compatible = "fsl,imx28-i2c";
 	reg = <0x80058000 2000>;
 	interrupts = <111 68>;
+	clock-frequency = <400000>;
 };
arch/arm/boot/dts/imx28.dtsi +1 -0
index ee3778a..832d30a 100644
@@ -419,6 +419,7 @@
 				compatible = "fsl,imx28-i2c";
 				reg = <0x80058000 2000>;
 				interrupts = <111 68>;
+				clock-frequency = <400000>;
 				status = "disabled";
 			};
 

arch/arm/boot/dts/imx28.dtsi line 432

Quoted 4 lines
arch/arm/boot/dts/imx28.dtsi +1 -0
@@ -428,6 +429,7 @@
 				compatible = "fsl,imx28-i2c";
 				reg = <0x8005a000 2000>;
 				interrupts = <110 69>;
+				clock-frequency = <400000>;

NACK on that. Not all slaves can do 400KHz, so this is not a sensible default.

Quoted 20 lines
arch/arm/boot/dts/imx28.dtsi +0 -0
 				status = "disabled";
 			};
 
drivers/i2c/busses/i2c-mxs.c +4 -0
index 04eb441..47a7e20 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,25 @@
 #define MXS_CMD_I2C_READ	(MXS_I2C_CTRL0_SEND_NAK_ON_LAST | \

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

Quoted 10 lines
drivers/i2c/busses/i2c-mxs.c +8 -0
 				 MXS_I2C_CTRL0_MASTER_MODE)
 
+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. */
+static const struct mxs_i2c_speed_config mxs_i2c_95kHz_config = {

Hmm, the 100KHz vs 95KHz issue is confusing. My suggestion would be to name this mxs_i2c_100kHz_config and write a comment that this is technically 95Khz due to limitation of the docs (or whatever). If you want to keep the name, then a similar comment should be placed...

Quoted 37 lines
drivers/i2c/busses/i2c-mxs.c +18 -0
+	.timing0	= 0x00780030,
+	.timing1	= 0x00800030,
+	.timing2	= 0x00300030,
+};
+
+static const struct mxs_i2c_speed_config mxs_i2c_400kHz_config = {
+	.timing0	= 0x000f0007,
+	.timing1	= 0x001f000f,
+	.timing2	= 0x00300030,
+};
+
 /**
  * struct mxs_i2c_dev - per device, private MXS-I2C data
  *
@@ -112,11 +135,17 @@ struct mxs_i2c_dev {
 	struct completion cmd_complete;
 	u32 cmd_err;
 	struct i2c_adapter adapter;
+	const struct mxs_i2c_speed_config *speed;
 };
 
 static void mxs_i2c_reset(struct mxs_i2c_dev *i2c)
 {
 	stmp_reset_block(i2c->regs);
+
+	writel(i2c->speed->timing0, i2c->regs + MXS_I2C_TIMING0);
+	writel(i2c->speed->timing1, i2c->regs + MXS_I2C_TIMING1);
+	writel(i2c->speed->timing2, i2c->regs + MXS_I2C_TIMING2);
+
 	writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_SET);
 	writel(MXS_I2C_QUEUECTRL_PIO_QUEUE_MODE,
 			i2c->regs + MXS_I2C_QUEUECTRL_SET);
@@ -319,6 +348,28 @@ static const struct i2c_algorithm mxs_i2c_algo = {
 	.functionality = mxs_i2c_func,
 };
 
+static int mxs_i2c_get_ofdata(struct mxs_i2c_dev *i2c)

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

Quoted 10 lines
drivers/i2c/busses/i2c-mxs.c +10 -0
+{
+	uint32_t speed;
+	struct device *dev = i2c->dev;
+	struct device_node *node = dev->of_node;
+	int ret;
+
+	if (!node)
+		return -EINVAL;
+
+	i2c->speed = &mxs_i2c_95kHz_config;

...here

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

Quoted 7 lines
drivers/i2c/busses/i2c-mxs.c +7 -0
+	ret = of_property_read_u32(node, "clock-frequency", &speed);
+	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");

Minor: s/Invalid/Unsupported/ ?

Quoted 22 lines
drivers/i2c/busses/i2c-mxs.c +9 -0
+
+	return 0;
+}
+
 static int __devinit mxs_i2c_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -358,6 +409,11 @@ static int __devinit mxs_i2c_probe(struct platform_device *pdev)
 		return err;
 
 	i2c->dev = dev;
+
+	err = mxs_i2c_get_ofdata(i2c);
+	if (err)
+		return err;
+
 	platform_set_drvdata(pdev, i2c);
 
 	/* Do reset to enforce correct startup after pinmuxing */
Signature · 1 line
1.7.10

Regards,

Wolfram

Signature · 9 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120709/a1602a2d/attachment.sig>
#3 lore raw

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

Dear Wolfram Sang,

[...]

Quoted 4 lines
Quoted 4 lines
arch/arm/boot/dts/imx28.dtsi +0 -0
index ee3778a..832d30a 100644

[...]

Quoted 10 lines

arch/arm/boot/dts/imx28.dtsi line 434

Quoted 7 lines
arch/arm/boot/dts/imx28.dtsi +1 -0
@@ -428,6 +429,7 @@
 
 				compatible = "fsl,imx28-i2c";
 				reg = <0x8005a000 2000>;
 				interrupts = <110 69>;
 
+				clock-frequency = <400000>;

NACK on that. Not all slaves can do 400KHz, so this is not a sensible default.

How many of such chips are there and how many of the chips can do 400kHz ? I believe the majority shouldn't suffer because of minority.

[...]

Best regards,
Marek Vasut

#4 lore raw

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

Quoted 12 lines
Quoted 5 lines
Quoted 5 lines
arch/arm/boot/dts/imx28.dtsi +0 -0
index ee3778a..832d30a 100644

[...]

Quoted 6 lines
Quoted 6 lines
arch/arm/boot/dts/imx28.dtsi +0 -0
@@ -428,6 +429,7 @@
 
 				compatible = "fsl,imx28-i2c";
 				reg = <0x8005a000 2000>;
 				interrupts = <110 69>;
 
Quoted 7 lines
Quoted 4 lines

arch/arm/boot/dts/imx28.dtsi line 434

Quoted 1 line
arch/arm/boot/dts/imx28.dtsi +1 -0
+				clock-frequency = <400000>;

NACK on that. Not all slaves can do 400KHz, so this is not a sensible default.

How many of such chips are there and how many of the chips can do 400kHz ? I believe the majority shouldn't suffer because of minority.

The kernel should work for all users, not only for the majority, so:
Better safe than sorry.

Also, defaults should make the system work. Tuning can be done later by somebody who understands what is needed.

And frankly, this attitude which made you add a potential regression is worrisome. I'd suggest to give stability a higher priority.

Regards,

Wolfram

Signature · 9 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120709/e81f2bc3/attachment.sig>
#5 lore raw

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

Dear Wolfram Sang,

Quoted 21 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0

b/arch/arm/boot/dts/imx28.dtsi index ee3778a..832d30a 100644

arch/arm/boot/dts/imx28.dtsi +0 -0

[...]

Quoted 6 lines
Quoted 6 lines
arch/arm/boot/dts/imx28.dtsi +0 -0
@@ -428,6 +429,7 @@
 
 				compatible = "fsl,imx28-i2c";
 				reg = <0x8005a000 2000>;
 				interrupts = <110 69>;
 
Quoted 7 lines
Quoted 4 lines

arch/arm/boot/dts/imx28.dtsi line 434

Quoted 1 line
arch/arm/boot/dts/imx28.dtsi +1 -0
+				clock-frequency = <400000>;

NACK on that. Not all slaves can do 400KHz, so this is not a sensible default.

How many of such chips are there and how many of the chips can do 400kHz ? I believe the majority shouldn't suffer because of minority.

Quoted 8 lines

The kernel should work for all users, not only for the majority, so:
Better safe than sorry.

Also, defaults should make the system work. Tuning can be done later by somebody who understands what is needed.

And frankly, this attitude which made you add a potential regression is worrisome. I'd suggest to give stability a higher priority.

I believe you misunderstood my intention. Setting it to 400kHz was done because it's what most people will use, therefore avoiding duplication (most of the board files will override this setting now). All right, your sane defaults here can be applied, I won't argue.

And frankly, you could have left the last jab out. Let's avoid attacking each other, I'm not in the mood for it today.

Quoted 3 lines

Regards,

Wolfram

Best regards,
Marek Vasut

#6 lore raw

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

Quoted 6 lines · Marek Vasut
Quoted 6 lines

The kernel should work for all users, not only for the majority, so:
Better safe than sorry.

Also, defaults should make the system work. Tuning can be done later by somebody who understands what is needed.

Quoted 7 lines
Quoted 2 lines

And frankly, this attitude which made you add a potential regression is worrisome. I'd suggest to give stability a higher priority.

I believe you misunderstood my intention. Setting it to 400kHz was done because it's what most people will use, therefore avoiding duplication (most of the board files will override this setting now). All right, your sane defaults here can be applied, I won't argue.

I think all I2C chips support 100 kHz, but only selected ones support 400 kHz.

rsc

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 Robert Schwebel,

Quoted 10 lines · Marek Vasut
Quoted 9 lines
Quoted 8 lines

The kernel should work for all users, not only for the majority, so:
Better safe than sorry.

Also, defaults should make the system work. Tuning can be done later by somebody who understands what is needed.

And frankly, this attitude which made you add a potential regression is worrisome. I'd suggest to give stability a higher priority.

Quoted 7 lines
Quoted 4 lines

I believe you misunderstood my intention. Setting it to 400kHz was done because it's what most people will use, therefore avoiding duplication (most of the board files will override this setting now). All right, your sane defaults here can be applied, I won't argue.

I think all I2C chips support 100 kHz, but only selected ones support 400 kHz.

Yes, this is correct. And I never argued about this.

But anyway, V3 patch is out, let's cut this discussion short.

Best regards,
Marek Vasut