aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorEugen Mandrenko <ievgen.mandrenko@ti.com>2012-01-24 15:57:14 +0200
committerZiyann <jaraidaniel@gmail.com>2014-10-01 13:00:23 +0200
commite8725de8f975090eec1849e84a00b52aacc06132 (patch)
treee5cb9c667dc032b9c009dfe6dcccfec6758216c7 /drivers/power
parentd5e2f4464129c7f26c84c5314405f5e2cd29d550 (diff)
downloadkernel_samsung_tuna-e8725de8f975090eec1849e84a00b52aacc06132.zip
kernel_samsung_tuna-e8725de8f975090eec1849e84a00b52aacc06132.tar.gz
kernel_samsung_tuna-e8725de8f975090eec1849e84a00b52aacc06132.tar.bz2
OMAP4: twl6030: fix for battery detection
There were two different ways of battery detection: one for TWL6030 and second for TWL6032. ADC returned resistance for TWL6030 but voltage for TWL6032 (channel 0). The threshold 5000 in function is_battery_present() was not correct for TWL6032. But threshold was used for both ways of battery detection and we couldn't change it. The next changes were implemented: ADC returns voltage from channel 0 for TWL6030. The same way of battery detection was implemented for TWL6030 and TWL6032. Threshold was changed. Change-Id: I30a5282c95947edb06a33388d195fc4d17fbd96c Signed-off-by: Sergii Postulga <x0153364@ti.com> Signed-off-by: Eugen Mandrenko <ievgen.mandrenko@ti.com>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/twl6030_bci_battery.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/drivers/power/twl6030_bci_battery.c b/drivers/power/twl6030_bci_battery.c
index a2f8ce0..64602a1 100644
--- a/drivers/power/twl6030_bci_battery.c
+++ b/drivers/power/twl6030_bci_battery.c
@@ -231,6 +231,10 @@
#define STS_HW_CONDITIONS 0x21
#define STS_USB_ID (1 << 2) /* Level status of USB ID */
+#define BATTERY_RESISTOR 10000
+#define SIMULATOR_RESISTOR 5000
+#define BATTERY_DETECT_THRESHOLD ((BATTERY_RESISTOR + SIMULATOR_RESISTOR) / 2)
+
/* To get VBUS input limit from twl6030_usb */
#if CONFIG_TWL6030_USB
extern unsigned int twl6030_get_usb_max_power(struct otg_transceiver *x);
@@ -567,30 +571,28 @@ static int is_battery_present(struct twl6030_bci_device_info *di)
*/
val = twl6030_get_gpadc_conversion(di, 0);
- if (di->features & TWL6032_SUBCLASS) {
- /*
- * twl6030_get_gpadc_conversion for
- * 6030 return resistance, for 6032 - voltage and
- * it should be converted to resistance before
- * using.
- */
- 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__);
+ /*
+ * twl6030_get_gpadc_conversion for
+ * 6030 return resistance, for 6032 - voltage and
+ * it should be converted to resistance before
+ * using.
+ */
+ if (!current_src_val) {
+ u8 reg = 0;
- current_src_val = (reg & GPADC_CTRL_ISOURCE_EN) ?
- GPADC_ISOURCE_22uA :
- GPADC_ISOURCE_7uA;
- }
+ if (twl_i2c_read_u8(TWL_MODULE_MADC, &reg,
+ TWL6030_GPADC_CTRL))
+ pr_err("%s: Error reading TWL6030_GPADC_CTRL\n",
+ __func__);
- val = (val * 1000) / current_src_val;
+ current_src_val = (reg & GPADC_CTRL_ISOURCE_EN) ?
+ GPADC_ISOURCE_22uA :
+ GPADC_ISOURCE_7uA;
}
- if (val < 5000)
+ val = (val * 1000) / current_src_val;
+
+ if (val < BATTERY_DETECT_THRESHOLD)
return 0;
return 1;