Lines Matching refs:imxtm
81 void (*gpt_setup_tctl)(struct imx_timer *imxtm);
82 void (*gpt_irq_enable)(struct imx_timer *imxtm);
83 void (*gpt_irq_disable)(struct imx_timer *imxtm);
84 void (*gpt_irq_acknowledge)(struct imx_timer *imxtm);
94 static void imx1_gpt_irq_disable(struct imx_timer *imxtm) in imx1_gpt_irq_disable() argument
98 tmp = readl_relaxed(imxtm->base + MXC_TCTL); in imx1_gpt_irq_disable()
99 writel_relaxed(tmp & ~MX1_2_TCTL_IRQEN, imxtm->base + MXC_TCTL); in imx1_gpt_irq_disable()
102 static void imx31_gpt_irq_disable(struct imx_timer *imxtm) in imx31_gpt_irq_disable() argument
104 writel_relaxed(0, imxtm->base + V2_IR); in imx31_gpt_irq_disable()
107 static void imx1_gpt_irq_enable(struct imx_timer *imxtm) in imx1_gpt_irq_enable() argument
111 tmp = readl_relaxed(imxtm->base + MXC_TCTL); in imx1_gpt_irq_enable()
112 writel_relaxed(tmp | MX1_2_TCTL_IRQEN, imxtm->base + MXC_TCTL); in imx1_gpt_irq_enable()
115 static void imx31_gpt_irq_enable(struct imx_timer *imxtm) in imx31_gpt_irq_enable() argument
117 writel_relaxed(1<<0, imxtm->base + V2_IR); in imx31_gpt_irq_enable()
120 static void imx1_gpt_irq_acknowledge(struct imx_timer *imxtm) in imx1_gpt_irq_acknowledge() argument
122 writel_relaxed(0, imxtm->base + MX1_2_TSTAT); in imx1_gpt_irq_acknowledge()
125 static void imx21_gpt_irq_acknowledge(struct imx_timer *imxtm) in imx21_gpt_irq_acknowledge() argument
128 imxtm->base + MX1_2_TSTAT); in imx21_gpt_irq_acknowledge()
131 static void imx31_gpt_irq_acknowledge(struct imx_timer *imxtm) in imx31_gpt_irq_acknowledge() argument
133 writel_relaxed(V2_TSTAT_OF1, imxtm->base + V2_TSTAT); in imx31_gpt_irq_acknowledge()
152 static int __init mxc_clocksource_init(struct imx_timer *imxtm) in mxc_clocksource_init() argument
154 unsigned int c = clk_get_rate(imxtm->clk_per); in mxc_clocksource_init()
155 void __iomem *reg = imxtm->base + imxtm->gpt->reg_tcn; in mxc_clocksource_init()
175 struct imx_timer *imxtm = to_imx_timer(ced); in mx1_2_set_next_event() local
178 tcmp = readl_relaxed(imxtm->base + MX1_2_TCN) + evt; in mx1_2_set_next_event()
180 writel_relaxed(tcmp, imxtm->base + MX1_2_TCMP); in mx1_2_set_next_event()
182 return (int)(tcmp - readl_relaxed(imxtm->base + MX1_2_TCN)) < 0 ? in mx1_2_set_next_event()
189 struct imx_timer *imxtm = to_imx_timer(ced); in v2_set_next_event() local
192 tcmp = readl_relaxed(imxtm->base + V2_TCN) + evt; in v2_set_next_event()
194 writel_relaxed(tcmp, imxtm->base + V2_TCMP); in v2_set_next_event()
197 (int)(tcmp - readl_relaxed(imxtm->base + V2_TCN)) < 0 ? in v2_set_next_event()
203 struct imx_timer *imxtm = to_imx_timer(ced); in mxc_shutdown() local
207 imxtm->gpt->gpt_irq_disable(imxtm); in mxc_shutdown()
209 tcn = readl_relaxed(imxtm->base + imxtm->gpt->reg_tcn); in mxc_shutdown()
211 writel_relaxed(tcn - 3, imxtm->base + imxtm->gpt->reg_tcmp); in mxc_shutdown()
214 imxtm->gpt->gpt_irq_acknowledge(imxtm); in mxc_shutdown()
225 struct imx_timer *imxtm = to_imx_timer(ced); in mxc_set_oneshot() local
228 imxtm->gpt->gpt_irq_disable(imxtm); in mxc_set_oneshot()
231 u32 tcn = readl_relaxed(imxtm->base + imxtm->gpt->reg_tcn); in mxc_set_oneshot()
233 writel_relaxed(tcn - 3, imxtm->base + imxtm->gpt->reg_tcmp); in mxc_set_oneshot()
236 imxtm->gpt->gpt_irq_acknowledge(imxtm); in mxc_set_oneshot()
249 imxtm->gpt->gpt_irq_enable(imxtm); in mxc_set_oneshot()
260 struct imx_timer *imxtm = to_imx_timer(ced); in mxc_timer_interrupt() local
263 tstat = readl_relaxed(imxtm->base + imxtm->gpt->reg_tstat); in mxc_timer_interrupt()
265 imxtm->gpt->gpt_irq_acknowledge(imxtm); in mxc_timer_interrupt()
272 static int __init mxc_clockevent_init(struct imx_timer *imxtm) in mxc_clockevent_init() argument
274 struct clock_event_device *ced = &imxtm->ced; in mxc_clockevent_init()
281 ced->set_next_event = imxtm->gpt->set_next_event; in mxc_clockevent_init()
284 ced->irq = imxtm->irq; in mxc_clockevent_init()
285 clockevents_config_and_register(ced, clk_get_rate(imxtm->clk_per), in mxc_clockevent_init()
288 return request_irq(imxtm->irq, mxc_timer_interrupt, in mxc_clockevent_init()
292 static void imx1_gpt_setup_tctl(struct imx_timer *imxtm) in imx1_gpt_setup_tctl() argument
297 writel_relaxed(tctl_val, imxtm->base + MXC_TCTL); in imx1_gpt_setup_tctl()
300 static void imx31_gpt_setup_tctl(struct imx_timer *imxtm) in imx31_gpt_setup_tctl() argument
305 if (clk_get_rate(imxtm->clk_per) == V2_TIMER_RATE_OSC_DIV8) in imx31_gpt_setup_tctl()
310 writel_relaxed(tctl_val, imxtm->base + MXC_TCTL); in imx31_gpt_setup_tctl()
313 static void imx6dl_gpt_setup_tctl(struct imx_timer *imxtm) in imx6dl_gpt_setup_tctl() argument
318 if (clk_get_rate(imxtm->clk_per) == V2_TIMER_RATE_OSC_DIV8) { in imx6dl_gpt_setup_tctl()
321 writel_relaxed(7 << V2_TPRER_PRE24M, imxtm->base + MXC_TPRER); in imx6dl_gpt_setup_tctl()
327 writel_relaxed(tctl_val, imxtm->base + MXC_TCTL); in imx6dl_gpt_setup_tctl()
374 static int __init _mxc_timer_init(struct imx_timer *imxtm) in _mxc_timer_init() argument
378 switch (imxtm->type) { in _mxc_timer_init()
380 imxtm->gpt = &imx1_gpt_data; in _mxc_timer_init()
383 imxtm->gpt = &imx21_gpt_data; in _mxc_timer_init()
386 imxtm->gpt = &imx31_gpt_data; in _mxc_timer_init()
389 imxtm->gpt = &imx6dl_gpt_data; in _mxc_timer_init()
395 if (IS_ERR(imxtm->clk_per)) { in _mxc_timer_init()
397 return PTR_ERR(imxtm->clk_per); in _mxc_timer_init()
400 if (!IS_ERR(imxtm->clk_ipg)) in _mxc_timer_init()
401 clk_prepare_enable(imxtm->clk_ipg); in _mxc_timer_init()
403 clk_prepare_enable(imxtm->clk_per); in _mxc_timer_init()
409 writel_relaxed(0, imxtm->base + MXC_TCTL); in _mxc_timer_init()
410 writel_relaxed(0, imxtm->base + MXC_TPRER); /* see datasheet note */ in _mxc_timer_init()
412 imxtm->gpt->gpt_setup_tctl(imxtm); in _mxc_timer_init()
415 ret = mxc_clocksource_init(imxtm); in _mxc_timer_init()
419 return mxc_clockevent_init(imxtm); in _mxc_timer_init()
424 struct imx_timer *imxtm; in mxc_timer_init_dt() local
432 imxtm = kzalloc(sizeof(*imxtm), GFP_KERNEL); in mxc_timer_init_dt()
433 if (!imxtm) in mxc_timer_init_dt()
436 imxtm->base = of_iomap(np, 0); in mxc_timer_init_dt()
437 if (!imxtm->base) { in mxc_timer_init_dt()
442 imxtm->irq = irq_of_parse_and_map(np, 0); in mxc_timer_init_dt()
443 if (imxtm->irq <= 0) { in mxc_timer_init_dt()
448 imxtm->clk_ipg = of_clk_get_by_name(np, "ipg"); in mxc_timer_init_dt()
451 imxtm->clk_per = of_clk_get_by_name(np, "osc_per"); in mxc_timer_init_dt()
452 if (IS_ERR(imxtm->clk_per)) in mxc_timer_init_dt()
453 imxtm->clk_per = of_clk_get_by_name(np, "per"); in mxc_timer_init_dt()
455 imxtm->type = type; in mxc_timer_init_dt()
457 ret = _mxc_timer_init(imxtm); in mxc_timer_init_dt()
466 kfree(imxtm); in mxc_timer_init_dt()