xref: /freebsd/sys/x86/isa/atrtc.c (revision 9768746b)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2008 Poul-Henning Kamp
5  * Copyright (c) 2010 Alexander Motin <mav@FreeBSD.org>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31 
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34 
35 #include "opt_acpi.h"
36 #include "opt_isa.h"
37 
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/bus.h>
41 #include <sys/clock.h>
42 #include <sys/lock.h>
43 #include <sys/mutex.h>
44 #include <sys/kdb.h>
45 #include <sys/kernel.h>
46 #include <sys/module.h>
47 #include <sys/proc.h>
48 #include <sys/rman.h>
49 #include <sys/timeet.h>
50 
51 #include <isa/rtc.h>
52 #ifdef DEV_ISA
53 #include <isa/isareg.h>
54 #include <isa/isavar.h>
55 #endif
56 #include <machine/intr_machdep.h>
57 #include "clock_if.h"
58 #ifdef DEV_ACPI
59 #include <contrib/dev/acpica/include/acpi.h>
60 #include <contrib/dev/acpica/include/accommon.h>
61 #include <dev/acpica/acpivar.h>
62 #include <machine/md_var.h>
63 #endif
64 
65 /* tunable to detect a power loss of the rtc */
66 static bool atrtc_power_lost = false;
67 SYSCTL_BOOL(_machdep, OID_AUTO, atrtc_power_lost, CTLFLAG_RD, &atrtc_power_lost,
68     false, "RTC lost power on last power cycle (probably caused by an emtpy cmos battery)");
69 
70 /*
71  * atrtc_lock protects low-level access to individual hardware registers.
72  * atrtc_time_lock protects the entire sequence of accessing multiple registers
73  * to read or write the date and time.
74  */
75 static struct mtx atrtc_lock;
76 MTX_SYSINIT(atrtc_lock_init, &atrtc_lock, "atrtc", MTX_SPIN);
77 
78 /* Force RTC enabled/disabled. */
79 static int atrtc_enabled = -1;
80 TUNABLE_INT("hw.atrtc.enabled", &atrtc_enabled);
81 
82 struct mtx atrtc_time_lock;
83 MTX_SYSINIT(atrtc_time_lock_init, &atrtc_time_lock, "atrtc_time", MTX_DEF);
84 
85 int	atrtcclock_disable = 0;
86 
87 static	int	rtc_century = 0;
88 static	int	rtc_reg = -1;
89 static	u_char	rtc_statusa = RTCSA_DIVIDER | RTCSA_NOPROF;
90 static	u_char	rtc_statusb = RTCSB_24HR;
91 
92 #ifdef DEV_ACPI
93 #define	_COMPONENT	ACPI_TIMER
94 ACPI_MODULE_NAME("ATRTC")
95 #endif
96 
97 /*
98  * RTC support routines
99  */
100 
101 static inline u_char
102 rtcin_locked(int reg)
103 {
104 
105 	if (rtc_reg != reg) {
106 		inb(0x84);
107 		outb(IO_RTC, reg);
108 		rtc_reg = reg;
109 		inb(0x84);
110 	}
111 	return (inb(IO_RTC + 1));
112 }
113 
114 static inline void
115 rtcout_locked(int reg, u_char val)
116 {
117 
118 	if (rtc_reg != reg) {
119 		inb(0x84);
120 		outb(IO_RTC, reg);
121 		rtc_reg = reg;
122 		inb(0x84);
123 	}
124 	outb(IO_RTC + 1, val);
125 	inb(0x84);
126 }
127 
128 int
129 rtcin(int reg)
130 {
131 	u_char val;
132 
133 	mtx_lock_spin(&atrtc_lock);
134 	val = rtcin_locked(reg);
135 	mtx_unlock_spin(&atrtc_lock);
136 	return (val);
137 }
138 
139 void
140 writertc(int reg, u_char val)
141 {
142 
143 	mtx_lock_spin(&atrtc_lock);
144 	rtcout_locked(reg, val);
145 	mtx_unlock_spin(&atrtc_lock);
146 }
147 
148 static void
149 atrtc_start(void)
150 {
151 
152 	mtx_lock_spin(&atrtc_lock);
153 	rtcout_locked(RTC_STATUSA, rtc_statusa);
154 	rtcout_locked(RTC_STATUSB, RTCSB_24HR);
155 	mtx_unlock_spin(&atrtc_lock);
156 }
157 
158 static void
159 atrtc_rate(unsigned rate)
160 {
161 
162 	rtc_statusa = RTCSA_DIVIDER | rate;
163 	writertc(RTC_STATUSA, rtc_statusa);
164 }
165 
166 static void
167 atrtc_enable_intr(void)
168 {
169 
170 	rtc_statusb |= RTCSB_PINTR;
171 	mtx_lock_spin(&atrtc_lock);
172 	rtcout_locked(RTC_STATUSB, rtc_statusb);
173 	rtcin_locked(RTC_INTR);
174 	mtx_unlock_spin(&atrtc_lock);
175 }
176 
177 static void
178 atrtc_disable_intr(void)
179 {
180 
181 	rtc_statusb &= ~RTCSB_PINTR;
182 	mtx_lock_spin(&atrtc_lock);
183 	rtcout_locked(RTC_STATUSB, rtc_statusb);
184 	rtcin_locked(RTC_INTR);
185 	mtx_unlock_spin(&atrtc_lock);
186 }
187 
188 void
189 atrtc_restore(void)
190 {
191 
192 	/* Restore all of the RTC's "status" (actually, control) registers. */
193 	mtx_lock_spin(&atrtc_lock);
194 	rtcin_locked(RTC_STATUSA);	/* dummy to get rtc_reg set */
195 	rtcout_locked(RTC_STATUSB, RTCSB_24HR);
196 	rtcout_locked(RTC_STATUSA, rtc_statusa);
197 	rtcout_locked(RTC_STATUSB, rtc_statusb);
198 	rtcin_locked(RTC_INTR);
199 	mtx_unlock_spin(&atrtc_lock);
200 }
201 
202 /**********************************************************************
203  * RTC driver for subr_rtc
204  */
205 
206 struct atrtc_softc {
207 	int port_rid, intr_rid;
208 	struct resource *port_res;
209 	struct resource *intr_res;
210 	void *intr_handler;
211 	struct eventtimer et;
212 #ifdef DEV_ACPI
213 	ACPI_HANDLE acpi_handle;
214 #endif
215 };
216 
217 static int
218 rtc_start(struct eventtimer *et, sbintime_t first, sbintime_t period)
219 {
220 
221 	atrtc_rate(max(fls(period + (period >> 1)) - 17, 1));
222 	atrtc_enable_intr();
223 	return (0);
224 }
225 
226 static int
227 rtc_stop(struct eventtimer *et)
228 {
229 
230 	atrtc_disable_intr();
231 	return (0);
232 }
233 
234 /*
235  * This routine receives statistical clock interrupts from the RTC.
236  * As explained above, these occur at 128 interrupts per second.
237  * When profiling, we receive interrupts at a rate of 1024 Hz.
238  *
239  * This does not actually add as much overhead as it sounds, because
240  * when the statistical clock is active, the hardclock driver no longer
241  * needs to keep (inaccurate) statistics on its own.  This decouples
242  * statistics gathering from scheduling interrupts.
243  *
244  * The RTC chip requires that we read status register C (RTC_INTR)
245  * to acknowledge an interrupt, before it will generate the next one.
246  * Under high interrupt load, rtcintr() can be indefinitely delayed and
247  * the clock can tick immediately after the read from RTC_INTR.  In this
248  * case, the mc146818A interrupt signal will not drop for long enough
249  * to register with the 8259 PIC.  If an interrupt is missed, the stat
250  * clock will halt, considerably degrading system performance.  This is
251  * why we use 'while' rather than a more straightforward 'if' below.
252  * Stat clock ticks can still be lost, causing minor loss of accuracy
253  * in the statistics, but the stat clock will no longer stop.
254  */
255 static int
256 rtc_intr(void *arg)
257 {
258 	struct atrtc_softc *sc = (struct atrtc_softc *)arg;
259 	int flag = 0;
260 
261 	while (rtcin(RTC_INTR) & RTCIR_PERIOD) {
262 		flag = 1;
263 		if (sc->et.et_active)
264 			sc->et.et_event_cb(&sc->et, sc->et.et_arg);
265 	}
266 	return(flag ? FILTER_HANDLED : FILTER_STRAY);
267 }
268 
269 #ifdef DEV_ACPI
270 /*
271  *  ACPI RTC CMOS address space handler
272  */
273 #define	ATRTC_LAST_REG	0x40
274 
275 static void
276 rtcin_region(int reg, void *buf, int len)
277 {
278 	u_char *ptr = buf;
279 
280 	/* Drop lock after each IO as intr and settime have greater priority */
281 	while (len-- > 0)
282 		*ptr++ = rtcin(reg++) & 0xff;
283 }
284 
285 static void
286 rtcout_region(int reg, const void *buf, int len)
287 {
288 	const u_char *ptr = buf;
289 
290 	while (len-- > 0)
291 		writertc(reg++, *ptr++);
292 }
293 
294 static bool
295 atrtc_check_cmos_access(bool is_read, ACPI_PHYSICAL_ADDRESS addr, UINT32 len)
296 {
297 
298 	/* Block address space wrapping on out-of-bound access */
299 	if (addr >= ATRTC_LAST_REG || addr + len > ATRTC_LAST_REG)
300 		return (false);
301 
302 	if (is_read) {
303 		/* Reading 0x0C will muck with interrupts */
304 		if (addr <= RTC_INTR && addr + len > RTC_INTR)
305 			return (false);
306 	} else {
307 		/*
308 		 * Allow single-byte writes to alarm registers and
309 		 * multi-byte writes to addr >= 0x30, else deny.
310 		 */
311 		if (!((len == 1 && (addr == RTC_SECALRM ||
312 				    addr == RTC_MINALRM ||
313 				    addr == RTC_HRSALRM)) ||
314 		      addr >= 0x30))
315 			return (false);
316 	}
317 	return (true);
318 }
319 
320 static ACPI_STATUS
321 atrtc_acpi_cmos_handler(UINT32 func, ACPI_PHYSICAL_ADDRESS addr,
322     UINT32 bitwidth, UINT64 *value, void *context, void *region_context)
323 {
324 	device_t dev = context;
325 	UINT32 bytewidth = howmany(bitwidth, 8);
326 	bool is_read = func == ACPI_READ;
327 
328 	/* ACPICA is very verbose on CMOS handler failures, so we, too */
329 #define	CMOS_HANDLER_ERR(fmt, ...) \
330 	device_printf(dev, "ACPI [SystemCMOS] handler: " fmt, ##__VA_ARGS__)
331 
332 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
333 
334 	if (value == NULL) {
335 		CMOS_HANDLER_ERR("NULL parameter\n");
336 		return (AE_BAD_PARAMETER);
337 	}
338 	if (bitwidth == 0 || (bitwidth & 0x07) != 0) {
339 		CMOS_HANDLER_ERR("Invalid bitwidth: %u\n", bitwidth);
340 		return (AE_BAD_PARAMETER);
341 	}
342 	if (!atrtc_check_cmos_access(is_read, addr, bytewidth)) {
343 		CMOS_HANDLER_ERR("%s access rejected: addr=%#04jx, len=%u\n",
344 		    is_read ? "Read" : "Write", (uintmax_t)addr, bytewidth);
345 		return (AE_BAD_PARAMETER);
346 	}
347 
348 	switch (func) {
349 	case ACPI_READ:
350 		rtcin_region(addr, value, bytewidth);
351 		break;
352 	case ACPI_WRITE:
353 		rtcout_region(addr, value, bytewidth);
354 		break;
355 	default:
356 		CMOS_HANDLER_ERR("Invalid function: %u\n", func);
357 		return (AE_BAD_PARAMETER);
358 	}
359 
360 	ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
361 	    "ACPI RTC CMOS %s access: addr=%#04x, len=%u, val=%*D\n",
362 	    is_read ? "read" : "write", (unsigned)addr, bytewidth,
363 	    bytewidth, value, " ");
364 
365 	return (AE_OK);
366 }
367 
368 static int
369 atrtc_reg_acpi_cmos_handler(device_t dev)
370 {
371 	struct atrtc_softc *sc = device_get_softc(dev);
372 
373 	ACPI_FUNCTION_TRACE((char *)(uintptr_t) __func__);
374 
375 	/* Don't handle address space events if driver is disabled. */
376 	if (acpi_disabled("atrtc"))
377 		return (ENXIO);
378 
379 	if (ACPI_FAILURE(AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_SB_", &sc->acpi_handle))) {
380 		return (ENXIO);
381 	}
382 
383 	if (sc->acpi_handle == NULL ||
384 	    ACPI_FAILURE(AcpiInstallAddressSpaceHandler(sc->acpi_handle,
385 	      ACPI_ADR_SPACE_CMOS, atrtc_acpi_cmos_handler, NULL, dev))) {
386 		sc->acpi_handle = NULL;
387 		device_printf(dev,
388 		    "Can't register ACPI CMOS address space handler\n");
389 		return (ENXIO);
390         }
391 
392         return (0);
393 }
394 
395 static int
396 atrtc_unreg_acpi_cmos_handler(device_t dev)
397 {
398 	struct atrtc_softc *sc = device_get_softc(dev);
399 
400 	ACPI_FUNCTION_TRACE((char *)(uintptr_t) __func__);
401 
402 	if (sc->acpi_handle != NULL)
403 		AcpiRemoveAddressSpaceHandler(sc->acpi_handle,
404 		    ACPI_ADR_SPACE_CMOS, atrtc_acpi_cmos_handler);
405 
406 	return (0);
407 }
408 #endif	/* DEV_ACPI */
409 
410 /*
411  * Attach to the ISA PnP descriptors for the timer and realtime clock.
412  */
413 static struct isa_pnp_id atrtc_ids[] = {
414 	{ 0x000bd041 /* PNP0B00 */, "AT realtime clock" },
415 	{ 0 }
416 };
417 
418 static bool
419 atrtc_acpi_disabled(void)
420 {
421 #ifdef DEV_ACPI
422 	uint16_t flags;
423 
424 	if (!acpi_get_fadt_bootflags(&flags))
425 		return (false);
426 	return ((flags & ACPI_FADT_NO_CMOS_RTC) != 0);
427 #else
428 	return (false);
429 #endif
430 }
431 
432 static int
433 rtc_acpi_century_get(void)
434 {
435 #ifdef DEV_ACPI
436 	ACPI_TABLE_FADT *fadt;
437 	vm_paddr_t physaddr;
438 	int century;
439 
440 	physaddr = acpi_find_table(ACPI_SIG_FADT);
441 	if (physaddr == 0)
442 		return (0);
443 
444 	fadt = acpi_map_table(physaddr, ACPI_SIG_FADT);
445 	if (fadt == NULL)
446 		return (0);
447 
448 	century = fadt->Century;
449 	acpi_unmap_table(fadt);
450 
451 	return (century);
452 #else
453 	return (0);
454 #endif
455 }
456 
457 static int
458 atrtc_probe(device_t dev)
459 {
460 	int result;
461 
462 	if ((atrtc_enabled == -1 && atrtc_acpi_disabled()) ||
463 	    (atrtc_enabled == 0))
464 		return (ENXIO);
465 
466 	result = ISA_PNP_PROBE(device_get_parent(dev), dev, atrtc_ids);
467 	/* ENOENT means no PnP-ID, device is hinted. */
468 	if (result == ENOENT) {
469 		device_set_desc(dev, "AT realtime clock");
470 		return (BUS_PROBE_LOW_PRIORITY);
471 	}
472 	rtc_century = rtc_acpi_century_get();
473 	return (result);
474 }
475 
476 static int
477 atrtc_attach(device_t dev)
478 {
479 	struct atrtc_softc *sc;
480 	rman_res_t s;
481 	int i;
482 
483 	sc = device_get_softc(dev);
484 	sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
485 	    IO_RTC, IO_RTC + 1, 2, RF_ACTIVE);
486 	if (sc->port_res == NULL)
487 		device_printf(dev, "Warning: Couldn't map I/O.\n");
488 	atrtc_start();
489 	clock_register(dev, 1000000);
490 	bzero(&sc->et, sizeof(struct eventtimer));
491 	if (!atrtcclock_disable &&
492 	    (resource_int_value(device_get_name(dev), device_get_unit(dev),
493 	     "clock", &i) != 0 || i != 0)) {
494 		sc->intr_rid = 0;
495 		while (bus_get_resource(dev, SYS_RES_IRQ, sc->intr_rid,
496 		    &s, NULL) == 0 && s != 8)
497 			sc->intr_rid++;
498 		sc->intr_res = bus_alloc_resource(dev, SYS_RES_IRQ,
499 		    &sc->intr_rid, 8, 8, 1, RF_ACTIVE);
500 		if (sc->intr_res == NULL) {
501 			device_printf(dev, "Can't map interrupt.\n");
502 			return (0);
503 		} else if ((bus_setup_intr(dev, sc->intr_res, INTR_TYPE_CLK,
504 		    rtc_intr, NULL, sc, &sc->intr_handler))) {
505 			device_printf(dev, "Can't setup interrupt.\n");
506 			return (0);
507 		} else {
508 			/* Bind IRQ to BSP to avoid live migration. */
509 			bus_bind_intr(dev, sc->intr_res, 0);
510 		}
511 		sc->et.et_name = "RTC";
512 		sc->et.et_flags = ET_FLAGS_PERIODIC | ET_FLAGS_POW2DIV;
513 		sc->et.et_quality = 0;
514 		sc->et.et_frequency = 32768;
515 		sc->et.et_min_period = 0x00080000;
516 		sc->et.et_max_period = 0x80000000;
517 		sc->et.et_start = rtc_start;
518 		sc->et.et_stop = rtc_stop;
519 		sc->et.et_priv = dev;
520 		et_register(&sc->et);
521 	}
522 	return(0);
523 }
524 
525 static int
526 atrtc_isa_attach(device_t dev)
527 {
528 
529 	return (atrtc_attach(dev));
530 }
531 
532 #ifdef DEV_ACPI
533 static int
534 atrtc_acpi_attach(device_t dev)
535 {
536 	int ret;
537 
538 	ret = atrtc_attach(dev);
539 	if (ret)
540 		return (ret);
541 
542 	(void)atrtc_reg_acpi_cmos_handler(dev);
543 
544 	return (0);
545 }
546 
547 static int
548 atrtc_acpi_detach(device_t dev)
549 {
550 
551 	(void)atrtc_unreg_acpi_cmos_handler(dev);
552 	return (0);
553 }
554 #endif	/* DEV_ACPI */
555 
556 static int
557 atrtc_resume(device_t dev)
558 {
559 
560 	atrtc_restore();
561 	return(0);
562 }
563 
564 static int
565 atrtc_settime(device_t dev __unused, struct timespec *ts)
566 {
567 	struct bcd_clocktime bct;
568 
569 	clock_ts_to_bcd(ts, &bct, false);
570 	clock_dbgprint_bcd(dev, CLOCK_DBG_WRITE, &bct);
571 
572 	mtx_lock(&atrtc_time_lock);
573 	mtx_lock_spin(&atrtc_lock);
574 
575 	/* Disable RTC updates and interrupts.  */
576 	rtcout_locked(RTC_STATUSB, RTCSB_HALT | RTCSB_24HR);
577 
578 	/* Write all the time registers. */
579 	rtcout_locked(RTC_SEC,   bct.sec);
580 	rtcout_locked(RTC_MIN,   bct.min);
581 	rtcout_locked(RTC_HRS,   bct.hour);
582 	rtcout_locked(RTC_WDAY,  bct.dow + 1);
583 	rtcout_locked(RTC_DAY,   bct.day);
584 	rtcout_locked(RTC_MONTH, bct.mon);
585 	rtcout_locked(RTC_YEAR,  bct.year & 0xff);
586 	if (rtc_century)
587 		rtcout_locked(rtc_century, bct.year >> 8);
588 
589 	/*
590 	 * Re-enable RTC updates and interrupts.
591 	 */
592 	rtcout_locked(RTC_STATUSB, rtc_statusb);
593 	rtcin_locked(RTC_INTR);
594 
595 	mtx_unlock_spin(&atrtc_lock);
596 	mtx_unlock(&atrtc_time_lock);
597 
598 	return (0);
599 }
600 
601 static int
602 atrtc_gettime(device_t dev, struct timespec *ts)
603 {
604 	struct bcd_clocktime bct;
605 
606 	/* Look if we have a RTC present and the time is valid */
607 	if (!(rtcin(RTC_STATUSD) & RTCSD_PWR)) {
608 		atrtc_power_lost = true;
609 		device_printf(dev, "WARNING: Battery failure indication\n");
610 		return (EINVAL);
611 	}
612 
613 	/*
614 	 * wait for time update to complete
615 	 * If RTCSA_TUP is zero, we have at least 244us before next update.
616 	 * This is fast enough on most hardware, but a refinement would be
617 	 * to make sure that no more than 240us pass after we start reading,
618 	 * and try again if so.
619 	 */
620 	mtx_lock(&atrtc_time_lock);
621 	while (rtcin(RTC_STATUSA) & RTCSA_TUP)
622 		continue;
623 	mtx_lock_spin(&atrtc_lock);
624 	bct.sec  = rtcin_locked(RTC_SEC);
625 	bct.min  = rtcin_locked(RTC_MIN);
626 	bct.hour = rtcin_locked(RTC_HRS);
627 	bct.day  = rtcin_locked(RTC_DAY);
628 	bct.mon  = rtcin_locked(RTC_MONTH);
629 	bct.year = rtcin_locked(RTC_YEAR);
630 	if (rtc_century)
631 		bct.year |= rtcin_locked(rtc_century) << 8;
632 	mtx_unlock_spin(&atrtc_lock);
633 	mtx_unlock(&atrtc_time_lock);
634 	/* dow is unused in timespec conversion and we have no nsec info. */
635 	bct.dow  = 0;
636 	bct.nsec = 0;
637 	clock_dbgprint_bcd(dev, CLOCK_DBG_READ, &bct);
638 	return (clock_bcd_to_ts(&bct, ts, false));
639 }
640 
641 static device_method_t atrtc_isa_methods[] = {
642 	/* Device interface */
643 	DEVMETHOD(device_probe,		atrtc_probe),
644 	DEVMETHOD(device_attach,	atrtc_isa_attach),
645 	DEVMETHOD(device_detach,	bus_generic_detach),
646 	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
647 	DEVMETHOD(device_suspend,	bus_generic_suspend),
648 		/* XXX stop statclock? */
649 	DEVMETHOD(device_resume,	atrtc_resume),
650 
651 	/* clock interface */
652 	DEVMETHOD(clock_gettime,	atrtc_gettime),
653 	DEVMETHOD(clock_settime,	atrtc_settime),
654 	{ 0, 0 }
655 };
656 
657 static driver_t atrtc_isa_driver = {
658 	"atrtc",
659 	atrtc_isa_methods,
660 	sizeof(struct atrtc_softc),
661 };
662 
663 #ifdef DEV_ACPI
664 static device_method_t atrtc_acpi_methods[] = {
665 	/* Device interface */
666 	DEVMETHOD(device_probe,		atrtc_probe),
667 	DEVMETHOD(device_attach,	atrtc_acpi_attach),
668 	DEVMETHOD(device_detach,	atrtc_acpi_detach),
669 		/* XXX stop statclock? */
670 	DEVMETHOD(device_resume,	atrtc_resume),
671 
672 	/* clock interface */
673 	DEVMETHOD(clock_gettime,	atrtc_gettime),
674 	DEVMETHOD(clock_settime,	atrtc_settime),
675 	{ 0, 0 }
676 };
677 
678 static driver_t atrtc_acpi_driver = {
679 	"atrtc",
680 	atrtc_acpi_methods,
681 	sizeof(struct atrtc_softc),
682 };
683 #endif	/* DEV_ACPI */
684 
685 DRIVER_MODULE(atrtc, isa, atrtc_isa_driver, 0, 0);
686 #ifdef DEV_ACPI
687 DRIVER_MODULE(atrtc, acpi, atrtc_acpi_driver, 0, 0);
688 #endif
689 ISA_PNP_INFO(atrtc_ids);
690