2 * Copyright (c) 2004 TAKAHASHI Yoshihiro
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
35 #include <sys/kernel.h>
37 #include <sys/module.h>
38 #include <sys/mutex.h>
40 #include <sys/systm.h>
42 #include <machine/bus.h>
44 #include <pc98/cbus/cbus.h>
45 #include <dev/fdc/fdcvar.h>
47 #include <isa/isavar.h>
49 static bus_addr_t fdc_iat[] = {0, 2, 4};
52 fdc_cbus_alloc_resources(device_t dev, struct fdc_data *fdc)
59 res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, fdc_iat, 3,
62 device_printf(dev, "cannot reserve I/O port range\n");
65 isa_load_resourcev(res, fdc_iat, 3);
66 for (i = 0; i < 3; i++) {
70 fdc->ioh[i] = rman_get_bushandle(res);
72 fdc->iot = rman_get_bustag(res);
75 bus_set_resource(dev, SYS_RES_IOPORT, rid, IO_FDPORT, 1);
76 res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
78 device_printf(dev, "cannot reserve I/O port range\n");
84 fdc->ioh[3] = rman_get_bushandle(res);
85 /* XXX: Reuses fdc->iot */
88 bus_set_resource(dev, SYS_RES_IOPORT, rid, 0x4be, 1);
89 res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
91 device_printf(dev, "cannot reserve I/O port range\n");
97 fdc->ioh[4] = rman_get_bushandle(res);
98 /* XXX: Reuses fdc->iot */
100 fdc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &fdc->rid_irq,
102 if (fdc->res_irq == NULL) {
103 device_printf(dev, "cannot reserve interrupt line\n");
107 if ((fdc->flags & FDC_NODMA) == 0) {
108 fdc->res_drq = bus_alloc_resource_any(dev, SYS_RES_DRQ,
109 &fdc->rid_drq, RF_ACTIVE);
110 if (fdc->res_drq == NULL) {
111 device_printf(dev, "cannot reserve DMA request line\n");
114 fdc->dmachan = rman_get_start(fdc->res_drq);
121 fdc_cbus_probe(device_t dev)
124 struct fdc_data *fdc;
126 fdc = device_get_softc(dev);
129 if (isa_get_vendorid(dev))
132 /* Attempt to allocate our resources for the duration of the probe */
133 error = fdc_cbus_alloc_resources(dev, fdc);
135 error = fdc_initial_reset(dev, fdc);
137 fdc_release_resources(fdc);
142 fdc_cbus_attach(device_t dev)
144 struct fdc_data *fdc;
147 fdc = device_get_softc(dev);
148 error = fdc_cbus_alloc_resources(dev, fdc);
150 error = fdc_attach(dev);
152 error = fdc_hints_probe(dev);
154 fdc_release_resources(fdc);
158 static device_method_t fdc_methods[] = {
159 /* Device interface */
160 DEVMETHOD(device_probe, fdc_cbus_probe),
161 DEVMETHOD(device_attach, fdc_cbus_attach),
162 DEVMETHOD(device_detach, fdc_detach),
163 DEVMETHOD(device_shutdown, bus_generic_shutdown),
164 DEVMETHOD(device_suspend, bus_generic_suspend),
165 DEVMETHOD(device_resume, bus_generic_resume),
168 DEVMETHOD(bus_print_child, fdc_print_child),
169 DEVMETHOD(bus_read_ivar, fdc_read_ivar),
170 DEVMETHOD(bus_write_ivar, fdc_write_ivar),
171 /* Our children never use any other bus interface methods. */
176 static driver_t fdc_driver = {
179 sizeof(struct fdc_data)
182 DRIVER_MODULE(fdc, isa, fdc_driver, fdc_devclass, 0, 0);