Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / dev / powermng / pc98 / canbepm / canbepm.c
1 /*-
2  * Copyright (c) 2000 KIYOHARA Takashi <kiyohara@kk.iij4u.ne.jp>
3  * Copyright (c) 2000 Takanori Watanabe <takawata@jp.FreeBSD.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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.
14  *
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
25  * SUCH DAMAGE.
26  *
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.2 2003/06/17 04:28:55 dillon Exp $
29  */
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/bus.h>
34 #include <sys/eventhandler.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/reboot.h>
38
39 #include <machine/bus.h>
40 #include <machine/resource.h>
41 #include <sys/rman.h>
42
43 #include <pc98/pc98/canbusvars.h>
44 #include "canbus_if.h"
45
46
47 /* canbepm softc */
48 struct canbepm_softc {
49         device_t canbepm_dev;                   /* canbepm device */
50
51         eventhandler_tag canbepm_tag;           /* event handler tag */
52 };
53
54
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);
60
61
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),
67         {0, 0}
68 };
69
70 static driver_t canbepm_driver = {
71         "canbepm",
72         canbepm_methods,
73         sizeof(struct canbepm_softc),
74 };
75
76 devclass_t canbepm_devclass;
77 DRIVER_MODULE(canbepm, canbus, canbepm_driver, canbepm_devclass, 0, 0);
78 MODULE_DEPEND(canbepm, canbus, 1, 1, 1);
79
80
81 static void
82 canbepm_soft_off (void *data, int howto)
83 {
84         struct canbepm_softc *sc = data;
85         u_int8_t poweroff_data[] = CANBE_POWEROFF_DATA;
86
87         if (!(howto & RB_POWEROFF))
88                 return;
89
90         CANBUS_WRITE_MULTI(device_get_parent(sc->canbepm_dev), sc->canbepm_dev,
91             CANBE_POWER_CTRL, sizeof (poweroff_data), poweroff_data);
92 }
93
94
95 static void
96 canbepm_identify(driver_t *drv, device_t parent)
97 {
98         if (device_find_child(parent, "canbepm", 0) == NULL) {
99                 if (BUS_ADD_CHILD(parent, 33, "canbepm", 0) == NULL)
100                         device_printf(parent, "canbepm cannot attach\n");
101         }
102 }
103
104
105 static int
106 canbepm_probe(device_t dev)
107 {
108         device_set_desc(dev, "CanBe Power Management Controller");
109
110         return (0);     
111 }
112
113 static int
114 canbepm_attach(device_t dev)
115 {
116         struct canbepm_softc *sc = device_get_softc(dev);
117
118         /* eventhandler regist */
119         sc->canbepm_tag = EVENTHANDLER_REGISTER(
120             shutdown_final, canbepm_soft_off, sc, SHUTDOWN_PRI_LAST);
121
122         sc->canbepm_dev = dev;
123
124         return (0);
125 }
126
127
128 static int
129 canbepm_detach(device_t dev)
130 {
131         struct canbepm_softc *sc = device_get_softc(dev);
132
133         /* eventhandler deregist */
134         EVENTHANDLER_DEREGISTER(shutdown_final, sc->canbepm_tag);
135         BUS_CHILD_DETACHED(device_get_parent(dev), dev);
136
137         return (0);
138 }