linux kernel - Hello Word Device Tree Based device driver -


i have read , gone through linux kernel documentation on device tree , device tree overlays.i not able understand if have create new entree in device tree of platform or create new overlay device new driver based on device tree. looking simple led glowing driver example led connected gpio pin , configuration mentioned in device tree overlay or device tree fragment on board's platform.how can build/pushed , tested using user space application.

  1. i created custom device in device tree:

    my_device@ffdf0000 {     compatible = "my_driver";     reg = <0xffdf0000 0x1000>      /*       * reg = address of device , size       * (minimum system's pagesize = 0x1000 byte in case      */ } 
  2. i wrote kernel stub device:

    (here took kernel_src/drivers/uio/uio_pdrv_genirq.c , hans j. koch: userspace i/o drivers in realtime context (device driver tutorial) basis.)

    this stub has following 2 structs:

    the of_device_id struct:

    static struct of_device_id my_match_table[] = {      {              .compatible = "my_driver",      },      {0} }; module_device_table(of, my_match_table); 

    and driver struct 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),         }, }; 
  3. now have access properties of device tree in probe 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 /* name device tree: "my_device" */         uioinfo->mem[0].addr = r->start; /* device address device tree */         uioinfo->mem[0].size = resource_size(r); /* size device tree */         [...] } 

when there match in compatible both kernel stub's entry , device tree, probe function called.


Comments