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 <machine/bus.h>
38 #include <sys/mutex.h>
40 #include <sys/serial.h>
42 #include <dev/scc/scc_bfe.h>
43 #include <dev/scc/scc_bus.h>
45 #include <dev/ic/z8530.h>
49 static int z8530_bfe_attach(struct scc_softc *, int);
50 static int z8530_bfe_iclear(struct scc_softc *, struct scc_chan *);
51 static int z8530_bfe_ipend(struct scc_softc *);
52 static int z8530_bfe_probe(struct scc_softc *);
54 /* Channel B is always at 0 offset. */
55 #define CHAN_A (-(sc->sc_class->cl_range))
58 static kobj_method_t z8530_methods[] = {
59 KOBJMETHOD(scc_attach, z8530_bfe_attach),
60 KOBJMETHOD(scc_iclear, z8530_bfe_iclear),
61 KOBJMETHOD(scc_ipend, z8530_bfe_ipend),
62 KOBJMETHOD(scc_probe, z8530_bfe_probe),
67 * escc (macio) spacing.
69 struct scc_class scc_z8530_escc_class = {
72 sizeof(struct scc_softc),
74 .cl_class = SCC_CLASS_Z8530,
75 .cl_modes = SCC_MODE_ASYNC | SCC_MODE_BISYNC | SCC_MODE_HDLC,
76 /* Negative .cl_range signifies this is channel spacing. */
77 .cl_range = (CHAN_B - 16),
81 * SUN compatible channel spacing.
83 struct scc_class scc_z8530_legacy_class = {
86 sizeof(struct scc_softc),
88 .cl_class = SCC_CLASS_Z8530,
89 .cl_modes = SCC_MODE_ASYNC | SCC_MODE_BISYNC | SCC_MODE_HDLC,
90 /* Negative .cl_range signifies this is channel spacing. */
91 .cl_range = (CHAN_B - 2),
94 /* Multiplexed I/O. */
95 static __inline uint8_t
96 scc_getmreg(struct scc_bas *bas, int ch, int reg)
99 scc_setreg(bas, ch + REG_CTRL, reg);
101 return (scc_getreg(bas, ch + REG_CTRL));
105 z8530_bfe_attach(struct scc_softc *sc __unused, int reset __unused)
112 z8530_bfe_iclear(struct scc_softc *sc, struct scc_chan *ch)
118 c = (ch->ch_nr == 1) ? CHAN_A : CHAN_B;
119 mtx_lock_spin(&sc->sc_hwmtx);
120 if (ch->ch_ipend & SER_INT_TXIDLE) {
121 scc_setreg(bas, c + REG_CTRL, CR_RSTTXI);
124 if (ch->ch_ipend & SER_INT_RXREADY) {
125 scc_getreg(bas, c + REG_DATA);
128 if (ch->ch_ipend & (SER_INT_OVERRUN|SER_INT_BREAK))
129 scc_setreg(bas, c + REG_CTRL, CR_RSTERR);
130 mtx_unlock_spin(&sc->sc_hwmtx);
134 #define SIGCHG(c, i, s, d) \
136 i |= (i & s) ? s : s | d; \
138 i = (i & s) ? (i & ~s) | d : i; \
142 z8530_bfe_ipend(struct scc_softc *sc)
145 struct scc_chan *ch[2];
147 uint8_t bes, ip, src;
150 ch[0] = &sc->sc_chan[0];
151 ch[1] = &sc->sc_chan[1];
155 mtx_lock_spin(&sc->sc_hwmtx);
156 ip = scc_getmreg(bas, CHAN_A, RR_IP);
158 ch[0]->ch_ipend |= SER_INT_RXREADY;
160 ch[1]->ch_ipend |= SER_INT_RXREADY;
162 ch[0]->ch_ipend |= SER_INT_TXIDLE;
164 ch[1]->ch_ipend |= SER_INT_TXIDLE;
166 bes = scc_getmreg(bas, CHAN_A, CR_RSTXSI);
168 ch[0]->ch_ipend |= SER_INT_BREAK;
169 sig = ch[0]->ch_hwsig;
170 SIGCHG(bes & BES_CTS, sig, SER_CTS, SER_DCTS);
171 SIGCHG(bes & BES_DCD, sig, SER_DCD, SER_DDCD);
172 SIGCHG(bes & BES_SYNC, sig, SER_DSR, SER_DDSR);
173 if (sig & SER_MASK_DELTA) {
174 ch[0]->ch_hwsig = sig;
175 ch[0]->ch_ipend |= SER_INT_SIGCHG;
177 src = scc_getmreg(bas, CHAN_A, RR_SRC);
179 ch[0]->ch_ipend |= SER_INT_OVERRUN;
182 bes = scc_getmreg(bas, CHAN_B, CR_RSTXSI);
184 ch[1]->ch_ipend |= SER_INT_BREAK;
185 sig = ch[1]->ch_hwsig;
186 SIGCHG(bes & BES_CTS, sig, SER_CTS, SER_DCTS);
187 SIGCHG(bes & BES_DCD, sig, SER_DCD, SER_DDCD);
188 SIGCHG(bes & BES_SYNC, sig, SER_DSR, SER_DDSR);
189 if (sig & SER_MASK_DELTA) {
190 ch[1]->ch_hwsig = sig;
191 ch[1]->ch_ipend |= SER_INT_SIGCHG;
193 src = scc_getmreg(bas, CHAN_B, RR_SRC);
195 ch[1]->ch_ipend |= SER_INT_OVERRUN;
197 mtx_unlock_spin(&sc->sc_hwmtx);
199 return (ch[0]->ch_ipend | ch[1]->ch_ipend);
203 z8530_bfe_probe(struct scc_softc *sc __unused)