timer.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_conv_64 - convert 32-bit counter value to 64-bit
  17. *
  18. * @count: 32-bit counter value
  19. * @return: 64-bit counter value
  20. */
  21. u64 timer_conv_64(u32 count);
  22. /*
  23. * Get the current timer count
  24. *
  25. * @dev: The timer device
  26. * @count: pointer that returns the current timer count
  27. * @return: 0 if OK, -ve on error
  28. */
  29. int timer_get_count(struct udevice *dev, u64 *count);
  30. /*
  31. * Get the timer input clock frequency
  32. *
  33. * @dev: The timer device
  34. * @return: the timer input clock frequency
  35. */
  36. unsigned long timer_get_rate(struct udevice *dev);
  37. /*
  38. * struct timer_ops - Driver model timer operations
  39. *
  40. * The uclass interface is implemented by all timer devices which use
  41. * driver model.
  42. */
  43. struct timer_ops {
  44. /*
  45. * Get the current timer count
  46. *
  47. * @dev: The timer device
  48. * @count: pointer that returns the current 64-bit timer count
  49. * @return: 0 if OK, -ve on error
  50. */
  51. int (*get_count)(struct udevice *dev, u64 *count);
  52. };
  53. /*
  54. * struct timer_dev_priv - information about a device used by the uclass
  55. *
  56. * @clock_rate: the timer input clock frequency
  57. */
  58. struct timer_dev_priv {
  59. unsigned long clock_rate;
  60. };
  61. /**
  62. * timer_early_get_count() - Implement timer_get_count() before driver model
  63. *
  64. * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return
  65. * the current timer value before the proper driver model timer is ready.
  66. * It should be implemented by one of the timer values. This is mostly useful
  67. * for tracing.
  68. */
  69. u64 timer_early_get_count(void);
  70. /**
  71. * timer_early_get_rate() - Get the timer rate before driver model
  72. *
  73. * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return
  74. * the current timer rate in Hz before the proper driver model timer is ready.
  75. * It should be implemented by one of the timer values. This is mostly useful
  76. * for tracing. This corresponds to the clock_rate value in struct
  77. * timer_dev_priv.
  78. */
  79. unsigned long timer_early_get_rate(void);
  80. #endif /* _TIMER_H_ */