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>
36 #include <sys/module.h>
38 #include <sys/systm.h>
40 #include <machine/bus.h>
42 #include <pc98/cbus/cbus.h>
43 #include <pc98/cbus/fdcreg.h>
44 #include <pc98/cbus/fdcvar.h>
46 #include <isa/isavar.h>
48 static bus_addr_t fdc_iat[] = {0, 2, 4};
51 fdc_cbus_alloc_resources(device_t dev, struct fdc_data *fdc)
62 fdc->res_ioport = isa_alloc_resourcev(dev, SYS_RES_IOPORT,
63 &fdc->rid_ioport, fdc_iat,
65 if (fdc->res_ioport == 0) {
66 device_printf(dev, "cannot reserve I/O port range\n");
69 isa_load_resourcev(fdc->res_ioport, fdc_iat, 3);
70 fdc->portt = rman_get_bustag(fdc->res_ioport);
71 fdc->porth = rman_get_bushandle(fdc->res_ioport);
74 bus_set_resource(dev, SYS_RES_IOPORT, rid, IO_FDPORT, 1);
75 fdc->res_fdsio = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
77 if (fdc->res_fdsio == 0)
79 fdc->sc_fdsiot = rman_get_bustag(fdc->res_fdsio);
80 fdc->sc_fdsioh = rman_get_bushandle(fdc->res_fdsio);
83 bus_set_resource(dev, SYS_RES_IOPORT, rid, 0x4be, 1);
84 fdc->res_fdemsio = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
86 if (fdc->res_fdemsio == 0)
88 fdc->sc_fdemsiot = rman_get_bustag(fdc->res_fdemsio);
89 fdc->sc_fdemsioh = rman_get_bushandle(fdc->res_fdemsio);
91 fdc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &fdc->rid_irq,
93 if (fdc->res_irq == 0) {
94 device_printf(dev, "cannot reserve interrupt line\n");
98 if ((fdc->flags & FDC_NODMA) == 0) {
99 fdc->res_drq = bus_alloc_resource_any(dev, SYS_RES_DRQ,
100 &fdc->rid_drq, RF_ACTIVE);
101 if (fdc->res_drq == 0) {
102 device_printf(dev, "cannot reserve DMA request line\n");
105 fdc->dmachan = rman_get_start(fdc->res_drq);
112 fdc_cbus_probe(device_t dev)
115 struct fdc_data *fdc;
117 fdc = device_get_softc(dev);
120 if (isa_get_vendorid(dev))
123 /* Attempt to allocate our resources for the duration of the probe */
124 error = fdc_cbus_alloc_resources(dev, fdc);
126 error = fdc_initial_reset(fdc);
128 fdc_release_resources(fdc);
133 fdc_cbus_attach(device_t dev)
135 struct fdc_data *fdc;
138 fdc = device_get_softc(dev);
140 if ((error = fdc_cbus_alloc_resources(dev, fdc)) != 0 ||
141 (error = fdc_attach(dev)) != 0 ||
142 (error = fdc_hints_probe(dev)) != 0) {
143 fdc_release_resources(fdc);
150 static device_method_t fdc_methods[] = {
151 /* Device interface */
152 DEVMETHOD(device_probe, fdc_cbus_probe),
153 DEVMETHOD(device_attach, fdc_cbus_attach),
154 DEVMETHOD(device_detach, fdc_detach),
155 DEVMETHOD(device_shutdown, bus_generic_shutdown),
156 DEVMETHOD(device_suspend, bus_generic_suspend),
157 DEVMETHOD(device_resume, bus_generic_resume),
160 DEVMETHOD(bus_print_child, fdc_print_child),
161 DEVMETHOD(bus_read_ivar, fdc_read_ivar),
162 DEVMETHOD(bus_write_ivar, fdc_write_ivar),
163 /* Our children never use any other bus interface methods. */
168 static driver_t fdc_driver = {
171 sizeof(struct fdc_data)
174 DRIVER_MODULE(fdc, isa, fdc_driver, fdc_devclass, 0, 0);