2

I've read a number of articles about using platfrom device system in Linux. For example, kernel.org document and platform device/driver vs i2c device/driver. As I understand, for using platform device in Linux I need to go through 2 steps:

  1. register the platform driver by platform_driver_register() function;
  2. register the device by platform_device_register() or platform_add_devices() function.

Also it says, it is important to define the same names fields in platform_driver and platform_device structures to bind device to driver (or platform driver to device driver ?).

I looked at platform driver for Synopsys DesignWare I2C device at drivers/i2c/busses/i2c-designware-platdrv.c. It seems to be platform driver and there is platform_driver_register() function call in __init section and driver name is set to i2c_designware. I supposed the appropriate device driver should exist somewhere in kernel source code. So I tried to find it by:

grep -rne "i2c_designware"

There are several file with matching, but nowhwre is there a call of platform_device_register() or platform_add_devices(). So, I see platform driver registration, but don't see platform device registration...

Could somebody explain this?

Ian Abbott
  • 15,083
  • 19
  • 33
Sergo
  • 21
  • 5
  • 1
    No, it com[lete depends on how the actual device is going to be instantiated. Most of them does **not** requre either _step 1_ and/or _step 2_. Yes, I can explain this: it's different type (rather usual) of instantiation of the devices, i.e. via ACPI or Device Tree. It calls the `platform_add_device()` but in places you probably never thought about. For example, for ACPI case: https://elixir.bootlin.com/linux/latest/source/drivers/acpi/acpi_platform.c#L154. – 0andriy Sep 05 '21 at 14:39
  • On top of that, don't forget about multi-functional devices, e.g. for Intel Skylake and newer SoCs it's being handled in the _drivers/mfd/intel-lpss.c_ via MFD core that creates a platform device. – 0andriy Sep 05 '21 at 14:39
  • Thanks, Oandry! Now it became clearer. So, for example, it is enough to "register" device in Device Tree system to provide device registration instead of calling `platform_add_device()` directly, isn`t it? – Sergo Sep 06 '21 at 07:31
  • Yes, for Device Tree enabled platforms. Read this: https://elixir.bootlin.com/linux/latest/source/drivers/of/platform.c#L335 for the details. – 0andriy Sep 06 '21 at 10:33

0 Answers0