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 08/10] usb: ehci-vf: take the register bases from the device tree
Date: Thu, 22 Oct 2026 09:08:58 +0200 [thread overview]
Message-ID: <20261022070900.616265-9-mehmet.fide@gmail.com> (raw)
In-Reply-To: <20261022070900.616265-1-mehmet.fide@gmail.com>
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
The driver keeps its own tables of PHY and controller base addresses
and reaches the anatop block through a hardcoded address, although the
device tree describes all three: the controller points at its PHY and
usbmisc nodes, and the PHY at its anatop.
Read them from there and drop the tables: the two phandles of the
controller node through dev_read_phandle_with_args(), the anatop one
from the PHY node. The helpers take the private data instead of single
addresses. The port number stays only for the choice between PLL3 and
PLL7, which the device tree does not express, and now comes from the
usbphy alias of the PHY node.
The usbmisc node already starts at the non-core registers, so the
driver no longer adds an offset to reach them.
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:
- portnr keeps its u32 type, Marek's review; the alias lookup writes a
local int
- adapted to the split of the previous patch, no other code change
Changes in v6:
- the phandles of the controller node are read with
dev_read_phandle_with_args()
- the helpers take the private data, not single addresses
- the dr_mode enum this patch used to move is gone, see the new patch
before this one
Changes in v5:
- the PHY node is looked up with the "usbphy" stem: the uclass name
"usb" found usbphy0 only through the prefix match of the flat lookup
Changes in v4:
- rebased on next
- dropped two comments that repeated the commit message
- reworded the commit message and took the note on the previous version
out of it
drivers/usb/host/ehci-vf.c | 135 ++++++++++++++++++++-----------------
1 file changed, 74 insertions(+), 61 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c
index 52ec83fc485..d2263a1224f 100644
--- a/drivers/usb/host/ehci-vf.c
+++ b/drivers/usb/host/ehci-vf.c
@@ -20,13 +20,10 @@
#include <asm/mach-imx/regs-usbphy.h>
#include <linux/delay.h>
#include <usb/ehci-ci.h>
-#include <fdtdec.h>
#include <linux/usb/otg.h>
#include "ehci.h"
-#define USB_NC_REG_OFFSET 0x00000800
-
#define ANADIG_PLL_CTRL_EN_USB_CLKS (1 << 6)
#define UCTRL_OVER_CUR_POL (1 << 8) /* OTG Polarity of Overcurrent */
@@ -36,31 +33,29 @@
#define UCMD_RUN_STOP (1 << 0) /* controller run/stop */
#define UCMD_RESET (1 << 1) /* controller reset */
-static const unsigned phy_bases[] = {
- USB_PHY0_BASE_ADDR,
- USB_PHY1_BASE_ADDR,
-};
-
-static const unsigned nc_reg_bases[] = {
- USBC0_BASE_ADDR,
- USBC1_BASE_ADDR,
+struct ehci_vf_priv_data {
+ struct ehci_ctrl ctrl;
+ struct usb_ehci *ehci;
+ struct gpio_desc cdet_gpio;
+ enum usb_init_type init_type;
+ enum usb_dr_mode dr_mode;
+ struct anadig_reg __iomem *anatop_addr;
+ void __iomem *phy_addr;
+ void __iomem *misc_addr;
+ u32 portnr;
};
-static void usb_internal_phy_clock_gate(int index)
+static void usb_internal_phy_clock_gate(struct ehci_vf_priv_data *priv)
{
- void __iomem *phy_reg;
-
- phy_reg = (void __iomem *)phy_bases[index];
- clrbits_le32(phy_reg + USBPHY_CTRL, USBPHY_CTRL_CLKGATE);
+ clrbits_le32(priv->phy_addr + USBPHY_CTRL, USBPHY_CTRL_CLKGATE);
}
-static void usb_power_config(int index)
+static void usb_power_config(struct ehci_vf_priv_data *priv)
{
- struct anadig_reg __iomem *anadig =
- (struct anadig_reg __iomem *)ANADIG_BASE_ADDR;
+ struct anadig_reg __iomem *anadig = priv->anatop_addr;
void __iomem *pll_ctrl;
- switch (index) {
+ switch (priv->portnr) {
case 0:
pll_ctrl = &anadig->pll3_ctrl;
clrbits_le32(pll_ctrl, ANADIG_PLL3_CTRL_BYPASS);
@@ -80,15 +75,14 @@ static void usb_power_config(int index)
}
}
-static void usb_phy_enable(int index, struct usb_ehci *ehci)
+static void usb_phy_enable(struct ehci_vf_priv_data *priv)
{
- void __iomem *phy_reg;
+ void __iomem *phy_reg = priv->phy_addr;
void __iomem *phy_ctrl;
void __iomem *usb_cmd;
- phy_reg = (void __iomem *)phy_bases[index];
phy_ctrl = (void __iomem *)(phy_reg + USBPHY_CTRL);
- usb_cmd = (void __iomem *)&ehci->usbcmd;
+ usb_cmd = (void __iomem *)&priv->ehci->usbcmd;
/* Stop then Reset */
clrbits_le32(usb_cmd, UCMD_RUN_STOP);
@@ -115,14 +109,10 @@ static void usb_phy_enable(int index, struct usb_ehci *ehci)
USBPHY_CTRL_ENUTMILEVEL3);
}
-static void usb_oc_config(int index)
+static void usb_oc_config(struct ehci_vf_priv_data *priv)
{
- void __iomem *ctrl;
-
- ctrl = (void __iomem *)(nc_reg_bases[index] + USB_NC_REG_OFFSET);
-
- setbits_le32(ctrl, UCTRL_OVER_CUR_POL);
- setbits_le32(ctrl, UCTRL_OVER_CUR_DIS);
+ setbits_le32(priv->misc_addr, UCTRL_OVER_CUR_POL);
+ setbits_le32(priv->misc_addr, UCTRL_OVER_CUR_DIS);
}
int __weak board_ehci_hcd_init(int port)
@@ -130,52 +120,75 @@ int __weak board_ehci_hcd_init(int port)
return 0;
}
-int ehci_vf_common_init(struct usb_ehci *ehci, int index)
+static int ehci_vf_common_init(struct ehci_vf_priv_data *priv)
{
int ret;
/* Do board specific initialisation */
- ret = board_ehci_hcd_init(index);
+ ret = board_ehci_hcd_init(priv->portnr);
if (ret)
return ret;
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
+ usb_power_config(priv);
+ usb_oc_config(priv);
+ usb_internal_phy_clock_gate(priv);
+ usb_phy_enable(priv);
return 0;
}
-struct ehci_vf_priv_data {
- struct ehci_ctrl ctrl;
- struct usb_ehci *ehci;
- struct gpio_desc cdet_gpio;
- enum usb_init_type init_type;
- enum usb_dr_mode dr_mode;
- u32 portnr;
-};
-
-static int vf_usb_of_to_plat(struct udevice *dev)
+static int vf_parse_dt_addrs(struct udevice *dev)
{
struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- fdt_addr_t phy_addr;
- ofnode phy_node;
- int i;
+ struct ofnode_phandle_args phy, misc;
+ ofnode anatop_node;
+ fdt_addr_t addr;
+ int seq, ret;
- phy_node = ofnode_parse_phandle(dev_ofnode(dev), "fsl,usbphy", 0);
- if (!ofnode_valid(phy_node))
+ ret = dev_read_phandle_with_args(dev, "fsl,usbphy", NULL, 0, 0, &phy);
+ if (ret)
+ return ret;
+
+ ret = dev_read_phandle_with_args(dev, "fsl,usbmisc", NULL, 0, 0,
+ &misc);
+ if (ret)
+ return ret;
+
+ anatop_node = ofnode_parse_phandle(phy.node, "fsl,anatop", 0);
+ if (!ofnode_valid(anatop_node))
return -EINVAL;
- phy_addr = ofnode_get_addr(phy_node);
- for (i = 0; i < ARRAY_SIZE(phy_bases); i++) {
- if (phy_addr == phy_bases[i])
- break;
- }
- if (i == ARRAY_SIZE(phy_bases))
+ ret = ofnode_get_alias_seq(phy.node, "usbphy", &seq);
+ if (ret)
+ return ret;
+ priv->portnr = seq;
+
+ addr = ofnode_get_addr(phy.node);
+ if (addr == FDT_ADDR_T_NONE)
return -EINVAL;
+ priv->phy_addr = (void __iomem *)addr;
- priv->portnr = i;
+ addr = ofnode_get_addr(misc.node);
+ if (addr == FDT_ADDR_T_NONE)
+ return -EINVAL;
+ priv->misc_addr = (void __iomem *)addr;
+
+ addr = ofnode_get_addr(anatop_node);
+ if (addr == FDT_ADDR_T_NONE)
+ return -EINVAL;
+ priv->anatop_addr = (struct anadig_reg __iomem *)addr;
+
+ return 0;
+}
+
+static int vf_usb_of_to_plat(struct udevice *dev)
+{
+ struct ehci_vf_priv_data *priv = dev_get_priv(dev);
+ int ret;
+
+ ret = vf_parse_dt_addrs(dev);
+ if (ret)
+ return ret;
priv->ehci = dev_read_addr_ptr(dev);
priv->dr_mode = usb_get_dr_mode(dev_ofnode(dev));
@@ -213,7 +226,7 @@ static int vf_init_after_reset(struct ehci_ctrl *dev)
struct usb_ehci *ehci = priv->ehci;
int ret;
- ret = ehci_vf_common_init(priv->ehci, priv->portnr);
+ ret = ehci_vf_common_init(priv);
if (ret)
return ret;
@@ -255,7 +268,7 @@ static int ehci_usb_probe(struct udevice *dev)
}
}
- ret = ehci_vf_common_init(ehci, priv->portnr);
+ ret = ehci_vf_common_init(priv);
if (ret)
goto err_gpio;
--
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 ` [PATCH v8 07/10] usb: ehci-vf: request the ID detect gpio through the device Mehmet Fide
2026-10-22 7:08 ` Mehmet Fide [this message]
2026-10-22 10:52 ` [PATCH v8 08/10] usb: ehci-vf: take the register bases from the device tree 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-9-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.