All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] power: max17042_battery: Fix current_{avg,now} hiding with no current sense
@ 2020-11-25  4:44 Sebastian Krzyszkowiak
  2020-11-25  4:46 ` [PATCH 2/4] power: max17042_battery: Improve accuracy of current_now and current_avg readings Sebastian Krzyszkowiak
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sebastian Krzyszkowiak @ 2020-11-25  4:44 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: Geordan Neukum, linux-pm, linux-kernel, kernel

When current sense is disabled, max17042_no_current_sense_psy_desc gets
used which ignores two last properties from the list.

Fixes: 21b01cc879cc ("power: supply: max17042_battery: Add support for the TTE_NOW prop")

Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
---
 drivers/power/supply/max17042_battery.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
index f284547913d6..2e9672fe4df1 100644
--- a/drivers/power/supply/max17042_battery.c
+++ b/drivers/power/supply/max17042_battery.c
@@ -85,9 +85,10 @@ static enum power_supply_property max17042_battery_props[] = {
 	POWER_SUPPLY_PROP_TEMP_MAX,
 	POWER_SUPPLY_PROP_HEALTH,
 	POWER_SUPPLY_PROP_SCOPE,
+	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
+	// these two have to be at the end on the list
 	POWER_SUPPLY_PROP_CURRENT_NOW,
 	POWER_SUPPLY_PROP_CURRENT_AVG,
-	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
 };
 
 static int max17042_get_temperature(struct max17042_chip *chip, int *temp)
-- 
2.29.2




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

* [PATCH 2/4] power: max17042_battery: Improve accuracy of current_now and current_avg readings
  2020-11-25  4:44 [PATCH 1/4] power: max17042_battery: Fix current_{avg,now} hiding with no current sense Sebastian Krzyszkowiak
@ 2020-11-25  4:46 ` Sebastian Krzyszkowiak
  2020-11-25  4:47 ` [PATCH 3/4] power: max17042_battery: Take r_sns value into account in charge_counter Sebastian Krzyszkowiak
  2020-11-25  4:48 ` [PATCH 4/4] power: max17042_battery: Export charge termination current property Sebastian Krzyszkowiak
  2 siblings, 0 replies; 4+ messages in thread
From: Sebastian Krzyszkowiak @ 2020-11-25  4:46 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: Geordan Neukum, linux-pm, linux-kernel, kernel

Dividing 1562500 by r_sns value usually doesn't result in an integer.

Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
---
 drivers/power/supply/max17042_battery.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
index 2e9672fe4df1..86adccb0f32d 100644
--- a/drivers/power/supply/max17042_battery.c
+++ b/drivers/power/supply/max17042_battery.c
@@ -395,8 +395,8 @@ static int max17042_get_property(struct power_supply *psy,
 			if (ret < 0)
 				return ret;
 
-			val->intval = sign_extend32(data, 15);
-			val->intval *= 1562500 / chip->pdata->r_sns;
+			data64 = sign_extend64(data, 15) * 1562500ll;
+			val->intval = div_s64(data64, chip->pdata->r_sns);
 		} else {
 			return -EINVAL;
 		}
@@ -407,8 +407,8 @@ static int max17042_get_property(struct power_supply *psy,
 			if (ret < 0)
 				return ret;
 
-			val->intval = sign_extend32(data, 15);
-			val->intval *= 1562500 / chip->pdata->r_sns;
+			data64 = sign_extend64(data, 15) * 1562500ll;
+			val->intval = div_s64(data64, chip->pdata->r_sns);
 		} else {
 			return -EINVAL;
 		}
-- 
2.29.2




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

* [PATCH 3/4] power: max17042_battery: Take r_sns value into account in charge_counter
  2020-11-25  4:44 [PATCH 1/4] power: max17042_battery: Fix current_{avg,now} hiding with no current sense Sebastian Krzyszkowiak
  2020-11-25  4:46 ` [PATCH 2/4] power: max17042_battery: Improve accuracy of current_now and current_avg readings Sebastian Krzyszkowiak
@ 2020-11-25  4:47 ` Sebastian Krzyszkowiak
  2020-11-25  4:48 ` [PATCH 4/4] power: max17042_battery: Export charge termination current property Sebastian Krzyszkowiak
  2 siblings, 0 replies; 4+ messages in thread
From: Sebastian Krzyszkowiak @ 2020-11-25  4:47 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: Geordan Neukum, linux-pm, linux-kernel, kernel

The default r_sns value was hardcoded there, so let's change it to the
actually configured one.

Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
---
 drivers/power/supply/max17042_battery.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
index 86adccb0f32d..26f6f89eb648 100644
--- a/drivers/power/supply/max17042_battery.c
+++ b/drivers/power/supply/max17042_battery.c
@@ -354,7 +354,8 @@ static int max17042_get_property(struct power_supply *psy,
 		if (ret < 0)
 			return ret;
 
-		val->intval = data * 1000 / 2;
+		data64 = sign_extend64(data, 15) * 5000000ll;
+		val->intval = div_s64(data64, chip->pdata->r_sns);
 		break;
 	case POWER_SUPPLY_PROP_TEMP:
 		ret = max17042_get_temperature(chip, &val->intval);
-- 
2.29.2




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

* [PATCH 4/4] power: max17042_battery: Export charge termination current property
  2020-11-25  4:44 [PATCH 1/4] power: max17042_battery: Fix current_{avg,now} hiding with no current sense Sebastian Krzyszkowiak
  2020-11-25  4:46 ` [PATCH 2/4] power: max17042_battery: Improve accuracy of current_now and current_avg readings Sebastian Krzyszkowiak
  2020-11-25  4:47 ` [PATCH 3/4] power: max17042_battery: Take r_sns value into account in charge_counter Sebastian Krzyszkowiak
@ 2020-11-25  4:48 ` Sebastian Krzyszkowiak
  2 siblings, 0 replies; 4+ messages in thread
From: Sebastian Krzyszkowiak @ 2020-11-25  4:48 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: Geordan Neukum, linux-pm, linux-kernel, kernel

The value is there, so let's export it.

Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
---
 drivers/power/supply/max17042_battery.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
index 26f6f89eb648..79d4b5988360 100644
--- a/drivers/power/supply/max17042_battery.c
+++ b/drivers/power/supply/max17042_battery.c
@@ -78,6 +78,7 @@ static enum power_supply_property max17042_battery_props[] = {
 	POWER_SUPPLY_PROP_CHARGE_FULL,
 	POWER_SUPPLY_PROP_CHARGE_NOW,
 	POWER_SUPPLY_PROP_CHARGE_COUNTER,
+	POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
 	POWER_SUPPLY_PROP_TEMP,
 	POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
 	POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
@@ -414,6 +415,14 @@ static int max17042_get_property(struct power_supply *psy,
 			return -EINVAL;
 		}
 		break;
+	case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
+		ret = regmap_read(map, MAX17042_ICHGTerm, &data);
+		if (ret < 0)
+			return ret;
+
+		data64 = data * 1562500ll;
+		val->intval = div_s64(data64, chip->pdata->r_sns);
+		break;
 	case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
 		ret = regmap_read(map, MAX17042_TTE, &data);
 		if (ret < 0)
-- 
2.29.2




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

end of thread, other threads:[~2020-11-25  4:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25  4:44 [PATCH 1/4] power: max17042_battery: Fix current_{avg,now} hiding with no current sense Sebastian Krzyszkowiak
2020-11-25  4:46 ` [PATCH 2/4] power: max17042_battery: Improve accuracy of current_now and current_avg readings Sebastian Krzyszkowiak
2020-11-25  4:47 ` [PATCH 3/4] power: max17042_battery: Take r_sns value into account in charge_counter Sebastian Krzyszkowiak
2020-11-25  4:48 ` [PATCH 4/4] power: max17042_battery: Export charge termination current property Sebastian Krzyszkowiak

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.