Skip to contentSkip to conversation

modify power_supply usage in dwc3

PATCH New Ray Chi 1 participant 3 messages Mar 27, 2021

Subsystems (3)
lore
Share & tools
lore

Ray Chi

author
#0 lore raw

cover modify power_supply usage in dwc3

Currently, the power_supply usage in dwc3 is wrong. In addition, there is a build error when CONFIG_POWER_SUPPLY is not enabled. Therefore, these patches will fix the problems.

Ray Chi (2):
usb: dwc3: gadget: modify the scale in vbus_draw callback
power: supply: Fix build error when CONFIG_POWER_SUPPLY is not
enabled.

 drivers/usb/dwc3/gadget.c    | 2 +-
 include/linux/power_supply.h | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
Signature · 1 line
2.31.0.291.g576ba9dcdaf-goog
author
#1 lore raw

PATCH 1/2 usb: dwc3: gadget: modify the scale in vbus_draw callback

Currently, vbus_draw callback used wrong scale for power_supply. The unit of power supply should be uA.
Therefore, this patch will fix this problem.

Fixes 99288de36020 ("usb: dwc3: add an alternate path in vbus_draw callback")
---
 drivers/usb/dwc3/gadget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc3/gadget.c +1 -1
index e1442fc763e1..8a361f07e045 100644
@@ -2536,7 +2536,7 @@ static int dwc3_gadget_vbus_draw(struct usb_gadget *g, unsigned int mA)
 	if (!dwc->usb_psy)
 		return -EOPNOTSUPP;
 
-	val.intval = mA;
+	val.intval = 1000 * mA;
 	ret = power_supply_set_property(dwc->usb_psy, POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, &val);
 
 	return ret;
Signature · 1 line
2.31.0.291.g576ba9dcdaf-goog
author
#2 lore raw

PATCH 2/2 power: supply: Fix build error when CONFIG_POWER_SUPPLY is not enabled.

In reply to Ray Chi

The build error happens when CONFIG_POWER_SUPPLY is not enabled.

h8300-linux-ld: drivers/usb/dwc3/gadget.o: in function `.L59':

Quoted 1 line
Quoted 1 line

gadget.c:(.text+0x655): undefined reference to `power_supply_set_property'

Fixes 99288de36020 ("usb: dwc3: add an alternate path in vbus_draw callback")
---
 include/linux/power_supply.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/linux/power_supply.h +7 -0
index 81a55e974feb..b495b4374cd0 100644
@@ -426,9 +426,16 @@ static inline int power_supply_is_system_supplied(void) { return -ENOSYS; }
 extern int power_supply_get_property(struct power_supply *psy,
 			    enum power_supply_property psp,
 			    union power_supply_propval *val);
+#if IS_ENABLED(CONFIG_POWER_SUPPLY)
 extern int power_supply_set_property(struct power_supply *psy,
 			    enum power_supply_property psp,
 			    const union power_supply_propval *val);
+#else
+static inline int power_supply_set_property(struct power_supply *psy,
+			    enum power_supply_property psp,
+			    const union power_supply_propval *val)
+{ return 0; }
+#endif
 extern int power_supply_property_is_writeable(struct power_supply *psy,
 					enum power_supply_property psp);
 extern void power_supply_external_power_changed(struct power_supply *psy);
Signature · 1 line
2.31.0.291.g576ba9dcdaf-goog