wdc_obio.c revision 1.1.6.3 1 1.1.6.3 nathanw /* $NetBSD: wdc_obio.c,v 1.1.6.3 2002/10/18 02:38:31 nathanw Exp $ */
2 1.1.6.2 nathanw
3 1.1.6.2 nathanw /*
4 1.1.6.2 nathanw * Copyright (c) 2002 Takeshi Shibagaki All rights reserved.
5 1.1.6.2 nathanw *
6 1.1.6.2 nathanw * mac68k OBIO-IDE attachment created by Takeshi Shibagaki
7 1.1.6.2 nathanw *
8 1.1.6.2 nathanw * Redistribution and use in source and binary forms, with or without
9 1.1.6.2 nathanw * modification, are permitted provided that the following conditions
10 1.1.6.2 nathanw * are met:
11 1.1.6.2 nathanw * 1. Redistributions of source code must retain the above copyright
12 1.1.6.2 nathanw * notice, this list of conditions and the following disclaimer.
13 1.1.6.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.6.2 nathanw * notice, this list of conditions and the following disclaimer in the
15 1.1.6.2 nathanw * documentation and/or other materials provided with the distribution.
16 1.1.6.2 nathanw * 3. All advertising materials mentioning features or use of this software
17 1.1.6.2 nathanw * must display the following acknowledgement:
18 1.1.6.2 nathanw * This product includes software developed by Charles M. Hannum.
19 1.1.6.2 nathanw * 4. The name of the author may not be used to endorse or promote products
20 1.1.6.2 nathanw * derived from this software without specific prior written permission.
21 1.1.6.2 nathanw *
22 1.1.6.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1.6.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1.6.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1.6.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1.6.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1.6.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1.6.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1.6.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1.6.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1.6.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1.6.2 nathanw */
33 1.1.6.2 nathanw
34 1.1.6.2 nathanw #include <sys/types.h>
35 1.1.6.2 nathanw #include <sys/param.h>
36 1.1.6.2 nathanw #include <sys/systm.h>
37 1.1.6.2 nathanw #include <sys/device.h>
38 1.1.6.2 nathanw #include <sys/malloc.h>
39 1.1.6.2 nathanw #include <sys/kernel.h>
40 1.1.6.2 nathanw #include <sys/callout.h>
41 1.1.6.2 nathanw
42 1.1.6.2 nathanw #include <machine/bus.h>
43 1.1.6.2 nathanw #include <machine/intr.h>
44 1.1.6.2 nathanw #include <machine/cpu.h>
45 1.1.6.2 nathanw #include <machine/viareg.h>
46 1.1.6.2 nathanw
47 1.1.6.2 nathanw #include <mac68k/obio/obiovar.h>
48 1.1.6.2 nathanw
49 1.1.6.2 nathanw #include <dev/ata/atavar.h>
50 1.1.6.2 nathanw #include <dev/ic/wdcvar.h>
51 1.1.6.2 nathanw
52 1.1.6.2 nathanw #define WDC_OBIO_REG_NPORTS (8<<3)
53 1.1.6.2 nathanw #define WDC_OBIO_AUXREG_OFFSET 0x38
54 1.1.6.2 nathanw #define WDC_OBIO_AUXREG_NPORTS 1
55 1.1.6.2 nathanw #define WDC_OBIO_ISR_OFFSET 0x101
56 1.1.6.2 nathanw #define WDC_OBIO_ISR_NPORTS 1
57 1.1.6.2 nathanw
58 1.1.6.2 nathanw static u_long IDEBase = 0x50f1a000;
59 1.1.6.2 nathanw
60 1.1.6.2 nathanw /*
61 1.1.6.2 nathanw * XXX This code currently doesn't even try to allow 32-bit data port use.
62 1.1.6.2 nathanw */
63 1.1.6.2 nathanw
64 1.1.6.2 nathanw struct wdc_obio_softc {
65 1.1.6.2 nathanw struct wdc_softc sc_wdcdev;
66 1.1.6.2 nathanw struct channel_softc *wdc_chanptr;
67 1.1.6.2 nathanw struct channel_softc wdc_channel;
68 1.1.6.2 nathanw void *sc_ih;
69 1.1.6.2 nathanw };
70 1.1.6.2 nathanw
71 1.1.6.2 nathanw int wdc_obio_match __P((struct device *, struct cfdata *, void *));
72 1.1.6.2 nathanw void wdc_obio_attach __P((struct device *, struct device *, void *));
73 1.1.6.2 nathanw void wdc_obio_intr __P((void *));
74 1.1.6.2 nathanw void mac68k_bsh_wdc_set_stride __P((bus_space_tag_t t,
75 1.1.6.2 nathanw bus_space_handle_t *h, int stride));
76 1.1.6.2 nathanw u_int16_t mac68k_bsr2_wdc_gen __P((bus_space_tag_t t,
77 1.1.6.2 nathanw bus_space_handle_t *bsh, bus_size_t offset));
78 1.1.6.2 nathanw
79 1.1.6.3 nathanw CFATTACH_DECL(wdc_obio, sizeof(struct wdc_obio_softc),
80 1.1.6.3 nathanw wdc_obio_match, wdc_obio_attach, NULL, NULL);
81 1.1.6.2 nathanw
82 1.1.6.2 nathanw int
83 1.1.6.2 nathanw wdc_obio_match(parent, match, aux)
84 1.1.6.2 nathanw struct device *parent;
85 1.1.6.2 nathanw struct cfdata *match;
86 1.1.6.2 nathanw void *aux;
87 1.1.6.2 nathanw {
88 1.1.6.2 nathanw struct obio_attach_args *oa = (struct obio_attach_args *) aux;
89 1.1.6.2 nathanw struct channel_softc ch;
90 1.1.6.2 nathanw static int wdc_matched = 0;
91 1.1.6.2 nathanw int result = 0;
92 1.1.6.2 nathanw
93 1.1.6.2 nathanw memset(&ch, 0, sizeof(ch));
94 1.1.6.2 nathanw
95 1.1.6.2 nathanw switch (current_mac_model->machineid) {
96 1.1.6.2 nathanw case MACH_MACPB150:
97 1.1.6.2 nathanw case MACH_MACPB190:
98 1.1.6.2 nathanw case MACH_MACPB190CS:
99 1.1.6.2 nathanw case MACH_MACP580:
100 1.1.6.2 nathanw case MACH_MACQ630:
101 1.1.6.2 nathanw ch.cmd_iot = ch.ctl_iot = oa->oa_tag;
102 1.1.6.2 nathanw
103 1.1.6.2 nathanw if (bus_space_map(ch.cmd_iot, IDEBase, WDC_OBIO_REG_NPORTS,
104 1.1.6.2 nathanw 0, &ch.cmd_ioh))
105 1.1.6.2 nathanw return 0;
106 1.1.6.2 nathanw
107 1.1.6.2 nathanw mac68k_bsh_wdc_set_stride(ch.cmd_iot, &ch.cmd_ioh, 4);
108 1.1.6.2 nathanw
109 1.1.6.2 nathanw if (bus_space_subregion(ch.cmd_iot, ch.cmd_ioh,
110 1.1.6.2 nathanw WDC_OBIO_AUXREG_OFFSET,
111 1.1.6.2 nathanw WDC_OBIO_AUXREG_NPORTS, &ch.ctl_ioh))
112 1.1.6.2 nathanw return 0;
113 1.1.6.2 nathanw
114 1.1.6.2 nathanw result = wdcprobe(&ch);
115 1.1.6.2 nathanw
116 1.1.6.2 nathanw bus_space_unmap(ch.cmd_iot, ch.cmd_ioh, WDC_OBIO_REG_NPORTS);
117 1.1.6.2 nathanw
118 1.1.6.2 nathanw if (result)
119 1.1.6.2 nathanw wdc_matched = 1;
120 1.1.6.2 nathanw return (result);
121 1.1.6.2 nathanw }
122 1.1.6.2 nathanw return 0;
123 1.1.6.2 nathanw }
124 1.1.6.2 nathanw
125 1.1.6.2 nathanw static bus_space_tag_t wdc_obio_isr_tag;
126 1.1.6.2 nathanw static bus_space_handle_t wdc_obio_isr_hdl;
127 1.1.6.2 nathanw static struct channel_softc *ch_sc = NULL;
128 1.1.6.2 nathanw
129 1.1.6.2 nathanw void
130 1.1.6.2 nathanw wdc_obio_intr(arg)
131 1.1.6.2 nathanw void *arg;
132 1.1.6.2 nathanw {
133 1.1.6.2 nathanw unsigned char status;
134 1.1.6.2 nathanw
135 1.1.6.2 nathanw status = bus_space_read_1(wdc_obio_isr_tag,
136 1.1.6.2 nathanw wdc_obio_isr_hdl, 0);
137 1.1.6.2 nathanw if (status & 0x20) {
138 1.1.6.2 nathanw wdcintr(ch_sc);
139 1.1.6.2 nathanw bus_space_write_1(wdc_obio_isr_tag,
140 1.1.6.2 nathanw wdc_obio_isr_hdl, 0, status&~0x20);
141 1.1.6.2 nathanw }
142 1.1.6.2 nathanw }
143 1.1.6.2 nathanw
144 1.1.6.2 nathanw void
145 1.1.6.2 nathanw wdc_obio_attach(parent, self, aux)
146 1.1.6.2 nathanw struct device *parent;
147 1.1.6.2 nathanw struct device *self;
148 1.1.6.2 nathanw void *aux;
149 1.1.6.2 nathanw {
150 1.1.6.2 nathanw struct wdc_obio_softc *sc = (void *)self;
151 1.1.6.2 nathanw struct obio_attach_args *oa = aux;
152 1.1.6.2 nathanw struct channel_softc *chp = &sc->wdc_channel;
153 1.1.6.2 nathanw
154 1.1.6.2 nathanw oa->oa_addr = IDEBase;
155 1.1.6.2 nathanw sc->wdc_channel.cmd_iot = sc->wdc_channel.ctl_iot = oa->oa_tag;
156 1.1.6.2 nathanw
157 1.1.6.2 nathanw if (bus_space_map(sc->wdc_channel.cmd_iot, oa->oa_addr,
158 1.1.6.2 nathanw WDC_OBIO_REG_NPORTS, 0, &sc->wdc_channel.cmd_ioh)) {
159 1.1.6.2 nathanw printf("%s: couldn't map registers\n",
160 1.1.6.2 nathanw sc->sc_wdcdev.sc_dev.dv_xname);
161 1.1.6.2 nathanw return;
162 1.1.6.2 nathanw }
163 1.1.6.2 nathanw
164 1.1.6.2 nathanw mac68k_bsh_wdc_set_stride(sc->wdc_channel.cmd_iot,
165 1.1.6.2 nathanw &sc->wdc_channel.cmd_ioh, 4);
166 1.1.6.2 nathanw
167 1.1.6.2 nathanw if (bus_space_subregion(sc->wdc_channel.cmd_iot,
168 1.1.6.2 nathanw sc->wdc_channel.cmd_ioh, WDC_OBIO_AUXREG_OFFSET,
169 1.1.6.2 nathanw WDC_OBIO_AUXREG_NPORTS,
170 1.1.6.2 nathanw &sc->wdc_channel.ctl_ioh))
171 1.1.6.2 nathanw return;
172 1.1.6.2 nathanw
173 1.1.6.2 nathanw wdc_obio_isr_tag = oa->oa_tag;
174 1.1.6.2 nathanw
175 1.1.6.2 nathanw if (bus_space_map(wdc_obio_isr_tag,
176 1.1.6.2 nathanw oa->oa_addr+WDC_OBIO_ISR_OFFSET,
177 1.1.6.2 nathanw WDC_OBIO_ISR_NPORTS, 0, &wdc_obio_isr_hdl)) {
178 1.1.6.2 nathanw printf("%s: couldn't map intr status register\n",
179 1.1.6.2 nathanw sc->sc_wdcdev.sc_dev.dv_xname);
180 1.1.6.2 nathanw return;
181 1.1.6.2 nathanw }
182 1.1.6.2 nathanw
183 1.1.6.2 nathanw switch (current_mac_model->machineid) {
184 1.1.6.2 nathanw case MACH_MACP580:
185 1.1.6.2 nathanw case MACH_MACQ630:
186 1.1.6.2 nathanw /*
187 1.1.6.2 nathanw * Quadra/Performa IDE generates pseudo Nubus intr at slot F
188 1.1.6.2 nathanw */
189 1.1.6.2 nathanw printf(" (Quadra/Performa series IDE interface)");
190 1.1.6.2 nathanw
191 1.1.6.2 nathanw add_nubus_intr(0xf, (void (*)(void*))wdc_obio_intr, (void *)sc);
192 1.1.6.2 nathanw
193 1.1.6.2 nathanw break;
194 1.1.6.2 nathanw case MACH_MACPB150:
195 1.1.6.2 nathanw case MACH_MACPB190:
196 1.1.6.2 nathanw case MACH_MACPB190CS:
197 1.1.6.2 nathanw /*
198 1.1.6.2 nathanw * PowerBook IDE generates pseudo NuBus intr at slot C
199 1.1.6.2 nathanw */
200 1.1.6.2 nathanw printf(" (PowerBook series IDE interface)");
201 1.1.6.2 nathanw
202 1.1.6.2 nathanw add_nubus_intr(0xc, (void (*)(void*))wdc_obio_intr, (void *)sc);
203 1.1.6.2 nathanw
204 1.1.6.2 nathanw break;
205 1.1.6.2 nathanw }
206 1.1.6.2 nathanw
207 1.1.6.2 nathanw ch_sc = chp;
208 1.1.6.2 nathanw if (sc->sc_wdcdev.sc_dev.dv_cfdata->cf_flags & WDC_CAPABILITY_NOIRQ)
209 1.1.6.2 nathanw sc->sc_wdcdev.cap |= WDC_CAPABILITY_NOIRQ;
210 1.1.6.2 nathanw sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
211 1.1.6.2 nathanw sc->sc_wdcdev.PIO_cap = 0;
212 1.1.6.2 nathanw sc->wdc_chanptr = chp;
213 1.1.6.2 nathanw sc->sc_wdcdev.channels = &sc->wdc_chanptr;
214 1.1.6.2 nathanw sc->sc_wdcdev.nchannels = 1;
215 1.1.6.2 nathanw chp->channel = 0;
216 1.1.6.2 nathanw chp->wdc = &sc->sc_wdcdev;
217 1.1.6.2 nathanw chp->ch_queue = malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
218 1.1.6.2 nathanw
219 1.1.6.2 nathanw if (chp->ch_queue == NULL) {
220 1.1.6.2 nathanw printf("%s: can't allocate memory for command queue",
221 1.1.6.2 nathanw sc->sc_wdcdev.sc_dev.dv_xname);
222 1.1.6.2 nathanw return;
223 1.1.6.2 nathanw }
224 1.1.6.2 nathanw
225 1.1.6.2 nathanw printf("\n");
226 1.1.6.2 nathanw
227 1.1.6.2 nathanw wdcattach(chp);
228 1.1.6.2 nathanw }
229 1.1.6.2 nathanw
230 1.1.6.2 nathanw u_int16_t
231 1.1.6.2 nathanw mac68k_bsr2_wdc_gen(bus_space_tag_t t, bus_space_handle_t *bsh, bus_size_t offset)
232 1.1.6.2 nathanw {
233 1.1.6.2 nathanw return (*(volatile u_int16_t *) (bsh->base + offset * bsh->stride));
234 1.1.6.2 nathanw }
235 1.1.6.2 nathanw
236 1.1.6.2 nathanw void
237 1.1.6.2 nathanw mac68k_bsh_wdc_set_stride(bus_space_tag_t t, bus_space_handle_t *h, int stride)
238 1.1.6.2 nathanw {
239 1.1.6.2 nathanw h->stride = stride;
240 1.1.6.2 nathanw h->bsr1 = mac68k_bsr1_gen;
241 1.1.6.2 nathanw h->bsr2 = mac68k_bsr2_wdc_gen;
242 1.1.6.2 nathanw h->bsr4 = mac68k_bsr4_gen;
243 1.1.6.2 nathanw h->bsrs2 = mac68k_bsrs2_gen;
244 1.1.6.2 nathanw h->bsrs4 = mac68k_bsrs4_gen;
245 1.1.6.2 nathanw h->bsrm1 = mac68k_bsrm1_gen;
246 1.1.6.2 nathanw h->bsrm2 = mac68k_bsrm2_swap;
247 1.1.6.2 nathanw h->bsrm4 = mac68k_bsrm4_swap;
248 1.1.6.2 nathanw h->bsrms2 = mac68k_bsrm2;
249 1.1.6.2 nathanw h->bsrms4 = mac68k_bsrm4;
250 1.1.6.2 nathanw h->bsrr1 = mac68k_bsrr1_gen;
251 1.1.6.2 nathanw h->bsrr2 = mac68k_bsrr2_gen;
252 1.1.6.2 nathanw h->bsrr4 = mac68k_bsrr4_gen;
253 1.1.6.2 nathanw h->bsrrs2 = mac68k_bsrrs2_gen;
254 1.1.6.2 nathanw h->bsrrs4 = mac68k_bsrrs4_gen;
255 1.1.6.2 nathanw h->bsw1 = mac68k_bsw1_gen;
256 1.1.6.2 nathanw h->bsw2 = mac68k_bsw2_gen;
257 1.1.6.2 nathanw h->bsw4 = mac68k_bsw4_gen;
258 1.1.6.2 nathanw h->bsws2 = mac68k_bsws2_gen;
259 1.1.6.2 nathanw h->bsws4 = mac68k_bsws4_gen;
260 1.1.6.2 nathanw h->bswm2 = mac68k_bswm2_swap;
261 1.1.6.2 nathanw h->bswm4 = mac68k_bswm4_swap;
262 1.1.6.2 nathanw h->bswms2 = mac68k_bswm2;
263 1.1.6.2 nathanw h->bswms4 = mac68k_bswm4;
264 1.1.6.2 nathanw h->bswr1 = mac68k_bswr1_gen;
265 1.1.6.2 nathanw h->bswr2 = mac68k_bswr2_gen;
266 1.1.6.2 nathanw h->bswr4 = mac68k_bswr4_gen;
267 1.1.6.2 nathanw h->bswrs2 = mac68k_bswrs2_gen;
268 1.1.6.2 nathanw h->bswrs4 = mac68k_bswrs4_gen;
269 1.1.6.2 nathanw h->bssm1 = mac68k_bssm1_gen;
270 1.1.6.2 nathanw h->bssm2 = mac68k_bssm2_gen;
271 1.1.6.2 nathanw h->bssm4 = mac68k_bssm4_gen;
272 1.1.6.2 nathanw h->bssr1 = mac68k_bssr1_gen;
273 1.1.6.2 nathanw h->bssr2 = mac68k_bssr2_gen;
274 1.1.6.2 nathanw h->bssr4 = mac68k_bssr4_gen;
275 1.1.6.2 nathanw }
276