Lines Matching refs:imxtm

77 	void (*gpt_setup_tctl)(struct imx_timer *imxtm);
78 void (*gpt_irq_enable)(struct imx_timer *imxtm);
79 void (*gpt_irq_disable)(struct imx_timer *imxtm);
80 void (*gpt_irq_acknowledge)(struct imx_timer *imxtm);
90 static void imx1_gpt_irq_disable(struct imx_timer *imxtm) in imx1_gpt_irq_disable() argument
94 tmp = readl_relaxed(imxtm->base + MXC_TCTL); in imx1_gpt_irq_disable()
95 writel_relaxed(tmp & ~MX1_2_TCTL_IRQEN, imxtm->base + MXC_TCTL); in imx1_gpt_irq_disable()
99 static void imx31_gpt_irq_disable(struct imx_timer *imxtm) in imx31_gpt_irq_disable() argument
101 writel_relaxed(0, imxtm->base + V2_IR); in imx31_gpt_irq_disable()
105 static void imx1_gpt_irq_enable(struct imx_timer *imxtm) in imx1_gpt_irq_enable() argument
109 tmp = readl_relaxed(imxtm->base + MXC_TCTL); in imx1_gpt_irq_enable()
110 writel_relaxed(tmp | MX1_2_TCTL_IRQEN, imxtm->base + MXC_TCTL); in imx1_gpt_irq_enable()
114 static void imx31_gpt_irq_enable(struct imx_timer *imxtm) in imx31_gpt_irq_enable() argument
116 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()
153 static int __init mxc_clocksource_init(struct imx_timer *imxtm) in mxc_clocksource_init() argument
155 unsigned int c = clk_get_rate(imxtm->clk_per); in mxc_clocksource_init()
156 void __iomem *reg = imxtm->base + imxtm->gpt->reg_tcn; in mxc_clocksource_init()
176 struct imx_timer *imxtm = to_imx_timer(ced); in mx1_2_set_next_event() local
179 tcmp = readl_relaxed(imxtm->base + MX1_2_TCN) + evt; in mx1_2_set_next_event()
181 writel_relaxed(tcmp, imxtm->base + MX1_2_TCMP); in mx1_2_set_next_event()
183 return (int)(tcmp - readl_relaxed(imxtm->base + MX1_2_TCN)) < 0 ? in mx1_2_set_next_event()
190 struct imx_timer *imxtm = to_imx_timer(ced); in v2_set_next_event() local
193 tcmp = readl_relaxed(imxtm->base + V2_TCN) + evt; in v2_set_next_event()
195 writel_relaxed(tcmp, imxtm->base + V2_TCMP); in v2_set_next_event()
198 (int)(tcmp - readl_relaxed(imxtm->base + V2_TCN)) < 0 ? in v2_set_next_event()
204 struct imx_timer *imxtm = to_imx_timer(ced); in mxc_shutdown() local
208 imxtm->gpt->gpt_irq_disable(imxtm); in mxc_shutdown()
210 tcn = readl_relaxed(imxtm->base + imxtm->gpt->reg_tcn); in mxc_shutdown()
212 writel_relaxed(tcn - 3, imxtm->base + imxtm->gpt->reg_tcmp); in mxc_shutdown()
215 imxtm->gpt->gpt_irq_acknowledge(imxtm); in mxc_shutdown()
226 struct imx_timer *imxtm = to_imx_timer(ced); in mxc_set_oneshot() local
229 imxtm->gpt->gpt_irq_disable(imxtm); in mxc_set_oneshot()
232 u32 tcn = readl_relaxed(imxtm->base + imxtm->gpt->reg_tcn); in mxc_set_oneshot()
234 writel_relaxed(tcn - 3, imxtm->base + imxtm->gpt->reg_tcmp); in mxc_set_oneshot()
237 imxtm->gpt->gpt_irq_acknowledge(imxtm); in mxc_set_oneshot()
250 imxtm->gpt->gpt_irq_enable(imxtm); in mxc_set_oneshot()
261 struct imx_timer *imxtm = to_imx_timer(ced); in mxc_timer_interrupt() local
264 tstat = readl_relaxed(imxtm->base + imxtm->gpt->reg_tstat); in mxc_timer_interrupt()
266 imxtm->gpt->gpt_irq_acknowledge(imxtm); in mxc_timer_interrupt()
273 static int __init mxc_clockevent_init(struct imx_timer *imxtm) in mxc_clockevent_init() argument
275 struct clock_event_device *ced = &imxtm->ced; in mxc_clockevent_init()
276 struct irqaction *act = &imxtm->act; in mxc_clockevent_init()
283 ced->set_next_event = imxtm->gpt->set_next_event; in mxc_clockevent_init()
286 ced->irq = imxtm->irq; in mxc_clockevent_init()
287 clockevents_config_and_register(ced, clk_get_rate(imxtm->clk_per), in mxc_clockevent_init()
295 return setup_irq(imxtm->irq, act); in mxc_clockevent_init()
298 static void imx1_gpt_setup_tctl(struct imx_timer *imxtm) in imx1_gpt_setup_tctl() argument
303 writel_relaxed(tctl_val, imxtm->base + MXC_TCTL); in imx1_gpt_setup_tctl()
307 static void imx31_gpt_setup_tctl(struct imx_timer *imxtm) in imx31_gpt_setup_tctl() argument
312 if (clk_get_rate(imxtm->clk_per) == V2_TIMER_RATE_OSC_DIV8) in imx31_gpt_setup_tctl()
317 writel_relaxed(tctl_val, imxtm->base + MXC_TCTL); in imx31_gpt_setup_tctl()
320 static void imx6dl_gpt_setup_tctl(struct imx_timer *imxtm) in imx6dl_gpt_setup_tctl() argument
325 if (clk_get_rate(imxtm->clk_per) == V2_TIMER_RATE_OSC_DIV8) { in imx6dl_gpt_setup_tctl()
328 writel_relaxed(7 << V2_TPRER_PRE24M, imxtm->base + MXC_TPRER); in imx6dl_gpt_setup_tctl()
334 writel_relaxed(tctl_val, imxtm->base + MXC_TCTL); in imx6dl_gpt_setup_tctl()
381 static int __init _mxc_timer_init(struct imx_timer *imxtm) in _mxc_timer_init() argument
385 switch (imxtm->type) { in _mxc_timer_init()
387 imxtm->gpt = &imx1_gpt_data; in _mxc_timer_init()
390 imxtm->gpt = &imx21_gpt_data; in _mxc_timer_init()
393 imxtm->gpt = &imx31_gpt_data; in _mxc_timer_init()
396 imxtm->gpt = &imx6dl_gpt_data; in _mxc_timer_init()
402 if (IS_ERR(imxtm->clk_per)) { in _mxc_timer_init()
404 return PTR_ERR(imxtm->clk_per); in _mxc_timer_init()
407 if (!IS_ERR(imxtm->clk_ipg)) in _mxc_timer_init()
408 clk_prepare_enable(imxtm->clk_ipg); in _mxc_timer_init()
410 clk_prepare_enable(imxtm->clk_per); in _mxc_timer_init()
416 writel_relaxed(0, imxtm->base + MXC_TCTL); in _mxc_timer_init()
417 writel_relaxed(0, imxtm->base + MXC_TPRER); /* see datasheet note */ in _mxc_timer_init()
419 imxtm->gpt->gpt_setup_tctl(imxtm); in _mxc_timer_init()
422 ret = mxc_clocksource_init(imxtm); in _mxc_timer_init()
426 return mxc_clockevent_init(imxtm); in _mxc_timer_init()
431 struct imx_timer *imxtm; in mxc_timer_init() local
433 imxtm = kzalloc(sizeof(*imxtm), GFP_KERNEL); in mxc_timer_init()
434 BUG_ON(!imxtm); in mxc_timer_init()
436 imxtm->clk_per = clk_get_sys("imx-gpt.0", "per"); in mxc_timer_init()
437 imxtm->clk_ipg = clk_get_sys("imx-gpt.0", "ipg"); in mxc_timer_init()
439 imxtm->base = ioremap(pbase, SZ_4K); in mxc_timer_init()
440 BUG_ON(!imxtm->base); in mxc_timer_init()
442 imxtm->type = type; in mxc_timer_init()
443 imxtm->irq = irq; in mxc_timer_init()
445 _mxc_timer_init(imxtm); in mxc_timer_init()
450 struct imx_timer *imxtm; in mxc_timer_init_dt() local
458 imxtm = kzalloc(sizeof(*imxtm), GFP_KERNEL); in mxc_timer_init_dt()
459 if (!imxtm) in mxc_timer_init_dt()
462 imxtm->base = of_iomap(np, 0); in mxc_timer_init_dt()
463 if (!imxtm->base) in mxc_timer_init_dt()
466 imxtm->irq = irq_of_parse_and_map(np, 0); in mxc_timer_init_dt()
467 if (imxtm->irq <= 0) in mxc_timer_init_dt()
470 imxtm->clk_ipg = of_clk_get_by_name(np, "ipg"); in mxc_timer_init_dt()
473 imxtm->clk_per = of_clk_get_by_name(np, "osc_per"); in mxc_timer_init_dt()
474 if (IS_ERR(imxtm->clk_per)) in mxc_timer_init_dt()
475 imxtm->clk_per = of_clk_get_by_name(np, "per"); in mxc_timer_init_dt()
477 imxtm->type = type; in mxc_timer_init_dt()
479 ret = _mxc_timer_init(imxtm); in mxc_timer_init_dt()