1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
27ec58e52SStanley Chu /*
37ec58e52SStanley Chu  * Mediatek SoCs General-Purpose Timer handling.
47ec58e52SStanley Chu  *
57ec58e52SStanley Chu  * Copyright (C) 2014 Matthias Brugger
67ec58e52SStanley Chu  *
77ec58e52SStanley Chu  * Matthias Brugger <matthias.bgg@gmail.com>
87ec58e52SStanley Chu  */
97ec58e52SStanley Chu 
107ec58e52SStanley Chu #define pr_fmt(fmt)	KBUILD_MODNAME ": " fmt
117ec58e52SStanley Chu 
127ec58e52SStanley Chu #include <linux/clockchips.h>
13a0858f93SStanley Chu #include <linux/clocksource.h>
147ec58e52SStanley Chu #include <linux/interrupt.h>
157ec58e52SStanley Chu #include <linux/irqreturn.h>
167ec58e52SStanley Chu #include <linux/sched_clock.h>
177ec58e52SStanley Chu #include <linux/slab.h>
18a0858f93SStanley Chu #include "timer-of.h"
197ec58e52SStanley Chu 
2056d52d3fSStanley Chu #define TIMER_CLK_EVT           (1)
2156d52d3fSStanley Chu #define TIMER_CLK_SRC           (2)
2256d52d3fSStanley Chu 
2356d52d3fSStanley Chu #define TIMER_SYNC_TICKS        (3)
2456d52d3fSStanley Chu 
2556d52d3fSStanley Chu /* gpt */
267ec58e52SStanley Chu #define GPT_IRQ_EN_REG          0x00
277ec58e52SStanley Chu #define GPT_IRQ_ENABLE(val)     BIT((val) - 1)
287ec58e52SStanley Chu #define GPT_IRQ_ACK_REG	        0x08
297ec58e52SStanley Chu #define GPT_IRQ_ACK(val)        BIT((val) - 1)
307ec58e52SStanley Chu 
3156d52d3fSStanley Chu #define GPT_CTRL_REG(val)       (0x10 * (val))
3256d52d3fSStanley Chu #define GPT_CTRL_OP(val)        (((val) & 0x3) << 4)
3356d52d3fSStanley Chu #define GPT_CTRL_OP_ONESHOT     (0)
3456d52d3fSStanley Chu #define GPT_CTRL_OP_REPEAT      (1)
3556d52d3fSStanley Chu #define GPT_CTRL_OP_FREERUN     (3)
3656d52d3fSStanley Chu #define GPT_CTRL_CLEAR          (2)
3756d52d3fSStanley Chu #define GPT_CTRL_ENABLE         (1)
3856d52d3fSStanley Chu #define GPT_CTRL_DISABLE        (0)
397ec58e52SStanley Chu 
4056d52d3fSStanley Chu #define GPT_CLK_REG(val)        (0x04 + (0x10 * (val)))
4156d52d3fSStanley Chu #define GPT_CLK_SRC(val)        (((val) & 0x1) << 4)
4256d52d3fSStanley Chu #define GPT_CLK_SRC_SYS13M      (0)
4356d52d3fSStanley Chu #define GPT_CLK_SRC_RTC32K      (1)
4456d52d3fSStanley Chu #define GPT_CLK_DIV1            (0x0)
4556d52d3fSStanley Chu #define GPT_CLK_DIV2            (0x1)
467ec58e52SStanley Chu 
4756d52d3fSStanley Chu #define GPT_CNT_REG(val)        (0x08 + (0x10 * (val)))
4856d52d3fSStanley Chu #define GPT_CMP_REG(val)        (0x0C + (0x10 * (val)))
497ec58e52SStanley Chu 
50e3af6776SStanley Chu /* system timer */
51e3af6776SStanley Chu #define SYST_BASE               (0x40)
52e3af6776SStanley Chu 
53e3af6776SStanley Chu #define SYST_CON                (SYST_BASE + 0x0)
54e3af6776SStanley Chu #define SYST_VAL                (SYST_BASE + 0x4)
55e3af6776SStanley Chu 
56e3af6776SStanley Chu #define SYST_CON_REG(to)        (timer_of_base(to) + SYST_CON)
57e3af6776SStanley Chu #define SYST_VAL_REG(to)        (timer_of_base(to) + SYST_VAL)
58e3af6776SStanley Chu 
59e3af6776SStanley Chu /*
60e3af6776SStanley Chu  * SYST_CON_EN: Clock enable. Shall be set to
61e3af6776SStanley Chu  *   - Start timer countdown.
62e3af6776SStanley Chu  *   - Allow timeout ticks being updated.
63*ce957065SFengquan Chen  *   - Allow changing interrupt status,like clear irq pending.
64e3af6776SStanley Chu  *
65*ce957065SFengquan Chen  * SYST_CON_IRQ_EN: Set to enable interrupt.
66e3af6776SStanley Chu  *
67e3af6776SStanley Chu  * SYST_CON_IRQ_CLR: Set to clear interrupt.
68e3af6776SStanley Chu  */
69e3af6776SStanley Chu #define SYST_CON_EN              BIT(0)
70e3af6776SStanley Chu #define SYST_CON_IRQ_EN          BIT(1)
71e3af6776SStanley Chu #define SYST_CON_IRQ_CLR         BIT(4)
72e3af6776SStanley Chu 
737ec58e52SStanley Chu static void __iomem *gpt_sched_reg __read_mostly;
747ec58e52SStanley Chu 
mtk_syst_ack_irq(struct timer_of * to)75e3af6776SStanley Chu static void mtk_syst_ack_irq(struct timer_of *to)
76e3af6776SStanley Chu {
77e3af6776SStanley Chu 	/* Clear and disable interrupt */
78*ce957065SFengquan Chen 	writel(SYST_CON_EN, SYST_CON_REG(to));
79e3af6776SStanley Chu 	writel(SYST_CON_IRQ_CLR | SYST_CON_EN, SYST_CON_REG(to));
80e3af6776SStanley Chu }
81e3af6776SStanley Chu 
mtk_syst_handler(int irq,void * dev_id)82e3af6776SStanley Chu static irqreturn_t mtk_syst_handler(int irq, void *dev_id)
83e3af6776SStanley Chu {
84e3af6776SStanley Chu 	struct clock_event_device *clkevt = dev_id;
85e3af6776SStanley Chu 	struct timer_of *to = to_timer_of(clkevt);
86e3af6776SStanley Chu 
87e3af6776SStanley Chu 	mtk_syst_ack_irq(to);
88e3af6776SStanley Chu 	clkevt->event_handler(clkevt);
89e3af6776SStanley Chu 
90e3af6776SStanley Chu 	return IRQ_HANDLED;
91e3af6776SStanley Chu }
92e3af6776SStanley Chu 
mtk_syst_clkevt_next_event(unsigned long ticks,struct clock_event_device * clkevt)93e3af6776SStanley Chu static int mtk_syst_clkevt_next_event(unsigned long ticks,
94e3af6776SStanley Chu 				      struct clock_event_device *clkevt)
95e3af6776SStanley Chu {
96e3af6776SStanley Chu 	struct timer_of *to = to_timer_of(clkevt);
97e3af6776SStanley Chu 
98e3af6776SStanley Chu 	/* Enable clock to allow timeout tick update later */
99e3af6776SStanley Chu 	writel(SYST_CON_EN, SYST_CON_REG(to));
100e3af6776SStanley Chu 
101e3af6776SStanley Chu 	/*
102e3af6776SStanley Chu 	 * Write new timeout ticks. Timer shall start countdown
103e3af6776SStanley Chu 	 * after timeout ticks are updated.
104e3af6776SStanley Chu 	 */
105e3af6776SStanley Chu 	writel(ticks, SYST_VAL_REG(to));
106e3af6776SStanley Chu 
107e3af6776SStanley Chu 	/* Enable interrupt */
108e3af6776SStanley Chu 	writel(SYST_CON_EN | SYST_CON_IRQ_EN, SYST_CON_REG(to));
109e3af6776SStanley Chu 
110e3af6776SStanley Chu 	return 0;
111e3af6776SStanley Chu }
112e3af6776SStanley Chu 
mtk_syst_clkevt_shutdown(struct clock_event_device * clkevt)113e3af6776SStanley Chu static int mtk_syst_clkevt_shutdown(struct clock_event_device *clkevt)
114e3af6776SStanley Chu {
115*ce957065SFengquan Chen 	/* Clear any irq */
116*ce957065SFengquan Chen 	mtk_syst_ack_irq(to_timer_of(clkevt));
117*ce957065SFengquan Chen 
118e3af6776SStanley Chu 	/* Disable timer */
119e3af6776SStanley Chu 	writel(0, SYST_CON_REG(to_timer_of(clkevt)));
120e3af6776SStanley Chu 
121e3af6776SStanley Chu 	return 0;
122e3af6776SStanley Chu }
123e3af6776SStanley Chu 
mtk_syst_clkevt_resume(struct clock_event_device * clkevt)124e3af6776SStanley Chu static int mtk_syst_clkevt_resume(struct clock_event_device *clkevt)
125e3af6776SStanley Chu {
126e3af6776SStanley Chu 	return mtk_syst_clkevt_shutdown(clkevt);
127e3af6776SStanley Chu }
128e3af6776SStanley Chu 
mtk_syst_clkevt_oneshot(struct clock_event_device * clkevt)129e3af6776SStanley Chu static int mtk_syst_clkevt_oneshot(struct clock_event_device *clkevt)
130e3af6776SStanley Chu {
131e3af6776SStanley Chu 	return 0;
132e3af6776SStanley Chu }
133e3af6776SStanley Chu 
mtk_gpt_read_sched_clock(void)13456d52d3fSStanley Chu static u64 notrace mtk_gpt_read_sched_clock(void)
1357ec58e52SStanley Chu {
1367ec58e52SStanley Chu 	return readl_relaxed(gpt_sched_reg);
1377ec58e52SStanley Chu }
1387ec58e52SStanley Chu 
mtk_gpt_clkevt_time_stop(struct timer_of * to,u8 timer)139a0858f93SStanley Chu static void mtk_gpt_clkevt_time_stop(struct timer_of *to, u8 timer)
1407ec58e52SStanley Chu {
1417ec58e52SStanley Chu 	u32 val;
1427ec58e52SStanley Chu 
143a0858f93SStanley Chu 	val = readl(timer_of_base(to) + GPT_CTRL_REG(timer));
144a0858f93SStanley Chu 	writel(val & ~GPT_CTRL_ENABLE, timer_of_base(to) +
14556d52d3fSStanley Chu 	       GPT_CTRL_REG(timer));
1467ec58e52SStanley Chu }
1477ec58e52SStanley Chu 
mtk_gpt_clkevt_time_setup(struct timer_of * to,unsigned long delay,u8 timer)148a0858f93SStanley Chu static void mtk_gpt_clkevt_time_setup(struct timer_of *to,
1497ec58e52SStanley Chu 				      unsigned long delay, u8 timer)
1507ec58e52SStanley Chu {
151a0858f93SStanley Chu 	writel(delay, timer_of_base(to) + GPT_CMP_REG(timer));
1527ec58e52SStanley Chu }
1537ec58e52SStanley Chu 
mtk_gpt_clkevt_time_start(struct timer_of * to,bool periodic,u8 timer)154a0858f93SStanley Chu static void mtk_gpt_clkevt_time_start(struct timer_of *to,
1557ec58e52SStanley Chu 				      bool periodic, u8 timer)
1567ec58e52SStanley Chu {
1577ec58e52SStanley Chu 	u32 val;
1587ec58e52SStanley Chu 
1597ec58e52SStanley Chu 	/* Acknowledge interrupt */
160a0858f93SStanley Chu 	writel(GPT_IRQ_ACK(timer), timer_of_base(to) + GPT_IRQ_ACK_REG);
1617ec58e52SStanley Chu 
162a0858f93SStanley Chu 	val = readl(timer_of_base(to) + GPT_CTRL_REG(timer));
1637ec58e52SStanley Chu 
1647ec58e52SStanley Chu 	/* Clear 2 bit timer operation mode field */
16556d52d3fSStanley Chu 	val &= ~GPT_CTRL_OP(0x3);
1667ec58e52SStanley Chu 
1677ec58e52SStanley Chu 	if (periodic)
16856d52d3fSStanley Chu 		val |= GPT_CTRL_OP(GPT_CTRL_OP_REPEAT);
1697ec58e52SStanley Chu 	else
17056d52d3fSStanley Chu 		val |= GPT_CTRL_OP(GPT_CTRL_OP_ONESHOT);
1717ec58e52SStanley Chu 
17256d52d3fSStanley Chu 	writel(val | GPT_CTRL_ENABLE | GPT_CTRL_CLEAR,
173a0858f93SStanley Chu 	       timer_of_base(to) + GPT_CTRL_REG(timer));
1747ec58e52SStanley Chu }
1757ec58e52SStanley Chu 
mtk_gpt_clkevt_shutdown(struct clock_event_device * clk)17656d52d3fSStanley Chu static int mtk_gpt_clkevt_shutdown(struct clock_event_device *clk)
1777ec58e52SStanley Chu {
178a0858f93SStanley Chu 	mtk_gpt_clkevt_time_stop(to_timer_of(clk), TIMER_CLK_EVT);
179a0858f93SStanley Chu 
1807ec58e52SStanley Chu 	return 0;
1817ec58e52SStanley Chu }
1827ec58e52SStanley Chu 
mtk_gpt_clkevt_set_periodic(struct clock_event_device * clk)18356d52d3fSStanley Chu static int mtk_gpt_clkevt_set_periodic(struct clock_event_device *clk)
1847ec58e52SStanley Chu {
185a0858f93SStanley Chu 	struct timer_of *to = to_timer_of(clk);
1867ec58e52SStanley Chu 
187a0858f93SStanley Chu 	mtk_gpt_clkevt_time_stop(to, TIMER_CLK_EVT);
188a0858f93SStanley Chu 	mtk_gpt_clkevt_time_setup(to, to->of_clk.period, TIMER_CLK_EVT);
189a0858f93SStanley Chu 	mtk_gpt_clkevt_time_start(to, true, TIMER_CLK_EVT);
190a0858f93SStanley Chu 
1917ec58e52SStanley Chu 	return 0;
1927ec58e52SStanley Chu }
1937ec58e52SStanley Chu 
mtk_gpt_clkevt_next_event(unsigned long event,struct clock_event_device * clk)19456d52d3fSStanley Chu static int mtk_gpt_clkevt_next_event(unsigned long event,
1957ec58e52SStanley Chu 				     struct clock_event_device *clk)
1967ec58e52SStanley Chu {
197a0858f93SStanley Chu 	struct timer_of *to = to_timer_of(clk);
1987ec58e52SStanley Chu 
199a0858f93SStanley Chu 	mtk_gpt_clkevt_time_stop(to, TIMER_CLK_EVT);
200a0858f93SStanley Chu 	mtk_gpt_clkevt_time_setup(to, event, TIMER_CLK_EVT);
201a0858f93SStanley Chu 	mtk_gpt_clkevt_time_start(to, false, TIMER_CLK_EVT);
2027ec58e52SStanley Chu 
2037ec58e52SStanley Chu 	return 0;
2047ec58e52SStanley Chu }
2057ec58e52SStanley Chu 
mtk_gpt_interrupt(int irq,void * dev_id)20656d52d3fSStanley Chu static irqreturn_t mtk_gpt_interrupt(int irq, void *dev_id)
2077ec58e52SStanley Chu {
208a0858f93SStanley Chu 	struct clock_event_device *clkevt = (struct clock_event_device *)dev_id;
209a0858f93SStanley Chu 	struct timer_of *to = to_timer_of(clkevt);
2107ec58e52SStanley Chu 
2117ec58e52SStanley Chu 	/* Acknowledge timer0 irq */
212a0858f93SStanley Chu 	writel(GPT_IRQ_ACK(TIMER_CLK_EVT), timer_of_base(to) + GPT_IRQ_ACK_REG);
213a0858f93SStanley Chu 	clkevt->event_handler(clkevt);
2147ec58e52SStanley Chu 
2157ec58e52SStanley Chu 	return IRQ_HANDLED;
2167ec58e52SStanley Chu }
2177ec58e52SStanley Chu 
2187ec58e52SStanley Chu static void
mtk_gpt_setup(struct timer_of * to,u8 timer,u8 option)219a0858f93SStanley Chu __init mtk_gpt_setup(struct timer_of *to, u8 timer, u8 option)
2207ec58e52SStanley Chu {
22156d52d3fSStanley Chu 	writel(GPT_CTRL_CLEAR | GPT_CTRL_DISABLE,
222a0858f93SStanley Chu 	       timer_of_base(to) + GPT_CTRL_REG(timer));
2237ec58e52SStanley Chu 
22456d52d3fSStanley Chu 	writel(GPT_CLK_SRC(GPT_CLK_SRC_SYS13M) | GPT_CLK_DIV1,
225a0858f93SStanley Chu 	       timer_of_base(to) + GPT_CLK_REG(timer));
2267ec58e52SStanley Chu 
227a0858f93SStanley Chu 	writel(0x0, timer_of_base(to) + GPT_CMP_REG(timer));
2287ec58e52SStanley Chu 
22956d52d3fSStanley Chu 	writel(GPT_CTRL_OP(option) | GPT_CTRL_ENABLE,
230a0858f93SStanley Chu 	       timer_of_base(to) + GPT_CTRL_REG(timer));
2317ec58e52SStanley Chu }
2327ec58e52SStanley Chu 
mtk_gpt_enable_irq(struct timer_of * to,u8 timer)233a0858f93SStanley Chu static void mtk_gpt_enable_irq(struct timer_of *to, u8 timer)
2347ec58e52SStanley Chu {
2357ec58e52SStanley Chu 	u32 val;
2367ec58e52SStanley Chu 
2377ec58e52SStanley Chu 	/* Disable all interrupts */
238a0858f93SStanley Chu 	writel(0x0, timer_of_base(to) + GPT_IRQ_EN_REG);
2397ec58e52SStanley Chu 
2407ec58e52SStanley Chu 	/* Acknowledge all spurious pending interrupts */
241a0858f93SStanley Chu 	writel(0x3f, timer_of_base(to) + GPT_IRQ_ACK_REG);
2427ec58e52SStanley Chu 
243a0858f93SStanley Chu 	val = readl(timer_of_base(to) + GPT_IRQ_EN_REG);
2447ec58e52SStanley Chu 	writel(val | GPT_IRQ_ENABLE(timer),
245a0858f93SStanley Chu 	       timer_of_base(to) + GPT_IRQ_EN_REG);
2467ec58e52SStanley Chu }
2477ec58e52SStanley Chu 
mtk_gpt_resume(struct clock_event_device * clk)24875ac5cc2SEvan Benn static void mtk_gpt_resume(struct clock_event_device *clk)
24975ac5cc2SEvan Benn {
25075ac5cc2SEvan Benn 	struct timer_of *to = to_timer_of(clk);
25175ac5cc2SEvan Benn 
25275ac5cc2SEvan Benn 	mtk_gpt_enable_irq(to, TIMER_CLK_EVT);
25375ac5cc2SEvan Benn }
25475ac5cc2SEvan Benn 
mtk_gpt_suspend(struct clock_event_device * clk)25575ac5cc2SEvan Benn static void mtk_gpt_suspend(struct clock_event_device *clk)
25675ac5cc2SEvan Benn {
25775ac5cc2SEvan Benn 	struct timer_of *to = to_timer_of(clk);
25875ac5cc2SEvan Benn 
25975ac5cc2SEvan Benn 	/* Disable all interrupts */
26075ac5cc2SEvan Benn 	writel(0x0, timer_of_base(to) + GPT_IRQ_EN_REG);
26175ac5cc2SEvan Benn 
26275ac5cc2SEvan Benn 	/*
26375ac5cc2SEvan Benn 	 * This is called with interrupts disabled,
26475ac5cc2SEvan Benn 	 * so we need to ack any interrupt that is pending
26575ac5cc2SEvan Benn 	 * or for example ATF will prevent a suspend from completing.
26675ac5cc2SEvan Benn 	 */
26775ac5cc2SEvan Benn 	writel(0x3f, timer_of_base(to) + GPT_IRQ_ACK_REG);
26875ac5cc2SEvan Benn }
26975ac5cc2SEvan Benn 
270a0858f93SStanley Chu static struct timer_of to = {
271a0858f93SStanley Chu 	.flags = TIMER_OF_IRQ | TIMER_OF_BASE | TIMER_OF_CLOCK,
272a0858f93SStanley Chu 
273a0858f93SStanley Chu 	.clkevt = {
274a0858f93SStanley Chu 		.name = "mtk-clkevt",
275a0858f93SStanley Chu 		.rating = 300,
276a0858f93SStanley Chu 		.cpumask = cpu_possible_mask,
277a0858f93SStanley Chu 	},
278a0858f93SStanley Chu 
279a0858f93SStanley Chu 	.of_irq = {
280a0858f93SStanley Chu 		.flags = IRQF_TIMER | IRQF_IRQPOLL,
281a0858f93SStanley Chu 	},
282a0858f93SStanley Chu };
283a0858f93SStanley Chu 
mtk_syst_init(struct device_node * node)284e3af6776SStanley Chu static int __init mtk_syst_init(struct device_node *node)
285e3af6776SStanley Chu {
286e3af6776SStanley Chu 	int ret;
287e3af6776SStanley Chu 
288e3af6776SStanley Chu 	to.clkevt.features = CLOCK_EVT_FEAT_DYNIRQ | CLOCK_EVT_FEAT_ONESHOT;
289e3af6776SStanley Chu 	to.clkevt.set_state_shutdown = mtk_syst_clkevt_shutdown;
290e3af6776SStanley Chu 	to.clkevt.set_state_oneshot = mtk_syst_clkevt_oneshot;
291e3af6776SStanley Chu 	to.clkevt.tick_resume = mtk_syst_clkevt_resume;
292e3af6776SStanley Chu 	to.clkevt.set_next_event = mtk_syst_clkevt_next_event;
293e3af6776SStanley Chu 	to.of_irq.handler = mtk_syst_handler;
294e3af6776SStanley Chu 
295e3af6776SStanley Chu 	ret = timer_of_init(node, &to);
296e3af6776SStanley Chu 	if (ret)
29741d49e79SFabien Parent 		return ret;
298e3af6776SStanley Chu 
299e3af6776SStanley Chu 	clockevents_config_and_register(&to.clkevt, timer_of_rate(&to),
300e3af6776SStanley Chu 					TIMER_SYNC_TICKS, 0xffffffff);
301e3af6776SStanley Chu 
302e3af6776SStanley Chu 	return 0;
303e3af6776SStanley Chu }
304e3af6776SStanley Chu 
mtk_gpt_init(struct device_node * node)30556d52d3fSStanley Chu static int __init mtk_gpt_init(struct device_node *node)
3067ec58e52SStanley Chu {
307a0858f93SStanley Chu 	int ret;
3087ec58e52SStanley Chu 
309a0858f93SStanley Chu 	to.clkevt.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
310a0858f93SStanley Chu 	to.clkevt.set_state_shutdown = mtk_gpt_clkevt_shutdown;
311a0858f93SStanley Chu 	to.clkevt.set_state_periodic = mtk_gpt_clkevt_set_periodic;
312a0858f93SStanley Chu 	to.clkevt.set_state_oneshot = mtk_gpt_clkevt_shutdown;
313a0858f93SStanley Chu 	to.clkevt.tick_resume = mtk_gpt_clkevt_shutdown;
314a0858f93SStanley Chu 	to.clkevt.set_next_event = mtk_gpt_clkevt_next_event;
31575ac5cc2SEvan Benn 	to.clkevt.suspend = mtk_gpt_suspend;
31675ac5cc2SEvan Benn 	to.clkevt.resume = mtk_gpt_resume;
317a0858f93SStanley Chu 	to.of_irq.handler = mtk_gpt_interrupt;
3187ec58e52SStanley Chu 
319a0858f93SStanley Chu 	ret = timer_of_init(node, &to);
320a0858f93SStanley Chu 	if (ret)
32141d49e79SFabien Parent 		return ret;
3227ec58e52SStanley Chu 
3237ec58e52SStanley Chu 	/* Configure clock source */
324a0858f93SStanley Chu 	mtk_gpt_setup(&to, TIMER_CLK_SRC, GPT_CTRL_OP_FREERUN);
325a0858f93SStanley Chu 	clocksource_mmio_init(timer_of_base(&to) + GPT_CNT_REG(TIMER_CLK_SRC),
326a0858f93SStanley Chu 			      node->name, timer_of_rate(&to), 300, 32,
327a0858f93SStanley Chu 			      clocksource_mmio_readl_up);
328a0858f93SStanley Chu 	gpt_sched_reg = timer_of_base(&to) + GPT_CNT_REG(TIMER_CLK_SRC);
329a0858f93SStanley Chu 	sched_clock_register(mtk_gpt_read_sched_clock, 32, timer_of_rate(&to));
3307ec58e52SStanley Chu 
3317ec58e52SStanley Chu 	/* Configure clock event */
332a0858f93SStanley Chu 	mtk_gpt_setup(&to, TIMER_CLK_EVT, GPT_CTRL_OP_REPEAT);
333a0858f93SStanley Chu 	clockevents_config_and_register(&to.clkevt, timer_of_rate(&to),
334a0858f93SStanley Chu 					TIMER_SYNC_TICKS, 0xffffffff);
3357ec58e52SStanley Chu 
336a0858f93SStanley Chu 	mtk_gpt_enable_irq(&to, TIMER_CLK_EVT);
3377ec58e52SStanley Chu 
3387ec58e52SStanley Chu 	return 0;
3397ec58e52SStanley Chu }
34056d52d3fSStanley Chu TIMER_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_gpt_init);
341e3af6776SStanley Chu TIMER_OF_DECLARE(mtk_mt6765, "mediatek,mt6765-timer", mtk_syst_init);
342