soc_pm.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2018 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file reboot configuration macros for Actions SoC
  8. */
  9. #ifndef _ACTIONS_SOC_PM_H_
  10. #define _ACTIONS_SOC_PM_H_
  11. //reboot type, mask is 0xf00, low byte for details
  12. //reboot reason, mask is 0xff, low byte for details
  13. #define REBOOT_TYPE_NORMAL 0x000
  14. #define REBOOT_TYPE_GOTO_ADFU 0x100
  15. #define REBOOT_TYPE_GOTO_SYSTEM 0x200
  16. #define REBOOT_TYPE_GOTO_RECOVERY 0x300
  17. #define REBOOT_TYPE_GOTO_BTSYS 0x400
  18. #define REBOOT_TYPE_GOTO_WIFISYS 0x500
  19. #define REBOOT_TYPE_GOTO_SWJTAG 0x600
  20. #define REBOOT_TYPE_GOTO_OTA 0x700
  21. #define WAKE_CTL_BATLV_VOL_e 29
  22. #define WAKE_CTL_BATLV_VOL_SHIFT 27
  23. #define WAKE_CTL_BATLV_VOL_MASK (0x7<<27)
  24. #define WAKE_CTL_DC5VLV_VOL_e 26
  25. #define WAKE_CTL_DC5VLV_VOL_SHIFT 24
  26. #define WAKE_CTL_DC5VLV_VOL_MASK (0x7<<24)
  27. #define WAKE_CTL_WIO1LV_VOL_e 23
  28. #define WAKE_CTL_WIO1LV_VOL_SHIFT 22
  29. #define WAKE_CTL_WIO1LV_VOL_MASK (0x3<<22)
  30. #define WAKE_CTL_WIO0LV_VOL_e 21
  31. #define WAKE_CTL_WIO0LV_VOL_SHIFT 20
  32. #define WAKE_CTL_WIO0LV_VOL_MASK (0x3<<20)
  33. #define WAKE_CTL_REMOTE_WKEN (1<<12)
  34. #define WAKE_CTL_BATLV_WKEN (1<<11)
  35. #define WAKE_CTL_DC5VLV_WKEN (1<<10)
  36. //#define WAKE_CTL_WIO1LV_DETEN (1<<9)
  37. #define WAKE_CTL_WIO0LV_DETEN (1<<8)
  38. //#define WAKE_CTL_WIO1LV_WKEN (1<<7)
  39. #define WAKE_CTL_WIO0LV_WKEN (1<<6)
  40. #define WAKE_CTL_WIO_WKEN (1<<5)
  41. #define WAKE_CTL_ALARM8HZ_WKEN (1<<4)
  42. #define WAKE_CTL_DC5VOUT_WKEN (1<<3)
  43. #define WAKE_CTL_DC5VIN_WKEN (1<<2)
  44. #define WAKE_CTL_SHORT_WKEN (1<<1)
  45. #define WAKE_CTL_LONG_WKEN (1<<0)
  46. union sys_pm_wakeup_src {
  47. uint32_t data;
  48. struct {
  49. uint32_t long_onoff : 1; /* ONOFF key long pressed wakeup */
  50. uint32_t short_onoff : 1; /* ONOFF key short pressed wakeup */
  51. uint32_t bat : 1; /* battery plug in wakeup */
  52. uint32_t alarm : 1; /* RTC alarm wakeup */
  53. uint32_t wio : 1; /* WIO wakeup */
  54. uint32_t remote : 1; /* remote wakeup */
  55. uint32_t batlv : 1; /*battery low power*/
  56. uint32_t dc5vlv : 1; /*dc5v low voltage*/
  57. uint32_t dc5vin : 1; /*dc5v in wakeup*/
  58. uint32_t watchdog : 1; /* watchdog reboot */
  59. uint32_t onoff_reset : 1; /* long onff reset */
  60. } t;
  61. };
  62. struct sys_pm_backup_time {
  63. uint32_t rtc_time_sec;
  64. uint32_t rtc_time_msec;
  65. uint32_t counter8hz_cycles;
  66. uint32_t user_alarm_cycles;
  67. uint32_t rc32k_freq;
  68. uint8_t is_backup_time_valid;
  69. uint8_t is_user_alarm_on;
  70. uint8_t is_user_cur_use;
  71. uint8_t is_use_alarm_cal;
  72. };
  73. typedef void (*shipmode_callback_t)(void *arg);
  74. void sys_pm_reboot(int type);
  75. int sys_pm_get_reboot_reason(u16_t *reboot_type, u8_t *reason);
  76. int sys_pm_get_wakeup_source(union sys_pm_wakeup_src *src);
  77. void sys_pm_set_dc5v_low_wakeup(int enable, int threshold);
  78. int sys_pm_get_dc5v_low_threshold(uint8_t *volt);
  79. void sys_pm_set_bat_low_wakeup(int enable, int threshold);
  80. int sys_pm_get_bat_low_threshold(uint8_t *volt);
  81. void sys_pm_set_onoff_wakeup(int enable);
  82. void sys_pm_poweroff(void);
  83. void sys_pm_factory_poweroff(void);
  84. void sys_pm_shimode_register_callback(shipmode_callback_t func, void *arg);
  85. void sys_pm_shipmode(void);
  86. /*soc_sleep.c*/
  87. void soc_enter_deep_sleep(void);
  88. void soc_enter_light_sleep(void);
  89. void soc_udelay(uint32_t us);
  90. /*soc_pm.c*/
  91. void sys_pm_enter_deep_sleep(void);
  92. void sys_pm_enter_light_sleep(void);
  93. #endif /* _ACTIONS_SOC_PM_H_ */