wdc_acafh.c revision 1.5 1 /* $NetBSD: wdc_acafh.c,v 1.5 2017/10/07 16:05:31 jdolecek 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.5 2017/10/07 16:05:31 jdolecek 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 wdc_regs wdr;
73 };
74
75 struct wdc_acafh_softc {
76 struct wdc_softc sc_wdcdev;
77 struct ata_channel *sc_chanlist[WDC_ACAFH_SLOTS];
78 struct wdc_acafh_slot sc_slots[WDC_ACAFH_SLOTS];
79
80 struct isr sc_isr;
81
82 struct bus_space_tag cmd_iot;
83
84 struct acafh_softc *aca_sc;
85 };
86
87 int wdc_acafh_match(device_t, cfdata_t, void *);
88 void wdc_acafh_attach(device_t, device_t, void *);
89 int wdc_acafh_intr(void *);
90 static void wdc_acafh_attach_channel(struct wdc_acafh_softc *, int);
91 static void wdc_acafh_map_channel(struct wdc_acafh_softc *, int);
92
93 CFATTACH_DECL_NEW(wdc_acafh, sizeof(struct wdc_acafh_softc),
94 wdc_acafh_match, wdc_acafh_attach, NULL, NULL);
95
96 int
97 wdc_acafh_match(device_t parent, cfdata_t cfp, void *aux)
98 {
99 struct acafhbus_attach_args *aap = aux;
100
101 if (strcmp(aap->aaa_name, "wdc_acafh") != 0)
102 return(0);
103 return 1;
104 }
105
106 void
107 wdc_acafh_attach(device_t parent, device_t self, void *aux)
108 {
109 struct wdc_acafh_softc *sc = device_private(self);
110 int i;
111
112 aprint_normal(": ACA500 CompactFlash interface\n");
113 sc->aca_sc = device_private(parent);
114
115 gayle_init();
116
117 /* XXX: take addr from attach args? */
118 sc->cmd_iot.base = (u_long) ztwomap(GAYLE_IDE_BASE + 2);
119 sc->cmd_iot.absm = &amiga_bus_stride_4swap;
120
121 sc->sc_wdcdev.sc_atac.atac_dev = self;
122 sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16;
123 sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
124 sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
125 sc->sc_wdcdev.sc_atac.atac_nchannels = WDC_ACAFH_SLOTS;
126 sc->sc_wdcdev.wdc_maxdrives = 2;
127 sc->sc_wdcdev.cap = WDC_CAPABILITY_NO_AUXCTL;
128
129 wdc_allocate_regs(&sc->sc_wdcdev);
130 for (i = 0; i < WDC_ACAFH_SLOTS; i++) {
131 wdc_acafh_attach_channel(sc, i);
132 }
133
134 sc->sc_isr.isr_intr = wdc_acafh_intr;
135 sc->sc_isr.isr_arg = sc;
136 sc->sc_isr.isr_ipl = 2;
137 add_isr (&sc->sc_isr);
138
139 gayle_intr_enable_set(GAYLE_INT_IDE);
140
141 }
142
143 void
144 wdc_acafh_attach_channel(struct wdc_acafh_softc *sc, int chnum)
145 {
146 #ifdef WDC_ACAFH_DEBUG
147 device_t self;
148
149 self = sc->sc_wdcdev.sc_atac.atac_dev;
150 #endif /* WDC_ACAFH_DEBUG */
151
152 sc->sc_chanlist[chnum] = &sc->sc_slots[chnum].channel;
153 memset(&sc->sc_slots[chnum],0,sizeof(struct wdc_acafh_slot));
154 sc->sc_slots[chnum].channel.ch_channel = chnum;
155 sc->sc_slots[chnum].channel.ch_atac = &sc->sc_wdcdev.sc_atac;
156 sc->sc_slots[chnum].channel.ch_queue = ata_queue_alloc(1);
157
158 wdc_acafh_map_channel(sc, chnum);
159
160 wdc_init_shadow_regs(CHAN_TO_WDC_REGS(&sc->sc_slots[chnum].channel));
161 wdcattach(&sc->sc_slots[chnum].channel);
162
163 #ifdef WDC_ACAFH_DEBUG
164 aprint_normal_dev(self, "done init for channel %d\n", chnum);
165 #endif /* WDC_ACAFH_DEBUG */
166 }
167
168 void
169 wdc_acafh_map_channel(struct wdc_acafh_softc *sc, int chnum)
170 {
171 struct wdc_regs *wdr;
172 bus_addr_t off;
173 device_t self;
174 int i;
175
176 self = sc->sc_wdcdev.sc_atac.atac_dev;
177
178 wdr = CHAN_TO_WDC_REGS(&sc->sc_slots[chnum].channel);
179 wdr->cmd_iot = &sc->cmd_iot;
180
181 if (chnum == 0)
182 off = 0;
183 else
184 off = 0x400;
185
186 if (bus_space_map(wdr->cmd_iot, off, 0x40, 0,
187 &wdr->cmd_baseioh)) {
188 aprint_error_dev(self, "couldn't map regs\n");
189 return;
190 }
191
192 for (i = 0; i < WDC_NREG; i++) {
193 if (bus_space_subregion(wdr->cmd_iot,
194 wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
195 &wdr->cmd_iohs[i]) != 0) {
196
197 bus_space_unmap(wdr->cmd_iot,
198 wdr->cmd_baseioh, 0x40);
199 aprint_error_dev(self, "couldn't map regs\n");
200 return;
201 }
202 }
203
204 }
205
206 int
207 wdc_acafh_intr(void *arg)
208 {
209 struct wdc_acafh_softc *sc;
210 uint8_t intreq;
211 int ret;
212
213 sc = (struct wdc_acafh_softc *) arg;
214 intreq = gayle_intr_status();
215 ret = 0;
216
217 if (intreq & GAYLE_INT_IDE) {
218 if (acafh_cf_intr_status(sc->aca_sc, 1) == 1) {
219 ret = wdcintr(&sc->sc_slots[1].channel);
220 }
221 if (acafh_cf_intr_status(sc->aca_sc, 0) == 1) {
222 ret = wdcintr(&sc->sc_slots[0].channel);
223 }
224 gayle_intr_ack(0x7C | (intreq & GAYLE_INT_IDEACK));
225 }
226
227 return ret;
228 }
229
230