wdc_amiga.c revision 1.15 1 /* $NetBSD: wdc_amiga.c,v 1.15 2003/12/07 20:59:00 is Exp $ */
2
3 /*-
4 * Copyright (c) 2000, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Michael L. Hitch.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: wdc_amiga.c,v 1.15 2003/12/07 20:59:00 is Exp $");
41
42 #include <sys/types.h>
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/malloc.h>
46 #include <sys/device.h>
47
48 #include <machine/cpu.h>
49 #include <machine/bus.h>
50 #include <machine/intr.h>
51 #include <machine/bswap.h>
52
53 #include <amiga/amiga/cia.h>
54 #include <amiga/amiga/custom.h>
55 #include <amiga/amiga/device.h>
56 #include <amiga/amiga/gayle.h>
57 #include <amiga/dev/zbusvar.h>
58
59 #include <dev/ata/atavar.h>
60 #include <dev/ic/wdcvar.h>
61
62 struct wdc_amiga_softc {
63 struct wdc_softc sc_wdcdev;
64 struct channel_softc *wdc_chanptr;
65 struct channel_softc wdc_channel;
66 struct isr sc_isr;
67 volatile u_char *sc_intreg;
68 struct bus_space_tag cmd_iot;
69 struct bus_space_tag ctl_iot;
70 char sc_a1200;
71 };
72
73 int wdc_amiga_probe(struct device *, struct cfdata *, void *);
74 void wdc_amiga_attach(struct device *, struct device *, void *);
75 int wdc_amiga_intr(void *);
76
77 CFATTACH_DECL(wdc_amiga, sizeof(struct wdc_amiga_softc),
78 wdc_amiga_probe, wdc_amiga_attach, NULL, NULL);
79
80 int
81 wdc_amiga_probe(struct device *parent, struct cfdata *cfp, void *aux)
82 {
83 if ((!is_a4000() && !is_a1200()) || !matchname(aux, "wdc"))
84 return(0);
85 return 1;
86 }
87
88 void
89 wdc_amiga_attach(struct device *parent, struct device *self, void *aux)
90 {
91 struct wdc_amiga_softc *sc = (void *)self;
92 int i;
93
94 printf("\n");
95
96 if (is_a4000()) {
97 sc->cmd_iot.base = (u_long)ztwomap(0xdd2020 + 2);
98 sc->sc_intreg = (u_char *)ztwomap(0xdd2020 + 0x1000);
99 sc->sc_a1200 = 0;
100 } else {
101 sc->cmd_iot.base = (u_long) ztwomap(0xda0000 + 2);
102 sc->ctl_iot.base = (u_long) ztwomap(0xda4000);
103 gayle_init();
104 sc->sc_intreg = &gayle.intreq;
105 sc->sc_a1200 = 1;
106 }
107 sc->cmd_iot.absm = sc->ctl_iot.absm = &amiga_bus_stride_4swap;
108 sc->wdc_channel.cmd_iot = &sc->cmd_iot;
109 sc->wdc_channel.ctl_iot = &sc->ctl_iot;
110
111 if (bus_space_map(sc->wdc_channel.cmd_iot, 0, 0x40, 0,
112 &sc->wdc_channel.cmd_baseioh)) {
113 printf("%s: couldn't map registers\n",
114 sc->sc_wdcdev.sc_dev.dv_xname);
115 return;
116 }
117
118 for (i = 0; i < WDC_NREG; i++) {
119 if (bus_space_subregion(sc->wdc_channel.cmd_iot,
120 sc->wdc_channel.cmd_baseioh, i, i == 0 ? 4 : 1,
121 &sc->wdc_channel.cmd_iohs[i]) != 0) {
122
123 bus_space_unmap(sc->wdc_channel.cmd_iot,
124 sc->wdc_channel.cmd_baseioh, 0x40);
125 printf("%s: couldn't map registers\n",
126 sc->sc_wdcdev.sc_dev.dv_xname);
127 return;
128 }
129 }
130
131 if (sc->sc_a1200)
132 sc->wdc_channel.ctl_ioh = sc->ctl_iot.base;
133 else if (bus_space_subregion(sc->wdc_channel.cmd_iot,
134 sc->wdc_channel.cmd_baseioh, 0x406, 1, &sc->wdc_channel.ctl_ioh))
135 return;
136
137 sc->sc_wdcdev.cap = WDC_CAPABILITY_DATA16;
138 sc->sc_wdcdev.PIO_cap = 0;
139 sc->wdc_chanptr = &sc->wdc_channel;
140 sc->sc_wdcdev.channels = &sc->wdc_chanptr;
141 sc->sc_wdcdev.nchannels = 1;
142 sc->wdc_channel.channel = 0;
143 sc->wdc_channel.wdc = &sc->sc_wdcdev;
144 sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
145 M_DEVBUF, M_NOWAIT);
146 if (sc->wdc_channel.ch_queue == NULL) {
147 printf("%s: can't allocate memory for command queue",
148 sc->sc_wdcdev.sc_dev.dv_xname);
149 return;
150 }
151 sc->sc_isr.isr_intr = wdc_amiga_intr;
152 sc->sc_isr.isr_arg = sc;
153 sc->sc_isr.isr_ipl = 2;
154 add_isr (&sc->sc_isr);
155
156 if (sc->sc_a1200)
157 gayle.intena |= GAYLE_INT_IDE;
158
159 wdcattach(&sc->wdc_channel);
160 }
161
162 int
163 wdc_amiga_intr(void *arg)
164 {
165 struct wdc_amiga_softc *sc = (struct wdc_amiga_softc *)arg;
166 u_char intreq = *sc->sc_intreg;
167 int ret = 0;
168
169 if (intreq & GAYLE_INT_IDE) {
170 if (sc->sc_a1200)
171 gayle.intreq = 0x7c | (intreq & 0x03);
172 ret = wdcintr(&sc->wdc_channel);
173 }
174
175 return ret;
176 }
177