[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240831142039.28830-3-hdegoede@redhat.com>
Date: Sat, 31 Aug 2024 16:20:35 +0200
From: Hans de Goede <hdegoede@...hat.com>
To: Sebastian Reichel <sre@...nel.org>,
Thomas Weißschuh <linux@...ssschuh.net>,
MyungJoo Ham <myungjoo.ham@...sung.com>,
Chanwoo Choi <cw00.choi@...sung.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
Vinod Koul <vkoul@...nel.org>,
Kishon Vijay Abraham I <kishon@...nel.org>
Cc: Hans de Goede <hdegoede@...hat.com>,
Enric Balletbo Serra <enric.balletbo@...labora.com>,
Andrey Smirnov <andrew.smirnov@...il.com>,
linux-pm@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-usb@...r.kernel.org,
linux-phy@...ts.infradead.org
Subject: [PATCH 2/6] 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 <enric.balletbo@...labora.com>
Cc: Andrey Smirnov <andrew.smirnov@...il.com>
Signed-off-by: Hans de Goede <hdegoede@...hat.com>
---
drivers/power/supply/ucs1002_power.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/power/supply/ucs1002_power.c b/drivers/power/supply/ucs1002_power.c
index 7970843a4f48..b67d5b03d93e 100644
--- a/drivers/power/supply/ucs1002_power.c
+++ b/drivers/power/supply/ucs1002_power.c
@@ -308,10 +308,13 @@ static int ucs1002_set_usb_type(struct ucs1002_info *info, int val)
{
unsigned int mode;
- if (val < 0 || val >= ARRAY_SIZE(ucs1002_usb_types))
- return -EINVAL;
-
- switch (ucs1002_usb_types[val]) {
+ switch (val) {
+ /*
+ * POWER_SUPPLY_USB_TYPE_UNKNOWN == 0, map this to dedicated for
+ * userspace API compatibility with older versions of this driver
+ * which mapped 0 to dedicated.
+ */
+ case POWER_SUPPLY_USB_TYPE_UNKNOWN:
case POWER_SUPPLY_USB_TYPE_PD:
mode = V_SET_ACTIVE_MODE_DEDICATED;
break;
--
2.46.0
Powered by blists - more mailing lists