2 * Copyright (c) 2012 The Chromium OS Authors.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 #include <asm/i8254.h>
24 #include <asm/ibmpc.h>
26 #include <asm/u-boot-x86.h>
28 DECLARE_GLOBAL_DATA_PTR;
30 void timer_set_base(u64 base)
32 gd->arch.tsc_base = base;
36 * Get the number of CPU time counter ticks since it was read first time after
37 * restart. This yields a free running counter guaranteed to take almost 6
38 * years to wrap around even at 100GHz clock rate.
42 u64 now_tick = rdtsc();
44 /* We assume that 0 means the base hasn't been set yet */
45 if (!gd->arch.tsc_base)
46 panic("No tick base available");
47 return now_tick - gd->arch.tsc_base;
50 #define PLATFORM_INFO_MSR 0xce
52 /* Get the speed of the TSC timer in MHz */
53 unsigned long get_tbclk_mhz(void)
56 u64 platform_info = native_read_msr(PLATFORM_INFO_MSR);
58 /* 100MHz times Max Non Turbo ratio */
59 ratio = (platform_info >> 8) & 0xff;
63 unsigned long get_tbclk(void)
65 return get_tbclk_mhz() * 1000 * 1000;
68 static ulong get_ms_timer(void)
70 return (get_ticks() * 1000) / get_tbclk();
73 ulong get_timer(ulong base)
75 return get_ms_timer() - base;
78 ulong timer_get_us(void)
80 return get_ticks() / get_tbclk_mhz();
83 ulong timer_get_boot_us(void)
85 return timer_get_us();
88 void __udelay(unsigned long usec)
90 u64 now = get_ticks();
93 stop = now + usec * get_tbclk_mhz();
95 while ((int64_t)(stop - get_ticks()) > 0)
101 #ifdef CONFIG_SYS_PCAT_TIMER
102 /* Set up the PCAT timer if required */