soc_pmu.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright (c) 2021 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief Actions LEOPARD family PMU public APIs
  9. */
  10. #ifndef _SOC_PMU_H_
  11. #define _SOC_PMU_H_
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /* Macro of peripheral devices that PMU supervise the devices voltage level change.*/
  16. #define PMU_DETECT_DEV_DC5V (1)
  17. #define PMU_DETECT_DEV_REMOTE (2)
  18. #define PMU_DETECT_DEV_ONOFF (3)
  19. #define PMU_DETECT_DEV_COUNTER8HZ (4)
  20. #define PMU_DETECT_DEV_ALARM8HZ (5)
  21. #define PMU_DETECT_DEV_BAT (6)
  22. #define PMU_DETECT_MAX_DEV (6)
  23. /* Max cycles of counter8hz */
  24. #define PMU_COUTNER8HZ_MAX (0x3FFFFFF)
  25. /**
  26. * enum pmu_hotplug_state
  27. * @brief Hotplug devices (e.g. DV5V) state change which detected by PMU.
  28. */
  29. enum pmu_notify_state {
  30. PMU_NOTIFY_STATE_OUT = 0,
  31. PMU_NOTIFY_STATE_IN,
  32. PMU_NOTIFY_STATE_PRESSED,
  33. PMU_NOTIFY_STATE_LONG_PRESSED,
  34. PMU_NOTIFY_STATE_TIME_ON,
  35. PMU_NOTIFY_STATE_BAT_PROTECT
  36. };
  37. typedef void (*pmu_notify_t)(void *cb_data, int state);
  38. /**
  39. * struct notify_param_t
  40. * @brief Parameters for PMU notify register.
  41. */
  42. struct detect_param_t {
  43. uint8_t detect_dev;
  44. pmu_notify_t notify;
  45. void *cb_data;
  46. };
  47. /* @brief Register the device that PMU start to monitor */
  48. int soc_pmu_register_notify(struct detect_param_t *param);
  49. /* @brief Unregister the device that PMU stop to monitor */
  50. void soc_pmu_unregister_notify(uint8_t detect_dev);
  51. /* @brief Get the wakeup source caused by system power up */
  52. uint32_t soc_pmu_get_wakeup_source(void);
  53. /* @brief return the wakeup setting by system startup */
  54. uint32_t soc_pmu_get_wakeup_setting(void);
  55. /* @brief check if system wakeup by RTC alarm */
  56. bool soc_pmu_is_alarm_wakeup(void);
  57. /* @brief get the current DC5V status of plug in or out and if retval of status is 1 indicates that plug-in*/
  58. bool soc_pmu_get_dc5v_status(void);
  59. /* @brief lock DC5V charging for reading battery voltage */
  60. void soc_pmu_read_bat_lock(void);
  61. /* @brief unlock and restart DC5V charging */
  62. void soc_pmu_read_bat_unlock(void);
  63. /* @brief configure the long press on-off key time */
  64. void soc_pmu_config_onoffkey_function(uint8_t val);
  65. /* @brief check long onoff reset func, if clear, set */
  66. void soc_pmu_check_onoff_reset_func(void);
  67. /* @brief configure the long press on-off key time */
  68. void soc_pmu_config_onoffkey_time(uint8_t val);
  69. /* @brief check if the onoff key has been pressed or not */
  70. bool soc_pmu_is_onoff_key_pressed(void);
  71. /* @brief set const voltage value */
  72. void soc_pmu_set_const_voltage(uint8_t cv);
  73. /* @brief set the max constant current */
  74. void soc_pmu_set_max_current(uint16_t cur_ma);
  75. /* @brief get the max constant current */
  76. uint16_t soc_pmu_get_max_current(void);
  77. /* @brief configure the long press on-off key reset/restart time */
  78. void soc_pmu_config_onoffkey_reset_time(uint8_t val);
  79. /* @brief counter 8hz clock enable */
  80. void soc_pmu_counter8hz_enable(void);
  81. /* @brief get counter8hz and the retval is by cycles */
  82. int soc_pmu_get_counter8hz_cycles(bool is_sync);
  83. /*@brief 8hzchcle cal to ms by rc32k
  84. rc32k_sum = rc32k_old + rc32k_new
  85. */
  86. uint32_t sys_pmu_8hzcycle_to_ms(uint32_t cycle, uint32_t rc32k_sum);
  87. /* @brief enable PMU alarm 8hz */
  88. int soc_pmu_alarm8hz_enable(uint32_t alarm_msec);
  89. /* @brief disable PMU alarm8hz */
  90. void soc_pmu_alarm8hz_disable(void);
  91. /* @brief get alarm8hz cycles */
  92. int soc_pmu_get_alarm8hz(void);
  93. /* @brief get current rc32k freq by hosc count, cal_cyc is rc32k cycle */
  94. uint32_t acts_clock_rc32k_set_cal_cyc(uint32_t cal_cyc);
  95. /* @brief get calibrate mul rc32k by hosc return hosc/rc32k */
  96. uint32_t soc_rc32K_mutiple_hosc(void);
  97. /* @brief get rc32k freq */
  98. uint32_t soc_rc32K_freq(void);
  99. /* @brief get S1 VDD voltage */
  100. uint32_t soc_pmu_get_vdd_voltage(void);
  101. /* @brief set S1 VDD voltage */
  102. void soc_pmu_set_vdd_voltage(uint32_t volt_mv);
  103. /* @brief set S1 VD12 voltage */
  104. void soc_pmu_set_vd12_voltage(uint32_t volt_mv);
  105. /* @brief get temperature degrees (multiply 10) in centigrade and if retval is negative will get error */
  106. int soc_pmu_get_temperature(void);
  107. /* @brief set pmu reg CHG_CTL_SVCC */
  108. void soc_pmu_set_chg_ctl_svcc(uint32_t mask, uint32_t value);
  109. /* @brief get pmu reg CHG_CTL_SVCC */
  110. uint32_t soc_pmu_get_chg_ctl_svcc(void);
  111. /* @brief set pmu reg POWER_CTL_SVCC */
  112. void soc_pmu_sys_poweroff(void);
  113. /* @brief set pmu reg BDG_CTL_SVCC */
  114. void soc_pmu_set_bdg_ctl_svcc(uint32_t mask, uint32_t value);
  115. /* @brief get pmu reg BDG_CTL_SVCC */
  116. uint32_t soc_pmu_get_bdg_ctl_svcc(void);
  117. /* @brief set pmu reg PMUADC_CTL */
  118. void soc_pmu_set_pmuadc_ctl(uint32_t mask, uint32_t value);
  119. /* @brief get pmu reg PMUADC_CTL */
  120. uint32_t soc_pmu_get_pmuadc_ctl(void);
  121. /* @brief set pmu reg PMUADCDIG_CTL */
  122. void soc_pmu_set_pmuadcdig_ctl(uint32_t mask, uint32_t value);
  123. /* @brief get pmu reg PMUADCDIG_CTL */
  124. uint32_t soc_pmu_get_pmuadcdig_ctl(void);
  125. /* @brief set pmu reg VOUT_CTL0 */
  126. void soc_pmu_set_vout_ctl0(uint32_t mask, uint32_t value);
  127. /* @brief get pmu reg VOUT_CTL0 */
  128. uint32_t soc_pmu_get_vout_ctl0(void);
  129. /* @brief clear PMUADC_PD */
  130. void soc_pmu_clear_pmuadc_pd(void);
  131. /* @brief clear PMUADC_INTMASK */
  132. void soc_pmu_clear_pmuadc_intmask(void);
  133. /* @brief get PMUADC_PD */
  134. uint32_t soc_pmu_get_pmuadc_pd(void);
  135. /* @brief get CHARGI_DATA */
  136. uint32_t soc_pmu_get_chargi_data(void);
  137. /* @brief get BATADC_DATA */
  138. uint32_t soc_pmu_get_batadc_data(void);
  139. /* @brief get DC5VADC_DATA */
  140. uint32_t soc_pmu_get_dc5vadc_data(void);
  141. /* @brief get LRADCx_DATA */
  142. uint32_t soc_pmu_get_lradcxadc_data(uint8_t chn);
  143. /* @brief get bat volt */
  144. bool soc_pmu_lowpower_check(void);
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. #endif /* _SOC_PMU_H_ */