preload和LK电源管理分析
一.proload电源管理分析
pmic_init
//detect V battery Drop
pmic_DetectVbatDrop(); //检测是否是PMIC_VBAT_DROP
pmic_read_interface( MT6328_STRUP_CON9, (&just_rst), MT6328_PMIC_JUST_PWRKEY_RST_MASK, MT6328_PMIC_JUST_PWRKEY_RST_SHIFT );
pmic_config_interface(MT6328_STRUP_CON9, 1, MT6328_PMIC_CLR_JUST_RST_MASK, MT6328_PMIC_CLR_JUST_RST_SHIFT);
if(just_rst)
vbat_status = PMIC_VBAT_DROP;
else
vbat_status = PMIC_VBAT_NOT_DROP;
if(hw_check_battery()==1) //探测电池是否存在,如果存在
pmic_disable_usbdl_wo_battery(); //关闭usb下载模式
pmic_6328_efuse_management //pmic熔断保护机制,比电池过压保护等
upmu_set_rg_vio18_184(); //设置VIO18的校准电压
mt6311_driver_probe();
mt6311_hw_component_detect
update_mt6311_chip_id(); //获取id,看看pmic是否存在
if(g_mt6311_hw_exist==1)
mt6311_hw_init //硬件寄存器的一些初始化
g_mt6311_driver_ready=1;
pl_check_bat_protect_status //检测电池状态,//单独分析1
//单独分析1
pl_check_bat_protect_status //检测电池状态
bat_val = get_bat_sense_volt(5); //得到bat sense电压
chr_volt= get_charger_volt(1); //得到charger电压
#if defined(MTK_FAN5405_SUPPORT)
fan5405_hw_init(); //如果是fan5404需要初始化一下
#endif
while (bat_val < BATTERY_LOWVOL_THRESOLD) //mtk默认3.3v,宇龙1.5v
{ mtk_wdt_restart //重新开始看门狗计数
if(upmu_is_chr_det() == KAL_FALSE) //如果没有充电器
break
chr_volt= get_charger_volt(1); //charge电压大于6.5v
break;
pchr_turn_on_charging
pmic_config_interface(MT6328_PMIC_RG_CS_VTH_ADDR,0xc 。。) //450ma
#if defined(MTK_FAN5405_SUPPORT)
fan5405_turn_on_charging(); //如果电压fan5405启动充电
#endif
for(i=0;i<10;i++)
{ current=get_charging_current(1);
chr_volt=get_charger_volt(1);
if(current<100 && chr_volt<4400) //如果电流小于100 && 电压低于4400V
cnt++;
}
if(cnt>=8) //大于8就直接停止充电
pchr_turn_on_charging(KAL_FALSE);
bat_val = get_bat_sense_volt(5);
}
二.LK电源管理相关
Mt_battery.c (bootable\bootloader\lk\platform\mt6735)
#if defined(MTK_BQ24296_SUPPORT)
#define SWCHR_POWER_PATH //带路径管理的充电芯片
#endif
mt65xx_bat_init
#if defined(SWCHR_POWER_PATH)
bat_vol = get_i_sense_volt(1); //ADC_isense
#else
bat_vol = get_bat_sense_volt(1); //ADC_batsense
#endif
#if defined(MTK_FAN5405_SUPPORT) //resolve 5405 register lock
pchr_turn_on_charging(KAL_TRUE); //开始充电
#endif
if(g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT && (pmic_get_register_value(PMIC_PWRKEY_DEB)==0) ) //电源键没有按下
g_boot_reason_change = true; //充电启动模式
rtc_boot_check(false); //不是定时器启动
if (bat_vol < BATTERY_LOWVOL_THRESOLD) //MTK默认是3.45V,如果小于3.45在里面循环充电,大于就跳出开机,单独分析1
fgauge_initialization(NULL); //初始化 fgauge
pchr_turn_on_charging(KAL_FALSE); //关闭充电
get_dlpt_imix_r(); //得到电阻值
pchr_turn_on_charging(KAL_TRUE); //开始充电
check_bat_protect_status //看单独分析1里面的check_bat_protect_status
单独分析1
if (bat_vol < BATTERY_LOWVOL_THRESOLD) //MTK默认是3.45V,如果小于3.45在里面循环充电,大于就跳出开机
if(g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT && upmu_is_chr_det() == KAL_TRUE) //关机充电模式
check_bat_protect_status
#if defined(SWCHR_POWER_PATH)
bat_val = get_i_sense_volt(5);
#else
bat_val = get_bat_sense_volt(5);
#endif
while (bat_val < BATTERY_LOWVOL_PROTECT) //小于3.3V
mtk_wdt_restart(); //重启看门狗
pchr_turn_on_charging(KAL_TRUE); //开始充电
设置pmic充电电流等......
bq24296_hw_init(); //充电芯片初始化设置
bq24296_charging_enable(bEnable); //开始充电
bq24296_dump_register //打印充电芯片寄存器值
mdelay(5000); //5S
#if defined(SWCHR_POWER_PATH) //再次读取电池电压
bat_val = get_i_sense_volt(5);
#else
bat_val = get_bat_sense_volt(5);
#endif
else //正常开机
mt_disp_show_low_battery(); //显示低电图片
init_fb_screen();
fill_animation_logo(LOW_BATTERY_INDEX, mt_get_fb_addr(), mt_get_tempfb_addr(), logo_addr, phical_screen);
mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
mt65xx_leds_brightness_set(MT65XX_LED_TYPE_LCD, LOW_BAT_LEDS_BRIGHT); //设置背光亮度