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 <machine/bus.h>
37 #include <sys/rman.h>
38 #include <sys/serial.h>
39
40 #include <dev/scc/scc_bfe.h>
41 #include <dev/scc/scc_bus.h>
42
43 #include <dev/ic/sab82532.h>
44
45 #include "scc_if.h"
46
47 static int sab82532_bfe_attach(struct scc_softc *, int);
48 static int sab82532_bfe_iclear(struct scc_softc *, struct scc_chan *);
49 static int sab82532_bfe_ipend(struct scc_softc *);
50 static int sab82532_bfe_probe(struct scc_softc *);
51
52 static kobj_method_t sab82532_methods[] = {
53 KOBJMETHOD(scc_attach, sab82532_bfe_attach),
54 KOBJMETHOD(scc_iclear, sab82532_bfe_iclear),
55 KOBJMETHOD(scc_ipend, sab82532_bfe_ipend),
56 KOBJMETHOD(scc_probe, sab82532_bfe_probe),
57 KOBJMETHOD_END
58 };
59
60 struct scc_class scc_sab82532_class = {
61 "sab82532 class",
62 sab82532_methods,
63 sizeof(struct scc_softc),
64 .cl_channels = SAB_NCHAN,
65 .cl_class = SCC_CLASS_SAB82532,
66 .cl_modes = SCC_MODE_ASYNC | SCC_MODE_BISYNC | SCC_MODE_HDLC,
67 .cl_range = SAB_CHANLEN,
68 };
69
70 static int
sab82532_bfe_attach(struct scc_softc * sc __unused,int reset __unused)71 sab82532_bfe_attach(struct scc_softc *sc __unused, int reset __unused)
72 {
73
74 return (0);
75 }
76
77 static int
sab82532_bfe_iclear(struct scc_softc * sc,struct scc_chan * ch)78 sab82532_bfe_iclear(struct scc_softc *sc, struct scc_chan *ch)
79 {
80 struct scc_bas *bas;
81 int i, ofs, rbcl;
82
83 bas = &sc->sc_bas;
84 ofs = (ch->ch_nr - 1) * SAB_CHANLEN;
85 mtx_lock_spin(&sc->sc_hwmtx);
86 if (ch->ch_ipend & SER_INT_RXREADY) {
87 if (scc_getreg(bas, ofs + SAB_STAR) & SAB_STAR_RFNE) {
88 rbcl = scc_getreg(bas, ofs + SAB_RBCL) & 31;
89 if (rbcl == 0)
90 rbcl = 32;
91 for (i = 0; i < rbcl; i += 2) {
92 (void)scc_getreg(bas, ofs + SAB_RFIFO);
93 (void)scc_getreg(bas, ofs + SAB_RFIFO + 1);
94 }
95 }
96 while (scc_getreg(bas, ofs + SAB_STAR) & SAB_STAR_CEC)
97 ;
98 scc_setreg(bas, ofs + SAB_CMDR, SAB_CMDR_RMC);
99 scc_barrier(bas);
100 }
101 mtx_unlock_spin(&sc->sc_hwmtx);
102 return (0);
103 }
104
105 static int
sab82532_bfe_ipend(struct scc_softc * sc)106 sab82532_bfe_ipend(struct scc_softc *sc)
107 {
108 struct scc_bas *bas;
109 struct scc_chan *ch;
110 int ipend;
111 int c, ofs;
112 uint8_t isr0, isr1;
113
114 bas = &sc->sc_bas;
115 ipend = 0;
116 for (c = 0; c < SAB_NCHAN; c++) {
117 ch = &sc->sc_chan[c];
118 ofs = c * SAB_CHANLEN;
119 mtx_lock_spin(&sc->sc_hwmtx);
120 isr0 = scc_getreg(bas, ofs + SAB_ISR0);
121 isr1 = scc_getreg(bas, ofs + SAB_ISR1);
122 scc_barrier(bas);
123 if (isr0 & SAB_ISR0_TIME) {
124 while (scc_getreg(bas, ofs + SAB_STAR) & SAB_STAR_CEC)
125 ;
126 scc_setreg(bas, ofs + SAB_CMDR, SAB_CMDR_RFRD);
127 scc_barrier(bas);
128 }
129 mtx_unlock_spin(&sc->sc_hwmtx);
130
131 ch->ch_ipend = 0;
132 if (isr1 & SAB_ISR1_BRKT)
133 ch->ch_ipend |= SER_INT_BREAK;
134 if (isr0 & SAB_ISR0_RFO)
135 ch->ch_ipend |= SER_INT_OVERRUN;
136 if (isr0 & (SAB_ISR0_TCD|SAB_ISR0_RPF))
137 ch->ch_ipend |= SER_INT_RXREADY;
138 if ((isr0 & SAB_ISR0_CDSC) || (isr1 & SAB_ISR1_CSC))
139 ch->ch_ipend |= SER_INT_SIGCHG;
140 if (isr1 & SAB_ISR1_ALLS)
141 ch->ch_ipend |= SER_INT_TXIDLE;
142 ipend |= ch->ch_ipend;
143 }
144 return (ipend);
145 }
146
147 static int
sab82532_bfe_probe(struct scc_softc * sc __unused)148 sab82532_bfe_probe(struct scc_softc *sc __unused)
149 {
150
151 return (0);
152 }
153