]> Joshua Wise's Git repositories - netwatch.git/blame - ich2/ich2-timer.c
Merge nyus.joshuawise.com:/storage/git/netwatch
[netwatch.git] / ich2 / ich2-timer.c
CommitLineData
20ef1208
JW
1#include <pci.h>
2#include <io.h>
3#include <reg-82801b.h>
4
5static 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
15static unsigned long _curtmr()
16{
17 return inl(_get_PMBASE + ICH2_PMBASE_PM1_TMR) & 0xFFFFFF;
18}
19
20/* This is kind of a heuristic, since we can't get interrupts. */
21static unsigned long starttmr = 0, endtmr = 0;
22
23void oneshot_start_ms(unsigned long milliseconds)
24{
25 starttmr = _curtmr();
26 endtmr = (starttmr + milliseconds*(ICH2_PM1_TMR_FREQ/1000)) % 0xFFFFFF;
27}
28
29int oneshot_running(void)
30{
31 if (endtmr == 0 && starttmr == 0)
32 return 0;
33 if ((endtmr < starttmr) && ((_curtmr() > starttmr) || (_curtmr() < endtmr)))
34 return 1;
35 else if ((_curtmr() < endtmr) && (_curtmr() > starttmr))
36 return 1;
37 endtmr = starttmr = 0;
38 return 0;
39}
This page took 0.024433 seconds and 4 git commands to generate.