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