Exemple #1
0
static INT32 get_kadc_001p(struct battery_type *battery)
{
	INT32 pd_m = 0;
	INT32 pd_temp = 0;

	INT32 temp_01c = battery->temp_01c;
	INT32 current_mA = battery->current_mA;

	UINT32 *m_paramtable;

	INT32 pd_m_coef;
	INT32 pd_m_resl;

	INT32 capacity_deduction_01p = CAPACITY_DEDUCTION_01p[battery->temp_index];
	INT32 capacity_predict_001p;
	/* 1. INT32 overflow check: assert abs(iChgCurrent_ma) <= 3000, iBattTemp_01c>-250, pd_t_coef <= 1000
		when calculating pd_temp: 0x7FFFFFFF / (500 * 3000 * 1000) =:= 1.4*/

	if (battery->current_mA > 3000)
		current_mA = 3000;
	else if (battery->current_mA < -3000)
		current_mA = -3000;
	if (battery->temp_01c <= -250)
		temp_01c = -250;

	/* 2. calculate pd_m and pd_temp*/

	if (battery->is_power_on_reset) {
		pd_m_coef = PD_M_COEF_TABLE_BOOT[battery->temp_index][battery->id_index];
		pd_m_resl = PD_M_RESL_TABLE_BOOT[battery->temp_index][battery->id_index];
	}
	else{
		pd_m_coef = PD_M_COEF_TABLE[battery->temp_index][battery->id_index];
		pd_m_resl = PD_M_RESL_TABLE[battery->temp_index][battery->id_index];
	}

	if (battery->current_mA < -pd_m_bias_mA) {
		/* ex: -150mA < -130mA*/
		pd_m = (abs(battery->current_mA) - pd_m_bias_mA) * pd_m_coef /pd_m_resl;
	}

	if (battery->temp_01c < 250) {
		pd_temp = ((250 - battery->temp_01c) * (abs(battery->current_mA) * PD_T_COEF[battery->id_index])) / (10 * 10000);
	}
	battery->pd_m = pd_m;

	/* 3. calculate KADC using M_PARAMTER_TABLE*/

	m_paramtable = M_PARAMTER_TABLE[battery->id_index];
	if (m_paramtable) {
		int i = 0; /* assume that m_paramtable has at least 2 items...the last capacity item must be 0 to end the loop...*/

		voltage_curve_translator_init(&__get_kadc_t);

		while (1) {
			INT32 capacity = m_paramtable[i];
			INT32 voltage = m_paramtable[i + 1];
			if (capacity == 10000) {
				/* full capacity, no need to fix voltage level*/
				voltage_curve_translator_add(&__get_kadc_t, voltage, capacity);
			}
			else {
				voltage_curve_translator_add(&__get_kadc_t, voltage - pd_temp, capacity);
			}

			if (capacity == 0)
				break;

			i += 2;
		}

#if HTC_ENABLE_POWER_DEBUG
		printk(DRIVER_ZONE " pd_m=%d, pd_temp=%d\n", pd_m, pd_temp);
#endif /* HTC_ENABLE_POWER_DEBUG*/

		capacity_predict_001p = voltage_curve_translator_get(&__get_kadc_t, battery->voltage_mV + pd_m);
	}
	else{
		capacity_predict_001p = (battery->voltage_mV - 3400) * 10000 / (4200 - 3400);
	}

	return (capacity_predict_001p - capacity_deduction_01p * 10) * 10000 / (10000 - capacity_deduction_01p * 10);
}
static INT32 get_kadc_001p(struct battery_type *battery)
{
	INT32 pd_m = 0;
	INT32 pd_temp = 0;

	INT32 temp_01c = battery->temp_01c;
	INT32 current_mA = battery->current_mA;

	UINT32 *m_paramtable;

	INT32 pd_m_coef;
	INT32 pd_m_resl;

	INT32 pd_t_coef;

	INT32 capacity_deduction_01p;
	INT32 capacity_predict_001p;

	struct battery_parameter* batt_param = container_of(
		battery, struct poweralg_type, battery)->pdata->batt_param;

	if (battery->current_mA > 3000)
		current_mA = 3000;
	else if (battery->current_mA < -3000)
		current_mA = -3000;
	if (battery->temp_01c <= -250)
		temp_01c = -250;

	

	if (battery->is_power_on_reset) {
		if (batt_param->pd_m_coef_tbl_boot)
			pd_m_coef = batt_param->pd_m_coef_tbl_boot[battery->temp_index][battery->id_index];
		else
			pd_m_coef = PD_M_COEF_DEFAULT;
		if (batt_param->pd_m_resl_tbl_boot)
			pd_m_resl = batt_param->pd_m_resl_tbl_boot[battery->temp_index][battery->id_index];
		else
			pd_m_resl = PD_M_RESL_DEFAULT;
	}
	else{
		if (batt_param->pd_m_coef_tbl)
			pd_m_coef = batt_param->pd_m_coef_tbl[battery->temp_index][battery->id_index];
		else
			pd_m_coef = PD_M_COEF_DEFAULT;
		if (batt_param->pd_m_resl_tbl)
			pd_m_resl = batt_param->pd_m_resl_tbl[battery->temp_index][battery->id_index];
		else
			pd_m_resl = PD_M_RESL_DEFAULT;
	}

	if (battery->current_mA < -pd_m_bias_mA) {
		
		pd_m = (abs(battery->current_mA) - pd_m_bias_mA) * pd_m_coef /pd_m_resl;
	}

	if (battery->temp_01c < 250) {
		if (batt_param->pd_t_coef)
			pd_t_coef = batt_param->pd_t_coef[battery->id_index];
		else
			pd_t_coef = PD_T_COEF_DEFAULT;
		pd_temp = ((250 - battery->temp_01c) * (abs(battery->current_mA) * pd_t_coef)) / (10 * 10000);
	}
	battery->pd_m = pd_m;

	

	if (batt_param->m_param_tbl)
		m_paramtable = batt_param->m_param_tbl[battery->id_index];
	else
		m_paramtable = M_PARAMETER_DEFAULT;
	if (m_paramtable) {
		int i = 0; 

		voltage_curve_translator_init(&__get_kadc_t);

		while (1) {
			INT32 capacity = m_paramtable[i];
			INT32 voltage = m_paramtable[i + 1];
			if (capacity == 10000) {
				
				voltage_curve_translator_add(&__get_kadc_t, voltage, capacity);
			}
			else {
				voltage_curve_translator_add(&__get_kadc_t, voltage - pd_temp, capacity);
			}

			if (capacity == 0)
				break;

			i += 2;
		}

#if HTC_ENABLE_POWER_DEBUG
		printk(DRIVER_ZONE " pd_m=%d, pd_temp=%d\n", pd_m, pd_temp);
#endif 

		capacity_predict_001p = voltage_curve_translator_get(&__get_kadc_t, battery->voltage_mV + pd_m);
	}
	else{
		capacity_predict_001p = (battery->voltage_mV - 3400) * 10000 / (4200 - 3400);
	}

	if (batt_param->capacity_deduction_tbl_01p)
		capacity_deduction_01p = batt_param->capacity_deduction_tbl_01p[battery->temp_index];
	else
		capacity_deduction_01p = CAPACITY_DEDUCTION_DEFAULT;
	return (capacity_predict_001p - capacity_deduction_01p * 10) * 10000 / (10000 - capacity_deduction_01p * 10);
}