There is a lot of tricks on how to handle case if required device come later than device which need it.
That patch make it automatically by checking standard props:
* interrupts
* clocks
* power-domains
* resets
* phys
* dmas
* gpios
Plus it track dependency via special prop "freebsd,phandle". My board has broken generic_timer, which require to enable first 64bits timer of "Generic Purpose Timer" device. So I add such code to `platform_attach` sub:
phandle_t gpt, gt;
gt = OF_finddevice("/timer");
gpt = OF_finddevice("/timer@10008000");
if (gt && gpt && gt != gpt) {
gpt = OF_xref_from_node(gpt);
gpt = cpu_to_fdt32(gpt);
OF_setprop(gt, "freebsd,phandle", &gpt, sizeof(gpt));
}
Now ofwbus attach mtk_gpt first, mtk_gpt enables 64bits counter and then, ofwbus attach generic_timer.
Subsystem can be enabled by adding option OFWBUS_AUTODEP to kernel config file.
If you need reoder generic_timer, you also need to do something with its EARLY_DRIVER_MODULE(...., BUS_PASS_TIMER ...). For that I prepare simple helper which redefine BUS_PASS_TIMER as BUS_PASS_DEFAULT. It can be enabled with kernel config option OFWBUS_AUTODEP_BUS_PASS_OVERRIDE.
Since many vendors use own props and some of them to define required module, like our syscon(extres), I did linker list which can be added to platform_attach that way:
static struct ofwbus_static_req_props mtk_gpio_req_props = {
"mediatek,pctl-regmap",
NULL,
OFWBUS_REQ_FIND_PROP,
};
OFWBUS_STATIC_REQ_PROP(mtk_gpio_req_props);
This way I make gpio controller driver to use syscon defined lower in DTS.