fdc_pnpbus.c revision 1.1 1 1.1 garbled /* $NetBSD: fdc_pnpbus.c,v 1.1 2008/04/28 19:01:45 garbled Exp $ */
2 1.1 garbled
3 1.1 garbled /*-
4 1.1 garbled * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.1 garbled * All rights reserved.
6 1.1 garbled *
7 1.1 garbled * This code is derived from software contributed to The NetBSD Foundation
8 1.1 garbled * by Tim Rightnour
9 1.1 garbled *
10 1.1 garbled * Redistribution and use in source and binary forms, with or without
11 1.1 garbled * modification, are permitted provided that the following conditions
12 1.1 garbled * are met:
13 1.1 garbled * 1. Redistributions of source code must retain the above copyright
14 1.1 garbled * notice, this list of conditions and the following disclaimer.
15 1.1 garbled * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 garbled * notice, this list of conditions and the following disclaimer in the
17 1.1 garbled * documentation and/or other materials provided with the distribution.
18 1.1 garbled * 3. All advertising materials mentioning features or use of this software
19 1.1 garbled * must display the following acknowledgement:
20 1.1 garbled * This product includes software developed by the NetBSD
21 1.1 garbled * Foundation, Inc. and its contributors.
22 1.1 garbled * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 garbled * contributors may be used to endorse or promote products derived
24 1.1 garbled * from this software without specific prior written permission.
25 1.1 garbled *
26 1.1 garbled * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 garbled * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 garbled * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 garbled * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 garbled * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 garbled * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 garbled * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 garbled * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 garbled * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 garbled * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 garbled * POSSIBILITY OF SUCH DAMAGE.
37 1.1 garbled */
38 1.1 garbled
39 1.1 garbled /*
40 1.1 garbled * PNPBIOS attachment for the PC Floppy Controller driver.
41 1.1 garbled */
42 1.1 garbled
43 1.1 garbled #include <sys/cdefs.h>
44 1.1 garbled __KERNEL_RCSID(0, "$NetBSD: fdc_pnpbus.c,v 1.1 2008/04/28 19:01:45 garbled Exp $");
45 1.1 garbled
46 1.1 garbled #include "rnd.h"
47 1.1 garbled
48 1.1 garbled #include <sys/param.h>
49 1.1 garbled #include <sys/systm.h>
50 1.1 garbled #include <sys/callout.h>
51 1.1 garbled #include <sys/device.h>
52 1.1 garbled #include <sys/buf.h>
53 1.1 garbled #include <sys/queue.h>
54 1.1 garbled #if NRND > 0
55 1.1 garbled #include <sys/rnd.h>
56 1.1 garbled #endif
57 1.1 garbled
58 1.1 garbled #include <machine/bus.h>
59 1.1 garbled #include <machine/intr.h>
60 1.1 garbled #include <machine/isa_machdep.h>
61 1.1 garbled
62 1.1 garbled #include <dev/isa/isavar.h>
63 1.1 garbled #include <dev/isa/isadmavar.h>
64 1.1 garbled
65 1.1 garbled #include <dev/isa/fdcvar.h>
66 1.1 garbled
67 1.1 garbled #include <prep/pnpbus/pnpbusvar.h>
68 1.1 garbled
69 1.1 garbled static int fdc_pnpbus_match(device_t, cfdata_t, void *);
70 1.1 garbled static void fdc_pnpbus_attach(device_t, device_t, void *);
71 1.1 garbled
72 1.1 garbled struct fdc_pnpbus_softc {
73 1.1 garbled struct fdc_softc sc_fdc; /* base fdc device */
74 1.1 garbled
75 1.1 garbled bus_space_handle_t sc_baseioh; /* base I/O handle */
76 1.1 garbled };
77 1.1 garbled
78 1.1 garbled CFATTACH_DECL2_NEW(fdc_pnpbus, sizeof(struct fdc_pnpbus_softc),
79 1.1 garbled fdc_pnpbus_match, fdc_pnpbus_attach, NULL, NULL, NULL, NULL);
80 1.1 garbled
81 1.1 garbled static int
82 1.1 garbled fdc_pnpbus_match(device_t parent, cfdata_t match, void *aux)
83 1.1 garbled {
84 1.1 garbled struct pnpbus_dev_attach_args *pna = aux;
85 1.1 garbled int ret = 0;
86 1.1 garbled
87 1.1 garbled if (strcmp(pna->pna_devid, "PNP0700") == 0)
88 1.1 garbled ret = 1;
89 1.1 garbled
90 1.1 garbled if (ret)
91 1.1 garbled pnpbus_scan(pna, pna->pna_ppc_dev);
92 1.1 garbled
93 1.1 garbled return ret;
94 1.1 garbled }
95 1.1 garbled
96 1.1 garbled static void
97 1.1 garbled fdc_pnpbus_attach(device_t parent, device_t self, void *aux)
98 1.1 garbled {
99 1.1 garbled struct fdc_pnpbus_softc *pdc = device_private(self);
100 1.1 garbled struct fdc_softc *fdc = &pdc->sc_fdc;
101 1.1 garbled struct pnpbus_dev_attach_args *pna = aux;
102 1.1 garbled int size, base;
103 1.1 garbled
104 1.1 garbled fdc->sc_dev = self;
105 1.1 garbled fdc->sc_ic = pna->pna_ic;
106 1.1 garbled
107 1.1 garbled if (pnpbus_io_map(&pna->pna_res, 0, &fdc->sc_iot, &pdc->sc_baseioh)) {
108 1.1 garbled aprint_error_dev(self, "unable to map I/O space\n");
109 1.1 garbled return;
110 1.1 garbled }
111 1.1 garbled
112 1.1 garbled /*
113 1.1 garbled * Start accounting for "odd" pnpbus's. Some probe as 4 ports,
114 1.1 garbled * some as 6 and some don't give the ctl port back.
115 1.1 garbled */
116 1.1 garbled
117 1.1 garbled if (pnpbus_getioport(&pna->pna_res, 0, &base, &size)) {
118 1.1 garbled aprint_error_dev(self, "can't get iobase size\n");
119 1.1 garbled return;
120 1.1 garbled }
121 1.1 garbled
122 1.1 garbled switch (size) {
123 1.1 garbled
124 1.1 garbled /* Easy case. This matches right up with what the fdc code expects. */
125 1.1 garbled case 4:
126 1.1 garbled fdc->sc_ioh = pdc->sc_baseioh;
127 1.1 garbled break;
128 1.1 garbled
129 1.1 garbled /* Map a subregion so this all lines up with the fdc code. */
130 1.1 garbled case 6:
131 1.1 garbled if (bus_space_subregion(fdc->sc_iot, pdc->sc_baseioh, 2, 4,
132 1.1 garbled &fdc->sc_ioh)) {
133 1.1 garbled aprint_error_dev(self,
134 1.1 garbled "unable to subregion I/O space\n");
135 1.1 garbled return;
136 1.1 garbled }
137 1.1 garbled break;
138 1.1 garbled default:
139 1.1 garbled aprint_error_dev(self, "unknown size: %d of io mapping\n", size);
140 1.1 garbled return;
141 1.1 garbled }
142 1.1 garbled
143 1.1 garbled /*
144 1.1 garbled * XXX: This is bad. If the pnpbus claims only 1 I/O range then it's
145 1.1 garbled * omitting the controller I/O port. (One has to exist for there to
146 1.1 garbled * be a working fdc). Just try and force the mapping in.
147 1.1 garbled */
148 1.1 garbled
149 1.1 garbled if (pna->pna_res.numio == 1) {
150 1.1 garbled if (bus_space_map(fdc->sc_iot, base + size + 1, 1, 0,
151 1.1 garbled &fdc->sc_fdctlioh)) {
152 1.1 garbled aprint_error_dev(self,
153 1.1 garbled "unable to force map CTL I/O space\n");
154 1.1 garbled return;
155 1.1 garbled }
156 1.1 garbled } else if (pnpbus_io_map(&pna->pna_res, 1, &fdc->sc_iot,
157 1.1 garbled &fdc->sc_fdctlioh)) {
158 1.1 garbled aprint_error_dev(self, "unable to map CTL I/O space\n");
159 1.1 garbled return;
160 1.1 garbled }
161 1.1 garbled
162 1.1 garbled if (pnpbus_getdmachan(&pna->pna_res, 0, &fdc->sc_drq)) {
163 1.1 garbled aprint_error_dev(self, "unable to get DMA channel\n");
164 1.1 garbled return;
165 1.1 garbled }
166 1.1 garbled
167 1.1 garbled if (pna->pna_res.numio == 1)
168 1.1 garbled aprint_normal_dev(self,
169 1.1 garbled "ctl io %x didn't probe. Forced attach\n", base + size + 1);
170 1.1 garbled
171 1.1 garbled aprint_normal("\n");
172 1.1 garbled
173 1.1 garbled /* The 7043-140 gets the type wrong, so overide to edge allways */
174 1.1 garbled fdc->sc_ih = pnpbus_intr_establish(0, IPL_BIO, IST_EDGE, fdcintr, fdc,
175 1.1 garbled &pna->pna_res);
176 1.1 garbled
177 1.1 garbled fdcattach(fdc);
178 1.1 garbled }
179