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