aboutsummaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
authorJohan Palsson <johan.palsson@stericsson.com>2011-02-03 11:24:59 +0100
committerJonas ABERG <jonas.aberg@stericsson.com>2011-02-07 10:24:30 +0100
commit27646ade4b39f17c2040b836a9304cab2280939a (patch)
treef6d233c1c4219ac58820d572c360ac6fd03c6527 /drivers/power
parentea0c5fc93a9679b4152e322b5672103a00ed41fb (diff)
misc: ab8500_gpadc: Use calibrated ADC values from OTP
Three ADC channels are calibrated in factory and the parameters are stored in OTP. These parameters are now read and used in the GPADC driver. Also the function ab8500_gpadc_convert now returns a voltage instead of a raw AD-value ST-Ericsson ID: WP322611 ST-Ericsson FOSS-OUT ID: Trivial Change-Id: I600faf8b30122a6dd95048c1059b33623f37aeeb Signed-off-by: Johan Palsson <johan.palsson@stericsson.com> Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/14191 Reviewed-by: Mattias WALLIN <mattias.wallin@stericsson.com>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/ab8500_btemp.c26
-rw-r--r--drivers/power/ab8500_charger.c40
-rw-r--r--drivers/power/ab8500_fg.c19
3 files changed, 25 insertions, 60 deletions
diff --git a/drivers/power/ab8500_btemp.c b/drivers/power/ab8500_btemp.c
index 8acd5e598ff..ac1a318d7c1 100644
--- a/drivers/power/ab8500_btemp.c
+++ b/drivers/power/ab8500_btemp.c
@@ -155,23 +155,18 @@ static int ab8500_btemp_batctrl_volt_to_res(struct ab8500_btemp *di,
*/
static int ab8500_btemp_read_batctrl_voltage(struct ab8500_btemp *di)
{
- int data, vbs;
+ int vbtemp;
static int prev;
- data = ab8500_gpadc_convert(di->parent->gpadc, BAT_CTRL);
- if (data < 0) {
+ vbtemp = ab8500_gpadc_convert(di->parent->gpadc, BAT_CTRL);
+ if (vbtemp < 0) {
dev_err(di->dev,
"%s gpadc conversion failed, using previous value",
__func__);
return prev;
}
- /*
- * The range BAT_CTRL channel of the GPADC is
- * 0 to 1350mV, and 1 LSB is worth 1.32 mV
- */
- vbs = (1350 * data) / ADC_RESOLUTION;
- prev = vbs;
- return vbs;
+ prev = vbtemp;
+ return vbtemp;
}
/**
@@ -401,7 +396,6 @@ static int ab8500_btemp_res_to_temp(struct ab8500_btemp *di,
*/
static int ab8500_btemp_measure_temp(struct ab8500_btemp *di)
{
- int data;
int temp;
static int prev;
int rbat, rntc, vntc;
@@ -427,21 +421,17 @@ static int ab8500_btemp_measure_temp(struct ab8500_btemp *di)
di->bat->bat_type[t].r_to_t_tbl,
di->bat->bat_type[t].n_temp_tbl_elements, rbat);
} else {
- data = ab8500_gpadc_convert(di->parent->gpadc, BTEMP_BALL);
- if (data < 0) {
+ vntc = ab8500_gpadc_convert(di->parent->gpadc, BTEMP_BALL);
+ if (vntc < 0) {
dev_err(di->dev,
"%s gpadc conversion failed,"
" using previous value\n", __func__);
return prev;
}
/*
- * First convert the ADC value to a voltage. This is the voltage
- * over the NTC placed on the PCB
- * 1350 mV will give maximum output value on the ADC on BTEMP
- * channel. The PCB NTC is sourced from VTVOUT via a 230kOhm
+ * The PCB NTC is sourced from VTVOUT via a 230kOhm
* resistor.
*/
- vntc = data * 1350 / ADC_RESOLUTION;
rntc = 230000 * vntc / (VTVOUT_V - vntc);
temp = ab8500_btemp_res_to_temp(di, di->bat->pcb_ntc,
diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c
index e7ebd92e7a3..a91ca8ac0db 100644
--- a/drivers/power/ab8500_charger.c
+++ b/drivers/power/ab8500_charger.c
@@ -228,30 +228,22 @@ static enum power_supply_property ab8500_charger_usb_props[] = {
*/
static int ab8500_charger_get_ac_voltage(struct ab8500_charger *di)
{
- int data;
+ int vch;
static int prev;
/* Only measure voltage if the charger is connected */
if (di->ac.charger_connected) {
- data = ab8500_gpadc_convert(di->parent->gpadc, MAIN_CHARGER_V);
- if (data < 0) {
+ vch = ab8500_gpadc_convert(di->parent->gpadc, MAIN_CHARGER_V);
+ if (vch < 0) {
dev_err(di->dev, "%s gpadc conversion failed, "
"using previous value\n", __func__);
return prev;
}
-
- /*
- * conversion from RAW val to voltage
- * MAIN charger range from 0 to 20.03V. The resolution
- * of the ADC is 10 bits
- * Figures taken from AB8500 spec, UM0836
- */
- data = (ADC_CH_MAIN_MAX * data) / ADC_RESOLUTION;
- prev = data;
+ prev = vch;
} else {
- data = 0;
+ vch = 0;
}
- return data;
+ return vch;
}
/**
@@ -292,30 +284,22 @@ static int ab8500_charger_ac_cv(struct ab8500_charger *di)
*/
static int ab8500_charger_get_vbus_voltage(struct ab8500_charger *di)
{
- int data;
+ int vch;
static int prev;
/* Only measure voltage if the charger is connected */
if (di->usb.charger_connected) {
- data = ab8500_gpadc_convert(di->parent->gpadc, VBUS_V);
- if (data < 0) {
+ vch = ab8500_gpadc_convert(di->parent->gpadc, VBUS_V);
+ if (vch < 0) {
dev_err(di->dev, "%s gpadc conversion failed, "
"using previous value\n", __func__);
return prev;
}
-
- /*
- * conversion from RAW data to voltage
- * VBUS range from 0 to 20.03V. The resolution of the ADC
- * is 10 bits
- * Figures taken from AB8500 spec, UM0836
- */
- data = (ADC_CH_VBUS_MAX * data) / ADC_RESOLUTION;
- prev = data;
+ prev = vch;
} else {
- data = 0;
+ vch = 0;
}
- return data;
+ return vch;
}
/**
diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c
index 2e3b8f3bb30..e82aa31fbd2 100644
--- a/drivers/power/ab8500_fg.c
+++ b/drivers/power/ab8500_fg.c
@@ -522,28 +522,19 @@ exit:
*/
static int ab8500_fg_bat_voltage(struct ab8500_fg *di)
{
- int data;
+ int vbat;
static int prev;
- data = ab8500_gpadc_convert(di->parent->gpadc, MAIN_BAT_V);
- if (data < 0) {
+ vbat = ab8500_gpadc_convert(di->parent->gpadc, MAIN_BAT_V);
+ if (vbat < 0) {
dev_err(di->dev,
"%s gpadc conversion failed, using previous value\n",
__func__);
return prev;
}
- /*
- * conversion from RAW value to voltage
- * VBAT range from 2.3 to 4.8V. The resolution of the ADC
- * is 10 bits
- * Figures taken from AB8500 spec, UM0836
- */
- data = ADC_CH_VBAT_MIN +
- (((ADC_CH_VBAT_MAX - ADC_CH_VBAT_MIN) * data) / ADC_RESOLUTION);
-
- prev = data;
- return data;
+ prev = vbat;
+ return vbat;
}
/**