[03/15] power: supply: cpcap-battery: Fix battery low status reporting
diff mbox series

Message ID 20200315151206.30909-3-spinal.by@gmail.com
State New
Headers show
Series
  • [01/15] power: supply: cpcap-battery: Fix battery full status reporting
Related show

Commit Message

Arthur D. March 15, 2020, 3:11 p.m. UTC
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(-)

Comments

Tony Lindgren March 21, 2020, 2:47 p.m. UTC | #1
* 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
Arthur D. March 21, 2020, 9:40 p.m. UTC | #2
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 :)

Patch
diff mbox series

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)