xref: /linux/include/clocksource/timer-xilinx.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1bc1ce713SSean Anderson /* SPDX-License-Identifier: GPL-2.0+ */
2bc1ce713SSean Anderson /*
3bc1ce713SSean Anderson  * Copyright (C) 2021 Sean Anderson <sean.anderson@seco.com>
4bc1ce713SSean Anderson  */
5bc1ce713SSean Anderson 
6bc1ce713SSean Anderson #ifndef XILINX_TIMER_H
7bc1ce713SSean Anderson #define XILINX_TIMER_H
8bc1ce713SSean Anderson 
9bc1ce713SSean Anderson #include <linux/compiler.h>
10bc1ce713SSean Anderson 
11bc1ce713SSean Anderson #define TCSR0	0x00
12bc1ce713SSean Anderson #define TLR0	0x04
13bc1ce713SSean Anderson #define TCR0	0x08
14bc1ce713SSean Anderson #define TCSR1	0x10
15bc1ce713SSean Anderson #define TLR1	0x14
16bc1ce713SSean Anderson #define TCR1	0x18
17bc1ce713SSean Anderson 
18bc1ce713SSean Anderson #define TCSR_MDT	BIT(0)
19bc1ce713SSean Anderson #define TCSR_UDT	BIT(1)
20bc1ce713SSean Anderson #define TCSR_GENT	BIT(2)
21bc1ce713SSean Anderson #define TCSR_CAPT	BIT(3)
22bc1ce713SSean Anderson #define TCSR_ARHT	BIT(4)
23bc1ce713SSean Anderson #define TCSR_LOAD	BIT(5)
24bc1ce713SSean Anderson #define TCSR_ENIT	BIT(6)
25bc1ce713SSean Anderson #define TCSR_ENT	BIT(7)
26bc1ce713SSean Anderson #define TCSR_TINT	BIT(8)
27bc1ce713SSean Anderson #define TCSR_PWMA	BIT(9)
28bc1ce713SSean Anderson #define TCSR_ENALL	BIT(10)
29bc1ce713SSean Anderson #define TCSR_CASC	BIT(11)
30bc1ce713SSean Anderson 
31bc1ce713SSean Anderson struct clk;
32bc1ce713SSean Anderson struct device_node;
33bc1ce713SSean Anderson struct regmap;
34bc1ce713SSean Anderson 
35bc1ce713SSean Anderson /**
36bc1ce713SSean Anderson  * struct xilinx_timer_priv - Private data for Xilinx AXI timer drivers
37bc1ce713SSean Anderson  * @map: Regmap of the device, possibly with an offset
38bc1ce713SSean Anderson  * @clk: Parent clock
39bc1ce713SSean Anderson  * @max: Maximum value of the counters
40bc1ce713SSean Anderson  */
41bc1ce713SSean Anderson struct xilinx_timer_priv {
42bc1ce713SSean Anderson 	struct regmap *map;
43bc1ce713SSean Anderson 	struct clk *clk;
44*56f45266SKen Sloat 	u64 max;
45bc1ce713SSean Anderson };
46bc1ce713SSean Anderson 
47bc1ce713SSean Anderson /**
48bc1ce713SSean Anderson  * xilinx_timer_tlr_cycles() - Calculate the TLR for a period specified
49bc1ce713SSean Anderson  *                             in clock cycles
50bc1ce713SSean Anderson  * @priv: The timer's private data
51bc1ce713SSean Anderson  * @tcsr: The value of the TCSR register for this counter
52bc1ce713SSean Anderson  * @cycles: The number of cycles in this period
53bc1ce713SSean Anderson  *
54bc1ce713SSean Anderson  * Callers of this function MUST ensure that @cycles is representable as
55bc1ce713SSean Anderson  * a TLR.
56bc1ce713SSean Anderson  *
57bc1ce713SSean Anderson  * Return: The calculated value for TLR
58bc1ce713SSean Anderson  */
59bc1ce713SSean Anderson u32 xilinx_timer_tlr_cycles(struct xilinx_timer_priv *priv, u32 tcsr,
60bc1ce713SSean Anderson 			    u64 cycles);
61bc1ce713SSean Anderson 
62bc1ce713SSean Anderson /**
63bc1ce713SSean Anderson  * xilinx_timer_get_period() - Get the current period of a counter
64bc1ce713SSean Anderson  * @priv: The timer's private data
65bc1ce713SSean Anderson  * @tlr: The value of TLR for this counter
66bc1ce713SSean Anderson  * @tcsr: The value of TCSR for this counter
67bc1ce713SSean Anderson  *
68bc1ce713SSean Anderson  * Return: The period, in ns
69bc1ce713SSean Anderson  */
70bc1ce713SSean Anderson unsigned int xilinx_timer_get_period(struct xilinx_timer_priv *priv,
71bc1ce713SSean Anderson 				     u32 tlr, u32 tcsr);
72bc1ce713SSean Anderson 
73bc1ce713SSean Anderson #endif /* XILINX_TIMER_H */
74