mtk charger


// xxx_tb_xxx_n_bat_setting.dtsi

bat_comm: bat_comm {
...
        usb_charger_current = <50000>;  /* Unit: 0.01 mA */
    ac_charger_current = <100000>;  /* Unit: 0.01 mA */

        };





//   select_jeita_cv         (  switch_charging.c)
static BATTERY_VOLTAGE_ENUM select_jeita_cv(void)
{
    BATTERY_VOLTAGE_ENUM cv_voltage;

    if(!g_runin_battery_test_flag) {
        if (g_temp_status == TEMP_ABOVE_POS_60)
        {
            cv_voltage = JEITA_TEMP_ABOVE_POS_60_CV_VOLTAGE;
            g_stander_charging_temp_CC_value = JEITA_TEMP_ABOVE_POS_60_CV_CURRENT;
        }
        else if (g_temp_status == TEMP_POS_45_TO_POS_60)
        {
            cv_voltage = JEITA_TEMP_POS_45_TO_POS_60_CV_VOLTAGE;
            g_stander_charging_temp_CC_value = JEITA_TEMP_POS_45_TO_POS_60_CV_CURRENT;
        } else if (g_temp_status == TEMP_POS_10_TO_POS_45)

        ....
   }




// battery  


// mtxxx.dtsi      zvc
bat_meter {
            compatible = "mediatek,bat_meter";

bat_meter1 {
            compatible = "mediatek,bat_meter1";

//battery_meter.c
static struct platform_driver battery_meter_dts_driver = {
    .probe = battery_meter_dts_probe,
    .remove = NULL,
    .shutdown = NULL,
    .suspend = NULL,
    .resume = NULL,
    .driver = {
           .name = "battery_meter_dts",
#ifdef CONFIG_OF
           .of_match_table = "mediatek,bat_meter",
#endif
           },
};


static int battery_meter_probe(struct platform_device *dev)
{
....
    batt_meter_init_cust_data();   ->   __batt_meter_init_cust_data_from_dt();

...

}

__batt_meter_init_cust_data_from_dt()
{
...
  if (HQ_BATTERY_FMT == batteryID)
    {
        np = of_find_compatible_node(NULL, NULL, "mediatek,bat_meter");
        bm_err("Battery Type: xxxxxxxx\n");
    }
    else
    {
        np = of_find_compatible_node(NULL, NULL, "mediatek,bat_meter1");
        bm_err("Battery Type: xxxxxxxx\n");
    }

....
}




//battery_meter_hal.c 

signed int bm_ctrl_cmd(BATTERY_METER_CTRL_CMD cmd, void *data)
{
    signed int status = 0;
    static signed int init = -1;

    if (init == -1) {
        init = 0;
        bm_func[BATTERY_METER_CMD_HW_FG_INIT] = fgauge_initialization;
        bm_func[BATTERY_METER_CMD_GET_HW_FG_CURRENT] = fgauge_read_current;                 //get charge current
        bm_func[BATTERY_METER_CMD_GET_HW_FG_CURRENT_SIGN] = fgauge_read_current_sign;
        bm_func[BATTERY_METER_CMD_GET_HW_FG_CAR] = fgauge_read_columb;
        bm_func[BATTERY_METER_CMD_HW_RESET] = fgauge_hw_reset;
        bm_func[BATTERY_METER_CMD_GET_ADC_V_BAT_SENSE] = read_adc_v_bat_sense;
        bm_func[BATTERY_METER_CMD_GET_ADC_V_I_SENSE] = read_adc_v_i_sense;
        bm_func[BATTERY_METER_CMD_GET_ADC_V_BAT_TEMP] = read_adc_v_bat_temp;
        bm_func[BATTERY_METER_CMD_GET_ADC_V_CHARGER] = read_adc_v_charger;
        bm_func[BATTERY_METER_CMD_GET_HW_OCV] = read_hw_ocv;
        bm_func[BATTERY_METER_CMD_DUMP_REGISTER] = dump_register_fgadc;
    }




// switch_charging.c  

static unsigned int charging_full_check(void)
{
    unsigned int status;

    battery_charging_control(CHARGING_CMD_GET_CHARGING_STATUS, &status);
    return status;
}







// battery temperature    NTC  resistance

--- a/drivers/misc/mediatek/include/mt-plat/mt8163/include/mach/mt_battery_meter.h
+++ b/drivers/misc/mediatek/include/mt-plat/mt8163/include/mach/mt_battery_meter.h
@@ -114,7 +114,7 @@

 /* Disable Battery check for HQA */
 #ifdef CONFIG_MTK_DISABLE_POWER_ON_OFF_VOLTAGE_LIMITATION
-#define FIXED_TBAT_25                  // fix battery temperation 
+//#define FIXED_TBAT_25
 #endif

 /* Dynamic change wake up period of battery thread when suspend*/
diff --git a/drivers/misc/mediatek/include/mt-plat/mt8163/include/mach/mt_battery_meter_table.h b/drivers/misc/mediatek/include/mt-plat/mt8163/include/mach/mt_battery_meter_table.h
index 0267880..ddc7f53 100644
--- a/drivers/misc/mediatek/include/mt-plat/mt8163/include/mach/mt_battery_meter_table.h
+++ b/drivers/misc/mediatek/include/mt-plat/mt8163/include/mach/mt_battery_meter_table.h
@@ -76,23 +76,23 @@ typedef enum {
 /* ============================================================*/
 #if (BAT_NTC_10 == 1)
 BATT_TEMPERATURE Batt_Temperature_Table[] = {
-       {-20 , 75022},
-       {-15 , 57926},
-       {-10 , 45168},
-       { -5 , 35548},
-       {  0 , 28224},
-       {  5 , 22595},
-       { 10 , 18231},
-       { 15 , 14820},
-       { 20 , 12133},
+       {-20 , 67790},
+       {-15 , 53460},
+       {-10 , 42450},
+       { -5 , 33930},
+       {  0 , 27280},
+       {  5 , 22070},
+       { 10 , 17960},
+       { 15 , 14700},
+       { 20 , 12090},
        { 25 , 10000},
-       { 30 , 8295},
-       { 35 , 6922},
-       { 40 , 5810},
-       { 45 , 4903},
-       { 50 , 4160},
-       { 55 , 3547},
-       { 60 , 3039}
+       { 30 , 8312},
+       { 35 , 6942},
+       { 40 , 5826},
+       { 45 , 4911},
+       { 50 , 4158},
+       { 55 , 3536},
+       { 60 , 3019}
 };
 #endif







// get battery data     ( battery_common.c )

void mt_battery_GetBatteryData(void)
 {
 ...
        BMT_status.Vsense = Vsense;
    BMT_status.charger_vol = charger_vol;
    BMT_status.temperatureV = temperatureV;
    BMT_status.temperatureR = temperatureR;
    BMT_status.SOC = SOC;
    BMT_status.ZCV = ZCV;
    BMT_status.IBattery = battery_meter_get_battery_current()/10;
...
 }



//charger control inteface      (battery_common.c /charging_hw_sm5414.c)

static void get_charging_control(void)
{
    battery_charging_control = chr_control_interface;
}


typedef enum  
{  
        CHARGING_CMD_INIT,  
       CHARGING_CMD_DUMP_REGISTER,  
        CHARGING_CMD_ENABLE,  
        CHARGING_CMD_SET_CV_VOLTAGE,  
        CHARGING_CMD_GET_CURRENT,  
        CHARGING_CMD_SET_CURRENT,  
        CHARGING_CMD_SET_INPUT_CURRENT,  
        CHARGING_CMD_GET_CHARGING_STATUS,  
        CHARGING_CMD_RESET_WATCH_DOG_TIMER,  
        CHARGING_CMD_SET_HV_THRESHOLD,  
        CHARGING_CMD_GET_HV_STATUS,  
        CHARGING_CMD_GET_BATTERY_STATUS,  
        CHARGING_CMD_GET_CHARGER_DET_STATUS,  
        CHARGING_CMD_GET_CHARGER_TYPE,  
        CHARGING_CMD_GET_IS_PCM_TIMER_TRIGGER,  
        CHARGING_CMD_SET_PLATFORM_RESET,  
        CHARGING_CMD_GET_PLATFORM_BOOT_MODE,  
        CHARGING_CMD_SET_POWER_OFF,  
        CHARGING_CMD_NUMBER  
} CHARGING_CTRL_CMD;  







//  battery thread   (battery_common.c)

void BAT_thread(void)
{
    static kal_bool battery_meter_initilized = KAL_FALSE;

    if (battery_meter_initilized == KAL_FALSE) {
        battery_meter_initial();    /* move from battery_probe() to decrease booting time */
        BMT_status.nPercent_ZCV = battery_meter_get_battery_nPercent_zcv();
        battery_meter_initilized = KAL_TRUE;
    }

    mt_battery_charger_detect_check();
    mt_battery_GetBatteryData();                            // get battery data
    if (BMT_status.charger_exist == KAL_TRUE)
        check_battery_exist();

    mt_battery_thermal_check();
    mt_battery_notify_check();

    if (BMT_status.charger_exist == KAL_TRUE) {
        mt_battery_CheckBatteryStatus();             // battery status check : over charge or temprature is too hight, CHR_PRE,CHR_HOLD
        mt_battery_charging_algorithm();               // battery status action
    }

    mt_battery_update_status();                                 // update battery status
    mt_kpoc_power_off_check();
}





                // battery status action   (switch_charging.c)
                    void mt_battery_charging_algorithm(void)
                    {
                        battery_charging_control(CHARGING_CMD_RESET_WATCH_DOG_TIMER, NULL);

                        /* Generate AICR upper bound by AICL */
                        if (!mtk_is_pep_series_connect()) {
                            battery_charging_control(CHARGING_CMD_RUN_AICL,
                                &g_aicr_upper_bound);
                        }

                        mtk_pep20_check_charger();
                        mtk_pep_check_charger();
                        switch (BMT_status.bat_charging_state) {
                        case CHR_PRE:
                            BAT_PreChargeModeAction();
                            break;

                        case CHR_CC:
                            BAT_ConstantCurrentModeAction();
                            break;

                        case CHR_BATFULL:
                            BAT_BatteryFullAction();
                            break;

                        case CHR_HOLD:
                            BAT_BatteryHoldAction();
                            break;

                        case CHR_ERROR:
                            BAT_BatteryStatusFailAction();
                            break;
                        }

                        battery_charging_control(CHARGING_CMD_DUMP_REGISTER, NULL);
                    }







//  battery_update  (battery_common.c)   

static void battery_update(struct battery_data *bat_data)
{
....
    if (resetBatteryMeter == KAL_TRUE) {
        battery_meter_reset();              // reset soc
    } else {
        if (BMT_status.bat_full == KAL_TRUE && is_uisoc_ever_100 == KAL_TRUE) {
            BMT_status.UI_SOC = 100;
            battery_log(BAT_LOG_CRTI, "[recharging] UI_SOC=%d, SOC=%d\n",
                    BMT_status.UI_SOC, BMT_status.SOC);
        } else {
            mt_battery_Sync_UI_Percentage_to_Real();        // sync ui_soc to soc
        }
    }
....    

}



// (mt_battery_meter.h)      BAT_VOL_USE_ISENSE & SWCHR_POWER_PATH

#define BAT_VOL_USE_ISENSE
#define SWCHR_POWER_PATH
#define EXTERNAL_SWCHR_SUPPORT


// charger type detect
static void mt_battery_charger_detect_check(void)


 SYSTEM_OFF_VOLTAGE      //power off v


// battery soc

battery_meter_initial
{
...

#if defined(SOC_BY_HW_FG)
        fgauge_initialization();
        fgauge_algo_run_init();
        bm_print(BM_LOG_CRTI, "[battery_meter_initial] SOC_BY_HW_FG done\n");
#endif



#if defined(SOC_BY_SW_FG)
        g_auxadc_solution = 1;
        table_init();
        oam_init();
        bm_print(BM_LOG_CRTI, "[battery_meter_initial] SOC_BY_SW_FG done\n");
#endif
....
}


void oam_init(void)
{
..
    gFG_capacity_by_v = fgauge_read_capacity_by_v(gFG_voltage);
    vbat_capacity = fgauge_read_capacity_by_v(g_booting_vbat);
.
 ...
    dod_init();


}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值