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/quicc.h>
49 #define quicc_read2(bas, reg) \
50 bus_space_read_2((bas)->bst, (bas)->bsh, reg)
51 #define quicc_read4(bas, reg) \
52 bus_space_read_4((bas)->bst, (bas)->bsh, reg)
54 #define quicc_write2(bas, reg, val) \
55 bus_space_write_2((bas)->bst, (bas)->bsh, reg, val)
56 #define quicc_write4(bas, reg, val) \
57 bus_space_write_4((bas)->bst, (bas)->bsh, reg, val)
59 static int quicc_bfe_attach(struct scc_softc *, int);
60 static int quicc_bfe_enabled(struct scc_softc *, struct scc_chan *);
61 static int quicc_bfe_iclear(struct scc_softc *, struct scc_chan *);
62 static int quicc_bfe_ipend(struct scc_softc *);
63 static int quicc_bfe_probe(struct scc_softc *);
65 static kobj_method_t quicc_methods[] = {
66 KOBJMETHOD(scc_attach, quicc_bfe_attach),
67 KOBJMETHOD(scc_enabled, quicc_bfe_enabled),
68 KOBJMETHOD(scc_iclear, quicc_bfe_iclear),
69 KOBJMETHOD(scc_ipend, quicc_bfe_ipend),
70 KOBJMETHOD(scc_probe, quicc_bfe_probe),
74 struct scc_class scc_quicc_class = {
77 sizeof(struct scc_softc),
79 .cl_class = SCC_CLASS_QUICC,
80 .cl_modes = SCC_MODE_ASYNC | SCC_MODE_BISYNC | SCC_MODE_HDLC,
85 quicc_bfe_attach(struct scc_softc *sc __unused, int reset __unused)
92 quicc_bfe_enabled(struct scc_softc *sc, struct scc_chan *ch)
100 val0 = quicc_read2(bas, QUICC_REG_SCC_TODR(unit));
101 quicc_write2(bas, QUICC_REG_SCC_TODR(unit), ~val0);
102 val1 = quicc_read2(bas, QUICC_REG_SCC_TODR(unit));
103 quicc_write2(bas, QUICC_REG_SCC_TODR(unit), val0);
104 return (((val0 | val1) == 0x8000) ? 1 : 0);
108 quicc_bfe_iclear(struct scc_softc *sc, struct scc_chan *ch)
114 mtx_lock_spin(&sc->sc_hwmtx);
115 if (ch->ch_ipend & SER_INT_RXREADY) {
116 rb = quicc_read2(bas, QUICC_PRAM_SCC_RBASE(ch->ch_nr - 1));
117 st = quicc_read2(bas, rb);
118 (void)quicc_read4(bas, rb + 4);
119 quicc_write2(bas, rb, st | 0x9000);
121 mtx_unlock_spin(&sc->sc_hwmtx);
126 quicc_bfe_ipend(struct scc_softc *sc)
135 for (c = 0; c < 4; c++) {
136 ch = &sc->sc_chan[c];
140 mtx_lock_spin(&sc->sc_hwmtx);
141 scce = quicc_read2(bas, QUICC_REG_SCC_SCCE(c));
142 quicc_write2(bas, QUICC_REG_SCC_SCCE(c), ~0);
143 mtx_unlock_spin(&sc->sc_hwmtx);
145 ch->ch_ipend |= SER_INT_RXREADY;
147 ch->ch_ipend |= SER_INT_TXIDLE;
149 ch->ch_ipend |= SER_INT_OVERRUN;
151 ch->ch_ipend |= SER_INT_BREAK;
153 ipend |= ch->ch_ipend;
159 quicc_bfe_probe(struct scc_softc *sc __unused)