Implementing Device Tree Overlay Support in Custom GPIO Serial Communication Device Driver
Pravin Raghul
Embedded Software Engineer | Cortex-M | Embedded Linux & Kernel Drivers | C, C++, Python
This article is a continuation of our previous article series building a custom GPIO serial communication driver. Please refer the articles links,
Why we Device Tree Overlay in this driver?
Device Tree Overlay Implementation
Device tree overlay implementation for this driver is as follows,
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835";
fragment@0 {
target = <&soc>;
__overlay__ {
gpioserdev {
compatible = "gpioserdev";
gpios = <&gpio 16 0>, <&gpio 19 0>;
strobe-gpios = <&gpio 19 0>;
data-gpios = <&gpio 16 0>;
};
};
};
};
Driver support for Device Tree Overlay
The driver has been modified to support device tree configuration, the main changes includes.,
static int gpioserdev_pinsetup(void) {
struct device_node *np;
np = of_find_node_by_name(NULL, "gpioserdev");
if (!np) {
printk("gpioserdev: device tree node not found\n");
return -ENODEV;
}
gpioserdev_strobe_pin = of_get_named_gpio(np, "strobe-gpios", 0);
if (!gpio_is_valid(gpioserdev_strobe_pin)) {
printk("gpioserdev: invalid strobe GPIO\n");
return -ENODEV;
}
gpioserdev_data_pin = of_get_named_gpio(np, "data-gpios", 0);
if (!gpio_is_valid(gpioserdev_data_pin)) {
printk("gpioserdev: invalid data GPIO\n");
return -ENODEV;
}
// ... rest of intialization
}
领英推荐
Testing and Validation
Hardware Setup:
Device Tree Overlay verification:
Once the device tree overlay is compiled and installed into the system, we can verify the overlay by,
Testing the driver:
Conclusion
Implementing device tree overlay support in our Custom GPIO Serial Communication Driver has improved flexibility.
We'll explore the including this driver into a simple build system in the next article. Let me know your thoughts...!