Skip to contentSkip to conversation

ARM: mxs: move to generic DMA device tree binding

PATCH In review Shawn Guo 7 participants 28 messages Mar 5, 2013 – Mar 21, 2013

Subsystems (13)
lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

v2 cover ARM: mxs: move to generic DMA device tree binding

The series converts mxs-dma and its clients to generic DMA device tree binding/helper.

I published a branch below to ease people who is willing to help testing the series.

git://git.linaro.org/people/shawnguo/linux-2.6.git devel/mxs-dma-dt

Changes since v1:
- Remove the use of of_dma_filter_info which should not be needed by a customized xlate function
- Correct dma-names to have it mean the channel function in client devices
- Add a new dmaengine_pcm API snd_dmaengine_generic_pcm_open() for users that support generic DMA device tree binding
- Remove the old fsl,<module>-dma-channel properties from device tree

Subsystem maintainers,

I need your ACKs to have the series go via arm-soc as a whole if the patches look good to you.

Thanks,
Shawn

Shawn Guo (12):
ARM: dts: add generic DMA device tree binding for mxs-dma
dma: mxs-dma: use devm_* managed functions
dma: mxs-dma: move to generic device tree binding
mmc: mxs-mmc: move to use generic DMA helper
spi: mxs-spi: move to use generic DMA helper
i2c: i2c-mxs: move to use generic DMA helper
mtd: gpmi: move to use generic DMA helper
serial: mxs-auart: move to use generic DMA helper
ASoC: dmaengine_pcm: add snd_dmaengine_generic_pcm_open()
ASoC: mxs: move to use generic DMA helper
dma: mxs-dma: remove code left from generic DMA binding conversion
ARM: dts: remove old DMA binding data from client nodes

 .../devicetree/bindings/dma/fsl-mxs-dma.txt        |   49 +++++++-
 Documentation/devicetree/bindings/i2c/i2c-mxs.txt  |   12 +-
 Documentation/devicetree/bindings/mmc/mxs-mmc.txt  |   12 +-
 .../devicetree/bindings/mtd/gpmi-nand.txt          |   17 +--
 .../devicetree/bindings/sound/mxs-saif.txt         |   18 +--
 Documentation/devicetree/bindings/spi/mxs-spi.txt  |   12 +-
 .../bindings/tty/serial/fsl-mxs-auart.txt          |   16 ++-
 arch/arm/boot/dts/imx23.dtsi                       |   57 +++++++--
 arch/arm/boot/dts/imx28.dtsi                       |  104 +++++++++++-----
 arch/arm/boot/dts/imx6qdl.dtsi                     |   12 +-
 drivers/dma/mxs-dma.c                              |  128 +++++++++++---------
 drivers/i2c/busses/i2c-mxs.c                       |   40 +-----
 drivers/mmc/host/mxs-mmc.c                         |   48 +-------
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c             |   51 +-------
 drivers/mtd/nand/gpmi-nand/gpmi-nand.h             |    3 +-
 drivers/spi/spi-mxs.c                              |   60 ++-------
 drivers/tty/serial/mxs-auart.c                     |   52 +-------
 include/linux/fsl/mxs-dma.h                        |   20 ---
 include/linux/spi/mxs-spi.h                        |    4 +-
 include/sound/dmaengine_pcm.h                      |    2 +
 sound/soc/mxs/mxs-pcm.c                            |   42 +------
 sound/soc/mxs/mxs-pcm.h                            |    5 -
 sound/soc/mxs/mxs-saif.c                           |   28 +----
 sound/soc/mxs/mxs-saif.h                           |    1 -
 sound/soc/soc-dmaengine-pcm.c                      |   39 ++++++
 25 files changed, 368 insertions(+), 464 deletions(-)
 delete mode 100644 include/linux/fsl/mxs-dma.h
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v2 1/12 ARM: dts: add generic DMA device tree binding for mxs-dma

Add generic DMA device tree binding for mxs-dma. The changes include:

* Add channel interrupts into DMA controller nodes
* Add properties '#dma-cells' and 'dma-channels' for DMA controller nodes
* And properties 'dmas' and 'dma-names' for DMA client nodes
* Update mxs-dma device tree binding doc

---
 .../devicetree/bindings/dma/fsl-mxs-dma.txt        |   49 +++++++++++++++--
 arch/arm/boot/dts/imx23.dtsi                       |   42 +++++++++++++-
 arch/arm/boot/dts/imx28.dtsi                       |   58 +++++++++++++++++++-
 arch/arm/boot/dts/imx6qdl.dtsi                     |    8 ++-
 4 files changed, 148 insertions(+), 9 deletions(-)
Documentation/devicetree/bindings/dma/fsl-mxs-dma.txt +45 -4
index ded0398..a4873e5 100644
@@ -3,17 +3,58 @@
 Required properties:
 - compatible : Should be "fsl,<chip>-dma-apbh" or "fsl,<chip>-dma-apbx"
 - reg : Should contain registers location and length
+- interrupts : Should contain the interrupt numbers of DMA channels.
+  If a channel is empty/reserved, 0 should be filled in place.
+- #dma-cells : Must be <1>.  The number cell specifies the channel ID.
+- dma-channels : Number of channels supported by the DMA controller
+
+Optional properties:
+- interrupt-names : Name of DMA channel interrupts
 
 Supported chips:
 imx23, imx28.
 
 Examples:
-dma-apbh at 80004000 {
+
+dma_apbh: dma-apbh at 80004000 {
 	compatible = "fsl,imx28-dma-apbh";
-	reg = <0x80004000 2000>;
+	reg = <0x80004000 0x2000>;
+	interrupts = <82 83 84 85
+		      88 88 88 88
+		      88 88 88 88
+		      87 86 0 0>;
+	interrupt-names = "ssp0", "ssp1", "ssp2", "ssp3",
+			  "gpmi0", "gmpi1", "gpmi2", "gmpi3",
+			  "gpmi4", "gmpi5", "gpmi6", "gmpi7",
+			  "hsadc", "lcdif", "empty", "empty";
+	#dma-cells = <1>;
+	dma-channels = <16>;
 };
 
-dma-apbx at 80024000 {
+dma_apbx: dma-apbx at 80024000 {
 	compatible = "fsl,imx28-dma-apbx";
-	reg = <0x80024000 2000>;
+	reg = <0x80024000 0x2000>;
+	interrupts = <78 79 66 0
+		      80 81 68 69
+		      70 71 72 73
+		      74 75 76 77>;
+	interrupt-names = "auart4-rx", "aurat4-tx", "spdif-tx", "empty",
+			  "saif0", "saif1", "i2c0", "i2c1",
+			  "auart0-rx", "auart0-tx", "auart1-rx", "auart1-tx",
+			  "auart2-rx", "auart2-tx", "auart3-rx", "auart3-tx";
+	#dma-cells = <1>;
+	dma-channels = <16>;
+};
+
+DMA clients connected to the MXS DMA controller must use the format
+described in the dma.txt file.
+
+Examples:
+
+auart0: serial at 8006a000 {
+	compatible = "fsl,imx28-auart", "fsl,imx23-auart";
+	reg = <0x8006a000 0x2000>;
+	interrupts = <112>;
+	dmas = <&dma_apbx 8>, <&dma_apbx 9>;
+	dma-names = "rx", "tx";
 };
arch/arm/boot/dts/imx23.dtsi +40 -2

121 lines not on this page · raw message

arch/arm/boot/dts/imx28.dtsi +56 -2

173 lines not on this page · raw message

arch/arm/boot/dts/imx6qdl.dtsi +7 -1
index 06ec460..e6b8781 100644
@@ -65,9 +65,13 @@
 		interrupt-parent = <&intc>;
 		ranges;
 
-		dma-apbh at 00110000 {
+		dma_apbh: dma-apbh at 00110000 {
 			compatible = "fsl,imx6q-dma-apbh", "fsl,imx28-dma-apbh";
 			reg = <0x00110000 0x2000>;
+			interrupts = <0 13 0x04>, <0 13 0x04>, <0 13 0x04>, <0 13 0x04>;
+			interrupt-names = "gpmi0", "gpmi1", "gpmi2", "gpmi3";
+			#dma-cells = <1>;
+			dma-channels = <4>;
 			clocks = <&clks 106>;
 		};
 
@@ -83,6 +87,8 @@
 				 <&clks 150>, <&clks 149>;
 			clock-names = "gpmi_io", "gpmi_apb", "gpmi_bch",
 				      "gpmi_bch_apb", "per1_bch";
+			dmas = <&dma_apbh 0>;
+			dma-names = "gpmi";
 			fsl,gpmi-dma-channel = <0>;
 			status = "disabled";
 		};
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v2 1/12 ARM: dts: add generic DMA device tree binding for mxs-dma

arch/arm/boot/dts/imx6qdl.dtsi line 93

Quoted 7 lines · Shawn Guo
                                 <&clks 150>, <&clks 149>;
                        clock-names = "gpmi_io", "gpmi_apb", "gpmi_bch",
                                      "gpmi_bch_apb", "per1_bch";
arch/arm/boot/dts/imx6qdl.dtsi +2 -0
+                       dmas = <&dma_apbh 0>;
+                       dma-names = "gpmi";
                        fsl,gpmi-dma-channel = <0>;
                        status = "disabled";

Looks like a small bug:

In patch "[PATCH v2 07/12] mtd: gpmi: move to use generic DMA helper" you require the dma-names property for this device to be "rx-tx", not "gpmi".

Arnd

author
#3 lore raw

PATCH v2 1/12 ARM: dts: add generic DMA device tree binding for mxs-dma

Quoted 9 lines · Arnd Bergmann

arch/arm/boot/dts/imx6qdl.dtsi line 93

Quoted 7 lines · Shawn Guo
                                 <&clks 150>, <&clks 149>;
                        clock-names = "gpmi_io", "gpmi_apb", "gpmi_bch",
                                      "gpmi_bch_apb", "per1_bch";
arch/arm/boot/dts/imx6qdl.dtsi +2 -0
+                       dmas = <&dma_apbh 0>;
+                       dma-names = "gpmi";
                        fsl,gpmi-dma-channel = <0>;
                        status = "disabled";
Quoted 5 lines

Looks like a small bug:

In patch "[PATCH v2 07/12] mtd: gpmi: move to use generic DMA helper" you require the dma-names property for this device to be "rx-tx", not "gpmi".

Dammit. I missed this one. Thanks for spotting it. Fixed.

Shawn

author
#4 lore raw

PATCH v2 2/12 dma: mxs-dma: use devm_* managed functions

In reply to Shawn Guo

Use devm_* managed functions to simplify probe() error handling.

---
 drivers/dma/mxs-dma.c |   39 +++++++++------------------------------
 1 file changed, 9 insertions(+), 30 deletions(-)
drivers/dma/mxs-dma.c +9 -30
index 8f6d30d..bb86f7f 100644
@@ -674,7 +674,7 @@ static int __init mxs_dma_probe(struct platform_device *pdev)
 	struct resource *iores;
 	int ret, i;
 
-	mxs_dma = kzalloc(sizeof(*mxs_dma), GFP_KERNEL);
+	mxs_dma = devm_kzalloc(&pdev->dev, sizeof(*mxs_dma), GFP_KERNEL);
 	if (!mxs_dma)
 		return -ENOMEM;
 
@@ -689,24 +689,13 @@ static int __init mxs_dma_probe(struct platform_device *pdev)
 	mxs_dma->dev_id = dma_type->id;
 
 	iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	mxs_dma->base = devm_ioremap_resource(&pdev->dev, iores);
+	if (IS_ERR(mxs_dma->base))
+		return PTR_ERR(mxs_dma->base);
 
-	if (!request_mem_region(iores->start, resource_size(iores),
-				pdev->name)) {
-		ret = -EBUSY;
-		goto err_request_region;
-	}
-
-	mxs_dma->base = ioremap(iores->start, resource_size(iores));
-	if (!mxs_dma->base) {
-		ret = -ENOMEM;
-		goto err_ioremap;
-	}
-
-	mxs_dma->clk = clk_get(&pdev->dev, NULL);
-	if (IS_ERR(mxs_dma->clk)) {
-		ret = PTR_ERR(mxs_dma->clk);
-		goto err_clk;
-	}
+	mxs_dma->clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(mxs_dma->clk))
+		return PTR_ERR(mxs_dma->clk);
 
 	dma_cap_set(DMA_SLAVE, mxs_dma->dma_device.cap_mask);
 	dma_cap_set(DMA_CYCLIC, mxs_dma->dma_device.cap_mask);
@@ -732,7 +721,7 @@ static int __init mxs_dma_probe(struct platform_device *pdev)
 
 	ret = mxs_dma_init(mxs_dma);
 	if (ret)
-		goto err_init;
+		return ret;
 
 	mxs_dma->dma_device.dev = &pdev->dev;
 
@@ -751,22 +740,12 @@ static int __init mxs_dma_probe(struct platform_device *pdev)
 	ret = dma_async_device_register(&mxs_dma->dma_device);
 	if (ret) {
 		dev_err(mxs_dma->dma_device.dev, "unable to register\n");
-		goto err_init;
+		return ret;
 	}
 
 	dev_info(mxs_dma->dma_device.dev, "initialized\n");
 
 	return 0;
-
-err_init:
-	clk_put(mxs_dma->clk);
-err_clk:
-	iounmap(mxs_dma->base);
-err_ioremap:
-	release_mem_region(iores->start, resource_size(iores));
-err_request_region:
-	kfree(mxs_dma);
-	return ret;
 }
 
 static struct platform_driver mxs_dma_driver = {
Signature · 1 line
1.7.9.5
author
#5 lore raw

PATCH v2 3/12 dma: mxs-dma: move to generic device tree binding

In reply to Shawn Guo

Update mxs-dma driver to adopt generic DMA device tree binding. It calls of_dma_controller_register() with mxs specific of_dma_xlate to get the generic DMA device tree helper support. Then DMA clients only need to call dma_request_slave_channel() for requesting a DMA channel from dmaengine.

The existing way of requesting channel, clients directly call dma_request_channel(), still work there, and will be removed after all mxs-dma clients get converted to generic DMA device tree helper.

---
 drivers/dma/mxs-dma.c |   70 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 66 insertions(+), 4 deletions(-)
drivers/dma/mxs-dma.c +66 -4
index bb86f7f..b48a79c 100644
@@ -27,6 +27,7 @@
 #include <linux/stmp_device.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
+#include <linux/of_dma.h>
 
 #include <asm/irq.h>
 
@@ -139,6 +140,8 @@ struct mxs_dma_engine {
 	struct dma_device		dma_device;
 	struct device_dma_parameters	dma_parms;
 	struct mxs_dma_chan		mxs_chans[MXS_DMA_CHANNELS];
+	struct platform_device		*pdev;
+	unsigned int			nr_channels;
 };
 
 struct mxs_dma_type {
@@ -350,10 +353,8 @@ static int mxs_dma_alloc_chan_resources(struct dma_chan *chan)
 	struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
 	int ret;
 
-	if (!data)
-		return -EINVAL;
-
-	mxs_chan->chan_irq = data->chan_irq;
+	if (data)
+		mxs_chan->chan_irq = data->chan_irq;
 
 	mxs_chan->ccw = dma_alloc_coherent(mxs_dma->dma_device.dev,
 				CCW_BLOCK_SIZE, &mxs_chan->ccw_phys,
@@ -665,8 +666,55 @@ err_out:
 	return ret;
 }
 
+struct mxs_dma_filter_param {
+	struct device_node *of_node;
+	unsigned int chan_id;
+};
+
+static bool mxs_dma_filter_fn(struct dma_chan *chan, void *fn_param)
+{
+	struct mxs_dma_filter_param *param = fn_param;
+	struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
+	struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
+	int chan_irq;
+
+	if (mxs_dma->dma_device.dev->of_node != param->of_node)
+		return false;
+
+	if (chan->chan_id != param->chan_id)
+		return false;
+
+	chan_irq = platform_get_irq(mxs_dma->pdev, param->chan_id);
+	if (chan_irq < 0)
+		return false;
+
+	mxs_chan->chan_irq = chan_irq;
+
+	return true;
+}
+
+struct dma_chan *mxs_dma_xlate(struct of_phandle_args *dma_spec,
+			       struct of_dma *ofdma)
+{
+	struct mxs_dma_engine *mxs_dma = ofdma->of_dma_data;
+	dma_cap_mask_t mask = mxs_dma->dma_device.cap_mask;
+	struct mxs_dma_filter_param param;
+
+	if (dma_spec->args_count != 1)
+		return NULL;
+
+	param.of_node = ofdma->of_node;
+	param.chan_id = dma_spec->args[0];
+
+	if (param.chan_id >= mxs_dma->nr_channels)
+		return NULL;
+
+	return dma_request_channel(mask, mxs_dma_filter_fn, &param);
+}
+
 static int __init mxs_dma_probe(struct platform_device *pdev)
 {
+	struct device_node *np = pdev->dev.of_node;
 	const struct platform_device_id *id_entry;
 	const struct of_device_id *of_id;
 	const struct mxs_dma_type *dma_type;
@@ -678,6 +726,12 @@ static int __init mxs_dma_probe(struct platform_device *pdev)
 	if (!mxs_dma)
 		return -ENOMEM;
 
+	ret = of_property_read_u32(np, "dma-channels", &mxs_dma->nr_channels);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to read dma-channels\n");
+		return ret;
+	}
+
 	of_id = of_match_device(mxs_dma_dt_ids, &pdev->dev);
 	if (of_id)
 		id_entry = of_id->data;
@@ -723,6 +777,7 @@ static int __init mxs_dma_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	mxs_dma->pdev = pdev;
 	mxs_dma->dma_device.dev = &pdev->dev;
 
 	/* mxs_dma gets 65535 bytes maximum sg size */
@@ -743,6 +798,13 @@ static int __init mxs_dma_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	ret = of_dma_controller_register(np, mxs_dma_xlate, mxs_dma);
+	if (ret) {
+		dev_err(mxs_dma->dma_device.dev,
+			"failed to register controller\n");
+		dma_async_device_unregister(&mxs_dma->dma_device);
+	}
+
 	dev_info(mxs_dma->dma_device.dev, "initialized\n");
 
 	return 0;
Signature · 1 line
1.7.9.5
author
#6 lore raw

PATCH v2 4/12 mmc: mxs-mmc: move to use generic DMA helper

In reply to Shawn Guo

With the generic DMA device tree helper supported by mxs-dma driver, client devices only need to call dma_request_slave_channel() for requesting a DMA channel from dmaengine.

Since mxs is a DT only platform now, along with the changes, the non-DT case checking in probe function also gets cleaned up.

Cc Chris Ball <[email protected]>
Cc linux-mmc at vger.kernel.org
---
 Documentation/devicetree/bindings/mmc/mxs-mmc.txt |   12 ++++--
 drivers/mmc/host/mxs-mmc.c                        |   48 +++------------------
 2 files changed, 13 insertions(+), 47 deletions(-)
Documentation/devicetree/bindings/mmc/mxs-mmc.txt +8 -4
index 54949f6..515addc 100644
@@ -9,15 +9,19 @@ and the properties used by the mxsmmc driver.
 Required properties:
 - compatible: Should be "fsl,<chip>-mmc".  The supported chips include
   imx23 and imx28.
-- interrupts: Should contain ERROR and DMA interrupts
-- fsl,ssp-dma-channel: APBH DMA channel for the SSP
+- interrupts: Should contain ERROR interrupt number
+- dmas: DMA specifier, consisting of a phandle to DMA controller node
+  and SSP DMA channel ID.
+  Refer to dma.txt and fsl-mxs-dma.txt for details.
+- dma-names: Must be "rx-tx".
 
 Examples:
 
 ssp0: ssp at 80010000 {
 	compatible = "fsl,imx28-mmc";
 	reg = <0x80010000 2000>;
-	interrupts = <96 82>;
-	fsl,ssp-dma-channel = <0>;
+	interrupts = <96>;
+	dmas = <&dma_apbh 0>;
+	dma-names = "rx-tx";
 	bus-width = <8>;
 };
drivers/mmc/host/mxs-mmc.c +5 -43

80 lines not on this page · raw message

Signature · 1 line
1.7.9.5
author
#7 lore raw

PATCH v2 5/12 spi: mxs-spi: move to use generic DMA helper

In reply to Shawn Guo

With the generic DMA device tree helper supported by mxs-dma driver, client devices only need to call dma_request_slave_channel() for requesting a DMA channel from dmaengine.

Since mxs is a DT only platform now, along with the changes, the non-DT case handling in probe function also gets removed.

---
 Documentation/devicetree/bindings/spi/mxs-spi.txt |   12 +++--
 drivers/spi/spi-mxs.c                             |   60 ++++-----------------
 include/linux/spi/mxs-spi.h                       |    4 +-
 3 files changed, 18 insertions(+), 58 deletions(-)
Documentation/devicetree/bindings/spi/mxs-spi.txt +8 -4
index e2e1395..3499b73 100644
@@ -3,8 +3,11 @@
 Required properties:
 - compatible: Should be "fsl,<soc>-spi", where soc is "imx23" or "imx28"
 - reg: Offset and length of the register set for the device
-- interrupts: Should contain SSP interrupts (error irq first, dma irq second)
-- fsl,ssp-dma-channel: APBX DMA channel for the SSP
+- interrupts: Should contain SSP ERROR interrupt
+- dmas: DMA specifier, consisting of a phandle to DMA controller node
+  and SSP DMA channel ID.
+  Refer to dma.txt and fsl-mxs-dma.txt for details.
+- dma-names: Must be "rx-tx".
 
 Optional properties:
 - clock-frequency : Input clock frequency to the SPI block in Hz.
@@ -17,6 +20,7 @@ ssp0: ssp at 80010000 {
 	#size-cells = <0>;
 	compatible = "fsl,imx28-spi";
 	reg = <0x80010000 0x2000>;
-	interrupts = <96 82>;
-	fsl,ssp-dma-channel = <0>;
+	interrupts = <96>;
+	dmas = <&dma_apbh 0>;
+	dma-names = "rx-tx";
 };
drivers/spi/spi-mxs.c +9 -51

100 lines not on this page · raw message

include/linux/spi/mxs-spi.h +1 -3
index 61ae130..4835486 100644
@@ -24,7 +24,7 @@
 #ifndef __LINUX_SPI_MXS_SPI_H__
 #define __LINUX_SPI_MXS_SPI_H__
 
-#include <linux/fsl/mxs-dma.h>
+#include <linux/dmaengine.h>
 
 #define ssp_is_old(host)	((host)->devid == IMX23_SSP)
 
@@ -137,9 +137,7 @@ struct mxs_ssp {
 	unsigned int			clk_rate;
 	enum mxs_ssp_id			devid;
 
-	int				dma_channel;
 	struct dma_chan			*dmach;
-	struct mxs_dma_data		dma_data;
 	unsigned int			dma_dir;
 	enum dma_transfer_direction	slave_dirn;
 	u32				ssp_pio_words[SSP_PIO_NUM];
Signature · 1 line
1.7.9.5
author
#8 lore raw

PATCH v2 6/12 i2c: i2c-mxs: move to use generic DMA helper

In reply to Shawn Guo

With the generic DMA device tree helper supported by mxs-dma driver, client devices only need to call dma_request_slave_channel() for requesting a DMA channel from dmaengine.

Cc Wolfram Sang <[email protected]>
Cc linux-i2c at vger.kernel.org
---
 Documentation/devicetree/bindings/i2c/i2c-mxs.txt |   12 ++++---
 drivers/i2c/busses/i2c-mxs.c                      |   40 ++-------------------
 2 files changed, 11 insertions(+), 41 deletions(-)
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +8 -4
index 7a3fe9e..4e1c8ac 100644
@@ -3,10 +3,13 @@
 Required properties:
 - compatible: Should be "fsl,<chip>-i2c"
 - reg: Should contain registers location and length
-- interrupts: Should contain ERROR and DMA interrupts
+- interrupts: Should contain ERROR interrupt number
 - 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
+- dmas: DMA specifier, consisting of a phandle to DMA controller node
+  and I2C DMA channel ID.
+  Refer to dma.txt and fsl-mxs-dma.txt for details.
+- dma-names: Must be "rx-tx".
 
 Examples:
 
@@ -15,7 +18,8 @@ i2c0: i2c at 80058000 {
 	#size-cells = <0>;
 	compatible = "fsl,imx28-i2c";
 	reg = <0x80058000 2000>;
-	interrupts = <111 68>;
+	interrupts = <111>;
 	clock-frequency = <100000>;
-	fsl,i2c-dma-channel = <6>;
+	dmas = <&dma_apbx 6>;
+	dma-names = "rx-tx";
 };
drivers/i2c/busses/i2c-mxs.c +3 -37
index 120f246..d1ba6b4 100644
@@ -31,7 +31,6 @@
 #include <linux/of_i2c.h>
 #include <linux/dma-mapping.h>
 #include <linux/dmaengine.h>
-#include <linux/fsl/mxs-dma.h>
 
 #define DRIVER_NAME "mxs-i2c"
 
@@ -113,9 +112,7 @@ struct mxs_i2c_dev {
 	uint32_t timing1;
 
 	/* DMA support components */
-	int				dma_channel;
 	struct dma_chan         	*dmach;
-	struct mxs_dma_data		dma_data;
 	uint32_t			pio_data[2];
 	uint32_t			addr_data;
 	struct scatterlist		sg_io[2];
@@ -518,21 +515,6 @@ static const struct i2c_algorithm mxs_i2c_algo = {
 	.functionality = mxs_i2c_func,
 };
 
-static bool mxs_i2c_dma_filter(struct dma_chan *chan, void *param)
-{
-	struct mxs_i2c_dev *i2c = param;
-
-	if (!mxs_dma_is_apbx(chan))
-		return false;
-
-	if (chan->chan_id != i2c->dma_channel)
-		return false;
-
-	chan->private = &i2c->dma_data;
-
-	return true;
-}
-
 static void mxs_i2c_derive_timing(struct mxs_i2c_dev *i2c, int speed)
 {
 	/* The I2C block clock run at 24MHz */
@@ -577,17 +559,6 @@ static int mxs_i2c_get_ofdata(struct mxs_i2c_dev *i2c)
 	struct device_node *node = dev->of_node;
 	int ret;
 
-	/*
-	 * 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_err(dev, "Failed to get DMA channel!\n");
-		return -ENODEV;
-	}
-
 	ret = of_property_read_u32(node, "clock-frequency", &speed);
 	if (ret) {
 		dev_warn(dev, "No I2C speed selected, using 100kHz\n");
@@ -607,8 +578,7 @@ static int mxs_i2c_probe(struct platform_device *pdev)
 	struct pinctrl *pinctrl;
 	struct resource *res;
 	resource_size_t res_size;
-	int err, irq, dmairq;
-	dma_cap_mask_t mask;
+	int err, irq;
 
 	pinctrl = devm_pinctrl_get_select_default(dev);
 	if (IS_ERR(pinctrl))
@@ -620,9 +590,8 @@ static int mxs_i2c_probe(struct platform_device *pdev)
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	irq = platform_get_irq(pdev, 0);
-	dmairq = platform_get_irq(pdev, 1);
 
-	if (!res || irq < 0 || dmairq < 0)
+	if (!res || irq < 0)
 		return -ENOENT;
 
 	res_size = resource_size(res);
@@ -648,10 +617,7 @@ static int mxs_i2c_probe(struct platform_device *pdev)
 	}
 
 	/* Setup the DMA */
-	dma_cap_zero(mask);
-	dma_cap_set(DMA_SLAVE, mask);
-	i2c->dma_data.chan_irq = dmairq;
-	i2c->dmach = dma_request_channel(mask, mxs_i2c_dma_filter, i2c);
+	i2c->dmach = dma_request_slave_channel(dev, "rx-tx");
 	if (!i2c->dmach) {
 		dev_err(dev, "Failed to request dma\n");
 		return -ENODEV;
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH v2 6/12 i2c: i2c-mxs: move to use generic DMA helper

Quoted 7 lines · Shawn Guo

With the generic DMA device tree helper supported by mxs-dma driver, client devices only need to call dma_request_slave_channel() for requesting a DMA channel from dmaengine.

Cc Wolfram Sang <[email protected]>
Cc linux-i2c at vger.kernel.org

Yay, DMA helpers \o/ Assuming the helpers work, for the i2c driver:

Thanks for doing this!

author
#10 lore raw

PATCH v2 7/12 mtd: gpmi: move to use generic DMA helper

In reply to Shawn Guo

With the generic DMA device tree helper supported by mxs-dma driver, client devices only need to call dma_request_slave_channel() for requesting a DMA channel from dmaengine.

Cc Artem Bityutskiy <[email protected]>
Cc linux-mtd at lists.infradead.org
---
 .../devicetree/bindings/mtd/gpmi-nand.txt          |   17 ++++---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c             |   51 +-------------------
 drivers/mtd/nand/gpmi-nand/gpmi-nand.h             |    3 +-
 3 files changed, 12 insertions(+), 59 deletions(-)
Documentation/devicetree/bindings/mtd/gpmi-nand.txt +10 -7
index 3fb3f901..551b2a1 100644
@@ -7,10 +7,12 @@ Required properties:
   - compatible : should be "fsl,<chip>-gpmi-nand"
   - reg : should contain registers location and length for gpmi and bch.
   - reg-names: Should contain the reg names "gpmi-nand" and "bch"
-  - interrupts : The first is the DMA interrupt number for GPMI.
-                 The second is the BCH interrupt number.
-  - interrupt-names : The interrupt names "gpmi-dma", "bch";
-  - fsl,gpmi-dma-channel : Should contain the dma channel it uses.
+  - interrupts : BCH interrupt number.
+  - interrupt-names : Should be "bch".
+  - dmas: DMA specifier, consisting of a phandle to DMA controller node
+    and GPMI DMA channel ID.
+    Refer to dma.txt and fsl-mxs-dma.txt for details.
+  - dma-names: Must be "rx-tx".
 
 Optional properties:
   - nand-on-flash-bbt: boolean to enable on flash bbt option if not
@@ -27,9 +29,10 @@ gpmi-nand at 8000c000 {
 	#size-cells = <1>;
 	reg = <0x8000c000 2000>, <0x8000a000 2000>;
 	reg-names = "gpmi-nand", "bch";
-	interrupts = <88>, <41>;
-	interrupt-names = "gpmi-dma", "bch";
-	fsl,gpmi-dma-channel = <4>;
+	interrupts = <41>;
+	interrupt-names = "bch";
+	dmas = <&dma_apbh 4>;
+	dma-names = "rx-tx";
 
 	partition at 0 {
 	...
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1 -50

72 lines not on this page · raw message

drivers/mtd/nand/gpmi-nand/gpmi-nand.h +1 -2
index 0729477..a7685e3 100644
@@ -20,7 +20,7 @@
 #include <linux/mtd/nand.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
-#include <linux/fsl/mxs-dma.h>
+#include <linux/dmaengine.h>
 
 #define GPMI_CLK_MAX 5 /* MX6Q needs five clocks */
 struct resources {
@@ -180,7 +180,6 @@ struct gpmi_nand_data {
 	/* DMA channels */
 #define DMA_CHANS		8
 	struct dma_chan		*dma_chans[DMA_CHANS];
-	struct mxs_dma_data	dma_data;
 	enum dma_ops_type	last_dma_type;
 	enum dma_ops_type	dma_type;
 	struct completion	dma_done;
Signature · 1 line
1.7.9.5
author
#11 lore raw

PATCH v2 8/12 serial: mxs-auart: move to use generic DMA helper

In reply to Shawn Guo

With the generic DMA device tree helper supported by mxs-dma driver, client devices only need to call dma_request_slave_channel() for requesting a DMA channel from dmaengine.

Cc Greg Kroah-Hartman <[email protected]>
Cc linux-serial at vger.kernel.org
---
 .../bindings/tty/serial/fsl-mxs-auart.txt          |   16 +++---
 drivers/tty/serial/mxs-auart.c                     |   52 ++------------------
 2 files changed, 11 insertions(+), 57 deletions(-)
Documentation/devicetree/bindings/tty/serial/fsl-mxs-auart.txt +7 -9
index 273a8d5..2c00ec6 100644
@@ -5,20 +5,18 @@ Required properties:
   imx23 and imx28.
 - reg : Address and length of the register set for the device
 - interrupts : Should contain the auart interrupt numbers
-
-Optional properties:
-- fsl,auart-dma-channel : The DMA channels, the first is for RX, the other
-		is for TX. If you add this property, it also means that you
-		will enable the DMA support for the auart.
-		Note: due to the hardware bug in imx23(see errata : 2836),
-		only the imx28 can enable the DMA support for the auart.
+- dmas: DMA specifier, consisting of a phandle to DMA controller node
+  and AUART DMA channel ID.
+  Refer to dma.txt and fsl-mxs-dma.txt for details.
+- dma-names: "rx" for RX channel, "tx" for TX channel.
 
 Example:
 auart0: serial at 8006a000 {
 	compatible = "fsl,imx28-auart", "fsl,imx23-auart";
 	reg = <0x8006a000 0x2000>;
-	interrupts = <112 70 71>;
-	fsl,auart-dma-channel = <8 9>;
+	interrupts = <112>;
+	dmas = <&dma_apbx 8>, <&dma_apbx 9>;
+	dma-names = "rx", "tx";
 };
 
 Note: Each auart port should have an alias correctly numbered in "aliases"
drivers/tty/serial/mxs-auart.c +4 -48

99 lines not on this page · raw message

Signature · 1 line
1.7.9.5
author
#13 lore raw

PATCH v2 9/12 ASoC: dmaengine_pcm: add snd_dmaengine_generic_pcm_open()

In reply to Shawn Guo

With generic DMA device tree binding and helper function dma_request_slave_channel() in place, dmaengine_pcm should support that in requesting DMA channel for users that support generic DMA device tree binding.

Add a new API snd_dmaengine_generic_pcm_open() as the variant of snd_dmaengine_pcm_open(). It takes DMA client struct device pointer and slave channel name as arguments and calls generic DMA helper dma_request_slave_channel() to request DMA channel from dmaengine.

Cc Mark Brown <[email protected]>
Cc alsa-devel at alsa-project.org

---
Mark,

Please maintain a topic branch for the patch if it looks good to you. It should be useful for any dmaengine_pcm user that is moving to generic DMA device tree binding.

Thanks,
Shawn

 include/sound/dmaengine_pcm.h |    2 ++
 sound/soc/soc-dmaengine-pcm.c |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
include/sound/dmaengine_pcm.h +2 -0
index b877334..452df15 100644
@@ -43,6 +43,8 @@ snd_pcm_uframes_t snd_dmaengine_pcm_pointer_no_residue(struct snd_pcm_substream
 
 int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream,
 	dma_filter_fn filter_fn, void *filter_data);
+int snd_dmaengine_generic_pcm_open(struct snd_pcm_substream *substream,
+				   struct device *dev, const char *name);
 int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream);
 
 struct dma_chan *snd_dmaengine_pcm_get_chan(struct snd_pcm_substream *substream);
sound/soc/soc-dmaengine-pcm.c +39 -0
index 111b7d92..970eb2b 100644
@@ -304,6 +304,45 @@ int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream,
 EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open);
 
 /**
+ * snd_dmaengine_generic_pcm_open - Open a dmaengine based PCM substream
+ * @substream: PCM substream
+ * @dev: pointer to DMA client device structure
+ * @name: DMA slave channel name
+ *
+ * Returns 0 on success, a negative error code otherwise.
+ *
+ * This function is a variant of snd_dmaengine_pcm_open(). It takes different
+ * parameters and calls generic DMA helper dma_request_slave_channel() to
+ * request a DMA channel from dmaengine.
+ */
+int snd_dmaengine_generic_pcm_open(struct snd_pcm_substream *substream,
+				   struct device *dev, const char *name)
+{
+	struct dmaengine_pcm_runtime_data *prtd;
+	int ret;
+
+	ret = snd_pcm_hw_constraint_integer(substream->runtime,
+					    SNDRV_PCM_HW_PARAM_PERIODS);
+	if (ret < 0)
+		return ret;
+
+	prtd = kzalloc(sizeof(*prtd), GFP_KERNEL);
+	if (!prtd)
+		return -ENOMEM;
+
+	prtd->dma_chan = dma_request_slave_channel(dev, name);
+	if (!prtd->dma_chan) {
+		kfree(prtd);
+		return -ENXIO;
+	}
+
+	substream->runtime->private_data = prtd;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_dmaengine_generic_pcm_open);
+
+/**
  * snd_dmaengine_pcm_close - Close a dmaengine based PCM substream
  * @substream: PCM substream
  */
Signature · 1 line
1.7.9.5
author
#14 lore raw

PATCH v3 9/12 ASoC: dmaengine_pcm: add snd_dmaengine_generic_pcm_open()

With generic DMA device tree binding and helper function dma_request_slave_channel() in place, dmaengine_pcm should support that in requesting DMA channel for users that support generic DMA device tree binding.

Add a new API snd_dmaengine_generic_pcm_open() as the variant of snd_dmaengine_pcm_open(). It takes DMA client struct device pointer and slave channel name as arguments and calls generic DMA helper dma_request_slave_channel() to request DMA channel from dmaengine.

---
Changes since v2:
- Drop 'const' from argument 'name' to fix the warning below.

sound/soc/soc-dmaengine-pcm.c: In function 'snd_dmaengine_generic_pcm_open':
sound/soc/soc-dmaengine-pcm.c:333:2: warning: passing argument 2 of 'dma_request_slave_channel' discards 'const' qualifier from pointer target type [enabled by default] include/linux/dmaengine.h:971:18: note: expected 'char *' but argument is of type 'const char *'

 include/sound/dmaengine_pcm.h |    2 ++
 sound/soc/soc-dmaengine-pcm.c |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
include/sound/dmaengine_pcm.h +2 -0
index b877334..394272b 100644
@@ -43,6 +43,8 @@ snd_pcm_uframes_t snd_dmaengine_pcm_pointer_no_residue(struct snd_pcm_substream
 
 int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream,
 	dma_filter_fn filter_fn, void *filter_data);
+int snd_dmaengine_generic_pcm_open(struct snd_pcm_substream *substream,
+				   struct device *dev, char *name);
 int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream);
 
 struct dma_chan *snd_dmaengine_pcm_get_chan(struct snd_pcm_substream *substream);
sound/soc/soc-dmaengine-pcm.c +39 -0
index 111b7d92..e9d9897 100644
@@ -304,6 +304,45 @@ int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream,
 EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open);
 
 /**
+ * snd_dmaengine_generic_pcm_open - Open a dmaengine based PCM substream
+ * @substream: PCM substream
+ * @dev: pointer to DMA client device structure
+ * @name: DMA slave channel name
+ *
+ * Returns 0 on success, a negative error code otherwise.
+ *
+ * This function is a variant of snd_dmaengine_pcm_open(). It takes different
+ * parameters and calls generic DMA helper dma_request_slave_channel() to
+ * request a DMA channel from dmaengine.
+ */
+int snd_dmaengine_generic_pcm_open(struct snd_pcm_substream *substream,
+				   struct device *dev, char *name)
+{
+	struct dmaengine_pcm_runtime_data *prtd;
+	int ret;
+
+	ret = snd_pcm_hw_constraint_integer(substream->runtime,
+					    SNDRV_PCM_HW_PARAM_PERIODS);
+	if (ret < 0)
+		return ret;
+
+	prtd = kzalloc(sizeof(*prtd), GFP_KERNEL);
+	if (!prtd)
+		return -ENOMEM;
+
+	prtd->dma_chan = dma_request_slave_channel(dev, name);
+	if (!prtd->dma_chan) {
+		kfree(prtd);
+		return -ENXIO;
+	}
+
+	substream->runtime->private_data = prtd;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_dmaengine_generic_pcm_open);
+
+/**
  * snd_dmaengine_pcm_close - Close a dmaengine based PCM substream
  * @substream: PCM substream
  */
Signature · 1 line
1.7.9.5
#15 lore raw

Re: [PATCH v3 09/12] ASoC: dmaengine_pcm: add snd_dmaengine_generic_pcm_open()

Hi Shawn,

Quoted 10 lines

With generic DMA device tree binding and helper function dma_request_slave_channel() in place, dmaengine_pcm should support that in requesting DMA channel for users that support generic DMA device tree binding.

Add a new API snd_dmaengine_generic_pcm_open() as the variant of snd_dmaengine_pcm_open(). It takes DMA client struct device pointer and slave channel name as arguments and calls generic DMA helper dma_request_slave_channel() to request DMA channel from dmaengine.

Quoted 7 lines

---
Changes since v2:
- Drop 'const' from argument 'name' to fix the warning below.

[...]

v3 changelog missing ;-) What did you adjust here please?

Best regards,
Marek Vasut

author
#16 lore raw

Re: [PATCH v3 09/12] ASoC: dmaengine_pcm: add snd_dmaengine_generic_pcm_open()

Quoted 19 lines · Marek Vasut

Hi Shawn,

Quoted 10 lines

With generic DMA device tree binding and helper function dma_request_slave_channel() in place, dmaengine_pcm should support that in requesting DMA channel for users that support generic DMA device tree binding.

Add a new API snd_dmaengine_generic_pcm_open() as the variant of snd_dmaengine_pcm_open(). It takes DMA client struct device pointer and slave channel name as arguments and calls generic DMA helper dma_request_slave_channel() to request DMA channel from dmaengine.

Quoted 7 lines

---
Changes since v2:
- Drop 'const' from argument 'name' to fix the warning below.

Quoted 3 lines

[...]

v3 changelog missing ;-) What did you adjust here please?

The "Changes since v2" means v3 changelog.

Shawn

#17 lore raw

Re: [PATCH v3 09/12] ASoC: dmaengine_pcm: add snd_dmaengine_generic_pcm_open()

Dear Shawn Guo,

Quoted 18 lines · Marek Vasut
Quoted 17 lines

Hi Shawn,

Quoted 15 lines

With generic DMA device tree binding and helper function dma_request_slave_channel() in place, dmaengine_pcm should support that in requesting DMA channel for users that support generic DMA device tree binding.

Add a new API snd_dmaengine_generic_pcm_open() as the variant of snd_dmaengine_pcm_open(). It takes DMA client struct device pointer and slave channel name as arguments and calls generic DMA helper dma_request_slave_channel() to request DMA channel from dmaengine.

---

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Changes since v2:
- Drop 'const' from argument 'name' to fix the warning below.

[...]

v3 changelog missing ;-) What did you adjust here please?

The "Changes since v2" means v3 changelog.

Bah, it was too late then, sorry.

Best regards,
Marek Vasut

#18 lore raw

Re: [PATCH v3 09/12] ASoC: dmaengine_pcm: add snd_dmaengine_generic_pcm_open()

In reply to Shawn Guo
Quoted 4 lines · Shawn Guo

With generic DMA device tree binding and helper function dma_request_slave_channel() in place, dmaengine_pcm should support that in requesting DMA channel for users that support generic DMA device tree binding.

This purpetuates the brain-dead behaviour of the existing ASoC DMA engine layer, which makes it unsuitable for platforms with special DMA memory requirements.

The problem is that the DMA mask to be used for allocating DMA-able memory is the DMA engine struct device, not the struct device associated with the ASoC device.

I got this right in my ASoC generic DMA engine layer. Converting this layer is far from trivial though, and as my test platform has now become my entire network firewall, I'm not doing any testing on that anymore.

#19 lore raw

Re: [PATCH v3 09/12] ASoC: dmaengine_pcm: add snd_dmaengine_generic_pcm_open()

Quoted 11 lines · Russell King - ARM Linux

This purpetuates the brain-dead behaviour of the existing ASoC DMA engine layer, which makes it unsuitable for platforms with special DMA memory requirements.

The problem is that the DMA mask to be used for allocating DMA-able memory is the DMA engine struct device, not the struct device associated with the ASoC device.

I got this right in my ASoC generic DMA engine layer. Converting this layer is far from trivial though, and as my test platform has now become my entire network firewall, I'm not doing any testing on that anymore.

Could you go into more detail here please? Looking at the code I'm not
seeing any allocations done by the library code at all, the allocations
are all done by the individual platform DMA drivers so I don't see
anything stopping them doing what they need.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130307/0bb5bfe6/attachment.sig>

#20 lore raw

Re: [PATCH v3 09/12] ASoC: dmaengine_pcm: add snd_dmaengine_generic_pcm_open()

Quoted 10 lines · Mark Brown
Quoted 7 lines · Russell King - ARM Linux

This purpetuates the brain-dead behaviour of the existing ASoC DMA engine layer, which makes it unsuitable for platforms with special DMA memory requirements.

The problem is that the DMA mask to be used for allocating DMA-able memory is the DMA engine struct device, not the struct device associated with the ASoC device.

Quoted 8 lines
Quoted 3 lines

I got this right in my ASoC generic DMA engine layer. Converting this layer is far from trivial though, and as my test platform has now become my entire network firewall, I'm not doing any testing on that anymore.

Could you go into more detail here please? Looking at the code I'm not seeing any allocations done by the library code at all, the allocations are all done by the individual platform DMA drivers so I don't see anything stopping them doing what they need.

I don't know what else you require apart from the description above. Isn't it rather obvious that you can't preallocate the ALSA buffer against the DMA engine device if you can only obtain the DMA engine device in the open function?

Notice in the code below where the DMA engine is obtained in pcm_new and the buffer is preallocated against the DMA engine struct device. That's exactly what I'm talking about.

/*
* Generic ASoC DMA engine backend
*
* Copyright (C) 2012 Russell King
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* We expect the DMA engine to give accurate residue information,
* returning the number of bytes left to complete to the requested
* cookie. We also expect the DMA engine to be able to resume
* submitted descriptors after a suspend/resume cycle.
*/
#include <linux/dma-mapping.h>
#include <linux/dmaengine.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/spinlock.h>

#include <sound/core.h>
#include <sound/soc-dmaengine.h>
#include <sound/soc.h>
#include <sound/pcm_params.h>

#define BUFFER_SIZE_MAX 65536
#define PERIOD_SIZE_MIN 32
#define PERIOD_SIZE_MAX 16384
#define PERIODS_MIN 2
#define PERIODS_MAX 256

struct buf_info {
	struct scatterlist sg;
	dma_cookie_t cookie;
};
struct soc_dma_chan {
	const struct soc_dma_config *conf;
	spinlock_t lock;
	struct dma_chan *chan;
	struct dma_slave_config cfg;
	enum dma_transfer_direction dir;
	unsigned nr_periods;
	unsigned sg_index;
	unsigned stopped;
	unsigned cyclic;
	dma_cookie_t cyclic_cookie;
	struct buf_info buf[PERIODS_MAX];
};
struct soc_dma_info {
	struct soc_dma_chan *chan[2];
};

static const struct snd_pcm_hardware soc_dmaengine_hardware = {
.info = SNDRV_PCM_INFO_MMAP |
SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME,
.period_bytes_min = PERIOD_SIZE_MIN,
.period_bytes_max = PERIOD_SIZE_MAX,
.periods_min = PERIODS_MIN,
.periods_max = PERIODS_MAX,
.buffer_bytes_max = BUFFER_SIZE_MAX,
};

static int soc_dmaengine_submit(struct snd_pcm_substream *substream,

	struct soc_dma_chan *dma);

static void soc_dmaengine_callback(void *data)

{
	struct snd_pcm_substream *substream = data;
	struct soc_dma_chan *dma = substream->runtime->private_data;
	int ret;

	snd_pcm_period_elapsed(substream);

	if (!dma->stopped && !dma->cyclic) {
		spin_lock(&dma->lock);
		ret = soc_dmaengine_submit(substream, dma);
		spin_unlock(&dma->lock);

		if (ret == 0)
			dma_async_issue_pending(dma->chan);
		else
			pr_err("%s: failed to submit next DMA buffer\n", __func__);
	}
}

static int soc_dmaengine_submit(struct snd_pcm_substream *substream,
struct soc_dma_chan *dma)

{
	struct dma_async_tx_descriptor *tx;
	struct dma_chan *ch = dma->chan;
	struct buf_info *buf;
	unsigned sg_index;

	sg_index = dma->sg_index;

	buf = &dma->buf[sg_index];

	tx = dmaengine_prep_slave_sg(ch, &buf->sg, 1, dma->dir,
		DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
	if (tx) {
		tx->callback = soc_dmaengine_callback;
		tx->callback_param = substream;

		buf->cookie = dmaengine_submit(tx);

		sg_index++;
		if (sg_index >= dma->nr_periods)
			sg_index = 0;
		dma->sg_index = sg_index;
	}

	return tx ? 0 : -ENOMEM;
}

static int soc_dmaengine_start(struct snd_pcm_substream *substream)

{
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct soc_dma_chan *dma = runtime->private_data;
	unsigned long flags;
	unsigned i;
	int ret = 0;

	if (!dma->cyclic) {
		spin_lock_irqsave(&dma->lock, flags);
		for (i = 0; i < dma->nr_periods; i++) {
			ret = soc_dmaengine_submit(substream, dma);
			if (ret)
				break;
		}
		spin_unlock_irqrestore(&dma->lock, flags);
		if (ret == 0) {
			dma->stopped = 0;
			dma_async_issue_pending(dma->chan);
		} else {
			dma->stopped = 1;
			dmaengine_terminate_all(dma->chan);
		}
	} else {
		struct dma_async_tx_descriptor *tx;

		tx = dmaengine_prep_dma_cyclic(dma->chan, runtime->dma_addr,
			snd_pcm_lib_buffer_bytes(substream),
			snd_pcm_lib_period_bytes(substream), dma->dir,
			DMA_CTRL_ACK | DMA_PREP_INTERRUPT);
		if (tx) {
			tx->callback = soc_dmaengine_callback;
			tx->callback_param = substream;

			dma->cyclic_cookie = dmaengine_submit(tx);
			dma_async_issue_pending(dma->chan);
		}
	}

	return ret;
}

static int soc_dmaengine_stop(struct snd_pcm_substream *substream)

{
	struct soc_dma_chan *dma = substream->runtime->private_data;

	dma->stopped = 1;
	dmaengine_terminate_all(dma->chan);

	return 0;
}

static int soc_dmaengine_open(struct snd_pcm_substream *substream)

{
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct snd_soc_pcm_runtime *rtd = substream->private_data;
	struct soc_dma_info *info = snd_soc_platform_get_drvdata(rtd->platform);
	struct soc_dma_chan *dma = info->chan[substream->stream];
	int ret = 0;

	if (!dma)
		return -EINVAL;

	runtime->hw = soc_dmaengine_hardware;
	runtime->hw.fifo_size = dma->conf->fifo_size;

	if (dma->conf->align) {
		/*
		 * FIXME: Ideally, there should be some way to query
		 * this from the DMA engine itself.
		 *
		 * It would also be helpful to know the maximum size
		 * a scatterlist entry can be to set the period size.
		 */
		ret = snd_pcm_hw_constraint_step(runtime, 0,
			SNDRV_PCM_HW_PARAM_PERIOD_BYTES, dma->conf->align);
		if (ret)
			goto err;

		ret = snd_pcm_hw_constraint_step(runtime, 0,
			SNDRV_PCM_HW_PARAM_BUFFER_BYTES, dma->conf->align);
		if (ret)
			goto err;
	}

	runtime->private_data = dma;

err:

	return ret;
}

static int soc_dmaengine_close(struct snd_pcm_substream *substream)

{
	return 0;
}

static int soc_dmaengine_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)

{
	int ret = snd_pcm_lib_malloc_pages(substream,
			params_buffer_bytes(params));

	return ret < 0 ? ret : 0;
}

static int soc_dmaengine_prepare(struct snd_pcm_substream *substream)

{
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct soc_dma_chan *dma = runtime->private_data;
	size_t buf_size = snd_pcm_lib_buffer_bytes(substream);
	size_t period = snd_pcm_lib_period_bytes(substream);
	dma_addr_t addr = runtime->dma_addr;
	unsigned i;

	/* Create an array of sg entries, one for each period */
	for (i = 0; i < PERIODS_MAX && buf_size; i++) {
		BUG_ON(buf_size < period);

		sg_dma_address(&dma->buf[i].sg) = addr;
		sg_dma_len(&dma->buf[i].sg) = period;

		addr += period;
		buf_size -= period;
	}

	if (buf_size) {
		pr_err("DMA buffer size not a multiple of the period size: residue=%zu\n", buf_size);
		return -EINVAL;
	}

	dma->nr_periods = i;
	dma->sg_index = 0;

	return 0;
}

static int soc_dmaengine_trigger(struct snd_pcm_substream *substream, int cmd)

{
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct soc_dma_chan *dma = runtime->private_data;
	int ret;

	switch (cmd) {
	case SNDRV_PCM_TRIGGER_START:
		ret = soc_dmaengine_start(substream);
		break;

	case SNDRV_PCM_TRIGGER_STOP:
		ret = soc_dmaengine_stop(substream);
		break;

	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
	case SNDRV_PCM_TRIGGER_SUSPEND:
		ret = dmaengine_pause(dma->chan);
		break;

	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
	case SNDRV_PCM_TRIGGER_RESUME:
		ret = dmaengine_resume(dma->chan);
		break;

	default:
		ret = -EINVAL;
	}

	return ret;
}

static snd_pcm_uframes_t soc_dmaengine_pointer(struct snd_pcm_substream *substream)

{
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct soc_dma_chan *dma = runtime->private_data;
	struct dma_chan *ch = dma->chan;
	struct dma_tx_state state;
	unsigned bytes;

	if (dma->cyclic) {
		ch->device->device_tx_status(ch, dma->cyclic_cookie, &state);

		bytes = snd_pcm_lib_buffer_bytes(substream) - state.residue;
	} else {
		unsigned index, pos;
		size_t period = snd_pcm_lib_period_bytes(substream);
		unsigned long flags;
		enum dma_status status;
		dma_cookie_t cookie;

		/*
		 * Get the next-to-be-submitted index, and the last submitted
		 * cookie value.  We use this to obtain the DMA engine state.
		 */
		spin_lock_irqsave(&dma->lock, flags);
		index = dma->sg_index;
		do {
			cookie = dma->buf[index].cookie;
			status = ch->device->device_tx_status(ch, cookie, &state);
			if (status == DMA_SUCCESS) {
				index++;
				if (index > dma->nr_periods)
					index = 0;
			}
		} while (status == DMA_SUCCESS);
		spin_unlock_irqrestore(&dma->lock, flags);

		/* The end of the current DMA buffer */
		pos = (index + 1) * period;
		/* Now take off the residue */
		bytes = pos - state.residue;
		/* And correct for wrap-around */
		if (bytes >= period * dma->nr_periods)
			bytes -= period * dma->nr_periods;
	}

	return bytes_to_frames(runtime, bytes);
}

static int soc_dmaengine_mmap(struct snd_pcm_substream *substream,
struct vm_area_struct *vma)

{
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct snd_dma_buffer *buf = runtime->dma_buffer_p;

	return dma_mmap_writecombine(buf->dev.dev, vma,
		runtime->dma_area, runtime->dma_addr, runtime->dma_bytes);
}

static struct snd_pcm_ops soc_dmaengine_ops = {
.open = soc_dmaengine_open,
.close = soc_dmaengine_close,
.ioctl = snd_pcm_lib_ioctl,
.hw_params = soc_dmaengine_hw_params,
.hw_free = snd_pcm_lib_free_pages,
.prepare = soc_dmaengine_prepare,
.trigger = soc_dmaengine_trigger,
.pointer = soc_dmaengine_pointer,
.mmap = soc_dmaengine_mmap,
};

static struct soc_dma_chan *soc_dmaengine_alloc(void)

{
	struct soc_dma_chan *dma = kzalloc(sizeof(*dma), GFP_KERNEL);
	unsigned i;

	if (dma) {
		spin_lock_init(&dma->lock);
		for (i = 0; i < PERIODS_MAX; i++)
			sg_init_table(&dma->buf[i].sg, 1);
	}
	return dma;
}

static struct dma_chan *soc_dmaengine_get(enum dma_transaction_type type,
struct soc_dma_config *cfg)

{
	dma_cap_mask_t m;

	dma_cap_zero(m);
	dma_cap_set(type, m);
	return dma_request_channel(m, cfg->filter, cfg->data);
}

static int soc_dmaengine_request(struct soc_dma_chan *dma,
struct soc_dma_config *cfg, unsigned stream)

{
	int ret;

	dma->conf = cfg;
	dma->chan = soc_dmaengine_get(DMA_CYCLIC, cfg);
	if (!dma->chan)
		dma->chan = soc_dmaengine_get(DMA_SLAVE, cfg);
	else
		dma->cyclic = 1;
	if (!dma->chan) {
		ret = -ENXIO;
		goto err_dma_req;
	}

	if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
		dma->dir = DMA_MEM_TO_DEV;
		dma->cfg.direction = DMA_MEM_TO_DEV;
		dma->cfg.dst_addr = cfg->reg;
		dma->cfg.dst_addr_width = cfg->width;
		dma->cfg.dst_maxburst = cfg->maxburst;
	} else {
		dma->dir = DMA_DEV_TO_MEM;
		dma->cfg.direction = DMA_DEV_TO_MEM;
		dma->cfg.src_addr = cfg->reg;
		dma->cfg.src_addr_width = cfg->width;
		dma->cfg.src_maxburst = cfg->maxburst;
	}

	ret = dmaengine_slave_config(dma->chan, &dma->cfg);
	if (ret)
		goto err_dma_cfg;

	return 0;

err_dma_cfg:

	dma_release_channel(dma->chan);
	dma->chan = NULL;
 err_dma_req:
	return ret;
}

static void soc_dmaengine_release(struct soc_dma_chan *dma)

{
	if (dma && dma->chan)
		dma_release_channel(dma->chan);
	kfree(dma);
}

static int soc_dmaengine_preallocate_buffer(struct snd_pcm *pcm,
unsigned stream, struct soc_dma_chan *dma)

{
	struct snd_pcm_substream *substream = pcm->streams[stream].substream;
	int ret = 0;

	if (substream) {
		struct snd_dma_buffer *buf = &substream->dma_buffer;

		buf->dev.type = SNDRV_DMA_TYPE_DEV;
		buf->dev.dev = dma->chan->device->dev;
		buf->private_data = NULL;
		buf->area = dma_alloc_writecombine(buf->dev.dev,
				BUFFER_SIZE_MAX, &buf->addr, GFP_KERNEL);
		if (!buf->area)
			return -ENOMEM;

		buf->bytes = BUFFER_SIZE_MAX;
	}
	return ret;
}

static int soc_dmaengine_pcm_new(struct snd_soc_pcm_runtime *rtd)

{
	struct snd_pcm *pcm = rtd->pcm;
	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
	struct soc_dma_info *info;
	unsigned stream;
	int ret = 0;

	if (!cpu_dai)
		return -EINVAL;

	if (!cpu_dai->playback_dma_data &&
	    !cpu_dai->capture_dma_data) {
		pr_err("soc_dmaengine: %s has no cpu_dai DMA data - incorrect probe ordering?\n",
			rtd->card->name);
		return -EINVAL;
	}

	info = kzalloc(sizeof(*info), GFP_KERNEL);
	if (!info)
		return -ENOMEM;

	for (stream = 0; stream < ARRAY_SIZE(pcm->streams); stream++) {
		struct soc_dma_config *cfg = NULL;
		struct soc_dma_chan *dma;

		if (stream == SNDRV_PCM_STREAM_PLAYBACK)
			cfg = cpu_dai->playback_dma_data;
		else if (stream == SNDRV_PCM_STREAM_CAPTURE)
			cfg = cpu_dai->capture_dma_data;

		if (!cfg)
			continue;

		info->chan[stream] = dma = soc_dmaengine_alloc();
		if (!dma) {
			ret = -ENOMEM;
			break;
		}

		ret = soc_dmaengine_request(dma, cfg, stream);
		if (ret)
			return ret;

		ret = soc_dmaengine_preallocate_buffer(pcm, stream, dma);
		if (ret)
			break;
	}

	if (ret) {
		for (stream = 0; stream < ARRAY_SIZE(info->chan); stream++)
			soc_dmaengine_release(info->chan[stream]);
		kfree(info);
	} else {
		snd_soc_platform_set_drvdata(rtd->platform, info);
	}

	return ret;
}

/*
* Use write-combining memory here: the standard ALSA
* snd_free_dev_pages() doesn't support this. */
static void soc_dmaengine_pcm_free(struct snd_pcm *pcm)

{
	unsigned stream;

	for (stream = 0; stream < ARRAY_SIZE(pcm->streams); stream++) {
		struct snd_pcm_substream *substream = pcm->streams[stream].substream;
		struct snd_dma_buffer *buf;

		if (!substream)
			continue;
		buf = &substream->dma_buffer;
		if (!buf->area)
			continue;

		if (buf->dev.type == SNDRV_DMA_TYPE_DEV)
			dma_free_writecombine(buf->dev.dev, buf->bytes,
					      buf->area, buf->addr);
		else
			snd_dma_free_pages(buf);
		buf->area = NULL;
	}
}

/*
* This is annoying - we can't have symetry with .pcm_new because .pcm_free
* is called after the runtime information has been removed. It would be
* better if we could find somewhere else to store our soc_dma_info pointer. */
static int soc_dmaengine_plat_remove(struct snd_soc_platform *platform)

{
	struct soc_dma_info *info = snd_soc_platform_get_drvdata(platform);
	unsigned stream;

	for (stream = 0; stream < ARRAY_SIZE(info->chan); stream++)
		soc_dmaengine_release(info->chan[stream]);
	kfree(info);

	return 0;
}

static struct snd_soc_platform_driver soc_dmaengine_platform = {
.remove = soc_dmaengine_plat_remove,
.pcm_new = soc_dmaengine_pcm_new,
.pcm_free = soc_dmaengine_pcm_free,
.ops = &soc_dmaengine_ops,
/* Wait until the cpu_dai has been probed */ .probe_order = SND_SOC_COMP_ORDER_LATE,
};

static int soc_dmaengine_probe(struct platform_device *pdev)

{
	return snd_soc_register_platform(&pdev->dev, &soc_dmaengine_platform);
}

static int soc_dmaengine_remove(struct platform_device *pdev)

{
	snd_soc_unregister_platform(&pdev->dev);
	return 0;
}

static struct platform_driver soc_dmaengine_driver = {
.driver = {
.name = "soc-dmaengine", .owner = THIS_MODULE,
},
.probe = soc_dmaengine_probe,
.remove = soc_dmaengine_remove,
};

module_platform_driver(soc_dmaengine_driver);

MODULE_AUTHOR("Russell King");
MODULE_DESCRIPTION("ALSA SoC DMA engine driver");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:soc-dmaengine");

#21 lore raw

Re: [PATCH v3 09/12] ASoC: dmaengine_pcm: add snd_dmaengine_generic_pcm_open()

Quoted 11 lines · Russell King - ARM Linux
Quoted 4 lines · Mark Brown

Could you go into more detail here please? Looking at the code I'm not seeing any allocations done by the library code at all, the allocations are all done by the individual platform DMA drivers so I don't see anything stopping them doing what they need.

I don't know what else you require apart from the description above. Isn't it rather obvious that you can't preallocate the ALSA buffer against the DMA engine device if you can only obtain the DMA engine device in the open function?

The bit I'm missing is why this is particularly hard to change, it
doesn't seem like a massive refactoring and there's not many users.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130307/4c3d78f0/attachment.sig>

#22 lore raw

Re: [PATCH v3 09/12] ASoC: dmaengine_pcm: add snd_dmaengine_generic_pcm_open()

Quoted 8 lines · Mark Brown
Quoted 6 lines · Russell King - ARM Linux
Quoted 4 lines · Mark Brown

Could you go into more detail here please? Looking at the code I'm not seeing any allocations done by the library code at all, the allocations are all done by the individual platform DMA drivers so I don't see anything stopping them doing what they need.

Quoted 7 lines
Quoted 4 lines

I don't know what else you require apart from the description above. Isn't it rather obvious that you can't preallocate the ALSA buffer against the DMA engine device if you can only obtain the DMA engine device in the open function?

The bit I'm missing is why this is particularly hard to change, it doesn't seem like a massive refactoring and there's not many users.

Well, it requires the thing to be reworked along with everyone who uses it, specifically snd_dmaengine_pcm_open() and snd_dmaengine_pcm_close().

Now, I could use your excuse that you've given me in the past: "I don't have much of that hardware so I can't test the changes, so I'm not going to touch this code evar again!" (That's basically what you said about the AC'97 struct device stuff.) You can't have it both ways and always shovel what you don't like onto other people.

So... I'll just go back to quietly sitting on my SA11x0 ASoC support and totally ignoring mainline with it because of obstructive maintainers. :)

#23 lore raw

Re: [PATCH v3 09/12] ASoC: dmaengine_pcm: add snd_dmaengine_generic_pcm_open()

Quoted 7 lines · Russell King - ARM Linux
Quoted 2 lines · Mark Brown

The bit I'm missing is why this is particularly hard to change, it doesn't seem like a massive refactoring and there's not many users.

Well, it requires the thing to be reworked along with everyone who uses it, specifically snd_dmaengine_pcm_open() and snd_dmaengine_pcm_close().

Oh, OK. That doesn't seem like a big deal really - it's certainly not a throw the thing out and start over job. It sounded like you'd identifed some new issue you'd not mentioned rather than just the same issue, it wasn't clear to me that it was the same issue.

Quoted 3 lines

Now, I could use your excuse that you've given me in the past: "I don't have much of that hardware so I can't test the changes, so I'm not going to touch this code evar again!" (That's basically what you said about

I'm not particularly asking you to fix this yourself except in that it seems like it's an important issue for you. If anything something like this patch ought to make things marginally easier to deal with by factoring out a very small bit of the code.

Quoted 2 lines

the AC'97 struct device stuff.) You can't have it both ways and always shovel what you don't like onto other people.

I'm aware of the issue, as are the people who've worked on the code. Speaking personally I just happen to disagree with you about the urgency here - it's not like it's the only problem we've got and the practical effects are limited to a subset of mostly older hardware which generally doesn't use dmaeengine in the first place. I imagine that a similar thing is true for everyone else.

There's plenty of other hardware that doesn't work right now, another pressing example I can think of is devices that subdivide an audio interface into multiple unrelated streams of audio, you aren't alone in having hardware that needs the frameworks improving in order to achieve basic functionality.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#24 lore raw

PATCH v2 10/12 ASoC: mxs: move to use generic DMA helper

In reply to Shawn Guo

With the generic DMA device tree helper supported by mxs-dma driver, we now only need to call snd_dmaengine_generic_pcm_open() to have dmaengine_pcm request DMA channel from dmaengine by calling generic DMA helper dma_request_slave_channel().

Cc Mark Brown <[email protected]>
Cc alsa-devel at alsa-project.org
---
 .../devicetree/bindings/sound/mxs-saif.txt         |   18 +++++----
 sound/soc/mxs/mxs-pcm.c                            |   42 ++------------------
 sound/soc/mxs/mxs-pcm.h                            |    5 ---
 sound/soc/mxs/mxs-saif.c                           |   28 +------------
 sound/soc/mxs/mxs-saif.h                           |    1 -
 5 files changed, 15 insertions(+), 79 deletions(-)
Documentation/devicetree/bindings/sound/mxs-saif.txt +11 -7
index c37ba61..89b3821 100644
@@ -3,8 +3,11 @@
 Required properties:
 - compatible: Should be "fsl,<chip>-saif"
 - reg: Should contain registers location and length
-- interrupts: Should contain ERROR and DMA interrupts
-- fsl,saif-dma-channel: APBX DMA channel for the SAIF
+- interrupts: Should contain ERROR interrupt number
+- dmas: DMA specifier, consisting of a phandle to DMA controller node
+  and SAIF DMA channel ID.
+  Refer to dma.txt and fsl-mxs-dma.txt for details.
+- dma-names: Must be "rx-tx".
 
 Optional properties:
 - fsl,saif-master: phandle to the master SAIF.  It's only required for
@@ -23,14 +26,15 @@ aliases {
 saif0: saif at 80042000 {
 	compatible = "fsl,imx28-saif";
 	reg = <0x80042000 2000>;
-	interrupts = <59 80>;
-	fsl,saif-dma-channel = <4>;
+	interrupts = <59>;
+	dmas = <&dma_apbx 4>;
+	dma-names = "rx-tx";
 };
 
 saif1: saif at 80046000 {
 	compatible = "fsl,imx28-saif";
 	reg = <0x80046000 2000>;
-	interrupts = <58 81>;
-	fsl,saif-dma-channel = <5>;
-	fsl,saif-master = <&saif0>;
+	interrupts = <58>;
+	dmas = <&dma_apbx 5>;
+	dma-names = "rx-tx";
 };
sound/soc/mxs/mxs-pcm.c +3 -39

78 lines not on this page · raw message

sound/soc/mxs/mxs-pcm.h +0 -5
index 35ba2ca..bc685b6 100644
@@ -19,11 +19,6 @@
 #ifndef _MXS_PCM_H
 #define _MXS_PCM_H
 
-struct mxs_pcm_dma_params {
-	int chan_irq;
-	int chan_num;
-};
-
 int mxs_pcm_platform_register(struct device *dev);
 void mxs_pcm_platform_unregister(struct device *dev);
 
sound/soc/mxs/mxs-saif.c +1 -27
index 3a2aa1d..0c70903 100644
@@ -26,7 +26,6 @@
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/time.h>
-#include <linux/fsl/mxs-dma.h>
 #include <linux/pinctrl/consumer.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
@@ -369,7 +368,6 @@ static int mxs_saif_startup(struct snd_pcm_substream *substream,
 			   struct snd_soc_dai *cpu_dai)
 {
 	struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai);
-	snd_soc_dai_set_dma_data(cpu_dai, substream, &saif->dma_param);
 
 	/* clear error status to 0 for each re-open */
 	saif->fifo_underrun = 0;
@@ -659,7 +657,7 @@ static irqreturn_t mxs_saif_irq(int irq, void *dev_id)
 static int mxs_saif_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
-	struct resource *iores, *dmares;
+	struct resource *iores;
 	struct mxs_saif *saif;
 	struct pinctrl *pinctrl;
 	int ret = 0;
@@ -721,22 +719,6 @@ static int mxs_saif_probe(struct platform_device *pdev)
 	if (IS_ERR(saif->base))
 		return PTR_ERR(saif->base);
 
-	dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
-	if (!dmares) {
-		/*
-		 * TODO: This is a temporary solution and should be changed
-		 * to use generic DMA binding later when the helplers get in.
-		 */
-		ret = of_property_read_u32(np, "fsl,saif-dma-channel",
-					   &saif->dma_param.chan_num);
-		if (ret) {
-			dev_err(&pdev->dev, "failed to get dma channel\n");
-			return ret;
-		}
-	} else {
-		saif->dma_param.chan_num = dmares->start;
-	}
-
 	saif->irq = platform_get_irq(pdev, 0);
 	if (saif->irq < 0) {
 		ret = saif->irq;
@@ -753,14 +735,6 @@ static int mxs_saif_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	saif->dma_param.chan_irq = platform_get_irq(pdev, 1);
-	if (saif->dma_param.chan_irq < 0) {
-		ret = saif->dma_param.chan_irq;
-		dev_err(&pdev->dev, "failed to get dma irq resource: %d\n",
-			ret);
-		return ret;
-	}
-
 	platform_set_drvdata(pdev, saif);
 
 	ret = snd_soc_register_dai(&pdev->dev, &mxs_saif_dai);
sound/soc/mxs/mxs-saif.h +0 -1
index 3cb342e..53eaa4b 100644
@@ -117,7 +117,6 @@ struct mxs_saif {
 	unsigned int mclk_in_use;
 	void __iomem *base;
 	int irq;
-	struct mxs_pcm_dma_params dma_param;
 	unsigned int id;
 	unsigned int master_id;
 	unsigned int cur_rate;
Signature · 1 line
1.7.9.5
author
#25 lore raw

PATCH v2 11/12 dma: mxs-dma: remove code left from generic DMA binding conversion

In reply to Shawn Guo

With all mxs-dma clients moved to use generic DMA helper, the code left from generic DMA binding conversion can be removed now.

---
 drivers/dma/mxs-dma.c       |   23 -----------------------
 include/linux/fsl/mxs-dma.h |   20 --------------------
 2 files changed, 43 deletions(-)
 delete mode 100644 include/linux/fsl/mxs-dma.h
drivers/dma/mxs-dma.c +0 -23
index b48a79c..65ac0ea 100644
@@ -23,7 +23,6 @@
 #include <linux/dmaengine.h>
 #include <linux/delay.h>
 #include <linux/module.h>
-#include <linux/fsl/mxs-dma.h>
 #include <linux/stmp_device.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
@@ -197,24 +196,6 @@ static struct mxs_dma_chan *to_mxs_dma_chan(struct dma_chan *chan)
 	return container_of(chan, struct mxs_dma_chan, chan);
 }
 
-int mxs_dma_is_apbh(struct dma_chan *chan)
-{
-	struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
-	struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
-
-	return dma_is_apbh(mxs_dma);
-}
-EXPORT_SYMBOL_GPL(mxs_dma_is_apbh);
-
-int mxs_dma_is_apbx(struct dma_chan *chan)
-{
-	struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
-	struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
-
-	return !dma_is_apbh(mxs_dma);
-}
-EXPORT_SYMBOL_GPL(mxs_dma_is_apbx);
-
 static void mxs_dma_reset_chan(struct mxs_dma_chan *mxs_chan)
 {
 	struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
@@ -349,13 +330,9 @@ static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)
 static int mxs_dma_alloc_chan_resources(struct dma_chan *chan)
 {
 	struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
-	struct mxs_dma_data *data = chan->private;
 	struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
 	int ret;
 
-	if (data)
-		mxs_chan->chan_irq = data->chan_irq;
-
 	mxs_chan->ccw = dma_alloc_coherent(mxs_dma->dma_device.dev,
 				CCW_BLOCK_SIZE, &mxs_chan->ccw_phys,
 				GFP_KERNEL);
include/linux/fsl/mxs-dma.h deleted +0 -20
deleted file mode 100644
index 55d8702..0000000
@@ -1,20 +0,0 @@
-/*
- * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#ifndef __MACH_MXS_DMA_H__
-#define __MACH_MXS_DMA_H__
-
-#include <linux/dmaengine.h>
-
-struct mxs_dma_data {
-	int chan_irq;
-};
-
-extern int mxs_dma_is_apbh(struct dma_chan *chan);
-extern int mxs_dma_is_apbx(struct dma_chan *chan);
-#endif /* __MACH_MXS_DMA_H__ */
Signature · 1 line
1.7.9.5
author
#26 lore raw

PATCH v2 12/12 ARM: dts: remove old DMA binding data from client nodes

In reply to Shawn Guo

After adopting generic DMA device tree binding, now channel interrupt number is defined in DMA controller node, and channel ID is listed in "dmas" property. So the DMA channel interrupt number in client nodes' "interrupts" property and fsl,<module>-dma-channel which are used by old customized DMA binding can be removed now.

---
 arch/arm/boot/dts/imx23.dtsi   |   15 ++++++-------
 arch/arm/boot/dts/imx28.dtsi   |   46 ++++++++++++++++------------------------
 arch/arm/boot/dts/imx6qdl.dtsi |    4 ++--
 3 files changed, 26 insertions(+), 39 deletions(-)
arch/arm/boot/dts/imx23.dtsi +6 -9
index 64f901f..c32a651 100644
@@ -72,23 +72,21 @@
 				#size-cells = <1>;
 				reg = <0x8000c000 0x2000>, <0x8000a000 0x2000>;
 				reg-names = "gpmi-nand", "bch";
-				interrupts = <13>, <56>;
-				interrupt-names = "gpmi-dma", "bch";
+				interrupts = <56>;
+				interrupt-names = "bch";
 				clocks = <&clks 34>;
 				clock-names = "gpmi_io";
 				dmas = <&dma_apbh 4>;
 				dma-names = "rx-tx";
-				fsl,gpmi-dma-channel = <4>;
 				status = "disabled";
 			};
 
 			ssp0: ssp at 80010000 {
 				reg = <0x80010000 0x2000>;
-				interrupts = <15 14>;
+				interrupts = <15>;
 				clocks = <&clks 33>;
 				dmas = <&dma_apbh 1>;
 				dma-names = "rx-tx";
-				fsl,ssp-dma-channel = <1>;
 				status = "disabled";
 			};
 
@@ -360,11 +358,10 @@
 
 			ssp1: ssp at 80034000 {
 				reg = <0x80034000 0x2000>;
-				interrupts = <2 20>;
+				interrupts = <2>;
 				clocks = <&clks 33>;
 				dmas = <&dma_apbh 2>;
 				dma-names = "rx-tx";
-				fsl,ssp-dma-channel = <2>;
 				status = "disabled";
 			};
 
@@ -465,7 +462,7 @@
 			auart0: serial at 8006c000 {
 				compatible = "fsl,imx23-auart";
 				reg = <0x8006c000 0x2000>;
-				interrupts = <24 25 23>;
+				interrupts = <24>;
 				clocks = <&clks 32>;
 				dmas = <&dma_apbx 6>, <&dma_apbx 7>;
 				dma-names = "rx", "tx";
@@ -475,7 +472,7 @@
 			auart1: serial at 8006e000 {
 				compatible = "fsl,imx23-auart";
 				reg = <0x8006e000 0x2000>;
-				interrupts = <59 60 58>;
+				interrupts = <59>;
 				clocks = <&clks 32>;
 				dmas = <&dma_apbx 8>, <&dma_apbx 9>;
 				dma-names = "rx", "tx";
arch/arm/boot/dts/imx28.dtsi +18 -28

178 lines not on this page · raw message

arch/arm/boot/dts/imx6qdl.dtsi +2 -2
index e6b8781..ba7eed8 100644
@@ -81,8 +81,8 @@
 			#size-cells = <1>;
 			reg = <0x00112000 0x2000>, <0x00114000 0x2000>;
 			reg-names = "gpmi-nand", "bch";
-			interrupts = <0 13 0x04>, <0 15 0x04>;
-			interrupt-names = "gpmi-dma", "bch";
+			interrupts = <0 15 0x04>;
+			interrupt-names = "bch";
 			clocks = <&clks 152>, <&clks 153>, <&clks 151>,
 				 <&clks 150>, <&clks 149>;
 			clock-names = "gpmi_io", "gpmi_apb", "gpmi_bch",
Signature · 1 line
1.7.9.5
Reviewed-by on the v2 series
#27 lore raw
In reply to Shawn Guo
Quoted 5 lines · Shawn Guo

The series converts mxs-dma and its clients to generic DMA device tree binding/helper.

I published a branch below to ease people who is willing to help testing the series.

Looks all good, aside from the bug I found in the first patch.