1 /* 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * Description: Low-power management operations for peripheral devices. 15 * 16 * Create: 2021-4-28 17 */ 18 19 #ifndef LPM_DEV_OPS_H 20 #define LPM_DEV_OPS_H 21 #include <stdbool.h> 22 23 #ifdef __cplusplus 24 #if __cplusplus 25 extern "C" { 26 #endif /* __cplusplus */ 27 #endif /* __cplusplus */ 28 29 /** 30 * @defgroup connectivity_drivers_non_os_lpm LPM 31 * @ingroup connectivity_drivers_non_os 32 * @{ 33 */ 34 /** 35 * @brief The peripheral device operation functions. 36 * @note The functions are registered by pmu/clocks and is used by peripheral devices. 37 */ 38 typedef struct { 39 int (*power_on)(bool); /*!< Power on or power off the device. */ 40 int (*power_sts)(void); /*!< Get the device power status. */ 41 int (*set_voltage)(int); /*!< Config the device voltage. */ 42 int (*get_voltage)(void); /*!< Get the device voltage. */ 43 int (*clock_en)(bool); /*!< Enable or disable the device clock switch. */ 44 int (*clock_sts)(void); /*!< Get the device clock switch status. */ 45 int (*set_freq)(int); /*!< Set the clock frequency of the device. */ 46 int (*get_freq)(void); /*!< Get the clock frequency of the device. */ 47 int (*set_div_num)(int); /*!< Set the clock frequency divider of the device. */ 48 int (*get_div_num)(void); /*!< Get the clock frequency divider of the device. */ 49 int (*sub_clken)(int, bool); /*!< Enables or disables the clock of a subdevice. */ 50 int (*resume)(void); /*!< Resume the device. */ 51 int (*suspend)(void); /*!< Suspend the device. */ 52 } lpm_dev_ops_t; 53 54 /** 55 * @brief Peripheral device ID. 56 */ 57 typedef enum { 58 DEV_ADC, 59 DEV_I2C, 60 DEV_DMA, 61 DEV_SPI, 62 DEV_QSPI, 63 DEV_UART, 64 DEV_CAP, 65 DEV_OPI, 66 DEV_PSRAM, 67 DEV_IR, 68 DEV_EMMC, 69 DEV_SDIO, 70 DEV_DSS, 71 DEV_GPU, 72 DEV_PCIE, 73 DEV_PWM, 74 DEV_MAX, 75 } lpm_dev_id_t; 76 77 /** 78 * @brief Function return value. 79 */ 80 typedef enum { 81 LPM_RET_OK = 0, /*!< Run successfully. */ 82 LPM_RET_NOREG, /*!< Not register. */ 83 LPM_RET_ON, /*!< The switch status is ON. */ 84 LPM_RET_OFF, /*!< The switch status is OFF. */ 85 LPM_RET_ERR, /*!< Run error. */ 86 LPM_RET_UNINIT, /*!< Uninitialized. */ 87 LPM_RET_MAX, 88 } lpm_ret_t; 89 90 typedef void (*lpm_clock_init_callback)(void); 91 92 /** 93 * @brief The peripheral device operations init. 94 * @return Result of the operation, true indicates success, false for failed. 95 */ 96 bool lpm_dev_ops_init(void); 97 98 /** 99 * @brief The peripheral device operations deinit. 100 * @return Result of the operation, true indicates success, false for failed. 101 */ 102 bool lpm_dev_ops_deinit(void); 103 104 /** 105 * @brief Register low-power operation interface of the peripheral device. 106 * @param id Peripheral device ID. 107 * @param ops Peripheral device operation methods. 108 * @return Result of the operation, true indicates success, false for failed. 109 */ 110 bool lpm_dev_ops_register(lpm_dev_id_t id, lpm_dev_ops_t *ops); 111 112 /** 113 * @brief Deregister low-power operation interface of the peripheral device. 114 * @param id Peripheral device ID. 115 * @return Result of the operation, true indicates success, false for failed. 116 */ 117 bool lpm_dev_ops_unregister(lpm_dev_id_t id); 118 119 /** 120 * @brief Update the operation function of the device. 121 * @param id Peripheral device ID. 122 * @param ops ops Peripheral device operation methods. 123 * @return Success or not, for details, refer to lpm_ret_t. 124 */ 125 int lpm_dev_ops_update(lpm_dev_id_t id, lpm_dev_ops_t *ops); 126 127 /** 128 * @brief Power on or power off the peripheral device. 129 * @param id Peripheral device ID. 130 * @param on Power on or Power off. 131 * @return Success or not, for details, refer to lpm_ret_t. 132 */ 133 int lpm_dev_power_on(lpm_dev_id_t id, bool on); 134 135 /** 136 * @brief Get the power status of peripheral Devices. 137 * @param id Peripheral device ID. 138 * @return Power status, for details, refer to lpm_ret_t. 139 */ 140 int lpm_dev_get_power_sts(lpm_dev_id_t id); 141 142 /** 143 * @brief Config the peripheral device voltage. 144 * @param id Peripheral device ID. 145 * @param vset Voltage to be configured. 146 * @return Success or not, for details, refer to lpm_ret_t. 147 */ 148 int lpm_dev_set_voltage(lpm_dev_id_t id, int vset); 149 150 /** 151 * @brief Get the voltage of peripheral device. 152 * @param id Peripheral device ID. 153 * @return Current voltage of the peripheral device. 154 */ 155 int lpm_dev_get_voltage(lpm_dev_id_t id); 156 157 /** 158 * @brief Enable or disable the device clock switch. 159 * @param id Peripheral device ID. 160 * @param on Enable or disable. 161 * @return Success or not, for details, refer to lpm_ret_t. 162 */ 163 int lpm_dev_clock_en(lpm_dev_id_t id, bool on); 164 165 /** 166 * @brief Get the device clock switch status. 167 * @param id Peripheral device ID. 168 * @return Clock enable status, for details, refer to lpm_ret_t. 169 */ 170 int lpm_dev_get_clock_sts(lpm_dev_id_t id); 171 172 /** 173 * @brief Set the clock frequency of the peripheral device. 174 * @param id Peripheral device ID. 175 * @param freq Frequency to be configured. 176 * @return Success or not, for details, refer to lpm_ret_t. 177 */ 178 int lpm_dev_set_freq(lpm_dev_id_t id, int freq); 179 180 /** 181 * @brief Get the clock frequency of the peripheral device. 182 * @param id Peripheral device ID. 183 * @return Current frequency of the peripheral device. 184 */ 185 int lpm_dev_get_freq(lpm_dev_id_t id); 186 187 /** 188 * @brief Set the divider number of the peripheral device clock. 189 * @param id Peripheral device ID. 190 * @param clk_div Divider number to be configured. 191 * @return Success or not, for details, refer to lpm_ret_t. 192 */ 193 int lpm_dev_set_div_num(lpm_dev_id_t id, int clk_div); 194 195 /** 196 * @brief Get the divider number of the peripheral device clock. 197 * @param id Peripheral device ID. 198 * @return Current divider number of the peripheral device clock. 199 */ 200 int lpm_dev_get_div_num(lpm_dev_id_t id); 201 202 /** 203 * @brief Enables or disables the clock of a subdevice. 204 * @param id Peripheral device ID. 205 * @param bus Sub device bus number. 206 * @param on Enable or disable. 207 * @return Success or not, for details, refer to lpm_ret_t. 208 */ 209 int lpm_dev_sub_bus_clken(lpm_dev_id_t id, int bus, bool on); 210 211 /** 212 * @brief Registering the callback function for clock initialization configuration of the display module. 213 * @param callback Callback function. 214 */ 215 void lpm_display_clocks_init_register_callback(lpm_clock_init_callback callback); 216 217 /** 218 * @brief Clock initialization configuration of the display module. 219 */ 220 void lpm_display_clocks_init(void); 221 222 /** 223 * @} 224 */ 225 #ifdef __cplusplus 226 #if __cplusplus 227 } 228 #endif /* __cplusplus */ 229 #endif /* __cplusplus */ 230 #endif