Beispiel #1
0
static BOOL __battery_param_udpate(struct battery_type *battery)
{
	INT32 temp_01c;
	INT32 temp_voltage_mv;
	struct battery_parameter* batt_param = container_of(
		battery, struct poweralg_type, battery)->pdata->batt_param;

	if (support_ds2746_gauge_ic) {
		/* adc register value are read from __ds2746_battery_adc_udpate()*/
		if (!__ds2746_battery_adc_udpate(battery))
			return FALSE;
	}
	else{
		/* adc register value are read from BAHW_get_batt_info_all()
		if ( !BAHW_get_batt_info_all(battery) ) return FALSE;*/
	}

	/*real physical value*/
	temp_voltage_mv =
		(battery->voltage_adc * batt_param->voltage_adc_to_mv_coef /
			batt_param->voltage_adc_to_mv_resl);

	if (temp_voltage_mv < BATTERY_VOLTAGE_MIN ||
		temp_voltage_mv > BATTERY_VOLTAGE_MAX) {
		printk(DRIVER_ZONE " invalid V(%d). Update stop.\n", temp_voltage_mv);
		return FALSE;
	}

	battery->voltage_mV = temp_voltage_mv;
	battery->current_mA =
		(battery->current_adc * batt_param->current_adc_to_mv_coef /
			batt_param->current_adc_to_mv_resl);
	battery->discharge_mA =
		(battery->discharge_adc * batt_param->discharge_adc_to_mv_coef /
			batt_param->discharge_adc_to_mv_resl);
	battery->charge_counter_mAh =
		(battery->charge_counter_adc * batt_param->acr_adc_to_mv_coef /
		batt_param->acr_adc_to_mv_resl) - batt_param->charge_counter_zero_base_mAh;
	battery->current_mA = battery->current_mA - battery->discharge_mA;
	/* prevent from adc out of range*/
	if (battery->id_adc >= batt_param->id_adc_overflow) {
		/* when id pin grounded with charger connected, id_adc rawdata
			will overflow to an extreme large value (ffe) */
		battery->id_adc = 1;
	}
	if (battery->id_adc >= batt_param->id_adc_resl) {
		battery->id_adc = batt_param->id_adc_resl - 1;
	}
	if (battery->id_adc <= 0) {
		battery->id_adc = 1;
	}
	if (battery->temp_adc >= batt_param->temp_adc_resl) {
		battery->temp_adc = batt_param->temp_adc_resl - 1;
	}
	if (battery->temp_adc <= 0) {
		battery->temp_adc = 1;
	}

	if (is_need_battery_id_detection == TRUE)
		battery_id_detection(battery);

	/* calculate temperature*/
	//    battery->temp_01c 			  = get_temp_c((float)temp_R_kohm / ((float)batt_param->temp_adc_resl/battery->temp_adc - 1))*10;
	temp_01c = get_temp_01c(battery);
	if (temp_01c >= TEMP_MIN*10)
		battery->temp_01c = temp_01c;
	else
		printk(DRIVER_ZONE " get temp_01c(%d) failed...\n", temp_01c);
	battery->temp_index = get_temp_index(battery);

	/* calculate KADC and RARC*/
	battery->KADC_01p = CEILING(get_kadc_001p(battery), 10);
	battery->RARC_01p = CEILING(10000 * battery->charge_counter_mAh / battery->charge_full_real_mAh, 10);
	if (!support_ds2746_gauge_ic) {
		__software_acr_update(battery);
	}

	/*! star_lee 20100426 - minimum RARC is 0%*/
	if (battery->RARC_01p <= 0) {
		battery->RARC_01p = 0;
	}

#if HTC_PARAM_DS2746_DEBUG_ENABLE
	printk(DRIVER_ZONE " V=%d(%x) I=%d(%x) C=%d.%d/%d(%x) id=%d(%x) T=%d(%x) KADC=%d\n",
		battery->voltage_mV,
		battery->voltage_adc,
		battery->current_mA,
		battery->current_adc,
		battery->charge_counter_mAh,
		battery->software_charge_counter_mAms,
		battery->charge_full_real_mAh,
		battery->charge_counter_adc,
		battery->id_index,
		battery->id_adc,
		battery->temp_01c,
		battery->temp_adc,
		battery->KADC_01p);
#endif

	return TRUE;
}
Beispiel #2
0
static BOOL __battery_param_udpate(struct battery_type *battery)
{
	static int batt_id_stable_counter = 0;
	INT32 batt_id_index;
	INT32 temp_01c;

	if (support_ds2746_gauge_ic) {
		/* adc register value are read from __ds2746_battery_adc_udpate()*/
		if (!__ds2746_battery_adc_udpate(battery))
			return FALSE;
	}
	else{
		/* adc register value are read from BAHW_get_batt_info_all()
		if ( !BAHW_get_batt_info_all(battery) ) return FALSE;*/
	}

	/*real physical value*/
	battery->voltage_mV = (battery->voltage_adc * voltage_adc_to_mv_coef / voltage_adc_to_mv_resl);
	battery->current_mA = (battery->current_adc * current_adc_to_mv_coef / current_adc_to_mv_resl);
	battery->discharge_mA = (battery->discharge_adc * discharge_adc_to_mv_coef / discharge_adc_to_mv_resl);
	battery->charge_counter_mAh = (battery->charge_counter_adc * acr_adc_to_mv_coef / acr_adc_to_mv_resl) -	charge_counter_zero_base_mAh;
	battery->current_mA = battery->current_mA - battery->discharge_mA;
	/* prevent from adc out of range*/
	if (battery->id_adc >= id_adc_resl) {
		battery->id_adc = id_adc_resl - 1;
	}
	if (battery->id_adc <= 0) {
		battery->id_adc = 1;
	}
	if (battery->temp_adc >= temp_adc_resl) {
		battery->temp_adc = temp_adc_resl - 1;
	}
	if (battery->temp_adc <= 0) {
		battery->temp_adc = 1;
	}

	/* battery ID shall be ready first for temp/kadc calculation*/
	//   if ( id_conversion ) battery->id_ohm = ((float)id_R_kohm / ((float)id_adc_resl/battery->id_adc - 1)) * 1000;     // kohm -> ohm
	//   else   			  battery->id_ohm = battery->id_adc;
	battery->id_ohm = battery->id_adc;
	calibrate_id_ohm(battery);

	batt_id_index = get_id_index(battery);

	if (is_allow_batt_id_change) {
		/*! TODO: batt_id changes immediately; may need to modify in future*/
		if (batt_id_stable_counter >= 3 && batt_id_index != battery->id_index){
			/* if batt_id is stable but is different from previous one*/
			batt_id_stable_counter = 0; /* reset stable counter and set batt_id to new one*/
		}
	}

	if (batt_id_stable_counter < 3) {
		if (batt_id_stable_counter == 0) {
			/* first time to get the batt id*/
			battery->id_index = batt_id_index;
			battery->charge_full_design_mAh = FL_25[battery->id_index];
			battery->charge_full_real_mAh = battery->charge_full_design_mAh;
			batt_id_stable_counter = 1;
		}
		else{
			/* 2nd and further time to get the batt id*/
			if (batt_id_index == battery->id_index)
				batt_id_stable_counter++;
			else
				batt_id_stable_counter = 0;
		}
	}

	/* calculate temperature*/
	//    battery->temp_01c 			  = get_temp_c((float)temp_R_kohm / ((float)temp_adc_resl/battery->temp_adc - 1))*10;
	temp_01c = get_temp_01c(battery);
	if (temp_01c >= TEMP_MIN*10)
		battery->temp_01c = temp_01c;
	else
		printk(DRIVER_ZONE " get temp_01c(%d) failed...\n", temp_01c);
	battery->temp_index = get_temp_index(battery);

	/* calculate KADC and RARC*/
	battery->KADC_01p = CEILING(get_kadc_001p(battery), 10);
	battery->RARC_01p = CEILING(10000 * battery->charge_counter_mAh / battery->charge_full_real_mAh, 10);
	if (!support_ds2746_gauge_ic) {
		__software_acr_update(battery);
	}

	if (battery->voltage_mV <BATTERY_VOLTAGE_MIN ||
		battery->voltage_mV> BATTERY_VOLTAGE_MAX) {
		printk(DRIVER_ZONE " invalid V(%d).\n", battery->voltage_mV);
		return FALSE;
	}

	/*! star_lee 20100426 - minimum RARC is 0%*/
	if (battery->RARC_01p <= 0) {
		battery->RARC_01p = 0;
	}

	printk(DRIVER_ZONE " V=%d(%x) I=%d(%x) C=%d.%d/%d(%x) id=%d(%x) T=%d(%x) KADC=%d\n",
		battery->voltage_mV,
		battery->voltage_adc,
		battery->current_mA,
		battery->current_adc,
		battery->charge_counter_mAh,
		battery->software_charge_counter_mAms,
		battery->charge_full_real_mAh,
		battery->charge_counter_adc,
		battery->id_index,
		battery->id_adc,
		battery->temp_01c,
		battery->temp_adc,
		battery->KADC_01p);

	return TRUE;
}
static BOOL __battery_param_udpate(struct battery_type *battery)
{
	INT32 temp_01c;

#if defined(CONFIG_MACH_DUMMY)
	return TRUE;
#endif

	if (support_ds2746_gauge_ic) {
		
		if (!__ds2746_battery_adc_udpate(battery))
			return FALSE;
	}
	else{
	}

	
	battery->voltage_mV = (battery->voltage_adc * voltage_adc_to_mv_coef / voltage_adc_to_mv_resl);
	battery->current_mA = (battery->current_adc * current_adc_to_mv_coef / current_adc_to_mv_resl);
	battery->discharge_mA = (battery->discharge_adc * discharge_adc_to_mv_coef / discharge_adc_to_mv_resl);
	battery->charge_counter_mAh = (battery->charge_counter_adc * acr_adc_to_mv_coef / acr_adc_to_mv_resl) -	charge_counter_zero_base_mAh;
	battery->current_mA = battery->current_mA - battery->discharge_mA;
	
	if (battery->id_adc >= id_adc_overflow) {
		battery->id_adc = 1;
	}
	if (battery->id_adc >= id_adc_resl) {
		battery->id_adc = id_adc_resl - 1;
	}
	if (battery->id_adc <= 0) {
		battery->id_adc = 1;
	}
	if (battery->temp_adc >= temp_adc_resl) {
		battery->temp_adc = temp_adc_resl - 1;
	}
	if (battery->temp_adc <= 0) {
		battery->temp_adc = 1;
	}

	if (is_need_battery_id_detection == TRUE) {
		battery_id_detection(battery);
	} else {
#if (defined(CONFIG_MACH_PRIMODS) || defined(CONFIG_MACH_PROTOU) || defined(CONFIG_MACH_DUMMY) || defined(CONFIG_MACH_DUMMY))
		battery->id_index = (INT32)get_batt_id();
#endif
	}

	
	
	temp_01c = get_temp_01c(battery);
	if (temp_01c >= TEMP_MIN*10)
		battery->temp_01c = temp_01c;
	else
		printk(DRIVER_ZONE " get temp_01c(%d) failed...\n", temp_01c);
	battery->temp_index = get_temp_index(battery);
#if (defined(CONFIG_MACH_PRIMODS))
	if(system_rev == XA_board || system_rev == XB_board)
		battery->temp_01c = 280;	
	#endif
	
	battery->KADC_01p = CEILING(get_kadc_001p(battery), 10);
	battery->RARC_01p = CEILING(10000 * battery->charge_counter_mAh / battery->charge_full_real_mAh, 10);
	if (!support_ds2746_gauge_ic) {
		__software_acr_update(battery);
	}

	if (battery->voltage_mV <BATTERY_VOLTAGE_MIN ||
		battery->voltage_mV> BATTERY_VOLTAGE_MAX) {
		printk(DRIVER_ZONE " invalid V(%d).\n", battery->voltage_mV);
		return FALSE;
	}

	
	if (battery->RARC_01p <= 0) {
		battery->RARC_01p = 0;
	}

#if HTC_PARAM_DS2746_DEBUG_ENABLE
	printk(DRIVER_ZONE " V=%d(%x) I=%d(%x) C=%d.%d/%d(%x) id=%d(%x) T=%d(%x) KADC=%d\n",
		battery->voltage_mV,
		battery->voltage_adc,
		battery->current_mA,
		battery->current_adc,
		battery->charge_counter_mAh,
		battery->software_charge_counter_mAms,
		battery->charge_full_real_mAh,
		battery->charge_counter_adc,
		battery->id_index,
		battery->id_adc,
		battery->temp_01c,
		battery->temp_adc,
		battery->KADC_01p);
#endif

	return TRUE;
}