usb: pd: Exposing the Peak Current value of Fixed Supplies to user space
authorHeikki Krogerus <heikki.krogerus@linux.intel.com>
Mon, 2 Oct 2023 14:22:40 +0000 (17:22 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 2 Oct 2023 14:38:29 +0000 (16:38 +0200)
Exposing the value of the field as is.

The Peak Current value has to be interpreted as described
in Table 6-10 (Fixed Power Source Peak Current Capability)
of the USB Power Delivery Specification, but that
interpretation will be done in user space, not in kernel.

Suggested-by: Douglas Gilbert <dgilbert@interlog.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20231002142240.2641962-1-heikki.krogerus@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Documentation/ABI/testing/sysfs-class-usb_power_delivery
drivers/usb/typec/pd.c
include/linux/usb/pd.h

index 1bf9d1d7902ce4e93ee296ecc057dbedf9ae25b8..61d233c320ea7f6e2e81890f166c89f65e9b0e84 100644 (file)
@@ -124,6 +124,13 @@ Contact:   Heikki Krogerus <heikki.krogerus@linux.intel.com>
 Description:
                The voltage the supply supports in millivolts.
 
+What:          /sys/class/usb_power_delivery/.../source-capabilities/<position>:fixed_supply/peak_current
+Date:          October 2023
+Contact:       Heikki Krogerus <heikki.krogerus@linux.intel.com>
+Description:
+               This file shows the value of the Fixed Power Source Peak Current
+               Capability field.
+
 What:          /sys/class/usb_power_delivery/.../source-capabilities/<position>:fixed_supply/maximum_current
 Date:          May 2022
 Contact:       Heikki Krogerus <heikki.krogerus@linux.intel.com>
index 8cc66e4467c48f3f6175f612092c661b484a44e0..85d015cdbe1fe1b530720ae34bdddf08dae10929 100644 (file)
@@ -83,14 +83,12 @@ unchunked_extended_messages_supported_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(unchunked_extended_messages_supported);
 
-/*
- * REVISIT: Peak Current requires access also to the RDO.
 static ssize_t
 peak_current_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       ...
+       return sysfs_emit(buf, "%u\n", (to_pdo(dev)->pdo >> PDO_FIXED_PEAK_CURR_SHIFT) & 3);
 }
-*/
+static DEVICE_ATTR_RO(peak_current);
 
 static ssize_t
 fast_role_swap_current_show(struct device *dev, struct device_attribute *attr, char *buf)
@@ -135,7 +133,7 @@ static struct attribute *source_fixed_supply_attrs[] = {
        &dev_attr_usb_communication_capable.attr,
        &dev_attr_dual_role_data.attr,
        &dev_attr_unchunked_extended_messages_supported.attr,
-       /*&dev_attr_peak_current.attr,*/
+       &dev_attr_peak_current.attr,
        &dev_attr_voltage.attr,
        &maximum_current_attr.attr,
        NULL
@@ -144,7 +142,7 @@ static struct attribute *source_fixed_supply_attrs[] = {
 static umode_t fixed_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n)
 {
        if (to_pdo(kobj_to_dev(kobj))->object_position &&
-           /*attr != &dev_attr_peak_current.attr &&*/
+           attr != &dev_attr_peak_current.attr &&
            attr != &dev_attr_voltage.attr &&
            attr != &maximum_current_attr.attr &&
            attr != &operational_current_attr.attr)
index c59fb79a42e8672111c0f146c8d535c04c395777..eb626af0e4e7cfc739842a34736317688ac88187 100644 (file)
@@ -228,6 +228,7 @@ enum pd_pdo_type {
 #define PDO_FIXED_UNCHUNK_EXT          BIT(24) /* Unchunked Extended Message supported (Source) */
 #define PDO_FIXED_FRS_CURR_MASK                (BIT(24) | BIT(23)) /* FR_Swap Current (Sink) */
 #define PDO_FIXED_FRS_CURR_SHIFT       23
+#define PDO_FIXED_PEAK_CURR_SHIFT      20
 #define PDO_FIXED_VOLT_SHIFT           10      /* 50mV units */
 #define PDO_FIXED_CURR_SHIFT           0       /* 10mA units */