scc_dev_z8530.c revision 253899
1157299Smarcel/*- 2157299Smarcel * Copyright (c) 2004-2006 Marcel Moolenaar 3157299Smarcel * All rights reserved. 4157299Smarcel * 5157299Smarcel * Redistribution and use in source and binary forms, with or without 6157299Smarcel * modification, are permitted provided that the following conditions 7157299Smarcel * are met: 8157299Smarcel * 9157299Smarcel * 1. Redistributions of source code must retain the above copyright 10157299Smarcel * notice, this list of conditions and the following disclaimer. 11157299Smarcel * 2. Redistributions in binary form must reproduce the above copyright 12157299Smarcel * notice, this list of conditions and the following disclaimer in the 13157299Smarcel * documentation and/or other materials provided with the distribution. 14157299Smarcel * 15157299Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16157299Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17157299Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18157299Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19157299Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20157299Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21157299Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22157299Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23157299Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24157299Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25157299Smarcel */ 26157299Smarcel 27157299Smarcel#include <sys/cdefs.h> 28157299Smarcel__FBSDID("$FreeBSD: head/sys/dev/scc/scc_dev_z8530.c 253899 2013-08-02 23:28:49Z marius $"); 29157299Smarcel 30157299Smarcel#include <sys/param.h> 31157299Smarcel#include <sys/systm.h> 32157299Smarcel#include <sys/bus.h> 33157299Smarcel#include <sys/conf.h> 34157299Smarcel#include <machine/bus.h> 35157299Smarcel#include <sys/rman.h> 36157299Smarcel#include <sys/serial.h> 37157299Smarcel 38157299Smarcel#include <dev/scc/scc_bfe.h> 39157299Smarcel#include <dev/scc/scc_bus.h> 40157299Smarcel 41157299Smarcel#include <dev/ic/z8530.h> 42157299Smarcel 43157299Smarcel#include "scc_if.h" 44157299Smarcel 45157299Smarcelstatic int z8530_bfe_attach(struct scc_softc *, int); 46157299Smarcelstatic int z8530_bfe_iclear(struct scc_softc *, struct scc_chan *); 47157299Smarcelstatic int z8530_bfe_ipend(struct scc_softc *); 48157299Smarcelstatic int z8530_bfe_probe(struct scc_softc *); 49157299Smarcel 50157299Smarcelstatic kobj_method_t z8530_methods[] = { 51157299Smarcel KOBJMETHOD(scc_attach, z8530_bfe_attach), 52157299Smarcel KOBJMETHOD(scc_iclear, z8530_bfe_iclear), 53157299Smarcel KOBJMETHOD(scc_ipend, z8530_bfe_ipend), 54157299Smarcel KOBJMETHOD(scc_probe, z8530_bfe_probe), 55253899Smarius KOBJMETHOD_END 56157299Smarcel}; 57157299Smarcel 58157299Smarcelstruct scc_class scc_z8530_class = { 59157299Smarcel "z8530 class", 60157299Smarcel z8530_methods, 61157299Smarcel sizeof(struct scc_softc), 62157299Smarcel .cl_channels = 2, 63157299Smarcel .cl_class = SCC_CLASS_Z8530, 64157299Smarcel .cl_modes = SCC_MODE_ASYNC | SCC_MODE_BISYNC | SCC_MODE_HDLC, 65160689Smarcel .cl_range = CHAN_B - CHAN_A, 66157299Smarcel}; 67157299Smarcel 68157299Smarcel/* Multiplexed I/O. */ 69157299Smarcelstatic __inline void 70157299Smarcelscc_setmreg(struct scc_bas *bas, int ch, int reg, int val) 71157299Smarcel{ 72157299Smarcel 73157299Smarcel scc_setreg(bas, ch + REG_CTRL, reg); 74157299Smarcel scc_barrier(bas); 75157299Smarcel scc_setreg(bas, ch + REG_CTRL, val); 76157299Smarcel} 77157299Smarcel 78157299Smarcelstatic __inline uint8_t 79157299Smarcelscc_getmreg(struct scc_bas *bas, int ch, int reg) 80157299Smarcel{ 81157299Smarcel 82157299Smarcel scc_setreg(bas, ch + REG_CTRL, reg); 83157299Smarcel scc_barrier(bas); 84157299Smarcel return (scc_getreg(bas, ch + REG_CTRL)); 85157299Smarcel} 86157299Smarcel 87157299Smarcelstatic int 88253899Smariusz8530_bfe_attach(struct scc_softc *sc __unused, int reset __unused) 89157299Smarcel{ 90157299Smarcel 91157299Smarcel return (0); 92157299Smarcel} 93157299Smarcel 94157299Smarcelstatic int 95157299Smarcelz8530_bfe_iclear(struct scc_softc *sc, struct scc_chan *ch) 96157299Smarcel{ 97157299Smarcel struct scc_bas *bas; 98157299Smarcel int c; 99157299Smarcel 100157299Smarcel bas = &sc->sc_bas; 101157299Smarcel c = (ch->ch_nr == 1) ? CHAN_A : CHAN_B; 102157299Smarcel mtx_lock_spin(&sc->sc_hwmtx); 103157299Smarcel if (ch->ch_ipend & SER_INT_TXIDLE) { 104157299Smarcel scc_setreg(bas, c + REG_CTRL, CR_RSTTXI); 105157299Smarcel scc_barrier(bas); 106157299Smarcel } 107157299Smarcel if (ch->ch_ipend & SER_INT_RXREADY) { 108157299Smarcel scc_getreg(bas, c + REG_DATA); 109157299Smarcel scc_barrier(bas); 110157299Smarcel } 111157299Smarcel if (ch->ch_ipend & (SER_INT_OVERRUN|SER_INT_BREAK)) 112157299Smarcel scc_setreg(bas, c + REG_CTRL, CR_RSTERR); 113157299Smarcel mtx_unlock_spin(&sc->sc_hwmtx); 114157299Smarcel return (0); 115157299Smarcel} 116157299Smarcel 117157299Smarcel#define SIGCHG(c, i, s, d) \ 118157299Smarcel if (c) { \ 119157299Smarcel i |= (i & s) ? s : s | d; \ 120157299Smarcel } else { \ 121157299Smarcel i = (i & s) ? (i & ~s) | d : i; \ 122157299Smarcel } 123157299Smarcel 124157299Smarcelstatic int 125157299Smarcelz8530_bfe_ipend(struct scc_softc *sc) 126157299Smarcel{ 127157299Smarcel struct scc_bas *bas; 128157299Smarcel struct scc_chan *ch[2]; 129157299Smarcel uint32_t sig; 130157299Smarcel uint8_t bes, ip, src; 131157299Smarcel 132157299Smarcel bas = &sc->sc_bas; 133157299Smarcel ch[0] = &sc->sc_chan[0]; 134157299Smarcel ch[1] = &sc->sc_chan[1]; 135157299Smarcel ch[0]->ch_ipend = 0; 136157299Smarcel ch[1]->ch_ipend = 0; 137157299Smarcel 138157299Smarcel mtx_lock_spin(&sc->sc_hwmtx); 139157299Smarcel ip = scc_getmreg(bas, CHAN_A, RR_IP); 140157299Smarcel if (ip & IP_RIA) 141157299Smarcel ch[0]->ch_ipend |= SER_INT_RXREADY; 142157299Smarcel if (ip & IP_RIB) 143157299Smarcel ch[1]->ch_ipend |= SER_INT_RXREADY; 144157299Smarcel if (ip & IP_TIA) 145157299Smarcel ch[0]->ch_ipend |= SER_INT_TXIDLE; 146157299Smarcel if (ip & IP_TIB) 147157299Smarcel ch[1]->ch_ipend |= SER_INT_TXIDLE; 148157299Smarcel if (ip & IP_SIA) { 149157299Smarcel scc_setreg(bas, CHAN_A + REG_CTRL, CR_RSTXSI); 150157299Smarcel scc_barrier(bas); 151157299Smarcel bes = scc_getreg(bas, CHAN_A + REG_CTRL); 152157299Smarcel if (bes & BES_BRK) 153157299Smarcel ch[0]->ch_ipend |= SER_INT_BREAK; 154157299Smarcel sig = ch[0]->ch_hwsig; 155157299Smarcel SIGCHG(bes & BES_CTS, sig, SER_CTS, SER_DCTS); 156157299Smarcel SIGCHG(bes & BES_DCD, sig, SER_DCD, SER_DDCD); 157157299Smarcel SIGCHG(bes & BES_SYNC, sig, SER_DSR, SER_DDSR); 158157299Smarcel if (sig & SER_MASK_DELTA) { 159157299Smarcel ch[0]->ch_hwsig = sig; 160157299Smarcel ch[0]->ch_ipend |= SER_INT_SIGCHG; 161157299Smarcel } 162157299Smarcel src = scc_getmreg(bas, CHAN_A, RR_SRC); 163157299Smarcel if (src & SRC_OVR) 164157299Smarcel ch[0]->ch_ipend |= SER_INT_OVERRUN; 165157299Smarcel } 166157299Smarcel if (ip & IP_SIB) { 167157299Smarcel scc_setreg(bas, CHAN_B + REG_CTRL, CR_RSTXSI); 168157299Smarcel scc_barrier(bas); 169157299Smarcel bes = scc_getreg(bas, CHAN_B + REG_CTRL); 170157299Smarcel if (bes & BES_BRK) 171157299Smarcel ch[1]->ch_ipend |= SER_INT_BREAK; 172157299Smarcel sig = ch[1]->ch_hwsig; 173157299Smarcel SIGCHG(bes & BES_CTS, sig, SER_CTS, SER_DCTS); 174157299Smarcel SIGCHG(bes & BES_DCD, sig, SER_DCD, SER_DDCD); 175157299Smarcel SIGCHG(bes & BES_SYNC, sig, SER_DSR, SER_DDSR); 176157299Smarcel if (sig & SER_MASK_DELTA) { 177157299Smarcel ch[1]->ch_hwsig = sig; 178157299Smarcel ch[1]->ch_ipend |= SER_INT_SIGCHG; 179157299Smarcel } 180157299Smarcel src = scc_getmreg(bas, CHAN_B, RR_SRC); 181157299Smarcel if (src & SRC_OVR) 182157299Smarcel ch[1]->ch_ipend |= SER_INT_OVERRUN; 183157299Smarcel } 184157299Smarcel mtx_unlock_spin(&sc->sc_hwmtx); 185157299Smarcel 186157299Smarcel return (ch[0]->ch_ipend | ch[1]->ch_ipend); 187157299Smarcel} 188157299Smarcel 189157299Smarcelstatic int 190253899Smariusz8530_bfe_probe(struct scc_softc *sc __unused) 191157299Smarcel{ 192157299Smarcel 193157299Smarcel return (0); 194157299Smarcel} 195