[PATCH v2 5/5] power: supply: core: supply battery soc with decimal form

From: Qiwu Huang
Date: Mon Jul 13 2020 - 00:06:10 EST


From: Qiwu Huang <huangqiwu@xxxxxxxxxx>

Broadcast battery soc with decimal form.
soc_decimal is the decimal part of battery soc.
soc_decimal_rate is update frequency of decimal
part of battery soc.
We want to report such as 0.01 to 99.99% to
user space to improve user experience
when do very quick charging.

Signed-off-by: Qiwu Huang <huangqiwu@xxxxxxxxxx>
---
Documentation/ABI/testing/sysfs-class-power | 20 ++++++++++++++++++++
drivers/power/supply/power_supply_sysfs.c | 2 ++
include/linux/power_supply.h | 2 ++
3 files changed, 24 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/ABI/testing/sysfs-class-power
index f4234ba1684a..bcc8ccad8163 100644
--- a/Documentation/ABI/testing/sysfs-class-power
+++ b/Documentation/ABI/testing/sysfs-class-power
@@ -349,6 +349,26 @@ Description:
Access: Read
Valid values: Represented in microvolts

+What: /sys/class/power_supply/<supply_name>/soc_decimal,
+Date: Jul 2020
+Contact: jiangfei1@xxxxxxxxxx
+Description:
+ Broadcast battery soc with decimal form.
+ soc_decimal is the start decimal part of battery soc.
+
+ Access: Read
+ Valid values: 0 - 100
+
+What: /sys/class/power_supply/<supply_name>/soc_decimal_rate,
+Date: Jul 2020
+Contact: jiangfei1@xxxxxxxxxx
+Description:
+ Broadcast battery soc with decimal form.
+ soc_decimal_rate is the decimal part of battery soc update freqency.
+
+ Access: Read
+ Valid values: 0 - 100
+
===== USB Properties =====

What: /sys/class/power_supply/<supply_name>/current_avg
diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
index 81916b6b6ccf..a837addb4f21 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -210,6 +210,8 @@ static struct power_supply_attr power_supply_attrs[] = {
POWER_SUPPLY_ATTR(TX_ADAPTER),
POWER_SUPPLY_ATTR(SIGNAL_STRENGTH),
POWER_SUPPLY_ATTR(REVERSE_CHG_MODE),
+ POWER_SUPPLY_ATTR(SOC_DECIMAL),
+ POWER_SUPPLY_ATTR(SOC_DECIMAL_RATE),
};

static struct attribute *
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 319bf6456867..d1aa5497938e 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -171,6 +171,8 @@ enum power_supply_property {
POWER_SUPPLY_PROP_TX_ADAPTER,
POWER_SUPPLY_PROP_SIGNAL_STRENGTH,
POWER_SUPPLY_PROP_REVERSE_CHG_MODE,
+ POWER_SUPPLY_PROP_SOC_DECIMAL,
+ POWER_SUPPLY_PROP_SOC_DECIMAL_RATE,
};

enum power_supply_type {
--
2.27.0