OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [src/] [drivers/] [timer/] [omap/] [timer.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * omap GP timer driver honoring generic
3
 * timer library API
4
 *
5
 * Copyright (C) 2010 B Labs Ltd.
6
 *
7
 * Author: Bahadir Balban
8
 */
9
#include <l4/drivers/timer/omap/timer.h>
10
#include INC_ARCH(io.h)
11
 
12
#define OMAP_TIMER_MAT_IT_FLAG  (1 << 0)
13
#define OMAP_TIMER_OVR_IT_FLAG  (1 << 1)
14
#define OMAP_TIMER_TCAR_IT_FLAG (1 << 2)
15
void timer_irq_clear(unsigned long timer_base)
16
{
17
        volatile u32 reg = read(timer_base + OMAP_TIMER_TISR);
18
        reg |= OMAP_TIMER_OVR_IT_FLAG;
19
        write(reg, timer_base + OMAP_TIMER_TISR);
20
}
21
 
22
u32 timer_periodic_intr_status(unsigned long timer_base)
23
{
24
        volatile u32 reg = read(timer_base + OMAP_TIMER_TISR);
25
        return (reg & OMAP_TIMER_OVR_IT_FLAG);
26
}
27
 
28
#define OMAP_TIMER_SOFT_RESET   (1 << 1)
29
void timer_reset(unsigned long timer_base)
30
{
31
        /* Reset Timer */
32
        write(OMAP_TIMER_SOFT_RESET, timer_base + OMAP_TIMER_TIOCP);
33
 
34
        /* Wait for reset completion */
35
        while (!read(timer_base + OMAP_TIMER_TSTAT));
36
}
37
 
38
void timer_load(unsigned long timer_base, u32 value)
39
{
40
        write(value, timer_base + OMAP_TIMER_TLDR);
41
        write(value, timer_base + OMAP_TIMER_TCRR);
42
}
43
 
44
u32 timer_read(unsigned long timer_base)
45
{
46
        return read(timer_base + OMAP_TIMER_TCRR);
47
}
48
 
49
#define OMAP_TIMER_START        (1 << 0)
50
void timer_start(unsigned long timer_base)
51
{
52
        volatile u32 reg = read(timer_base + OMAP_TIMER_TCLR);
53
        reg |= OMAP_TIMER_START;
54
        write(reg, timer_base + OMAP_TIMER_TCLR);
55
}
56
 
57
void timer_stop(unsigned long timer_base)
58
{
59
        volatile u32 reg = read(timer_base + OMAP_TIMER_TCLR);
60
        reg &= (~OMAP_TIMER_START);
61
        write(reg, timer_base + OMAP_TIMER_TCLR);
62
}
63
 
64
/*
65
* Beagle Board RevC manual:
66
* overflow period = (0xffffffff - TLDR + 1)*PS*(1/TIMER_FCLK)
67
* where,
68
* PS: Prescaler divisor (we are not using this)
69
*
70
* Beagle board manual says, 26MHz oscillator present on board.
71
* U-Boot divides the sys_clock by 2 if sys_clk is >19MHz,
72
* so,we have sys_clk frequency = 13MHz
73
*
74
* TIMER_FCLK = 13MHz
75
*
76
*/
77
void timer_init_oneshot(unsigned long timer_base)
78
{
79
        volatile u32 reg;
80
 
81
        /* Reset the timer */
82
        timer_reset(timer_base);
83
 
84
        /* Set timer to compare mode */
85
        reg = read(timer_base + OMAP_TIMER_TCLR);
86
        reg |= (1 << OMAP_TIMER_MODE_COMPARE);
87
        write(reg, timer_base + OMAP_TIMER_TCLR);
88
 
89
        write(0xffffffff, timer_base + OMAP_TIMER_TMAR);
90
 
91
        /* Clear pending Interrupts, if any */
92
        write(7, timer_base + OMAP_TIMER_TISR);
93
}
94
 
95
void timer_init_periodic(unsigned long timer_base)
96
{
97
        volatile u32 reg;
98
 
99
        /* Reset the timer */
100
        timer_reset(timer_base);
101
 
102
        /* Set timer to autoreload mode */
103
        reg = read(timer_base + OMAP_TIMER_TCLR);
104
        reg |= (1 << OMAP_TIMER_MODE_AUTORELAOD);
105
        write(reg, timer_base + OMAP_TIMER_TCLR);
106
 
107
        /*
108
        * Beagle Board RevC manual:
109
        * overflow period = (0xffffffff - TLDR + 1)*PS*(1/TIMER_FCLK)
110
        * where,
111
        * PS: Prescaler divisor (we are not using this)
112
        *
113
        * Beagle board manual says, 26MHz oscillator present on board.
114
        * U-Boot divides the sys_clock by 2 if sys_clk is >19MHz,
115
        * so,we have sys_clk frequency = 13MHz
116
        *
117
        * TIMER_FCLK = 13MHz
118
        * So, for 1ms period, TLDR = 0xffffcd38
119
        *
120
        */
121
        timer_load(timer_base, 0xffffcd38);
122
 
123
        /* Clear pending Interrupts, if any */
124
        write(7, timer_base + OMAP_TIMER_TISR);
125
 
126
        /* Enable inteerupts */
127
        write((1 << OMAP_TIMER_INTR_OVERFLOW), timer_base + OMAP_TIMER_TIER);
128
}
129
 
130
void timer_init(unsigned long timer_base)
131
{
132
        timer_init_periodic(timer_base);
133
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.