1
votes

While going through the usb code in linux. I came across platform_device_add() api.

My question is when we create a platform device using the above api, how does the associated driver gets bind to it?

As per my understanding is that the platform drivers register itself and when a match occurs with the device tree compatible string and the one mentioned in the driver, the probe of the driver is called.

So does it use something like a "compatible string" as in the case of the device tree? Does it use the "name" field present in the "struct platform_device" and match it with the "struct platform_driver" 's "name" field.

Please correct me if I am wrong. Also any text source to learn more on this will be helpful as I am new to this.

1

1 Answers

1
votes

So, you have asked a few questions here.

  1. We call platform_device_add() whenever we 100% sure that on the given platform we expect the device in question to be present and functioning.

  2. In most cases ->probe() callback is being called synchronously either at the moment of device addition (if driver is already loaded) or at driver loading stage if device is present in the system.

  3. It does not use Device Tree, it's purely board file based enumeration (device presence is identified by other means than ACPI or Device Tree).

  4. Indeed it uses driver name to match. When the API is called it matches by device name. See implementation of platform_match_id() for the actual code.