wdc_pcmcia.c revision 1.10 1 /* $NetBSD: wdc_pcmcia.c,v 1.10 1998/09/18 14:43:58 enami Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum, by Onno van der Linden and by Manuel Bouyer.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/conf.h>
43 #include <sys/file.h>
44 #include <sys/stat.h>
45 #include <sys/ioctl.h>
46 #include <sys/buf.h>
47 #include <sys/uio.h>
48 #include <sys/malloc.h>
49 #include <sys/device.h>
50 #include <sys/disklabel.h>
51 #include <sys/disk.h>
52 #include <sys/syslog.h>
53 #include <sys/proc.h>
54
55 #include <vm/vm.h>
56
57 #include <machine/cpu.h>
58 #include <machine/intr.h>
59 #include <machine/bus.h>
60
61 #include <dev/pcmcia/pcmciavar.h>
62 #include <dev/pcmcia/pcmciadevs.h>
63
64 #include <dev/isa/isavar.h>
65 #include <dev/ic/wdcvar.h>
66
67 #define WDC_PCMCIA_REG_NPORTS 8
68 #define WDC_PCMCIA_AUXREG_OFFSET (WDC_PCMCIA_REG_NPORTS + 6)
69 #define WDC_PCMCIA_AUXREG_NPORTS 2
70
71 struct wdc_pcmcia_softc {
72 struct wdc_softc sc_wdcdev;
73 struct wdc_attachment_data sc_ad;
74 struct pcmcia_io_handle sc_pioh;
75 struct pcmcia_io_handle sc_auxpioh;
76 int sc_iowindow;
77 int sc_auxiowindow;
78 void *sc_ih;
79 };
80
81 static int wdc_pcmcia_match __P((struct device *, struct cfdata *, void *));
82 static void wdc_pcmcia_attach __P((struct device *, struct device *, void *));
83
84 struct cfattach wdc_pcmcia_ca = {
85 sizeof(struct wdc_pcmcia_softc), wdc_pcmcia_match, wdc_pcmcia_attach
86 };
87
88 struct wdc_pcmcia_product {
89 u_int32_t wpp_vendor; /* vendor ID */
90 u_int32_t wpp_product; /* product ID */
91 int wpp_quirk_flag; /* Quirk flags */
92 #define WDC_PCMCIA_FORCE_16BIT_IO 0x01 /* Don't use PCMCIA_WIDTH_AUTO */
93 #define WDC_PCMCIA_NO_EXTRA_RESETS 0x02 /* Only reset ctrl once */
94 const char *wpp_cis_info[4]; /* XXX necessary? */
95 const char *wpp_name; /* product name */
96 } wdc_pcmcia_products[] = {
97
98 { /* PCMCIA_VENDOR_DIGITAL XXX */ 0x0100,
99 PCMCIA_PRODUCT_DIGITAL_MOBILE_MEDIA_CDROM,
100 0, { NULL, "Digital Mobile Media CD-ROM", NULL, NULL },
101 PCMCIA_STR_DIGITAL_MOBILE_MEDIA_CDROM },
102
103 { PCMCIA_VENDOR_HAGIWARASYSCOM,
104 -1, /* XXX */
105 WDC_PCMCIA_FORCE_16BIT_IO,
106 { NULL, NULL, NULL, NULL },
107 "Hagiwara SYS-COM ComactFlash Card" },
108
109 /* CANON FC-8M is also matches. */
110 { PCMCIA_VENDOR_SANDISK,
111 PCMCIA_PRODUCT_SANDISK_SDCFB,
112 WDC_PCMCIA_FORCE_16BIT_IO /* _AUTO also works */,
113 { NULL, NULL, NULL, NULL },
114 PCMCIA_STR_SANDISK_SDCFB },
115
116 /* The TEAC IDE/Card II is used on the Sony Vaio */
117 { PCMCIA_VENDOR_TEAC,
118 PCMCIA_PRODUCT_TEAC_IDECARDII,
119 WDC_PCMCIA_NO_EXTRA_RESETS,
120 PCMCIA_CIS_TEAC_IDECARDII,
121 PCMCIA_STR_TEAC_IDECARDII },
122
123 { 0, 0, 0, { NULL, NULL, NULL, NULL}, NULL }
124 };
125
126 struct wdc_pcmcia_product *
127 wdc_pcmcia_lookup __P((struct pcmcia_attach_args *));
128
129 struct wdc_pcmcia_product *
130 wdc_pcmcia_lookup(pa)
131 struct pcmcia_attach_args *pa;
132 {
133 struct wdc_pcmcia_product *wpp;
134 int i, cis_match;
135
136 for (wpp = wdc_pcmcia_products; wpp->wpp_name != NULL; wpp++)
137 if ((wpp->wpp_vendor == -1 ||
138 pa->manufacturer == wpp->wpp_vendor) &&
139 (wpp->wpp_product == -1 ||
140 pa->product == wpp->wpp_product)) {
141 cis_match = 1;
142 for (i = 0; i < 4; i++) {
143 if (!(wpp->wpp_cis_info[i] == NULL ||
144 (pa->card->cis1_info[i] != NULL &&
145 strcmp(pa->card->cis1_info[i],
146 wpp->wpp_cis_info[i]) == 0)))
147 cis_match = 0;
148 }
149 if (cis_match)
150 return(wpp);
151 }
152
153 return (NULL);
154 }
155
156 static int
157 wdc_pcmcia_match(parent, match, aux)
158 struct device *parent;
159 struct cfdata *match;
160 void *aux;
161 {
162 struct pcmcia_attach_args *pa = aux;
163
164 if (wdc_pcmcia_lookup(pa) != NULL)
165 return (1);
166
167 return (0);
168 }
169
170 static void
171 wdc_pcmcia_attach(parent, self, aux)
172 struct device *parent;
173 struct device *self;
174 void *aux;
175 {
176 struct wdc_pcmcia_softc *sc = (void *)self;
177 struct pcmcia_attach_args *pa = aux;
178 struct pcmcia_config_entry *cfe;
179 struct wdc_pcmcia_product *wpp;
180
181 for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL;
182 cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
183 if (cfe->num_iospace != 1 && cfe->num_iospace != 2)
184 continue;
185
186 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
187 cfe->iospace[0].length,
188 cfe->iospace[0].start == 0 ? cfe->iospace[0].length : 0,
189 &sc->sc_pioh))
190 continue;
191
192 if (cfe->num_iospace == 2) {
193 if (!pcmcia_io_alloc(pa->pf, cfe->iospace[1].start,
194 cfe->iospace[1].length, 0, &sc->sc_auxpioh))
195 break;
196 } else /* num_iospace == 1 */ {
197 sc->sc_auxpioh.iot = sc->sc_pioh.iot;
198 if (!bus_space_subregion(sc->sc_pioh.iot,
199 sc->sc_pioh.ioh, WDC_PCMCIA_AUXREG_OFFSET,
200 WDC_PCMCIA_AUXREG_NPORTS, &sc->sc_auxpioh.ioh))
201 break;
202 }
203 pcmcia_chip_io_free(pa->pf->sc->pct, pa->pf->sc->pch,
204 &sc->sc_pioh);
205 }
206
207 if (cfe == NULL) {
208 printf(": can't handle card info\n");
209 return;
210 }
211
212 sc->sc_ad.iot = sc->sc_pioh.iot;
213 sc->sc_ad.ioh = sc->sc_pioh.ioh;
214 sc->sc_ad.auxiot = sc->sc_auxpioh.iot;
215 sc->sc_ad.auxioh = sc->sc_auxpioh.ioh;
216
217 /* Enable the card. */
218 pcmcia_function_init(pa->pf, cfe);
219 if (pcmcia_function_enable(pa->pf)) {
220 printf(": function enable failed\n");
221 return;
222 }
223
224 /*
225 * XXX DEC Mobile Media CDROM is not yet tested whether it works
226 * XXX with PCMCIA_WIDTH_IO16. HAGIWARA SYS-COM HPC-CF32 doesn't
227 * XXX work with PCMCIA_WIDTH_AUTO.
228 * XXX CANON FC-8M (SANDISK SDCFB 8M) works for both _AUTO and IO16.
229 * XXX So, here is temporary work around.
230 */
231 wpp = wdc_pcmcia_lookup(pa);
232 if (wpp == NULL)
233 panic("wdc_pcmcia_attach: impossible");
234
235 if (pcmcia_io_map(pa->pf,
236 wpp->wpp_quirk_flag & WDC_PCMCIA_FORCE_16BIT_IO ?
237 PCMCIA_WIDTH_IO16 : PCMCIA_WIDTH_AUTO, 0,
238 sc->sc_pioh.size, &sc->sc_pioh, &sc->sc_iowindow)) {
239 printf(": can't map first I/O space\n");
240 return;
241 }
242
243 /*
244 * Currently, # of iospace is 1 except DIGITAL Mobile Media CD-ROM.
245 * So whether the work around like above is necessary or not
246 * is unknown. XXX.
247 */
248 if (cfe->num_iospace > 1 &&
249 pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
250 sc->sc_auxpioh.size, &sc->sc_auxpioh, &sc->sc_auxiowindow)) {
251 printf(": can't map second I/O space\n");
252 return;
253 }
254
255 printf("\n");
256
257 sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_BIO, wdcintr, sc);
258 if (sc->sc_ih == NULL) {
259 printf("%s: couldn't establish interrupt\n", self->dv_xname);
260 return;
261 }
262
263 if (wpp->wpp_quirk_flag & WDC_PCMCIA_NO_EXTRA_RESETS)
264 sc->sc_ad.flags |= WDC_NO_EXTRA_RESETS;
265
266 wdcattach(&sc->sc_wdcdev, &sc->sc_ad);
267 }
268