rtfps.c revision 1.29
1/*	$NetBSD: rtfps.c,v 1.29 1997/08/13 21:26:54 jtk Exp $	*/
2
3/*
4 * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
5 * Copyright (c) 1995 Charles Hannum.  All rights reserved.
6 *
7 * This code is derived from public-domain software written by
8 * Roland McGrath.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *	This product includes software developed by Charles Hannum.
21 * 4. The name of the author may not be used to endorse or promote products
22 *    derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/device.h>
39#include <sys/termios.h>
40
41#include <machine/bus.h>
42#include <machine/intr.h>
43
44#include <dev/isa/isavar.h>
45#include <dev/isa/comreg.h>
46#include <dev/isa/comvar.h>
47#include <dev/isa/com_multi.h>
48
49#define	NSLAVES	4
50
51struct rtfps_softc {
52	struct device sc_dev;
53	void *sc_ih;
54
55	bus_space_tag_t sc_iot;
56	int sc_iobase;
57	int sc_irqport;
58	bus_space_handle_t sc_irqioh;
59
60	int sc_alive;			/* mask of slave units attached */
61	void *sc_slaves[NSLAVES];	/* com device unit numbers */
62	bus_space_handle_t sc_slaveioh[NSLAVES];
63};
64
65int rtfpsprobe __P((struct device *, void *, void *));
66void rtfpsattach __P((struct device *, struct device *, void *));
67int rtfpsintr __P((void *));
68int rtfpsprint __P((void *, const char *));
69
70struct cfattach rtfps_ca = {
71	sizeof(struct rtfps_softc), rtfpsprobe, rtfpsattach
72};
73
74struct cfdriver rtfps_cd = {
75	NULL, "rtfps", DV_TTY
76};
77
78int
79rtfpsprobe(parent, self, aux)
80	struct device *parent;
81	void *self;
82	void *aux;
83{
84	struct isa_attach_args *ia = aux;
85	int iobase = ia->ia_iobase;
86	bus_space_tag_t iot = ia->ia_iot;
87	bus_space_handle_t ioh;
88	int i, rv = 1;
89
90	/*
91	 * Do the normal com probe for the first UART and assume
92	 * its presence, and the ability to map the other UARTS,
93	 * means there is a multiport board there.
94	 * XXX Needs more robustness.
95	 */
96
97	/* if the first port is in use as console, then it. */
98	if (iobase == comconsaddr
99#ifdef KGDB
100	    || iobase == com_kgdb_addr
101#endif
102	    )
103		goto checkmappings;
104
105	if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
106		rv = 0;
107		goto out;
108	}
109	rv = comprobe1(iot, ioh, iobase);
110	bus_space_unmap(iot, ioh, COM_NPORTS);
111	if (rv == 0)
112		goto out;
113
114checkmappings:
115	for (i = 1; i < NSLAVES; i++) {
116		iobase += COM_NPORTS;
117
118		if (iobase == comconsaddr
119#ifdef KGDB
120		    || iobase == com_kgdb_addr
121#endif
122		    )
123			continue;
124
125		if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
126			rv = 0;
127			goto out;
128		}
129		bus_space_unmap(iot, ioh, COM_NPORTS);
130	}
131
132out:
133	if (rv)
134		ia->ia_iosize = NSLAVES * COM_NPORTS;
135	return (rv);
136}
137
138int
139rtfpsprint(aux, pnp)
140	void *aux;
141	const char *pnp;
142{
143	struct commulti_attach_args *ca = aux;
144
145	if (pnp)
146		printf("com at %s", pnp);
147	printf(" slave %d", ca->ca_slave);
148	return (UNCONF);
149}
150
151void
152rtfpsattach(parent, self, aux)
153	struct device *parent, *self;
154	void *aux;
155{
156	struct rtfps_softc *sc = (void *)self;
157	struct isa_attach_args *ia = aux;
158	struct commulti_attach_args ca;
159	static int irqport[] = {
160		IOBASEUNK, IOBASEUNK, IOBASEUNK, IOBASEUNK,
161		IOBASEUNK, IOBASEUNK, IOBASEUNK, IOBASEUNK,
162		IOBASEUNK,     0x2f2,     0x6f2,     0x6f3,
163		IOBASEUNK, IOBASEUNK, IOBASEUNK, IOBASEUNK
164	};
165	bus_space_tag_t iot = ia->ia_iot;
166	int i;
167
168	sc->sc_iot = ia->ia_iot;
169	sc->sc_iobase = ia->ia_iobase;
170
171	if (ia->ia_irq >= 16 || irqport[ia->ia_irq] == IOBASEUNK)
172		panic("rtfpsattach: invalid irq");
173	sc->sc_irqport = irqport[ia->ia_irq];
174
175	for (i = 0; i < NSLAVES; i++)
176		if (bus_space_map(iot, sc->sc_iobase + i * COM_NPORTS,
177		    COM_NPORTS, 0, &sc->sc_slaveioh[i]))
178			panic("rtfpsattach: couldn't map slave %d", i);
179	if (bus_space_map(iot, sc->sc_irqport, 1, 0, &sc->sc_irqioh))
180		panic("rtfpsattach: couldn't map irq port at 0x%x\n",
181		    sc->sc_irqport);
182
183	bus_space_write_1(iot, sc->sc_irqioh, 0, 0);
184
185	printf("\n");
186
187	for (i = 0; i < NSLAVES; i++) {
188		ca.ca_slave = i;
189		ca.ca_iot = sc->sc_iot;
190		ca.ca_ioh = sc->sc_slaveioh[i];
191		ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS;
192		ca.ca_noien = 0;
193
194		sc->sc_slaves[i] = config_found(self, &ca, rtfpsprint);
195		if (sc->sc_slaves[i] != NULL)
196			sc->sc_alive |= 1 << i;
197	}
198
199	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
200	    IPL_SERIAL, rtfpsintr, sc);
201}
202
203int
204rtfpsintr(arg)
205	void *arg;
206{
207	struct rtfps_softc *sc = arg;
208	bus_space_tag_t iot = sc->sc_iot;
209	int alive = sc->sc_alive;
210
211	bus_space_write_1(iot, sc->sc_irqioh, 0, 0);
212
213#define	TRY(n) \
214	if (alive & (1 << (n))) \
215		comintr(sc->sc_slaves[n]);
216	TRY(0);
217	TRY(1);
218	TRY(2);
219	TRY(3);
220#undef TRY
221
222	return (1);
223}
224