9 #include <sys/kernel.h>
10 #include <sys/module.h>
12 #include <sys/fcntl.h>
17 #include <sys/mutex.h>
19 #include <machine/bus.h>
20 #include <machine/resource.h>
23 #include <isa/isavar.h>
25 #include <dev/scd/scdreg.h>
26 #include <dev/scd/scdvar.h>
28 static int scd_isa_probe (device_t);
29 static int scd_isa_attach (device_t);
30 static int scd_isa_detach (device_t);
32 static int scd_alloc_resources (device_t);
33 static void scd_release_resources (device_t);
36 scd_isa_probe (device_t dev)
38 struct scd_softc * sc;
42 if (isa_get_vendorid(dev))
45 /* IO port must be configured. */
46 if (bus_get_resource_start(dev, SYS_RES_IOPORT, 0) == 0)
49 sc = device_get_softc(dev);
52 sc->port_type = SYS_RES_IOPORT;
53 error = scd_alloc_resources(dev);
57 error = scd_probe(sc);
59 device_printf(dev, "Probe failed.\n");
63 device_set_desc(dev, sc->data.name);
66 scd_release_resources(dev);
71 scd_isa_attach (device_t dev)
73 struct scd_softc * sc;
76 sc = device_get_softc(dev);
81 sc->port_type = SYS_RES_IOPORT;
82 error = scd_alloc_resources(dev);
86 error = scd_probe(sc);
88 device_printf(dev, "Re-Probe failed.\n");
92 error = scd_attach(sc);
94 device_printf(dev, "Attach failed.\n");
100 scd_release_resources(dev);
105 scd_isa_detach (device_t dev)
107 struct scd_softc * sc;
110 sc = device_get_softc(dev);
113 destroy_dev(sc->scd_dev_t);
115 scd_release_resources(dev);
121 scd_alloc_resources (device_t dev)
123 struct scd_softc * sc;
126 sc = device_get_softc(dev);
128 mtx_init(&sc->mtx, "scd", NULL, MTX_DEF);
131 sc->port = bus_alloc_resource_any(dev, sc->port_type,
132 &sc->port_rid, RF_ACTIVE);
133 if (sc->port == NULL) {
134 device_printf(dev, "Unable to allocate PORT resource.\n");
145 scd_release_resources (device_t dev)
147 struct scd_softc * sc;
149 sc = device_get_softc(dev);
152 bus_release_resource(dev, sc->port_type, sc->port_rid, sc->port);
154 mtx_destroy(&sc->mtx);
159 static device_method_t scd_isa_methods[] = {
160 DEVMETHOD(device_probe, scd_isa_probe),
161 DEVMETHOD(device_attach, scd_isa_attach),
162 DEVMETHOD(device_detach, scd_isa_detach),
167 static driver_t scd_isa_driver = {
170 sizeof(struct scd_softc)
173 static devclass_t scd_devclass;
175 DRIVER_MODULE(scd, isa, scd_isa_driver, scd_devclass, NULL, 0);