fdc_acpi.c revision 1.1 1 /* $NetBSD: fdc_acpi.c,v 1.1 2002/12/28 19:31:35 jmcneill Exp $ */
2
3 /*
4 * Copyright (c) 2002 Jared D. McNeill <jmcneill (at) invisible.ca>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 /*
29 * ACPI attachment for the PC Floppy Controller driver, based on
30 * sys/arch/i386/pnpbios/fdc_pnpbios.c by Jason R. Thorpe
31 */
32
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: fdc_acpi.c,v 1.1 2002/12/28 19:31:35 jmcneill Exp $");
35
36 #include "rnd.h"
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/callout.h>
41 #include <sys/device.h>
42 #include <sys/buf.h>
43 #include <sys/queue.h>
44 #if NRND > 0
45 #include <sys/rnd.h>
46 #endif
47
48 #include <machine/bus.h>
49 #include <machine/intr.h>
50
51 #include <dev/isa/isavar.h>
52 #include <dev/isa/isadmavar.h>
53
54 #include <dev/acpi/acpica.h>
55 #include <dev/acpi/acpireg.h>
56 #include <dev/acpi/acpivar.h>
57
58 #include <dev/isa/fdcvar.h>
59
60 int fdc_acpi_match(struct device *, struct cfdata *, void *);
61 void fdc_acpi_attach(struct device *, struct device *, void *);
62
63 struct fdc_acpi_softc {
64 struct fdc_softc sc_fdc;
65 bus_space_handle_t sc_baseioh;
66 };
67
68 CFATTACH_DECL(fdc_acpi, sizeof(struct fdc_acpi_softc), fdc_acpi_match,
69 fdc_acpi_attach, NULL, NULL);
70
71 /*
72 * Supported device IDs
73 */
74
75 static const char * const fdc_acpi_ids[] = {
76 "PNP0700", /* PC standard floppy disk controller */
77 #if 0 /* XXX do we support this? */
78 "PNP0701", /* Standard floppy controller for MS Device Bay Spec */
79 #endif
80 NULL
81 };
82
83 /*
84 * fdc_acpi_match: autoconf(9) match routine
85 */
86 int
87 fdc_acpi_match(struct device *parent, struct cfdata *match, void *aux)
88 {
89 struct acpi_attach_args *aa = aux;
90 const char *id;
91 int i;
92
93 if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
94 return 0;
95
96 for (i = 0; (id = fdc_acpi_ids[i]) != NULL; ++i) {
97 if (strcmp(aa->aa_node->ad_devinfo.HardwareId, id) == 0)
98 return 1;
99 }
100
101 /* No matches found */
102 return 0;
103 }
104
105 /*
106 * fdc_acpi_attach: autoconf(9) attach routine
107 */
108 void
109 fdc_acpi_attach(struct device *parent, struct device *self, void *aux)
110 {
111 struct fdc_acpi_softc *asc = (struct fdc_acpi_softc *)self;
112 struct fdc_softc *sc = &asc->sc_fdc;
113 struct acpi_attach_args *aa = aux;
114 struct acpi_resources res;
115 struct acpi_io *io, *ctlio;
116 struct acpi_irq *irq;
117 struct acpi_drq *drq;
118 ACPI_STATUS rv;
119
120 printf("\n");
121
122 sc->sc_ic = aa->aa_ic;
123
124 /* parse resources */
125 rv = acpi_resource_parse(&sc->sc_dev, aa->aa_node, &res,
126 &acpi_resource_parse_ops_default);
127 if (rv != AE_OK) {
128 printf("%s: unable to parse resources\n", sc->sc_dev.dv_xname);
129 return;
130 }
131
132 /* find our i/o registers */
133 io = acpi_res_io(&res, 0);
134 if (io == NULL) {
135 printf("%s: unable to find i/o register resource\n",
136 sc->sc_dev.dv_xname);
137 return;
138 }
139
140 /* find our IRQ */
141 irq = acpi_res_irq(&res, 0);
142 if (irq == NULL) {
143 printf("%s: unable to find irq resource\n",
144 sc->sc_dev.dv_xname);
145 return;
146 }
147
148 /* find our DRQ */
149 drq = acpi_res_drq(&res, 0);
150 if (drq == NULL) {
151 printf("%s: unable to find drq resource\n",
152 sc->sc_dev.dv_xname);
153 return;
154 }
155
156 sc->sc_iot = aa->aa_iot;
157 if (bus_space_map(sc->sc_iot, io->ar_base, io->ar_length,
158 0, &asc->sc_baseioh)) {
159 printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
160 return;
161 }
162
163 switch (io->ar_length) {
164 case 4:
165 sc->sc_ioh = asc->sc_baseioh;
166 break;
167 case 6:
168 if (bus_space_subregion(sc->sc_iot, asc->sc_baseioh, 2, 4,
169 &sc->sc_ioh)) {
170 printf("%s: unable to subregion i/o space\n",
171 sc->sc_dev.dv_xname);
172 return;
173 }
174 break;
175 default:
176 printf("%s: unknown size: %d of io mapping\n",
177 sc->sc_dev.dv_xname, io->ar_length);
178 return;
179 }
180
181 /*
182 * XXX: This is bad. If the pnpbios claims only 1 I/O range then it's
183 * omitting the controller I/O port. (One has to exist for there to
184 * be a working fdc). Just try and force the mapping in.
185 */
186 ctlio = acpi_res_io(&res, 1);
187 if (ctlio == NULL) {
188 if (bus_space_map(sc->sc_iot, io->ar_base + io->ar_length + 1,
189 1, 0, &sc->sc_fdctlioh)) {
190 printf("%s: unable to force map ctl i/o space\n",
191 sc->sc_dev.dv_xname);
192 return;
193 }
194 printf("%s: ctl io %x did't probe. Forced attach\n",
195 sc->sc_dev.dv_xname, io->ar_base + io->ar_length + 1);
196 } else {
197 if (bus_space_map(sc->sc_iot, ctlio->ar_base, ctlio->ar_length,
198 0, &sc->sc_fdctlioh)) {
199 printf("%s: unable to map ctl i/o space\n",
200 sc->sc_dev.dv_xname);
201 return;
202 }
203 }
204
205 sc->sc_ih = isa_intr_establish(aa->aa_ic, irq->ar_irq, 0,
206 IPL_BIO, fdcintr, sc);
207
208 fdcattach(sc);
209 }
210