wdc_amiga.c revision 1.25.2.2 1 /* $NetBSD: wdc_amiga.c,v 1.25.2.2 2008/03/24 09:38:37 yamt 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.25.2.2 2008/03/24 09:38:37 yamt 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 <sys/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 ata_channel *sc_chanlist[1];
65 struct ata_channel sc_channel;
66 struct ata_queue sc_chqueue;
67 struct wdc_regs sc_wdc_regs;
68 struct isr sc_isr;
69 volatile u_char *sc_intreg;
70 struct bus_space_tag cmd_iot;
71 struct bus_space_tag ctl_iot;
72 char sc_a1200;
73 };
74
75 int wdc_amiga_probe(device_t, cfdata_t, void *);
76 void wdc_amiga_attach(device_t, device_t, void *);
77 int wdc_amiga_intr(void *);
78
79 CFATTACH_DECL_NEW(wdc_amiga, sizeof(struct wdc_amiga_softc),
80 wdc_amiga_probe, wdc_amiga_attach, NULL, NULL);
81
82 int
83 wdc_amiga_probe(device_t parent, cfdata_t cfp, void *aux)
84 {
85 if ((!is_a4000() && !is_a1200()) || !matchname(aux, "wdc"))
86 return(0);
87 return 1;
88 }
89
90 void
91 wdc_amiga_attach(device_t parent, device_t self, void *aux)
92 {
93 struct wdc_amiga_softc *sc = device_private(self);
94 struct wdc_regs *wdr;
95 int i;
96
97 aprint_normal("\n");
98
99 sc->sc_wdcdev.sc_atac.atac_dev = self;
100 sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs;
101
102 if (is_a4000()) {
103 sc->cmd_iot.base = (u_long)ztwomap(0xdd2020 + 2);
104 sc->sc_intreg = (volatile u_char *)ztwomap(0xdd2020 + 0x1000);
105 sc->sc_a1200 = 0;
106 } else {
107 sc->cmd_iot.base = (u_long) ztwomap(0xda0000 + 2);
108 gayle_init();
109 sc->sc_intreg = &gayle.intreq;
110 sc->sc_a1200 = 1;
111 }
112 sc->cmd_iot.absm = sc->ctl_iot.absm = &amiga_bus_stride_4swap;
113 wdr->cmd_iot = &sc->cmd_iot;
114 wdr->ctl_iot = &sc->ctl_iot;
115
116 if (bus_space_map(wdr->cmd_iot, 0, 0x40, 0,
117 &wdr->cmd_baseioh)) {
118 aprint_error_dev(self, "couldn't map registers\n");
119 return;
120 }
121
122 for (i = 0; i < WDC_NREG; i++) {
123 if (bus_space_subregion(wdr->cmd_iot,
124 wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
125 &wdr->cmd_iohs[i]) != 0) {
126
127 bus_space_unmap(wdr->cmd_iot,
128 wdr->cmd_baseioh, 0x40);
129 aprint_error_dev(self, "couldn't map registers\n");
130 return;
131 }
132 }
133
134 if (bus_space_subregion(wdr->cmd_iot,
135 wdr->cmd_baseioh, 0x406, 1, &wdr->ctl_ioh))
136 return;
137
138 sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16;
139 sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
140 sc->sc_chanlist[0] = &sc->sc_channel;
141 sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
142 sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
143 sc->sc_channel.ch_channel = 0;
144 sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
145 sc->sc_channel.ch_queue = &sc->sc_chqueue;
146 sc->sc_channel.ch_ndrive = 2;
147
148 wdc_init_shadow_regs(&sc->sc_channel);
149
150 sc->sc_isr.isr_intr = wdc_amiga_intr;
151 sc->sc_isr.isr_arg = sc;
152 sc->sc_isr.isr_ipl = 2;
153 add_isr (&sc->sc_isr);
154
155 if (sc->sc_a1200)
156 gayle.intena |= GAYLE_INT_IDE;
157
158 wdcattach(&sc->sc_channel);
159 }
160
161 int
162 wdc_amiga_intr(void *arg)
163 {
164 struct wdc_amiga_softc *sc = (struct wdc_amiga_softc *)arg;
165 u_char intreq = *sc->sc_intreg;
166 int ret = 0;
167
168 if (intreq & GAYLE_INT_IDE) {
169 if (sc->sc_a1200)
170 gayle.intreq = 0x7c | (intreq & 0x03);
171 ret = wdcintr(&sc->sc_channel);
172 }
173
174 return ret;
175 }
176