Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: pd: Exposing the Peak Current value of Fixed Supplies to user space

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>

authored by

Heikki Krogerus and committed by
Greg Kroah-Hartman
568441b7 b447e9ef

+12 -6
+7
Documentation/ABI/testing/sysfs-class-usb_power_delivery
··· 124 124 Description: 125 125 The voltage the supply supports in millivolts. 126 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 + This file shows the value of the Fixed Power Source Peak Current 132 + Capability field. 133 + 127 134 What: /sys/class/usb_power_delivery/.../source-capabilities/<position>:fixed_supply/maximum_current 128 135 Date: May 2022 129 136 Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com>
+4 -6
drivers/usb/typec/pd.c
··· 83 83 } 84 84 static DEVICE_ATTR_RO(unchunked_extended_messages_supported); 85 85 86 - /* 87 - * REVISIT: Peak Current requires access also to the RDO. 88 86 static ssize_t 89 87 peak_current_show(struct device *dev, struct device_attribute *attr, char *buf) 90 88 { 91 - ... 89 + return sysfs_emit(buf, "%u\n", (to_pdo(dev)->pdo >> PDO_FIXED_PEAK_CURR_SHIFT) & 3); 92 90 } 93 - */ 91 + static DEVICE_ATTR_RO(peak_current); 94 92 95 93 static ssize_t 96 94 fast_role_swap_current_show(struct device *dev, struct device_attribute *attr, char *buf) ··· 133 135 &dev_attr_usb_communication_capable.attr, 134 136 &dev_attr_dual_role_data.attr, 135 137 &dev_attr_unchunked_extended_messages_supported.attr, 136 - /*&dev_attr_peak_current.attr,*/ 138 + &dev_attr_peak_current.attr, 137 139 &dev_attr_voltage.attr, 138 140 &maximum_current_attr.attr, 139 141 NULL ··· 142 144 static umode_t fixed_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n) 143 145 { 144 146 if (to_pdo(kobj_to_dev(kobj))->object_position && 145 - /*attr != &dev_attr_peak_current.attr &&*/ 147 + attr != &dev_attr_peak_current.attr && 146 148 attr != &dev_attr_voltage.attr && 147 149 attr != &maximum_current_attr.attr && 148 150 attr != &operational_current_attr.attr)
+1
include/linux/usb/pd.h
··· 228 228 #define PDO_FIXED_UNCHUNK_EXT BIT(24) /* Unchunked Extended Message supported (Source) */ 229 229 #define PDO_FIXED_FRS_CURR_MASK (BIT(24) | BIT(23)) /* FR_Swap Current (Sink) */ 230 230 #define PDO_FIXED_FRS_CURR_SHIFT 23 231 + #define PDO_FIXED_PEAK_CURR_SHIFT 20 231 232 #define PDO_FIXED_VOLT_SHIFT 10 /* 50mV units */ 232 233 #define PDO_FIXED_CURR_SHIFT 0 /* 10mA units */ 233 234