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