scc_dev_sab82532.c revision 157299
1/*-
2 * Copyright (c) 2004-2006 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
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.
14 *
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.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/scc/scc_dev_sab82532.c 157299 2006-03-30 18:33:22Z marcel $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/bus.h>
33#include <sys/conf.h>
34#include <machine/bus.h>
35#include <sys/rman.h>
36#include <sys/serial.h>
37
38#include <dev/scc/scc_bfe.h>
39#include <dev/scc/scc_bus.h>
40
41#include <dev/ic/sab82532.h>
42
43#include "scc_if.h"
44
45#define	DEFAULT_RCLK	29491200
46
47static int sab82532_bfe_attach(struct scc_softc *, int);
48static int sab82532_bfe_iclear(struct scc_softc *, struct scc_chan *);
49static int sab82532_bfe_ipend(struct scc_softc *);
50static int sab82532_bfe_probe(struct scc_softc *);
51
52static 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	{ 0, 0 }
58};
59
60struct 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	.cl_rclk = DEFAULT_RCLK,
69	.cl_regshft = 0
70};
71
72static int
73sab82532_bfe_attach(struct scc_softc *sc, int reset)
74{
75	struct scc_bas *bas;
76
77	bas = &sc->sc_bas;
78	return (0);
79}
80
81static int
82sab82532_bfe_iclear(struct scc_softc *sc, struct scc_chan *ch)
83{
84
85	return (0);
86}
87
88static int
89sab82532_bfe_ipend(struct scc_softc *sc)
90{
91	struct scc_bas *bas;
92	struct scc_chan *ch;
93	int ipend;
94	int c, ofs;
95	uint8_t isr0, isr1;
96
97	bas = &sc->sc_bas;
98	ipend = 0;
99	for (c = 0; c < SAB_NCHAN; c++) {
100		ch = &sc->sc_chan[c];
101		ofs = c * SAB_CHANLEN;
102		mtx_lock_spin(&sc->sc_hwmtx);
103		isr0 = scc_getreg(bas, ofs + SAB_ISR0);
104		isr1 = scc_getreg(bas, ofs + SAB_ISR1);
105		scc_barrier(bas);
106		if (isr0 & SAB_ISR0_TIME) {
107			while (scc_getreg(bas, ofs + SAB_STAR) & SAB_STAR_CEC)
108				;
109			scc_setreg(bas, ofs + SAB_CMDR, SAB_CMDR_RFRD);
110			scc_barrier(bas);
111		}
112		mtx_unlock_spin(&sc->sc_hwmtx);
113
114		ch->ch_ipend = 0;
115		if (isr1 & SAB_ISR1_BRKT)
116			ch->ch_ipend |= SER_INT_BREAK;
117		if (isr0 & SAB_ISR0_RFO)
118			ch->ch_ipend |= SER_INT_OVERRUN;
119		if (isr0 & (SAB_ISR0_TCD|SAB_ISR0_RPF))
120			ch->ch_ipend |= SER_INT_RXREADY;
121		if ((isr0 & SAB_ISR0_CDSC) || (isr1 & SAB_ISR1_CSC))
122			ch->ch_ipend |= SER_INT_SIGCHG;
123		if (isr1 & SAB_ISR1_ALLS)
124			ch->ch_ipend |= SER_INT_TXIDLE;
125		ipend |= ch->ch_ipend;
126	}
127	return (ipend);
128}
129
130static int
131sab82532_bfe_probe(struct scc_softc *sc)
132{
133	struct scc_bas *bas;
134
135	bas = &sc->sc_bas;
136	return (0);
137}
138