xref: /netbsd-src/sys/arch/amiga/dev/gvpio.c (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*	$NetBSD: gvpio.c,v 1.16 2007/03/04 05:59:20 christos Exp $ */
2 
3 /*
4  * Copyright (c) 1997 Ignatios Souvatzis
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Ignatios Souvatzis
18  *      for the NetBSD Project.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: gvpio.c,v 1.16 2007/03/04 05:59:20 christos Exp $");
36 
37 /*
38  * GVP I/O Extender
39  */
40 
41 #include <sys/types.h>
42 
43 #include <sys/conf.h>
44 #include <sys/device.h>
45 #include <sys/systm.h>
46 #include <sys/param.h>
47 
48 #include <machine/bus.h>
49 #include <machine/intr.h>
50 
51 #include <amiga/include/cpu.h>
52 
53 #include <amiga/amiga/device.h>
54 #include <amiga/amiga/drcustom.h>
55 
56 #include <amiga/dev/supio.h>
57 #include <amiga/dev/zbusvar.h>
58 #include <amiga/dev/gvpbusvar.h>
59 
60 struct gvpio_softc {
61 	struct device sc_dev;
62 	struct bus_space_tag sc_bst;
63 	void *sc_cntr;
64 	LIST_HEAD(, gvpcom_int_hdl) sc_comhdls;
65 	struct isr sc_comisr;
66 };
67 
68 int gvpiomatch(struct device *, struct cfdata *, void *);
69 void gvpioattach(struct device *, struct device *, void *);
70 int gvpioprint(void *auxp, const char *);
71 int gvp_com_intr(void *);
72 void gvp_com_intr_establish(struct device *, struct gvpcom_int_hdl *);
73 
74 CFATTACH_DECL(gvpio, sizeof(struct gvpio_softc),
75     gvpiomatch, gvpioattach, NULL, NULL);
76 
77 int
78 gvpiomatch(struct device *parent, struct cfdata *cfp, void *auxp)
79 {
80 
81 	struct gvpbus_args *gap;
82 
83 	gap = auxp;
84 
85 	if (gap->flags & GVP_IO)
86 		return (1);
87 
88 	return (0);
89 }
90 
91 struct gvpio_devs {
92 	char *name;
93 	int off;
94 	int arg;
95 	int ipl;
96 } gvpiodevs[] = {
97 	{ "com", 0x0b0, 115200 * 16 * 4, 6 },
98 	{ "com", 0x130, 115200 * 16 * 4, 6 },
99 	{ "lpt", 0x1b0, 0, 2 },
100 	{ 0 }
101 };
102 
103 void
104 gvpioattach(struct device *parent, struct device *self, void *auxp)
105 {
106 	struct gvpio_softc *giosc;
107 	struct gvpio_devs  *giosd;
108 	struct gvpbus_args *gap;
109 	struct supio_attach_args supa;
110 	volatile void *gbase;
111 	u_int16_t needpsl;
112 
113 	giosc = (struct gvpio_softc *)self;
114 	gap = auxp;
115 
116 	if (parent)
117 		printf("\n");
118 
119 	gbase = gap->zargs.va;
120 	giosc->sc_cntr = &gbase[0x41];
121 	giosc->sc_bst.base = (u_long)gbase + 1;
122 	giosc->sc_bst.absm = &amiga_bus_stride_2;
123 	LIST_INIT(&giosc->sc_comhdls);
124 	giosd = gvpiodevs;
125 
126 	supa.supio_iot = &giosc->sc_bst;
127 
128 	gbase[0x041] = 0;
129 	gbase[0x161 + 1*2] = 0;
130 	gbase[0x261 + 1*2] = 0;
131 	gbase[0x361 + 2*2] = 0;
132 	gbase[0x461] = 0xd0;
133 
134 	while (giosd->name) {
135 		supa.supio_name = giosd->name;
136 		supa.supio_iobase = giosd->off;
137 		supa.supio_arg = giosd->arg;
138 		supa.supio_ipl = giosd->ipl;
139 		config_found(self, &supa, gvpioprint); /* XXX */
140 		++giosd;
141 	}
142 	if (giosc->sc_comhdls.lh_first) {
143 		/* XXX this should be really in the interrupt stuff */
144 		needpsl = PSL_S|PSL_IPL6;
145 		if (ipl2spl_table[IPL_SERIAL] < needpsl) {
146 			printf("%s: raising ipl2spl_table[IPL_SERIAL] "
147 			    "from 0x%x to 0x%x\n",
148 			    giosc->sc_dev.dv_xname, ipl2spl_table[IPL_SERIAL],
149 			    needpsl);
150 			ipl2spl_table[IPL_SERIAL] = needpsl;
151 		}
152 		giosc->sc_comisr.isr_intr = gvp_com_intr;
153 		giosc->sc_comisr.isr_arg = giosc;
154 		giosc->sc_comisr.isr_ipl = 6;
155 		add_isr(&giosc->sc_comisr);
156 	}
157 	gbase[0x041] = 0x08;
158 }
159 
160 int
161 gvpioprint(void *auxp, const char *pnp)
162 {
163 	struct supio_attach_args *supa;
164 	supa = auxp;
165 
166 	if (pnp == NULL)
167 		return(QUIET);
168 
169 	aprint_normal("%s at %s port 0x%02x ipl %d",
170 	    supa->supio_name, pnp, supa->supio_iobase, supa->supio_ipl);
171 
172 	return(UNCONF);
173 }
174 
175 void
176 gvp_com_intr_establish(struct device *self, struct gvpcom_int_hdl *p)
177 {
178 	struct gvpio_softc *sc;
179 
180 	sc = (struct gvpio_softc *)self;
181 	LIST_INSERT_HEAD(&sc->sc_comhdls, p, next);
182 
183 }
184 
185 int
186 gvp_com_intr(void *p)
187 {
188 	struct gvpio_softc *sc;
189 	struct gvpcom_int_hdl *np;
190 	volatile void *cntr;
191 
192 	sc = (struct gvpio_softc *)p;
193 
194 	cntr = sc->sc_cntr;
195 
196 	if (!(*cntr & 0x2))
197 		return (0);
198 
199 	*cntr &= ~0xa;
200 
201 	for (np = sc->sc_comhdls.lh_first; np != NULL;
202 	    np = np->next.le_next) {
203 
204 		(*np->f)(np->p);
205 	}
206 	*cntr |= 0x8;
207 
208 	return (1);
209 }
210