Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * Copyright (C) 2021 Sean Anderson <sean.anderson@seco.com>
0004  */
0005 
0006 #ifndef XILINX_TIMER_H
0007 #define XILINX_TIMER_H
0008 
0009 #include <linux/compiler.h>
0010 
0011 #define TCSR0   0x00
0012 #define TLR0    0x04
0013 #define TCR0    0x08
0014 #define TCSR1   0x10
0015 #define TLR1    0x14
0016 #define TCR1    0x18
0017 
0018 #define TCSR_MDT    BIT(0)
0019 #define TCSR_UDT    BIT(1)
0020 #define TCSR_GENT   BIT(2)
0021 #define TCSR_CAPT   BIT(3)
0022 #define TCSR_ARHT   BIT(4)
0023 #define TCSR_LOAD   BIT(5)
0024 #define TCSR_ENIT   BIT(6)
0025 #define TCSR_ENT    BIT(7)
0026 #define TCSR_TINT   BIT(8)
0027 #define TCSR_PWMA   BIT(9)
0028 #define TCSR_ENALL  BIT(10)
0029 #define TCSR_CASC   BIT(11)
0030 
0031 struct clk;
0032 struct device_node;
0033 struct regmap;
0034 
0035 /**
0036  * struct xilinx_timer_priv - Private data for Xilinx AXI timer drivers
0037  * @map: Regmap of the device, possibly with an offset
0038  * @clk: Parent clock
0039  * @max: Maximum value of the counters
0040  */
0041 struct xilinx_timer_priv {
0042     struct regmap *map;
0043     struct clk *clk;
0044     u32 max;
0045 };
0046 
0047 /**
0048  * xilinx_timer_tlr_cycles() - Calculate the TLR for a period specified
0049  *                             in clock cycles
0050  * @priv: The timer's private data
0051  * @tcsr: The value of the TCSR register for this counter
0052  * @cycles: The number of cycles in this period
0053  *
0054  * Callers of this function MUST ensure that @cycles is representable as
0055  * a TLR.
0056  *
0057  * Return: The calculated value for TLR
0058  */
0059 u32 xilinx_timer_tlr_cycles(struct xilinx_timer_priv *priv, u32 tcsr,
0060                 u64 cycles);
0061 
0062 /**
0063  * xilinx_timer_get_period() - Get the current period of a counter
0064  * @priv: The timer's private data
0065  * @tlr: The value of TLR for this counter
0066  * @tcsr: The value of TCSR for this counter
0067  *
0068  * Return: The period, in ns
0069  */
0070 unsigned int xilinx_timer_get_period(struct xilinx_timer_priv *priv,
0071                      u32 tlr, u32 tcsr);
0072 
0073 #endif /* XILINX_TIMER_H */