Example #1
0
static int pmic_get_batt_current(unsigned short *curr)
{
	t_channel channel;
	unsigned short result[8];

	channel = BATTERY_CURRENT;
	CHECK_ERROR(pmic_adc_convert(channel, result));
	*curr = result[0];

	return 0;
}
Example #2
0
static int pmic_get_batt_voltage(unsigned short *voltage)
{
	t_channel channel;
	unsigned short result[8];

	channel = BATTERY_VOLTAGE;
	CHECK_ERROR(pmic_adc_convert(channel, result));
	*voltage = result[0];

	return 0;
}
Example #3
0
/*!
 * This function is retrives the main battery voltage.
 *
 * @param      b_voltage   Output parameter for voltage setting.
 *
 * @return     This function returns PMIC_SUCCESS if successful.
 */
PMIC_STATUS pmic_batt_get_batt_voltage(unsigned short *b_voltage)
{
	t_channel channel;
	unsigned short result[8];

	if (suspend_flag == 1)
		return PMIC_ERROR;
	channel = BATTERY_VOLTAGE;
	CHECK_ERROR(pmic_adc_convert(channel, result));
	*b_voltage = result[0];

	return PMIC_SUCCESS;
}
Example #4
0
/*!
 * This function is retrives the main battery charging current.
 *
 * @param      c_current   Output parameter for charging current setting.
 *
 * @return     This function returns PMIC_SUCCESS if successful.
 */
PMIC_STATUS pmic_batt_get_charge_current(unsigned short *c_current)
{
	t_channel channel;
	unsigned short result[8];

	if (suspend_flag == 1)
		return PMIC_ERROR;

	channel = CHARGE_CURRENT;
	CHECK_ERROR(pmic_adc_convert(channel, result));
	*c_current = result[0];

	return PMIC_SUCCESS;
}
Example #5
0
/*!
 * This function is retrives the main battery temperature.
 *
 * @param      b_temper   Output parameter for temperature setting.
 *
 * @return     This function returns PMIC_SUCCESS if successful.
 */
PMIC_STATUS pmic_batt_get_batt_temperature(unsigned short *b_temper)
{
	t_channel channel;
	unsigned short result[8];

	if (suspend_flag == 1)
		return PMIC_ERROR;

	channel = GEN_PURPOSE_AD5;
	CHECK_ERROR(pmic_adc_convert(channel, result));
	*b_temper = result[0];

	return PMIC_SUCCESS;
}
Example #6
0
static int pmic_get_chg_value(unsigned int *value)
{
	t_channel channel;
	unsigned short result[8], max1 = 0, min1 = 0, max2 = 0, min2 = 0, i;
	unsigned int average = 0, average1 = 0, average2 = 0;

	channel = CHARGE_CURRENT;
	CHECK_ERROR(pmic_adc_convert(channel, result));


	for (i = 0; i < 8; i++) {
		if ((result[i] & 0x200) != 0) {
			result[i] = 0x400 - result[i];
			average2 += result[i];
			if ((max2 == 0) || (max2 < result[i]))
				max2 = result[i];
			if ((min2 == 0) || (min2 > result[i]))
				min2 = result[i];
		} else {
			average1 += result[i];
			if ((max1 == 0) || (max1 < result[i]))
				max1 = result[i];
			if ((min1 == 0) || (min1 > result[i]))
				min1 = result[i];
		}
	}

	if (max1 != 0) {
		average1 -= max1;
		if (max2 != 0)
			average2 -= max2;
		else
			average1 -= min1;
	} else
		average2 -= max2 + min2;

	if (average1 >= average2) {
		average = (average1 - average2) / 6;
		*value = average;
	} else {
		average = (average2 - average1) / 6;
		*value = ((~average) + 1) & 0x3FF;
	}

	return 0;
}
Example #7
0
/*
 * get Battery/DCinput voltage from PMIC
 *  voltage [mV]
 */
static int pmic_get_voltage(t_channel channel, unsigned short *voltage, int *rawval,
			    int force)
{
	unsigned short            result[8];
	struct _volt_input_value *info;
	unsigned long             dif, jif = jiffies;
	int                       rc, volt, isBat = 0;

	if ((channel == BATTERY_VOLTAGE) || (channel == GEN_PURPOSE_AD5)) {
		/*
		 * Battery Voltage
		 */
		info    = &(volt_input_value [0]);
		channel = GEN_PURPOSE_AD5;
		isBat   = 1;
	} else if (channel == GEN_PURPOSE_AD7) {
		/*
		 * DCinput Voltage
		 */
		info = &(volt_input_value [1]);
	} else if (channel == GEN_PURPOSE_AD2) {
		/*
		 * BPSNS Voltage
		 */
		info  = &(volt_input_value [2]);
		isBat = 2;
	} else {
		return -1;
	}

#if 1 /* add 090731 */
	if (g_apm_spi_disable) {
		if (channel == BATTERY_VOLTAGE || channel == GEN_PURPOSE_AD5) {
			if (voltage != 0) {
				*voltage = 8300;
			}
			if (rawval != 0) {
				*rawval = 991;
			}
			return 0;
		} else if (channel == GEN_PURPOSE_AD7) {
			if (voltage != 0) {
				*voltage = 11000;
			}
			if (rawval != 0) {
				*rawval = 1020;
			}
			return 0;
		} else if (channel == GEN_PURPOSE_AD2) {
			if (voltage != 0) {
				*voltage = 3450;
			}
			if (rawval != 0) {
				*rawval = 735;
			}
			return 0;
		} else {
			return -1;
		}
	}
#endif

	/*
	 * check measure timing
	 */
	if (force == 0) {
	if (info->jif <= jif) {
		dif = jif - info->jif;
	} else {
		dif = 0xffffffff - info->jif + jif;
	}
	if (dif < VOLT_MEASURE_INTERVAL) {
		/*
		 * using already measure value
		 */
		if (voltage != 0) {
			*voltage = info->volt;
		}
		if (rawval != 0) {
			*rawval = info->raw;
		}
		return 0;
	}
	}

#ifdef ALWAY_REFON
	rc = pmic_adc_convert(channel, result);
#else
	gpio_refon(1);		// select measurement
	rc = pmic_adc_convert(channel, result);
	gpio_refon(0);		// release measurement
#endif /* ALWAY_REFON */
	if (rc == 0) {
	/*
	 * scale convert(mV)
	 */
	if (isBat == 1) {
		/*
		 * Battery
		 */
			volt = (int)BATT_RAW_TO_VOLT(result[0]);
		} else if (isBat == 2) {
			/*
			 * BPSNS
			 *  4.80V - 1023
			 */
			volt = (int)(result[0] * 4800 / 1023);
	} else {
		/*
		 * DCinput
		 */
		volt = (int)(result[0] * 20398) / 0x3FF;
	}
	info->volt = volt;
	info->raw  = result[0];
		info->jif  = jif;

	if (voltage != 0) {
		*voltage = volt;
	}
	if (rawval != 0) {
		*rawval = result[0];
	}
	}

	return rc;
}