new ofw_search_compatible()
Ian Lepore
ian at FreeBSD.org
Wed Oct 23 14:39:21 UTC 2013
While creating drivers that work for a variety of SoCs, I increasingly
find myself coding sequences such as:
if (ofw_bus_is_compatible(dev, "fsl,imx51-fec"))
sc->fectype = FECTYPE_IMX51;
else if (ofw_bus_is_compatible(dev, "fsl,imx53-fec"))
sc->fectype = FECTYPE_IMX53;
else if (ofw_bus_is_compatible(dev, "fsl,imx6q-fec"))
sc->fectype = FECTYPE_IMX6;
else
sc->fectype = FECTYPE_GENERIC;
That's a short list as an example, eventually that driver may support a
dozen SoCs. I'd like to add a helper routine that turns this into a
table lookup, patch attached. Any objections? It turns sequences such
as the above into:
static struct ofw_compat_data compat_data[] = {
{"fsl,imx51-fec", FECTYPE_IMX51},
{"fsl,imx53-fec", FECTYPE_IMX53},
{"fsl,imx6q-fec", FECTYPE_IMX6},
{NULL, FECTYPE_NONE},
};
/* ... */
sc->fectype = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
The search routine by design can't return NULL unless you pass it a NULL
table pointer. That lets you provide whatever "not found" value in the
table-end sentry that works best for the way your code is structured.
-- Ian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ofw_search_compat.diff
Type: text/x-patch
Size: 1633 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-embedded/attachments/20131023/13f790c3/attachment.bin>
More information about the freebsd-embedded
mailing list