1 /* 2 * Copyright (c) 2023 Intel Corporation 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef _SEDI_DRIVER_GPIO_H_ 8 #define _SEDI_DRIVER_GPIO_H_ 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 #include "sedi_driver_common.h" 15 16 /*! 17 * \defgroup sedi_driver_gpio GPIO 18 * \ingroup sedi_driver 19 */ 20 21 #define SEDI_GPIO_API_VERSION SEDI_DRIVER_VERSION_MAJOR_MINOR(0, 1) 22 23 /****** GPIO pin config *****/ 24 25 /*! 26 * \defgroup gpio_pin_config GPIO Pin Configuration 27 * \ingroup sedi_driver_gpio 28 * \{ 29 */ 30 31 /*! 32 * \struct sedi_gpio_port_ 33 * \brief GPIO pin port enumeration 34 */ 35 typedef enum { 36 GPIO_PORT_0 = 0, 37 GPIO_PORT_1, 38 GPIO_PORT_2, 39 GPIO_PORT_3, 40 GPIO_PORT_4, 41 GPIO_PORT_5, 42 GPIO_PORT_MAX_NUM 43 } sedi_gpio_port_t; 44 45 /*! 46 * \struct sedi_gpio_direction_mode_ 47 * \brief GPIO pin direction enumeration 48 */ 49 typedef enum { 50 SEDI_GPIO_DIR_MODE_INPUT = 0, 51 SEDI_GPIO_DIR_MODE_OUTPUT 52 } sedi_gpio_direction_mode_t; 53 54 /*! 55 * \struct sedi_gpio_interrupt_mode_ 56 * \brief GPIO interrupt mode enumeration 57 */ 58 typedef enum { 59 SEDI_GPIO_INT_MODE_FALLING_EDGE = 0x1, 60 SEDI_GPIO_INT_MODE_RISING_EDGE = 0x2, 61 SEDI_GPIO_INT_MODE_BOTH_EDGE = 0x3 62 } sedi_gpio_interrupt_mode_t; 63 64 /*! 65 * \struct sedi_gpio_pin_config_ 66 * \brief GPIO Pin Config Structure definition 67 */ 68 typedef struct { 69 sedi_gpio_direction_mode_t direction; 70 bool enable_interrupt; 71 bool enable_wakeup; 72 sedi_gpio_interrupt_mode_t interrupt_mode; 73 } sedi_gpio_pin_config_t; 74 75 /*! 76 * \} 77 */ 78 79 /*! 80 * \struct sedi_gpio_pin_state 81 * \brief GPIO pin low or high value enumeration 82 * \ingroup sedi_driver_gpio 83 */ 84 typedef enum { 85 SEDI_GPIO_STATE_LOW = 0, 86 SEDI_GPIO_STATE_HIGH 87 } sedi_gpio_pin_state_t; 88 89 /****** GPIO Event *****/ 90 91 /*! 92 * \defgroup gpio_event GPIO Event Types 93 * \ingroup sedi_driver_gpio 94 * \{ 95 */ 96 97 /*! 98 * \def SEDI_GPIO_EVENT_INTERRUPT 99 * \brief Interrupt event 100 */ 101 #define SEDI_GPIO_EVENT_INTERRUPT (1UL << 0) 102 103 /*! 104 * \} 105 */ 106 107 /*! 108 * \struct sedi_gpio_capabilities_t 109 * \brief GPIO Driver Capabilities. 110 * \ingroup sedi_driver_gpio 111 */ 112 typedef struct { 113 uint32_t support_pins_map; /**< supports pins map */ 114 uint32_t support_timestamp : 1; /**< interrupt supports timestamp */ 115 uint32_t is_available : 1; /** 1:available 0:used by host **/ 116 uint32_t reserved : 30; /**< Reserved (must be zero) */ 117 } sedi_gpio_capabilities_t; 118 119 /*! 120 * \defgroup gpio_event_handler GPIO Event Handler Callback 121 * \ingroup sedi_driver_gpio 122 * \{ 123 */ 124 /*! 125 * \typedef sedi_gpio_event_cb_t 126 * \brief Callback function type for signal gpio event. 127 * \param[in] pin_mask: 32-bits pin mask, indicate the pins trigger this 128 * callback. 129 * \param[in] group: Group number, a port can cover 32 pins. 130 * \param[in] param: User callback parameter pointer. 131 * \return void 132 */ 133 typedef void (*sedi_gpio_event_cb_t)(IN uint32_t pin_mask, 134 IN sedi_gpio_port_t port, 135 INOUT void *param); 136 137 /*! 138 * \} 139 */ 140 141 /*! 142 * \defgroup gpio_function_calls GPIO Driver Function Calls 143 * \ingroup sedi_driver_gpio 144 * \{ 145 */ 146 147 /*! 148 * \brief Get the gpio driver's API version. 149 * \return the version of current gpio driver's API 150 */ 151 sedi_driver_version_t sedi_gpio_get_version(void); 152 153 /*! 154 * \brief Get the device's capabilities. 155 * \param[in] gpio_device: device id 156 * \param[out] cap: gpio device capabilities 157 * \return \ref return_status 158 */ 159 int32_t sedi_gpio_get_capabilities(IN sedi_gpio_t gpio_device, 160 OUT sedi_gpio_capabilities_t *cap); 161 162 /*! 163 * \brief Initialize the device 164 * \param[in] gpio_device: gpio device id 165 * \param[in] cb: the callback function which can receive device's events. 166 * \param[in] param: User parameter for callback function. 167 * \return \ref return_status 168 */ 169 int32_t sedi_gpio_init(IN sedi_gpio_t gpio_device, IN sedi_gpio_event_cb_t cb, 170 INOUT void *param); 171 172 /*! 173 * \brief Uninitialize the device 174 * \param[in] gpio_device: gpio device id 175 * \return \ref return_status 176 */ 177 int32_t sedi_gpio_uninit(IN sedi_gpio_t gpio_device); 178 179 /*! 180 * \brief Set the device's power 181 * \param[in] gpio_device: gpio device id 182 * \param[in] state: the power state to be set to the device 183 * \return \ref return_status 184 */ 185 int32_t sedi_gpio_set_power(IN sedi_gpio_t gpio_device, 186 IN sedi_power_state_t state); 187 188 /*! 189 * \brief Configurate the pin of a gpio device 190 * \param[in] gpio_device: gpio device id 191 * \param[in] pin: gpio pin number in this device 192 * \param[in] pin_config: pin configuration 193 * \return void 194 */ 195 void sedi_gpio_config_pin(IN sedi_gpio_t gpio_device, IN uint32_t pin, 196 IN sedi_gpio_pin_config_t pin_config); 197 198 /*! 199 * \brief Write pin state value 200 * \param[in] gpio_device: gpio device id 201 * \param[in] pin: gpio pin number in this device 202 * \param[in] pin_state: pin state value to write 203 * \return void 204 */ 205 void sedi_gpio_write_pin(IN sedi_gpio_t gpio_device, IN uint32_t pin, 206 IN sedi_gpio_pin_state_t pin_state); 207 208 /*! 209 * \brief Write 8 pins state value one time 210 * \param[in] gpio_device: gpio device id 211 * \param[in] group: gpio pin group, 8 pins in a group 212 * \param[in] pin_state: pin state value to write 213 * \return void 214 */ 215 void sedi_gpio_write_pin_8bits(IN sedi_gpio_t gpio_device, IN uint8_t group, 216 IN sedi_gpio_pin_state_t pin_state); 217 218 /*! 219 * \brief Write 16 pins state value one time 220 * \param[in] gpio_device: gpio device id 221 * \param[in] group: gpio pin group, 16 pins in a group 222 * \param[in] pin_state: pin state value to write 223 * \return void 224 */ 225 void sedi_gpio_write_pin_16bits(IN sedi_gpio_t gpio_device, IN uint8_t group, 226 IN sedi_gpio_pin_state_t pin_state); 227 228 /*! 229 * \brief Write 32 pins state value one time 230 * \param[in] gpio_device: gpio device id 231 * \param[in] group: gpio pin group, 32 pins in a group 232 * \param[in] pin_state: pin state value to write 233 * \return void 234 */ 235 void sedi_gpio_write_pin_32bits(IN sedi_gpio_t gpio_device, IN uint8_t group, 236 IN sedi_gpio_pin_state_t pin_state); 237 238 /*! 239 * \brief Read 8 pins state value one time 240 * \param[in] gpio_device: gpio device id 241 * \param[in] group: gpio pin group, 8 pins in a group 242 * \return 8-bit pin value 243 */ 244 uint8_t sedi_gpio_read_pin_8bits(IN sedi_gpio_t gpio_device, IN uint8_t group); 245 246 /*! 247 * \brief Read 16 pins state value one time 248 * \param[in] gpio_device: gpio device id 249 * \param[in] group: gpio pin group, 16 pins in a group 250 * \return 16-bit pin value 251 */ 252 uint16_t sedi_gpio_read_pin_16bits(IN sedi_gpio_t gpio_device, 253 IN uint8_t group); 254 255 /*! 256 * \brief Read 32 pins state value one time 257 * \param[in] gpio_device: gpio device id 258 * \param[in] group: gpio pin group, 32 pins in a group 259 * \return 32-bit pin value 260 */ 261 uint32_t sedi_gpio_read_pin_32bits(IN sedi_gpio_t gpio_device, 262 IN uint8_t group); 263 264 /*! 265 * \brief Read pin state value 266 * \param[in] gpio_device: gpio device id 267 * \param[in] pin: gpio pin number in this device 268 * \return the pin state value of this device 269 */ 270 sedi_gpio_pin_state_t sedi_gpio_read_pin(IN sedi_gpio_t gpio_device, 271 IN uint32_t pin); 272 273 /*! 274 * \brief Toggle the pin state 275 * \param[in] gpio_device: gpio device id 276 * \param[in] pin: gpio pin number in this device 277 * \return void 278 */ 279 void sedi_gpio_toggle_pin(IN sedi_gpio_t gpio_device, IN uint32_t pin); 280 281 /*! 282 * \brief Get device's interrupt status register value 283 * \param[in] gpio_device: gpio device id 284 * \param[in] port: Port id, one port represents 32 pins. 285 * \return current device's interrupt status register value 286 */ 287 uint32_t sedi_gpio_get_gisr(IN sedi_gpio_t gpio_device, 288 IN sedi_gpio_port_t port); 289 290 /*! 291 * \brief Get device's wake up status register value 292 * \param[in] gpio_device: gpio device id 293 * \param[in] port: Port id, one port represents 32 pins. 294 * \return current device's wake up status register value 295 */ 296 uint32_t sedi_gpio_get_gwsr(IN sedi_gpio_t gpio_device, 297 IN sedi_gpio_port_t port); 298 299 /*! 300 * \brief Clear the interrupt status manually 301 * \param[in] gpio_device: gpio device id 302 * \param[in] port: Port id, one port represents 32 pins. 303 * \param[in] val: Clear mask value, any bit equals to 1 means clear the 304 * relevant pin interrupt status. 305 */ 306 void sedi_gpio_clear_gisr(IN sedi_gpio_t gpio_device, IN sedi_gpio_port_t port, 307 IN uint32_t val); 308 309 /*! 310 * \brief Clear the wake up status manually. 311 * \param[in] gpio_device: gpio device id 312 * \param[in] port: Port id, one port represents 32 pins. 313 * \param[in] val: Clear mask value, any bit equals to 1 means clear the 314 * relevant pin wake up status. 315 */ 316 void sedi_gpio_clear_gwsr(IN sedi_gpio_t gpio_device, IN sedi_gpio_port_t port, 317 IN uint32_t val); 318 319 /*! 320 * \brief Enable/Disable GPIO pin interrupt 321 * \param[in] gpio_device: gpio device id 322 * \param[in] pin: gpio pin number in this device 323 * \param[in] enable: True means enable, false means disable 324 */ 325 void sedi_gpio_enable_interrupt(IN sedi_gpio_t gpio_device, IN uint32_t pin, 326 bool enable); 327 328 /*! 329 * \brief Enable/Disable GPIO pin wake up 330 * \param[in] gpio_device: gpio device id 331 * \param[in] pin: gpio pin number in this device 332 * \param[in] enable: True means enable, false means disable 333 */ 334 void sedi_gpio_enable_wakeup(IN sedi_gpio_t gpio_device, IN uint32_t pin, 335 bool enable); 336 337 /*! 338 * \} 339 */ 340 341 #ifdef __cplusplus 342 } 343 #endif 344 345 #endif /* _SEDI_DRIVER_GPIO_H_*/ 346