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