2 * PMC (Power Management Controller of NEC PC-98Note) Driver
4 * Copyright (c) 2001 Chiharu Shibata.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/eventhandler.h>
36 #include <sys/kernel.h>
37 #include <sys/module.h>
39 #include <sys/types.h>
41 #include <sys/reboot.h>
43 #include <machine/bus.h>
44 #include <machine/resource.h>
47 #include <isa/isavar.h>
49 struct pmc_isa_softc {
50 struct resource *port_res;
55 static int pmc_isa_alloc_resources(device_t);
56 static void pmc_isa_release_resources(device_t);
57 static int pmc_isa_probe(device_t);
58 static int pmc_isa_attach(device_t);
59 static int pmc_isa_detach(device_t);
61 #define PMC_ISA_PORT 0x8f0
62 #define PMC_ISA_PORTSIZE 4
64 #define sc_inw(sc, port) \
65 bus_space_read_2(rman_get_bustag((sc)->port_res), \
66 rman_get_bushandle((sc)->port_res), (port))
68 #define sc_outw(sc, port, value) \
69 bus_space_write_2(rman_get_bustag((sc)->port_res), \
70 rman_get_bushandle((sc)->port_res), (port), (value))
73 pmc_poweroff(void *arg, int howto)
75 struct pmc_isa_softc *sc = (struct pmc_isa_softc *)arg;
78 outb(0x5e8e, inb(0x5e8e) & ~0x11); /* FDD LED off */
81 if (!(howto & RB_POWEROFF)) {
85 sc_outw(sc, 0, 0x0044);
86 sc_outw(sc, 2, 1 << 10);
89 sc_outw(sc, 0, 0xf00a);
90 sc_outw(sc, 2, 1 << 9);
95 pmc_isa_alloc_resources(device_t dev)
97 struct pmc_isa_softc *sc = device_get_softc(dev);
100 bzero(sc, sizeof(*sc));
103 sc->port_res = bus_alloc_resource_anywhere(dev, SYS_RES_IOPORT, &rid,
104 PMC_ISA_PORTSIZE, RF_ACTIVE);
105 if (sc->port_res == NULL) {
113 pmc_isa_release_resources(device_t dev)
115 struct pmc_isa_softc *sc = device_get_softc(dev);
117 if (sc->port_res != NULL) {
118 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port_res);
124 pmc_isa_probe(device_t dev)
126 struct pmc_isa_softc *sc = device_get_softc(dev);
131 if (isa_get_vendorid(dev)) {
134 if (device_get_unit(dev) > 0) {
135 printf("pmc: Only one PMC driver supported.\n");
139 port = isa_get_port(dev);
144 device_printf(dev, "port = 0x%x\n", port);
147 if (bus_set_resource(dev, SYS_RES_IOPORT, 0, port, PMC_ISA_PORTSIZE)) {
149 device_printf(dev, "bus_set_resource failed\n");
153 if (pmc_isa_alloc_resources(dev)) {
155 device_printf(dev, "pmc_isa_alloc_resources failed\n");
160 /* Check the existence of PMC */
161 sc_outw(sc, 0, 0x0052);
162 save = sc_inw(sc, 2);
165 if (sc_inw(sc, 2) != tmp) {
167 device_printf(dev, "failed to clear index(0x0052)\n");
170 pmc_isa_release_resources(dev);
176 if (sc_inw(sc, 2) != tmp) {
178 device_printf(dev, "failed to set index(0x0052)\n");
181 pmc_isa_release_resources(dev);
184 sc_outw(sc, 2, save);
186 pmc_isa_release_resources(dev);
188 device_set_desc(dev, "Power Management Controller");
193 pmc_isa_attach(device_t dev)
195 struct pmc_isa_softc *sc = device_get_softc(dev);
198 error = pmc_isa_alloc_resources(dev);
200 device_printf(dev, "resource allocation failed\n");
204 /* Power the system off using PMC */
205 sc->evt = EVENTHANDLER_REGISTER(shutdown_final, pmc_poweroff, sc,
207 sc->flags = device_get_flags(dev);
212 pmc_isa_detach(device_t dev)
214 struct pmc_isa_softc *sc = device_get_softc(dev);
217 device_printf(dev, "pmc_isa_detach called\n");
220 if (sc->evt != NULL) {
221 EVENTHANDLER_DEREGISTER(shutdown_final, sc->evt);
225 pmc_isa_release_resources(dev);
229 static device_method_t pmc_isa_methods[] = {
230 /* Device interface */
231 DEVMETHOD(device_probe, pmc_isa_probe),
232 DEVMETHOD(device_attach, pmc_isa_attach),
233 DEVMETHOD(device_detach, pmc_isa_detach),
237 static driver_t pmc_isa_driver = {
239 pmc_isa_methods, sizeof(struct pmc_isa_softc),
242 devclass_t pmc_devclass;
244 DRIVER_MODULE(pmc, isa, pmc_isa_driver, pmc_devclass, 0, 0);