]>
Commit | Line | Data |
---|---|---|
20ef1208 JW |
1 | #include <pci.h> |
2 | #include <io.h> | |
3 | #include <reg-82801b.h> | |
4 | ||
5 | static uint16_t _get_PMBASE() | |
6 | { | |
7 | static long pmbase = -1; | |
8 | ||
9 | if (pmbase == -1) /* Memoize it so that we don't have to hit PCI so often. */ | |
10 | pmbase = pci_read32(ICH2_LPC_BUS, ICH2_LPC_DEV, ICH2_LPC_FN, ICH2_LPC_PCI_PMBASE) & ICH2_PMBASE_MASK; | |
11 | ||
12 | return pmbase; | |
13 | } | |
14 | ||
15 | static unsigned long _curtmr() | |
16 | { | |
79de1b98 | 17 | return inl(_get_PMBASE() + ICH2_PMBASE_PM1_TMR) & 0xFFFFFF; |
20ef1208 JW |
18 | } |
19 | ||
20 | /* This is kind of a heuristic, since we can't get interrupts. */ | |
21 | static unsigned long starttmr = 0, endtmr = 0; | |
22 | ||
23 | void oneshot_start_ms(unsigned long milliseconds) | |
24 | { | |
25 | starttmr = _curtmr(); | |
79de1b98 | 26 | endtmr = (starttmr + milliseconds*(ICH2_PM1_TMR_FREQ/1000)) & 0xFFFFFF; |
20ef1208 JW |
27 | } |
28 | ||
29 | int oneshot_running(void) | |
30 | { | |
79de1b98 JW |
31 | unsigned long time = _curtmr(); |
32 | ||
20ef1208 JW |
33 | if (endtmr == 0 && starttmr == 0) |
34 | return 0; | |
79de1b98 | 35 | if ((endtmr < starttmr) && ((time > starttmr) || (time < endtmr))) |
20ef1208 | 36 | return 1; |
79de1b98 | 37 | else if ((time < endtmr) && (time > starttmr)) |
20ef1208 JW |
38 | return 1; |
39 | endtmr = starttmr = 0; | |
40 | return 0; | |
41 | } |