ARM: at91: move to generic DMA device tree bindings
Subsystems (7)
cover ARM: at91: move to generic DMA device tree bindings
From: Ludovic Desroches <[email protected]>
Hi,
This set of patches introduces DMA device tree bindings support for the atmel DMA controller and first driver conversions.
I'll send an update of dts file in the next version if there is no major issue with the bindings.
Regards
Ludovic Desroches (3):
at_hdmac: move to generic DMA binding
i2c: at91: convert to dma_request_slave_channel_compat()
mci: at91: convert to dma_request_slave_channel_compat()
.../devicetree/bindings/dma/atmel-dma.txt | 26 +++++- arch/arm/boot/dts/sama5d3.dtsi | 4 +- drivers/dma/at_hdmac.c | 93 ++++++++++++++++++++-- drivers/dma/at_hdmac_regs.h | 4 + drivers/i2c/busses/i2c-at91.c | 49 ++++++------ drivers/mmc/host/atmel-mci.c | 25 +++--- 6 files changed, 154 insertions(+), 47 deletions(-)
Signature · 1 line
1.7.11.3
PATCH 1/3 at_hdmac: move to generic DMA binding
From: Ludovic Desroches <[email protected]>
Update at_hdmac driver to support generic DMA device tree binding. Devices can still request channel with dma_request_channel() then it doesn't break DMA for non DT boards.
--- .../devicetree/bindings/dma/atmel-dma.txt | 26 +++++- arch/arm/boot/dts/sama5d3.dtsi | 4 +- drivers/dma/at_hdmac.c | 93 ++++++++++++++++++++-- drivers/dma/at_hdmac_regs.h | 4 + 4 files changed, 117 insertions(+), 10 deletions(-)
Documentation/devicetree/bindings/dma/atmel-dma.txt +24 -2
@@ -4,11 +4,33 @@ Required properties: - compatible: Should be "atmel,<chip>-dma" - reg: Should contain DMA registers location and length - interrupts: Should contain DMA interrupt +- #dma-cells: Must be <2> -Examples: +Example: -dma at ffffec00 { +dma0: dma at ffffec00 { compatible = "atmel,at91sam9g45-dma"; reg = <0xffffec00 0x200>; interrupts = <21>; + #dma-cells = <2>; +}; + +DMA clients connected to the Atmel DMA controller must use the format +described in the dma.txt file, using a three-cell specifier for each channel. +The three cells in order are: + +1. A phandle pointing to the DMA controller +2. The memory interface (16 most significant bits), the peripheral interface +(16 less significant bits) +3. The peripheral identifier (can be different for tx and rx) + +Example: + +i2c0 at i2c@f8010000 { + compatible = "atmel,at91sam9x5-i2c"; + reg = <0xf8010000 0x100>; + interrupts = <9 4 6>; + dmas = <&dma0 1 7>, + <&dma0 1 8>; + dma-names = "tx", "rx" };
arch/arm/boot/dts/sama5d3.dtsi +2 -2
@@ -348,14 +348,14 @@ compatible = "atmel,at91sam9g45-dma"; reg = <0xffffe600 0x200>; interrupts = <30 4 0>; - #dma-cells = <1>; + #dma-cells = <2>; }; dma1: dma-controller at ffffe800 { compatible = "atmel,at91sam9g45-dma"; reg = <0xffffe800 0x200>; interrupts = <31 4 0>; - #dma-cells = <1>; + #dma-cells = <2>; }; ramc0: ramc at ffffea00 {
drivers/dma/at_hdmac.c +87 -6
143 lines not on this page · raw message
drivers/dma/at_hdmac_regs.h +4 -0
@@ -220,6 +220,8 @@ enum atc_status {* @device: parent device * @ch_regs: memory mapped register base * @mask: channel index in a mask +* @per_if: peripheral interface +* @mem_if: memory interface * @status: transmit status information from irq/prep* functions * to tasklet (use atomic operations) * @tasklet: bottom half to finish transaction work
@@ -238,6 +240,8 @@ struct at_dma_chan {struct at_dma *device;void __iomem *ch_regs;u8 mask; +u8 per_if; +u8 mem_if;unsigned long status;struct tasklet_struct tasklet;u32 save_cfg;
Signature · 1 line
1.7.11.3
PATCH 1/3 at_hdmac: move to generic DMA binding
On 04/15/2013 02:16 PM, ludovic.desroches at atmel.com :
Quoted 7 lines
From: Ludovic Desroches <[email protected]>
Update
at_hdmacdriver to support generic DMA device tree binding. Devices can still request channel withdma_request_channel()then it doesn't break DMA for non DT boards.Signed-off-by Ludovic Desroches <[email protected]>
Some minor comments but the overall is good: so, after adding a little more explanation to documentation:
Very nice and concise patch for adding such an important feature: kudos!
Quoted 3 lines
--- .../devicetree/bindings/dma/atmel-dma.txt | 26 +++++- arch/arm/boot/dts/sama5d3.dtsi | 4 +-
Maybe we can have a separate patch for .dtsi modifications.
Documentation/devicetree/bindings/dma/atmel-dma.txt Required properties: · line 7
Quoted 13 lines
drivers/dma/at_hdmac.c | 93 ++++++++++++++++++++-- drivers/dma/at_hdmac_regs.h | 4 + 4 files changed, 117 insertions(+), 10 deletions(-)Documentation/devicetree/bindings/dma/atmel-dma.txt +1
-0@@ -4,11 +4,33 @@ Required properties: - compatible: Should be "atmel,<chip>-dma" - reg: Should contain DMA registers location and length - interrupts: Should contain DMA interrupt +- #dma-cells: Must be <2>
Maybe add some explanation (taken from pl330): "used to represent the number of integer cells in the dmas property of client device."
Documentation/devicetree/bindings/dma/atmel-dma.txt Required properties:
Quoted 13 lines
Documentation/devicetree/bindings/dma/atmel-dma.txt +7
-2-Examples: +Example: -dma at ffffec00 { +dma0: dma at ffffec00 { compatible = "atmel,at91sam9g45-dma"; reg = <0xffffec00 0x200>; interrupts = <21>; + #dma-cells = <2>; +}; + +DMA clients connected to the Atmel DMA controller must use the format +described in the dma.txt file, using a three-cell specifier for each channel
(to establish the link with the #dma-cells property:)
"
using a three-cell specifier for each channel: a phandle plus two integer cells.
"
Documentation/devicetree/bindings/dma/atmel-dma.txt Required properties: · line 25
Quoted 6 lines
Documentation/devicetree/bindings/dma/atmel-dma.txt +6
-0+The three cells in order are: + +1. A phandle pointing to the DMA controller +2. The memory interface (16 most significant bits), the peripheral interface +(16 less significant bits) +3. The peripheral identifier (can be different for tx and rx)
Yes but the peripheral identifier needs more explanation: what about:
"
Peripheral identifier for the hardware handshaking interface. The identifier can be different for tx and rx.
"
arch/arm/boot/dts/sama5d3.dtsi
Quoted 15 lines
Documentation/devicetree/bindings/dma/atmel-dma.txt +10
-0+ +Example: + +i2c0 at i2c@f8010000 { + compatible = "atmel,at91sam9x5-i2c"; + reg = <0xf8010000 0x100>; + interrupts = <9 4 6>; + dmas = <&dma0 1 7>, + <&dma0 1 8>; + dma-names = "tx", "rx" };arch/arm/boot/dts/sama5d3.dtsi +0
-0
Ditto.
Quoted 195 lines
arch/arm/boot/dts/sama5d3.dtsi +2
-2@@ -348,14 +348,14 @@ compatible = "atmel,at91sam9g45-dma"; reg = <0xffffe600 0x200>; interrupts = <30 4 0>; - #dma-cells = <1>; + #dma-cells = <2>; }; dma1: dma-controller at ffffe800 { compatible = "atmel,at91sam9g45-dma"; reg = <0xffffe800 0x200>; interrupts = <31 4 0>; - #dma-cells = <1>; + #dma-cells = <2>; }; ramc0: ramc at ffffea00 {drivers/dma/at_hdmac.c +87
-6@@ -24,6 +24,7 @@#include <linux/slab.h> #include <linux/of.h> #include <linux/of_device.h> +#include <linux/of_dma.h> #include "at_hdmac_regs.h" #include "dmaengine.h" @@ -676,7 +677,7 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, ctrlb |=ATC_DST_ADDR_MODE_FIXED |ATC_SRC_ADDR_MODE_INCR |ATC_FC_MEM2PER - |ATC_SIF (AT_DMA_MEM_IF ) |ATC_DIF (AT_DMA_PER_IF ); + |ATC_SIF (atchan->mem_if) |ATC_DIF (atchan->per_if); reg = sconfig->dst_addr;for_each_sg (sgl, sg, sg_len, i) {struct at_desc *desc;@@ -715,7 +716,7 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, ctrlb |=ATC_DST_ADDR_MODE_INCR |ATC_SRC_ADDR_MODE_FIXED |ATC_FC_PER2MEM - |ATC_SIF (AT_DMA_PER_IF ) |ATC_DIF (AT_DMA_MEM_IF ); + |ATC_SIF (atchan->per_if) |ATC_DIF (atchan->mem_if); reg = sconfig->src_addr;for_each_sg (sgl, sg, sg_len, i) {@@ -821,8 +822,8 @@ atc_dma_cyclic_fill_desc(struct dma_chan *chan, struct at_desc *desc, desc->lli.ctrlb =ATC_DST_ADDR_MODE_FIXED |ATC_SRC_ADDR_MODE_INCR |ATC_FC_MEM2PER - |ATC_SIF (AT_DMA_MEM_IF ) - |ATC_DIF (AT_DMA_PER_IF ); + |ATC_SIF (atchan->mem_if) + |ATC_DIF (atchan->per_if);break ;case DMA_DEV_TO_MEM :@@ -832,8 +833,8 @@ atc_dma_cyclic_fill_desc(struct dma_chan *chan, struct at_desc *desc, desc->lli.ctrlb =ATC_DST_ADDR_MODE_INCR |ATC_SRC_ADDR_MODE_FIXED |ATC_FC_PER2MEM - |ATC_SIF (AT_DMA_PER_IF ) - |ATC_DIF (AT_DMA_MEM_IF ); + |ATC_SIF (atchan->per_if) + |ATC_DIF (atchan->mem_if);break ;default :@@ -1189,6 +1190,67 @@ static void atc_free_chan_resources(struct dma_chan *chan)dev_vdbg (chan2dev (chan),"free_chan_resources: done\n" ); } +static bool at_dma_filter (struct dma_chan *chan,void *slave) +{ +struct at_dma_slave *atslave = slave; + +if (atslave->dma_dev == chan->device->dev) { + chan->private = atslave; +return true; + }else { +return false; + } +} + +#ifdef CONFIG_OF +static struct dma_chan *at_dma_xlate (struct of_phandle_args *dma_spec, +struct of_dma *of_dma) +{ +struct dma_chan *chan; +struct at_dma_chan *atchan; +struct at_dma_slave *atslave; +dma_cap_mask_t mask; +unsigned int per_id; +struct platform_device *dmac_pdev; + +if (dma_spec->args_count !=2 ) +return NULL ; + + dmac_pdev =of_find_device_by_node (dma_spec->np); + +dma_cap_zero (mask); +dma_cap_set (DMA_SLAVE , mask); + + atslave =devm_kzalloc (&dmac_pdev->dev,sizeof (*atslave),GFP_KERNEL ); +if (!atslave) +return NULL ; +/* +* We can fill both SRC_PER and DST_PER, one of these fields will be +* ignored depending on DMA transfer direction. +*/ + per_id = dma_spec->args[1 ]; + atslave->cfg =ATC_FIFOCFG_HALFFIFO |ATC_DST_H2SEL_HW + |ATC_SRC_H2SEL_HW |ATC_DST_PER (per_id) + |ATC_SRC_PER (per_id); + atslave->dma_dev = &dmac_pdev->dev; + + chan =dma_request_channel (mask, at_dma_filter, atslave); +if (!chan) +return NULL ; + + atchan =to_at_dma_chan (chan); + atchan->per_if = dma_spec->args[0 ] &0xff ; + atchan->mem_if = (dma_spec->args[0 ] >>16 ) &0xff ; + +return chan; +} +#else +static struct dma_chan *at_dma_xlate (struct of_phandle_args *dma_spec, +struct of_dma *of_dma) +{ +return NULL ; +} +#endif /*-- Module Management -----------------------------------------------*/ @@ -1343,6 +1405,8 @@ static int __init at_dma_probe(struct platform_device *pdev)for (i =0 ; i < plat_dat->nr_channels; i++) {struct at_dma_chan *atchan = &atdma->chan[i]; + atchan->mem_if =AT_DMA_MEM_IF ; + atchan->per_if =AT_DMA_PER_IF ; atchan->chan_common.device = &atdma->dma_common;dma_cookie_init (&atchan->chan_common); list_add_tail(&atchan->chan_common.device_node,@@ -1389,8 +1453,25 @@ static int __init at_dma_probe(struct platform_device *pdev)dma_async_device_register (&atdma->dma_common); +/* +* Do not return an error if the dmac node is not present in order to +* not break the existing way of requesting channel with +* dma_request_channel(). +*/ +if (pdev->dev.of_node) { + err =of_dma_controller_register (pdev->dev.of_node, + at_dma_xlate, atdma); +if (err) { +dev_err (&pdev->dev,"could not register of_dma_controller\n" ); + goto err_of_dma_controller_register; + } + } +return 0 ; +err_of_dma_controller_register: +dma_async_device_unregister (&atdma->dma_common); +dma_pool_destroy (atdma->dma_desc_pool); err_pool_create:platform_set_drvdata (pdev,NULL );free_irq (platform_get_irq (pdev,0 ), atdma);drivers/dma/at_hdmac_regs.h +4
-0@@ -220,6 +220,8 @@ enum atc_status {* @device: parent device * @ch_regs: memory mapped register base * @mask: channel index in a mask +* @per_if: peripheral interface +* @mem_if: memory interface * @status: transmit status information from irq/prep* functions * to tasklet (use atomic operations) * @tasklet: bottom half to finish transaction work @@ -238,6 +240,8 @@ struct at_dma_chan {struct at_dma *device;void __iomem *ch_regs;u8 mask; +u8 per_if; +u8 mem_if;unsigned long status;struct tasklet_struct tasklet;u32 save_cfg;
Signature · 1 line
Nicolas Ferre
PATCH 2/3 i2c: at91: convert to dma_request_slave_channel_compat()
In reply to ludovic.desroches at atmel.comFrom: Ludovic Desroches <[email protected]>
Use generic DMA DT helper. Platforms booting with or without DT populated are both supported.
--- drivers/i2c/busses/i2c-at91.c | 49 ++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 24 deletions(-)
drivers/i2c/busses/i2c-at91.c +25 -24
@@ -607,11 +607,16 @@ MODULE_DEVICE_TABLE(of, atmel_twi_dt_ids);#define atmel_twi_dt_ids NULL#endif -static bool filter (struct dma_chan *chan,void *slave) +static bool filter (struct dma_chan *chan,void *pdata) { -struct at_dma_slave *sl = slave; +struct at91_twi_pdata *sl_pdata = pdata; +struct at_dma_slave *sl; -if (sl->dma_dev == chan->device->dev) { +if (!sl_pdata) +return false; + + sl = &sl_pdata->dma_slave; +if (sl && (sl->dma_dev == chan->device->dev)) { chan->private = sl;return true; }else {
@@ -622,11 +627,10 @@ static bool filter(struct dma_chan *chan, void *slave)static int at91_twi_configure_dma (struct at91_twi_dev *dev,u32 phy_addr) {int ret =0 ; -struct at_dma_slave *sdata; +struct at91_twi_pdata *pdata = dev->pdata;struct dma_slave_config slave_config;struct at91_twi_dma *dma = &dev->dma; - - sdata = &dev->pdata->dma_slave; +dma_cap_mask_t mask;memset (&slave_config,0 ,sizeof (slave_config)); slave_config.src_addr = (dma_addr_t )phy_addr +AT91_TWI_RHR ;
@@ -637,25 +641,22 @@ static int at91_twi_configure_dma(struct at91_twi_dev *dev, u32 phy_addr) slave_config.dst_maxburst =1 ; slave_config.device_fc = false; -if (sdata && sdata->dma_dev) { -dma_cap_mask_t mask; +dma_cap_zero (mask); +dma_cap_set (DMA_SLAVE , mask); -dma_cap_zero (mask); -dma_cap_set (DMA_SLAVE , mask); - dma->chan_tx =dma_request_channel (mask, filter, sdata); -if (!dma->chan_tx) { -dev_err (dev->dev,"no DMA channel available for tx\n" ); - ret = -EBUSY ; - goto error; - } - dma->chan_rx =dma_request_channel (mask, filter, sdata); -if (!dma->chan_rx) { -dev_err (dev->dev,"no DMA channel available for rx\n" ); - ret = -EBUSY ; - goto error; - } - }else { - ret = -EINVAL ; + dma->chan_tx =dma_request_slave_channel_compat (mask, filter, pdata, + dev->dev,"tx" ); +if (!dma->chan_tx) { +dev_err (dev->dev,"can't get a DMA channel for tx\n" ); + ret = -EBUSY ; + goto error; + } + + dma->chan_rx =dma_request_slave_channel_compat (mask, filter, pdata, + dev->dev,"rx" ); +if (!dma->chan_rx) { +dev_err (dev->dev,"can't get a DMA channel for rx\n" ); + ret = -EBUSY ; goto error; }
Signature · 1 line
1.7.11.3
Wolfram Sang
AppliedPATCH 2/3 i2c: at91: convert to dma_request_slave_channel_compat()
Quoted 6 lines · ludovic.desroches at atmel.com
From: Ludovic Desroches <[email protected]>
Use generic DMA DT helper. Platforms booting with or without DT populated are both supported.
Signed-off-by Ludovic Desroches <[email protected]>
Applied to for-next, thanks!
PATCH 3/3 mci: at91: convert to dma_request_slave_channel_compat()
In reply to ludovic.desroches at atmel.comFrom: Ludovic Desroches <[email protected]>
Use generic DMA DT helper. Platforms booting with or without DT populated are both supported.
--- drivers/mmc/host/atmel-mci.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/mmc/host/atmel-mci.c +12 -13
@@ -2224,10 +2224,15 @@ static void __exit atmci_cleanup_slot(struct atmel_mci_slot *slot,mmc_free_host (slot->mmc); } -static bool atmci_filter (struct dma_chan *chan,void *slave) +static bool atmci_filter (struct dma_chan *chan,void *pdata) { -struct mci_dma_data *sl = slave; +struct mci_platform_data *sl_pdata = pdata; +struct mci_dma_data *sl; +if (!sl_pdata) +return false; + + sl = sl_pdata->dma_slave;if (sl &&find_slave_dev (sl) == chan->device->dev) { chan->private =slave_data_ptr (sl);return true;
@@ -2239,24 +2244,18 @@ static bool atmci_filter(struct dma_chan *chan, void *slave)static bool atmci_configure_dma (struct atmel_mci *host) {struct mci_platform_data *pdata; +dma_cap_mask_t mask;if (host ==NULL )return false; pdata = host->pdev->dev.platform_data; -if (!pdata) -return false; +dma_cap_zero (mask); +dma_cap_set (DMA_SLAVE , mask); -if (pdata->dma_slave &&find_slave_dev (pdata->dma_slave)) { -dma_cap_mask_t mask; - -/* Try to grab a DMA channel */ -dma_cap_zero (mask); -dma_cap_set (DMA_SLAVE , mask); - host->dma.chan = -dma_request_channel (mask, atmci_filter, pdata->dma_slave); - } + host->dma.chan =dma_request_slave_channel_compat (mask, atmci_filter, pdata, + &host->pdev->dev,"rxtx" );if (!host->dma.chan) {dev_warn (&host->pdev->dev,"no DMA channel available\n" );return false;
Signature · 1 line
1.7.11.3
PATCH 3/3 mci: at91: convert to dma_request_slave_channel_compat()
On 04/15/2013 02:16 PM, ludovic.desroches at atmel.com :
Quoted 6 lines
From: Ludovic Desroches <[email protected]>
Use generic DMA DT helper. Platforms booting with or without DT populated are both supported.
Signed-off-by Ludovic Desroches <[email protected]>
Quoted 57 lines
--- drivers/mmc/host/atmel-mci.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)drivers/mmc/host/atmel-mci.c +12
-13@@ -2224,10 +2224,15 @@ static void __exit atmci_cleanup_slot(struct atmel_mci_slot *slot,mmc_free_host (slot->mmc); } -static bool atmci_filter (struct dma_chan *chan,void *slave) +static bool atmci_filter (struct dma_chan *chan,void *pdata) { -struct mci_dma_data *sl = slave; +struct mci_platform_data *sl_pdata = pdata; +struct mci_dma_data *sl; +if (!sl_pdata) +return false; + + sl = sl_pdata->dma_slave;if (sl &&find_slave_dev (sl) == chan->device->dev) { chan->private =slave_data_ptr (sl);return true;@@ -2239,24 +2244,18 @@ static bool atmci_filter(struct dma_chan *chan, void *slave)static bool atmci_configure_dma (struct atmel_mci *host) {struct mci_platform_data *pdata; +dma_cap_mask_t mask;if (host ==NULL )return false; pdata = host->pdev->dev.platform_data; -if (!pdata) -return false; +dma_cap_zero (mask); +dma_cap_set (DMA_SLAVE , mask); -if (pdata->dma_slave &&find_slave_dev (pdata->dma_slave)) { -dma_cap_mask_t mask; - -/* Try to grab a DMA channel */ -dma_cap_zero (mask); -dma_cap_set (DMA_SLAVE , mask); - host->dma.chan = -dma_request_channel (mask, atmci_filter, pdata->dma_slave); - } + host->dma.chan =dma_request_slave_channel_compat (mask, atmci_filter, pdata, + &host->pdev->dev,"rxtx" );if (!host->dma.chan) {dev_warn (&host->pdev->dev,"no DMA channel available\n" );return false;
Signature · 1 line
Nicolas Ferre
cover ARM: at91: move to generic DMA device tree bindings
In reply to ludovic.desroches at atmel.comQuoted 9 lines · ludovic.desroches at atmel.com
From: Ludovic Desroches <[email protected]>
Hi,
This set of patches introduces DMA device tree bindings support for the atmel DMA controller and first driver conversions.
I'll send an update of dts file in the next version if there is no major issue with the bindings.
looks fine
Best Regards,
J.
Quoted 20 lines
Regards
Ludovic Desroches (3):
at_hdmac: move to generic DMA binding
i2c: at91: convert todma_request_slave_channel_compat()
mci: at91: convert todma_request_slave_channel_compat().../devicetree/bindings/dma/atmel-dma.txt | 26 +++++- arch/arm/boot/dts/sama5d3.dtsi | 4 +- drivers/dma/at_hdmac.c | 93 ++++++++++++++++++++-- drivers/dma/at_hdmac_regs.h | 4 + drivers/i2c/busses/i2c-at91.c | 49 ++++++------ drivers/mmc/host/atmel-mci.c | 25 +++--- 6 files changed, 154 insertions(+), 47 deletions(-)Signature · 1 line
1.7.11.3