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