Re: [RFC] early init and DT platform devices allocation/registration
From: Grant Likely <hidden>
Date: 2013-06-26 13:12:06
Also in:
linux-tegra
On Wed, Jun 26, 2013 at 1:44 PM, Sebastian Hesselbarth [off-list ref] wrote:
On 06/26/13 12:03, Grant Likely wrote:quoted
On Wed, Jun 26, 2013 at 7:00 AM, Hiroshi Doyu [off-list ref] wrote:quoted
Grant Likely [off-list ref] wrote @ Tue, 25 Jun 2013 19:52:33 +0200:quoted
quoted
Here's my workaround. I need to call of_detach_node() with OF_DYNAMIC to avoid duplicated device registration.Gah! my eyes! Don't do that. It is incredibly problematic. Look at inhibiting duplicate device creation instead.I may not follow this thread correctly, but could anyone point out the above "inhibiting duplicate device creation" if there's already such solution?No, the solution doesn't exist yet, but it wouldn't be hard to implement. What you need to do is to add a struct device pointer to struct device_node, and set the pointer to the struct device when of_platform_device_create creates a device. (it would also need to be set for early_platform_device creation, but that's not something that should affect you). You would also add a check to of_platform_device_create to check if the device pointer is already set. If it is, then skip creation of the device.Grant, What about the other way round, i.e. check if there is a device with .of_node pointed to the struct device_node currently at of_platform_device_create? That will avoid adding struct device to struct device_node which you fought against for good reasons.
The main thing is that it means searching through the entire list of platform devices every time a new platform device is created. That seems unnecessarily expensive to me.
Also, I guess of_platform_device_create could be exported and used by anyone who wants to create platform_devices early.
Yes, but in that case it is probably better for them to call of_platform_populate early if of_platform_device_create is fixed to support early calling. Then you'd just set up all the devices earlier in init, allow drivers that support early probing to do so, and then everything else uses the normal initcall path. g.