Platform device drivers in the Linux Kernel

Platform devices in the Linux kernel are devices that are hardware devices that are autonomous can be directly addressed by the CPU and they are not based on communication via conventional buses. some examples of platform devices include legacy port-based devices and host bridges to peripheral buses, and most controllers integrated into system-on-chip platforms.

Refer the articles here from the Linux kernel development community which is a rich source of information-

  1. Link -Platform Devices and Drivers
  2. Platform devices and device trees – part 1
  3. Platform devices and device trees – Part 2

The platform devices are defined in the device source tree (.dts) file and the kernel invokes the appropriate device driver on reading the device information and the compatible driver for the same.

The two important structures which are also explained beautifully in the articles above are the “platform_driver” structure and the “platform_device” structure. The two structures are provided below.

platform_device from kernel 6.2.8
platform_driver from kernel 6.2.8

The above structure are used to depict a platform device and register a platform driver. in the platform driver structure, at least “probe” and “remove” functions need to be implemented. The platform device structure is used to register a platform device to the linux kernel as by default a platform device is not discoverable.

In the case, the device tree source (.dts) file defines a platform device and defines also a compatible driver, the kernel will invoke the platform driver registered for that device and send a pointer for the enumerated platform_device.

in either of the cases where a platform device is explicitly registered via a driver or if the kernel reads and enumerates a platform device from the device tree source file, the kernel will invoke the “probe” function of the compatible driver.

In the next article, we will look at the sample code for a dummy platform device and the associated driver and kernel operation.

Platform Device driver code example

Comments

  1. Pingback: Miscellaneous device driver example | Hitch Hiker's Guide to Learning

Leave a Reply

Your email address will not be published. Required fields are marked *