timer.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
  4. */
  5. #ifndef _TIMER_H_
  6. #define _TIMER_H_
  7. /**
  8. * dm_timer_init() - initialize a timer for time keeping. On success
  9. * initializes gd->timer so that lib/timer can use it for future
  10. * referrence.
  11. *
  12. * Return: 0 on success or error number
  13. */
  14. int dm_timer_init(void);
  15. /**
  16. * timer_timebase_fallback() - Helper for timers using timebase fallback
  17. * @dev: A timer partially-probed timer device
  18. *
  19. * This is a helper function designed for timers which need to fall back on the
  20. * cpu's timebase. This function is designed to be called during the driver's
  21. * probe(). If there is a clocks or clock-frequency property in the timer's
  22. * binding, then it will be used. Otherwise, the timebase of the current cpu
  23. * will be used. This is initialized by the cpu driver, and usually gotten from
  24. * ``/cpus/timebase-frequency`` or ``/cpus/cpu@X/timebase-frequency``.
  25. *
  26. * Return: 0 if OK, or negative error code on failure
  27. */
  28. int timer_timebase_fallback(struct udevice *dev);
  29. /**
  30. * timer_conv_64() - convert 32-bit counter value to 64-bit
  31. * @count: 32-bit counter value
  32. *
  33. * Return: 64-bit counter value
  34. */
  35. u64 timer_conv_64(u32 count);
  36. /**
  37. * timer_get_count() - Get the current timer count
  38. * @dev: The timer device
  39. * @count: pointer that returns the current timer count
  40. *
  41. * Return: 0 if OK, -ve on error
  42. */
  43. int timer_get_count(struct udevice *dev, u64 *count);
  44. /**
  45. * timer_get_rate() - Get the timer input clock frequency
  46. * @dev: The timer device
  47. *
  48. * Return: the timer input clock frequency
  49. */
  50. unsigned long timer_get_rate(struct udevice *dev);
  51. /**
  52. * struct timer_ops - Driver model timer operations
  53. *
  54. * The uclass interface is implemented by all timer devices which use
  55. * driver model.
  56. */
  57. struct timer_ops {
  58. /**
  59. * @get_count: Get the current timer count
  60. *
  61. * @dev: The timer device
  62. *
  63. * This function may be called at any time after the driver is probed.
  64. * All necessary initialization must be completed by the time probe()
  65. * returns. The count returned by this functions should be monotonic.
  66. * This function must succeed.
  67. *
  68. * Return: The current 64-bit timer count
  69. */
  70. u64 (*get_count)(struct udevice *dev);
  71. };
  72. /**
  73. * struct timer_dev_priv - information about a device used by the uclass
  74. *
  75. * @clock_rate: the timer input clock frequency
  76. */
  77. struct timer_dev_priv {
  78. unsigned long clock_rate;
  79. };
  80. /**
  81. * timer_early_get_count() - Implement timer_get_count() before driver model
  82. *
  83. * If ``CONFIG_TIMER_EARLY`` is enabled, this function wil be called to return
  84. * the current timer value before the proper driver model timer is ready.
  85. * It should be implemented by one of the timer values. This is mostly useful
  86. * for tracing.
  87. */
  88. u64 timer_early_get_count(void);
  89. /**
  90. * timer_early_get_rate() - Get the timer rate before driver model
  91. *
  92. * If ``CONFIG_TIMER_EARLY`` is enabled, this function wil be called to return
  93. * the current timer rate in Hz before the proper driver model timer is ready.
  94. * It should be implemented by one of the timer values. This is mostly useful
  95. * for tracing. This corresponds to the clock_rate value in struct
  96. * timer_dev_priv.
  97. */
  98. unsigned long timer_early_get_rate(void);
  99. #endif /* _TIMER_H_ */