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(dev, SYS_RES_IOPORT, &rid,
104 0ul, ~0ul, PMC_ISA_PORTSIZE,
106 if (sc->port_res == NULL) {
114 pmc_isa_release_resources(device_t dev)
116 struct pmc_isa_softc *sc = device_get_softc(dev);
118 if (sc->port_res != NULL) {
119 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port_res);
125 pmc_isa_probe(device_t dev)
127 struct pmc_isa_softc *sc = device_get_softc(dev);
132 if (isa_get_vendorid(dev)) {
135 if (device_get_unit(dev) > 0) {
136 printf("pmc: Only one PMC driver supported.\n");
140 port = isa_get_port(dev);
145 device_printf(dev, "port = 0x%x\n", port);
148 if (bus_set_resource(dev, SYS_RES_IOPORT, 0, port, PMC_ISA_PORTSIZE)) {
150 device_printf(dev, "bus_set_resource failed\n");
154 if (pmc_isa_alloc_resources(dev)) {
156 device_printf(dev, "pmc_isa_alloc_resources failed\n");
161 /* Check the existence of PMC */
162 sc_outw(sc, 0, 0x0052);
163 save = sc_inw(sc, 2);
166 if (sc_inw(sc, 2) != tmp) {
168 device_printf(dev, "failed to clear index(0x0052)\n");
171 pmc_isa_release_resources(dev);
177 if (sc_inw(sc, 2) != tmp) {
179 device_printf(dev, "failed to set index(0x0052)\n");
182 pmc_isa_release_resources(dev);
185 sc_outw(sc, 2, save);
187 pmc_isa_release_resources(dev);
189 device_set_desc(dev, "Power Management Controller");
194 pmc_isa_attach(device_t dev)
196 struct pmc_isa_softc *sc = device_get_softc(dev);
199 error = pmc_isa_alloc_resources(dev);
201 device_printf(dev, "resource allocation failed\n");
205 /* Power the system off using PMC */
206 sc->evt = EVENTHANDLER_REGISTER(shutdown_final, pmc_poweroff, sc,
208 sc->flags = device_get_flags(dev);
213 pmc_isa_detach(device_t dev)
215 struct pmc_isa_softc *sc = device_get_softc(dev);
218 device_printf(dev, "pmc_isa_detach called\n");
221 if (sc->evt != NULL) {
222 EVENTHANDLER_DEREGISTER(shutdown_final, sc->evt);
226 pmc_isa_release_resources(dev);
230 static device_method_t pmc_isa_methods[] = {
231 /* Device interface */
232 DEVMETHOD(device_probe, pmc_isa_probe),
233 DEVMETHOD(device_attach, pmc_isa_attach),
234 DEVMETHOD(device_detach, pmc_isa_detach),
238 static driver_t pmc_isa_driver = {
240 pmc_isa_methods, sizeof(struct pmc_isa_softc),
243 devclass_t pmc_devclass;
245 DRIVER_MODULE(pmc, isa, pmc_isa_driver, pmc_devclass, 0, 0);