timer-xilinx.h 1.7 KB

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