wdc_pcmcia.c revision 1.3 1 /* $NetBSD: wdc_pcmcia.c,v 1.3 1998/04/25 17:43:27 matt 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->manufacturer == 0x100 && pa->card->product == 0xd00) {
104 if (pa->card->cis1_info[1] != NULL &&
105 strcmp(pa->card->cis1_info[1], "Digital Mobile Media CD-ROM") == 0)
106 return 1;
107 }
108
109
110 return 0;
111 }
112
113 static void
114 wdc_pcmcia_attach(parent, self, aux)
115 struct device *parent;
116 struct device *self;
117 void *aux;
118 {
119 struct wdc_pcmcia_softc *sc = (void *)self;
120 struct pcmcia_attach_args *pa = aux;
121 struct pcmcia_config_entry *cfe = pa->pf->cfe_head.sqh_first;
122
123 printf("\n");
124
125 for (; cfe != NULL; cfe = cfe->cfe_list.sqe_next) {
126 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
127 cfe->iospace[0].length, 0, &sc->sc_pioh))
128 continue;
129 if (cfe->num_iospace > 1) {
130 if (!pcmcia_io_alloc(pa->pf, cfe->iospace[1].start,
131 cfe->iospace[1].length, 0, &sc->sc_auxpioh)) {
132 break;
133 }
134 } else {
135 sc->sc_auxpioh.iot = sc->sc_pioh.iot;
136 if (!bus_space_subregion(sc->sc_pioh.iot, sc->sc_pioh.ioh,
137 WDC_PCMCIA_REG_NPORTS,
138 cfe->iospace[0].length - WDC_PCMCIA_REG_NPORTS,
139 &sc->sc_auxpioh.ioh))
140 break;
141 }
142 pcmcia_chip_io_free(pa->pf->sc->pct, pa->pf->sc->pch, &sc->sc_pioh);
143 }
144
145 if (cfe == NULL) {
146 printf("%s: can't handle card info\n", self->dv_xname);
147 return;
148 }
149
150 sc->sc_ad.iot = sc->sc_pioh.iot;
151 sc->sc_ad.ioh = sc->sc_pioh.ioh;
152 sc->sc_ad.auxiot = sc->sc_auxpioh.iot;
153 sc->sc_ad.auxioh = sc->sc_auxpioh.ioh;
154
155 /* Enable the card. */
156 pcmcia_function_init(pa->pf, cfe);
157 if (pcmcia_function_enable(pa->pf)) {
158 printf("%s: function enable failed\n", self->dv_xname);
159 return;
160 }
161
162 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
163 sc->sc_pioh.size, &sc->sc_pioh,
164 &sc->sc_iowindow)) {
165 printf("%s: can't map first I/O space\n", self->dv_xname);
166 return;
167 }
168 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
169 sc->sc_auxpioh.size, &sc->sc_auxpioh,
170 &sc->sc_auxiowindow)) {
171 printf("%s: can't map second I/O space\n", self->dv_xname);
172 return;
173 }
174
175 sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_BIO, wdcintr, sc);
176 if (sc->sc_ih == NULL) {
177 printf("%s: couldn't establish interrupt\n", self->dv_xname);
178 return;
179 }
180
181 wdcattach(&sc->sc_wdcdev, &sc->sc_ad);
182 }
183