aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/supply
diff options
context:
space:
mode:
authorTony Lindgren <tony@atomide.com>2019-10-16 15:30:05 -0700
committerSebastian Reichel <sre@kernel.org>2019-10-20 20:26:17 +0200
commit50fc99f83f102c60a9429f451594019a6a978103 (patch)
tree65fe146110e5133ded9b4e1c57fee9b6fddec8aa /drivers/power/supply
parentpower: supply: cpcap-battery: Check voltage before orderly_poweroff (diff)
downloadlinux-dev-50fc99f83f102c60a9429f451594019a6a978103.tar.xz
linux-dev-50fc99f83f102c60a9429f451594019a6a978103.zip
power: supply: cpcap-charger: Improve battery detection
We are currently using a wrong ADC range for the battery detection. The ADC returns the battery temperature if connected. Cc: Merlijn Wajer <merlijn@wizzup.org> Cc: Pavel Machek <pavel@ucw.cz> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power/supply')
-rw-r--r--drivers/power/supply/cpcap-charger.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/power/supply/cpcap-charger.c b/drivers/power/supply/cpcap-charger.c
index 88bbab6e62f0..a04354c8f1e3 100644
--- a/drivers/power/supply/cpcap-charger.c
+++ b/drivers/power/supply/cpcap-charger.c
@@ -176,20 +176,21 @@ static enum power_supply_property cpcap_charger_props[] = {
POWER_SUPPLY_PROP_CURRENT_NOW,
};
+/* No battery always shows temperature of -40000 */
static bool cpcap_charger_battery_found(struct cpcap_charger_ddata *ddata)
{
struct iio_channel *channel;
- int error, value;
+ int error, temperature;
channel = ddata->channels[CPCAP_CHARGER_IIO_BATTDET];
- error = iio_read_channel_raw(channel, &value);
+ error = iio_read_channel_processed(channel, &temperature);
if (error < 0) {
dev_warn(ddata->dev, "%s failed: %i\n", __func__, error);
return false;
}
- return value == 1;
+ return temperature > -20000 && temperature < 60000;
}
static int cpcap_charger_get_charge_voltage(struct cpcap_charger_ddata *ddata)