bcm2835: Getting DMA-busaddress for HW-register

Noralf Trønnes noralf at tronnes.org
Sun May 10 09:36:46 PDT 2015


Den 10.05.2015 14:35, skrev Martin Sperl:
> To make the dma implementation of spi-bcm2835.c portable
> I need to get the DMA address for the registers somewhere.
>
> platform_get_resource only gives me the address of the register
> in arm-address-space (so for SPI: start=20204000 end=20204fff)
>
> Is there a better (and portable) way to get the dma_addr_t
> other than using the following (as per sound/soc/bcm/bcm2835-i2s.c):
>
> #define BCM2835_VCMMU_SHIFT             (0x7E000000 - 0x20000000)
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> dma_reg = res->start + BCM2835_VCMMU_SHIFT + BCM2835_SPI_FIFO;
>
> This obviously does not/will not work with a rpi2 where it would
> need to be defined as:
> #define BCM2835_VCMMU_SHIFT             (0x7E000000 - 0x3F000000)
>
> Another option would be hard-coding the base-address
> (as it can not change anyway):
> dma_reg = 0x7E204000 + BCM2835_SPI_FIFO;
>
> In principle the information is in the device-tree:
>          soc {
>                  compatible = "simple-bus";
>                  ranges = <0x7e000000 0x20000000 0x2000000>;
> ...
>                  spi at 7e204000 {
>                          reg = <0x7e204000 0x1000>;
>
> So how can I get the base address from the device tree?

Apparently dma_regs is the same as the reg DT property:

--- workdir/linux/drivers/spi/spi-bcm2835.c.dma    2015-05-10 
18:18:28.955545580 +0200
+++ workdir/linux/drivers/spi/spi-bcm2835.c    2015-05-10 
18:20:26.315255619 +0200
@@ -29,6 +29,7 @@
  #include <linux/kernel.h>
  #include <linux/module.h>
  #include <linux/of.h>
+#include <linux/of_address.h>
  #include <linux/of_irq.h>
  #include <linux/of_gpio.h>
  #include <linux/of_device.h>
@@ -793,6 +794,15 @@
  #define BCM2835_VCMMU_SHIFT             (0x7E000000 - 0x20000000)
      bs->dma_regs = res->start + BCM2835_VCMMU_SHIFT;

+    {
+    const __be32 *addrp;
+
+    pr_info("%s: bs->dma_regs=%pad\n", __func__, &bs->dma_regs);
+    addrp = of_get_address(pdev->dev.of_node, 0, NULL, NULL);
+    if (addrp)
+        pr_info("%s: reg=0x%x\n", __func__, be32_to_cpup(addrp));
+    }
+
      bs->clk = devm_clk_get(&pdev->dev, NULL);
      if (IS_ERR(bs->clk)) {
          err = PTR_ERR(bs->clk);


Results in:
[    5.934687] bcm2835_spi_probe: bs->dma_regs=0x7e204000
[    6.066097] bcm2835_spi_probe: reg=0x7e204000




More information about the linux-rpi-kernel mailing list