gvpio.c revision 1.6.4.1 1 /* $NetBSD: gvpio.c,v 1.6.4.1 2002/02/11 20:06:59 jdolecek 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.6.4.1 2002/02/11 20:06:59 jdolecek 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/conf.h>
50 #include <machine/intr.h>
51
52 #include <amiga/include/cpu.h>
53
54 #include <amiga/amiga/device.h>
55 #include <amiga/amiga/drcustom.h>
56
57 #include <amiga/dev/supio.h>
58 #include <amiga/dev/zbusvar.h>
59 #include <amiga/dev/gvpbusvar.h>
60
61 struct gvpio_softc {
62 struct device sc_dev;
63 struct bus_space_tag sc_bst;
64 caddr_t sc_cntr;
65 LIST_HEAD(, gvpcom_int_hdl) sc_comhdls;
66 struct isr sc_comisr;
67 };
68
69 int gvpiomatch(struct device *, struct cfdata *, void *);
70 void gvpioattach(struct device *, struct device *, void *);
71 int gvpioprint(void *auxp, const char *);
72 int gvp_com_intr(void *);
73 void gvp_com_intr_establish(struct device *, struct gvpcom_int_hdl *);
74
75 struct cfattach gvpio_ca = {
76 sizeof(struct gvpio_softc), gvpiomatch, gvpioattach
77 };
78
79 int
80 gvpiomatch(struct device *parent, struct cfdata *cfp, 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(struct device *parent, struct device *self, void *auxp)
107 {
108 struct gvpio_softc *giosc;
109 struct gvpio_devs *giosd;
110 struct gvpbus_args *gap;
111 struct supio_attach_args supa;
112 volatile caddr_t gbase;
113 u_int16_t needpsl;
114
115 giosc = (struct gvpio_softc *)self;
116 gap = auxp;
117
118 if (parent)
119 printf("\n");
120
121 gbase = gap->zargs.va;
122 giosc->sc_cntr = &gbase[0x41];
123 giosc->sc_bst.base = (u_long)gbase + 1;
124 giosc->sc_bst.absm = &amiga_bus_stride_2;
125 LIST_INIT(&giosc->sc_comhdls);
126 giosd = gvpiodevs;
127
128 supa.supio_iot = &giosc->sc_bst;
129
130 gbase[0x041] = 0;
131 gbase[0x161 + 1*2] = 0;
132 gbase[0x261 + 1*2] = 0;
133 gbase[0x361 + 2*2] = 0;
134 gbase[0x461] = 0xd0;
135
136 while (giosd->name) {
137 supa.supio_name = giosd->name;
138 supa.supio_iobase = giosd->off;
139 supa.supio_arg = giosd->arg;
140 supa.supio_ipl = giosd->ipl;
141 config_found(self, &supa, gvpioprint); /* XXX */
142 ++giosd;
143 }
144 if (giosc->sc_comhdls.lh_first) {
145 /* XXX this should be really in the interupt stuff */
146 needpsl = PSL_S|PSL_IPL6;
147 if (amiga_serialspl < needpsl) {
148 printf("%s: raising amiga_serialspl from 0x%x to 0x%x\n",
149 giosc->sc_dev.dv_xname, amiga_serialspl, needpsl);
150 amiga_serialspl = 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 printf("%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 caddr_t 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