timer.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #ifndef _TIMER_H_
  7. #define _TIMER_H_
  8. /*
  9. * dm_timer_init - initialize a timer for time keeping. On success
  10. * initializes gd->timer so that lib/timer can use it for future
  11. * referrence.
  12. *
  13. * @return - 0 on success or error number
  14. */
  15. int dm_timer_init(void);
  16. /*
  17. * timer_conv_64 - convert 32-bit counter value to 64-bit
  18. *
  19. * @count: 32-bit counter value
  20. * @return: 64-bit counter value
  21. */
  22. u64 timer_conv_64(u32 count);
  23. /*
  24. * Get the current timer count
  25. *
  26. * @dev: The timer device
  27. * @count: pointer that returns the current timer count
  28. * @return: 0 if OK, -ve on error
  29. */
  30. int timer_get_count(struct udevice *dev, u64 *count);
  31. /*
  32. * Get the timer input clock frequency
  33. *
  34. * @dev: The timer device
  35. * @return: the timer input clock frequency
  36. */
  37. unsigned long timer_get_rate(struct udevice *dev);
  38. /*
  39. * struct timer_ops - Driver model timer operations
  40. *
  41. * The uclass interface is implemented by all timer devices which use
  42. * driver model.
  43. */
  44. struct timer_ops {
  45. /*
  46. * Get the current timer count
  47. *
  48. * @dev: The timer device
  49. * @count: pointer that returns the current 64-bit timer count
  50. * @return: 0 if OK, -ve on error
  51. */
  52. int (*get_count)(struct udevice *dev, u64 *count);
  53. };
  54. /*
  55. * struct timer_dev_priv - information about a device used by the uclass
  56. *
  57. * @clock_rate: the timer input clock frequency
  58. */
  59. struct timer_dev_priv {
  60. unsigned long clock_rate;
  61. };
  62. /**
  63. * timer_early_get_count() - Implement timer_get_count() before driver model
  64. *
  65. * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return
  66. * the current timer value before the proper driver model timer is ready.
  67. * It should be implemented by one of the timer values. This is mostly useful
  68. * for tracing.
  69. */
  70. u64 timer_early_get_count(void);
  71. /**
  72. * timer_early_get_rate() - Get the timer rate before driver model
  73. *
  74. * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return
  75. * the current timer rate in Hz before the proper driver model timer is ready.
  76. * It should be implemented by one of the timer values. This is mostly useful
  77. * for tracing. This corresponds to the clock_rate value in struct
  78. * timer_dev_priv.
  79. */
  80. unsigned long timer_early_get_rate(void);
  81. #endif /* _TIMER_H_ */