1
votes

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) ?

2

2 Answers

4
votes

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.

0
votes

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.