summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKalle Komierowski <kalle.komierowski@gmail.com>2011-06-07 15:43:55 +0200
committersaid m bagheri <ebgheri@steludxu2848.(none)>2011-06-17 13:42:12 +0200
commit729af29d23ea0106d22584d5ea4da30655eb271e (patch)
tree1c60e0e9050e4183ac972592d5220767e325134f
parent757d98bacef2f7f4c8e32a923c8d6a8baf21f8e6 (diff)
mfd: ab8500_gpadc: Raw ADC value converted twice
A bug made the raw ADC value converted to voltage entity twice. Renamed some gpadc function arguments to clarify use. ST-Ericsson ID: 344073 ST-Ericsson Linux next: Tested by ELINWAL ST-Ericsson FOSS-OUT ID: Trivial Change-Id: I53465c2e65c001c23d13929b4bdb59700eb7cf18 Signed-off-by: Kalle Komierowski <kalle.komierowski@gmail.com> Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/24552 Tested-by: Karl KOMIEROWSKI <karl.komierowski@stericsson.com> Reviewed-by: Mattias WALLIN <mattias.wallin@stericsson.com> Reviewed-by: John BECKETT <john.beckett@stericsson.com> Reviewed-by: QATEST
-rw-r--r--drivers/mfd/ab8500-gpadc.c46
-rw-r--r--include/linux/mfd/ab8500/gpadc.h6
2 files changed, 30 insertions, 22 deletions
diff --git a/drivers/mfd/ab8500-gpadc.c b/drivers/mfd/ab8500-gpadc.c
index 82124a51ba9..38fbb7025a8 100644
--- a/drivers/mfd/ab8500-gpadc.c
+++ b/drivers/mfd/ab8500-gpadc.c
@@ -142,12 +142,12 @@ EXPORT_SYMBOL(ab8500_gpadc_get);
/**
* ab8500_gpadc_ad_to_voltage() - Convert a raw ADC value to a voltage
*/
-int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, u8 input,
+int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, u8 channel,
int ad_value)
{
int res;
- switch (input) {
+ switch (channel) {
case MAIN_CHARGER_V:
/* For some reason we don't have calibrated data */
if (!gpadc->cal_data[ADC_INPUT_VMAIN].gain) {
@@ -234,32 +234,41 @@ int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, u8 input,
/**
* ab8500_gpadc_convert() - gpadc conversion
- * @input: analog input to be converted to digital data
+ * @channel: analog channel to be converted to digital data
*
* This function converts the selected analog i/p to digital
* data.
*/
-int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 input)
+int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 channel)
{
- int data;
- int ret;
+ int ad_value;
+ int voltage;
- data = ab8500_gpadc_read_raw(gpadc, input);
- ret = ab8500_gpadc_ad_to_voltage(gpadc, input, data);
- return ret;
+ ad_value = ab8500_gpadc_read_raw(gpadc, channel);
+ if (ad_value < 0) {
+ dev_err(gpadc->dev, "GPADC raw value failed ch: %d\n", channel);
+ return ad_value;
+ }
+
+ voltage = ab8500_gpadc_ad_to_voltage(gpadc, channel, ad_value);
+
+ if (voltage < 0)
+ dev_err(gpadc->dev, "GPADC to voltage conversion failed ch:"
+ " %d AD: 0x%x\n", channel, ad_value);
+
+ return voltage;
}
/**
* ab8500_gpadc_read_raw() - gpadc read
- * @input: analog input to be read
+ * @channel: analog channel to be read
*
* This function obtains the raw ADC value, this then needs
* to be converted by calling ab8500_gpadc_ad_to_voltage()
*/
-int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 input)
+int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel)
{
int ret;
- u16 data = 0;
int looplimit = 0;
u8 val, low_data, high_data;
@@ -294,9 +303,9 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 input)
goto out;
}
- /* Select the input source and set average samples to 16 */
+ /* Select the channel source and set average samples to 16 */
ret = abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC,
- AB8500_GPADC_CTRL2_REG, (input | SW_AVG_16));
+ AB8500_GPADC_CTRL2_REG, (channel | SW_AVG_16));
if (ret < 0) {
dev_err(gpadc->dev,
"gpadc_conversion: set avg samples failed\n");
@@ -308,7 +317,7 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 input)
* charging current sense if it needed, ABB 3.0 needs some special
* treatment too.
*/
- switch (input) {
+ switch (channel) {
case MAIN_CHARGER_C:
case USB_CHARGER_C:
ret = abx500_mask_and_set_register_interruptible(gpadc->dev,
@@ -375,7 +384,6 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 input)
goto out;
}
- data = (high_data << 8) | low_data;
/* Disable GPADC */
ret = abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC,
AB8500_GPADC_CTRL1_REG, DIS_GPADC);
@@ -386,8 +394,8 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 input)
/* Disable VTVout LDO this is required for GPADC */
regulator_disable(gpadc->regu);
mutex_unlock(&gpadc->ab8500_gpadc_lock);
- ret = ab8500_gpadc_ad_to_voltage(gpadc, input, data);
- return ret;
+
+ return (high_data << 8) | low_data;
out:
/*
@@ -401,7 +409,7 @@ out:
regulator_disable(gpadc->regu);
mutex_unlock(&gpadc->ab8500_gpadc_lock);
dev_err(gpadc->dev,
- "gpadc_conversion: Failed to AD convert channel %d\n", input);
+ "gpadc_conversion: Failed to AD convert channel %d\n", channel);
return ret;
}
diff --git a/include/linux/mfd/ab8500/gpadc.h b/include/linux/mfd/ab8500/gpadc.h
index 6688cbc8208..fa706c5a04a 100644
--- a/include/linux/mfd/ab8500/gpadc.h
+++ b/include/linux/mfd/ab8500/gpadc.h
@@ -27,9 +27,9 @@
struct ab8500_gpadc;
struct ab8500_gpadc *ab8500_gpadc_get(void);
-int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 input);
-int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 input);
+int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 channel);
+int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel);
int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc,
- u8 input, int ad_value);
+ u8 channel, int ad_value);
#endif /* _AB8500_GPADC_H */