timer.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. *
  32. * @count: 32-bit counter value
  33. * @return: 64-bit counter value
  34. */
  35. u64 timer_conv_64(u32 count);
  36. /*
  37. * Get the current timer count
  38. *
  39. * @dev: The timer device
  40. * @count: pointer that returns the current timer count
  41. * @return: 0 if OK, -ve on error
  42. */
  43. int timer_get_count(struct udevice *dev, u64 *count);
  44. /*
  45. * Get the timer input clock frequency
  46. *
  47. * @dev: The timer device
  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 the current timer count
  60. *
  61. * @dev: The timer device
  62. * @count: pointer that returns the current 64-bit timer count
  63. * @return: 0 if OK, -ve on error
  64. */
  65. int (*get_count)(struct udevice *dev, u64 *count);
  66. };
  67. /*
  68. * struct timer_dev_priv - information about a device used by the uclass
  69. *
  70. * @clock_rate: the timer input clock frequency
  71. */
  72. struct timer_dev_priv {
  73. unsigned long clock_rate;
  74. };
  75. /**
  76. * timer_early_get_count() - Implement timer_get_count() before driver model
  77. *
  78. * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return
  79. * the current timer value before the proper driver model timer is ready.
  80. * It should be implemented by one of the timer values. This is mostly useful
  81. * for tracing.
  82. */
  83. u64 timer_early_get_count(void);
  84. /**
  85. * timer_early_get_rate() - Get the timer rate before driver model
  86. *
  87. * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return
  88. * the current timer rate in Hz before the proper driver model timer is ready.
  89. * It should be implemented by one of the timer values. This is mostly useful
  90. * for tracing. This corresponds to the clock_rate value in struct
  91. * timer_dev_priv.
  92. */
  93. unsigned long timer_early_get_rate(void);
  94. #endif /* _TIMER_H_ */