From 837c596bdf90e7a723864b65a3bac84155ee66f6 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 16 Dec 2024 05:14:45 +0000 Subject: [PATCH] usbdwc: preserve Prtpwr bit for portstatus, turn off power by default, handle channel timeout preserve the Prtpwr bit in portstatus instead of unconditionally setting it. turn off port powert on init. (let usbd will turn it on). make chanio() halt the channel and error out when interrupt status is 0 after timout. this happens when the port is powered off. --- sys/src/9/bcm/usbdwc.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sys/src/9/bcm/usbdwc.c b/sys/src/9/bcm/usbdwc.c index 074f5768d..2986f7c4d 100644 --- a/sys/src/9/bcm/usbdwc.c +++ b/sys/src/9/bcm/usbdwc.c @@ -234,14 +234,20 @@ chanwait(Ep *ep, Ctlr *ctlr, Hostchan *hc, int mask) int intr, ointr, chan; ulong start, now; + if(waserror()){ + chanhalt(ep, hc); + nexterror(); + } chan = hc - ctlr->regs->hchan; for(;;){ -restart: + restart: tsleep(&ctlr->chanintr[chan], chandone, hc, 1000); if((intr = hc->hcint) == 0) - goto restart; - if(intr & Chhltd) + error("channel timeout"); + if(intr & Chhltd){ + poperror(); return intr; + } ointr = intr; now = start = fastticks(0); do{ @@ -252,6 +258,7 @@ restart: (now - start) > 60) dprint("ep%d.%d await %x after %ldµs %x -> %x\n", ep->dev->nb, ep->nb, mask, now - start, ointr, intr); + poperror(); return intr; } if((intr & mask) == 0){ @@ -686,7 +693,7 @@ init(Hci *hp) dprint("usbdwc: FIFO depth %d sizes rx/nptx/ptx %8.8ux %8.8ux %8.8ux\n", n, r->grxfsiz, r->gnptxfsiz, r->hptxfsiz); - r->hport0 = Prtpwr|Prtconndet|Prtenchng|Prtovrcurrchng; + r->hport0 = Prtconndet|Prtenchng|Prtovrcurrchng; r->gintsts = ~0; r->gintmsk = Hcintr; r->gahbcfg |= Glblintrmsk; @@ -982,7 +989,7 @@ portstatus(Hci *hp, int) s = r->hport0; b = s & (Prtconndet|Prtenchng|Prtovrcurrchng); if(b != 0) - r->hport0 = Prtpwr | b; + r->hport0 = (s & Prtpwr) | b; b = 0; if(s & Prtconnsts) b |= HPpresent;