drv_pmic_intr.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _DRV_PMIC_INTR_H_
  13. #define _DRV_PMIC_INTR_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * PMIC bypass wakeup mask
  22. */
  23. typedef enum
  24. {
  25. DRV_PMIC_BYPASS_WDT_WAKEUP = 0,
  26. DRV_PMIC_BYPASS_TIMER_WAKEUP,
  27. DRV_PMIC_BYPASS_GPT_WAKEUP,
  28. DRV_PMIC_BYPASS_GPIO_WAKEUP,
  29. DRV_PMIC_BYPASS_CHG_ON_WAKEUP,
  30. DRV_PMIC_BYPASS_PWRKEY_WAKEUP,
  31. DRV_PMIC_BYPASS_WDT_RESET,
  32. DRV_PMIC_BYPASS_OPT_RESET,
  33. DRV_PMIC_BYPASS_OVLO_RESET,
  34. DRV_PMIC_BYPASS_UVLO_RESET,
  35. DRV_PMIC_BYPASS_VBATLOW_RESET,
  36. DRV_PMIC_BYPASS_PIN_RESET,
  37. DRV_PMIC_BYPASS_WAKEUP_COUNT
  38. } drvWakeupMaskType_t;
  39. /**
  40. * PMIC interrupt types
  41. */
  42. #ifdef CONFIG_SOC_8811
  43. enum drvPmicIntrType_t
  44. {
  45. DRV_PMIC_INTR_GPIO, ///< PMIC GPIO interrupt
  46. DRV_PMIC_INTR_GPT16, ///< PMIC RTC interrupt
  47. DRV_PMIC_INTR_TMR, ///< PMIC timer interrupt
  48. DRV_PMIC_INTR_WDG, ///< PMIC watchdog interrupt
  49. DRV_PMIC_INTR_POWER_KEY, ///< PMIC powerkey interrupt
  50. DRV_PMIC_INTR_CHG_ON, ///< PMIC charge on interrupt
  51. DRV_PMIC_INTR_CHG_OFF, ///< PMIC charge off interrupt
  52. DRV_PMIC_INTR_ADC, ///< PMIC adc interrupt
  53. DRV_PMIC_INTR_COUNT
  54. };
  55. #else
  56. #ifdef CONFIG_SOC_8850
  57. enum drvPmicIntrType_t
  58. {
  59. DRV_PMIC_INTR_ADC, ///< PMIC ADC interrupt
  60. DRV_PMIC_INTR_RTC, ///< PMIC RTC interrupt
  61. DRV_PMIC_INTR_WDG, ///< PMIC watchdog interrupt
  62. DRV_PMIC_INTR_FGU, ///< PMIC fuel gauge unit interrupt
  63. DRV_PMIC_INTR_EIC, ///< PMIC EIC interrupt
  64. DRV_PMIC_INTR_AUD, ///< PMIC audio interrupt
  65. DRV_PMIC_INTR_TMR, ///< PMIC timer interrupt
  66. DRV_PMIC_INTR_CAL, ///< PMIC oscillator calibration interrupt
  67. DRV_PMIC_INTR_TYPEC,
  68. DRV_PMIC_INTR_COUNT
  69. };
  70. #else
  71. enum drvPmicIntrType_t
  72. {
  73. DRV_PMIC_INTR_ADC, ///< PMIC ADC interrupt
  74. DRV_PMIC_INTR_RTC, ///< PMIC RTC interrupt
  75. DRV_PMIC_INTR_WDG, ///< PMIC watchdog interrupt
  76. DRV_PMIC_INTR_FGU, ///< PMIC fuel gauge unit interrupt
  77. DRV_PMIC_INTR_EIC, ///< PMIC EIC interrupt
  78. DRV_PMIC_INTR_AUD, ///< PMIC audio interrupt
  79. DRV_PMIC_INTR_TMR, ///< PMIC timer interrupt
  80. DRV_PMIC_INTR_CAL, ///< PMIC oscillator calibration interrupt
  81. DRV_PMIC_INTR_COUNT
  82. };
  83. #endif
  84. #endif
  85. /**
  86. * PMIC EIC interrupt types
  87. */
  88. enum drvPmicEicType_t
  89. {
  90. DRV_PMIC_EIC_CHGR_INT, ///< charge indicator
  91. DRV_PMIC_EIC_PBINT, ///< power on 1
  92. DRV_PMIC_EIC_PBINT2, ///< power on 2
  93. DRV_PMIC_EIC_AUDIO_HEAD_BUTTON, ///< ??
  94. DRV_PMIC_EIC_CHGR_CV, ///< ??
  95. DRV_PMIC_EIC_AUDIO_HEAD_INSERT, ///< ??
  96. DRV_PMIC_EIC_VCHG_OVI, ///< ??
  97. DRV_PMIC_EIC_AUDIO_HEAD_INSERT2, ///< ??
  98. DRV_PMIC_EIC_BATDET_OK, ///< ??
  99. DRV_PMIC_EIC_EXT_RSTN, ///< ??
  100. DRV_PMIC_EIC_EXT_XTL_EN0, ///< ??
  101. DRV_PMIC_EIC_AUDIO_HEAD_INSERT3, ///< ??
  102. DRV_PMIC_EIC_AUDIO_HEAD_INSERT_ALL, ///< ??
  103. DRV_PMIC_EIC_EXT_XTL_EN1, ///< ??
  104. DRV_PMIC_EIC_EXT_XTL_EN2, ///< ??
  105. DRV_PMIC_EIC_EXT_XTL_EN3, ///< ??
  106. DRV_PMIC_EIC_COUNT
  107. };
  108. /**
  109. * callback function for PMIC interrupt
  110. *
  111. * It is called in ISR, and it is needed to follow ISR programming guide.
  112. */
  113. typedef void (*drvPmicIntrCB_t)(void *ctx);
  114. /**
  115. * @brief PMIC interrupt module initialization
  116. *
  117. * It should be called after ADI bus is initialized, and before
  118. * any other modules which will use PMIC interrupt and PMIC EIC
  119. * interrupts.
  120. */
  121. void drvPmicIntrInit(void);
  122. /**
  123. * @brief enable PMIC interrupt and set callback
  124. *
  125. * When there already exist callback for the specified PMIC interrupt,
  126. * the previous one will be replaced.
  127. *
  128. * @param intr PMIC interrupt type (\a drvPmicType_t)
  129. * @param cb PMIC interrupt callback
  130. * @param ctx PMIC interrupt cabback context
  131. */
  132. void drvPmicIntrEnable(unsigned intr, drvPmicIntrCB_t cb, void *ctx);
  133. /**
  134. * @brief disable PMIC interrupt
  135. *
  136. * @param intr PMIC interrupt type (\a drvPmicType_t)
  137. */
  138. void drvPmicIntrDisable(unsigned intr);
  139. /**
  140. * @brief set PMIC EIC interrupt callback
  141. *
  142. * Set the callback of PMIC EIC intterupt. The EIC interrupt won't
  143. * be started automatically.
  144. *
  145. * In callback, it is permitted to call EIC APIs, such as re-trigger
  146. * it in opposite polarity.
  147. *
  148. * @param eic PMIC EIC interrupt type (\a drvPmicEicType_t)
  149. * @param cb PMIC EIC interrupt callback
  150. * @param ctx PMIC EIC interrupt callback context
  151. */
  152. void drvPmicEicSetCB(unsigned eic, drvPmicIntrCB_t cb, void *ctx);
  153. /**
  154. * @brief enable PMIC EIC interrupt
  155. *
  156. * After EIC interrupt arrived, the interrupt will be disabled
  157. * automatically. When the interrupt is needed, \a drvPmicEicTrigger
  158. * (with the same or opposite polarity).
  159. *
  160. * When \a debounce is too small, it will be set to the minimum
  161. * value suitable for underlay hardware. Typically, it will be
  162. * several milliseconds.
  163. *
  164. * @param eic PMIC EIC interrupt type (\a drvPmicEicType_t)
  165. * @param debounce debounce time in milliseconds
  166. * @param level trigger level, true for high
  167. */
  168. void drvPmicEicTrigger(unsigned eic, unsigned debounce, bool level);
  169. /**
  170. * @brief PMIC EIC source current level
  171. *
  172. * @param eic PMIC EIC interrupt type (\a drvPmicEicType_t)
  173. * @return
  174. * - true for high level
  175. * - false for low level, or invalid type
  176. */
  177. bool drvPmicEicGetLevel(unsigned eic);
  178. /**
  179. * @brief disable PMIC EIC interrupt
  180. *
  181. * @param eic PMIC EIC interrupt type (\a drvPmicEicType_t)
  182. */
  183. void drvPmicEicDisable(unsigned eic);
  184. /**
  185. * @brief PMIC bypass wakeup
  186. *
  187. * @param type PMIC bypass wakeup type (drvWakeupMaskType_t)
  188. * @param bypass true for bypass wakeup
  189. */
  190. bool drvPmicBypassMask(drvWakeupMaskType_t type, bool bypass);
  191. #ifdef __cplusplus
  192. }
  193. #endif
  194. #endif