dmaengine: Add support for BCM2835
Subsystems (4)
PATCH v9 1/1 dmaengine: Add support for BCM2835
Add support for DMA controller of BCM2835 as used in the Raspberry Pi. Currently it only supports cyclic DMA.
---
Andy, thank you for the review!
The changes are just for the minor issues you raised.
.../devicetree/bindings/dma/bcm2835-dma.txt | 57 ++ drivers/dma/Kconfig | 6 + drivers/dma/Makefile | 1 + drivers/dma/bcm2835-dma.c | 732 +++++++++++++++++++++ 4 files changed, 796 insertions(+) create mode 100644 Documentation/devicetree/bindings/dma/bcm2835-dma.txt create mode 100644 drivers/dma/bcm2835-dma.c
Documentation/devicetree/bindings/dma/bcm2835-dma.txt new file +57 -0
@@ -0,0 +1,57 @@ +* BCM2835 DMA controller + +The BCM2835 DMA controller has 16 channels in total. +Only the lower 13 channels have an associated IRQ. +Some arbitrary channels are used by the firmware +(1,3,6,7 in the current firmware version). +The channels 0,2 and 3 have special functionality +and should not be used by the driver. + +Required properties: +- compatible: Should be "brcm,bcm2835-dma". +- reg: Should contain DMA registers location and length. +- interrupts: Should contain the DMA interrupts associated + to the DMA channels in ascending order. +- #dma-cells: Must be <1>, the cell in the dmas property of the + client device represents the DREQ number. +- brcm,dma-channel-mask: Bit mask representing the channels + not used by the firmware in ascending order, + i.e. first channel corresponds to LSB. + +Example: + +dma: dma at 7e007000 { + compatible = "brcm,bcm2835-dma"; + reg = <0x7e007000 0xf00>; + interrupts = <1 16> + <1 17> + <1 18> + <1 19> + <1 20> + <1 21> + <1 22> + <1 23> + <1 24> + <1 25> + <1 26> + <1 27> + <1 28>; + + #dma-cells = <1>; + brcm,dma-channel-mask = <0x7f35>; +}; + +DMA clients connected to the BCM2835 DMA controller must use the format +described in the dma.txt file, using a two-cell specifier for each channel. + +Example: + +bcm2835_i2s: i2s at 7e203000 { + compatible = "brcm,bcm2835-i2s"; + reg = < 0x7e203000 0x20> + < 0x7e101098 0x02>; + + dmas = <&dma 2> + <&dma 3>; + dma-names = "tx", "rx"; +};
drivers/dma/Kconfig +6 -0
@@ -300,6 +300,12 @@ config DMA_OMAP select DMA_ENGINE select DMA_VIRTUAL_CHANNELS +config DMA_BCM2835 + tristate "BCM2835 DMA engine support" + depends on (ARCH_BCM2835 || MACH_BCM2708) + select DMA_ENGINE + select DMA_VIRTUAL_CHANNELS + config TI_CPPI41 tristate "AM33xx CPPI41 DMA support" depends on ARCH_OMAP
drivers/dma/Makefile +1 -0
@@ -38,6 +38,7 @@ obj-$(CONFIG_EP93XX_DMA) += ep93xx_dma.o obj-$(CONFIG_DMA_SA11X0) += sa11x0-dma.o obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o obj-$(CONFIG_DMA_OMAP) += omap-dma.o +obj-$(CONFIG_DMA_BCM2835) += bcm2835-dma.o obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o obj-$(CONFIG_TI_CPPI41) += cppi41.o
drivers/dma/bcm2835-dma.c new file +732 -0
732 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Quoted 2 lines · On Thursday 02 January 2014 18:49:23 Florian Meier wrote:
Add support for DMA controller of BCM2835 as used in the Raspberry Pi. Currently it only supports cyclic DMA.
Looks very nice. Just a few details I noticed:
drivers/dma/bcm2835-dma.c line 554
Quoted 7 lines
drivers/dma/bcm2835-dma.c new file +7
-0+#if defined(CONFIG_OF ) +static const struct of_device_id bcm2835_dma_of_match[] = { + { .compatible ="brcm,bcm2835-dma" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, bcm2835_dma_of_match); +#endif
I doubt we are going to see non-DT versions of this driver, so the #ifdef can just get removed here.
Quoted 26 lines
drivers/dma/bcm2835-dma.c new file +26
-0+static struct dma_chan *bcm2835_dma_xlate (struct of_phandle_args *spec, +struct of_dma *ofdma) +{ +struct bcm2835_dmadev *d = ofdma->of_dma_data; +struct dma_chan *chan, *candidate; + +retry: + candidate =NULL ; + +/* +* Walk the list of channels registered with the current instance and +* find one that is currently unused. +*/ +list_for_each_entry (chan, &d->ddev.channels, device_node) +if (chan->client_count ==0 ) { + candidate = chan; +break ; + } + +if (!candidate) +return NULL ; + +/* +* dma_get_slave_channel will return NULL if we lost a race between +* the lookup and the reservation. +*/
drivers/dma/bcm2835-dma.c line 591
Quoted 10 lines
drivers/dma/bcm2835-dma.c new file +10
-0+ chan =dma_get_slave_channel (candidate); + +if (!chan) + goto retry; + +/* Set DREQ from param */ +to_bcm2835_dma_chan (chan)->dreq = spec->args[0 ]; + +return chan; +}
This can now be simplified using the dma_get_any_slave_channel() interface taht Stephen Warren introduced.
drivers/dma/bcm2835-dma.c line 621
Quoted 8 lines
drivers/dma/bcm2835-dma.c new file +8
-0+ +if (!pdev->dev.dma_mask) + pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; + + rc =dma_set_mask (&pdev->dev,DMA_BIT_MASK (32 )); +if (rc) +return rc; +dma_set_coherent_mask (&pdev->dev,DMA_BIT_MASK (32 ));
dma_set_mask_and_coherent()
drivers/dma/bcm2835-dma.c line 689
Quoted 9 lines
drivers/dma/bcm2835-dma.c new file +9
-0+if (pdev->dev.of_node) { +/* Device-tree DMA controller registration */ + rc =of_dma_controller_register (pdev->dev.of_node, + bcm2835_dma_xlate, od); +if (rc) { +dev_err (&pdev->dev,"Failed to register DMA controller\n" ); + goto err_no_dma; + } + }
If pdev->dev.of_node isn't set, you didn't get here, so the if() can be removed.
Arnd
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Arnd Bergmann
Quoted 2 lines · On Thursday 02 January 2014 18:49:23 Florian Meier wrote:
Add support for DMA controller of BCM2835 as used in the Raspberry Pi. Currently it only supports cyclic DMA.
Looks very nice. Just a few details I noticed:
Quoted 10 lines
drivers/dma/bcm2835-dma.c line 554
Quoted 7 lines
drivers/dma/bcm2835-dma.c new file +7
-0+#if defined(CONFIG_OF ) +static const struct of_device_id bcm2835_dma_of_match[] = { + { .compatible ="brcm,bcm2835-dma" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, bcm2835_dma_of_match); +#endif I doubt we are going to see non-DT versions of this driver, so the #ifdef can just get removed here.
As already explained in previous versions of this patch thread, there is a non-DT version in a downstream kernel and the more I make this patch incompatible with non-DT, the harder it gets to upstream the remaining stuff. I hope this is not something that blocks this driver from getting accepted.
Quoted 5 lines
[...]
This can now be simplified using thedma_get_any_slave_channel()interface taht Stephen Warren introduced.
[...]dma_set_mask_and_coherent()
Sigh, the API is developing faster than I can keep track with updating this patch. I hope some day I will be faster....
When Russell told me about the second one before, it hoped that I can avoid merging different trees on my own, but it seems that you want me to do that ;-)
Quoted 11 lines
Quoted 9 lines
+ if (
pdev->dev.of_node) {
+ /* Device-tree DMA controller registration */
+ rc = of_dma_controller_register(pdev->dev.of_node,
+bcm2835_dma_xlate, od);
+ if (rc) {
+dev_err(&pdev->dev, "Failed to register DMA controller\n");
+ gotoerr_no_dma;
+ }
+ }If
pdev->dev.of_nodeisn't set, you didn't get here, so theif()can be removed.
Why not? (In the case of non-DT initialization)
Greetings,
Florian
Quoted 18 lines · Florian Meier
Quoted 6 lines · Arnd Bergmann
Quoted 2 lines · On Thursday 02 January 2014 18:49:23 Florian Meier wrote:
Add support for DMA controller of BCM2835 as used in the Raspberry Pi. Currently it only supports cyclic DMA.
Looks very nice. Just a few details I noticed:
Quoted 10 lines
drivers/dma/bcm2835-dma.c line 554
Quoted 7 lines
drivers/dma/bcm2835-dma.c new file +7
-0+#if defined(CONFIG_OF ) +static const struct of_device_id bcm2835_dma_of_match[] = { + { .compatible ="brcm,bcm2835-dma" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, bcm2835_dma_of_match); +#endif I doubt we are going to see non-DT versions of this driver, so the #ifdef can just get removed here.
Quoted 5 lines
As already explained in previous versions of this patch thread, there is a non-DT version in a downstream kernel and the more I make this patch incompatible with non-DT, the harder it gets to upstream the remaining stuff. I hope this is not something that blocks this driver from getting accepted.
In this case, that's certainly not an excuse unless you are worried about 400 bytes of .rodata in one driver and there are no side-effects of having the device ID listed when it's not used. Even if it made a real difference to another project, you'd need a much better excuse -- if you are worried about compatibility between mainline and some downstream kernel, how about changing that downstream kernel to use DT?
Quoted 11 lines
Quoted 5 lines
[...]
This can now be simplified using thedma_get_any_slave_channel()interface taht Stephen Warren introduced.
[...]dma_set_mask_and_coherent()Sigh, the API is developing faster than I can keep track with updating this patch. I hope some day I will be faster....
When Russell told me about the second one before, it hoped that I can avoid merging different trees on my own, but it seems that you want me to do that ;-)
The dma_get_any_slave_channel() change is probably my fault. I suggested both the initial dma_get_slave_channel() API and this one because the original approach turned out too complicated. If dma_set_mask_and_coherent().
I don't think you have to merge other trees, to get both APIs, they should already be part of the dma-slave tree that your patch would get merged into. If not, we can probably come up with a different solution. The dma_set_mask_and_coherent() suggestion is not as important as the dma_get_any_slave_channel() one, if you have to choose between them.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
+ if (
pdev->dev.of_node) {
+ /* Device-tree DMA controller registration */
+ rc = of_dma_controller_register(pdev->dev.of_node,
+bcm2835_dma_xlate, od);
+ if (rc) {
+dev_err(&pdev->dev, "Failed to register DMA controller\n");
+ gotoerr_no_dma;
+ }
+ }
Quoted 3 lines
Quoted 1 line
If
pdev->dev.of_nodeisn't set, you didn't get here, so theif()can be removed.Why not? (In the case of non-DT initialization)
The code I quoted is right after these lines:
+ /* Request DMA channel mask from device tree */
+ if (of_property_read_u32(pdev->dev.of_node,
+ "brcm,dma-channel-mask",
+ &chans_available)) {
+ dev_err(&pdev->dev, "Failed to get channel mask\n"); + rc = -EINVAL; + goto err_no_dma;
+ }
If DT is disabled or not used, you return -EINVAL here.
Arnd
Quoted 25 lines · Arnd Bergmann
Quoted 18 lines · Florian Meier
Quoted 6 lines · Arnd Bergmann
Quoted 2 lines · On Thursday 02 January 2014 18:49:23 Florian Meier wrote:
Add support for DMA controller of BCM2835 as used in the Raspberry Pi. Currently it only supports cyclic DMA.
Looks very nice. Just a few details I noticed:
Quoted 10 lines
drivers/dma/bcm2835-dma.c line 554
Quoted 7 lines
drivers/dma/bcm2835-dma.c new file +7
-0+#if defined(CONFIG_OF ) +static const struct of_device_id bcm2835_dma_of_match[] = { + { .compatible ="brcm,bcm2835-dma" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, bcm2835_dma_of_match); +#endif I doubt we are going to see non-DT versions of this driver, so the #ifdef can just get removed here.
Quoted 5 lines
As already explained in previous versions of this patch thread, there is a non-DT version in a downstream kernel and the more I make this patch incompatible with non-DT, the harder it gets to upstream the remaining stuff. I hope this is not something that blocks this driver from getting accepted.
Quoted 3 lines
In this case, that's certainly not an excuse unless you are worried about 400 bytes of .rodata in one driver and there are no side-effects of having the device ID listed when it's not used.
You are right! I forgot that having these lines doesn't prevent non-DT initialization. I will change that.
Quoted 4 lines
Even if it made a real difference
to another project, you'd need a much better excuse -- if you are worried about compatibility between mainline and some downstream kernel, how about changing that downstream kernel to use DT?
That is the future plan. Although, the current state is that there is a downstream kernel with lots of devicetree incompatible drivers and an upstream kernel with some missing important drivers. Therefore, since I want my drivers being tested by the community, they have to be non-DT compatible (or at least it should be easy to bring changes from the non-DT version to the DT version and vice versa).
Anyway, in this case this introduces no problem as you have mentioned before.
Quoted 16 lines
Quoted 11 lines
Quoted 5 lines
[...]
This can now be simplified using thedma_get_any_slave_channel()interface taht Stephen Warren introduced.
[...]dma_set_mask_and_coherent()Sigh, the API is developing faster than I can keep track with updating this patch. I hope some day I will be faster....
When Russell told me about the second one before, it hoped that I can avoid merging different trees on my own, but it seems that you want me to do that ;-)The
dma_get_any_slave_channel()change is probably my fault. I suggested both the initialdma_get_slave_channel()API and this one because the original approach turned out too complicated. Ifdma_set_mask_and_coherent().
Quoted 5 lines
I don't think you have to merge other trees, to get both APIs, they should already be part of the dma-slave tree that your patch would get merged into. If not, we can probably come up with a different solution. The
dma_set_mask_and_coherent()suggestion is not as important as thedma_get_any_slave_channel()one, if you have to choose between them.
Both changes are in the slave-dma tree, but I need patches from the bcm2835 tree and the asoc tree, too. Although, it shouldn't be too complicated to merge them, I hope.
Quoted 25 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
+ if (
pdev->dev.of_node) {
+ /* Device-tree DMA controller registration */
+ rc = of_dma_controller_register(pdev->dev.of_node,
+bcm2835_dma_xlate, od);
+ if (rc) {
+dev_err(&pdev->dev, "Failed to register DMA controller\n");
+ gotoerr_no_dma;
+ }
+ }Quoted 3 lines
Quoted 1 line
If
pdev->dev.of_nodeisn't set, you didn't get here, so theif()can be removed.Why not? (In the case of non-DT initialization)
The code I quoted is right after these lines:
drivers/dma/bcm2835-dma.c new file +8
-0+/* Request DMA channel mask from device tree */ +if (of_property_read_u32 (pdev->dev.of_node, +"brcm,dma-channel-mask" , + &chans_available)) { +dev_err (&pdev->dev,"Failed to get channel mask\n" ); + rc = -EINVAL ; + goto err_no_dma; + }
Quoted 1 line
If DT is disabled or not used, you return
-EINVALhere.
Stupid me, thank you!
Greetings,
Florian
Quoted 18 lines · Florian Meier
Quoted 11 lines · Arnd Bergmann
Quoted 6 lines
Sigh, the API is developing faster than I can keep track with updating this patch. I hope some day I will be faster....
When Russell told me about the second one before, it hoped that I can avoid merging different trees on my own, but it seems that you want me to do that ;-)The
dma_get_any_slave_channel()change is probably my fault. I suggested both the initialdma_get_slave_channel()API and this one because the original approach turned out too complicated. Ifdma_set_mask_and_coherent().Quoted 5 lines
I don't think you have to merge other trees, to get both APIs, they should already be part of the dma-slave tree that your patch would get merged into. If not, we can probably come up with a different solution. The
dma_set_mask_and_coherent()suggestion is not as important as thedma_get_any_slave_channel()one, if you have to choose between them.
Quoted 3 lines
Both changes are in the slave-dma tree, but I need patches from the bcm2835 tree and the asoc tree, too. Although, it shouldn't be too complicated to merge them, I hope.
Why do you need the bcm2835 and asoc changes? The addition of the dmaengine driver should be self-contained as far as I can tell, except that the audio driver won't work unless both are merged.
This wouldn't be considered a strict dependency since you are not breaking anything that used to work prior to the patches, and you don't create a kernel version that doesn't build. Note that this would be different if you had a dependency on a platform_data definition.
Arnd
Quoted 27 lines · Arnd Bergmann
Quoted 18 lines · Florian Meier
Quoted 11 lines · Arnd Bergmann
Quoted 6 lines
Sigh, the API is developing faster than I can keep track with updating this patch. I hope some day I will be faster....
When Russell told me about the second one before, it hoped that I can avoid merging different trees on my own, but it seems that you want me to do that ;-)The
dma_get_any_slave_channel()change is probably my fault. I suggested both the initialdma_get_slave_channel()API and this one because the original approach turned out too complicated. Ifdma_set_mask_and_coherent().Quoted 5 lines
I don't think you have to merge other trees, to get both APIs, they should already be part of the dma-slave tree that your patch would get merged into. If not, we can probably come up with a different solution. The
dma_set_mask_and_coherent()suggestion is not as important as thedma_get_any_slave_channel()one, if you have to choose between them.Quoted 3 lines
Both changes are in the slave-dma tree, but I need patches from the bcm2835 tree and the asoc tree, too. Although, it shouldn't be too complicated to merge them, I hope.
Why do you need the bcm2835 and asoc changes? The addition of the dmaengine driver should be self-contained as far as I can tell, except that the audio driver won't work unless both are merged.
Quoted 5 lines
This wouldn't be considered a strict dependency since you are not breaking anything that used to work prior to the patches, and you don't create a kernel version that doesn't build. Note that this would be different if you had a dependency on a
platform_datadefinition.
You are right! I just have to merge them for testing the driver.