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