wdc_acafh.c revision 1.3 1 /* $NetBSD: wdc_acafh.c,v 1.3 2014/01/03 00:33:06 rkujawa Exp $ */
2
3 /*-
4 * Copyright (c) 2000, 2003, 2013 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Radoslaw Kujawa.
9 *
10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Michael L. Hitch.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 /*
36 * ACA500 CF (IDE) controller driver.
37 *
38 * The hardware emulates original A600/A1200 Gayle interface. However, it has
39 * two channels, second channel placed instead of ctl registers (so software
40 * reset of the bus is not possible, duh). There are no slave devices.
41 */
42
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: wdc_acafh.c,v 1.3 2014/01/03 00:33:06 rkujawa Exp $");
45
46 #include <sys/types.h>
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/malloc.h>
50 #include <sys/device.h>
51 #include <sys/bus.h>
52
53 #include <machine/cpu.h>
54 #include <machine/intr.h>
55 #include <sys/bswap.h>
56
57 #include <amiga/amiga/cia.h>
58 #include <amiga/amiga/custom.h>
59 #include <amiga/amiga/device.h>
60 #include <amiga/amiga/gayle.h>
61 #include <amiga/dev/zbusvar.h>
62 #include <amiga/dev/acafhvar.h>
63 #include <amiga/dev/acafhreg.h>
64
65 #include <dev/ata/atavar.h>
66 #include <dev/ic/wdcvar.h>
67
68 #define WDC_ACAFH_SLOTS 2
69
70 struct wdc_acafh_slot {
71 struct ata_channel channel;
72 struct ata_queue chqueue;
73 struct wdc_regs wdr;
74 };
75
76 struct wdc_acafh_softc {
77 device_t sc_dev;
78
79 struct wdc_softc sc_wdcdev;
80 struct ata_channel *sc_chanlist[WDC_ACAFH_SLOTS];
81 struct wdc_acafh_slot sc_slots[WDC_ACAFH_SLOTS];
82
83 struct isr sc_isr;
84
85 struct bus_space_tag cmd_iot;
86
87 struct acafh_softc *aca_sc;
88 };
89
90 int wdc_acafh_match(device_t, cfdata_t, void *);
91 void wdc_acafh_attach(device_t, device_t, void *);
92 int wdc_acafh_intr(void *);
93 static void wdc_acafh_attach_channel(struct wdc_acafh_softc *, int);
94 static void wdc_acafh_map_channel(struct wdc_acafh_softc *, int);
95
96 CFATTACH_DECL_NEW(wdc_acafh, sizeof(struct wdc_acafh_softc),
97 wdc_acafh_match, wdc_acafh_attach, NULL, NULL);
98
99 int
100 wdc_acafh_match(device_t parent, cfdata_t cfp, void *aux)
101 {
102 struct acafhbus_attach_args *aap = aux;
103
104 if (strcmp(aap->aaa_name, "wdc_acafh") != 0)
105 return(0);
106 return 1;
107 }
108
109 void
110 wdc_acafh_attach(device_t parent, device_t self, void *aux)
111 {
112 struct wdc_acafh_softc *sc = device_private(self);
113 int i;
114
115 aprint_normal(": ACA500 CompactFlash interface\n");
116
117 sc->sc_dev = device_private(self);
118 sc->aca_sc = device_private(parent);
119
120 gayle_init();
121
122 /* XXX: take addr from attach args? */
123 sc->cmd_iot.base = (u_long) ztwomap(GAYLE_IDE_BASE + 2);
124 sc->cmd_iot.absm = &amiga_bus_stride_4swap;
125
126 sc->sc_wdcdev.sc_atac.atac_dev = self;
127 sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16;
128 sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
129 sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
130 sc->sc_wdcdev.sc_atac.atac_nchannels = WDC_ACAFH_SLOTS;
131 sc->sc_wdcdev.wdc_maxdrives = 2;
132 sc->sc_wdcdev.cap = WDC_CAPABILITY_NO_AUXCTL;
133
134 wdc_allocate_regs(&sc->sc_wdcdev);
135 for (i = 0; i < WDC_ACAFH_SLOTS; i++) {
136 wdc_acafh_attach_channel(sc, i);
137 }
138
139 sc->sc_isr.isr_intr = wdc_acafh_intr;
140 sc->sc_isr.isr_arg = sc;
141 sc->sc_isr.isr_ipl = 2;
142 add_isr (&sc->sc_isr);
143
144 gayle_intr_enable_set(GAYLE_INT_IDE);
145
146 }
147
148 void
149 wdc_acafh_attach_channel(struct wdc_acafh_softc *sc, int chnum)
150 {
151 sc->sc_chanlist[chnum] = &sc->sc_slots[chnum].channel;
152 memset(&sc->sc_slots[chnum],0,sizeof(struct wdc_acafh_slot));
153 sc->sc_slots[chnum].channel.ch_channel = chnum;
154 sc->sc_slots[chnum].channel.ch_atac = &sc->sc_wdcdev.sc_atac;
155 sc->sc_slots[chnum].channel.ch_queue = &sc->sc_slots[chnum].chqueue;
156
157 wdc_acafh_map_channel(sc, chnum);
158
159 wdc_init_shadow_regs(&sc->sc_slots[chnum].channel);
160 wdcattach(&sc->sc_slots[chnum].channel);
161
162 #ifdef WDC_ACAFH_DEBUG
163 aprint_normal_dev(sc->sc_dev, "done init for channel %d\n", chnum);
164 #endif /* WDC_ACAFH_DEBUG */
165
166 }
167
168 void
169 wdc_acafh_map_channel(struct wdc_acafh_softc *sc, int chnum)
170 {
171 struct wdc_regs *wdr;
172 int i;
173 bus_addr_t off;
174
175 wdr = CHAN_TO_WDC_REGS(&sc->sc_slots[chnum].channel);
176 wdr->cmd_iot = &sc->cmd_iot;
177
178 if (chnum == 0)
179 off = 0;
180 else
181 off = 0x400;
182
183 if (bus_space_map(wdr->cmd_iot, off, 0x40, 0,
184 &wdr->cmd_baseioh)) {
185 aprint_error_dev(sc->sc_dev, "couldn't map regs\n");
186 return;
187 }
188
189 for (i = 0; i < WDC_NREG; i++) {
190 if (bus_space_subregion(wdr->cmd_iot,
191 wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
192 &wdr->cmd_iohs[i]) != 0) {
193
194 bus_space_unmap(wdr->cmd_iot,
195 wdr->cmd_baseioh, 0x40);
196 aprint_error_dev(sc->sc_dev, "couldn't map regs\n");
197 return;
198 }
199 }
200
201 }
202
203 int
204 wdc_acafh_intr(void *arg)
205 {
206 struct wdc_acafh_softc *sc;
207 uint8_t intreq;
208 int ret;
209
210 sc = (struct wdc_acafh_softc *) arg;
211 intreq = gayle_intr_status();
212 ret = 0;
213
214 if (intreq & GAYLE_INT_IDE) {
215 if (acafh_cf_intr_status(sc->aca_sc, 1) == 1) {
216 ret = wdcintr(&sc->sc_slots[1].channel);
217 }
218 if (acafh_cf_intr_status(sc->aca_sc, 0) == 1) {
219 ret = wdcintr(&sc->sc_slots[0].channel);
220 }
221 gayle_intr_ack(0x7C | (intreq & GAYLE_INT_IDEACK));
222 }
223
224 return ret;
225 }
226
227