#include "sgm41562.h"
#include "custom_utils.h"
+#include "tcxo.h"
#undef pr_debug
#define pr_debug printf
printf("[%s] shutdown lpm done\n", __func__);
}
-/** @brief 船运模式或关机低功耗(见 SGM41562_USE_FET_DIS_SHIP) */
+#define SGM41562_SHIP_ENTRY_DELAY_MS 1100
+
+/** @brief 进入船运:关 WDT/监测,REG00 允许 VIN 退出,REG06 FET_DIS 断 BAT→SYS */
void sgm41562_entry_shipmode(void)
{
-#ifdef SGM41562_USE_FET_DIS_SHIP
- (void)sgm41562_ctrl_setting(REG_BIT_EN_CEB, true);
- (void)sgm41562_ctrl_setting(REG_BIT_EN_HIZ, true);
- (void)sgm41562_set_batfet_dis(true);
-#else
- sgm41562_entry_shutdown_lpm();
-#endif
+ int ret;
+ uint8_t reg_val = 0;
+
+ ret = sgm41562_set_watchdog_timer(SGM41562_WDT_TIMER_DISABLE);
+ if (ret)
+ printf("[%s] disable watchdog fail %d\n", __func__, ret);
+
+ ret = sgm41562_ctrl_setting(REG_BIT_EN_TIMER, false);
+ if (ret)
+ printf("[%s] disable safety timer fail %d\n", __func__, ret);
+
+ ret = sgm41562_ctrl_setting(REG_BIT_EN_TERM, false);
+ if (ret)
+ printf("[%s] disable term fail %d\n", __func__, ret);
+
+ ret = sgm41562_ctrl_setting(REG_BIT_EN_NTC, false);
+ if (ret)
+ printf("[%s] disable NTC fail %d\n", __func__, ret);
+
+ ret = sgm41562_ctrl_setting(REG_BIT_EN_PCB_OTP, true);
+ if (ret)
+ printf("[%s] disable PCB OTP fail %d\n", __func__, ret);
+
+ ret = sgm41562_ctrl_setting(REG_BIT_EN_CEB, true);
+ if (ret)
+ printf("[%s] disable charge fail %d\n", __func__, ret);
+
+ ret = sgm41562_ctrl_setting(REG_BIT_EN_HIZ, true);
+ if (ret)
+ printf("[%s] enable HIZ fail %d\n", __func__, ret);
+
+ /* REG00:插 VBUS / nINT 可退出船运(规格书 Table 3) */
+ ret = sgm41562_update_bits(SGM41562_CHRG_REG_0,
+ SGM41562_VIN_EXIT_SHIP | SGM41562_INT_EXIT_SHIP,
+ SGM41562_VIN_EXIT_SHIP | SGM41562_INT_EXIT_SHIP);
+ if (ret)
+ printf("[%s] set ship exit bits fail %d\n", __func__, ret);
+
+ ret = sgm41562_ctrl_setting(REG_BIT_FET_DIS, true);
+ if (ret)
+ printf("[%s] FET_DIS fail %d\n", __func__, ret);
+
+ uapi_tcxo_delay_ms(SGM41562_SHIP_ENTRY_DELAY_MS);
+
+ if (sgm41562_read_reg(SGM41562_CHRG_REG_8, ®_val) == 0) {
+ printf("[%s] REG08 PG_STAT=%u after ship entry\n", __func__,
+ (unsigned int)((reg_val & SGM41562_PG_STAT) ? 1U : 0U));
+ }
+
+ printf("[%s] ship mode entry done\n", __func__);
}
bool sgm41562_set_chrg_ichg_mA(uint16_t current_mA)
#if defined(ENABLE_SGM41562)
if (sgm41562_probe()) {
+ printf("[charge_ic] SGM41562 detected\n");
return CHARGE_IC_TYPE_SGM41562;
}
#endif
#if defined(ENABLE_HP4570)
if (hp4570n_identify(HP4570N) == 0) {
+ printf("[charge_ic] HP4570 detected\n");
return CHARGE_IC_TYPE_HP4570;
}
#endif
g_charge_ic_type = charge_ic_detect();
if (g_charge_ic_type == CHARGE_IC_TYPE_NONE) {
+ printf("[charge_ic] no charge IC detected\n");
return ERRCODE_FAIL;
}
}
#if defined(ENABLE_SGM41562)
- sgm41562_entry_shutdown_lpm();
+ sgm41562_entry_shipmode();
#endif
}
PRINT("[PWR_FLOW] uapi_poweroff_device: poweroff_bt_dsp_display\r\n");
poweroff_bt_dsp_display();
#ifdef SUPPORT_BATTERY_SERVICE
- {
- char charge_ic_dump[512];
- (void)charge_ic_dump_debug_registers(charge_ic_dump, sizeof(charge_ic_dump));
- PRINT("[PWR_FLOW] charge_ic before shutdown lpm:\r\n%s\r\n", charge_ic_dump);
- charge_ic_shutdown_lpm();
- (void)charge_ic_dump_debug_registers(charge_ic_dump, sizeof(charge_ic_dump));
- PRINT("[PWR_FLOW] charge_ic after shutdown lpm:\r\n%s\r\n", charge_ic_dump);
- }
+ PRINT("[PWR_FLOW] uapi_poweroff_device: charge_ic shipmode\r\n");
+ charge_ic_shutdown_lpm();
#endif
PRINT("[PWR_FLOW] uapi_poweroff_device: mcu_poweroff\r\n");
mcu_poweroff();