^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __TIMER_OF_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __TIMER_OF_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/clockchips.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define TIMER_OF_BASE 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define TIMER_OF_CLOCK 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define TIMER_OF_IRQ 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) struct of_timer_irq {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) int percpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) irq_handler_t handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct of_timer_base {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct of_timer_clk {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) unsigned long rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) unsigned long period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct timer_of {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct clock_event_device clkevt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct of_timer_base of_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct of_timer_irq of_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct of_timer_clk of_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) void *private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static inline struct timer_of *to_timer_of(struct clock_event_device *clkevt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return container_of(clkevt, struct timer_of, clkevt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static inline void __iomem *timer_of_base(struct timer_of *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return to->of_base.base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static inline int timer_of_irq(struct timer_of *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return to->of_irq.irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static inline unsigned long timer_of_rate(struct timer_of *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) return to->of_clk.rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static inline unsigned long timer_of_period(struct timer_of *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return to->of_clk.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) extern int timer_of_init(struct device_node *np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct timer_of *to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) extern void timer_of_cleanup(struct timer_of *to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #endif