I created my own device in my device tree:
my_device@ffdf0000 {
compatible = "my_driver";
reg = <0xffdf0000 0x1000>
/*
* reg = address of device and size
* (Minimum is System Pagesize = 0x1000 Byte in my case
*/
}
I wrote a kernel stub for this device:
(Here I took kernel_src/drivers/uio/uio_pdrv_genirq.cand Hans J. Koch: Userspace I/O drivers in a realtime context(device driver tutorial) as the basis.)
This stub has the following two structures:
Structure of_device_id:
static struct of_device_id my_match_table[] = {
{
.compatible = "my_driver",
},
{0}
};
MODULE_DEVICE_TABLE(of, my_match_table);
and the driver structure itself:
static struct platform_driver my_platform_driver = {
.probe = my_probe,
.remove = my_remove,
.driver = {
.name = "my_driver",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(my_match_table),
},
};
Now I have access to the properties of the device tree in my sensing function:
static int my_probe(struct platform_device *dev)
{
struct uio_info *uioinfo;
struct resource *r = &dev->resource[0];
[...]
uioinfo->name = dev->dev.of_node->name
uioinfo->mem[0].addr = r->start;
uioinfo->mem[0].size = resource_size(r);
[...]
}
If compatiblethere is a match with the kernel record and the device tree, the probe function is called.
source
share