Message ID | 20200315151206.30909-3-spinal.by@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [01/15] power: supply: cpcap-battery: Fix battery full status reporting | expand |
* Arthur Demchenkov <spinal.by@gmail.com> [200315 15:15]: > If we hit battery low once, we should stick on reporting it until the > charger is connected. This way low->counter_uah will be updated > properly, and that will allow us to get more accurate charge_full value. > > Signed-off-by: Arthur Demchenkov <spinal.by@gmail.com> > --- > drivers/power/supply/cpcap-battery.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c > index 52f03a2662a5..8a58ad943960 100644 > --- a/drivers/power/supply/cpcap-battery.c > +++ b/drivers/power/supply/cpcap-battery.c > @@ -421,11 +421,14 @@ static bool cpcap_battery_full(struct cpcap_battery_ddata *ddata) > static bool cpcap_battery_low(struct cpcap_battery_ddata *ddata) > { > struct cpcap_battery_state_data *state = cpcap_battery_latest(ddata); > + static bool is_low; > > - if (state->current_ua && state->voltage <= 3300000) > - return true; > + if (state->current_ua > 0 && (state->voltage <= 3300000 || is_low)) > + is_low = true; > + else > + is_low = false; > > - return false; > + return is_low; > } Please set up bitmask in ddata for unsigned int battery_low:1; instead of using a static variable here. If we ever had two instances of cpcap on the same device the static variable here would not work :) Regards, Tony
Will do. Thanks! > Please set up bitmask in ddata for unsigned int battery_low:1; instead of > using a static variable here. If we ever had two instances of cpcap on > the same device the static variable here would not work :)
diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 52f03a2662a5..8a58ad943960 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -421,11 +421,14 @@ static bool cpcap_battery_full(struct cpcap_battery_ddata *ddata) static bool cpcap_battery_low(struct cpcap_battery_ddata *ddata) { struct cpcap_battery_state_data *state = cpcap_battery_latest(ddata); + static bool is_low; - if (state->current_ua && state->voltage <= 3300000) - return true; + if (state->current_ua > 0 && (state->voltage <= 3300000 || is_low)) + is_low = true; + else + is_low = false; - return false; + return is_low; } static int cpcap_battery_update_status(struct cpcap_battery_ddata *ddata)
If we hit battery low once, we should stick on reporting it until the charger is connected. This way low->counter_uah will be updated properly, and that will allow us to get more accurate charge_full value. Signed-off-by: Arthur Demchenkov <spinal.by@gmail.com> --- drivers/power/supply/cpcap-battery.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)