int32_t pm8xxx_adc_batt_scaler(struct pm8xxx_adc_arb_btm_param *btm_param,
		const struct pm8xxx_adc_properties *adc_properties,
		const struct pm8xxx_adc_chan_properties *chan_properties)
{
	int rc;
	struct pm8xxx_adc_map_pt *adc_map = NULL;
	uint32_t						adc_map_array_size;
	static unsigned int 			phaseid = 0;

	/*
	 * this function is called by pm8xxx_adc_btm_configure which to configure 
	 * PMIC temperature IRQ and callback function, which alien battery
	 * doesn't need to, so here don't take alien battery into consideration
	 */

	if (phaseid == 0)
		phaseid = fih_get_product_phase();

	if (phaseid <= PHASE_SP) {
		adc_map = adcmap_btm_threshold;
		adc_map_array_size = ARRAY_SIZE(adcmap_btm_threshold);
	}
	else {
		adc_map = adcmap_btm_threshold_pre_ap;
		adc_map_array_size = ARRAY_SIZE(adcmap_btm_threshold_pre_ap);
	}

	rc = pm8xxx_adc_map_linear(
		adc_map,
		adc_map_array_size,
		(btm_param->low_thr_temp),
		&btm_param->low_thr_voltage);
	if (rc)
		return rc;

	btm_param->low_thr_voltage *=
		chan_properties->adc_graph[ADC_CALIB_RATIOMETRIC].dy;
	do_div(btm_param->low_thr_voltage, adc_properties->adc_vdd_reference);
	btm_param->low_thr_voltage +=
		chan_properties->adc_graph[ADC_CALIB_RATIOMETRIC].adc_gnd;

	rc = pm8xxx_adc_map_linear(
		adc_map,
		adc_map_array_size,
		(btm_param->high_thr_temp),
		&btm_param->high_thr_voltage);
	if (rc)
		return rc;

	btm_param->high_thr_voltage *=
		chan_properties->adc_graph[ADC_CALIB_RATIOMETRIC].dy;
	do_div(btm_param->high_thr_voltage, adc_properties->adc_vdd_reference);
	btm_param->high_thr_voltage +=
		chan_properties->adc_graph[ADC_CALIB_RATIOMETRIC].adc_gnd;


	return rc;
}
int32_t pm8xxx_adc_scale_bl_therm(int32_t adc_code,
		const struct pm8xxx_adc_properties *adc_properties,
		const struct pm8xxx_adc_chan_properties *chan_properties,
		struct pm8xxx_adc_chan_result *adc_chan_result)
{
	int64_t bl_voltage = 0;
	uint32_t tablesize;
	int rc = 0;

	bl_voltage = pm8xxx_adc_scale_ratiometric_calib(adc_code,
			adc_properties, chan_properties);
	tablesize = ARRAY_SIZE(adcmap_bl_therm);

	if (bl_voltage > adcmap_bl_therm[0].x
		|| bl_voltage < adcmap_bl_therm[tablesize-1].x){
		adc_chan_result->physical = PM8xxx_ADC_BL_THERM_INVALID_TEMP;
	} else {
		rc = pm8xxx_adc_map_linear(
				adcmap_bl_therm,
				tablesize,
				bl_voltage,
				&adc_chan_result->physical);
	}

	return rc;
}
Ejemplo n.º 3
0
int32_t pm8xxx_adc_scale_batt_therm(int32_t adc_code,
		const struct pm8xxx_adc_properties *adc_properties,
		const struct pm8xxx_adc_chan_properties *chan_properties,
		struct pm8xxx_adc_chan_result *adc_chan_result)
{
	pm8xxx_adc_scale_default(adc_code, adc_properties, chan_properties,
								adc_chan_result);
	/* convert mV ---> degC using the table */
	return pm8xxx_adc_map_linear(
			adcmap_batttherm,
			ARRAY_SIZE(adcmap_batttherm),
			adc_chan_result->physical,
			&adc_chan_result->physical);
}
Ejemplo n.º 4
0
int32_t pm8xxx_adc_batt_scaler(struct pm8xxx_adc_arb_btm_param *btm_param,
		const struct pm8xxx_adc_properties *adc_properties,
		const struct pm8xxx_adc_chan_properties *chan_properties)
{
	int rc;

	rc = pm8xxx_adc_map_linear(
		adcmap_btm_threshold,
		ARRAY_SIZE(adcmap_btm_threshold),
		(btm_param->low_thr_temp),
		&btm_param->low_thr_voltage);
	if (rc)
		return rc;

	btm_param->low_thr_voltage *=
		chan_properties->adc_graph[ADC_CALIB_RATIOMETRIC].dy;
	do_div(btm_param->low_thr_voltage, adc_properties->adc_vdd_reference);
	btm_param->low_thr_voltage +=
		chan_properties->adc_graph[ADC_CALIB_RATIOMETRIC].adc_gnd;

	rc = pm8xxx_adc_map_linear(
		adcmap_btm_threshold,
		ARRAY_SIZE(adcmap_btm_threshold),
		(btm_param->high_thr_temp),
		&btm_param->high_thr_voltage);
	if (rc)
		return rc;

	btm_param->high_thr_voltage *=
		chan_properties->adc_graph[ADC_CALIB_RATIOMETRIC].dy;
	do_div(btm_param->high_thr_voltage, adc_properties->adc_vdd_reference);
	btm_param->high_thr_voltage +=
		chan_properties->adc_graph[ADC_CALIB_RATIOMETRIC].adc_gnd;


	return rc;
}
Ejemplo n.º 5
0
int32_t pm8xxx_adc_scale_batt_therm(int32_t adc_code,
		const struct pm8xxx_adc_properties *adc_properties,
		const struct pm8xxx_adc_chan_properties *chan_properties,
		struct pm8xxx_adc_chan_result *adc_chan_result)
{
	/* Note: adc_chan_result->measurement is in the unit of
		adc_properties.adc_reference */
	adc_chan_result->measurement = adc_code;
	/* convert mV ---> degC using the table */
	return pm8xxx_adc_map_linear(
			adcmap_batttherm,
			ARRAY_SIZE(adcmap_batttherm),
			adc_code,
			&adc_chan_result->physical);
}
Ejemplo n.º 6
0
int32_t pm8xxx_adc_scale_pa_therm(int32_t adc_code,
		const struct pm8xxx_adc_properties *adc_properties,
		const struct pm8xxx_adc_chan_properties *chan_properties,
		struct pm8xxx_adc_chan_result *adc_chan_result)
{
	int64_t pa_voltage = 0;

	pa_voltage = pm8xxx_adc_scale_ratiometric_calib(adc_code,
			adc_properties, chan_properties);

	return pm8xxx_adc_map_linear(
			adcmap_pa_therm,
			ARRAY_SIZE(adcmap_pa_therm),
			pa_voltage,
			&adc_chan_result->physical);
}
Ejemplo n.º 7
0
/* Scales the ADC code to 0.001 degrees C using the map
 * table for the XO thermistor.
 */
int32_t pm8xxx_adc_tdkntcg_therm(int32_t adc_code,
		const struct pm8xxx_adc_properties *adc_properties,
		const struct pm8xxx_adc_chan_properties *chan_properties,
		struct pm8xxx_adc_chan_result *adc_chan_result)
{
	int32_t rt_r25;
	int32_t offset = chan_properties->adc_graph[ADC_CALIB_ABSOLUTE].offset;

	rt_r25 = adc_code - offset;

	pm8xxx_adc_map_linear(adcmap_ntcg_104ef_104fb,
		ARRAY_SIZE(adcmap_ntcg_104ef_104fb),
		rt_r25, &adc_chan_result->physical);

	return 0;
}
Ejemplo n.º 8
0
/* Scales the ADC code to 0.001 degrees C using the map
 * table for the XO thermistor.
 */
int32_t pm8xxx_adc_tdkntcg_therm(int32_t adc_code,
		const struct pm8xxx_adc_properties *adc_properties,
		const struct pm8xxx_adc_chan_properties *chan_properties,
		struct pm8xxx_adc_chan_result *adc_chan_result)
{
	int64_t xo_thm = 0;

	if (!chan_properties || !chan_properties->offset_gain_numerator ||
		!chan_properties->offset_gain_denominator || !adc_properties
		|| !adc_chan_result)
		return -EINVAL;

	xo_thm = pm8xxx_adc_scale_ratiometric_calib(adc_code,
			adc_properties, chan_properties);
	xo_thm <<= 4;
	pm8xxx_adc_map_linear(adcmap_ntcg_104ef_104fb,
		ARRAY_SIZE(adcmap_ntcg_104ef_104fb),
		xo_thm, &adc_chan_result->physical);

	return 0;
}
/* Scales the ADC code to 0.001 degrees C using the map
 * table for the XO thermistor.
 */
int32_t pm8xxx_adc_tdkntcg_therm(int32_t adc_code,
		const struct pm8xxx_adc_properties *adc_properties,
		const struct pm8xxx_adc_chan_properties *chan_properties,
		struct pm8xxx_adc_chan_result *adc_chan_result)
{
	int64_t xo_thm = 0;
	uint32_t num1 = 0;
	uint32_t num2 = 0;
	uint32_t dnum = 0;
	uint32_t rt_r25 = 0;

	if (!chan_properties || !chan_properties->offset_gain_numerator ||
		!chan_properties->offset_gain_denominator || !adc_properties
		|| !adc_chan_result)
		return -EINVAL;

	xo_thm = pm8xxx_adc_scale_ratiometric_calib(adc_code,
			adc_properties, chan_properties);
	if (xo_thm < 0)
		xo_thm = -xo_thm;

	num1 = xo_thm << 14;
	num2 = (adc_properties->adc_vdd_reference - xo_thm) >> 1;
	dnum = (adc_properties->adc_vdd_reference - xo_thm);

	if (dnum == 0)
		rt_r25 = 0x7FFFFFFF ;
	else
		rt_r25 = (num1 + num2)/dnum ;

	pm8xxx_adc_map_linear(adcmap_ntcg_104ef_104fb,
		ARRAY_SIZE(adcmap_ntcg_104ef_104fb),
		rt_r25, &adc_chan_result->physical);

	return 0;
}