wdc_pcmcia.c revision 1.8 1 /* $NetBSD: wdc_pcmcia.c,v 1.8 1998/08/15 10:10:55 mycroft 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/isa/isavar.h>
63 #include <dev/ic/wdcvar.h>
64
65 #define WDC_PCMCIA_REG_NPORTS 8
66 #define WDC_PCMCIA_AUXREG_OFFSET 0x206
67 #define WDC_PCMCIA_AUXREG_NPORTS 2
68
69 struct wdc_pcmcia_softc {
70 struct wdc_softc sc_wdcdev;
71 struct wdc_attachment_data sc_ad;
72 struct pcmcia_io_handle sc_pioh;
73 struct pcmcia_io_handle sc_auxpioh;
74 int sc_iowindow;
75 int sc_auxiowindow;
76 void *sc_ih;
77 };
78
79 static int wdc_pcmcia_match __P((struct device *, struct cfdata *, void *));
80 static void wdc_pcmcia_attach __P((struct device *, struct device *, void *));
81
82 struct cfattach wdc_pcmcia_ca = {
83 sizeof(struct wdc_pcmcia_softc), wdc_pcmcia_match, wdc_pcmcia_attach
84 };
85
86 static int
87 wdc_pcmcia_match(parent, match, aux)
88 struct device *parent;
89 struct cfdata *match;
90 void *aux;
91 {
92 struct pcmcia_attach_args *pa = aux;
93
94 if (pa->card->manufacturer == 0x100 && pa->card->product == 0xd00) {
95 if (pa->card->cis1_info[1] != NULL &&
96 strcmp(pa->card->cis1_info[1], "Digital Mobile Media CD-ROM") == 0)
97 return 1;
98 }
99
100
101 return 0;
102 }
103
104 static void
105 wdc_pcmcia_attach(parent, self, aux)
106 struct device *parent;
107 struct device *self;
108 void *aux;
109 {
110 struct wdc_pcmcia_softc *sc = (void *)self;
111 struct pcmcia_attach_args *pa = aux;
112 struct pcmcia_config_entry *cfe;
113
114 for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL;
115 cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
116 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
117 cfe->iospace[0].length, 0, &sc->sc_pioh))
118 continue;
119 if (cfe->num_iospace > 1) {
120 if (!pcmcia_io_alloc(pa->pf, cfe->iospace[1].start,
121 cfe->iospace[1].length, 0, &sc->sc_auxpioh)) {
122 break;
123 }
124 } else {
125 sc->sc_auxpioh.iot = sc->sc_pioh.iot;
126 if (!bus_space_subregion(sc->sc_pioh.iot, sc->sc_pioh.ioh,
127 WDC_PCMCIA_REG_NPORTS,
128 cfe->iospace[0].length - WDC_PCMCIA_REG_NPORTS,
129 &sc->sc_auxpioh.ioh))
130 break;
131 }
132 pcmcia_chip_io_free(pa->pf->sc->pct, pa->pf->sc->pch, &sc->sc_pioh);
133 }
134
135 if (cfe == NULL) {
136 printf(": can't handle card info\n");
137 return;
138 }
139
140 sc->sc_ad.iot = sc->sc_pioh.iot;
141 sc->sc_ad.ioh = sc->sc_pioh.ioh;
142 sc->sc_ad.auxiot = sc->sc_auxpioh.iot;
143 sc->sc_ad.auxioh = sc->sc_auxpioh.ioh;
144
145 /* Enable the card. */
146 pcmcia_function_init(pa->pf, cfe);
147 if (pcmcia_function_enable(pa->pf)) {
148 printf(": function enable failed\n");
149 return;
150 }
151
152 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
153 sc->sc_pioh.size, &sc->sc_pioh,
154 &sc->sc_iowindow)) {
155 printf(": can't map first I/O space\n");
156 return;
157 }
158 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
159 sc->sc_auxpioh.size, &sc->sc_auxpioh,
160 &sc->sc_auxiowindow)) {
161 printf(": can't map second I/O space\n");
162 return;
163 }
164
165 printf("\n");
166
167 sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_BIO, wdcintr, sc);
168 if (sc->sc_ih == NULL) {
169 printf("%s: couldn't establish interrupt\n", self->dv_xname);
170 return;
171 }
172
173 wdcattach(&sc->sc_wdcdev, &sc->sc_ad);
174 }
175