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