1

I am refering following li k to decribe all the drivers used in my embedded Arm linux board as platform devices, need few points to be clarified. Please suggest on these.

http://thomas.enix.org/pub/conf/rmll2010/kernel-architecture-for-drivers.pdf

=============== Defining platform driver ==================

static struct platform_driver serial_imx_driver = {
.probe = serial_imx_probe,
.remove = serial_imx_remove,
.driver = {
.name = "imx-uart",
.owner = THIS_MODULE,
},
};

================= Defining a platform device ================

static struct platform_device imx_uart1_device = {
.name = "imx-uart",
.id = 0,
.num_resources = ARRAY_SIZE(imx_uart1_resources),
.resource = imx_uart1_resources,
.dev = {
.platform_data = &uart_pdata,
}
};

======== Kernel start up code location - /arch/arm/mach-imx/mx1ads.c ===========

static struct platform_device *devices[] __initdata = {
&cs89x0_device,
&imx_uart1_device,
&imx_uart2_device,
};



static void __init mx1ads_init(void)
{
[...]
platform_add_devices(devices, ARRAY_SIZE(devices));
[...]
}
MACHINE_START(MX1ADS, "Freescale MX1ADS")
[...]
.init_machine = mx1ads_init,
MACHINE_END

===============================

In linux /drivers/ folder if i have 10 folders for 10 different platform drivers. And i want only 6 drivers to be included in kernel source ? So how will my kernel come to know which driver to include ?

Are platform drivers compiled as modules or statically compiled in the kernel ?

Also what happens when we call platform_add_devices() system call ?

Does all the platform drivers which are included in kernel are loaded into ram before call to platform_add_devices() system call is made ?

At Which path/file in kernel source i can define all platform devices used in my embedded linux system (means where all platform devices used on board are described) ?

Katoch
  • 2,709
  • 9
  • 51
  • 84

2 Answers2

4

Basically platform drivers are registered in the board files (for example /arch/arm/mach-imx/eukrea_mbimx27-baseboard.c). Modern systems use Device Tree approach.

In order to compile a driver it must be first selected (for example via make menuconfig). So if you select 6 drivers, then 6 drivers will be compiled.

platform_add_devices() registers platform drivers (adds them to a list, see drivers/base/platform.c), so that kernel know, which of them to initialize during the boot stage.

Platform drivers are part of the kernel, so they are in RAM as soon as the kernel image itself is loaded.

See this article for more details.

yegorich
  • 4,653
  • 3
  • 31
  • 37
  • so in modern system board files contain device tree or device tree is passed by uboot to the kernel ? ... also you told to select driver using make menuconfig ... suppose platform driver is not in the kernel & i have to add it, so in this case i will have to do it statically in kernel source by modifying the makefiles .. ? – Katoch Feb 27 '14 at 11:16
  • With device tree approach you have basically two files: kernel image and a device tree blob (`*.dtb`). Both files will be loaded by u-boot. For adding a kernel driver see this [answer](http://stackoverflow.com/questions/11710022/adding-new-driver-code-to-linux-source-code). – yegorich Feb 27 '14 at 19:54
1

Platform devices (not drivers, like is stated above) are declared in a board file like /arch/arm/mach-* and made known to the kernel with platform_add_devices(). This board file is statically compiled and linked to the kernel.

platform_add_devices() is not a system call. it is the part of a kernel API platform_device_register() call for registering devices so they can be later binded with drivers.

Platform drivers are usually statically linked with kernel and when platform_driver_register() is called, kernel tries to bind driver to the device by matching platform_device and platform_driver name property.

If match is made, driver is registered and probe() function of the driver is called.

Obviously devices has to be registered first, before drivers are loaded.

Nowadays device tree files are used instead board files. Devices from separate device tree blob file are registered by kernel, and matched to driver with compatible string property. So this property has to be declared within device_driver structure and device node in device tree file.

Goal is, when you change devices or their properties, you have to recompile just device tree file, and not the kernel itself.

Dražen G.
  • 358
  • 3
  • 10
  • Do you know are there any references listing the kernel versions for first introducing & broadly using the device tree for the mainstream arches (like x86, arm, mips)? – occia Feb 07 '20 at 01:44