22 #include <linux/time.h>
35 #include <mach/irqs.h>
40 #define RTC_SECONDS 0x08
41 #define RTC_SHADOW_SECONDS 0x0c
42 #define RTC_MILLISECONDS 0x10
44 #define TIMERUS_CNTR_1US 0x10
45 #define TIMERUS_USEC_CFG 0x14
46 #define TIMERUS_CNTR_FREEZE 0x4c
48 #define TIMER1_BASE 0x0
49 #define TIMER2_BASE 0x8
50 #define TIMER3_BASE 0x50
51 #define TIMER4_BASE 0x58
59 static struct timespec persistent_ts;
60 static u64 persistent_ms, last_persistent_ms;
62 #define timer_writel(value, reg) \
63 __raw_writel(value, timer_reg_base + (reg))
64 #define timer_readl(reg) \
65 __raw_readl(timer_reg_base + (reg))
67 static int tegra_timer_set_next_event(
unsigned long cycles,
68 struct clock_event_device *
evt)
72 reg = 0x80000000 | ((cycles > 1) ? (cycles-1) : 0);
78 static void tegra_timer_set_mode(
enum clock_event_mode
mode,
79 struct clock_event_device *
evt)
86 case CLOCK_EVT_MODE_PERIODIC:
87 reg = 0xC0000000 | ((1000000/
HZ)-1);
90 case CLOCK_EVT_MODE_ONESHOT:
92 case CLOCK_EVT_MODE_UNUSED:
93 case CLOCK_EVT_MODE_SHUTDOWN:
94 case CLOCK_EVT_MODE_RESUME:
99 static struct clock_event_device tegra_clockevent = {
102 .features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_PERIODIC,
103 .set_next_event = tegra_timer_set_next_event,
104 .set_mode = tegra_timer_set_mode,
107 static u32 notrace tegra_read_sched_clock(
void)
118 static u64 tegra_rtc_read_ms(
void)
135 static void tegra_read_persistent_clock(
struct timespec *
ts)
140 last_persistent_ms = persistent_ms;
141 persistent_ms = tegra_rtc_read_ms();
142 delta = persistent_ms - last_persistent_ms;
150 struct clock_event_device *evt = (
struct clock_event_device *)dev_id;
152 evt->event_handler(evt);
156 static struct irqaction tegra_timer_irq = {
159 .handler = tegra_timer_interrupt,
160 .dev_id = &tegra_clockevent,
164 #ifdef CONFIG_HAVE_ARM_TWD
173 pr_err(
"twd_local_timer_register failed %d\n", err);
176 #define tegra_twd_init() do {} while(0)
179 static void __init tegra_init_timer(
void)
187 pr_warn(
"Unable to get timer clock."
188 " Assuming 12Mhz input clock.\n");
191 clk_prepare_enable(clk);
201 pr_warn(
"Unable to get rtc-tegra clock\n");
203 clk_prepare_enable(clk);
219 WARN(1,
"Unknown clock rate");
236 clockevents_calc_mult_shift(&tegra_clockevent, 1000000, 5);
237 tegra_clockevent.max_delta_ns =
239 tegra_clockevent.min_delta_ns =
242 tegra_clockevent.irq = tegra_timer_irq.
irq;
249 .init = tegra_init_timer,
253 static u32 usec_config;
255 void tegra_timer_suspend(
void)
260 void tegra_timer_resume(
void)