diff mbox series

[v4,3/5] power: supply: core: Add POWER_SUPPLY_PROP_*CELL* entries

Message ID 20240415081305.316107-3-mike.looijmans@topic.nl (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series [v4,1/5] dt-bindings: power: Extend battery chemistry with capacitor | expand

Commit Message

Mike Looijmans April 15, 2024, 8:13 a.m. UTC
For multi-cell chargers (or stacks of capacitors), allow to report the
number of cells in series and the voltage of each cell.

Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
---

(no changes since v1)

 Documentation/ABI/testing/sysfs-class-power | 51 +++++++++++++++++++++
 Documentation/power/power_supply_class.rst  |  7 +++
 drivers/power/supply/power_supply_sysfs.c   |  7 +++
 include/linux/power_supply.h                |  7 +++
 4 files changed, 72 insertions(+)
diff mbox series

Patch

diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/ABI/testing/sysfs-class-power
index 1f6a04a17c81..f5b194ad61b3 100644
--- a/Documentation/ABI/testing/sysfs-class-power
+++ b/Documentation/ABI/testing/sysfs-class-power
@@ -516,6 +516,57 @@  Description:
 			Integer > 0: representing full cycles
 			Integer = 0: cycle_count info is not available
 
+What:		/sys/class/power_supply/<supply_name>/number_of_serial_cells
+Date:		April 2024
+Contact:	linux-pm@vger.kernel.org
+Description:
+		If the energy storage is composed of multiple cells in series,
+		this provides the number of stacked cells. Parallel cells aren't
+		considered here.
+
+		Access: Read
+
+		Valid values:
+			Integer > 0: number of cells
+			Integer = 0: info is not available
+
+What:		/sys/class/power_supply/<supply_name>/cell1_voltage_now
+Date:		April 2024
+Contact:	linux-pm@vger.kernel.org
+Description:
+		Reports an instant, single cell voltage reading. The voltage is
+		measured across the cell. The battery reports voltages for up to
+		'number_of_serial_cells' cells, in cell2_voltage_now and so on.
+
+		Access: Read
+
+		Valid values: Represented in microvolts
+
+What:		/sys/class/power_supply/<supply_name>/cell_voltage_max
+Date:		April 2024
+Contact:	linux-pm@vger.kernel.org
+Description:
+		Maximum allowed voltage for a single cell. This value is shared
+		across all cells in the range 1 to 'number_of_serial_cells'.
+		Typically used to trigger an alert for userspace.
+
+		Access: Read, Write
+
+		Valid values: Represented in microvolts
+
+What:		/sys/class/power_supply/<supply_name>/cell_voltage_min
+Date:		April 2024
+Contact:	linux-pm@vger.kernel.org
+Description:
+		Minimum allowed voltage for a single cell. This value is shared
+		across all cells in the range 1 to 'number_of_serial_cells'.
+		Typically used to trigger an alert for userspace.
+
+		Access: Read, Write
+
+		Valid values: Represented in microvolts
+
+
 **USB Properties**
 
 What:		/sys/class/power_supply/<supply_name>/input_current_limit
diff --git a/Documentation/power/power_supply_class.rst b/Documentation/power/power_supply_class.rst
index da8e275a14ff..42110cbbea4a 100644
--- a/Documentation/power/power_supply_class.rst
+++ b/Documentation/power/power_supply_class.rst
@@ -213,6 +213,13 @@  TIME_TO_FULL
   seconds left for battery to be considered full
   (i.e. while battery is charging)
 
+NUMBER_OF_SERIAL_CELLS
+  If the energy storage is composed of multiple cells in series, this provides
+  the number of stacked cells. Parallel cells aren't considered here.
+CELLn_VOLTAGE
+  voltage measured of the n-th cell in the stack
+CELL_VOLTAGE
+  single cell voltage when the cells share the same value (usually MIN or MAX)
 
 Battery <-> external power supply interaction
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
index 9d8540ce1f7e..4ea6b556f3fd 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -218,6 +218,13 @@  static struct power_supply_attr power_supply_attrs[] = {
 	POWER_SUPPLY_ATTR(MANUFACTURE_YEAR),
 	POWER_SUPPLY_ATTR(MANUFACTURE_MONTH),
 	POWER_SUPPLY_ATTR(MANUFACTURE_DAY),
+	POWER_SUPPLY_ATTR(NUMBER_OF_SERIAL_CELLS),
+	POWER_SUPPLY_ATTR(CELL1_VOLTAGE_NOW),
+	POWER_SUPPLY_ATTR(CELL2_VOLTAGE_NOW),
+	POWER_SUPPLY_ATTR(CELL3_VOLTAGE_NOW),
+	POWER_SUPPLY_ATTR(CELL4_VOLTAGE_NOW),
+	POWER_SUPPLY_ATTR(CELL_VOLTAGE_MIN),
+	POWER_SUPPLY_ATTR(CELL_VOLTAGE_MAX),
 	/* Properties of type `const char *' */
 	POWER_SUPPLY_ATTR(MODEL_NAME),
 	POWER_SUPPLY_ATTR(MANUFACTURER),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index af5a4e700881..3c208dff8af8 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -171,6 +171,13 @@  enum power_supply_property {
 	POWER_SUPPLY_PROP_MANUFACTURE_YEAR,
 	POWER_SUPPLY_PROP_MANUFACTURE_MONTH,
 	POWER_SUPPLY_PROP_MANUFACTURE_DAY,
+	POWER_SUPPLY_PROP_NUMBER_OF_SERIAL_CELLS,
+	POWER_SUPPLY_PROP_CELL1_VOLTAGE_NOW,
+	POWER_SUPPLY_PROP_CELL2_VOLTAGE_NOW,
+	POWER_SUPPLY_PROP_CELL3_VOLTAGE_NOW,
+	POWER_SUPPLY_PROP_CELL4_VOLTAGE_NOW,
+	POWER_SUPPLY_PROP_CELL_VOLTAGE_MIN,
+	POWER_SUPPLY_PROP_CELL_VOLTAGE_MAX,
 	/* Properties of type `const char *' */
 	POWER_SUPPLY_PROP_MODEL_NAME,
 	POWER_SUPPLY_PROP_MANUFACTURER,