Message ID | 20230928105944.1718897-1-heikki.krogerus@linux.intel.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [v2] usb: pd: Exposing the Peak Current value of Fixed Supplies to user space | expand |
On Thu, Sep 28, 2023 at 01:59:44PM +0300, Heikki Krogerus wrote: > 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> > Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> > --- > v2: Include ABI documentation. > > --- > .../testing/sysfs-class-usb_power_delivery | 31 +++++++++++++++++++ > drivers/usb/typec/pd.c | 10 +++--- > include/linux/usb/pd.h | 1 + > 3 files changed, 36 insertions(+), 6 deletions(-) > > diff --git a/Documentation/ABI/testing/sysfs-class-usb_power_delivery b/Documentation/ABI/testing/sysfs-class-usb_power_delivery > index 1bf9d1d7902c..4b0708af4a41 100644 > --- a/Documentation/ABI/testing/sysfs-class-usb_power_delivery > +++ b/Documentation/ABI/testing/sysfs-class-usb_power_delivery > @@ -124,6 +124,37 @@ 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: > + Fixed Power Source Peak Current Capability > + (IOC: Negotiated current as defined in IEC 63002): > + == =========================================================== > + 0 Peak current equals IOC (default) > + 1 Overload Capabilities: > + 1. Peak current equals 150% IOC for 1ms @ 5% duty cycle > + (low current equals 97% IOC for 19ms) > + 2. Peak current equals 125% IOC for 2ms @ 10% duty cycle > + (low current equals 97% IOC for 18ms) > + 3. Peak current equals 110% IOC for 10ms @ 50% duty cycle > + (low current equals 90% IOC for 10ms) > + 2 Overload Capabilities: > + 1. Peak current equals 200% IOC for 1ms @ 5% duty cycle > + (low current equals 95% IOC for 19ms) > + 2. Peak current equals 150% IOC for 2ms @ 10% duty cycle > + (low current equals 94% IOC for 18ms) > + 3. Peak current equals 125% IOC for 10ms @ 50% duty cycle > + (low current equals 75% IOC for 10ms) > + 3 Overload Capabilities: > + 1. Peak current equals 200% IOC for 1ms @ 5% duty cycle > + (low current equals 95% IOC for 19ms) > + 2. Peak current equals 175% IOC for 2ms @ 10% duty cycle > + (low current equals 92% IOC for 18ms) > + 3. Peak current equals 150% IOC for 10ms @ 50% duty cycle > + (low current equals 50% IOC for 10ms) > + == =========================================================== > + > What: /sys/class/usb_power_delivery/.../source-capabilities/<position>:fixed_supply/maximum_current > Date: May 2022 > Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> > diff --git a/drivers/usb/typec/pd.c b/drivers/usb/typec/pd.c > index 8cc66e4467c4..85d015cdbe1f 100644 > --- a/drivers/usb/typec/pd.c > +++ b/drivers/usb/typec/pd.c > @@ -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) > diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h > index c59fb79a42e8..eb626af0e4e7 100644 > --- a/include/linux/usb/pd.h > +++ b/include/linux/usb/pd.h > @@ -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 */ > > -- > 2.40.1 >
Hi Heikki, kernel test robot noticed the following build warnings: [auto build test WARNING on usb/usb-testing] [also build test WARNING on usb/usb-next usb/usb-linus linus/master v6.6-rc3 next-20230929] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Heikki-Krogerus/usb-pd-Exposing-the-Peak-Current-value-of-Fixed-Supplies-to-user-space/20230928-190152 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing patch link: https://lore.kernel.org/r/20230928105944.1718897-1-heikki.krogerus%40linux.intel.com patch subject: [PATCH v2] usb: pd: Exposing the Peak Current value of Fixed Supplies to user space reproduce: (https://download.01.org/0day-ci/archive/20231002/202310020520.759dWkR0-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202310020520.759dWkR0-lkp@intel.com/ All warnings (new ones prefixed by >>): >> Documentation/ABI/testing/sysfs-class-usb_power_delivery:128: WARNING: Unexpected indentation. >> Documentation/ABI/testing/sysfs-class-usb_power_delivery:128: WARNING: Block quote ends without a blank line; unexpected unindent. >> Documentation/ABI/testing/sysfs-class-usb_power_delivery:128: WARNING: Definition list ends without a blank line; unexpected unindent. >> Documentation/ABI/testing/sysfs-class-usb_power_delivery:128: WARNING: Malformed table. >> Documentation/ABI/testing/sysfs-class-usb_power_delivery:1: WARNING: undefined label: abi_sys_class_usb_power_delivery_version (if the link has no caption the label must precede a section header) >> Documentation/ABI/testing/sysfs-class-usb_power_delivery:1: WARNING: undefined label: abi_sys_class_usb_power_delivery_source_capabilities_position_variable_supply_maximum_current (if the link has no caption the label must precede a section header) >> Documentation/ABI/testing/sysfs-class-usb_power_delivery:1: WARNING: undefined label: abi_sys_class_usb_power_delivery_source_capabilities_position_programmable_supply_pps_power_limited (if the link has no caption the label must precede a section header) vim +128 Documentation/ABI/testing/sysfs-class-usb_power_delivery > 1 What: /sys/class/usb_power_delivery 2 Date: May 2022 3 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 4 Description: 5 Directory for USB Power Delivery devices. 6 7 What: /sys/class/usb_power_delivery/.../revision 8 Date: May 2022 9 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 10 Description: 11 File showing the USB Power Delivery Specification Revision used 12 in communication. 13 14 What: /sys/class/usb_power_delivery/.../version 15 Date: May 2022 16 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 17 Description: 18 This is an optional attribute file showing the version of the 19 specific revision of the USB Power Delivery Specification. In 20 most cases the specification version is not known and the file 21 is not available. 22 23 What: /sys/class/usb_power_delivery/.../source-capabilities 24 Date: May 2022 25 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 26 Description: 27 The source capabilities message "Source_Capabilities" contains a 28 set of Power Data Objects (PDO), each representing a type of 29 power supply. The order of the PDO objects is defined in the USB 30 Power Delivery Specification. Each PDO - power supply - will 31 have its own device, and the PDO device name will start with the 32 object position number as the first character followed by the 33 power supply type name (":" as delimiter). 34 35 /sys/class/usb_power_delivery/.../source_capabilities/<position>:<type> 36 37 What: /sys/class/usb_power_delivery/.../sink-capabilities 38 Date: May 2022 39 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 40 Description: 41 The sink capability message "Sink_Capabilities" contains a set 42 of Power Data Objects (PDO) just like with source capabilities, 43 but instead of describing the power capabilities, these objects 44 describe the power requirements. 45 46 The order of the objects in the sink capability message is the 47 same as with the source capabilities message. 48 49 Fixed Supplies 50 51 What: /sys/class/usb_power_delivery/.../<capability>/<position>:fixed_supply 52 Date: May 2022 53 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 54 Description: 55 Devices containing the attributes (the bit fields) defined for 56 Fixed Supplies. 57 58 The device "1:fixed_supply" is special. USB Power Delivery 59 Specification dictates that the first PDO (at object position 60 1), and the only mandatory PDO, is always the vSafe5V Fixed 61 Supply Object. vSafe5V Object has additional fields defined for 62 it that the other Fixed Supply Objects do not have and that are 63 related to the USB capabilities rather than power capabilities. 64 65 What: /sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/dual_role_power 66 Date: May 2022 67 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 68 Description: 69 This file contains boolean value that tells does the device 70 support both source and sink power roles. 71 72 What: /sys/class/usb_power_delivery/.../source-capabilities/1:fixed_supply/usb_suspend_supported 73 Date: May 2022 74 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 75 Description: 76 This file shows the value of the USB Suspend Supported bit in 77 vSafe5V Fixed Supply Object. If the bit is set then the device 78 will follow the USB 2.0 and USB 3.2 rules for suspend and 79 resume. 80 81 What: /sys/class/usb_power_delivery/.../sink-capabilities/1:fixed_supply/higher_capability 82 Date: February 2023 83 Contact: Saranya Gopal <saranya.gopal@linux.intel.com> 84 Description: 85 This file shows the value of the Higher capability bit in 86 vsafe5V Fixed Supply Object. If the bit is set, then the sink 87 needs more than vsafe5V(eg. 12 V) to provide full functionality. 88 Valid values: 0, 1 89 90 What: /sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/unconstrained_power 91 Date: May 2022 92 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 93 Description: 94 This file shows the value of the Unconstrained Power bit in 95 vSafe5V Fixed Supply Object. The bit is set when an external 96 source of power, powerful enough to power the entire system on 97 its own, is available for the device. 98 99 What: /sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/usb_communication_capable 100 Date: May 2022 101 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 102 Description: 103 This file shows the value of the USB Communication Capable bit in 104 vSafe5V Fixed Supply Object. 105 106 What: /sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/dual_role_data 107 Date: May 2022 108 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 109 Description: 110 This file shows the value of the Dual-Role Data bit in vSafe5V 111 Fixed Supply Object. Dual role data means ability act as both 112 USB host and USB device. 113 114 What: /sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/unchunked_extended_messages_supported 115 Date: May 2022 116 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 117 Description: 118 This file shows the value of the Unchunked Extended Messages 119 Supported bit in vSafe5V Fixed Supply Object. 120 121 What: /sys/class/usb_power_delivery/.../<capability>/<position>:fixed_supply/voltage 122 Date: May 2022 123 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 124 Description: 125 The voltage the supply supports in millivolts. 126 127 What: /sys/class/usb_power_delivery/.../source-capabilities/<position>:fixed_supply/peak_current > 128 Date: October 2023 129 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> 130 Description: 131 Fixed Power Source Peak Current Capability 132 (IOC: Negotiated current as defined in IEC 63002): 133 == =========================================================== 134 0 Peak current equals IOC (default) 135 1 Overload Capabilities: 136 1. Peak current equals 150% IOC for 1ms @ 5% duty cycle 137 (low current equals 97% IOC for 19ms) 138 2. Peak current equals 125% IOC for 2ms @ 10% duty cycle 139 (low current equals 97% IOC for 18ms) 140 3. Peak current equals 110% IOC for 10ms @ 50% duty cycle 141 (low current equals 90% IOC for 10ms) 142 2 Overload Capabilities: 143 1. Peak current equals 200% IOC for 1ms @ 5% duty cycle 144 (low current equals 95% IOC for 19ms) 145 2. Peak current equals 150% IOC for 2ms @ 10% duty cycle 146 (low current equals 94% IOC for 18ms) 147 3. Peak current equals 125% IOC for 10ms @ 50% duty cycle 148 (low current equals 75% IOC for 10ms) 149 3 Overload Capabilities: 150 1. Peak current equals 200% IOC for 1ms @ 5% duty cycle 151 (low current equals 95% IOC for 19ms) 152 2. Peak current equals 175% IOC for 2ms @ 10% duty cycle 153 (low current equals 92% IOC for 18ms) 154 3. Peak current equals 150% IOC for 10ms @ 50% duty cycle 155 (low current equals 50% IOC for 10ms) 156 == =========================================================== 157
On Thu, Sep 28, 2023 at 01:59:44PM +0300, Heikki Krogerus wrote: > 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> > Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> > --- > v2: Include ABI documentation. Looks like the documentation build tool doesn't like the documentation format :(
diff --git a/Documentation/ABI/testing/sysfs-class-usb_power_delivery b/Documentation/ABI/testing/sysfs-class-usb_power_delivery index 1bf9d1d7902c..4b0708af4a41 100644 --- a/Documentation/ABI/testing/sysfs-class-usb_power_delivery +++ b/Documentation/ABI/testing/sysfs-class-usb_power_delivery @@ -124,6 +124,37 @@ 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: + Fixed Power Source Peak Current Capability + (IOC: Negotiated current as defined in IEC 63002): + == =========================================================== + 0 Peak current equals IOC (default) + 1 Overload Capabilities: + 1. Peak current equals 150% IOC for 1ms @ 5% duty cycle + (low current equals 97% IOC for 19ms) + 2. Peak current equals 125% IOC for 2ms @ 10% duty cycle + (low current equals 97% IOC for 18ms) + 3. Peak current equals 110% IOC for 10ms @ 50% duty cycle + (low current equals 90% IOC for 10ms) + 2 Overload Capabilities: + 1. Peak current equals 200% IOC for 1ms @ 5% duty cycle + (low current equals 95% IOC for 19ms) + 2. Peak current equals 150% IOC for 2ms @ 10% duty cycle + (low current equals 94% IOC for 18ms) + 3. Peak current equals 125% IOC for 10ms @ 50% duty cycle + (low current equals 75% IOC for 10ms) + 3 Overload Capabilities: + 1. Peak current equals 200% IOC for 1ms @ 5% duty cycle + (low current equals 95% IOC for 19ms) + 2. Peak current equals 175% IOC for 2ms @ 10% duty cycle + (low current equals 92% IOC for 18ms) + 3. Peak current equals 150% IOC for 10ms @ 50% duty cycle + (low current equals 50% IOC for 10ms) + == =========================================================== + What: /sys/class/usb_power_delivery/.../source-capabilities/<position>:fixed_supply/maximum_current Date: May 2022 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com> diff --git a/drivers/usb/typec/pd.c b/drivers/usb/typec/pd.c index 8cc66e4467c4..85d015cdbe1f 100644 --- a/drivers/usb/typec/pd.c +++ b/drivers/usb/typec/pd.c @@ -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) diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h index c59fb79a42e8..eb626af0e4e7 100644 --- a/include/linux/usb/pd.h +++ b/include/linux/usb/pd.h @@ -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 */
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> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> --- v2: Include ABI documentation. --- .../testing/sysfs-class-usb_power_delivery | 31 +++++++++++++++++++ drivers/usb/typec/pd.c | 10 +++--- include/linux/usb/pd.h | 1 + 3 files changed, 36 insertions(+), 6 deletions(-)