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
27 * $FreeBSD: src/sys/pc98/pc98/canbepm.c,v 1.3.2.1 2003/02/10 13:11:51 nyan Exp $
28 * $DragonFly: src/sys/dev/powermng/pc98/canbepm/Attic/canbepm.c,v 1.3 2003/11/20 22:07:33 dillon Exp $
31 #include <sys/param.h>
32 #include <sys/systm.h>
34 #include <sys/eventhandler.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/reboot.h>
39 #include <machine/bus.h>
40 #include <machine/resource.h>
43 #include <pc98/pc98/canbusvars.h>
44 #include "canbus_if.h"
48 struct canbepm_softc {
49 device_t canbepm_dev; /* canbepm device */
51 eventhandler_tag canbepm_tag; /* event handler tag */
55 static void canbepm_soft_off (void *, int);
56 static void canbepm_identify (driver_t *, device_t);
57 static int canbepm_probe (device_t);
58 static int canbepm_attach (device_t);
59 static int canbepm_detach (device_t);
62 static device_method_t canbepm_methods[] = {
63 DEVMETHOD(device_identify, canbepm_identify),
64 DEVMETHOD(device_probe, canbepm_probe),
65 DEVMETHOD(device_attach, canbepm_attach),
66 DEVMETHOD(device_detach, canbepm_detach),
70 static driver_t canbepm_driver = {
73 sizeof(struct canbepm_softc),
76 devclass_t canbepm_devclass;
78 DECLARE_DUMMY_MODULE(canbepm);
79 DRIVER_MODULE(canbepm, canbus, canbepm_driver, canbepm_devclass, 0, 0);
80 MODULE_DEPEND(canbepm, canbus, 1, 1, 1);
84 canbepm_soft_off (void *data, int howto)
86 struct canbepm_softc *sc = data;
87 u_int8_t poweroff_data[] = CANBE_POWEROFF_DATA;
89 if (!(howto & RB_POWEROFF))
92 CANBUS_WRITE_MULTI(device_get_parent(sc->canbepm_dev), sc->canbepm_dev,
93 CANBE_POWER_CTRL, sizeof (poweroff_data), poweroff_data);
98 canbepm_identify(driver_t *drv, device_t parent)
100 if (device_find_child(parent, "canbepm", 0) == NULL) {
101 if (BUS_ADD_CHILD(parent, 33, "canbepm", 0) == NULL)
102 device_printf(parent, "canbepm cannot attach\n");
108 canbepm_probe(device_t dev)
110 device_set_desc(dev, "CanBe Power Management Controller");
116 canbepm_attach(device_t dev)
118 struct canbepm_softc *sc = device_get_softc(dev);
120 /* eventhandler regist */
121 sc->canbepm_tag = EVENTHANDLER_REGISTER(
122 shutdown_final, canbepm_soft_off, sc, SHUTDOWN_PRI_LAST);
124 sc->canbepm_dev = dev;
131 canbepm_detach(device_t dev)
133 struct canbepm_softc *sc = device_get_softc(dev);
135 /* eventhandler deregist */
136 EVENTHANDLER_DEREGISTER(shutdown_final, sc->canbepm_tag);
137 BUS_CHILD_DETACHED(device_get_parent(dev), dev);