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