30 #include <mach/hardware.h>
33 #include <mach/common.h>
43 #define MXC_TCTL_TEN (1 << 0)
44 #define MXC_TPRER 0x04
47 #define MX1_2_TCTL_CLK_PCLK1 (1 << 1)
48 #define MX1_2_TCTL_IRQEN (1 << 4)
49 #define MX1_2_TCTL_FRR (1 << 8)
50 #define MX1_2_TCMP 0x08
51 #define MX1_2_TCN 0x10
52 #define MX1_2_TSTAT 0x14
55 #define MX2_TSTAT_CAPT (1 << 1)
56 #define MX2_TSTAT_COMP (1 << 0)
59 #define V2_TCTL_WAITEN (1 << 3)
60 #define V2_TCTL_CLK_IPG (1 << 6)
61 #define V2_TCTL_CLK_PER (2 << 6)
62 #define V2_TCTL_FRR (1 << 9)
65 #define V2_TSTAT_OF1 (1 << 0)
69 #define timer_is_v1() (cpu_is_mx1() || cpu_is_mx21() || cpu_is_mx27())
70 #define timer_is_v2() (!timer_is_v1())
72 static struct clock_event_device clockevent_mxc;
73 static enum clock_event_mode clockevent_mode = CLOCK_EVT_MODE_UNUSED;
75 static void __iomem *timer_base;
77 static inline void gpt_irq_disable(
void)
89 static inline void gpt_irq_enable(
void)
99 static void gpt_irq_acknowledge(
void)
111 static void __iomem *sched_clock_reg;
115 return sched_clock_reg ?
__raw_readl(sched_clock_reg) : 0;
118 static int __init mxc_clocksource_init(
struct clk *timer_clk)
123 sched_clock_reg =
reg;
132 static int mx1_2_set_next_event(
unsigned long evt,
133 struct clock_event_device *
unused)
145 static int v2_set_next_event(
unsigned long evt,
146 struct clock_event_device *unused)
159 static const char *clock_event_mode_label[] = {
160 [CLOCK_EVT_MODE_PERIODIC] =
"CLOCK_EVT_MODE_PERIODIC",
161 [CLOCK_EVT_MODE_ONESHOT] =
"CLOCK_EVT_MODE_ONESHOT",
162 [CLOCK_EVT_MODE_SHUTDOWN] =
"CLOCK_EVT_MODE_SHUTDOWN",
163 [CLOCK_EVT_MODE_UNUSED] =
"CLOCK_EVT_MODE_UNUSED",
164 [CLOCK_EVT_MODE_RESUME] =
"CLOCK_EVT_MODE_RESUME",
168 static void mxc_set_mode(
enum clock_event_mode
mode,
169 struct clock_event_device *evt)
182 if (mode != clockevent_mode) {
192 gpt_irq_acknowledge();
197 clock_event_mode_label[clockevent_mode],
198 clock_event_mode_label[mode]);
202 clockevent_mode =
mode;
206 case CLOCK_EVT_MODE_PERIODIC:
208 "supported for i.MX\n");
210 case CLOCK_EVT_MODE_ONESHOT:
221 case CLOCK_EVT_MODE_SHUTDOWN:
222 case CLOCK_EVT_MODE_UNUSED:
223 case CLOCK_EVT_MODE_RESUME:
234 struct clock_event_device *evt = &clockevent_mxc;
242 gpt_irq_acknowledge();
244 evt->event_handler(evt);
249 static struct irqaction mxc_timer_irq = {
250 .name =
"i.MX Timer Tick",
252 .handler = mxc_timer_interrupt,
255 static struct clock_event_device clockevent_mxc = {
256 .name =
"mxc_timer1",
257 .features = CLOCK_EVT_FEAT_ONESHOT,
259 .set_mode = mxc_set_mode,
260 .set_next_event = mx1_2_set_next_event,
264 static int __init mxc_clockevent_init(
struct clk *timer_clk)
269 clockevent_mxc.set_next_event = v2_set_next_event;
272 clockevent_mxc.shift);
273 clockevent_mxc.max_delta_ns =
275 clockevent_mxc.min_delta_ns =
288 struct clk *timer_clk;
289 struct clk *timer_ipg_clk;
292 if (IS_ERR(timer_clk)) {
293 pr_err(
"i.MX timer: unable to get clk\n");
298 if (!IS_ERR(timer_ipg_clk))
299 clk_prepare_enable(timer_ipg_clk);
301 clk_prepare_enable(timer_clk);
320 mxc_clocksource_init(timer_clk);
321 mxc_clockevent_init(timer_clk);