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
29 * Timer device driver for power management events.
30 * The code for suspend/resume is derived from APM device driver.
33 #include <sys/param.h>
34 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/syslog.h>
38 #include <sys/thread2.h>
39 #include <machine/clock.h>
41 #include <bus/isa/isavar.h>
43 static devclass_t pmtimer_devclass;
45 /* reject any PnP devices for now */
46 static struct isa_pnp_id pmtimer_ids[] = {
51 pmtimer_probe(device_t dev)
54 if (ISA_PNP_PROBE(device_get_parent(dev), dev, pmtimer_ids) == ENXIO) {
58 /* only one instance always */
59 return (device_get_unit(dev));
62 static struct timeval suspend_time;
63 static struct timeval diff_time;
66 pmtimer_suspend(device_t dev)
69 microtime(&diff_time);
71 microtime(&suspend_time);
72 timevalsub(&diff_time, &suspend_time);
78 pmtimer_resume(device_t dev)
80 u_int second, minute, hour;
81 struct timeval resume_time;
83 /* modified for adjkerntz */
85 timer_restore(); /* restore the all timers */
86 inittodr(0); /* adjust time to RTC */
87 microtime(&resume_time);
90 second = resume_time.tv_sec - suspend_time.tv_sec;
95 log(LOG_NOTICE, "wakeup from sleeping state (slept %02d:%02d:%02d)\n",
96 hour, minute, second);
101 * Because pmtimer is a static device that always exists under any attached
102 * isa device, and not scanned by the isa device, we need an identify
103 * function to install the device.
105 static device_method_t pmtimer_methods[] = {
106 /* Device interface */
107 DEVMETHOD(device_identify, bus_generic_identify),
108 DEVMETHOD(device_probe, pmtimer_probe),
109 DEVMETHOD(device_attach, bus_generic_attach),
110 DEVMETHOD(device_suspend, pmtimer_suspend),
111 DEVMETHOD(device_resume, pmtimer_resume),
115 static driver_t pmtimer_driver = {
121 DRIVER_MODULE(pmtimer, isa, pmtimer_driver, pmtimer_devclass, 0, 0);