Skip to content

Commit 83a4c42

Browse files
jwrdegoedesre
authored andcommitted
power: supply: ucs1002: Adjust ucs1002_set_usb_type() to accept string values
power_supply_sysfs.c accept wrrites of strings to "usb_type" for strings values matching an entry in POWER_SUPPLY_USB_TYPE_TEXT[]. If such a string value is written then the int value passed to ucs1002_set_property() will be an enum power_supply_usb_type value. Before this change ucs1002_set_usb_type() expected the value to be an index into ucs1002_usb_types[]. Adjust ucs1002_set_usb_type() to use the enum value directly so that writing string values works. The list of supported types in ucs1002_usb_types[] is: PD, SDP, DCP, CDP. The [POWER_SUPPLY_USB_TYPE_]SDP, DCP and CDP enum labels have a value of 1, 2 and 3. So userspace selecting SDP, DCP or CDP by writing 1, 2 or 3 will keep working. POWER_SUPPLY_USB_TYPE_PD which is mapped to the ucs1002 dedicated mode however has a value of 6. Before this change writing 0 would select the dedicated mode. To preserve userspace API compatibility also map POWER_SUPPLY_USB_TYPE_UNKNOWN (which is 0) to the dedicated mode. Cc: Enric Balletbo Serra <[email protected]> Cc: Andrey Smirnov <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 0d9af1e commit 83a4c42

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

drivers/power/supply/ucs1002_power.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,13 @@ static int ucs1002_set_usb_type(struct ucs1002_info *info, int val)
308308
{
309309
unsigned int mode;
310310

311-
if (val < 0 || val >= ARRAY_SIZE(ucs1002_usb_types))
312-
return -EINVAL;
313-
314-
switch (ucs1002_usb_types[val]) {
311+
switch (val) {
312+
/*
313+
* POWER_SUPPLY_USB_TYPE_UNKNOWN == 0, map this to dedicated for
314+
* userspace API compatibility with older versions of this driver
315+
* which mapped 0 to dedicated.
316+
*/
317+
case POWER_SUPPLY_USB_TYPE_UNKNOWN:
315318
case POWER_SUPPLY_USB_TYPE_PD:
316319
mode = V_SET_ACTIVE_MODE_DEDICATED;
317320
break;

0 commit comments

Comments
 (0)