1 /* 2 * Copyright 2017 NXP 3 * All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 #ifndef _FSL_PF1550_CHARGER_H_ 9 #define _FSL_PF1550_CHARGER_H_ 10 11 /******************************************************************************* 12 * Includes 13 ******************************************************************************/ 14 #include <stdint.h> 15 #include <stdbool.h> 16 17 #include "fsl_pf1550.h" 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 23 /*! @brief PF1550 Charger Interrupt Source definition. */ 24 enum _pf1550_charger_interrupt_source 25 { 26 kPF1550_IntSrcChargerSupMod = 0x01U, /* Supplement mode interrupt source. */ 27 kPF1550_IntSrcChargerBatt2SysOc = 0x02U, /* VBATT to VSYS Overcurrent interrupt source. */ 28 kPF1550_IntSrcChargerBatt = 0x04U, /* Battery interrupt source. */ 29 kPF1550_IntSrcChargerChg = 0x08U, /* Charger interrupt source. */ 30 kPF1550_IntSrcChargerVbus = 0x20U, /* VBUS interrupt source. */ 31 kPF1550_IntSrcChargerVbusDpm = 0x40U, /* VBUS_DPM interrupt source. */ 32 kPF1550_IntSrcChargerThm = 0x80U, /* THM interrupt source. */ 33 }; 34 35 /*! @brief PF1550 Charger Working Mode definition. */ 36 enum _pf1550_charger_mode 37 { 38 kPF1550_ChargerModePreChg = 0x00000000U, /* Charger is in precharge mode. */ 39 kPF1550_ChargerModeFastChgCc = 0x00000100U, /* Charger is in fast-charge constant current mode. */ 40 kPF1550_ChargerModeFastChgCv = 0x00000200U, /* Charger is in fast-charge constant voltage mode. */ 41 kPF1550_ChargerModeEndOfChg = 0x00000300U, /* Charger is in end-of-charge mode. */ 42 kPF1550_ChargerModeDone = 0x00000400U, /* Charger is in done mode. */ 43 kPF1550_ChargerModeTimerFault = 0x00000600U, /* Charger is in timer fault mode. */ 44 kPF1550_ChargerModeThermSuspend = 0x00000700U, /* Charger is in thermistor suspend mode. */ 45 kPF1550_ChargerModeOff = 0x00000800U, /* Charger is off, input invalid and/or charger is disabled. */ 46 kPF1550_ChargerModeBatOv = 0x00000900U, /* Battery over-voltage condition. */ 47 kPF1550_ChargerModeOffOt = 0x00000A00U, /* Charger is off and the junction temperature is > TJSHDN. */ 48 kPF1550_ChargerModeOffLinearOn = 0x00000C00U, /* Charger block is in Linear only mode, not charging. */ 49 }; 50 51 /*! @brief PF1550 Battery Working Mode definition. */ 52 enum _pf1550_battery_mode 53 { 54 kPF1550_BattModeNoValidVbus = 0x00000000U, /* No valid VBUS input. */ 55 kPF1550_BattModeVbattLessThanVpre = 0x00010000U, /* VBATT < VPRECHG.LB. */ 56 kPF1550_BattModeTimerFault = 0x00020000U, /* Charger is in timer fault mode. */ 57 kPF1550_BattModeVbattGreaterThanVpre = 0x00040000U, /* VPRECHG.LB < VBATT. */ 58 kPF1550_BattModeOv = 59 0x00050000U, /* the battery voltage is greater than the battery overvoltage flag threshold (VBATOV). */ 60 kPF1550_BattModeNoBatt = 0x00060000U, /* Battery not detected with a valid input and after VSYS wake-up. */ 61 }; 62 63 /*! @brief PF1550 Charger Status definition. */ 64 enum _pf1550_charger_status 65 { 66 kPF1550_ChargerStatusVbusUvlo = 0x00000004U, /* VBUS_LIN < VBUS_LIN_UVLO or VBUS is detached. */ 67 kPF1550_ChargerStatusVbusIn2Sys = 0x00000008U, /* VBUS_LIN < VBATT + VIN2SYS. */ 68 kPF1550_ChargerStatusVbusOvlo = 0x00000010U, /* VBUS_LIN > VBUS_LIN_OVLO. */ 69 kPF1550_ChargerStatusVbusValid = 70 0x00000020U, /* VBUS_LIN > VBUS_LIN_UVLO, VBUS_LIN > VBAT + VIN2SYS and VBUS_LIN < VBUS_LIN_OVLO. */ 71 kPF1550_ChargerStatusVbusDpm = 0x00000080U, /* VBUS_LIN DPM threshold has been triggered. */ 72 kPF1550_ChargerStatusChargerMode = 0x00000F00U, /* Charger working mode mask. */ 73 kPF1550_ChargerStatusWdogTimeout = 0x00002000U, /* Watch dog timer is expired. */ 74 kPF1550_ChargerStatusThm = 0x00004000U, /* Thermistor temperature is < Cool, or > Warm threshold. */ 75 kPF1550_ChargerStatusTreg = 76 0x00008000U, /* The junction temperature is greater than the threshold set by REGTEMP. */ 77 kPF1550_ChargerStatusBattMode = 0x00070000U, /* Battery working mode mask. */ 78 kPF1550_ChargerStatusBattOc = 0x00200000U, /* VBATT to VSYS overcurrent fault. */ 79 }; 80 81 /*! @brief PF1550 Charger Operation definition. */ 82 typedef enum _pf1550_charger_operation 83 { 84 kPF1550_ChargerOperation_ChargerOffLinearOff = 0x0U, /* Charger = off, linear = off. The BATFET switch is on 85 to allow the battery to support the system. */ 86 kPF1550_ChargerOperation_ChargerOffLinearOn = 87 0x1U, /* Charger = off, linear = on, When there is a valid input, 88 the linear regulator regulates the system voltage to be VCHGCV. */ 89 kPF1550_ChargerOperation_ChargerOnLinearOn = 0x2U, /* Charger = on, linear = on. When there is a valid input, 90 the battery is charging. VSYS is the larger of VMINSYS 91 and ~ VBATT + IBAT * RBATFET. */ 92 } pf1550_charger_operation_t; 93 94 /*! @brief PF1550 Thermaistor Configuration definition. */ 95 typedef enum _pf1550_thermal_mode 96 { 97 kPF1550_ThermalMode_0 = 0x0U, /* Thermistor not in control of charger. */ 98 kPF1550_ThermalMode_1 = 0x1U, /* Thermistor control in charger. */ 99 kPF1550_ThermalMode_2 = 0x2U, /* JEITA 1 settings: Change both current and voltage. */ 100 kPF1550_ThermalMode_3 = 0x3U, /* JEITA 2 settings; Change current only. */ 101 } pf1550_thermal_mode_t; 102 103 /*! @brief PF1550 LED Indicator work mode definition. */ 104 typedef enum _pf1550_led_mode 105 { 106 kPF1550_LedMode_0 = 0x0U, /* LED on during charging; flashing during charger fault; off in DONE state. */ 107 kPF1550_LedMode_1 = 0x1U, /* LED flashing during charging; on during charger fault; off in DONE state. */ 108 } pf1550_led_mode_t; 109 110 /*! @brief PF1550 Charger Attribute definition. */ 111 typedef struct _pf1550_charger_attribute 112 { 113 uint32_t fastChargeCurrent_mA; /* Fast Charge Current in mA. */ 114 uint32_t fastChargeVoltage_uV; /* Set Fast Charge Voltage in uV. */ 115 uint32_t preChargeTime_min; /* Precharge Timer timeout value in minute. */ 116 uint32_t fastChargeTime_hr; /* Fast-charge Timer timeout value in hour. */ 117 uint32_t endOfChargeTime_min; /* End-of-charge timer timeout value in minute. */ 118 uint32_t endOfChargeCurrentThreshold_mA; /* End-of-charge current in mA. */ 119 uint32_t restartVoltageThreshold_uV; /* Charger restart threshold in uV. */ 120 uint32_t miniSystemVoltage_uV; /* Minimum system regulation voltage in uV. */ 121 } pf1550_charger_attribute_t; 122 123 /*! @brief PF1550 BATT to VSYS FET Attribute definition. */ 124 typedef struct _pf1550_batFET_attribute 125 { 126 uint32_t overcurrentThreshold_mA; /* VBATT to VSYS FET overcurrent Threshold in mA. */ 127 bool overcurrentProtectEnable; /* BATFET battery overcurrent limit protection. */ 128 bool overcurrentProtectEnableNoVbus; /* BATFET battery overcurrent protection when no VBUS is present. */ 129 bool overvoltageFaultProtectEnable; /* BATFET control during battery overvoltage. */ 130 bool watchDogFaultProtectEnable; /* BATFET control during watchdog fault. */ 131 bool thermalFaultProtectEnable; /* BATFET control during thermistor fault (< Cold or > Hot). */ 132 bool thermalShutdownProtectEnable; /* BATFET control during thermal shutdown. */ 133 bool timerFaultProtectEnable; /* BATFET control during charger timer fault. */ 134 } pf1550_batFET_attribute_t; 135 136 /*! @brief PF1550 Power Path Attribute definition. */ 137 typedef struct _pf1550_power_path_attribute 138 { 139 uint32_t vbusCurrentLimit_mA; /* Maximum Vbus input current limit in mA. */ 140 uint32_t vbusDpmVoltage_uV; /* VBUS regulation voltage (DPM mode) in uV. */ 141 uint32_t vbusDpmStopThreshold_uV; /* Dynamic input power management panic stop threshold in uV. */ 142 uint32_t vbusOvDebounce_us; /* VBUS overvoltage debounce delay in us. */ 143 uint32_t vbus2vsysDebounce_us; /* VBUS to VSYS comparator debounce time in us. */ 144 uint32_t vbus2vsysThreashold_uV; /* VBUS to VSYS comparator threshold setting in uV. */ 145 uint32_t usbPhyVoltage_uV; /* USBPHY voltage in uV. */ 146 uint32_t vsysWakeupDelay_ms; /* Vsys Wake-up delay in ms. */ 147 bool usbPhyDischargerEnbale; /* Active discharger for USBPHY. */ 148 bool usbPhyLdoEnable; /* USBPHY LDO enable. */ 149 } pf1550_power_path_attribute_t; 150 151 /*! @brief PF1550 Thermal Attribute definition. */ 152 typedef struct _pf1550_thermal_attribute 153 { 154 pf1550_thermal_mode_t mode; /* Thermistor Configuration. */ 155 int32_t junctionThermalSetPoint_C; /* Junction temperature thermal regulation loop set point in C. */ 156 int32_t thermalColdThreshold_C; /* Thermistor cold temperature selection in C. */ 157 int32_t thermalCoolThreshold_C; /* Thermistor cool threshold setting in C. */ 158 int32_t thermalWarmThreshold_C; /* Thermistor warm threshold setting in C. */ 159 int32_t thermalHotThreshold_C; /* Thermistor hot temperature selection in C. */ 160 uint32_t thermalVoltageAdjust_uV; /* JEITA Thermistor battery termination voltage subtraction in uV. */ 161 uint32_t thermalCurrentAdjust_pct; /* JEITA Thermistor battery charging current setting (percentage of I_FC). */ 162 bool thermalFoldbackEnable; /* Enable/disable thermal foldback current function. */ 163 } pf1550_thermal_attribute_t; 164 165 /*! @brief PF1550 Charger LED Indicator Attribute definition. */ 166 typedef struct _pf1550_led_attribute 167 { 168 pf1550_led_mode_t mode; /* Controls LED on/blinking mode. */ 169 uint32_t pwmDuty_pct; /* LED PWM duty cycle setting in percentage. */ 170 uint32_t pwmFrequency_mHz; /* LED driver PWM frequency setting in mHz. */ 171 bool rampEnable; /* Enable PWM ramp enable. */ 172 bool swCtrlEnable; /* Enable software control of LED. */ 173 } pf1550_led_attribute_t; 174 175 /******************************************************************************* 176 * API 177 ******************************************************************************/ 178 #if defined(__cplusplus) 179 extern "C" { 180 #endif 181 182 /*! 183 * @name Charger control functions 184 * @{ 185 */ 186 187 void PF1550_SetChargerOperation(pf1550_handle_t *handle, pf1550_charger_operation_t operation); 188 void PF1550_SetChargerAttibute(pf1550_handle_t *handle, const pf1550_charger_attribute_t *attribute); 189 uint32_t PF1550_GetChargerStatus(pf1550_handle_t *handle); 190 void PF1550_SetChargerWdog(pf1550_handle_t *handle, uint32_t timeout_sec, bool enable); 191 void PF1550_ServiceChargerWdog(pf1550_handle_t *handle); 192 void PF1550_EnableBatFET(pf1550_handle_t *handle, bool enable); 193 void PF1550_SetBatFETAttibute(pf1550_handle_t *handle, const pf1550_batFET_attribute_t *attribute); 194 void PF1550_SetPowerPathAttibute(pf1550_handle_t *handle, const pf1550_power_path_attribute_t *attribute); 195 void PF1550_SetThermalAttibute(pf1550_handle_t *handle, const pf1550_thermal_attribute_t *attribute); 196 void PF1550_SetledOutput(pf1550_handle_t *handle, bool value); 197 void PF1550_SetLedAttibute(pf1550_handle_t *handle, const pf1550_led_attribute_t *attribute); 198 199 /* @} */ 200 201 #if defined(__cplusplus) 202 } 203 #endif 204 205 #endif /* _FSL_PF1550_CHARGER_H_ */ 206 207 /******************************************************************************* 208 * EOF 209 ******************************************************************************/ 210