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/serial.h>
40 #include <dev/scc/scc_bfe.h>
41 #include <dev/scc/scc_bus.h>
43 #include <dev/ic/quicc.h>
47 #define quicc_read2(bas, reg) \
48 bus_space_read_2((bas)->bst, (bas)->bsh, reg)
49 #define quicc_read4(bas, reg) \
50 bus_space_read_4((bas)->bst, (bas)->bsh, reg)
52 #define quicc_write2(bas, reg, val) \
53 bus_space_write_2((bas)->bst, (bas)->bsh, reg, val)
54 #define quicc_write4(bas, reg, val) \
55 bus_space_write_4((bas)->bst, (bas)->bsh, reg, val)
57 static int quicc_bfe_attach(struct scc_softc *, int);
58 static int quicc_bfe_enabled(struct scc_softc *, struct scc_chan *);
59 static int quicc_bfe_iclear(struct scc_softc *, struct scc_chan *);
60 static int quicc_bfe_ipend(struct scc_softc *);
61 static int quicc_bfe_probe(struct scc_softc *);
63 static kobj_method_t quicc_methods[] = {
64 KOBJMETHOD(scc_attach, quicc_bfe_attach),
65 KOBJMETHOD(scc_enabled, quicc_bfe_enabled),
66 KOBJMETHOD(scc_iclear, quicc_bfe_iclear),
67 KOBJMETHOD(scc_ipend, quicc_bfe_ipend),
68 KOBJMETHOD(scc_probe, quicc_bfe_probe),
72 struct scc_class scc_quicc_class = {
75 sizeof(struct scc_softc),
77 .cl_class = SCC_CLASS_QUICC,
78 .cl_modes = SCC_MODE_ASYNC | SCC_MODE_BISYNC | SCC_MODE_HDLC,
83 quicc_bfe_attach(struct scc_softc *sc __unused, int reset __unused)
90 quicc_bfe_enabled(struct scc_softc *sc, struct scc_chan *ch)
98 val0 = quicc_read2(bas, QUICC_REG_SCC_TODR(unit));
99 quicc_write2(bas, QUICC_REG_SCC_TODR(unit), ~val0);
100 val1 = quicc_read2(bas, QUICC_REG_SCC_TODR(unit));
101 quicc_write2(bas, QUICC_REG_SCC_TODR(unit), val0);
102 return (((val0 | val1) == 0x8000) ? 1 : 0);
106 quicc_bfe_iclear(struct scc_softc *sc, struct scc_chan *ch)
112 mtx_lock_spin(&sc->sc_hwmtx);
113 if (ch->ch_ipend & SER_INT_RXREADY) {
114 rb = quicc_read2(bas, QUICC_PRAM_SCC_RBASE(ch->ch_nr - 1));
115 st = quicc_read2(bas, rb);
116 (void)quicc_read4(bas, rb + 4);
117 quicc_write2(bas, rb, st | 0x9000);
119 mtx_unlock_spin(&sc->sc_hwmtx);
124 quicc_bfe_ipend(struct scc_softc *sc)
133 for (c = 0; c < 4; c++) {
134 ch = &sc->sc_chan[c];
138 mtx_lock_spin(&sc->sc_hwmtx);
139 scce = quicc_read2(bas, QUICC_REG_SCC_SCCE(c));
140 quicc_write2(bas, QUICC_REG_SCC_SCCE(c), ~0);
141 mtx_unlock_spin(&sc->sc_hwmtx);
143 ch->ch_ipend |= SER_INT_RXREADY;
145 ch->ch_ipend |= SER_INT_TXIDLE;
147 ch->ch_ipend |= SER_INT_OVERRUN;
149 ch->ch_ipend |= SER_INT_BREAK;
151 ipend |= ch->ch_ipend;
157 quicc_bfe_probe(struct scc_softc *sc __unused)