diff mbox series

[01/13] usb: ehci-mx6: Add powerup_fixup implementation

Message ID 20200916125705.4341-2-peng.fan@nxp.com
State Deferred
Delegated to: Tom Rini
Headers show
Series ehci-mx6: update and fix | expand

Commit Message

Peng Fan Sept. 16, 2020, 12:56 p.m. UTC
From: Peng Fan <peng.fan@nxp.com>

When doing port reset, the PR bit of PORTSC1 will be automatically
cleared by our IP, but standard EHCI needs explicit clear by software. The
EHCI-HCD driver follow the EHCI specification, so after 50ms wait, it
clear the PR bit by writting to the PORTSC1 register with value loaded before
setting PR.

This sequence is ok for our IP when the delay time is exact. But when the timer
is slower, some bits like PE, PSPD have been set by controller automatically
after the PR is automatically cleared. So the writing to the PORTSC1 will overwrite
these bits set by controller. And eventually the driver gets wrong status.

We implement the powerup_fixup operation which delays 50ms and will check
the PR until it is cleared by controller. And will update the reg value which is written
to PORTSC register by EHCI-HCD driver. This is much safer than depending on the delay
time to be accurate and aligining with controller's behaiver.

Signed-off-by: Ye Li <ye.li@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
 drivers/usb/host/ehci-mx6.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
diff mbox series


diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
index 37b59758bb..9531fefce0 100644
--- a/drivers/usb/host/ehci-mx6.c
+++ b/drivers/usb/host/ehci-mx6.c
@@ -20,6 +20,7 @@ 
 #include <dm.h>
 #include <asm/mach-types.h>
 #include <power/regulator.h>
+#include <linux/iopoll.h>
 #include <linux/usb/otg.h>
 #include "ehci.h"
@@ -267,6 +268,21 @@  int usb_phy_mode(int port)
+static void ehci_mx6_powerup_fixup(struct ehci_ctrl *ctrl, uint32_t *status_reg,
+				   uint32_t *reg)
+	u32 result;
+	int ret;
+	mdelay(50);
+	ret = read_poll_timeout(ehci_readl, status_reg, result, !(result & EHCI_PS_PR), 5, 2000);
+	if (ret)
+		printf("%s timeout\n", __func__);
+	*reg = ehci_readl(status_reg);
 static void usb_oc_config(int index)
 #if defined(CONFIG_MX6)
@@ -366,6 +382,10 @@  int ehci_mx6_common_init(struct usb_ehci *ehci, int index)
+static const struct ehci_ops mx6_ehci_ops = {
+	.powerup_fixup		= ehci_mx6_powerup_fixup,
 int ehci_hcd_init(int index, enum usb_init_type init,
 		struct ehci_hccr **hccr, struct ehci_hcor **hcor)
@@ -394,6 +414,8 @@  int ehci_hcd_init(int index, enum usb_init_type init,
 	if (ret)
 		return ret;
+	ehci_set_controller_priv(index, NULL, &mx6_ehci_ops);
 	type = board_usb_phy_mode(index);
 	if (hccr && hcor) {
@@ -467,7 +489,8 @@  static int mx6_init_after_reset(struct ehci_ctrl *dev)
 static const struct ehci_ops mx6_ehci_ops = {
-	.init_after_reset = mx6_init_after_reset
+	.powerup_fixup		= ehci_mx6_powerup_fixup,
+	.init_after_reset	= mx6_init_after_reset
 static int ehci_usb_phy_mode(struct udevice *dev)