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/sab82532.h>
49 static int sab82532_bfe_attach(struct scc_softc *, int);
50 static int sab82532_bfe_iclear(struct scc_softc *, struct scc_chan *);
51 static int sab82532_bfe_ipend(struct scc_softc *);
52 static int sab82532_bfe_probe(struct scc_softc *);
54 static kobj_method_t sab82532_methods[] = {
55 KOBJMETHOD(scc_attach, sab82532_bfe_attach),
56 KOBJMETHOD(scc_iclear, sab82532_bfe_iclear),
57 KOBJMETHOD(scc_ipend, sab82532_bfe_ipend),
58 KOBJMETHOD(scc_probe, sab82532_bfe_probe),
62 struct scc_class scc_sab82532_class = {
65 sizeof(struct scc_softc),
66 .cl_channels = SAB_NCHAN,
67 .cl_class = SCC_CLASS_SAB82532,
68 .cl_modes = SCC_MODE_ASYNC | SCC_MODE_BISYNC | SCC_MODE_HDLC,
69 .cl_range = SAB_CHANLEN,
73 sab82532_bfe_attach(struct scc_softc *sc __unused, int reset __unused)
80 sab82532_bfe_iclear(struct scc_softc *sc, struct scc_chan *ch)
86 ofs = (ch->ch_nr - 1) * SAB_CHANLEN;
87 mtx_lock_spin(&sc->sc_hwmtx);
88 if (ch->ch_ipend & SER_INT_RXREADY) {
89 if (scc_getreg(bas, ofs + SAB_STAR) & SAB_STAR_RFNE) {
90 rbcl = scc_getreg(bas, ofs + SAB_RBCL) & 31;
93 for (i = 0; i < rbcl; i += 2) {
94 (void)scc_getreg(bas, ofs + SAB_RFIFO);
95 (void)scc_getreg(bas, ofs + SAB_RFIFO + 1);
98 while (scc_getreg(bas, ofs + SAB_STAR) & SAB_STAR_CEC)
100 scc_setreg(bas, ofs + SAB_CMDR, SAB_CMDR_RMC);
103 mtx_unlock_spin(&sc->sc_hwmtx);
108 sab82532_bfe_ipend(struct scc_softc *sc)
118 for (c = 0; c < SAB_NCHAN; c++) {
119 ch = &sc->sc_chan[c];
120 ofs = c * SAB_CHANLEN;
121 mtx_lock_spin(&sc->sc_hwmtx);
122 isr0 = scc_getreg(bas, ofs + SAB_ISR0);
123 isr1 = scc_getreg(bas, ofs + SAB_ISR1);
125 if (isr0 & SAB_ISR0_TIME) {
126 while (scc_getreg(bas, ofs + SAB_STAR) & SAB_STAR_CEC)
128 scc_setreg(bas, ofs + SAB_CMDR, SAB_CMDR_RFRD);
131 mtx_unlock_spin(&sc->sc_hwmtx);
134 if (isr1 & SAB_ISR1_BRKT)
135 ch->ch_ipend |= SER_INT_BREAK;
136 if (isr0 & SAB_ISR0_RFO)
137 ch->ch_ipend |= SER_INT_OVERRUN;
138 if (isr0 & (SAB_ISR0_TCD|SAB_ISR0_RPF))
139 ch->ch_ipend |= SER_INT_RXREADY;
140 if ((isr0 & SAB_ISR0_CDSC) || (isr1 & SAB_ISR1_CSC))
141 ch->ch_ipend |= SER_INT_SIGCHG;
142 if (isr1 & SAB_ISR1_ALLS)
143 ch->ch_ipend |= SER_INT_TXIDLE;
144 ipend |= ch->ch_ipend;
150 sab82532_bfe_probe(struct scc_softc *sc __unused)