* [PATCH 1/2] usb: common: usb-conn-gpio: Make VBUS supply optional
@ 2020-08-06 16:02 Thierry Reding
2020-08-06 16:02 ` [PATCH 2/2] usb: common: usb-conn-gpio: Print error on failure to get VBUS Thierry Reding
0 siblings, 1 reply; 3+ messages in thread
From: Thierry Reding @ 2020-08-06 16:02 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-tegra
From: Thierry Reding <treding@nvidia.com>
If the connector is the child of a USB port and that USB port already
has a VBUS supply attached to it, it would be redundant to require the
connector to have a VBUS supply. In this case, allow the VBUS supply to
be optional.
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
drivers/usb/common/usb-conn-gpio.c | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/common/usb-conn-gpio.c b/drivers/usb/common/usb-conn-gpio.c
index 7b3a21360d7c..c5b516d327c7 100644
--- a/drivers/usb/common/usb-conn-gpio.c
+++ b/drivers/usb/common/usb-conn-gpio.c
@@ -91,14 +91,14 @@ static void usb_conn_detect_cable(struct work_struct *work)
return;
}
- if (info->last_role == USB_ROLE_HOST)
+ if (info->last_role == USB_ROLE_HOST && info->vbus)
regulator_disable(info->vbus);
ret = usb_role_switch_set_role(info->role_sw, role);
if (ret)
dev_err(info->dev, "failed to set role: %d\n", ret);
- if (role == USB_ROLE_HOST) {
+ if (role == USB_ROLE_HOST && info->vbus) {
ret = regulator_enable(info->vbus);
if (ret)
dev_err(info->dev, "enable vbus regulator failed\n");
@@ -106,8 +106,9 @@ static void usb_conn_detect_cable(struct work_struct *work)
info->last_role = role;
- dev_dbg(info->dev, "vbus regulator is %s\n",
- regulator_is_enabled(info->vbus) ? "enabled" : "disabled");
+ if (info->vbus)
+ dev_dbg(info->dev, "vbus regulator is %s\n",
+ regulator_is_enabled(info->vbus) ? "enabled" : "disabled");
power_supply_changed(info->charger);
}
@@ -156,6 +157,7 @@ static int usb_conn_probe(struct platform_device *pdev)
struct power_supply_config cfg = {
.of_node = dev->of_node,
};
+ bool need_vbus = true;
int ret = 0;
info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
@@ -185,7 +187,23 @@ static int usb_conn_probe(struct platform_device *pdev)
INIT_DELAYED_WORK(&info->dw_det, usb_conn_detect_cable);
- info->vbus = devm_regulator_get(dev, "vbus");
+ /*
+ * If the USB connector is a child of a USB port and that port already provides the VBUS
+ * supply, there's no need for the USB connector to provide it again.
+ */
+ if (dev->parent && dev->parent->of_node) {
+ if (of_find_property(dev->parent->of_node, "vbus-supply", NULL))
+ need_vbus = false;
+ }
+
+ if (!need_vbus) {
+ info->vbus = devm_regulator_get_optional(dev, "vbus");
+ if (PTR_ERR(info->vbus) == -ENODEV)
+ info->vbus = NULL;
+ } else {
+ info->vbus = devm_regulator_get(dev, "vbus");
+ }
+
if (IS_ERR(info->vbus)) {
if (PTR_ERR(info->vbus) != -EPROBE_DEFER)
dev_err(dev, "failed to get vbus\n");
@@ -266,7 +284,7 @@ static int usb_conn_remove(struct platform_device *pdev)
cancel_delayed_work_sync(&info->dw_det);
- if (info->last_role == USB_ROLE_HOST)
+ if (info->last_role == USB_ROLE_HOST && info->vbus)
regulator_disable(info->vbus);
usb_role_switch_put(info->role_sw);
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] usb: common: usb-conn-gpio: Print error on failure to get VBUS
2020-08-06 16:02 [PATCH 1/2] usb: common: usb-conn-gpio: Make VBUS supply optional Thierry Reding
@ 2020-08-06 16:02 ` Thierry Reding
2020-08-08 3:01 ` Michał Mirosław
0 siblings, 1 reply; 3+ messages in thread
From: Thierry Reding @ 2020-08-06 16:02 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-tegra
From: Thierry Reding <treding@nvidia.com>
The exact error that happened trying to get the VBUS supply can be
useful to troubleshoot what's going on.
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
drivers/usb/common/usb-conn-gpio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/common/usb-conn-gpio.c b/drivers/usb/common/usb-conn-gpio.c
index c5b516d327c7..6c4e3a19f42c 100644
--- a/drivers/usb/common/usb-conn-gpio.c
+++ b/drivers/usb/common/usb-conn-gpio.c
@@ -206,7 +206,7 @@ static int usb_conn_probe(struct platform_device *pdev)
if (IS_ERR(info->vbus)) {
if (PTR_ERR(info->vbus) != -EPROBE_DEFER)
- dev_err(dev, "failed to get vbus\n");
+ dev_err(dev, "failed to get vbus: %ld\n", PTR_ERR(info->vbus));
return PTR_ERR(info->vbus);
}
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] usb: common: usb-conn-gpio: Print error on failure to get VBUS
2020-08-06 16:02 ` [PATCH 2/2] usb: common: usb-conn-gpio: Print error on failure to get VBUS Thierry Reding
@ 2020-08-08 3:01 ` Michał Mirosław
0 siblings, 0 replies; 3+ messages in thread
From: Michał Mirosław @ 2020-08-08 3:01 UTC (permalink / raw)
To: Thierry Reding; +Cc: Greg Kroah-Hartman, linux-usb, linux-tegra
On Thu, Aug 06, 2020 at 06:02:48PM +0200, Thierry Reding wrote:
> The exact error that happened trying to get the VBUS supply can be
> useful to troubleshoot what's going on.
[...]
> --- a/drivers/usb/common/usb-conn-gpio.c
> +++ b/drivers/usb/common/usb-conn-gpio.c
> @@ -206,7 +206,7 @@ static int usb_conn_probe(struct platform_device *pdev)
>
> if (IS_ERR(info->vbus)) {
> if (PTR_ERR(info->vbus) != -EPROBE_DEFER)
> - dev_err(dev, "failed to get vbus\n");
> + dev_err(dev, "failed to get vbus: %ld\n", PTR_ERR(info->vbus));
There is now a nice "%pe" format, that can make this even better.
Best Regards,
Michał Mirosław
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-08-08 3:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-06 16:02 [PATCH 1/2] usb: common: usb-conn-gpio: Make VBUS supply optional Thierry Reding
2020-08-06 16:02 ` [PATCH 2/2] usb: common: usb-conn-gpio: Print error on failure to get VBUS Thierry Reding
2020-08-08 3:01 ` Michał Mirosław
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).