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