wdc_pcmcia.c revision 1.2 1 /* $NetBSD: wdc_pcmcia.c,v 1.2 1998/01/23 01:14:13 mycroft Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
5 *
6 * DMA and multi-sector PIO handling are derived from code contributed by
7 * Onno van der Linden.
8 *
9 * Atapi support added by Manuel Bouyer.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Charles M. Hannum.
22 * 4. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #undef ATAPI_DEBUG_WDC
38 #define WDDEBUG
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/conf.h>
44 #include <sys/file.h>
45 #include <sys/stat.h>
46 #include <sys/ioctl.h>
47 #include <sys/buf.h>
48 #include <sys/uio.h>
49 #include <sys/malloc.h>
50 #include <sys/device.h>
51 #include <sys/disklabel.h>
52 #include <sys/disk.h>
53 #include <sys/syslog.h>
54 #include <sys/proc.h>
55
56 #include <vm/vm.h>
57
58 #include <machine/cpu.h>
59 #include <machine/intr.h>
60 #include <machine/bus.h>
61
62 #include <dev/pcmcia/pcmciavar.h>
63 #include <dev/isa/isavar.h>
64 #include <dev/ic/wdcvar.h>
65
66 #define WDC_PCMCIA_REG_NPORTS 8
67 #define WDC_PCMCIA_AUXREG_OFFSET 0x206
68 #define WDC_PCMCIA_AUXREG_NPORTS 2
69
70 struct wdc_pcmcia_softc {
71 struct wdc_softc sc_wdcdev;
72 struct wdc_attachment_data sc_ad;
73 struct pcmcia_io_handle sc_pioh;
74 struct pcmcia_io_handle sc_auxpioh;
75 int sc_iowindow;
76 int sc_auxiowindow;
77 void *sc_ih;
78 };
79
80 #ifdef __BROKEN_INDIRECT_CONFIG
81 static int wdc_pcmcia_match __P((struct device *, void *, void *));
82 #else
83 static int wdc_pcmcia_match __P((struct device *, struct cfdata *, void *));
84 #endif
85 static void wdc_pcmcia_attach __P((struct device *, struct device *, void *));
86
87 struct cfattach wdc_pcmcia_ca = {
88 sizeof(struct wdc_pcmcia_softc), wdc_pcmcia_match, wdc_pcmcia_attach
89 };
90
91 static int
92 wdc_pcmcia_match(parent, match, aux)
93 struct device *parent;
94 #ifdef __BROKEN_INDIRECT_CONFIG
95 void *match;
96 #else
97 struct cfdata *match;
98 #endif
99 void *aux;
100 {
101 struct pcmcia_attach_args *pa = aux;
102
103 if (pa->card->cis1_info[0] != NULL &&
104 strcmp(pa->card->cis1_info[0], "Digital Equipment Corporation.") == 0 &&
105 pa->card->cis1_info[1] != NULL &&
106 strcmp(pa->card->cis1_info[1], "Digital Mobile Media CD-ROM") == 0)
107 return 1;
108
109 return 0;
110 }
111
112 static void
113 wdc_pcmcia_attach(parent, self, aux)
114 struct device *parent;
115 struct device *self;
116 void *aux;
117 {
118 struct wdc_pcmcia_softc *sc = (void *)self;
119 struct pcmcia_attach_args *pa = aux;
120 struct pcmcia_config_entry *cfe = pa->pf->cfe_head.sqh_first;
121
122 printf("\n");
123
124 for (; cfe != NULL; cfe = cfe->cfe_list.sqe_next) {
125 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
126 cfe->iospace[0].length, 0, &sc->sc_pioh))
127 continue;
128 if (cfe->num_iospace > 1) {
129 if (!pcmcia_io_alloc(pa->pf, cfe->iospace[1].start,
130 cfe->iospace[1].length, 0, &sc->sc_auxpioh)) {
131 break;
132 }
133 } else {
134 sc->sc_auxpioh.iot = sc->sc_pioh.iot;
135 if (!bus_space_subregion(sc->sc_pioh.iot, sc->sc_pioh.ioh,
136 WDC_PCMCIA_REG_NPORTS,
137 cfe->iospace[0].length - WDC_PCMCIA_REG_NPORTS,
138 &sc->sc_auxpioh.ioh))
139 break;
140 }
141 pcmcia_chip_io_free(pa->pf->sc->pct, pa->pf->sc->pch, &sc->sc_pioh);
142 }
143
144 if (cfe == NULL) {
145 printf("%s: can't handle card info\n", self->dv_xname);
146 return;
147 }
148
149 sc->sc_ad.iot = sc->sc_pioh.iot;
150 sc->sc_ad.ioh = sc->sc_pioh.ioh;
151 sc->sc_ad.auxiot = sc->sc_auxpioh.iot;
152 sc->sc_ad.auxioh = sc->sc_auxpioh.ioh;
153
154 /* Enable the card. */
155 pcmcia_function_init(pa->pf, cfe);
156 if (pcmcia_function_enable(pa->pf)) {
157 printf("%s: function enable failed\n", self->dv_xname);
158 return;
159 }
160
161 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
162 sc->sc_pioh.size, &sc->sc_pioh,
163 &sc->sc_iowindow)) {
164 printf("%s: can't map first I/O space\n", self->dv_xname);
165 return;
166 }
167 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
168 sc->sc_auxpioh.size, &sc->sc_auxpioh,
169 &sc->sc_auxiowindow)) {
170 printf("%s: can't map second I/O space\n", self->dv_xname);
171 return;
172 }
173
174 sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_BIO, wdcintr, sc);
175 if (sc->sc_ih == NULL) {
176 printf("%s: couldn't establish interrupt\n", self->dv_xname);
177 return;
178 }
179
180 wdcattach(&sc->sc_wdcdev, &sc->sc_ad);
181 }
182