18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __TIMER_OF_H__
38c2ecf20Sopenharmony_ci#define __TIMER_OF_H__
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/clockchips.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#define TIMER_OF_BASE	0x1
88c2ecf20Sopenharmony_ci#define TIMER_OF_CLOCK	0x2
98c2ecf20Sopenharmony_ci#define TIMER_OF_IRQ	0x4
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cistruct of_timer_irq {
128c2ecf20Sopenharmony_ci	int irq;
138c2ecf20Sopenharmony_ci	int index;
148c2ecf20Sopenharmony_ci	int percpu;
158c2ecf20Sopenharmony_ci	const char *name;
168c2ecf20Sopenharmony_ci	unsigned long flags;
178c2ecf20Sopenharmony_ci	irq_handler_t handler;
188c2ecf20Sopenharmony_ci};
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistruct of_timer_base {
218c2ecf20Sopenharmony_ci	void __iomem *base;
228c2ecf20Sopenharmony_ci	const char *name;
238c2ecf20Sopenharmony_ci	int index;
248c2ecf20Sopenharmony_ci};
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistruct of_timer_clk {
278c2ecf20Sopenharmony_ci	struct clk *clk;
288c2ecf20Sopenharmony_ci	const char *name;
298c2ecf20Sopenharmony_ci	int index;
308c2ecf20Sopenharmony_ci	unsigned long rate;
318c2ecf20Sopenharmony_ci	unsigned long period;
328c2ecf20Sopenharmony_ci};
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistruct timer_of {
358c2ecf20Sopenharmony_ci	unsigned int flags;
368c2ecf20Sopenharmony_ci	struct device_node *np;
378c2ecf20Sopenharmony_ci	struct clock_event_device clkevt;
388c2ecf20Sopenharmony_ci	struct of_timer_base of_base;
398c2ecf20Sopenharmony_ci	struct of_timer_irq  of_irq;
408c2ecf20Sopenharmony_ci	struct of_timer_clk  of_clk;
418c2ecf20Sopenharmony_ci	void *private_data;
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic inline struct timer_of *to_timer_of(struct clock_event_device *clkevt)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	return container_of(clkevt, struct timer_of, clkevt);
478c2ecf20Sopenharmony_ci}
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistatic inline void __iomem *timer_of_base(struct timer_of *to)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci	return to->of_base.base;
528c2ecf20Sopenharmony_ci}
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistatic inline int timer_of_irq(struct timer_of *to)
558c2ecf20Sopenharmony_ci{
568c2ecf20Sopenharmony_ci	return to->of_irq.irq;
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistatic inline unsigned long timer_of_rate(struct timer_of *to)
608c2ecf20Sopenharmony_ci{
618c2ecf20Sopenharmony_ci	return to->of_clk.rate;
628c2ecf20Sopenharmony_ci}
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistatic inline unsigned long timer_of_period(struct timer_of *to)
658c2ecf20Sopenharmony_ci{
668c2ecf20Sopenharmony_ci	return to->of_clk.period;
678c2ecf20Sopenharmony_ci}
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciextern int __init timer_of_init(struct device_node *np,
708c2ecf20Sopenharmony_ci				struct timer_of *to);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ciextern void __init timer_of_cleanup(struct timer_of *to);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#endif
75