1 /* $NetBSD: gvpio.c,v 1.16 2007/03/04 05:59:20 christos Exp $ */
4 * Copyright (c) 1997 Ignatios Souvatzis
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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 $");
35 #include <sys/types.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>
56 struct bus_space_tag sc_bst
;
58 LIST_HEAD(, gvpcom_int_hdl
) sc_comhdls
;
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
);
72 gvpiomatch(struct device
*parent
, struct cfdata
*cfp
, void *auxp
)
75 struct gvpbus_args
*gap
;
79 if (gap
->flags
& GVP_IO
)
91 { "com", 0x0b0, 115200 * 16 * 4, 6 },
92 { "com", 0x130, 115200 * 16 * 4, 6 },
93 { "lpt", 0x1b0, 0, 2 },
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
;
107 giosc
= (struct gvpio_softc
*)self
;
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
);
120 supa
.supio_iot
= &giosc
->sc_bst
;
123 gbase
[0x161 + 1*2] = 0;
124 gbase
[0x261 + 1*2] = 0;
125 gbase
[0x361 + 2*2] = 0;
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 */
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
],
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
);
155 gvpioprint(void *auxp
, const char *pnp
)
157 struct supio_attach_args
*supa
;
163 aprint_normal("%s at %s port 0x%02x ipl %d",
164 supa
->supio_name
, pnp
, supa
->supio_iobase
, supa
->supio_ipl
);
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
;
186 sc
= (struct gvpio_softc
*)p
;
195 for (np
= sc
->sc_comhdls
.lh_first
; np
!= NULL
;
196 np
= np
->next
.le_next
) {