What is a Platform Device in Linux?

Embedded linux



A platform device is a device that does not support auto discoverability or hot plugging when connected to a system. This device, then, will require a platform driver in order to work with the system it is connected to.

You've probably worked with devices such as a USB flash drive, which you plugged into your laptop and then you see a notification pop up on your computer, stating that the type of device it is.

This is a device that is autodiscoverable and that supports hot plugging.

Now, what if you were to plug in a device that wasn't autodiscoverable? A device that your embedded system could not detect automatically.

This device would be a platform device.

An important concept to know is that there is something in Linux called a platform bus.

In computer science, a bus is a collection of electrical wirings which transfers information (data or address or control) between devices.

A platform bus is a pseudo bus or Linux's virtual bus represents all nondiscoverable buses of an embedded platform.

This is linux terminology to represent bus interfaces that do not have auto discoverable and hot plugging capability.

In linux, any device connected to a platform bus is a platform device.

In the PC world, the dominant bus is the PCI bus, and this bus supports auto discoverability of devices connected to the PC. USB also supports auto discoverability of devices.

However, in the embedded world, the PCI bus may not be used. Instead, there may be another type of bus system, one which many times do not support auto discoverability and hot plugging.

Each embedded device may utilize different types of buses.

For example, an STM32F446 microcontroller board uses AHB and APB buses. These are buses that are part of the Advanced Microontroller Bus Architecture (AMBA) protocol family.

This can be seen in the block diagram for the STM32F446 microcontroller.


STM32F446C/E block diagram


AHB and APB buses do not support auto discoverability and hot plugging.

So if you plug in a platform device into this board, such as an I2C device, a SPI device, a UART device, etc., the embedded system will not automatically detect it. However, a USB device, which supports hot plugging, can be detected automatically.

So important things to know is that every device has its configuration data and resources, which need to be reported to the operating system, which is running on the computer system. 

An operating system, such as windows or Linux, running on a standard computer, can auto-discover these data .Thus, the operating system learns about the connected devices automatically. This is referred to as enumeration. Enumeration is a process through which the operating system can inquire and receive information, such as the type of the device, the manufacturer, device configuration, and all of the devices connected to a given bus. 

Once the operating system gathers information about a device, it can autoload the appropriate driver for the device. In the scenario with a PC, buses like the PCI bus and USB support auto enumeration/hot plugging of the devices. 

However, on embedded system platforms, this may not be the case, since most peripherals are connected to the CPU over buses that don't support auto-discovery or enumeration of devices. We call them platform devices. 

All these platform devices are non-discoverable by nature, but they must be part of the Linux device model, so the information about these devices must be fed to the Linux kernel manually either at compile time or at the boot time of the kernel. 

So what is some of the device information? 

The device information may include memory or I/O mapped base address and range information, IRQ number on which the device issues interrupts to the processor, device identification information, DMA channel information, device address, pin configuration, power or voltage parameters, and other device specific data. 

Let's now go over the various methods of adding platform device information to the kernel. 

One way platform device information can be added to the kernel is during compilation of the kernel. This is known as a static method or the board file approach. Hardware details of the platform device is hardcoded in the kernel source files and board files. This is a deprecated method and is not recommended anymore. The reason why is because it is a part of the kernel code itself and, thus, is not efficient. With this method, you have to recompile the kernel if any device property changes.

Another method of adding platform device information to a kernel is loading the information dynamically as a kernel module. This method as well is not recommended.

The last method of adding platform device information to a kernel is during the kernel boot through a device tree blob. This is the latest and recommended way. This is known as the Device tree method. The Device Tree was originally created by Open Firmware as part of of a communication method for passing data from Open Firmware to a client program such as an operating system. An operating system used the Device Tree to discover the topology of the hardware at runtime, and thereby support a majority of available hardware without hard coded information (assuming drivers were available for all devices).

This method avoids hardcoding device information into the kernel source files.

The device tree is a simple text file, where you need to follow some syntax to encode the hardware information of your device. Then later, you have to compile that device tree file to create a device tree binary, which the kernel will use to extract the hardware information about the device.

What we need to do with a platform device to get it to work with our embedded system is to use a platform driver, which is a driver that is in charge of handling a platform device. This platform driver, we usually do not have to write ourselves. This is normally provided by the manufacturer of the board we are using. Each peripheral device will come with its own platform driver, such as SPI platform controller driver, I2C platform controller driver, USB, CAN, MMC, GPIO, UART, LCD controller, touch screen controller, etc.

These files normally can be found at the website of the manufacturer.

So this explains what a platform device is in linux and why we must use platform drivers to work with these devices in an embedded system.



Related Resources





HTML Comment Box is loading comments...