1 /* $NetBSD: acpipmtimer.c,v 1.7 2009/05/12 14:25:17 cegger Exp $ */
4 __KERNEL_RCSID(0, "$NetBSD: acpipmtimer.c,v 1.7 2009/05/12 14:25:17 cegger Exp $");
9 #include <sys/device.h>
10 #include <sys/malloc.h>
13 #include <sys/timetc.h>
15 #include <dev/ic/acpipmtimer.h>
17 #define ACPI_PM_TIMER_FREQUENCY 3579545
20 struct timecounter tc
;
26 static u_int
acpihwtimer_read_safe(struct timecounter
*);
27 static u_int
acpihwtimer_read_fast(struct timecounter
*);
30 acpipmtimer_attach(device_t dev
,
31 bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t off
,
36 tc
= malloc(sizeof(struct hwtc
), M_DEVBUF
, M_WAITOK
|M_ZERO
);
40 tc
->tc
.tc_name
= device_xname(dev
);
41 tc
->tc
.tc_frequency
= ACPI_PM_TIMER_FREQUENCY
;
42 if (flags
& ACPIPMT_32BIT
)
43 tc
->tc
.tc_counter_mask
= 0xffffffff;
45 tc
->tc
.tc_counter_mask
= 0x00ffffff;
46 if (flags
& ACPIPMT_BADLATCH
) {
47 tc
->tc
.tc_get_timecount
= acpihwtimer_read_safe
;
48 tc
->tc
.tc_quality
= 900;
50 tc
->tc
.tc_get_timecount
= acpihwtimer_read_fast
;
51 tc
->tc
.tc_quality
= 1000;
60 aprint_normal("%s: %d-bit timer\n", tc
->tc
.tc_name
,
61 (flags
& ACPIPMT_32BIT
? 32 : 24));
66 acpipmtimer_detach(acpipmtimer_t timer
, int flags
)
68 struct hwtc
*tc
= timer
;
70 return tc_detach(&tc
->tc
);
73 #define r(h) bus_space_read_4(h->t, h->h, h->off)
76 acpihwtimer_read_safe(struct timecounter
*tc
)
78 struct hwtc
*h
= tc
->tc_priv
;
87 } while ((t1
> t2
) || (t2
> t3
));
92 acpihwtimer_read_fast(struct timecounter
*tc
)
94 struct hwtc
*h
= tc
->tc_priv
;