lkml.org 
[lkml]   [2021]   [Sep]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH 2/3] power: supply: Add support for PDOs props
Date
Add support for reporting Source and Sink Capabilities
Power Data Object (PDO) property. These are reported by USB
Power Delivery (PD) capable power sources.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
---
Documentation/ABI/testing/sysfs-class-power | 30 +++++++++++++++++++++
drivers/power/supply/power_supply_sysfs.c | 18 ++++++++++++-
include/linux/power_supply.h | 5 ++++
3 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/ABI/testing/sysfs-class-power
index ca830c6cd809..90d4198e6dfb 100644
--- a/Documentation/ABI/testing/sysfs-class-power
+++ b/Documentation/ABI/testing/sysfs-class-power
@@ -562,6 +562,36 @@ Description:
"Unknown", "SDP", "DCP", "CDP", "ACA", "C", "PD",
"PD_DRP", "PD_PPS", "BrickID"

+What: /sys/class/power_supply/<supply_name>/source_cap_pdos
+Date: September 2021
+Contact: linux-pm@vger.kernel.org
+Description:
+ Reports the Source Capabilities Power Data Objects (PDO) reported by the USB
+ PD-capable power source. 13 PDOs are listed. PDOs 1-7 represent the Source Caps
+ for devices which only support Standard Power Range (SPR), whereas PDOs 8-13
+ are for Extended Power Range (EPR) capable sources.
+ NOTE: The EPR Source Caps message is a superset of the Source Cap message, so on
+ SPR-only sources, PDOs 8-13 will be 0.
+
+ Access: Read-Only
+
+ Valid values: Represented as a list of 13 32-bit PDO objects in hexadecimal format.
+
+What: /sys/class/power_supply/<supply_name>/sink_cap_pdos
+Date: September 2021
+Contact: linux-pm@vger.kernel.org
+Description:
+ Reports the Sink Capabilities Power Data Objects (PDO) reported by the USB
+ PD-capable power source. 13 PDOs are listed. PDOs 1-7 represent the Sink Caps
+ for devices which only support Standard Power Range (SPR), whereas PDOs 8-13
+ are for Extended Power Range (EPR) capable sinks.
+ NOTE: The EPR Sink Caps message is a superset of the Sink Cap message, so on
+ SPR-only sinks, PDOs 8-13 will be 0.
+
+ Access: Read-Only
+
+ Valid values: Represented as a list of 13 32-bit PDO objects in hexadecimal format.
+
**Device Specific Properties**

What: /sys/class/power/ds2760-battery.*/charge_now
diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
index c3d7cbcd4fad..9d17d3376949 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -211,6 +211,9 @@ static struct power_supply_attr power_supply_attrs[] = {
POWER_SUPPLY_ATTR(MODEL_NAME),
POWER_SUPPLY_ATTR(MANUFACTURER),
POWER_SUPPLY_ATTR(SERIAL_NUMBER),
+ /* Array properties */
+ POWER_SUPPLY_ATTR(SINK_CAP_PDOS),
+ POWER_SUPPLY_ATTR(SOURCE_CAP_PDOS),
};

static struct attribute *
@@ -267,7 +270,11 @@ static ssize_t power_supply_show_property(struct device *dev,
struct power_supply *psy = dev_get_drvdata(dev);
struct power_supply_attr *ps_attr = to_ps_attr(attr);
enum power_supply_property psp = dev_attr_psp(attr);
- union power_supply_propval value;
+ union power_supply_propval value = {
+ .pdos = {0}
+ };
+ size_t count;
+ int i;

if (psp == POWER_SUPPLY_PROP_TYPE) {
value.intval = psy->desc->type;
@@ -299,6 +306,15 @@ static ssize_t power_supply_show_property(struct device *dev,
case POWER_SUPPLY_PROP_MODEL_NAME ... POWER_SUPPLY_PROP_SERIAL_NUMBER:
ret = sprintf(buf, "%s\n", value.strval);
break;
+ case POWER_SUPPLY_PROP_SINK_CAP_PDOS:
+ case POWER_SUPPLY_PROP_SOURCE_CAP_PDOS:
+ ret = 0;
+ for (i = 0; i < PDO_MAX_OBJECTS; i++) {
+ count = sprintf(buf, "0x%08x\n", value.pdos[i]);
+ buf += count;
+ ret += count;
+ }
+ break;
default:
ret = sprintf(buf, "%d\n", value.intval);
}
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 9ca1f120a211..a53c8fa4c1c9 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -17,6 +17,7 @@
#include <linux/leds.h>
#include <linux/spinlock.h>
#include <linux/notifier.h>
+#include <linux/usb/pd.h>

/*
* All voltages, currents, charges, energies, time and temperatures in uV,
@@ -171,6 +172,9 @@ enum power_supply_property {
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
POWER_SUPPLY_PROP_SERIAL_NUMBER,
+ /* Array properties */
+ POWER_SUPPLY_PROP_SINK_CAP_PDOS,
+ POWER_SUPPLY_PROP_SOURCE_CAP_PDOS,
};

enum power_supply_type {
@@ -209,6 +213,7 @@ enum power_supply_notifier_events {
union power_supply_propval {
int intval;
const char *strval;
+ u32 pdos[PDO_MAX_OBJECTS];
};

struct device_node;
--
2.33.0.153.gba50c8fa24-goog
\
 
 \ /
  Last update: 2021-09-02 23:37    [W:0.173 / U:1.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site