1 /* 2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved. 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 */ 15 #ifndef _PMIC_API_H_ 16 #define _PMIC_API_H_ 17 18 #include "chip.h" 19 #include "plf.h" 20 21 #if PLF_PMIC 22 #if PLF_PMIC_VER_LITE 23 #include "cs1000Lite_analog_reg.h" 24 #include "cs1000Lite_gpio.h" 25 //#include "cs1000Lite_intc.h" 26 #include "cs1000Lite_iomux.h" 27 #include "cs1000Lite_led_pwm.h" 28 #include "cs1000Lite_msadc.h" 29 //#include "cs1000Lite_psm.h" 30 #include "cs1000Lite_rtc_core.h" 31 #include "cs1000Lite_sys_ctrl.h" 32 //#include "cs1000Lite_wdg.h" 33 #elif PLF_PMIC_VER_AUD 34 #include "cs1000Aud_analog_reg.h" 35 //#include "cs1000Aud_aud_anc.h" 36 //#include "cs1000Aud_aud_codec.h" 37 //#include "cs1000Aud_aud_ctrl_reg.h" 38 //#include "cs1000Aud_aud_vad.h" 39 #include "cs1000Aud_gpio.h" 40 //#include "cs1000Aud_intc.h" 41 #include "cs1000Aud_iomux.h" 42 #include "cs1000Aud_led_pwm.h" 43 #include "cs1000Aud_msadc.h" 44 //#include "cs1000Aud_psm.h" 45 //#include "cs1000Aud_rtc_cnt.h" 46 #include "cs1000Aud_rtc_core.h" 47 #include "cs1000Aud_sys_ctrl.h" 48 //#include "cs1000Aud_wdg.h" 49 #endif 50 #if PLF_PMIC_ITF_ASDMA 51 #include "asdma_mst_api.h" 52 #else 53 #include "psim_api.h" 54 #endif 55 56 typedef enum { 57 #if PLF_PMIC_VER_LITE 58 PMIC_ASDMA_IRQn = 0, 59 PMIC_GPIO_IRQn = 1, 60 PMIC_I2CM_IRQn = 2, 61 PMIC_PWM0_IRQn = 3, 62 PMIC_PWM1_IRQn = 4, 63 PMIC_PWM2_IRQn = 5, 64 PMIC_PWM3_IRQn = 6, 65 PMIC_PWM4_IRQn = 7, 66 PMIC_PWM5_IRQn = 8, 67 PMIC_KEYPAD_IRQn = 9, 68 PMIC_WDG_IRQn = 10, 69 PMIC_DET_SDIO_IRQn = 11, 70 PMIC_TOUCH_IRQn = 12, 71 PMIC_PSM_IRQn = 13, 72 PMIC_CALENDAR_IRQn = 14, 73 PMIC_SPI_IRQn = 15, 74 PMIC_UART_DET_IRQn = 16, 75 PMIC_CAL_IRQn = 17, 76 PMIC_RTC_CORE_IRQn = 18, 77 PMIC_PWM_TMR_IRQn = 19, 78 #endif /* PLF_PMIC_VER_LITE */ 79 #if PLF_PMIC_VER_AUD 80 PMIC_GPIO_IRQn = 0, 81 PMIC_PWM0_IRQn = 1, 82 PMIC_PWM1_IRQn = 2, 83 PMIC_AUD_VAD_IRQn = 3, 84 PMIC_AUD_CODEC_IRQn = 4, 85 PMIC_AUD_ANC_IRQn = 5, 86 PMIC_WDG_IRQn = 6, 87 PMIC_TOUCH_IRQn = 7, 88 PMIC_PSM_IRQn = 8, 89 PMIC_RTC_CNT_IRQn = 9, 90 PMIC_RTC_CORE_IRQn = 10, 91 PMIC_PWM_TMR0_IRQn = 11, 92 PMIC_PWM_TMR1_IRQn = 12, 93 PMIC_TWS_UART_IRQn = 13, 94 #endif /* PLF_PMIC_VER_AUD */ 95 PMIC_IRQ_NUMBER 96 } PMIC_IRQ_T; 97 98 typedef void (*pmic_irq_callback_t)(void); 99 100 #if PLF_PMIC_ITF_ASDMA 101 #define PMIC_ITF_INIT(...) asdma_mst_init(__VA_ARGS__) 102 #define PMIC_MEM_READ(...) asdma_reg_rd(__VA_ARGS__) 103 #define PMIC_MEM_WRITE(...) asdma_reg_wr(__VA_ARGS__) 104 #define PMIC_MEM_MASK_WRITE(...) asdma_reg_mask_wr(__VA_ARGS__) 105 #else 106 #define PMIC_ITF_INIT(...) psim_init(__VA_ARGS__) 107 #define PMIC_MEM_READ(...) psim_read(__VA_ARGS__) 108 #define PMIC_MEM_WRITE(...) psim_write(__VA_ARGS__) 109 #define PMIC_MEM_MASK_WRITE(...) psim_mask_write(__VA_ARGS__) 110 #endif 111 112 void pmic_irq_enable_local(void); 113 void pmic_irq_callback_register(PMIC_IRQ_T irq_idx, pmic_irq_callback_t callback); 114 void pmic_irq_enable(uint32_t int_en); 115 void pmic_irq_process(void); 116 void pmic_pwm_timer_start(uint32_t ticks_32k); 117 #if PLF_PMIC_VER_LITE 118 void pmic_psm_timer_start(uint32_t ticks_32k_hi, uint16_t ticks_32k_lo); 119 #endif /* PLF_PMIC_VER_LITE */ 120 #if PLF_PMIC_VER_AUD 121 void pmic_rtccnt_timer_start(uint32_t ticks_32k_hi, uint32_t ticks_32k_lo); 122 #endif /* PLF_PMIC_VER_AUD */ 123 124 /** 125 * @brief: Enable pwrkey 126 * @return: current holding state 127 */ 128 int pmic_powerkey_enable(void); 129 130 /** 131 * @brief: Sw shutdown 132 */ 133 void pmic_chip_shutdown(void); 134 135 /** 136 * @brief: Sw reboot 137 */ 138 void pmic_chip_reboot(void); 139 140 /** 141 * @brief: Config BOR, low VBAT trigger power off 142 * @param[in] bor_vbit: vbit-voltage table 143 * +------+------+------+------+------+------+------+------+------+------+------+------+------+ 144 * | vbit | 0x4 | 0x5 | 0x6 | 0x7 | 0x8 | 0x9 | 0xA | 0xB | 0xC | 0xD | 0xE | 0xF | 145 * +------+------+------+------+------+------+------+------+------+------+------+------+------+ 146 * | Volt | 2.15 | 2.27 | 2.38 | 2.49 | 2.60 | 2.71 | 2.83 | 2.94 | 3.06 | 3.17 | 3.28 | 3.40 | 147 * +------+------+------+------+------+------+------+------+------+------+------+------+------+ 148 * @param[in] bor_repower: if auto re-power after charging 149 */ 150 void pmic_bor_config(uint32_t bor_vbit, int bor_repower); 151 #endif 152 153 #endif /* _PMIC_API_H_ */ 154