From: Mehmet Fide <mehmet.fide@gmail.com>
To: Marek Vasut <marek.vasut+usb@mailbox.org>
Cc: Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>,
Fabio Estevam <festevam@gmail.com>,
Stefan Agner <stefan@agner.ch>,
Francesco Dolcini <francesco@dolcini.it>,
u-boot@lists.u-boot-project.org, mehmet.fide@screeningeagle.com
Subject: [PATCH v8 07/10] usb: ehci-vf: request the ID detect gpio through the device
Date: Thu, 22 Oct 2026 09:08:57 +0200 [thread overview]
Message-ID: <20261022070900.616265-8-mehmet.fide@gmail.com> (raw)
In-Reply-To: <20261022070900.616265-1-mehmet.fide@gmail.com>
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
The ID detect gpio of an OTG port is requested through the flat node,
the result is never checked and the gpio is never freed: a bad gpio
description or a failing read silently leaves the port in device mode,
and every probe after a "usb stop" fails to request the pin again and
reads it only because the failed request left the descriptor pointing
at it.
Request it through the device in the probe and fail the probe on any
error but a missing property, which keeps the port in device mode as
before. Free it in a remove hook and on the failing probe paths, so
that the probe after a "usb stop" can request it again.
The flat tree access was the last user of the global data pointer:
drop it.
Reviewed-by: Marek Vasut <marek.vasut+usb@mailbox.org>
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
Notes:
Changes in v8:
- Reviewed-by from Marek
Changes in v7:
- new patch, split out of the previous one on Marek's review
- gpio_request_by_name() and dm_gpio_get_value() are checked; only a
missing property is tolerated
- the gpio is requested in the probe and freed in a new remove hook and
on the failing probe paths, so the probe after a "usb stop" can
request it again
drivers/usb/host/ehci-vf.c | 61 +++++++++++++++++++++++++-------------
1 file changed, 40 insertions(+), 21 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c
index 90840cea92d..52ec83fc485 100644
--- a/drivers/usb/host/ehci-vf.c
+++ b/drivers/usb/host/ehci-vf.c
@@ -10,7 +10,6 @@
#include <log.h>
#include <usb.h>
#include <errno.h>
-#include <asm/global_data.h>
#include <linux/compiler.h>
#include <asm/io.h>
#include <asm-generic/gpio.h>
@@ -37,8 +36,6 @@
#define UCMD_RUN_STOP (1 << 0) /* controller run/stop */
#define UCMD_RESET (1 << 1) /* controller reset */
-DECLARE_GLOBAL_DATA_PTR;
-
static const unsigned phy_bases[] = {
USB_PHY0_BASE_ADDR,
USB_PHY1_BASE_ADDR,
@@ -162,7 +159,6 @@ struct ehci_vf_priv_data {
static int vf_usb_of_to_plat(struct udevice *dev)
{
struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- int node = dev_of_offset(dev);
fdt_addr_t phy_addr;
ofnode phy_node;
int i;
@@ -207,18 +203,6 @@ static int vf_usb_of_to_plat(struct udevice *dev)
return -EINVAL;
}
- if (priv->dr_mode == USB_DR_MODE_OTG) {
- gpio_request_by_name_nodev(offset_to_ofnode(node),
- "fsl,cdet-gpio", 0, &priv->cdet_gpio,
- GPIOD_IS_IN);
- if (dm_gpio_is_valid(&priv->cdet_gpio)) {
- if (dm_gpio_get_value(&priv->cdet_gpio))
- priv->init_type = USB_INIT_DEVICE;
- else
- priv->init_type = USB_INIT_HOST;
- }
- }
-
return 0;
}
@@ -258,12 +242,27 @@ static int ehci_usb_probe(struct udevice *dev)
struct ehci_hcor *hcor;
int ret;
+ if (priv->dr_mode == USB_DR_MODE_OTG) {
+ ret = gpio_request_by_name(dev, "fsl,cdet-gpio", 0,
+ &priv->cdet_gpio, GPIOD_IS_IN);
+ if (ret && ret != -ENOENT)
+ return ret;
+ if (!ret) {
+ ret = dm_gpio_get_value(&priv->cdet_gpio);
+ if (ret < 0)
+ goto err_gpio;
+ priv->init_type = ret ? USB_INIT_DEVICE : USB_INIT_HOST;
+ }
+ }
+
ret = ehci_vf_common_init(ehci, priv->portnr);
if (ret)
- return ret;
+ goto err_gpio;
- if (priv->init_type != plat->init_type)
- return -ENODEV;
+ if (priv->init_type != plat->init_type) {
+ ret = -ENODEV;
+ goto err_gpio;
+ }
if (priv->init_type == USB_INIT_HOST) {
setbits_le32(&ehci->usbmode, CM_HOST);
@@ -277,7 +276,17 @@ static int ehci_usb_probe(struct udevice *dev)
hcor = (struct ehci_hcor *)((uint32_t)hccr +
HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
- return ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0, priv->init_type);
+ ret = ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0, priv->init_type);
+ if (ret)
+ goto err_gpio;
+
+ return 0;
+
+err_gpio:
+ if (dm_gpio_is_valid(&priv->cdet_gpio))
+ dm_gpio_free(dev, &priv->cdet_gpio);
+
+ return ret;
}
static const struct udevice_id vf_usb_ids[] = {
@@ -285,12 +294,22 @@ static const struct udevice_id vf_usb_ids[] = {
{ }
};
+static int ehci_usb_remove(struct udevice *dev)
+{
+ struct ehci_vf_priv_data *priv = dev_get_priv(dev);
+
+ if (dm_gpio_is_valid(&priv->cdet_gpio))
+ dm_gpio_free(dev, &priv->cdet_gpio);
+
+ return ehci_deregister(dev);
+}
+
U_BOOT_DRIVER(ehci_vf) = {
.name = "ehci_vf",
.id = UCLASS_USB,
.of_match = vf_usb_ids,
.probe = ehci_usb_probe,
- .remove = ehci_deregister,
+ .remove = ehci_usb_remove,
.ops = &ehci_usb_ops,
.of_to_plat = vf_usb_of_to_plat,
.plat_auto = sizeof(struct usb_plat),
--
2.55.0
next prev parent reply other threads:[~2026-10-22 7:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 7:08 [PATCH v8 00/10] usb: ehci-vf: make the USB host port usable Mehmet Fide
2026-10-22 7:08 ` [PATCH v8 01/10] fdtdec: match an alias to its stem only when the number follows it Mehmet Fide
2026-10-22 7:08 ` [PATCH v8 02/10] usb: ehci-vf: take the controller index from the device tree Mehmet Fide
2026-10-22 7:08 ` [PATCH v8 03/10] usb: ehci-vf: remove the code path for a build without DM_USB Mehmet Fide
2026-10-22 7:08 ` [PATCH v8 04/10] usb: ehci-vf: drop the empty bind hook Mehmet Fide
2026-10-22 7:08 ` [PATCH v8 05/10] dm: core: add ofnode_get_alias_seq() Mehmet Fide
2026-10-22 7:08 ` [PATCH v8 06/10] usb: ehci-vf: use usb_get_dr_mode() Mehmet Fide
2026-10-22 8:38 ` Marek Vasut
2026-10-22 7:08 ` Mehmet Fide [this message]
2026-10-22 7:08 ` [PATCH v8 08/10] usb: ehci-vf: take the register bases from the device tree Mehmet Fide
2026-10-22 10:52 ` Krzysztof Kozlowski
2026-10-22 11:51 ` Marek Vasut
2026-10-22 12:20 ` Mehmet Fide
2026-10-22 12:52 ` Marek Vasut
2026-10-22 12:07 ` Mehmet Fide
2026-10-22 7:08 ` [PATCH v8 09/10] usb: ehci-vf: sort the includes Mehmet Fide
2026-10-22 8:38 ` Marek Vasut
2026-10-22 7:09 ` [PATCH v8 10/10] usb: ehci-vf: enable the vbus supply of the port Mehmet Fide
2026-10-22 8:39 ` Marek Vasut
2026-10-22 13:31 ` Mehmet Fide
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261022070900.616265-8-mehmet.fide@gmail.com \
--to=mehmet.fide@gmail.com \
--cc=festevam@gmail.com \
--cc=francesco@dolcini.it \
--cc=marek.vasut+usb@mailbox.org \
--cc=mehmet.fide@screeningeagle.com \
--cc=sjg@chromium.org \
--cc=stefan@agner.ch \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.