static void mtk_ta_vchr_select(int i,int ta_v_chr_candidate[], int ta_charging_current_candidate[], int *max_charging_current, int *max_charging_current_i) { int current_vchr; kal_bool retransmit = KAL_TRUE; kal_uint32 retransmit_count=0; current_vchr = battery_meter_get_charger_voltage(); if(ta_current_level != 5000 && current_vchr >= 4900) { /* pattern error before, so reset vchr to 5V */ battery_log(BAT_LOG_CRTI, "mtk_ta_vchr_select() : curr_VChr=%d, ta_current_level=%d\n",current_vchr,ta_current_level); mtk_ta_reset_vchr(); } do { mtk_tuning_voltage(ta_current_level, ta_v_chr_candidate[i]); current_vchr = battery_meter_get_charger_voltage(); if((abs(current_vchr - ta_current_level) > 300) && (ta_cable_out_occur == KAL_FALSE)) { /* variation > 0.3V, error occur */ retransmit_count++; battery_log(BAT_LOG_CRTI, "mtk_ta_vchr_select(): retransmit_count =%d, cur_chr=%d, ta_current_level=%d\n", retransmit_count, current_vchr, ta_current_level); mtk_ta_reset_vchr(); } else { retransmit = KAL_FALSE; } if((retransmit_count == 2) || (ta_cable_out_occur == KAL_TRUE)) { retransmit = KAL_FALSE; } } while((retransmit == KAL_TRUE) && (ta_cable_out_occur == KAL_FALSE)); battery_charging_control(CHARGING_CMD_SET_CURRENT,&ta_charging_current); //1.5A battery_log(BAT_LOG_CRTI, "mtk_ta_vchr_select() : use 1.5A for select max current\n"); msleep(900); // over 800ms to avoid interference pattern ta_charging_current_candidate[i] = battery_meter_get_charging_current_imm(); /* we hope to choose the less VChr if the current difference between 2 step is not large, so we add weighting for different VChr step */ if(i == 1) ta_charging_current_candidate[i] += 100; // weighting, plus 120mA for Vbat+0.4V else if(i == 2) ta_charging_current_candidate[i] += 50; // weighting, plug 60mA for Vbat+0.6V if(ta_charging_current_candidate[i] > *max_charging_current) { *max_charging_current = ta_charging_current_candidate[i]; *max_charging_current_i = i; } }
static void battery_pump_express_charger_check(void) { if (KAL_TRUE == ta_check_chr_type && STANDARD_CHARGER == BMT_status.charger_type && BMT_status.SOC >= TA_START_BATTERY_SOC && BMT_status.SOC < TA_STOP_BATTERY_SOC) { mutex_lock(&ta_mutex); wake_lock(&TA_charger_suspend_lock); mtk_ta_reset_vchr(); mtk_ta_init(); mtk_ta_detector(); /* need to re-check if the charger plug out during ta detector */ if(KAL_TRUE == ta_cable_out_occur) ta_check_chr_type = KAL_TRUE; else ta_check_chr_type = KAL_FALSE; wake_unlock(&TA_charger_suspend_lock); mutex_unlock(&ta_mutex); } else { battery_xlog_printk(BAT_LOG_CRTI, "Stop battery_pump_express_charger_check, SOC=%d, ta_check_chr_type = %d, charger_type = %d \n", BMT_status.SOC, ta_check_chr_type, BMT_status.charger_type); } }
static void battery_pump_express_algorithm_start(void) { kal_int32 charger_vol; kal_uint32 charging_enable = KAL_FALSE; mutex_lock(&ta_mutex); wake_lock(&TA_charger_suspend_lock); if(KAL_TRUE == is_ta_connect) { /* check cable impedance */ charger_vol = battery_meter_get_charger_voltage(); if(KAL_FALSE == ta_vchr_tuning) { mtk_ta_retry_increase(); //increase TA voltage to 9V charger_vol = battery_meter_get_charger_voltage(); ta_vchr_tuning = KAL_TRUE; } else if(BMT_status.SOC > TA_STOP_BATTERY_SOC) { //disable charging, avoid Iterm issue battery_charging_control(CHARGING_CMD_ENABLE,&charging_enable); mtk_ta_reset_vchr(); //decrease TA voltage to 5V charger_vol = battery_meter_get_charger_voltage(); if(abs(charger_vol - ta_v_chr_org) <= 1000) // 1.0V is_ta_connect = KAL_FALSE; battery_xlog_printk(BAT_LOG_CRTI, "Stop battery_pump_express_algorithm, SOC=%d is_ta_connect =%d, TA_STOP_BATTERY_SOC: %d\n", BMT_status.SOC, is_ta_connect, TA_STOP_BATTERY_SOC); } battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] check cable impedance, VA(%d) VB(%d) delta(%d).\n", ta_v_chr_org, charger_vol, charger_vol - ta_v_chr_org); battery_xlog_printk(BAT_LOG_CRTI, "mtk_ta_algorithm() end\n"); } else { battery_xlog_printk(BAT_LOG_CRTI, "It's not a TA charger, bypass TA algorithm\n"); } wake_unlock(&TA_charger_suspend_lock); mutex_unlock(&ta_mutex); }
static void mtk_ta_detector(void) { int real_v_chrA; int real_v_chrB; kal_bool retransmit = KAL_TRUE; kal_uint32 retransmit_count=0; U32 charging_enable = true; battery_log(BAT_LOG_CRTI, "mtk_ta_detector() start\n"); battery_charging_control(CHARGING_CMD_ENABLE,&charging_enable); do { real_v_chrA = ta_get_charger_voltage(); mtk_ta_decrease(); mtk_ta_decrease(); real_v_chrB = ta_get_charger_voltage(); if(real_v_chrA - real_v_chrB >= 300) { /* 0.3V */ retransmit = KAL_FALSE; is_ta_connect = KAL_TRUE; } else { retransmit_count++; battery_log(BAT_LOG_CRTI, "mtk_ta_detector(): retransmit_count =%d, chrA=%d, chrB=%d\n", retransmit_count, real_v_chrA, real_v_chrB); mtk_ta_reset_vchr(); } if((retransmit_count == 3) || (BMT_status.charger_exist == KAL_FALSE)) { retransmit = KAL_FALSE; is_ta_connect = KAL_FALSE; } } while((retransmit == KAL_TRUE) && (ta_cable_out_occur == KAL_FALSE)); battery_log(BAT_LOG_CRTI, "mtk_ta_detector() ta_current_level=%d, real_v_chrA=%d, real_v_chrB=%d, is_ta_connect=%d\n", ta_current_level, real_v_chrA, real_v_chrB,is_ta_connect); battery_log(BAT_LOG_CRTI, "mtk_ta_detector() end, retry_count=%d, ta_cable_out_occur=%d \n",retransmit_count,ta_cable_out_occur); }
static void battery_pump_express_charger_check(void) { if (ta_check_chr_type == KAL_TRUE && BMT_status.charger_type == STANDARD_CHARGER) { mutex_lock(&ta_mutex); wake_lock(&TA_charger_suspend_lock); mtk_ta_reset_vchr(); mtk_ta_init(); mtk_ta_detector(); first_vchr_det = KAL_TRUE; if(ta_cable_out_occur == KAL_FALSE) { ta_check_chr_type = KAL_FALSE; } else { /* need to re-check if the charger plug out during ta detector */ ta_check_chr_type = KAL_TRUE; } wake_unlock(&TA_charger_suspend_lock); mutex_unlock(&ta_mutex); } }