aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergii Postulga <x0153364@ti.com>2011-12-20 16:06:26 -0600
committerZiyann <jaraidaniel@gmail.com>2014-10-01 13:00:23 +0200
commitd5e2f4464129c7f26c84c5314405f5e2cd29d550 (patch)
tree193b2ddb21da3772c9a9838e66df6a4ccfa4be2b
parent2cc594db93466e75bc363fce116eac0fd591fd74 (diff)
downloadkernel_samsung_tuna-d5e2f4464129c7f26c84c5314405f5e2cd29d550.zip
kernel_samsung_tuna-d5e2f4464129c7f26c84c5314405f5e2cd29d550.tar.gz
kernel_samsung_tuna-d5e2f4464129c7f26c84c5314405f5e2cd29d550.tar.bz2
POWER: TWL6032_BCI: Add voltage to resistance conversion
This functionality is needed for battery detection logic. GPADC driver for TWL6030 return resistance of battery detection sensor, but for TWL6032 - voltage. It should be converted to resistance value before using. Change-Id: Ic721aa36ef119c23bc3e79c79d145970aac13418 Signed-off-by: Sergii Postulga <x0153364@ti.com>
-rw-r--r--drivers/power/twl6030_bci_battery.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/drivers/power/twl6030_bci_battery.c b/drivers/power/twl6030_bci_battery.c
index d90cde1..a2f8ce0 100644
--- a/drivers/power/twl6030_bci_battery.c
+++ b/drivers/power/twl6030_bci_battery.c
@@ -202,6 +202,9 @@
#define GPADC_CTRL_TEMP2_EN_MONITOR (1 << 6)
#define GPADC_CTRL_ISOURCE_EN (1 << 7)
+#define GPADC_ISOURCE_22uA 22
+#define GPADC_ISOURCE_7uA 7
+
/* TWL6030/6032 BATTERY VOLTAGE GPADC CHANNELS */
#define TWL6030_GPADC_VBAT_CHNL 0x07
@@ -556,6 +559,7 @@ static int twl6030_get_gpadc_conversion(struct twl6030_bci_device_info *di,
static int is_battery_present(struct twl6030_bci_device_info *di)
{
int val;
+ static unsigned int current_src_val;
/*
* Prevent charging on batteries were id resistor is
@@ -564,17 +568,31 @@ static int is_battery_present(struct twl6030_bci_device_info *di)
val = twl6030_get_gpadc_conversion(di, 0);
if (di->features & TWL6032_SUBCLASS) {
- /* A 132K ID resistor will make approx 900mV on
- * channel 0 this is the maximum value of ID
- * PhoenixLite supports. Anything less than this
- * is a valid ID resistor.
+ /*
+ * twl6030_get_gpadc_conversion for
+ * 6030 return resistance, for 6032 - voltage and
+ * it should be converted to resistance before
+ * using.
*/
- if (val > 900)
- return 0;
- } else {
- if (val < 5000)
- return 0;
+ if (!current_src_val) {
+ u8 reg = 0;
+
+ if (twl_i2c_read_u8(TWL_MODULE_MADC, &reg,
+ TWL6030_GPADC_CTRL))
+ pr_err("%s: Error reading TWL6030_GPADC_CTRL\n",
+ __func__);
+
+ current_src_val = (reg & GPADC_CTRL_ISOURCE_EN) ?
+ GPADC_ISOURCE_22uA :
+ GPADC_ISOURCE_7uA;
+ }
+
+ val = (val * 1000) / current_src_val;
}
+
+ if (val < 5000)
+ return 0;
+
return 1;
}