2 * Copyright (c) 2004-2006 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
37 #include <machine/bus.h>
39 #include <machine/resource.h>
41 #include <dev/scc/scc_bus.h>
43 #include <dev/uart/uart.h>
44 #include <dev/uart/uart_bus.h>
46 static int uart_scc_attach(device_t dev);
47 static int uart_scc_probe(device_t dev);
49 static device_method_t uart_scc_methods[] = {
50 /* Device interface */
51 DEVMETHOD(device_probe, uart_scc_probe),
52 DEVMETHOD(device_attach, uart_scc_attach),
53 DEVMETHOD(device_detach, uart_bus_detach),
54 /* Serdev interface */
55 DEVMETHOD(serdev_ihand, uart_bus_ihand),
56 DEVMETHOD(serdev_sysdev, uart_bus_sysdev),
60 static driver_t uart_scc_driver = {
63 sizeof(struct uart_softc),
67 uart_scc_attach(device_t dev)
70 struct uart_softc *sc;
73 parent = device_get_parent(dev);
74 sc = device_get_softc(dev);
76 if (BUS_READ_IVAR(parent, dev, SCC_IVAR_HWMTX, &mtx))
78 sc->sc_hwmtx = (struct mtx *)(void *)mtx;
79 return (uart_bus_attach(dev));
83 uart_scc_probe(device_t dev)
86 struct uart_softc *sc;
87 uintptr_t ch, cl, md, rs;
89 parent = device_get_parent(dev);
90 sc = device_get_softc(dev);
92 if (BUS_READ_IVAR(parent, dev, SCC_IVAR_MODE, &md) ||
93 BUS_READ_IVAR(parent, dev, SCC_IVAR_CLASS, &cl))
95 if (md != SCC_MODE_ASYNC)
99 sc->sc_class = &uart_quicc_class;
101 case SCC_CLASS_SAB82532:
102 sc->sc_class = &uart_sab82532_class;
104 case SCC_CLASS_Z8530:
105 sc->sc_class = &uart_z8530_class;
110 if (BUS_READ_IVAR(parent, dev, SCC_IVAR_CHANNEL, &ch) ||
111 BUS_READ_IVAR(parent, dev, SCC_IVAR_CLOCK, &cl) ||
112 BUS_READ_IVAR(parent, dev, SCC_IVAR_REGSHFT, &rs))
115 return (uart_bus_probe(dev, rs, cl, 0, ch));
118 DRIVER_MODULE(uart, scc, uart_scc_driver, uart_devclass, 0, 0);