All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] power: supply: max8998_charger: Correct ONLINE and add STATUS props
@ 2020-05-16 22:35 Jonathan Bakker
  2020-06-19 18:03 ` Sebastian Reichel
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Bakker @ 2020-05-16 22:35 UTC (permalink / raw)
  To: sre; +Cc: linux-pm, linux-kernel, Jonathan Bakker

The ONLINE prop should be when the charger is present (ie able to
charge), however, it was for when it was actually charging or not.
Instead, add the STATUS prop to show whether charging is actually
going on or not.

The magic numbers have been ported from a downstream kernel for the
SGH-T959V.

Signed-off-by: Jonathan Bakker <xc-racer2@live.ca>
---
 drivers/power/supply/max8998_charger.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/power/supply/max8998_charger.c b/drivers/power/supply/max8998_charger.c
index 9a926c7c0f22..c26023b19f26 100644
--- a/drivers/power/supply/max8998_charger.c
+++ b/drivers/power/supply/max8998_charger.c
@@ -23,6 +23,7 @@ struct max8998_battery_data {
 static enum power_supply_property max8998_battery_props[] = {
 	POWER_SUPPLY_PROP_PRESENT, /* the presence of battery */
 	POWER_SUPPLY_PROP_ONLINE, /* charger is active or not */
+	POWER_SUPPLY_PROP_STATUS, /* charger is charging/discharging/full */
 };
 
 /* Note that the charger control is done by a current regulator "CHARGER" */
@@ -49,10 +50,28 @@ static int max8998_battery_get_property(struct power_supply *psy,
 		ret = max8998_read_reg(i2c, MAX8998_REG_STATUS2, &reg);
 		if (ret)
 			return ret;
-		if (reg & (1 << 3))
-			val->intval = 0;
-		else
+
+		if (reg & (1 << 5))
 			val->intval = 1;
+		else
+			val->intval = 0;
+
+		break;
+	case POWER_SUPPLY_PROP_STATUS:
+		ret = max8998_read_reg(i2c, MAX8998_REG_STATUS2, &reg);
+		if (ret)
+			return ret;
+
+		if (!(reg & (1 << 5))) {
+			val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
+		} else {
+			if (reg & (1 << 6))
+				val->intval = POWER_SUPPLY_STATUS_FULL;
+			else if (reg & (1 << 3))
+				val->intval = POWER_SUPPLY_STATUS_CHARGING;
+			else
+				val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
+		}
 		break;
 	default:
 		return -EINVAL;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] power: supply: max8998_charger: Correct ONLINE and add STATUS props
  2020-05-16 22:35 [PATCH] power: supply: max8998_charger: Correct ONLINE and add STATUS props Jonathan Bakker
@ 2020-06-19 18:03 ` Sebastian Reichel
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2020-06-19 18:03 UTC (permalink / raw)
  To: Jonathan Bakker; +Cc: linux-pm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2162 bytes --]

Hi,

On Sat, May 16, 2020 at 03:35:44PM -0700, Jonathan Bakker wrote:
> The ONLINE prop should be when the charger is present (ie able to
> charge), however, it was for when it was actually charging or not.
> Instead, add the STATUS prop to show whether charging is actually
> going on or not.
> 
> The magic numbers have been ported from a downstream kernel for the
> SGH-T959V.
> 
> Signed-off-by: Jonathan Bakker <xc-racer2@live.ca>
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/max8998_charger.c | 25 ++++++++++++++++++++++---
>  1 file changed, 22 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/power/supply/max8998_charger.c b/drivers/power/supply/max8998_charger.c
> index 9a926c7c0f22..c26023b19f26 100644
> --- a/drivers/power/supply/max8998_charger.c
> +++ b/drivers/power/supply/max8998_charger.c
> @@ -23,6 +23,7 @@ struct max8998_battery_data {
>  static enum power_supply_property max8998_battery_props[] = {
>  	POWER_SUPPLY_PROP_PRESENT, /* the presence of battery */
>  	POWER_SUPPLY_PROP_ONLINE, /* charger is active or not */
> +	POWER_SUPPLY_PROP_STATUS, /* charger is charging/discharging/full */
>  };
>  
>  /* Note that the charger control is done by a current regulator "CHARGER" */
> @@ -49,10 +50,28 @@ static int max8998_battery_get_property(struct power_supply *psy,
>  		ret = max8998_read_reg(i2c, MAX8998_REG_STATUS2, &reg);
>  		if (ret)
>  			return ret;
> -		if (reg & (1 << 3))
> -			val->intval = 0;
> -		else
> +
> +		if (reg & (1 << 5))
>  			val->intval = 1;
> +		else
> +			val->intval = 0;
> +
> +		break;
> +	case POWER_SUPPLY_PROP_STATUS:
> +		ret = max8998_read_reg(i2c, MAX8998_REG_STATUS2, &reg);
> +		if (ret)
> +			return ret;
> +
> +		if (!(reg & (1 << 5))) {
> +			val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
> +		} else {
> +			if (reg & (1 << 6))
> +				val->intval = POWER_SUPPLY_STATUS_FULL;
> +			else if (reg & (1 << 3))
> +				val->intval = POWER_SUPPLY_STATUS_CHARGING;
> +			else
> +				val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
> +		}
>  		break;
>  	default:
>  		return -EINVAL;
> -- 
> 2.20.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-19 18:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-16 22:35 [PATCH] power: supply: max8998_charger: Correct ONLINE and add STATUS props Jonathan Bakker
2020-06-19 18:03 ` Sebastian Reichel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.