Access FIFO Registers as memory
Some IP's have the requirement to access some registers as normal memory.By default, register space is considered device memory io.
When there are FIFO registers spanning length over 256bytes , it can be a requirement of the IP to consider this space as memory mapped io.
The steps include
Map the required register space as sram region
access the sram node in the ip node
gen sram_pool in the driver probe
pool alloc for the generated sram_pool
DT node
sram1: sram-reserved@80600040000 {
compatible = "mmio-sram";
#address-cells = <2>;
#size-cells = <2>;
reg = <0x806 0x00040000 0x00 0xFFFF>;
};
mydev:mydev@80600050000 {
compatible = "cmd,mydev-tmp";
reg = <0x806 0x00050000 0x00 0x10000>;
adi,sram = <&sram1>;
};
Linux probe code snippet
struct gen_pool *sram_pool;
void __iomem *fifo_base;
/*·Mapping·Funneled·FIFO·as·SRAM·Memory·*/
sram_pool = of_gen_pool_get((&pdev->dev)->of_node, "adi,sram", 0);
if (!sram_pool)·{
dev_err(&pdev->dev, "Unable·to·get·sram·pool!\n");
return -ENODEV;
}
/*·Get·the·allocated·virtual·memory·from·sram·pool·*/
fifo_base = (void *)gen_pool_alloc(sram_pool, PAGE_SIZE);
if (!fifo_base) {
dev_err(&pdev->dev, "Failed·to·alloc·sram·from·sram·pool!\n");
return PTR_ERR(fifo_base);
}
/* Read the contents. */
if (fifo_base)
memcpy(buf, fifo_base, size);
/* Free the allocated pool */
if (sram_pool)
gen_pool_free(sram_pool, (unsigned long)fifo_base, PAGE_SIZE);
References
https://wiki.analog.com/resources/tools-software/linuxdsp/docs/linux-kernel-and-drivers/sram
Last updated