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