2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2004-2006 Marcel Moolenaar
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/module.h>
39 #include <machine/bus.h>
41 #include <machine/resource.h>
43 #include <dev/scc/scc_bus.h>
45 #include <dev/uart/uart.h>
46 #include <dev/uart/uart_bus.h>
48 static int uart_scc_attach(device_t dev);
49 static int uart_scc_probe(device_t dev);
51 static device_method_t uart_scc_methods[] = {
52 /* Device interface */
53 DEVMETHOD(device_probe, uart_scc_probe),
54 DEVMETHOD(device_attach, uart_scc_attach),
55 DEVMETHOD(device_detach, uart_bus_detach),
56 /* Serdev interface */
57 DEVMETHOD(serdev_ihand, uart_bus_ihand),
58 DEVMETHOD(serdev_sysdev, uart_bus_sysdev),
62 static driver_t uart_scc_driver = {
65 sizeof(struct uart_softc),
69 uart_scc_attach(device_t dev)
72 struct uart_softc *sc;
75 parent = device_get_parent(dev);
76 sc = device_get_softc(dev);
78 if (BUS_READ_IVAR(parent, dev, SCC_IVAR_HWMTX, &mtx))
80 sc->sc_hwmtx = (struct mtx *)(void *)mtx;
81 return (uart_bus_attach(dev));
85 uart_scc_probe(device_t dev)
88 struct uart_softc *sc;
89 uintptr_t ch, cl, md, rs;
91 parent = device_get_parent(dev);
92 sc = device_get_softc(dev);
94 if (BUS_READ_IVAR(parent, dev, SCC_IVAR_MODE, &md) ||
95 BUS_READ_IVAR(parent, dev, SCC_IVAR_CLASS, &cl))
97 if (md != SCC_MODE_ASYNC)
100 case SCC_CLASS_QUICC:
101 sc->sc_class = &uart_quicc_class;
103 case SCC_CLASS_SAB82532:
104 sc->sc_class = &uart_sab82532_class;
106 case SCC_CLASS_Z8530:
107 sc->sc_class = &uart_z8530_class;
112 if (BUS_READ_IVAR(parent, dev, SCC_IVAR_CHANNEL, &ch) ||
113 BUS_READ_IVAR(parent, dev, SCC_IVAR_CLOCK, &cl) ||
114 BUS_READ_IVAR(parent, dev, SCC_IVAR_REGSHFT, &rs))
117 return (uart_bus_probe(dev, rs, 0, cl, 0, ch, 0));
120 DRIVER_MODULE(uart, scc, uart_scc_driver, uart_devclass, 0, 0);