blob: 842188a3c1a31c7638e5b086b22b06b018f1010b [file] [log] [blame]
Brian Swetland2500aa12009-01-01 04:33:55 -08001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google, Inc. nor the names of its contributors
15 * may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <debug.h>
33#include <reg.h>
34#include <sys/types.h>
35
36#include <platform/timer.h>
37#include <platform/irqs.h>
38#include <platform/iomap.h>
39#include <platform/interrupts.h>
40#include <kernel/thread.h>
41
42#define GPT_REG(off) (MSM_GPT_BASE + (off))
43
44#define GPT_MATCH_VAL GPT_REG(0x0000)
45#define GPT_COUNT_VAL GPT_REG(0x0004)
46#define GPT_ENABLE GPT_REG(0x0008)
47#define GPT_ENABLE_CLR_ON_MATCH_EN 2
48#define GPT_ENABLE_EN 1
49#define GPT_CLEAR GPT_REG(0x000C)
50
51#define DGT_MATCH_VAL GPT_REG(0x0010)
52#define DGT_COUNT_VAL GPT_REG(0x0014)
53#define DGT_ENABLE GPT_REG(0x0018)
54#define DGT_ENABLE_CLR_ON_MATCH_EN 2
55#define DGT_ENABLE_EN 1
56#define DGT_CLEAR GPT_REG(0x001C)
57
58
59static platform_timer_callback timer_callback;
60static void *timer_arg;
61static time_t timer_interval;
62
63static volatile uint32_t ticks;
64
65static enum handler_return timer_irq(void *arg)
66{
67 ticks += timer_interval;
68 return timer_callback(timer_arg, ticks);
69}
70
71status_t platform_set_periodic_timer(
72 platform_timer_callback callback,
73 void *arg, time_t interval)
74{
75 enter_critical_section();
76
77 timer_callback = callback;
78 timer_arg = arg;
79 timer_interval = interval;
80
81 writel(timer_interval * 19200, DGT_MATCH_VAL);
82 writel(0, DGT_CLEAR);
83 writel(DGT_ENABLE_EN | DGT_ENABLE_CLR_ON_MATCH_EN, DGT_ENABLE);
84
85 register_int_handler(INT_DEBUG_TIMER_EXP, timer_irq, 0);
86 unmask_interrupt(INT_DEBUG_TIMER_EXP);
87
88 exit_critical_section();
89 return 0;
90}
91
92
93time_t current_time(void)
94{
95 return ticks;
96}
97
98void platform_init_timer(void)
99{
100 writel(0, DGT_ENABLE);
101}
102