2 * Copyright (c) 2000 KIYOHARA Takashi <kiyohara@kk.iij4u.ne.jp>
3 * Copyright (c) 2000 Takanori Watanabe <takawata@jp.FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/param.h>
31 #include <sys/systm.h>
33 #include <sys/eventhandler.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
36 #include <sys/reboot.h>
38 #include <machine/bus.h>
39 #include <machine/resource.h>
42 #include <pc98/pc98/canbusvars.h>
43 #include "canbus_if.h"
47 struct canbepm_softc {
48 device_t canbepm_dev; /* canbepm device */
50 eventhandler_tag canbepm_tag; /* event handler tag */
54 static void canbepm_soft_off (void *, int);
55 static void canbepm_identify (driver_t *, device_t);
56 static int canbepm_probe (device_t);
57 static int canbepm_attach (device_t);
58 static int canbepm_detach (device_t);
61 static device_method_t canbepm_methods[] = {
62 DEVMETHOD(device_identify, canbepm_identify),
63 DEVMETHOD(device_probe, canbepm_probe),
64 DEVMETHOD(device_attach, canbepm_attach),
65 DEVMETHOD(device_detach, canbepm_detach),
69 static driver_t canbepm_driver = {
72 sizeof(struct canbepm_softc),
75 devclass_t canbepm_devclass;
76 DRIVER_MODULE(canbepm, canbus, canbepm_driver, canbepm_devclass, 0, 0);
77 MODULE_DEPEND(canbepm, canbus, 1, 1, 1);
81 canbepm_soft_off (void *data, int howto)
83 struct canbepm_softc *sc = data;
84 u_int8_t poweroff_data[] = CANBE_POWEROFF_DATA;
86 if (!(howto & RB_POWEROFF))
89 CANBUS_WRITE_MULTI(device_get_parent(sc->canbepm_dev), sc->canbepm_dev,
90 CANBE_POWER_CTRL, sizeof (poweroff_data), poweroff_data);
95 canbepm_identify(driver_t *drv, device_t parent)
97 if (device_find_child(parent, "canbepm", 0) == NULL) {
98 if (BUS_ADD_CHILD(parent, 33, "canbepm", 0) == NULL)
99 device_printf(parent, "canbepm cannot attach\n");
105 canbepm_probe(device_t dev)
107 device_set_desc(dev, "CanBe Power Management Controller");
113 canbepm_attach(device_t dev)
115 struct canbepm_softc *sc = device_get_softc(dev);
117 /* eventhandler regist */
118 sc->canbepm_tag = EVENTHANDLER_REGISTER(
119 shutdown_final, canbepm_soft_off, sc, SHUTDOWN_PRI_LAST);
121 sc->canbepm_dev = dev;
128 canbepm_detach(device_t dev)
130 struct canbepm_softc *sc = device_get_softc(dev);
132 /* eventhandler deregist */
133 EVENTHANDLER_DEREGISTER(shutdown_final, sc->canbepm_tag);
134 BUS_CHILD_DETACHED(device_get_parent(dev), dev);