Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Platform Devices and Device Tree Basics | Communicating with Hardware
C Device Drivers Basics

bookPlatform Devices and Device Tree Basics

Platform devices are a key concept in Linux device driver development, especially on embedded systems and SoCs. A platform device represents a device that is directly attached to the system board and is not discoverable by standard bus enumeration methods, such as PCI or USB. Instead, the kernel is informed about these devices through board-specific data, which can be provided statically in code or dynamically via the device tree. Platform devices are commonly used for on-chip peripherals, such as UARTs, timers, or GPIO controllers.

platform_device_example.c

platform_device_example.c

copy
1234567891011121314151617181920212223242526272829303132
// platform_device_example.c #include <linux/module.h> #include <linux/platform_device.h> static struct platform_device my_platform_device = { .name = "my_simple_device", .id = -1, }; static int __init my_platform_device_init(void) { int ret; ret = platform_device_register(&my_platform_device); if (ret) pr_err("Failed to register platform device\n"); else pr_info("Platform device registered\n"); return ret; } static void __exit my_platform_device_exit(void) { platform_device_unregister(&my_platform_device); pr_info("Platform device unregistered\n"); } module_init(my_platform_device_init); module_exit(my_platform_device_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Your Name"); MODULE_DESCRIPTION("Example Platform Device Registration");

While the previous code demonstrates registering a platform device directly in C, modern Linux systems—especially on ARM and embedded platforms—use a device tree to describe hardware. The device tree is a data structure for describing hardware layout to the kernel, decoupling hardware configuration from kernel code. This allows the same kernel binary to support multiple hardware variants without recompilation. Device drivers can then match their platform devices based on compatible strings or other properties defined in the device tree. In the context of the platform device code shown above, the device tree would provide the kernel with the information needed to instantiate a platform device for the driver, rather than requiring hardcoded registration in C.

my_simple_device.dts

my_simple_device.dts

copy
123456
// my_simple_device.dts snippet my_simple_device: my_simple_device@0x10000000 { compatible = "myvendor,my-simple-device"; reg = <0x10000000 0x1000>; status = "okay"; };
question mark

What is the main role of the device tree in Linux device driver development?

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 5. Capítulo 3

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

bookPlatform Devices and Device Tree Basics

Desliza para mostrar el menú

Platform devices are a key concept in Linux device driver development, especially on embedded systems and SoCs. A platform device represents a device that is directly attached to the system board and is not discoverable by standard bus enumeration methods, such as PCI or USB. Instead, the kernel is informed about these devices through board-specific data, which can be provided statically in code or dynamically via the device tree. Platform devices are commonly used for on-chip peripherals, such as UARTs, timers, or GPIO controllers.

platform_device_example.c

platform_device_example.c

copy
1234567891011121314151617181920212223242526272829303132
// platform_device_example.c #include <linux/module.h> #include <linux/platform_device.h> static struct platform_device my_platform_device = { .name = "my_simple_device", .id = -1, }; static int __init my_platform_device_init(void) { int ret; ret = platform_device_register(&my_platform_device); if (ret) pr_err("Failed to register platform device\n"); else pr_info("Platform device registered\n"); return ret; } static void __exit my_platform_device_exit(void) { platform_device_unregister(&my_platform_device); pr_info("Platform device unregistered\n"); } module_init(my_platform_device_init); module_exit(my_platform_device_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Your Name"); MODULE_DESCRIPTION("Example Platform Device Registration");

While the previous code demonstrates registering a platform device directly in C, modern Linux systems—especially on ARM and embedded platforms—use a device tree to describe hardware. The device tree is a data structure for describing hardware layout to the kernel, decoupling hardware configuration from kernel code. This allows the same kernel binary to support multiple hardware variants without recompilation. Device drivers can then match their platform devices based on compatible strings or other properties defined in the device tree. In the context of the platform device code shown above, the device tree would provide the kernel with the information needed to instantiate a platform device for the driver, rather than requiring hardcoded registration in C.

my_simple_device.dts

my_simple_device.dts

copy
123456
// my_simple_device.dts snippet my_simple_device: my_simple_device@0x10000000 { compatible = "myvendor,my-simple-device"; reg = <0x10000000 0x1000>; status = "okay"; };
question mark

What is the main role of the device tree in Linux device driver development?

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 5. Capítulo 3
some-alt