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 <machine/bus.h>
36 #include <sys/serial.h>
38 #include <dev/scc/scc_bfe.h>
39 #include <dev/scc/scc_bus.h>
41 #include <dev/ic/sab82532.h>
45 static int sab82532_bfe_attach(struct scc_softc *, int);
46 static int sab82532_bfe_iclear(struct scc_softc *, struct scc_chan *);
47 static int sab82532_bfe_ipend(struct scc_softc *);
48 static int sab82532_bfe_probe(struct scc_softc *);
50 static kobj_method_t sab82532_methods[] = {
51 KOBJMETHOD(scc_attach, sab82532_bfe_attach),
52 KOBJMETHOD(scc_iclear, sab82532_bfe_iclear),
53 KOBJMETHOD(scc_ipend, sab82532_bfe_ipend),
54 KOBJMETHOD(scc_probe, sab82532_bfe_probe),
58 struct scc_class scc_sab82532_class = {
61 sizeof(struct scc_softc),
62 .cl_channels = SAB_NCHAN,
63 .cl_class = SCC_CLASS_SAB82532,
64 .cl_modes = SCC_MODE_ASYNC | SCC_MODE_BISYNC | SCC_MODE_HDLC,
65 .cl_range = SAB_CHANLEN,
69 sab82532_bfe_attach(struct scc_softc *sc __unused, int reset __unused)
76 sab82532_bfe_iclear(struct scc_softc *sc, struct scc_chan *ch)
82 ofs = (ch->ch_nr - 1) * SAB_CHANLEN;
83 mtx_lock_spin(&sc->sc_hwmtx);
84 if (ch->ch_ipend & SER_INT_RXREADY) {
85 if (scc_getreg(bas, ofs + SAB_STAR) & SAB_STAR_RFNE) {
86 rbcl = scc_getreg(bas, ofs + SAB_RBCL) & 31;
89 for (i = 0; i < rbcl; i += 2) {
90 (void)scc_getreg(bas, ofs + SAB_RFIFO);
91 (void)scc_getreg(bas, ofs + SAB_RFIFO + 1);
94 while (scc_getreg(bas, ofs + SAB_STAR) & SAB_STAR_CEC)
96 scc_setreg(bas, ofs + SAB_CMDR, SAB_CMDR_RMC);
99 mtx_unlock_spin(&sc->sc_hwmtx);
104 sab82532_bfe_ipend(struct scc_softc *sc)
114 for (c = 0; c < SAB_NCHAN; c++) {
115 ch = &sc->sc_chan[c];
116 ofs = c * SAB_CHANLEN;
117 mtx_lock_spin(&sc->sc_hwmtx);
118 isr0 = scc_getreg(bas, ofs + SAB_ISR0);
119 isr1 = scc_getreg(bas, ofs + SAB_ISR1);
121 if (isr0 & SAB_ISR0_TIME) {
122 while (scc_getreg(bas, ofs + SAB_STAR) & SAB_STAR_CEC)
124 scc_setreg(bas, ofs + SAB_CMDR, SAB_CMDR_RFRD);
127 mtx_unlock_spin(&sc->sc_hwmtx);
130 if (isr1 & SAB_ISR1_BRKT)
131 ch->ch_ipend |= SER_INT_BREAK;
132 if (isr0 & SAB_ISR0_RFO)
133 ch->ch_ipend |= SER_INT_OVERRUN;
134 if (isr0 & (SAB_ISR0_TCD|SAB_ISR0_RPF))
135 ch->ch_ipend |= SER_INT_RXREADY;
136 if ((isr0 & SAB_ISR0_CDSC) || (isr1 & SAB_ISR1_CSC))
137 ch->ch_ipend |= SER_INT_SIGCHG;
138 if (isr1 & SAB_ISR1_ALLS)
139 ch->ch_ipend |= SER_INT_TXIDLE;
140 ipend |= ch->ch_ipend;
146 sab82532_bfe_probe(struct scc_softc *sc __unused)