how to understand devm_regmap_init_mmio function in kernel?
by DeanAnderson from LinuxQuestions.org on (#4V35B)
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 understandDoes 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?


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 understandDoes 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?