On Fri, Apr 08, 2016 at 05:14:03PM +0200, Patrick Wildt wrote:
> On Fri, Apr 08, 2016 at 04:34:25PM +0200, Martin Pieuchot wrote:
> > On 08/04/16(Fri) 14:46, Patrick Wildt wrote:
> > > Hi,
> > >
> > > so that we can easily check if a node is compatible or to find nodes
> > > that are compatible, I would like to add helpers to the fdt routines.
> > >
> > > This way the drivers can check if they "match" to a node by simply
> > > calling:
> > >
> > > if (fdt_node_compatible(ma->ma_node, "samsung,exynos4210-ehci"))
> > > return (1);
> > >
> > > Sometimes it's helpful to find any node that is compatible. It can
> > > be helpful for instance on finding the early uart. Simplified example:
> > >
> > > if ((node = fdt_find_compatible("arm,pl011")) != NULL)
> > > pl011cnattach(...);
> > >
> > > Thoughts? ok?
> >
> > Always hard to comment without seeing which code would use that.
> >
> > Is a custom function really needed? Why not do like sparc64 and macppc,
> > for example your ehci_match() could be:
> >
> > {
> > char compat[32];
> > ...
> >
> > if (OF_getprop(ma->ma_node, "compatible", compat, sizeof(compat)) == -1)
> > return 0;
> >
> > if (strcmp(compat, "samsung,exynos4210-ehci") == 0
> > return 1;
> >
> > return 0;
> > }
> >
>
> The compatible attribute can be a list of strings:
>
> compatible = "grinn,am335x-chiliboard", "grinn,am335x-chilisom",
> "ti,am33xx";
>
> Implementing parsing multiple strings in a buffer and checking it in
> every _match function seemed a bit too much overhead. Imagine 20 drivers
> doing the same code over and over again.
>
> Especially if you're also are not looking for one compatible, but
> multiple compatibles:
>
> static char *ampintc_compatibles[] = {
> "arm,gic",
> "arm,cortex-a7-gic",
> "arm,cortex-a9-gic",
> "arm,cortex-a15-gic",
> NULL
> };
>
> for (int i = 0; ampintc_compatibles[i]; i++)
> if (fdt_node_compatible(ia->ca_node,
> ampintc_compatibles[i]))
> return (1);
>
Or it could go further and take an array like pci_matchbyid()
return fdt_matchbyid(ia->ca_node, ampintc_devicess,
nitems(ampintc_devices));