Commit bb8b9a98 authored by Tony Lindgren's avatar Tony Lindgren Committed by Sebastian Reichel

power: supply: cpcap-battery: Use charger status for battery full detection

We now get battery full notification from cpcap-charger, so let's use that
for battery full status and charger disconnect.

Note that any current based battery full detection we have tried earlier is
flakey as it won't account for example for CPU load increasing the battery
current. Anyways, if current based battery full detection is also still
needed, we can reconsider adding it in addition to the charger status based
detection.

Cc: Arthur Demchenkov <spinal.by@gmail.com>
Cc: Carl Philipp Klemm <philipp@uvos.xyz>
Cc: Merlijn Wajer <merlijn@wizzup.org>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 2071236b
...@@ -135,6 +135,7 @@ struct cpcap_battery_ddata { ...@@ -135,6 +135,7 @@ struct cpcap_battery_ddata {
atomic_t active; atomic_t active;
int status; int status;
u16 vendor; u16 vendor;
unsigned int is_full:1;
}; };
#define CPCAP_NO_BATTERY -400 #define CPCAP_NO_BATTERY -400
...@@ -371,15 +372,62 @@ static int cpcap_battery_cc_get_avg_current(struct cpcap_battery_ddata *ddata) ...@@ -371,15 +372,62 @@ static int cpcap_battery_cc_get_avg_current(struct cpcap_battery_ddata *ddata)
return cpcap_battery_cc_to_ua(ddata, sample, acc, offset); return cpcap_battery_cc_to_ua(ddata, sample, acc, offset);
} }
static int cpcap_battery_get_charger_status(struct cpcap_battery_ddata *ddata,
int *val)
{
union power_supply_propval prop;
struct power_supply *charger;
int error;
charger = power_supply_get_by_name("usb");
if (!charger)
return -ENODEV;
error = power_supply_get_property(charger, POWER_SUPPLY_PROP_STATUS,
&prop);
if (error)
*val = POWER_SUPPLY_STATUS_UNKNOWN;
else
*val = prop.intval;
power_supply_put(charger);
return error;
}
static bool cpcap_battery_full(struct cpcap_battery_ddata *ddata) static bool cpcap_battery_full(struct cpcap_battery_ddata *ddata)
{ {
struct cpcap_battery_state_data *state = cpcap_battery_latest(ddata); struct cpcap_battery_state_data *state = cpcap_battery_latest(ddata);
unsigned int vfull;
int error, val;
error = cpcap_battery_get_charger_status(ddata, &val);
if (!error) {
switch (val) {
case POWER_SUPPLY_STATUS_DISCHARGING:
dev_dbg(ddata->dev, "charger disconnected\n");
ddata->is_full = 0;
break;
case POWER_SUPPLY_STATUS_FULL:
dev_dbg(ddata->dev, "charger full status\n");
ddata->is_full = 1;
break;
default:
break;
}
}
/*
* The full battery voltage here can be inaccurate, it's used just to
* filter out any trickle charging events. We clear the is_full status
* on charger disconnect above anyways.
*/
vfull = ddata->config.bat.constant_charge_voltage_max_uv - 120000;
if (state->voltage >= if (ddata->is_full && state->voltage < vfull)
(ddata->config.bat.constant_charge_voltage_max_uv - 18000)) ddata->is_full = 0;
return true;
return false; return ddata->is_full;
} }
static int cpcap_battery_update_status(struct cpcap_battery_ddata *ddata) static int cpcap_battery_update_status(struct cpcap_battery_ddata *ddata)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment