rtfps.c revision 1.20
1/*	$NetBSD: rtfps.c,v 1.20 1996/04/11 22:29:57 cgd 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/device.h>
38
39#ifdef i386							/* XXX */
40#include <machine/cpu.h>					/* XXX */
41#else								/* XXX */
42#include <machine/intr.h>
43#endif								/* XXX */
44#include <machine/bus.h>
45
46#include <dev/isa/isavar.h>
47#include <dev/isa/comreg.h>
48#include <dev/isa/comvar.h>
49
50#define	NSLAVES	4
51
52struct rtfps_softc {
53	struct device sc_dev;
54	void *sc_ih;
55
56	bus_chipset_tag_t sc_bc;
57	int sc_iobase;
58	int sc_irqport;
59	bus_io_handle_t sc_irqioh;
60
61	int sc_alive;			/* mask of slave units attached */
62	void *sc_slaves[NSLAVES];	/* com device unit numbers */
63	bus_io_handle_t sc_slaveioh[NSLAVES];
64};
65
66int rtfpsprobe();
67void rtfpsattach();
68int rtfpsintr __P((void *));
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, *self;
81	void *aux;
82{
83	struct isa_attach_args *ia = aux;
84	int iobase = ia->ia_iobase;
85	bus_chipset_tag_t bc = ia->ia_bc;
86	bus_io_handle_t ioh;
87	int i, rv = 1;
88
89	/*
90	 * Do the normal com probe for the first UART and assume
91	 * its presence, and the ability to map the other UARTS,
92	 * means there is a multiport board there.
93	 * XXX Needs more robustness.
94	 */
95
96	/* if the first port is in use as console, then it. */
97	if (iobase == comconsaddr && !comconsattached)
98		goto checkmappings;
99
100	if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) {
101		rv = 0;
102		goto out;
103	}
104	rv = comprobe1(bc, ioh, iobase);
105	bus_io_unmap(bc, ioh, COM_NPORTS);
106	if (rv == 0)
107		goto out;
108
109checkmappings:
110	for (i = 1; i < NSLAVES; i++) {
111		iobase += COM_NPORTS;
112
113		if (iobase == comconsaddr && !comconsattached)
114			continue;
115
116		if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) {
117			rv = 0;
118			goto out;
119		}
120		bus_io_unmap(bc, ioh, COM_NPORTS);
121	}
122
123out:
124	if (rv)
125		ia->ia_iosize = NSLAVES * COM_NPORTS;
126	return (rv);
127}
128
129int
130rtfpsprint(aux, pnp)
131	void *aux;
132	char *pnp;
133{
134	struct commulti_attach_args *ca = aux;
135
136	if (pnp)
137		printf("com at %s", pnp);
138	printf(" slave %d", ca->ca_slave);
139	return (UNCONF);
140}
141
142void
143rtfpsattach(parent, self, aux)
144	struct device *parent, *self;
145	void *aux;
146{
147	struct rtfps_softc *sc = (void *)self;
148	struct isa_attach_args *ia = aux;
149	struct commulti_attach_args ca;
150	static int irqport[] = {
151		IOBASEUNK, IOBASEUNK, IOBASEUNK, IOBASEUNK,
152		IOBASEUNK, IOBASEUNK, IOBASEUNK, IOBASEUNK,
153		IOBASEUNK,     0x2f2,     0x6f2,     0x6f3,
154		IOBASEUNK, IOBASEUNK, IOBASEUNK, IOBASEUNK
155	};
156	int i, subunit;
157
158	sc->sc_bc = ia->ia_bc;
159	sc->sc_iobase = ia->ia_iobase;
160
161	if (ia->ia_irq >= 16 || irqport[ia->ia_irq] == IOBASEUNK)
162		panic("rtfpsattach: invalid irq");
163	sc->sc_irqport = irqport[ia->ia_irq];
164
165	for (i = 0; i < NSLAVES; i++)
166		if (bus_io_map(bc, sc->sc_iobase + i * COM_NPORTS, COM_NPORTS,
167		    &sc->sc_slaveioh[i]))
168			panic("rtfpsattach: couldn't map slave %d", i);
169	if (bus_io_map(bc, sc->sc_irqport, 1, &sc->sc_irqioh))
170		panic("rtfpsattach: couldn't map irq port at 0x%x\n",
171		    sc->sc_irqport);
172
173	bus_io_write_1(bc, sc->sc_irqioh, 0, 0);
174
175	printf("\n");
176
177	for (i = 0; i < NSLAVES; i++) {
178		struct cfdata *match;
179
180		ca.ca_slave = i;
181		ca.ca_bc = sc->sc_bc;
182		ca.ca_ioh = sc->sc_slaveioh[i];
183		ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS;
184		ca.ca_noien = 0;
185
186		sc->sc_slaves[i] = config_found(self, &ca, rtfpsprint);
187		if (sc->sc_slaves[i] != NULL)
188			sc->sc_alive |= 1 << i;
189	}
190
191	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
192	    IPL_TTY, rtfpsintr, sc);
193}
194
195int
196rtfpsintr(arg)
197	void *arg;
198{
199	struct rtfps_softc *sc = arg;
200	bus_chipset_tag_t bc = sc->sc_bc;
201	int alive = sc->sc_alive;
202
203	bus_io_write_1(bc, sc->sc_irqioh, 0, 0);
204
205#define	TRY(n) \
206	if (alive & (1 << (n))) \
207		comintr(sc->sc_slaves[n]);
208	TRY(0);
209	TRY(1);
210	TRY(2);
211	TRY(3);
212#undef TRY
213
214	return (1);
215}
216