1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2004-2006 Marcel Moolenaar
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
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.
16 *
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.
27 */
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/bus.h>
35 #include <sys/conf.h>
36 #include <sys/kernel.h>
37 #include <sys/module.h>
38
39 #include <machine/bus.h>
40 #include <sys/rman.h>
41 #include <machine/resource.h>
42
43 #include <dev/scc/scc_bus.h>
44
45 #include <dev/uart/uart.h>
46 #include <dev/uart/uart_bus.h>
47
48 static int uart_scc_attach(device_t dev);
49 static int uart_scc_probe(device_t dev);
50
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),
59 { 0, 0 }
60 };
61
62 static driver_t uart_scc_driver = {
63 uart_driver_name,
64 uart_scc_methods,
65 sizeof(struct uart_softc),
66 };
67
68 static int
69 uart_scc_attach(device_t dev)
70 {
71 device_t parent;
72 struct uart_softc *sc;
73 uintptr_t mtx;
74
75 parent = device_get_parent(dev);
76 sc = device_get_softc(dev);
77
78 if (BUS_READ_IVAR(parent, dev, SCC_IVAR_HWMTX, &mtx))
79 return (ENXIO);
80 sc->sc_hwmtx = (struct mtx *)(void *)mtx;
81 return (uart_bus_attach(dev));
82 }
83
84 static int
85 uart_scc_probe(device_t dev)
86 {
87 device_t parent;
88 struct uart_softc *sc;
89 uintptr_t ch, cl, md, rs;
90
91 parent = device_get_parent(dev);
92 sc = device_get_softc(dev);
93
94 if (BUS_READ_IVAR(parent, dev, SCC_IVAR_MODE, &md) ||
95 BUS_READ_IVAR(parent, dev, SCC_IVAR_CLASS, &cl))
96 return (ENXIO);
97 if (md != SCC_MODE_ASYNC)
98 return (ENXIO);
99 switch (cl) {
100 case SCC_CLASS_QUICC:
101 sc->sc_class = &uart_quicc_class;
102 break;
103 case SCC_CLASS_Z8530:
104 sc->sc_class = &uart_z8530_class;
105 break;
106 default:
107 return (ENXIO);
108 }
109 if (BUS_READ_IVAR(parent, dev, SCC_IVAR_CHANNEL, &ch) ||
110 BUS_READ_IVAR(parent, dev, SCC_IVAR_CLOCK, &cl) ||
111 BUS_READ_IVAR(parent, dev, SCC_IVAR_REGSHFT, &rs))
112 return (ENXIO);
113
114 return (uart_bus_probe(dev, rs, 0, cl, 0, ch, 0));
115 }
116
117 DRIVER_MODULE(uart, scc, uart_scc_driver, uart_devclass, 0, 0);
Cache object: a1aa7dc0bc54a9f9d8bbc649a62db0fb
|