Hi
I am newbie in kernel linux programming and I am investigating probe function in one of kernel driver.
In device tree we have node:
Code:
reg = <0xF0001000 0x3C0>; //start addr + size
reg-names = "some_name";
In kernel module at the beginning of file:
Code:
struct Data {
....
void __iomem *pReg;
struct regmap *pRegMap;
...
}
stuct Data* pData;
static const struct regmap_config regCfg= {
.reg_bits = 32,
.reg_stride = 4,
.val_bits = 32,
.fast_io = true,
};
In probe in kernel module:
Code:
pData= devm_kzalloc(... //allocate memory for pData
struct resource* res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "some_name"); //go through pdev->resource and find "some_name"
pData->pReg = devm_ioremap(dev, res->start, resource_size(res)); //my understanding is that this one maps physical register address into virtual kernel address space, so beginning from now You can access by pData->pReg[3] so it is similar to mechanism used in user space with mmap
pData->pRegmap = devm_regmap_init_mmio(dev, pData->pReg, ®Cfg); //this unfortunately I ma not able to understand
Does anyone know what does function:
"devm_regmap_init_mmio"
do? I am not able to understand even looking at google. I don't see a need of existence such function, as I think after ioremap we can access to pData->pReg directly by indexing or initialize memory with some memset(&pData->pReg,...) or equivalent function in kernel, is it true?
It seems that devm_regmap_init_mmio is not needed at all if you plan to use iowrite32, ioread32 api on __iomem pointer. Above instead the idea was to use regmap_write, regmap_read api. For this API you have to firstly do some kind of initialization and that is why there is devm_regmap_init_mmio. Also it is not recommended practise to iterate through index __iomem pointer like in mmap case.