All of lore.kernel.org
 help / color / mirror / Atom feed
From: xy521521 <xy521521@gmail.com>
To: stern@rowland.harvard.edu, gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	EdisonZhang@zhaoxin.com, PeterWu@zhaoxin.com,
	cobechen@zhaoxin.com, wugaoquan@kylinos.cn,
	Hongyu Xie <xiehongyu1@kylinos.cn>
Subject: [PATCH -next] usb: ehci: Read CMD_RUN instead of STS_HALT in ehci_halt with ZX-200
Date: Sat, 23 Jul 2022 15:38:05 +0800	[thread overview]
Message-ID: <20220723073805.23491-1-xy521521@gmail.com> (raw)

From: Hongyu Xie <xiehongyu1@kylinos.cn>

Forcing HC to halt state is ensured by reading STS_HALT field in USBSTS
register every microsecond(2ms in total) after clearing CMD_RUN filed in
USBCMD register during initialization.

But sometimes the STS_HALT field in USBSTS is not set during that 2ms, i.e
ehci_handshake returns -ETIMEDOUT. And host controller won't work after
that, so does the device attached on it. This was first found on a system
with ZX-200 HC on it.

The interesting part is that if you ignore -ETIMEOUT returned from
ehci_handshak or read CMD_RUN instead and continue the initialization, the
HC works just fine.

So read CMD_RUN instead.

Signed-off-by: Hongyu Xie <xiehongyu1@kylinos.cn>
---
 drivers/usb/host/ehci-hcd.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 684164fa9716..a935cfb79bcc 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -181,6 +181,7 @@ static int tdi_in_host_mode (struct ehci_hcd *ehci)
 static int ehci_halt (struct ehci_hcd *ehci)
 {
 	u32	temp;
+	struct pci_dev  *pci_dev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
 
 	spin_lock_irq(&ehci->lock);
 
@@ -204,8 +205,14 @@ static int ehci_halt (struct ehci_hcd *ehci)
 	spin_unlock_irq(&ehci->lock);
 	synchronize_irq(ehci_to_hcd(ehci)->irq);
 
-	return ehci_handshake(ehci, &ehci->regs->status,
-			  STS_HALT, STS_HALT, 16 * 125);
+	if (((pci_dev->vendor == PCI_VENDOR_ID_ZHAOXIN) &&
+		(pci_dev->device == 0x3104) &&
+		((pci_dev->revision & 0xf0) == 0x90)))
+		return ehci_handshake(ehci, &ehci->regs->command, CMD_RUN,
+				0, 16 * 125);
+	else
+		return ehci_handshake(ehci, &ehci->regs->status, STS_HALT,
+				STS_HALT, 16 * 125);
 }
 
 /* put TDI/ARC silicon into EHCI mode */
-- 
2.25.1


             reply	other threads:[~2022-07-23  7:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-23  7:38 xy521521 [this message]
2022-07-23  9:31 ` [PATCH -next] usb: ehci: Read CMD_RUN instead of STS_HALT in ehci_halt with ZX-200 Greg KH

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=20220723073805.23491-1-xy521521@gmail.com \
    --to=xy521521@gmail.com \
    --cc=EdisonZhang@zhaoxin.com \
    --cc=PeterWu@zhaoxin.com \
    --cc=cobechen@zhaoxin.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=wugaoquan@kylinos.cn \
    --cc=xiehongyu1@kylinos.cn \
    /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.