From 180cdddb9524b6e0bc4aeec1d5629683275af232 Mon Sep 17 00:00:00 2001 From: ian Date: Fri, 13 Dec 2013 19:01:50 +0000 Subject: MFC r257480: Convert the if/else list of compatible devices to the table-driven ofw_bus_search_compatible() routine. In addition to converting existing strings to table entries, also add compat strings for the whole imx family. --- sys/dev/uart/uart_bus_fdt.c | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'sys/dev/uart/uart_bus_fdt.c') diff --git a/sys/dev/uart/uart_bus_fdt.c b/sys/dev/uart/uart_bus_fdt.c index da84f26..cb2ce06 100644 --- a/sys/dev/uart/uart_bus_fdt.c +++ b/sys/dev/uart/uart_bus_fdt.c @@ -61,6 +61,30 @@ static driver_t uart_fdt_driver = { sizeof(struct uart_softc), }; +/* + * Compatible devices. Keep this sorted in most- to least-specific order first, + * alphabetical second. That is, "zwie,ns16550" should appear before "ns16550" + * on the theory that the zwie driver knows how to make better use of the + * hardware than the generic driver. Likewise with chips within a family, the + * highest-numbers / most recent models should probably appear earlier. + */ +static struct ofw_compat_data compat_data[] = { + {"arm,pl011", (uintptr_t)&uart_pl011_class}, + {"cadence,uart", (uintptr_t)&uart_cdnc_class}, + {"exynos", (uintptr_t)&uart_s3c2410_class}, + {"fsl,imx6q-uart", (uintptr_t)&uart_imx_class}, + {"fsl,imx53-uart", (uintptr_t)&uart_imx_class}, + {"fsl,imx51-uart", (uintptr_t)&uart_imx_class}, + {"fsl,imx31-uart", (uintptr_t)&uart_imx_class}, + {"fsl,imx27-uart", (uintptr_t)&uart_imx_class}, + {"fsl,imx25-uart", (uintptr_t)&uart_imx_class}, + {"fsl,imx21-uart", (uintptr_t)&uart_imx_class}, + {"lpc,uart", (uintptr_t)&uart_lpc_class}, + {"ti,ns16550", (uintptr_t)&uart_ti8250_class}, + {"ns16550", (uintptr_t)&uart_ns8250_class}, + {NULL, (uintptr_t)NULL}, +}; + static int uart_fdt_get_clock(phandle_t node, pcell_t *cell) { @@ -99,25 +123,16 @@ uart_fdt_probe(device_t dev) phandle_t node; pcell_t clock, shift; int err; + const struct ofw_compat_data * cd; sc = device_get_softc(dev); - if (ofw_bus_is_compatible(dev, "lpc,uart")) - sc->sc_class = &uart_lpc_class; - else if (ofw_bus_is_compatible(dev, "fsl,imx-uart")) - sc->sc_class = &uart_imx_class; - else if (ofw_bus_is_compatible(dev, "arm,pl011")) - sc->sc_class = &uart_pl011_class; - else if (ofw_bus_is_compatible(dev, "exynos")) - sc->sc_class = &uart_s3c2410_class; - else if (ofw_bus_is_compatible(dev, "cadence,uart")) - sc->sc_class = &uart_cdnc_class; - else if (ofw_bus_is_compatible(dev, "ti,ns16550")) - sc->sc_class = &uart_ti8250_class; - else if (ofw_bus_is_compatible(dev, "ns16550")) - sc->sc_class = &uart_ns8250_class; - else + + cd = ofw_bus_search_compatible(dev, compat_data); + if (cd->ocd_data == (uintptr_t)NULL) return (ENXIO); + sc->sc_class = (struct uart_class *)cd->ocd_data; + node = ofw_bus_get_node(dev); if ((err = uart_fdt_get_clock(node, &clock)) != 0) -- cgit v1.1