Lines Matching +full:imx27 +full:- +full:gpt
1 // SPDX-License-Identifier: GPL-2.0+
3 // Copyright (C) 2000-2001 Deep Blue Solutions
5 // Copyright (C) 2006-2007 Pavel Pisa (ppisa@pikron.com)
23 * - MX1/MXL
24 * - MX21, MX27.
25 * - MX25, MX31, MX35, MX37, MX51, MX6Q(rev1.0)
26 * - MX6DL, MX6SX, MX6Q(rev1.1+)
68 const struct imx_gpt_data *gpt; member
93 tmp = readl_relaxed(imxtm->base + MXC_TCTL); in imx1_gpt_irq_disable()
94 writel_relaxed(tmp & ~MX1_2_TCTL_IRQEN, imxtm->base + MXC_TCTL); in imx1_gpt_irq_disable()
100 writel_relaxed(0, imxtm->base + V2_IR); in imx31_gpt_irq_disable()
108 tmp = readl_relaxed(imxtm->base + MXC_TCTL); in imx1_gpt_irq_enable()
109 writel_relaxed(tmp | MX1_2_TCTL_IRQEN, imxtm->base + MXC_TCTL); in imx1_gpt_irq_enable()
115 writel_relaxed(1<<0, imxtm->base + V2_IR); in imx31_gpt_irq_enable()
121 writel_relaxed(0, imxtm->base + MX1_2_TSTAT); in imx1_gpt_irq_acknowledge()
127 imxtm->base + MX1_2_TSTAT); in imx21_gpt_irq_acknowledge()
132 writel_relaxed(V2_TSTAT_OF1, imxtm->base + V2_TSTAT); in imx31_gpt_irq_acknowledge()
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()
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()
183 -ETIME : 0; in mx1_2_set_next_event()
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()
198 -ETIME : 0; in v2_set_next_event()
206 /* Disable interrupt in GPT module */ in mxc_shutdown()
207 imxtm->gpt->gpt_irq_disable(imxtm); in mxc_shutdown()
209 tcn = readl_relaxed(imxtm->base + imxtm->gpt->reg_tcn); in mxc_shutdown()
210 /* Set event time into far-far future */ 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()
227 /* Disable interrupt in GPT module */ in mxc_set_oneshot()
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()
232 /* Set event time into far-far future */ 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()
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()
267 ced->event_handler(ced); in mxc_timer_interrupt()
274 struct clock_event_device *ced = &imxtm->ced; in mxc_clockevent_init()
276 ced->name = "mxc_timer1"; in mxc_clockevent_init()
277 ced->features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_DYNIRQ; in mxc_clockevent_init()
278 ced->set_state_shutdown = mxc_shutdown; in mxc_clockevent_init()
279 ced->set_state_oneshot = mxc_set_oneshot; in mxc_clockevent_init()
280 ced->tick_resume = mxc_shutdown; in mxc_clockevent_init()
281 ced->set_next_event = imxtm->gpt->set_next_event; in mxc_clockevent_init()
282 ced->rating = 200; in mxc_clockevent_init()
283 ced->cpumask = cpumask_of(0); 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()
297 writel_relaxed(tctl_val, imxtm->base + MXC_TCTL); in imx1_gpt_setup_tctl()
306 if (clk_get_rate(imxtm->clk_per) == V2_TIMER_RATE_OSC_DIV8) in imx31_gpt_setup_tctl()
311 writel_relaxed(tctl_val, imxtm->base + MXC_TCTL); in imx31_gpt_setup_tctl()
319 if (clk_get_rate(imxtm->clk_per) == V2_TIMER_RATE_OSC_DIV8) { in imx6dl_gpt_setup_tctl()
322 writel_relaxed(7 << V2_TPRER_PRE24M, imxtm->base + MXC_TPRER); in imx6dl_gpt_setup_tctl()
328 writel_relaxed(tctl_val, imxtm->base + MXC_TCTL); in imx6dl_gpt_setup_tctl()
379 switch (imxtm->type) { in _mxc_timer_init()
381 imxtm->gpt = &imx1_gpt_data; in _mxc_timer_init()
384 imxtm->gpt = &imx21_gpt_data; in _mxc_timer_init()
387 imxtm->gpt = &imx31_gpt_data; in _mxc_timer_init()
390 imxtm->gpt = &imx6dl_gpt_data; in _mxc_timer_init()
393 return -EINVAL; in _mxc_timer_init()
396 if (IS_ERR(imxtm->clk_per)) { in _mxc_timer_init()
398 return PTR_ERR(imxtm->clk_per); in _mxc_timer_init()
401 if (!IS_ERR(imxtm->clk_ipg)) in _mxc_timer_init()
402 clk_prepare_enable(imxtm->clk_ipg); in _mxc_timer_init()
404 clk_prepare_enable(imxtm->clk_per); in _mxc_timer_init()
410 writel_relaxed(0, imxtm->base + MXC_TCTL); in _mxc_timer_init()
411 writel_relaxed(0, imxtm->base + MXC_TPRER); /* see datasheet note */ in _mxc_timer_init()
413 imxtm->gpt->gpt_setup_tctl(imxtm); in _mxc_timer_init()
430 imxtm->clk_per = clk_get_sys("imx-gpt.0", "per"); in mxc_timer_init()
431 imxtm->clk_ipg = clk_get_sys("imx-gpt.0", "ipg"); in mxc_timer_init()
433 imxtm->base = ioremap(pbase, SZ_4K); in mxc_timer_init()
434 BUG_ON(!imxtm->base); in mxc_timer_init()
436 imxtm->type = type; in mxc_timer_init()
437 imxtm->irq = irq; in mxc_timer_init()
454 return -ENOMEM; in mxc_timer_init_dt()
456 imxtm->base = of_iomap(np, 0); in mxc_timer_init_dt()
457 if (!imxtm->base) in mxc_timer_init_dt()
458 return -ENXIO; in mxc_timer_init_dt()
460 imxtm->irq = irq_of_parse_and_map(np, 0); in mxc_timer_init_dt()
461 if (imxtm->irq <= 0) in mxc_timer_init_dt()
462 return -EINVAL; in mxc_timer_init_dt()
464 imxtm->clk_ipg = of_clk_get_by_name(np, "ipg"); in mxc_timer_init_dt()
467 imxtm->clk_per = of_clk_get_by_name(np, "osc_per"); in mxc_timer_init_dt()
468 if (IS_ERR(imxtm->clk_per)) in mxc_timer_init_dt()
469 imxtm->clk_per = of_clk_get_by_name(np, "per"); in mxc_timer_init_dt()
471 imxtm->type = type; in mxc_timer_init_dt()
498 * GPT device, while they actually have different programming model. in imx31_timer_init_dt()
513 TIMER_OF_DECLARE(imx1_timer, "fsl,imx1-gpt", imx1_timer_init_dt);
514 TIMER_OF_DECLARE(imx21_timer, "fsl,imx21-gpt", imx21_timer_init_dt);
515 TIMER_OF_DECLARE(imx27_timer, "fsl,imx27-gpt", imx21_timer_init_dt);
516 TIMER_OF_DECLARE(imx31_timer, "fsl,imx31-gpt", imx31_timer_init_dt);
517 TIMER_OF_DECLARE(imx25_timer, "fsl,imx25-gpt", imx31_timer_init_dt);
518 TIMER_OF_DECLARE(imx50_timer, "fsl,imx50-gpt", imx31_timer_init_dt);
519 TIMER_OF_DECLARE(imx51_timer, "fsl,imx51-gpt", imx31_timer_init_dt);
520 TIMER_OF_DECLARE(imx53_timer, "fsl,imx53-gpt", imx31_timer_init_dt);
521 TIMER_OF_DECLARE(imx6q_timer, "fsl,imx6q-gpt", imx31_timer_init_dt);
522 TIMER_OF_DECLARE(imx6dl_timer, "fsl,imx6dl-gpt", imx6dl_timer_init_dt);
523 TIMER_OF_DECLARE(imx6sl_timer, "fsl,imx6sl-gpt", imx6dl_timer_init_dt);
524 TIMER_OF_DECLARE(imx6sx_timer, "fsl,imx6sx-gpt", imx6dl_timer_init_dt);