2 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
3 * Copyright (c) 2008 The DragonFly Project.
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 * $DragonFly: src/sys/platform/pc64/isa/pmtimer.c,v 1.1 2008/08/29 17:07:20 dillon Exp $
30 #include <sys/cdefs.h>
33 * Timer device driver for power management events.
34 * The code for suspend/resume is derived from APM device driver.
37 #include <sys/param.h>
38 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/syslog.h>
42 #include <sys/thread2.h>
43 #include <machine/clock.h>
45 #include <bus/isa/isavar.h>
47 static devclass_t pmtimer_devclass;
49 /* reject any PnP devices for now */
50 static struct isa_pnp_id pmtimer_ids[] = {
55 pmtimer_probe(device_t dev)
58 if (ISA_PNP_PROBE(device_get_parent(dev), dev, pmtimer_ids) == ENXIO) {
62 /* only one instance always */
63 return (device_get_unit(dev));
66 static struct timeval suspend_time;
67 static struct timeval diff_time;
70 pmtimer_suspend(device_t dev)
73 microtime(&diff_time);
75 microtime(&suspend_time);
76 timevalsub(&diff_time, &suspend_time);
82 pmtimer_resume(device_t dev)
84 u_int second, minute, hour;
85 struct timeval resume_time;
87 /* modified for adjkerntz */
89 timer_restore(); /* restore the all timers */
90 inittodr(0); /* adjust time to RTC */
91 microtime(&resume_time);
94 second = resume_time.tv_sec - suspend_time.tv_sec;
99 log(LOG_NOTICE, "wakeup from sleeping state (slept %02d:%02d:%02d)\n",
100 hour, minute, second);
105 * Because pmtimer is a static device that always exists under any attached
106 * isa device, and not scanned by the isa device, we need an identify
107 * function to install the device.
109 static device_method_t pmtimer_methods[] = {
110 /* Device interface */
111 DEVMETHOD(device_identify, bus_generic_identify),
112 DEVMETHOD(device_probe, pmtimer_probe),
113 DEVMETHOD(device_attach, bus_generic_attach),
114 DEVMETHOD(device_suspend, pmtimer_suspend),
115 DEVMETHOD(device_resume, pmtimer_resume),
119 static driver_t pmtimer_driver = {
125 DRIVER_MODULE(pmtimer, isa, pmtimer_driver, pmtimer_devclass, 0, 0);