Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / amiga / dev / gvpio.c
blob818919892bf1bf54a7dacebbd4c32bbe85c301d3
1 /* $NetBSD: gvpio.c,v 1.16 2007/03/04 05:59:20 christos Exp $ */
3 /*
4 * Copyright (c) 1997 Ignatios Souvatzis
5 * All rights reserved.
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: gvpio.c,v 1.16 2007/03/04 05:59:20 christos Exp $");
32 * GVP I/O Extender
35 #include <sys/types.h>
37 #include <sys/conf.h>
38 #include <sys/device.h>
39 #include <sys/systm.h>
40 #include <sys/param.h>
42 #include <machine/bus.h>
43 #include <machine/intr.h>
45 #include <amiga/include/cpu.h>
47 #include <amiga/amiga/device.h>
48 #include <amiga/amiga/drcustom.h>
50 #include <amiga/dev/supio.h>
51 #include <amiga/dev/zbusvar.h>
52 #include <amiga/dev/gvpbusvar.h>
54 struct gvpio_softc {
55 struct device sc_dev;
56 struct bus_space_tag sc_bst;
57 void *sc_cntr;
58 LIST_HEAD(, gvpcom_int_hdl) sc_comhdls;
59 struct isr sc_comisr;
62 int gvpiomatch(struct device *, struct cfdata *, void *);
63 void gvpioattach(struct device *, struct device *, void *);
64 int gvpioprint(void *auxp, const char *);
65 int gvp_com_intr(void *);
66 void gvp_com_intr_establish(struct device *, struct gvpcom_int_hdl *);
68 CFATTACH_DECL(gvpio, sizeof(struct gvpio_softc),
69 gvpiomatch, gvpioattach, NULL, NULL);
71 int
72 gvpiomatch(struct device *parent, struct cfdata *cfp, void *auxp)
75 struct gvpbus_args *gap;
77 gap = auxp;
79 if (gap->flags & GVP_IO)
80 return (1);
82 return (0);
85 struct gvpio_devs {
86 char *name;
87 int off;
88 int arg;
89 int ipl;
90 } gvpiodevs[] = {
91 { "com", 0x0b0, 115200 * 16 * 4, 6 },
92 { "com", 0x130, 115200 * 16 * 4, 6 },
93 { "lpt", 0x1b0, 0, 2 },
94 { 0 }
97 void
98 gvpioattach(struct device *parent, struct device *self, void *auxp)
100 struct gvpio_softc *giosc;
101 struct gvpio_devs *giosd;
102 struct gvpbus_args *gap;
103 struct supio_attach_args supa;
104 volatile void *gbase;
105 u_int16_t needpsl;
107 giosc = (struct gvpio_softc *)self;
108 gap = auxp;
110 if (parent)
111 printf("\n");
113 gbase = gap->zargs.va;
114 giosc->sc_cntr = &gbase[0x41];
115 giosc->sc_bst.base = (u_long)gbase + 1;
116 giosc->sc_bst.absm = &amiga_bus_stride_2;
117 LIST_INIT(&giosc->sc_comhdls);
118 giosd = gvpiodevs;
120 supa.supio_iot = &giosc->sc_bst;
122 gbase[0x041] = 0;
123 gbase[0x161 + 1*2] = 0;
124 gbase[0x261 + 1*2] = 0;
125 gbase[0x361 + 2*2] = 0;
126 gbase[0x461] = 0xd0;
128 while (giosd->name) {
129 supa.supio_name = giosd->name;
130 supa.supio_iobase = giosd->off;
131 supa.supio_arg = giosd->arg;
132 supa.supio_ipl = giosd->ipl;
133 config_found(self, &supa, gvpioprint); /* XXX */
134 ++giosd;
136 if (giosc->sc_comhdls.lh_first) {
137 /* XXX this should be really in the interrupt stuff */
138 needpsl = PSL_S|PSL_IPL6;
139 if (ipl2spl_table[IPL_SERIAL] < needpsl) {
140 printf("%s: raising ipl2spl_table[IPL_SERIAL] "
141 "from 0x%x to 0x%x\n",
142 giosc->sc_dev.dv_xname, ipl2spl_table[IPL_SERIAL],
143 needpsl);
144 ipl2spl_table[IPL_SERIAL] = needpsl;
146 giosc->sc_comisr.isr_intr = gvp_com_intr;
147 giosc->sc_comisr.isr_arg = giosc;
148 giosc->sc_comisr.isr_ipl = 6;
149 add_isr(&giosc->sc_comisr);
151 gbase[0x041] = 0x08;
155 gvpioprint(void *auxp, const char *pnp)
157 struct supio_attach_args *supa;
158 supa = auxp;
160 if (pnp == NULL)
161 return(QUIET);
163 aprint_normal("%s at %s port 0x%02x ipl %d",
164 supa->supio_name, pnp, supa->supio_iobase, supa->supio_ipl);
166 return(UNCONF);
169 void
170 gvp_com_intr_establish(struct device *self, struct gvpcom_int_hdl *p)
172 struct gvpio_softc *sc;
174 sc = (struct gvpio_softc *)self;
175 LIST_INSERT_HEAD(&sc->sc_comhdls, p, next);
180 gvp_com_intr(void *p)
182 struct gvpio_softc *sc;
183 struct gvpcom_int_hdl *np;
184 volatile void *cntr;
186 sc = (struct gvpio_softc *)p;
188 cntr = sc->sc_cntr;
190 if (!(*cntr & 0x2))
191 return (0);
193 *cntr &= ~0xa;
195 for (np = sc->sc_comhdls.lh_first; np != NULL;
196 np = np->next.le_next) {
198 (*np->f)(np->p);
200 *cntr |= 0x8;
202 return (1);