1 /* 2 * Copyright (c) 2023 Intel Corporation 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef _SEDI_DRIVER_HPET_H_ 8 #define _SEDI_DRIVER_HPET_H_ 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 #include "sedi_driver_common.h" 15 16 /*! 17 * \defgroup sedi_driver_hpet HPET 18 * \ingroup sedi_driver 19 */ 20 21 #define SEDI_HPET_API_VERSION SEDI_DRIVER_VERSION_MAJOR_MINOR(0, 1) 22 23 /*! 24 * \defgroup sedi_sideband_t HPET instance id 25 * \ingroup sedi_driver_hpet 26 */ 27 typedef enum { 28 HPET_0 = 0, 29 HPET_1, 30 HPET_2, 31 HPET_NUM, 32 } sedi_hpet_t; 33 34 /*! 35 * \struct sedi_hpet_capabilities_t 36 * \brief HPET Driver Capabilities. 37 * \ingroup sedi_driver_hpet 38 */ 39 typedef struct sedi_hpet_capabilities { 40 uint32_t reserved; 41 } sedi_hpet_capabilities_t; 42 43 /*! 44 * \defgroup hpet_function_calls HEPT Driver Function Calls 45 * \ingroup sedi_driver_hpet 46 * \{ 47 */ 48 49 /*! 50 * \brief Hpet callback function. 51 * \param param User callback parameter. 52 */ 53 typedef int (*hpet_callback_t)(void *param); 54 55 /*! 56 * \brief Get the hpet driver's API version. 57 * \return the version of current hpet driver's API 58 */ 59 sedi_driver_version_t sedi_hpet_get_version(void); 60 61 /*! 62 * \brief Get the device's capabilities. 63 * \return the capabilities of hpet device 64 */ 65 sedi_hpet_capabilities_t sedi_hpet_get_capabilities(void); 66 67 /*! 68 * \brief Get HPET's current setting of minimal delay time. 69 * \return HPET's current setting of minimal delay time. 70 */ 71 uint32_t sedi_hpet_get_min_delay(void); 72 73 /*! 74 * \brief Set HPET's minimal delay time. The comparator value must be set 75 * farther than this value, ahead of the current main counter value. 76 * Or interrupt might be missed due to the hardware latency 77 * \param[in] min_delay: SoC-specific HPET minimal delay time. 78 */ 79 void sedi_hpet_set_min_delay(uint32_t min_delay); 80 81 /*! 82 * \brief Initialize the device 83 * \param[in] clk_divisor: the clock divisor to set. 84 * \param[in] min_delay: SoC-specific HPET minimal delay time to set. 85 * \return \ref return_status 86 */ 87 int32_t sedi_hpet_init(uint32_t clk_divisor, uint32_t min_delay); 88 89 /*! 90 * \brief Uninitialize the device 91 * \return \ref return_status 92 */ 93 int32_t sedi_hpet_uninit(void); 94 95 /*! 96 * \brief Set the device's power 97 * \param[in] state: the power state to be set to the device 98 * \return \ref return_status 99 */ 100 int32_t sedi_hpet_set_power(IN sedi_power_state_t state); 101 102 /*! 103 * \brief Set the timer's comparator. This means when to trigger an interrupt. 104 * \param[in] timer_id: Timer ID to set. 105 * \param[in] value: The value need to set. 106 * \return \ref return_status 107 */ 108 int sedi_hpet_set_comparator(IN sedi_hpet_t timer_id, IN uint64_t value); 109 110 /*! 111 * \brief Set the timer's main counter to the new value. 112 * \param[in] value: The value need to set. 113 */ 114 void sedi_hpet_set_main_counter(uint64_t value); 115 116 /*! 117 * \brief Get the timer's current value of main counter. 118 * \return The current value of main counter. 119 */ 120 uint64_t sedi_hpet_get_main_counter(void); 121 122 /*! 123 * \brief Enable the timer's interrupt. 124 * \param[in] timer_id: Timer ID to enable interrupt. 125 */ 126 void sedi_hpet_enable_interrupt(IN sedi_hpet_t timer_id); 127 128 /*! 129 * \brief Disable the timer's interrupt. 130 * \param[in] timer_id: Timer ID to enable interrupt. 131 */ 132 void sedi_hpet_disable_interrupt(IN sedi_hpet_t timer_id); 133 134 /*! 135 * \brief Get the interrupt status. 136 * \return the current value of the interrupt status. 137 */ 138 uint32_t sedi_hpet_get_int_status(void); 139 140 /*! 141 * \brief Set value to the interrupt status to clear. 142 * \param[in] val: val to set to the interrupt status. 143 */ 144 void sedi_hpet_set_int_status(IN uint32_t val); 145 146 /*! 147 * \brief Handle the interrupt of HPET Timer N 148 * \param[in] timer_id: Timer ID to handle. 149 */ 150 void sedi_hpet_timer_int_handler(IN sedi_hpet_t timer_id); 151 152 /*! 153 * \brief Get the timer's period, specified in picoseconds. 154 * \1000000 ps: (1 MHz clock period) 155 * \83333 ps: (12 MHz clock period) 156 * \30517578 ps: (32.768 KHz clock period) 157 * \return the value of period. 158 */ 159 uint32_t sedi_hpet_get_period(void); 160 161 /*! 162 * \brief initialize one timer 163 * \param[in] timer_id Timer index to be configured 164 * \param[in] microseconds: the cycle of timer 165 * \param[in] callback: callback function when timeout 166 * \param[in] param: callback parameters 167 * \param[in] one_shot: if it is a one_shot timer 168 * \return fail reason 169 */ 170 int32_t sedi_hpet_config_timer(IN sedi_hpet_t timer_id, 171 IN uint64_t microseconds, 172 IN hpet_callback_t callback, IN void *param, 173 IN bool one_shot); 174 175 /*! 176 * \brief start the timer 177 * \param[in] timer_id: the timer's id 178 * \return fail reason 179 */ 180 int32_t sedi_hpet_start_timer(IN sedi_hpet_t timer_id); 181 182 /*! 183 * \brief kill the timer 184 * \param[in] timer_id: the timer's id 185 * \return fail reason 186 */ 187 int32_t sedi_hpet_kill_timer(IN sedi_hpet_t timer_id); 188 189 /*! 190 * \} 191 */ 192 193 #ifdef __cplusplus 194 } 195 #endif 196 197 #endif /* _SEDI_DRIVER_HPET_H_*/ 198