From 6350dd138086bb74518118b28724783a01e20015 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=AE=B8=E7=9B=9B=E9=A3=9E?= Date: Mon, 12 Jan 2015 11:43:27 +0800 Subject: [PATCH] rk818-battery: fix POWER_SUPPLY_PROP_PRESENT val error, and add Li-ion battery check MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: 许盛飞 --- drivers/power/rk818_battery.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/power/rk818_battery.c b/drivers/power/rk818_battery.c index 68d66e38be66..1aa7c5a645a3 100644 --- a/drivers/power/rk818_battery.c +++ b/drivers/power/rk818_battery.c @@ -870,6 +870,14 @@ static int _get_average_current(struct battery_info *di) } +static bool is_bat_exist(struct battery_info *di) +{ + u8 buf; + + battery_read(di->rk818, SUP_STS_REG, &buf, 1); + return (buf & 0x80) ? true : false; +} + static bool _is_first_poweron(struct battery_info *di) { u8 buf; @@ -993,6 +1001,7 @@ static int rk_battery_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { + u8 buf; struct battery_info *di = to_device_info(psy); switch (psp) { @@ -1005,9 +1014,12 @@ static int rk_battery_get_property(struct power_supply *psy, break; case POWER_SUPPLY_PROP_PRESENT: - val->intval = val->intval <= 0 ? 0 : 1; + /*val->intval = val->intval <= 0 ? 0 : 1;*/ + battery_read(di->rk818, SUP_STS_REG, &buf, 1); + val->intval = (buf >> 7); /*bit7:BAT_EX*/ break; + case POWER_SUPPLY_PROP_CAPACITY: val->intval = di->real_soc; break; @@ -2870,6 +2882,10 @@ static int battery_probe(struct platform_device *pdev) platform_set_drvdata(pdev, di); battery_info_init(di, chip); + if (!is_bat_exist(di)) { + dev_err(&pdev->dev, "could not find Li-ion battery!\n"); + return -ENODEV; + } fg_init(di); wake_lock_init(&di->resume_wake_lock, WAKE_LOCK_SUSPEND, "resume_charging"); -- 2.34.1