Message ID | 20240831142039.28830-2-hdegoede@redhat.com |
---|---|
State | Accepted |
Commit | 0d9af1e1c93b6a89f3fb6dcbafa5bc78892cb94f |
Headers | show |
Series | power: supply: Change usb_types from an array into a bitmask | expand |
On Sat, Aug 31, 2024 at 04:20:34PM +0200, Hans de Goede wrote: > According to Documentation/ABI/testing/sysfs-class-power the "usb_type" > property is Read-Only. > > For power-supplies which consume USB power such as battery charger chips, > this is correct. > > But the UCS1002 USB Port Power Controller driver which is a driver > for a chip which is a power-source for USB-A charging ports "usb_type" > is actually writable to configure the type of USB charger emulated > by the USB-A port. Ick, crazy hardware :( > > Adjust the docs and the power_supply_sysfs.c code to adjust for this > new writeable use of "usb_type": > > 1. Update Documentation/ABI/testing/sysfs-class-power to document that > "usb_type" may be writable > > 2. Change the power_supply_attr type in power_supply_sysfs.c from > POWER_SUPPLY_ATTR() into POWER_SUPPLY_ENUM_ATTR() so that the various > usb_type string values from POWER_SUPPLY_TYPE_TEXT[] such as e.g. > "SDP" and "USB_PD" can be written to the "usb_type" attribute instead > of only accepting integer values. > > Cc: Enric Balletbo Serra <enric.balletbo@collabora.com> > Cc: Andrey Smirnov <andrew.smirnov@gmail.com> > Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/ABI/testing/sysfs-class-power index 84973f66b42c..45180b62d426 100644 --- a/Documentation/ABI/testing/sysfs-class-power +++ b/Documentation/ABI/testing/sysfs-class-power @@ -608,7 +608,12 @@ Description: the supply, for example it can show if USB-PD capable source is attached. - Access: Read-Only + Access: For power-supplies which consume USB power such + as battery charger chips, this indicates the type of + the connected USB power source and is Read-Only. + + For power-supplies which act as a USB power-source such as + e.g. the UCS1002 USB Port Power Controller this is writable. Valid values: "Unknown", "SDP", "DCP", "CDP", "ACA", "C", "PD", diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c index 3e63d165b2f7..ff7e423edd57 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -209,7 +209,7 @@ static struct power_supply_attr power_supply_attrs[] = { POWER_SUPPLY_ATTR(TIME_TO_FULL_NOW), POWER_SUPPLY_ATTR(TIME_TO_FULL_AVG), POWER_SUPPLY_ENUM_ATTR(TYPE), - POWER_SUPPLY_ATTR(USB_TYPE), + POWER_SUPPLY_ENUM_ATTR(USB_TYPE), POWER_SUPPLY_ENUM_ATTR(SCOPE), POWER_SUPPLY_ATTR(PRECHARGE_CURRENT), POWER_SUPPLY_ATTR(CHARGE_TERM_CURRENT),
According to Documentation/ABI/testing/sysfs-class-power the "usb_type" property is Read-Only. For power-supplies which consume USB power such as battery charger chips, this is correct. But the UCS1002 USB Port Power Controller driver which is a driver for a chip which is a power-source for USB-A charging ports "usb_type" is actually writable to configure the type of USB charger emulated by the USB-A port. Adjust the docs and the power_supply_sysfs.c code to adjust for this new writeable use of "usb_type": 1. Update Documentation/ABI/testing/sysfs-class-power to document that "usb_type" may be writable 2. Change the power_supply_attr type in power_supply_sysfs.c from POWER_SUPPLY_ATTR() into POWER_SUPPLY_ENUM_ATTR() so that the various usb_type string values from POWER_SUPPLY_TYPE_TEXT[] such as e.g. "SDP" and "USB_PD" can be written to the "usb_type" attribute instead of only accepting integer values. Cc: Enric Balletbo Serra <enric.balletbo@collabora.com> Cc: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> --- Documentation/ABI/testing/sysfs-class-power | 7 ++++++- drivers/power/supply/power_supply_sysfs.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-)