wdc_acafh.c revision 1.1 1 /* $NetBSD: wdc_acafh.c,v 1.1 2013/12/22 02:21:51 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 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: wdc_acafh.c,v 1.1 2013/12/22 02:21:51 rkujawa Exp $");
37
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/malloc.h>
42 #include <sys/device.h>
43 #include <sys/bus.h>
44
45 #include <machine/cpu.h>
46 #include <machine/intr.h>
47 #include <sys/bswap.h>
48
49 #include <amiga/amiga/cia.h>
50 #include <amiga/amiga/custom.h>
51 #include <amiga/amiga/device.h>
52 #include <amiga/amiga/gayle.h>
53 #include <amiga/dev/zbusvar.h>
54 #include <amiga/dev/acafhvar.h>
55
56 #include <dev/ata/atavar.h>
57 #include <dev/ic/wdcvar.h>
58
59 struct wdc_acafh_softc {
60 struct wdc_softc sc_wdcdev;
61 struct ata_channel *sc_chanlist[1];
62 struct ata_channel sc_channel;
63 struct ata_queue sc_chqueue;
64 struct wdc_regs sc_wdc_regs;
65 struct isr sc_isr;
66 volatile u_char *sc_intreg;
67 struct bus_space_tag cmd_iot;
68 struct bus_space_tag ctl_iot;
69 struct acafh_softc *aca_sc;
70 };
71
72 int wdc_acafh_match(device_t, cfdata_t, void *);
73 void wdc_acafh_attach(device_t, device_t, void *);
74 int wdc_acafh_intr(void *);
75
76 CFATTACH_DECL_NEW(wdc_acafh, sizeof(struct wdc_acafh_softc),
77 wdc_acafh_match, wdc_acafh_attach, NULL, NULL);
78
79 int
80 wdc_acafh_match(device_t parent, cfdata_t cfp, void *aux)
81 {
82 struct acafhbus_attach_args *aap = aux;
83
84 if (strcmp(aap->aaa_name, "wdc_acafh") != 0)
85 return(0);
86 return 1;
87 }
88
89 void
90 wdc_acafh_attach(device_t parent, device_t self, void *aux)
91 {
92 struct wdc_acafh_softc *sc = device_private(self);
93 struct wdc_regs *wdr;
94 int i;
95
96 aprint_normal("\n");
97 gayle_init();
98
99 sc->aca_sc = device_private(parent);
100
101 sc->sc_wdcdev.sc_atac.atac_dev = self;
102 sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs;
103
104 sc->cmd_iot.base = (u_long) ztwomap(0xda0000 + 2);
105 gayle_init();
106 sc->sc_intreg = &gayle.intreq;
107
108 sc->cmd_iot.absm = sc->ctl_iot.absm = &amiga_bus_stride_4swap;
109 wdr->cmd_iot = &sc->cmd_iot;
110 wdr->ctl_iot = &sc->ctl_iot;
111
112 if (bus_space_map(wdr->cmd_iot, 0, 0x40, 0,
113 &wdr->cmd_baseioh)) {
114 aprint_error_dev(self, "couldn't map registers\n");
115 return;
116 }
117
118 for (i = 0; i < WDC_NREG; i++) {
119 if (bus_space_subregion(wdr->cmd_iot,
120 wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
121 &wdr->cmd_iohs[i]) != 0) {
122
123 bus_space_unmap(wdr->cmd_iot,
124 wdr->cmd_baseioh, 0x40);
125 aprint_error_dev(self, "couldn't map registers\n");
126 return;
127 }
128 }
129
130 if (bus_space_subregion(wdr->cmd_iot,
131 wdr->cmd_baseioh, 0x406, 1, &wdr->ctl_ioh))
132 return;
133
134 sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16;
135 sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
136 sc->sc_chanlist[0] = &sc->sc_channel;
137 sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
138 sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
139 sc->sc_wdcdev.wdc_maxdrives = 2;
140 sc->sc_channel.ch_channel = 0;
141 sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
142 sc->sc_channel.ch_queue = &sc->sc_chqueue;
143
144 wdc_init_shadow_regs(&sc->sc_channel);
145
146 sc->sc_isr.isr_intr = wdc_acafh_intr;
147 sc->sc_isr.isr_arg = sc;
148 sc->sc_isr.isr_ipl = 2;
149 add_isr (&sc->sc_isr);
150
151 gayle.intena |= GAYLE_INT_IDE;
152
153 wdcattach(&sc->sc_channel);
154 }
155
156 int
157 wdc_acafh_intr(void *arg)
158 {
159 struct wdc_acafh_softc *sc = (struct wdc_acafh_softc *)arg;
160 int ret = 0;
161 u_char intreq = *sc->sc_intreg;
162
163 if (intreq & GAYLE_INT_IDE) {
164 /*
165 if (acafh_cf_intr_status(sc->aca_sc, 1) == 1)
166 aprint_normal_dev(sc->aca_sc->sc_dev, "intr at slot 1\n");
167 if (acafh_cf_intr_status(sc->aca_sc, 0) == 1)
168 aprint_normal_dev(sc->aca_sc->sc_dev, "intr at slot 0\n");
169 */
170 ret = wdcintr(&sc->sc_channel);
171 gayle.intreq = 0x7c | (intreq & 0x03);
172 }
173
174 return ret;
175 }
176
177