static int get_hw_battery2_temp(void) { int ret = 0, data[4], i, ret_value = 0, ret_temp = 0, output; int times=1, Channel=0;//6589=1,6582=0(AUX_IN0_NTC) if( IMM_IsAdcInitReady() == 0 ) { printk("[thermal_auxadc_get_data]: AUXADC is not ready\n"); return 0; } i = times; while (i--) { ret_value = IMM_GetOneChannelValue(Channel, data, &ret_temp); ret += ret_temp; mtktsbattery2_dprintk("[thermal_auxadc_get_data(AUX_IN0_NTC)]: ret_temp=%d\n",ret_temp); } #if 0 Channel = 0; ret = 0 ; ret_temp = 0; i = times; while (i--) { ret_value = IMM_GetOneChannelValue(Channel, data, &ret_temp); ret += ret_temp; printk("[thermal_auxadc_get_data(ADCIN %d)]: ret_temp=%d\n",Channel,ret_temp); } Channel = 2; ret = 0 ; ret_temp = 0; i = times; while (i--) { ret_value = IMM_GetOneChannelValue(Channel, data, &ret_temp); ret += ret_temp; printk("[thermal_auxadc_get_data(ADCIN %d)]: ret_temp=%d\n",Channel,ret_temp); } #endif //ret = ret*1500/4096 ; ret = ret*1800/4096;//82's ADC power mtktsbattery2_dprintk("Battery output mV = %d\n",ret); output = BattVoltToTemp(ret); mtktsbattery2_dprintk("Battery output temperature = %d\n",output); return output; }
static void battery_update_info(struct batteryFTM *batt, char *info) { char *ptr; int temp = 0; #ifdef FEATURE_FTM_PMIC_632X int battery_fg_current = 0; bool pmic_is_connect = 0; #endif temp = get_ADC_channel(ADC_CHARGER, ADC_COUNT); if (temp != -1) { batt->charger_voltage = (temp/ADC_COUNT); /* Charger_Voltage */ if ( batt->charger_voltage >= 4100 ) { batt->charger_exist = true; batt->is_charging = true; } else { batt->charger_voltage = 0; batt->charger_exist = false; batt->is_charging = false; } } else { batt->charger_voltage = -1; batt->charger_exist = false; batt->is_charging = false; } //batt->bat_voltage = get_BAT_vol(); batt->bat_voltage = get_v_bat_sen(); if (batt->bat_voltage != -1) { #ifdef FEATURE_FTM_PMIC_632X batt->adc_vbat_current = ((batt->bat_voltage)*1024)/(4*1200); #else batt->adc_vbat_current = ((batt->bat_voltage)*1024)/(2*2800); #endif } else { batt->adc_vbat_current = -1; } //batt->current_charging = get_FG_current(); batt->current_charging = get_ADC_channel(ADC_BAT_FG_CURRENT, ADC_COUNT); temp = get_BAT_status(); if (temp != -1) { batt->is_calibration = (temp==1) ? true : false; } else { batt->is_calibration = false; } batt->bat_temperature = 25; #ifdef BATTERY_TYPE_B61UN temp = get_ADC_channel(ADC_BAT_TEMP, ADC_COUNT); if (temp != -1) { temp = (temp/ADC_COUNT); batt->bat_temperature = BattVoltToTemp(temp); } else { batt->bat_temperature = -100; } #endif #ifdef BATTERY_TYPE_BLP509 temp = get_ADC_channel(ADC_BAT_TEMP, ADC_COUNT); if (temp != -1) { temp = (temp/ADC_COUNT); batt->bat_temperature = BattVoltToTemp(temp); } else { batt->bat_temperature = -100; } #endif #ifdef BATTERY_TYPE_Z3 temp = get_ADC_channel(ADC_BAT_TEMP, ADC_COUNT); #ifdef FEATURE_FTM_PMIC_632X batt->bat_temperature = temp/ADC_COUNT; #else if (temp != -1) { temp = (temp/ADC_COUNT); batt->bat_temperature = BattVoltToTemp(temp); } else { batt->bat_temperature = -101; } #endif #endif #ifdef FEATURE_FTM_PMIC_632X temp = get_ADC_channel(ADC_BAT_FG_CURRENT, ADC_COUNT); if (temp != -1) { battery_fg_current = temp; } else { battery_fg_current = -1; } #endif #ifdef FEATURE_FTM_PMIC_632X if( batt->adc_vbat_current > 0 ) { pmic_is_connect = true; } else { pmic_is_connect = false; } #endif /* preare text view info */ ptr = info; ptr += sprintf(ptr, "%s : %d %s \n", uistr_info_title_battery_val, batt->bat_voltage, uistr_info_title_battery_mv); ptr += sprintf(ptr, "%s : %d %s \n", uistr_info_title_battery_temp, batt->bat_temperature, uistr_info_title_battery_c); ptr += sprintf(ptr, "%s : %s \n", uistr_info_title_battery_chr, (batt->is_charging) ? uistr_info_title_battery_yes : uistr_info_title_battery_no); ptr += sprintf(ptr, "%s : %d %s \n", uistr_info_title_battery_chr_val, batt->charger_voltage, uistr_info_title_battery_mv); #ifdef FEATURE_FTM_PMIC_632X ptr += sprintf(ptr, "%s: %d %s \n", uistr_info_title_battery_fg_cur, battery_fg_current, uistr_info_title_battery_ma); ptr += sprintf(ptr, "%s : %s \n", uistr_info_title_battery_pmic_chip, (pmic_is_connect) ? uistr_info_title_battery_connect : uistr_info_title_battery_no_connect); #endif return; }
static void battery_update_info(struct batteryFTM *batt, char *info) { char *ptr; int temp = 0; #ifdef FEATURE_FTM_PMIC_6329 int battery_fg_current = 0; bool pmic_is_connect = 0; #endif temp = get_ADC_channel(ADC_CHARGER, ADC_COUNT); if (temp != -1) { batt->charger_voltage = (temp/ADC_COUNT); /* Charger_Voltage */ if ( batt->charger_voltage >= 4100 ) { batt->charger_exist = true; batt->is_charging = true; } else { batt->charger_voltage = 0; batt->charger_exist = false; batt->is_charging = false; } } else { batt->charger_voltage = -1; batt->charger_exist = false; batt->is_charging = false; } #ifdef MTK_NCP1851_SUPPORT batt->bat_voltage = get_BAT_vol(); batt->current_charging = get_FG_current(); #else temp = get_ADC_channel(ADC_BAT_SEN, ADC_COUNT); if (temp != -1) { batt->bat_voltage = (temp/ADC_COUNT); #ifdef FEATURE_FTM_PMIC_6329 batt->adc_vbat_current = ((batt->bat_voltage)*1024)/(4*1200); #else batt->adc_vbat_current = ((batt->bat_voltage)*1024)/(2*2800); #endif } else { batt->bat_voltage = -1; batt->adc_vbat_current = -1; } temp = get_ADC_channel(ADC_I_SEN, ADC_COUNT); if (temp != -1) { temp = (temp/ADC_COUNT); /* I_sense */ if (batt->charger_exist) { batt->current_charging = ((temp-(batt->bat_voltage))*10)/2; } else { batt->current_charging = 0; } } else { batt->current_charging = -1; } #endif temp = get_BAT_status(); if (temp != -1) { batt->is_calibration = (temp==1) ? true : false; } else { batt->is_calibration = false; } batt->bat_temperature = 25; #ifdef BATTERY_TYPE_B61UN temp = get_ADC_channel(ADC_BAT_TEMP, ADC_COUNT); if (temp != -1) { temp = (temp/ADC_COUNT); batt->bat_temperature = BattVoltToTemp(temp); } else { batt->bat_temperature = -100; } #endif #ifdef BATTERY_TYPE_BLP509 temp = get_ADC_channel(ADC_BAT_TEMP, ADC_COUNT); if (temp != -1) { temp = (temp/ADC_COUNT); batt->bat_temperature = BattVoltToTemp(temp); } else { batt->bat_temperature = -100; } #endif #ifdef BATTERY_TYPE_Z3 temp = get_ADC_channel(ADC_BAT_TEMP, ADC_COUNT); #ifdef FEATURE_FTM_PMIC_6329 batt->bat_temperature = temp; #else if (temp != -1) { temp = (temp/ADC_COUNT); batt->bat_temperature = BattVoltToTemp(temp); } else { batt->bat_temperature = -101; } #endif #endif #ifdef FEATURE_FTM_PMIC_6329 temp = get_ADC_channel(ADC_BAT_FG_CURRENT, ADC_COUNT); if (temp != -1) { battery_fg_current = temp; } else { battery_fg_current = -1; } #endif #ifdef FEATURE_FTM_PMIC_6329 if( batt->adc_vbat_current > 0 ) { pmic_is_connect = true; } else { pmic_is_connect = false; } #endif /* preare text view info */ ptr = info; #ifndef MTK_NCP1851_SUPPORT ptr += sprintf(ptr, "BAT Cal. : %s\n", (batt->is_calibration) ? "YES" : "NO"); ptr += sprintf(ptr, "BAT Volt. : %d mV\n", batt->bat_voltage); ptr += sprintf(ptr, "BAT Temp. : %d Celsius\n", batt->bat_temperature); ptr += sprintf(ptr, "CHGR : %s\n", (batt->is_charging) ? "YES" : "NO"); ptr += sprintf(ptr, "CHGR Volt.: %d mV\n", batt->charger_voltage); ptr += sprintf(ptr, "CHGR Curr.: %d mA\n", batt->current_charging); ptr += sprintf(ptr, "AD32 : %d\n", batt->adc_vbat_3_2); ptr += sprintf(ptr, "AD42 : %d\n", batt->adc_vbat_4_2); ptr += sprintf(ptr, "CurAD : %d\n", batt->adc_vbat_current); #ifdef FEATURE_FTM_PMIC_6329 ptr += sprintf(ptr, "FG_Current: %dmA\n", battery_fg_current); ptr += sprintf(ptr, "PMIC Chip : %s\n", (pmic_is_connect) ? "Connect" : "NO connect"); #endif #else ptr += sprintf(ptr, "BAT Volt. : %d mV\n", batt->bat_voltage); ptr += sprintf(ptr, "BAT Temp. : %d Celsius\n", batt->bat_temperature); ptr += sprintf(ptr, "CHGR : %s\n", (batt->is_charging) ? "YES" : "NO"); ptr += sprintf(ptr, "CHGR Volt.: %d mV\n", batt->charger_voltage); #ifdef FEATURE_FTM_PMIC_6329 ptr += sprintf(ptr, "BAT Curr.: %dmA\n", battery_fg_current); #endif #endif return; }
//extern int BattVoltToTemp(int dwVolt); void mt65xx_bat_init(void) { kal_int32 bat_vol; kal_int32 bat_tempture; kal_int32 bat_temp; #ifdef MTK_IPO_POWERPATH_SUPPORT CHARGER_TYPE CHR_Type_num = CHARGER_UNKNOWN; #endif // Low Battery Safety Booting bat_vol = get_bat_sense_volt(1); bat_tempture = get_tbat_volt(1); bat_temp=BattVoltToTemp(bat_tempture); printf("the bat_vol is %d,the bat_tempture is %d,the bat_temp is %d\n",bat_vol,bat_tempture,bat_temp); #if defined(MTK_BQ24196_SUPPORT) ||defined(MTK_BQ24296_SUPPORT) bat_vol = get_i_sense_volt(5); #endif printf("[mt65xx_bat_init] check VBAT=%d mV with %d mV\n", bat_vol, BATTERY_LOWVOL_THRESOLD); pchr_turn_on_charging(); if(g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT && (upmu_get_pwrkey_deb()==0) ) { printf("[mt65xx_bat_init] KPOC+PWRKEY => change boot mode\n"); g_boot_reason_change = true; } rtc_boot_check(false); #ifndef MTK_DISABLE_POWER_ON_OFF_VOLTAGE_LIMITATION //if (bat_vol < BATTERY_LOWVOL_THRESOLD) if (is_low_battery(bat_vol)) { if(g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT && upmu_is_chr_det() == KAL_TRUE) { printf("[%s] Kernel Low Battery Power Off Charging Mode\n", __func__); g_boot_mode = LOW_POWER_OFF_CHARGING_BOOT; return; } #ifdef BULMA_PROJECT else if((META_BOOT == g_boot_mode) ||(ADVMETA_BOOT == g_boot_mode)) { printf("Enter Meta Mode emw\n\r"); } #endif else { #ifdef MTK_IPO_POWERPATH_SUPPORT //boot linux kernel because of supporting powerpath and using standard AC charger if(upmu_is_chr_det() == KAL_TRUE) { charging_get_charger_type(&CHR_Type_num); if(STANDARD_CHARGER == CHR_Type_num) { return; } } #endif printf("[BATTERY] battery voltage(%dmV) <= CLV ! Can not Boot Linux Kernel !! \n\r",bat_vol); #ifndef NO_POWER_OFF mt6575_power_off(); #endif while(1) { printf("If you see the log, please check with RTC power off API\n\r"); } } } if(is_high_bat_tempature(bat_temp)) { printf("[BATTERY] battery tempature(%dmV) <= CLV ! Can not Boot Linux Kernel !! \n\r",bat_tempture); #ifndef NO_POWER_OFF mt6575_power_off(); #endif while(1) { printf("If you see the log, please check with RTC power off API\n\r"); } } #endif return; }