new ofw_search_compatible()

John-Mark Gurney jmg at funkthat.com
Wed Oct 23 16:08:45 UTC 2013


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."


More information about the freebsd-embedded mailing list