wdc_amiga.c revision 1.6.8.2 1 1.6.8.2 nathanw /* $NetBSD: wdc_amiga.c,v 1.6.8.2 2002/02/28 04:07:02 nathanw Exp $ */
2 1.6.8.2 nathanw
3 1.6.8.2 nathanw /*-
4 1.6.8.2 nathanw * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.6.8.2 nathanw * All rights reserved.
6 1.6.8.2 nathanw *
7 1.6.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.6.8.2 nathanw * by Michael L. Hitch.
9 1.6.8.2 nathanw *
10 1.6.8.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.6.8.2 nathanw * modification, are permitted provided that the following conditions
12 1.6.8.2 nathanw * are met:
13 1.6.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.6.8.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.6.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.6.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.6.8.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.6.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.6.8.2 nathanw * must display the following acknowledgement:
20 1.6.8.2 nathanw * This product includes software developed by the NetBSD
21 1.6.8.2 nathanw * Foundation, Inc. and its contributors.
22 1.6.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.6.8.2 nathanw * contributors may be used to endorse or promote products derived
24 1.6.8.2 nathanw * from this software without specific prior written permission.
25 1.6.8.2 nathanw *
26 1.6.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.6.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.6.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.6.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.6.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.6.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.6.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.6.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.6.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.6.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.6.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.6.8.2 nathanw */
38 1.6.8.2 nathanw
39 1.6.8.2 nathanw #include <sys/cdefs.h>
40 1.6.8.2 nathanw __KERNEL_RCSID(0, "$NetBSD: wdc_amiga.c,v 1.6.8.2 2002/02/28 04:07:02 nathanw Exp $");
41 1.6.8.2 nathanw
42 1.6.8.2 nathanw #include <sys/types.h>
43 1.6.8.2 nathanw #include <sys/param.h>
44 1.6.8.2 nathanw #include <sys/systm.h>
45 1.6.8.2 nathanw #include <sys/malloc.h>
46 1.6.8.2 nathanw #include <sys/device.h>
47 1.6.8.2 nathanw
48 1.6.8.2 nathanw #include <machine/cpu.h>
49 1.6.8.2 nathanw #include <machine/bus.h>
50 1.6.8.2 nathanw #include <machine/intr.h>
51 1.6.8.2 nathanw #include <machine/bswap.h>
52 1.6.8.2 nathanw
53 1.6.8.2 nathanw #include <amiga/amiga/cia.h>
54 1.6.8.2 nathanw #include <amiga/amiga/custom.h>
55 1.6.8.2 nathanw #include <amiga/amiga/device.h>
56 1.6.8.2 nathanw #include <amiga/amiga/gayle.h>
57 1.6.8.2 nathanw #include <amiga/dev/zbusvar.h>
58 1.6.8.2 nathanw
59 1.6.8.2 nathanw #include <dev/ata/atavar.h>
60 1.6.8.2 nathanw #include <dev/ic/wdcvar.h>
61 1.6.8.2 nathanw
62 1.6.8.2 nathanw struct wdc_amiga_softc {
63 1.6.8.2 nathanw struct wdc_softc sc_wdcdev;
64 1.6.8.2 nathanw struct channel_softc *wdc_chanptr;
65 1.6.8.2 nathanw struct channel_softc wdc_channel;
66 1.6.8.2 nathanw struct isr sc_isr;
67 1.6.8.2 nathanw volatile u_char *sc_intreg;
68 1.6.8.2 nathanw struct bus_space_tag cmd_iot;
69 1.6.8.2 nathanw struct bus_space_tag ctl_iot;
70 1.6.8.2 nathanw char sc_a1200;
71 1.6.8.2 nathanw };
72 1.6.8.2 nathanw
73 1.6.8.2 nathanw int wdc_amiga_probe(struct device *, struct cfdata *, void *);
74 1.6.8.2 nathanw void wdc_amiga_attach(struct device *, struct device *, void *);
75 1.6.8.2 nathanw int wdc_amiga_intr(void *);
76 1.6.8.2 nathanw
77 1.6.8.2 nathanw struct cfattach wdc_amiga_ca = {
78 1.6.8.2 nathanw sizeof(struct wdc_amiga_softc), wdc_amiga_probe, wdc_amiga_attach
79 1.6.8.2 nathanw };
80 1.6.8.2 nathanw
81 1.6.8.2 nathanw int
82 1.6.8.2 nathanw wdc_amiga_probe(struct device *parent, struct cfdata *cfp, void *aux)
83 1.6.8.2 nathanw {
84 1.6.8.2 nathanw if ((!is_a4000() && !is_a1200()) || !matchname(aux, "wdc"))
85 1.6.8.2 nathanw return(0);
86 1.6.8.2 nathanw return 1;
87 1.6.8.2 nathanw }
88 1.6.8.2 nathanw
89 1.6.8.2 nathanw void
90 1.6.8.2 nathanw wdc_amiga_attach(struct device *parent, struct device *self, void *aux)
91 1.6.8.2 nathanw {
92 1.6.8.2 nathanw struct wdc_amiga_softc *sc = (void *)self;
93 1.6.8.2 nathanw
94 1.6.8.2 nathanw printf("\n");
95 1.6.8.2 nathanw
96 1.6.8.2 nathanw if (is_a4000()) {
97 1.6.8.2 nathanw sc->cmd_iot.base = (u_long)ztwomap(0xdd2020 + 2);
98 1.6.8.2 nathanw sc->sc_intreg = (u_char *)ztwomap(0xdd2020 + 0x1000);
99 1.6.8.2 nathanw sc->sc_a1200 = 0;
100 1.6.8.2 nathanw } else {
101 1.6.8.2 nathanw sc->cmd_iot.base = (u_long) ztwomap(0xda0000 + 2);
102 1.6.8.2 nathanw sc->ctl_iot.base = (u_long) ztwomap(0xda4000);
103 1.6.8.2 nathanw gayle_init();
104 1.6.8.2 nathanw sc->sc_intreg = &gayle.intreq;
105 1.6.8.2 nathanw sc->sc_a1200 = 1;
106 1.6.8.2 nathanw }
107 1.6.8.2 nathanw sc->cmd_iot.absm = sc->ctl_iot.absm = &amiga_bus_stride_4swap;
108 1.6.8.2 nathanw sc->wdc_channel.cmd_iot = &sc->cmd_iot;
109 1.6.8.2 nathanw sc->wdc_channel.ctl_iot = &sc->ctl_iot;
110 1.6.8.2 nathanw
111 1.6.8.2 nathanw if (bus_space_map(sc->wdc_channel.cmd_iot, 0, 0x40, 0,
112 1.6.8.2 nathanw &sc->wdc_channel.cmd_ioh)) {
113 1.6.8.2 nathanw printf("%s: couldn't map registers\n",
114 1.6.8.2 nathanw sc->sc_wdcdev.sc_dev.dv_xname);
115 1.6.8.2 nathanw return;
116 1.6.8.2 nathanw }
117 1.6.8.2 nathanw
118 1.6.8.2 nathanw if (sc->sc_a1200)
119 1.6.8.2 nathanw sc->wdc_channel.ctl_ioh = sc->ctl_iot.base;
120 1.6.8.2 nathanw else if (bus_space_subregion(sc->wdc_channel.cmd_iot,
121 1.6.8.2 nathanw sc->wdc_channel.cmd_ioh, 0x406, 1, &sc->wdc_channel.ctl_ioh))
122 1.6.8.2 nathanw return;
123 1.6.8.2 nathanw
124 1.6.8.2 nathanw sc->sc_wdcdev.cap = WDC_CAPABILITY_DATA16;
125 1.6.8.2 nathanw sc->sc_wdcdev.PIO_cap = 0;
126 1.6.8.2 nathanw sc->wdc_chanptr = &sc->wdc_channel;
127 1.6.8.2 nathanw sc->sc_wdcdev.channels = &sc->wdc_chanptr;
128 1.6.8.2 nathanw sc->sc_wdcdev.nchannels = 1;
129 1.6.8.2 nathanw sc->wdc_channel.channel = 0;
130 1.6.8.2 nathanw sc->wdc_channel.wdc = &sc->sc_wdcdev;
131 1.6.8.2 nathanw sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
132 1.6.8.2 nathanw M_DEVBUF, M_NOWAIT);
133 1.6.8.2 nathanw if (sc->wdc_channel.ch_queue == NULL) {
134 1.6.8.2 nathanw printf("%s: can't allocate memory for command queue",
135 1.6.8.2 nathanw sc->sc_wdcdev.sc_dev.dv_xname);
136 1.6.8.2 nathanw return;
137 1.6.8.2 nathanw }
138 1.6.8.2 nathanw sc->sc_isr.isr_intr = wdc_amiga_intr;
139 1.6.8.2 nathanw sc->sc_isr.isr_arg = sc;
140 1.6.8.2 nathanw sc->sc_isr.isr_ipl = 2;
141 1.6.8.2 nathanw add_isr (&sc->sc_isr);
142 1.6.8.2 nathanw
143 1.6.8.2 nathanw if (sc->sc_a1200)
144 1.6.8.2 nathanw gayle.intena |= GAYLE_INT_IDE;
145 1.6.8.2 nathanw
146 1.6.8.2 nathanw wdcattach(&sc->wdc_channel);
147 1.6.8.2 nathanw }
148 1.6.8.2 nathanw
149 1.6.8.2 nathanw int
150 1.6.8.2 nathanw wdc_amiga_intr(void *arg)
151 1.6.8.2 nathanw {
152 1.6.8.2 nathanw struct wdc_amiga_softc *sc = (struct wdc_amiga_softc *)arg;
153 1.6.8.2 nathanw u_char intreq = *sc->sc_intreg;
154 1.6.8.2 nathanw int ret = 0;
155 1.6.8.2 nathanw
156 1.6.8.2 nathanw if (intreq & GAYLE_INT_IDE) {
157 1.6.8.2 nathanw if (sc->sc_a1200)
158 1.6.8.2 nathanw gayle.intreq = 0x7c | (intreq & 0x03);
159 1.6.8.2 nathanw ret = wdcintr(&sc->wdc_channel);
160 1.6.8.2 nathanw }
161 1.6.8.2 nathanw
162 1.6.8.2 nathanw return ret;
163 1.6.8.2 nathanw }
164