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