gvpio.c revision 1.4 1 /* $NetBSD: gvpio.c,v 1.4 1999/12/30 20:56:45 is 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 /*
35 * GVP I/O Extender
36 */
37
38 #include <sys/types.h>
39
40 #include <sys/conf.h>
41 #include <sys/device.h>
42 #include <sys/systm.h>
43 #include <sys/param.h>
44
45 #include <machine/bus.h>
46 #include <machine/conf.h>
47 #include <machine/intr.h>
48
49 #include <amiga/include/cpu.h>
50
51 #include <amiga/amiga/device.h>
52 #include <amiga/amiga/drcustom.h>
53
54 #include <amiga/dev/supio.h>
55 #include <amiga/dev/zbusvar.h>
56 #include <amiga/dev/gvpbusvar.h>
57 #include <amiga/dev/gvpiovar.h>
58
59 struct gvpio_softc {
60 struct device sc_dev;
61 struct bus_space_tag sc_bst;
62 caddr_t sc_cntr;
63 LIST_HEAD(, gvpcom_int_hdl) sc_comhdls;
64 struct isr sc_comisr;
65 };
66
67 int gvpiomatch __P((struct device *, struct cfdata *, void *));
68 void gvpioattach __P((struct device *, struct device *, void *));
69 int gvpioprint __P((void *auxp, const char *));
70 int gvp_com_intr __P((void *));
71
72 struct cfattach gvpio_ca = {
73 sizeof(struct gvpio_softc), gvpiomatch, gvpioattach
74 };
75
76 int
77 gvpiomatch(parent, cfp, auxp)
78 struct device *parent;
79 struct cfdata *cfp;
80 void *auxp;
81 {
82
83 struct gvpbus_args *gap;
84
85 gap = auxp;
86
87 if (gap->flags & GVP_IO)
88 return (1);
89
90 return (0);
91 }
92
93 struct gvpio_devs {
94 char *name;
95 int off;
96 int arg;
97 int ipl;
98 } gvpiodevs[] = {
99 { "com", 0x0b0, 115200 * 16 * 4, 6 },
100 { "com", 0x130, 115200 * 16 * 4, 6 },
101 { "lpt", 0x1b0, 0, 2 },
102 { 0 }
103 };
104
105 void
106 gvpioattach(parent, self, auxp)
107 struct device *parent, *self;
108 void *auxp;
109 {
110 struct gvpio_softc *giosc;
111 struct gvpio_devs *giosd;
112 struct gvpbus_args *gap;
113 struct supio_attach_args supa;
114 volatile caddr_t gbase;
115 u_int16_t needpsl;
116
117 giosc = (struct gvpio_softc *)self;
118 gap = auxp;
119
120 if (parent)
121 printf("\n");
122
123 gbase = gap->zargs.va;
124 giosc->sc_cntr = &gbase[0x41];
125 giosc->sc_bst.base = (u_long)gbase + 1;
126 giosc->sc_bst.absm = amiga_bus_stride_2word;
127 LIST_INIT(&giosc->sc_comhdls);
128 giosd = gvpiodevs;
129
130 supa.supio_iot = &giosc->sc_bst;
131
132 gbase[0x041] = 0;
133 gbase[0x161 + 1*2] = 0;
134 gbase[0x261 + 1*2] = 0;
135 gbase[0x361 + 2*2] = 0;
136 gbase[0x461] = 0xd0;
137
138 while (giosd->name) {
139 supa.supio_name = giosd->name;
140 supa.supio_iobase = giosd->off;
141 supa.supio_arg = giosd->arg;
142 supa.supio_ipl = giosd->ipl;
143 config_found(self, &supa, gvpioprint); /* XXX */
144 ++giosd;
145 }
146 if (giosc->sc_comhdls.lh_first) {
147 /* XXX this should be really in the interupt stuff */
148 needpsl = PSL_S|PSL_IPL6;
149 if (amiga_serialspl < needpsl) {
150 printf("%s: raising amiga_serialspl from 0x%x to 0x%x\n",
151 giosc->sc_dev.dv_xname, amiga_serialspl, needpsl);
152 amiga_serialspl = needpsl;
153 }
154 giosc->sc_comisr.isr_intr = gvp_com_intr;
155 giosc->sc_comisr.isr_arg = giosc;
156 giosc->sc_comisr.isr_ipl = 6;
157 add_isr(&giosc->sc_comisr);
158 }
159 gbase[0x041] = 0x08;
160 }
161
162 int
163 gvpioprint(auxp, pnp)
164 void *auxp;
165 const char *pnp;
166 {
167 struct supio_attach_args *supa;
168 supa = auxp;
169
170 if (pnp == NULL)
171 return(QUIET);
172
173 printf("%s at %s port 0x%02x ipl %d",
174 supa->supio_name, pnp, supa->supio_iobase, supa->supio_ipl);
175
176 return(UNCONF);
177 }
178
179 void
180 gvp_com_intr_establish(self, p)
181 struct device *self;
182 struct gvpcom_int_hdl *p;
183 {
184 struct gvpio_softc *sc;
185
186 sc = (struct gvpio_softc *)self;
187 LIST_INSERT_HEAD(&sc->sc_comhdls, p, next);
188
189 }
190
191 int
192 gvp_com_intr(p)
193 void *p;
194 {
195 struct gvpio_softc *sc;
196 struct gvpcom_int_hdl *np;
197 volatile caddr_t cntr;
198
199 sc = (struct gvpio_softc *)p;
200
201 cntr = sc->sc_cntr;
202
203 if (!(*cntr & 0x2))
204 return (0);
205
206 *cntr &= ~0xa;
207
208 for (np = sc->sc_comhdls.lh_first; np != NULL;
209 np = np->next.le_next) {
210
211 (*np->f)(np->p);
212 }
213 *cntr |= 0x8;
214
215 return (1);
216 }
217