Date: Wed, 23 Oct 2013 09:08:43 -0700 From: John-Mark Gurney <jmg@funkthat.com> To: Ian Lepore <ian@freebsd.org> Cc: freebsd-embedded@freebsd.org Subject: Re: new ofw_search_compatible() Message-ID: <20131023160843.GG56872@funkthat.com> In-Reply-To: <1382539150.92499.206.camel@revolution.hippie.lan> References: <1382539150.92499.206.camel@revolution.hippie.lan>
next in thread | previous in thread | raw e-mail | index | archive | help
Ian Lepore wrote this message on Wed, Oct 23, 2013 at 08:39 -0600:
> 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.
Some comments would be good... Like a brief usage, such as the requirement
that the table end w/ NULL w/ a proper data return... a man page would
be even better, but no one has written any for the ofw stuff yet.. :(
--
John-Mark Gurney Voice: +1 415 225 5579
"All that I will do, has been done, All that I have, has not."
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20131023160843.GG56872>
