fdc_pcmcia.c revision 1.5 1 1.5 lukem /* $NetBSD: fdc_pcmcia.c,v 1.5 2001/11/13 07:26:32 lukem Exp $ */
2 1.1 christos
3 1.3 christos /*-
4 1.3 christos * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.3 christos * All rights reserved.
6 1.3 christos *
7 1.3 christos * This code is derived from software contributed to The NetBSD Foundation
8 1.3 christos * by Christos Zoulas.
9 1.1 christos *
10 1.1 christos * Redistribution and use in source and binary forms, with or without
11 1.1 christos * modification, are permitted provided that the following conditions
12 1.1 christos * are met:
13 1.1 christos * 1. Redistributions of source code must retain the above copyright
14 1.1 christos * notice, this list of conditions and the following disclaimer.
15 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 christos * notice, this list of conditions and the following disclaimer in the
17 1.1 christos * documentation and/or other materials provided with the distribution.
18 1.1 christos * 3. All advertising materials mentioning features or use of this software
19 1.1 christos * must display the following acknowledgement:
20 1.3 christos * This product includes software developed by the NetBSD
21 1.3 christos * Foundation, Inc. and its contributors.
22 1.3 christos * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.3 christos * contributors may be used to endorse or promote products derived
24 1.3 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.3 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.3 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.3 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.3 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.3 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.3 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.3 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.3 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.3 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.3 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.3 christos * POSSIBILITY OF SUCH DAMAGE.
37 1.1 christos */
38 1.5 lukem
39 1.5 lukem #include <sys/cdefs.h>
40 1.5 lukem __KERNEL_RCSID(0, "$NetBSD: fdc_pcmcia.c,v 1.5 2001/11/13 07:26:32 lukem Exp $");
41 1.1 christos
42 1.1 christos #include <sys/param.h>
43 1.1 christos #include <sys/systm.h>
44 1.1 christos #include <sys/conf.h>
45 1.1 christos #include <sys/device.h>
46 1.2 christos #include <sys/disk.h>
47 1.2 christos #include <sys/buf.h>
48 1.1 christos
49 1.1 christos #include <machine/bus.h>
50 1.1 christos #include <machine/conf.h>
51 1.1 christos #include <machine/intr.h>
52 1.1 christos
53 1.1 christos #include <dev/pcmcia/pcmciareg.h>
54 1.1 christos #include <dev/pcmcia/pcmciavar.h>
55 1.2 christos #include <dev/pcmcia/pcmciadevs.h>
56 1.1 christos
57 1.2 christos #include <dev/ic/fdcreg.h>
58 1.2 christos #include <dev/ic/fdcvar.h>
59 1.1 christos
60 1.1 christos struct fdc_pcmcia_softc {
61 1.1 christos struct fdc_softc sc_fdc; /* real "fdc" softc */
62 1.1 christos
63 1.1 christos /* PCMCIA-specific goo. */
64 1.1 christos struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o space info */
65 1.1 christos int sc_io_window; /* our i/o window */
66 1.1 christos struct pcmcia_function *sc_pf; /* our PCMCIA function */
67 1.1 christos };
68 1.1 christos
69 1.1 christos int fdc_pcmcia_probe __P((struct device *, struct cfdata *, void *));
70 1.1 christos void fdc_pcmcia_attach __P((struct device *, struct device *, void *));
71 1.1 christos static void fdc_conf __P((struct fdc_softc *));
72 1.1 christos
73 1.1 christos struct cfattach fdc_pcmcia_ca = {
74 1.1 christos sizeof(struct fdc_pcmcia_softc), fdc_pcmcia_probe, fdc_pcmcia_attach
75 1.1 christos };
76 1.1 christos
77 1.1 christos static void
78 1.1 christos fdc_conf(fdc)
79 1.1 christos struct fdc_softc *fdc;
80 1.1 christos {
81 1.1 christos bus_space_tag_t iot = fdc->sc_iot;
82 1.1 christos bus_space_handle_t ioh = fdc->sc_ioh;
83 1.1 christos int n;
84 1.1 christos
85 1.1 christos /* Figure out what we have */
86 1.1 christos if (out_fdc_cmd(iot, ioh, FDC_CMD_VERSION) == -1 ||
87 1.1 christos (n = fdcresult(fdc, 1)) != 1)
88 1.1 christos return;
89 1.1 christos
90 1.1 christos /* Nec765 or equivalent */
91 1.1 christos if (FDC_ST0(fdc->sc_status[0]) == FDC_ST0_INVL)
92 1.1 christos return;
93 1.1 christos
94 1.1 christos #if 0
95 1.1 christos /* ns8477 check */
96 1.1 christos if (out_fdc_cmd(iot, ioh, FDC_CMD_NSC) == -1 ||
97 1.1 christos (n = fdcresult(fdc, 1)) != 1) {
98 1.1 christos printf("NSC command failed\n");
99 1.1 christos return;
100 1.1 christos }
101 1.1 christos else
102 1.1 christos printf("Version %x\n", fdc->sc_status[0]);
103 1.1 christos #endif
104 1.1 christos
105 1.1 christos if (out_fdc_cmd(iot, ioh, FDC_CMD_DUMPREG) == -1 ||
106 1.1 christos (n = fdcresult(fdc, -1)) == -1)
107 1.1 christos return;
108 1.1 christos
109 1.1 christos /*
110 1.1 christos * Expect 10 bytes of status; one means that it did not
111 1.1 christos * understand the command
112 1.1 christos */
113 1.1 christos if (n == 1)
114 1.1 christos return;
115 1.1 christos
116 1.1 christos /*
117 1.1 christos * Configure controller to use FIFO and 8 bytes of FIFO threshold
118 1.1 christos */
119 1.1 christos (void)out_fdc_cmd(iot, ioh, FDC_CMD_CONFIGURE);
120 1.1 christos (void)out_fdc(iot, ioh, 0x00); /* doc says 0 */
121 1.1 christos (void)out_fdc(iot, ioh, 8); /* FIFO is active low. */
122 1.1 christos (void)out_fdc(iot, ioh, fdc->sc_status[9]); /* same comp */
123 1.1 christos /* No result phase */
124 1.1 christos
125 1.1 christos /* Lock this configuration */
126 1.1 christos if (out_fdc_cmd(iot, ioh, FDC_CMD_LOCK(FDC_CMD_FLAGS_LOCK)) == -1 ||
127 1.1 christos fdcresult(fdc, 1) != 1)
128 1.1 christos return;
129 1.1 christos }
130 1.1 christos
131 1.1 christos int
132 1.1 christos fdc_pcmcia_probe(parent, match, aux)
133 1.1 christos struct device *parent;
134 1.1 christos struct cfdata *match;
135 1.1 christos void *aux;
136 1.1 christos {
137 1.1 christos struct pcmcia_attach_args *pa = aux;
138 1.1 christos struct pcmcia_card *card = pa->card;
139 1.2 christos char *cis[4] = PCMCIA_CIS_YEDATA_EXTERNAL_FDD;
140 1.1 christos
141 1.1 christos /* For this card the manufacturer and product are -1 */
142 1.2 christos if (strcmp(cis[0], card->cis1_info[0]) == 0 &&
143 1.2 christos strcmp(cis[1], card->cis1_info[1]) == 0)
144 1.1 christos return 1;
145 1.1 christos
146 1.1 christos return 0;
147 1.1 christos }
148 1.1 christos
149 1.1 christos
150 1.1 christos void
151 1.1 christos fdc_pcmcia_attach(parent, self, aux)
152 1.1 christos struct device *parent, *self;
153 1.1 christos void *aux;
154 1.1 christos {
155 1.1 christos struct fdc_pcmcia_softc *psc = (void *)self;
156 1.1 christos struct fdc_softc *fdc = &psc->sc_fdc;
157 1.1 christos struct pcmcia_attach_args *pa = aux;
158 1.1 christos struct pcmcia_config_entry *cfe;
159 1.1 christos struct pcmcia_function *pf = pa->pf;
160 1.1 christos struct fdc_attach_args fa;
161 1.1 christos
162 1.1 christos psc->sc_pf = pf;
163 1.1 christos
164 1.1 christos for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL;
165 1.1 christos cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
166 1.1 christos if (cfe->num_memspace != 0 ||
167 1.1 christos cfe->num_iospace != 1)
168 1.1 christos continue;
169 1.1 christos
170 1.1 christos if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
171 1.1 christos cfe->iospace[0].length, cfe->iospace[0].length,
172 1.1 christos &psc->sc_pcioh) == 0)
173 1.1 christos break;
174 1.1 christos }
175 1.1 christos
176 1.1 christos if (cfe == 0) {
177 1.1 christos printf(": can't alloc i/o space\n");
178 1.1 christos return;
179 1.1 christos }
180 1.1 christos
181 1.1 christos /* Enable the card. */
182 1.1 christos pcmcia_function_init(pf, cfe);
183 1.1 christos if (pcmcia_function_enable(pf)) {
184 1.1 christos printf(": function enable failed\n");
185 1.1 christos return;
186 1.1 christos }
187 1.1 christos
188 1.1 christos /* Map in the io space */
189 1.1 christos if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0, psc->sc_pcioh.size,
190 1.1 christos &psc->sc_pcioh, &psc->sc_io_window)) {
191 1.1 christos printf(": can't map i/o space\n");
192 1.1 christos return;
193 1.1 christos }
194 1.1 christos
195 1.1 christos fdc->sc_iot = psc->sc_pcioh.iot;
196 1.1 christos fdc->sc_ioh = psc->sc_pcioh.ioh;
197 1.2 christos
198 1.4 christos fdc->sc_flags = FDC_HEADSETTLE;
199 1.1 christos fdc->sc_state = DEVIDLE;
200 1.1 christos TAILQ_INIT(&fdc->sc_drives);
201 1.1 christos
202 1.1 christos if (!fdcfind(fdc->sc_iot, fdc->sc_ioh, 1))
203 1.1 christos printf(": coundn't find fdc\n%s", fdc->sc_dev.dv_xname);
204 1.1 christos
205 1.2 christos printf(": %s\n", PCMCIA_STR_YEDATA_EXTERNAL_FDD);
206 1.1 christos
207 1.1 christos fdc_conf(fdc);
208 1.1 christos
209 1.1 christos /* Establish the interrupt handler. */
210 1.1 christos fdc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_BIO, fdchwintr, fdc);
211 1.1 christos if (fdc->sc_ih == NULL)
212 1.1 christos printf("%s: couldn't establish interrupt\n",
213 1.1 christos fdc->sc_dev.dv_xname);
214 1.1 christos
215 1.1 christos /* physical limit: four drives per controller. */
216 1.1 christos for (fa.fa_drive = 0; fa.fa_drive < 4; fa.fa_drive++) {
217 1.1 christos if (fa.fa_drive < 2)
218 1.1 christos fa.fa_deftype = &fd_types[0];
219 1.1 christos else
220 1.1 christos fa.fa_deftype = NULL; /* unknown */
221 1.1 christos (void)config_found(self, (void *)&fa, fdprint);
222 1.1 christos }
223 1.1 christos }
224