Linux machine board file
This wiki is an example to show how to add the necessary information to a Linux machine board file so that a Linux driver is associated with a chip that is always on the board. The Texas Instruments TPS65073 multi-function regulator, touch screen controller, and GPIO chip is used for this example.
TPS65073 chip overview
The TPS65073 is a multi-function device chip, so an MFD driver is used to coordinate access to the chip and route interrupts from the chip to the correct sub-driver.
The Linux files of interest include:
File | Purpose |
---|---|
include/linux/mfd/tps6507x.h | Multi-function device specific data structures used by board file |
include/linux/regulator/tps6507x.h | Regulator specific data structures used by board file |
include/linux/input/tps6507x-ts.h | Touch screen specific data structures used by board file |
arch/arm/mach-davinci/board-*.c | Machine/platform/board specific |
drivers/mfd/tps6507x.c | Multi-function (access control) driver |
drivers/regulator/tps6507x-regulator.c | Regulator sub-driver |
drivers/input/touchscreen/tps6507x-ts.c | Touch screen sub-driver |
include/linux/gpio/tps6507x.h | GPIO specific data structures used by board file Does not exist Likely not needed |
drivers/gpio/tps6507x.c | GPIO sub-driver Not written yet |
Kernel matching hardware with driver
The kernel needs to handle two different interactions between new hardware being discovered and new drivers being loaded:
- Hardware is known to the kernel (e.g. built onto the board) and the user loads the driver after boot (using insmod or modprobe).
- Kernel has initialized driver, (e.g. driver built into kernel or already loaded via insmod or modprobe) and user adds hardware (e.g. plugs in SD card or USB device).
How does the kernel connect the driver to the hardware in such a way that it works for both of these cases? The kernel keeps two lists - (a) all the known drivers and (b) all the known devices. Both lists are available from sysfs (/sys/modules and /sys/devices). When a device is connected, device_attach() in drivers/base/dd.c is called, which checks the list of drivers to see if any support the device. When a driver is loaded, driver_attach() in the same file is called, and in a similar way walks the list of devices to see if the driver can support that device.
You can enable CONFIG_DEBUG_DRIVER to see all driver / device interaction in action.
Platform devices
If a device is built into the base hardware, it is called a platform device. The platform devices are exposed to the kernel (meaning get added to the kernel's list of known devices) via the board file for that specific hardware. For example, for the LeopardBoard 365, the board file is arch/arm/mach-davinci/board-dm365-leopard.c