Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / cpu / amd / model_fxx / apic_timer.c
1 #include <stdint.h>
2 #include <delay.h>
3 #include <cpu/x86/msr.h>
4 #include <cpu/x86/lapic.h>
5
6 void init_timer(void)
7 {
8         /* Set the apic timer to no interrupts and periodic mode */
9         lapic_write(LAPIC_LVTT, (1 << 17)|(1<< 16)|(0 << 12)|(0 << 0));
10
11         /* Set the divider to 1, no divider */
12         lapic_write(LAPIC_TDCR, LAPIC_TDR_DIV_1);
13
14         /* Set the initial counter to 0xffffffff */
15         lapic_write(LAPIC_TMICT, 0xffffffff);
16
17 }
18
19 void udelay(unsigned usecs)
20 {
21         uint32_t start, value, ticks;
22         /* Calculate the number of ticks to run, our FSB runs a 200Mhz */
23         ticks = usecs * 200;
24         start = lapic_read(LAPIC_TMCCT);
25         do {
26                 value = lapic_read(LAPIC_TMCCT);
27         } while((start - value) < ticks);
28
29 }