Skip to contentSkip to conversation

MXS: Implement DMA support into mxs-i2c

PATCH Superseded Marek Vasut 3 participants 11 messages Aug 24, 2012 – Oct 8, 2012

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

PATCH v4 1/1 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 Fabio Estevam <[email protected]>
Cc linux-i2c at vger.kernel.org
CC Shawn Guo <[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                      |  269 +++++++++++++++++++--
 3 files changed, 251 insertions(+), 22 deletions(-)

V2: Fixed return value from mxs_i2c_dma_setup_xfer().
Fixed coding style nitpicks
Call mxs_i2c_dma_finish() in failpath only if DMA is active
V3: Align with changes in previous patch
V4: Succumb to nonsense for the greater good ... like working EEPROMs
Add "use_pioqueue" module parameter

Documentation/devicetree/bindings/i2c/i2c-mxs.txt +2 -0
index 30ac3a0..7a3fe9e 100644
@@ -6,6 +6,7 @@ Required properties:
 - interrupts: Should contain ERROR and DMA interrupts
 - clock-frequency: Desired I2C bus clock frequency in Hz.
                    Only 100000Hz and 400000Hz modes are supported.
+- fsl,i2c-dma-channel: APBX DMA channel for the I2C
 
 Examples:
 
@@ -16,4 +17,5 @@ i2c0: i2c at 80058000 {
 	reg = <0x80058000 2000>;
 	interrupts = <111 68>;
 	clock-frequency = <100000>;
+	fsl,i2c-dma-channel = <6>;
 };
arch/arm/boot/dts/imx28.dtsi +2 -0
index 3fa6d19..ba8227e 100644
@@ -661,6 +661,7 @@
 				reg = <0x80058000 0x2000>;
 				interrupts = <111 68>;
 				clock-frequency = <100000>;
+				fsl,i2c-dma-channel = <6>;
 				status = "disabled";
 			};
 
@@ -671,6 +672,7 @@
 				reg = <0x8005a000 0x2000>;
 				interrupts = <110 69>;
 				clock-frequency = <100000>;
+				fsl,i2c-dma-channel = <7>;
 				status = "disabled";
 			};
 
drivers/i2c/busses/i2c-mxs.c +247 -22

377 lines not on this page · raw message

Signature · 1 line
1.7.10.4
reviewer
#1 lore raw

PATCH v4 1/1 MXS: Implement DMA support into mxs-i2c

Quoted 8 lines · Marek Vasut

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

CC Fabio Estevam <[email protected]>
Cc linux-i2c at vger.kernel.org
CC Shawn Guo <[email protected]>
Cc Wolfram Sang <[email protected]>

On a mx28evk:

Wolfram,

Adding dma support into mxs-i2c has also the benefit to allow i2c on mx23 to work.

Please consider applying this one.

Thanks,

Fabio Estevam

#2 lore raw

PATCH v4 1/1 MXS: Implement DMA support into mxs-i2c

Quoted 10 lines · Fabio Estevam
Quoted 8 lines · Marek Vasut

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

CC Fabio Estevam <[email protected]>
Cc linux-i2c at vger.kernel.org
CC Shawn Guo <[email protected]>
Cc Wolfram Sang <[email protected]>
Quoted 3 lines

On a mx28evk:

Thanks, may I ask what your tests were?

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/20120916/ecd63a5b/attachment.sig>
reviewer
#3 lore raw

PATCH v4 1/1 MXS: Implement DMA support into mxs-i2c

Hi Wolfram,

Quoted 3 lines · Wolfram Sang
Quoted 1 line

Thanks, may I ask what your tests were?

I used i2c-tools to read/write to an i2c at24 eeprom connected to my mx28evk.

Regards,

Fabio Estevam

#4 lore raw

PATCH v4 1/1 MXS: Implement DMA support into mxs-i2c

In reply to Marek Vasut
Quoted 4 lines · Marek Vasut

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

Unsurprisingly, I also couldn't get the mode switching between DMA and PIOQUEUE to work :(

However, I did come up with an idea how to select DMA or PIOQUEUE per bus via devicetree. If we change the view from "I want PIOQUEUE" to "I don't want DMA", we could simply override the default DMA configuration in the devicetree with, e.g.:

			i2c0: i2c at 80058000 {
				...
				fsl,i2c-dma-channel = <>;
			};

So, no DMA channel set up will fall back to PIOQUEUE. This is more generic than a custom binding, because if one doesn't want DMA, don't configure it. That should also work with other devices which can fall back to something. I think this is worth trying, another advantage is that it doesn't expose something new to the user. So, there is no legacy support needed in case there will be a better way of configuration.

So, here is a proof-of-concept patch which adds that to Marek's DMA implementation which I'd like to fold into it. I am about to prepare a proper series and will post it later today. Comments appreciated.

Thanks,

Wolfram

drivers/i2c/busses/i2c-mxs.c +13 -19
index 1f58197..0198a43 100644
@@ -35,10 +35,6 @@
 
 #define DRIVER_NAME "mxs-i2c"
 
-static bool use_pioqueue;
-module_param(use_pioqueue, bool, 0);
-MODULE_PARM_DESC(use_pioqueue, "Use PIOQUEUE mode for transfer instead of DMA");
-
 #define MXS_I2C_CTRL0		(0x00)
 #define MXS_I2C_CTRL0_SET	(0x04)
 
@@ -556,24 +552,13 @@ static int mxs_i2c_get_ofdata(struct mxs_i2c_dev *i2c)
 	int ret;
 
 	/*
-	 * The MXS I2C DMA mode is prefered and enabled by default.
-	 * The PIO mode is still supported, but should be used only
-	 * for debuging purposes etc.
-	 */
-	i2c->dma_mode = !use_pioqueue;
-	if (!i2c->dma_mode)
-		dev_info(dev, "Using PIOQUEUE mode for I2C transfers!\n");
-
-	/*
 	 * TODO: This is a temporary solution and should be changed
 	 * to use generic DMA binding later when the helpers get in.
 	 */
 	ret = of_property_read_u32(node, "fsl,i2c-dma-channel",
 				   &i2c->dma_channel);
-	if (ret) {
-		dev_warn(dev, "Failed to get DMA channel, using PIOQUEUE!\n");
-		i2c->dma_mode = 0;
-	}
+	if (ret)
+		i2c->dma_mode = false;
 
 	ret = of_property_read_u32(node, "clock-frequency", &speed);
 	if (ret)
@@ -624,6 +609,13 @@ static int __devinit mxs_i2c_probe(struct platform_device *pdev)
 	if (err)
 		return err;
 
+	/*
+	 * The MXS I2C DMA mode is prefered and enabled by default.
+	 * Ideally, we'd switch between PIOQUEUE and DMA depending on the
+	 * message size, but neither Marek Vasut nor Wolfram Sang got this
+	 * to work without resetting the controller completely :(
+	 */
+	i2c->dma_mode = true;
 	i2c->dev = dev;
 	i2c->speed = &mxs_i2c_95kHz_config;
 
@@ -640,8 +632,8 @@ static int __devinit mxs_i2c_probe(struct platform_device *pdev)
 		i2c->dma_data.chan_irq = dmairq;
 		i2c->dmach = dma_request_channel(mask, mxs_i2c_dma_filter, i2c);
 		if (!i2c->dmach) {
-			dev_err(dev, "Failed to request dma\n");
-			return -ENODEV;
+			dev_err(dev, "Failed to request dma, falling back\n");
+			i2c->dma_mode = false;
 		}
 	}
 
@@ -668,6 +660,8 @@ static int __devinit mxs_i2c_probe(struct platform_device *pdev)
 
 	of_i2c_register_devices(adap);
 
+	dev_info(dev, "registered. DMA: %s\n", i2c->dma_mode ? "on" : "off");
+
 	return 0;
 }
 
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/20120916/589f15da/attachment.sig>
#5 lore raw

PATCH v4 1/1 MXS: Implement DMA support into mxs-i2c

Dear Wolfram Sang,

Quoted 8 lines · Marek Vasut
Quoted 4 lines

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

Unsurprisingly, I also couldn't get the mode switching between DMA and PIOQUEUE to work :(

I'd say more work should be invested into this. Besides, what about rather trying PIO + DMA instead of PIOQ + DMA?

Quoted 10 lines

However, I did come up with an idea how to select DMA or PIOQUEUE per bus via devicetree. If we change the view from "I want PIOQUEUE" to "I don't want DMA", we could simply override the default DMA configuration in the devicetree with, e.g.:

			i2c0: i2c at 80058000 {
				...
				fsl,i2c-dma-channel = <>;
			};
Quoted 6 lines

So, no DMA channel set up will fall back to PIOQUEUE. This is more generic than a custom binding, because if one doesn't want DMA, don't configure it. That should also work with other devices which can fall back to something. I think this is worth trying, another advantage is that it doesn't expose something new to the user. So, there is no legacy support needed in case there will be a better way of configuration.

Ewww ... that's such an ad-hoc hack. Besides, someone might simply forget to add the binding, you'd need to print a warning.

Quoted 76 lines

So, here is a proof-of-concept patch which adds that to Marek's DMA implementation which I'd like to fold into it. I am about to prepare a proper series and will post it later today. Comments appreciated.

Thanks,

Wolfram

drivers/i2c/busses/i2c-mxs.c +0 -3
index 1f58197..0198a43 100644
@@ -35,10 +35,6 @@
 
 #define DRIVER_NAME "mxs-i2c"
 
-static bool use_pioqueue;
-module_param(use_pioqueue, bool, 0);
-MODULE_PARM_DESC(use_pioqueue, "Use PIOQUEUE mode for transfer instead of

DMA"); -
#define MXS_I2C_CTRL0 (0x00)
#define MXS_I2C_CTRL0_SET (0x04)

drivers/i2c/busses/i2c-mxs.c +11 -15
@@ -556,24 +552,13 @@ static int mxs_i2c_get_ofdata(struct mxs_i2c_dev
 *i2c) int ret;
 
 	/*
-	 * The MXS I2C DMA mode is prefered and enabled by default.
-	 * The PIO mode is still supported, but should be used only
-	 * for debuging purposes etc.
-	 */
-	i2c->dma_mode = !use_pioqueue;
-	if (!i2c->dma_mode)
-		dev_info(dev, "Using PIOQUEUE mode for I2C transfers!\n");
-
-	/*
 	 * TODO: This is a temporary solution and should be changed
 	 * to use generic DMA binding later when the helpers get in.
 	 */
 	ret = of_property_read_u32(node, "fsl,i2c-dma-channel",
 				   &i2c->dma_channel);
-	if (ret) {
-		dev_warn(dev, "Failed to get DMA channel, using PIOQUEUE!\n");
-		i2c->dma_mode = 0;
-	}
+	if (ret)
+		i2c->dma_mode = false;
 
 	ret = of_property_read_u32(node, "clock-frequency", &speed);
 	if (ret)
@@ -624,6 +609,13 @@ static int __devinit mxs_i2c_probe(struct
 platform_device *pdev) if (err)
 		return err;
 
+	/*
+	 * The MXS I2C DMA mode is prefered and enabled by default.
+	 * Ideally, we'd switch between PIOQUEUE and DMA depending on the
+	 * message size, but neither Marek Vasut nor Wolfram Sang got this
+	 * to work without resetting the controller completely :(
+	 */
+	i2c->dma_mode = true;
 	i2c->dev = dev;
 	i2c->speed = &mxs_i2c_95kHz_config;
 
@@ -640,8 +632,8 @@ static int __devinit mxs_i2c_probe(struct
 platform_device *pdev) i2c->dma_data.chan_irq = dmairq;
 		i2c->dmach = dma_request_channel(mask, mxs_i2c_dma_filter, i2c);
 		if (!i2c->dmach) {
-			dev_err(dev, "Failed to request dma\n");
-			return -ENODEV;
+			dev_err(dev, "Failed to request dma, falling back\n");
+			i2c->dma_mode = false;
 		}
 	}
 

drivers/i2c/busses/i2c-mxs.c static int __devinit mxs_i2c_probe(struct · line 664

Quoted 5 lines
drivers/i2c/busses/i2c-mxs.c +1 -0
@@ -668,6 +660,8 @@ static int __devinit mxs_i2c_probe(struct
 platform_device *pdev)
 
 	of_i2c_register_devices(adap);
 
+	dev_info(dev, "registered. DMA: %s\n", i2c->dma_mode ? "on" : "off");

dev_debug() ?

Quoted 3 lines
drivers/i2c/busses/i2c-mxs.c +1 -0
+
 	return 0;
 }
#6 lore raw

PATCH v4 1/1 MXS: Implement DMA support into mxs-i2c

Quoted 5 lines
Quoted 3 lines

Unsurprisingly, I also couldn't get the mode switching between DMA and PIOQUEUE to work :(

I'd say more work should be invested into this.

I ran out of ideas. Next thing I'd do is to ask FSL if this is possible at all. Yet, I'd like to have some solution for 3.7.

Quoted 1 line

Besides, what about rather > trying PIO + DMA instead of PIOQ + DMA?

That could also be a solution.

Quoted 10 lines
Quoted 10 lines

However, I did come up with an idea how to select DMA or PIOQUEUE per bus via devicetree. If we change the view from "I want PIOQUEUE" to "I don't want DMA", we could simply override the default DMA configuration in the devicetree with, e.g.:

			i2c0: i2c at 80058000 {
				...
				fsl,i2c-dma-channel = <>;
			};
Quoted 8 lines
Quoted 6 lines

So, no DMA channel set up will fall back to PIOQUEUE. This is more generic than a custom binding, because if one doesn't want DMA, don't configure it. That should also work with other devices which can fall back to something. I think this is worth trying, another advantage is that it doesn't expose something new to the user. So, there is no legacy support needed in case there will be a better way of configuration.

Ewww ... that's such an ad-hoc hack.

Please give reasons.

Quoted 2 lines

Besides, someone might simply forget to add the binding, you'd need to print a warning.

? It is "on" by default because of the entry in the dtsi. And the status of DMA will be printed.

Quoted 3 lines

drivers/i2c/busses/i2c-mxs.c static int __devinit mxs_i2c_probe(struct platform_device *pdev) · line 663

Quoted 1 line
drivers/i2c/busses/i2c-mxs.c +1 -0
+	dev_info(dev, "registered. DMA: %s\n", i2c->dma_mode ? "on" : "off");

dev_debug() ?

Yup.

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/20120916/992906f8/attachment-0001.sig>
#7 lore raw

PATCH v4 1/1 MXS: Implement DMA support into mxs-i2c

Dear Wolfram Sang,

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Unsurprisingly, I also couldn't get the mode switching between DMA and PIOQUEUE to work :(

I'd say more work should be invested into this.

I ran out of ideas. Next thing I'd do is to ask FSL if this is possible at all. Yet, I'd like to have some solution for 3.7.

Why? You now have the module option solution.

Quoted 24 lines
Quoted 1 line

Besides, what about rather > trying PIO + DMA instead of PIOQ + DMA?

That could also be a solution.

Quoted 20 lines
Quoted 19 lines

However, I did come up with an idea how to select DMA or PIOQUEUE per bus via devicetree. If we change the view from "I want PIOQUEUE" to "I don't want DMA", we could simply override the default DMA configuration

in the devicetree with, e.g.:

			i2c0: i2c at 80058000 {
			
				...
				fsl,i2c-dma-channel = <>;
			
			};

So, no DMA channel set up will fall back to PIOQUEUE. This is more generic than a custom binding, because if one doesn't want DMA, don't configure it. That should also work with other devices which can fall back to something. I think this is worth trying, another advantage is that it doesn't expose something new to the user. So, there is no legacy support needed in case there will be a better way of configuration.

Quoted 3 lines
Quoted 1 line

Ewww ... that's such an ad-hoc hack.

Please give reasons.

It's abuse of proper configuration of hardware property.

Quoted 11 lines
Quoted 2 lines

Besides, someone might simply forget to add the binding, you'd need to print a warning.

? It is "on" by default because of the entry in the dtsi. And the status of DMA will be printed.

Quoted 3 lines

drivers/i2c/busses/i2c-mxs.c static int __devinit mxs_i2c_probe(struct platform_device *pdev) · line 663

Quoted 1 line
drivers/i2c/busses/i2c-mxs.c +1 -0
+	dev_info(dev, "registered. DMA: %s\n", i2c->dma_mode ? "on" : "off");

dev_debug() ?

Yup.

Best regards,
Marek Vasut

#8 lore raw

PATCH v4 1/1 MXS: Implement DMA support into mxs-i2c

In reply to Wolfram Sang

Dear Wolfram Sang,

[...]

Didn't you claim you're adding this DMA patch into next some time ago finally? ;-)

Subject: Re: I2C_FUNC_SMBUS_QUICK on i2c-mxs
Message-ID: <[email protected]>

Best regards,
Marek Vasut

Applied
#9 lore raw

PATCH v4 1/1 MXS: Implement DMA support into mxs-i2c

In reply to Marek Vasut
Quoted 4 lines · Marek Vasut

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

Thanks, applied to -next.

I am meanwhile thinking the driver needs massive changes, probably dropping PIOQUEUE entirely. This is probably best done via incremental patches to this one. I have sketches which were sadly not ready for this merge-window :(

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/20121008/2e129d13/attachment.sig>
#10 lore raw

PATCH v4 1/1 MXS: Implement DMA support into mxs-i2c

Dear Wolfram Sang,

Quoted 9 lines · Marek Vasut
Quoted 4 lines

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

Thanks, applied to -next.

I am meanwhile thinking the driver needs massive changes

+1 it does.

Quoted 1 line

probably dropping PIOQUEUE entirely

Yes, in favor of PIO which can do switching with DMA.

Quoted 3 lines

This is probably best done via incremental
patches to this one. I have sketches which were sadly not ready for this merge-window :(

Cc me when submitting, I'd like to see those.

Best regards,
Marek Vasut