From patchwork Wed Oct 21 22:46:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 318884 Delivered-To: patches@linaro.org Received: by 2002:a92:d1d1:0:0:0:0:0 with SMTP id u17csp2564066ilg; Wed, 21 Oct 2020 15:46:23 -0700 (PDT) X-Received: by 2002:aa7:82ce:0:b029:142:2501:35cb with SMTP id f14-20020aa782ce0000b0290142250135cbmr5725727pfn.43.1603320383635; Wed, 21 Oct 2020 15:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603320383; cv=none; d=google.com; s=arc-20160816; b=N2VF4kkzbGeCq96OtMUBmwKAEeNRMMY6Y5GLUV9yDv14HCLU0Rbu3mebXKFgjxqp01 f5IftVi025A32lUaZ58wbginV7Esg+pxkmJPT64CSij7O8gNWj6O8wEi5ox/4TEZzXz8 Kx18UKUhf8SOpJ1K4Hf5FDLNxV1c+NnWDUkn8aOGJqiMVXP3W5d1RqWT8M/nkfvAHerj vl8vZO5eHGYmBHdcRNBoDJAarIpY+huZn6sKa16WKrUKH2GNrN7A2Pglk5woAS8OM2s9 PPLeY9R1RGwtmdZu0OL4UwaZBxP93Rk0V6sI+j9SzGqwpwV9Pdn7lgsU80WDj9Y0PGor deYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=Yl4Y/ZzUqbDL5fTVWgJ1VesNcpeRsTPqSs1TyvB5H2Y=; b=nn2eb5szu6ZAnbmwYtcNxogmGa0iw+HKx1pC3Eqp34OygQIbal6kPGOFkh/JC22p2b eIvu0KJeTcWVJVpHTWf2vpisrBuf8XXgTVYHd8JkmV6X/OrSjNQ7DMS3+UvIV2vGEToi MDdbA+g7GThH2VX/pfPlZs8hhu2gy/005m8yl7KbpBKQseWn9Ji3PWpVG2u3bCWnqdgs 2XubxIV8GVjWsAuPuFBzOmZDQ/8JgclVuQMn9SZtEV4rn+5xFhyIdBQqVEZjeIOAvHgH JCgJVkfiFH4qIB6o6xQ2S9SBRPfqCj6on93/wY7NRg2qYI2x+zyHOvJfgYvkQ7v3+0mV G8Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QTnweYnC; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id f5sor1808594pfe.21.2020.10.21.15.46.23 for (Google Transport Security); Wed, 21 Oct 2020 15:46:23 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QTnweYnC; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=Yl4Y/ZzUqbDL5fTVWgJ1VesNcpeRsTPqSs1TyvB5H2Y=; b=QTnweYnCBSxbl9b89sHHA2Js7kV+ZTm0DcM5UkLUlAzkP0Pvld2y1wtens9HEwZGsT rppkETMLwVDexknu09JBjcK2bQi32XeHHAdP0oXwyl3PgSC/f3vT/jaGQ9TbJnKjKQbu xFmU0G/uOkVUNlr/tJdp0sJpzYpF5AwfWrIhoObgpmx6sCswvaeGPSYvHGjLKwqKr2p+ G8uJ74VHjlCOXrZ+koqFK747eem/sP7Qsv/zNFxeE9EPIZ72o6Mky9Acdto/ZpJ4XYGa EN7Vnmt8xh7wNGutYiFuhZPJJWUnt3Zc1Iv/aoVaT8OP5xS65wDKh/i77rxbk2YKMwUX TH4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Yl4Y/ZzUqbDL5fTVWgJ1VesNcpeRsTPqSs1TyvB5H2Y=; b=Iy3QazcB3PHOizyUYTSSLP0L8S5h0aDfffo8x6CqQR+Sx40La+wjEFanFOtzr/2pyA EbN0nvwb8W7l39s5Mu8+3JQO8qQQz8SOtWYWtdhjhWAxFDFjRTM6GI/yRltThP9oj4Kt 49naVb/jzuyw/AtRVcQiRvX8iwceXAEvmKkNQ3uei6M2HaaX+5tugNoBc70hBtYASfTj 7kAueOmaDeQDsHEvJ81tpbyOJGPFh7LW8N93NGaLihXdicykwKlv1UqEN8+dGmOzNp5I Kk236JAlDfNrs6wmdJooF6QEaIOsp9uDJ1RvDIEgVEhlCyUMK+zke28bnED72mVflZkW lvbQ== X-Gm-Message-State: AOAM532xozcV/FNOuZdkcQ76kpNGqUqwt2tuFB+ZTWhoUmQLnskXSmmK JQSV/Qf0Kzm9TXrMwhTxik6JVPzr X-Google-Smtp-Source: ABdhPJxO62PrV4abUHN2Yj7VIbT+tfAB3XC9h3CbEu9WwUuD0xeTMCm+GIrU1xeH1Fnju0TRZ9UIdg== X-Received: by 2002:a62:e308:0:b029:152:8cc3:ebdc with SMTP id g8-20020a62e3080000b02901528cc3ebdcmr153798pfh.42.1603320383159; Wed, 21 Oct 2020 15:46:23 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id q123sm3327432pfq.56.2020.10.21.15.46.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 15:46:22 -0700 (PDT) From: John Stultz To: lkml Cc: Yu Chen , Felipe Balbi , Tejas Joglekar , Yang Fei , YongQin Liu , Andrzej Pietrasiewicz , Thinh Nguyen , Jun Li , Mauro Carvalho Chehab , Greg Kroah-Hartman , linux-usb@vger.kernel.org, John Stultz Subject: [PATCH v2] usb: dwc3: Trigger a GCTL soft reset when switching modes in DRD Date: Wed, 21 Oct 2020 22:46:19 +0000 Message-Id: <20201021224619.20796-1-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 From: Yu Chen With the current dwc3 code on the HiKey960 we often see the COREIDLE flag get stuck off in __dwc3_gadget_start(), which seems to prevent the reset irq and causes the USB gadget to fail to initialize. We had seen occasional initialization failures with older kernels but with recent 5.x era kernels it seemed to be becoming much more common, so I dug back through some older trees and realized I dropped this quirk from Yu Chen during upstreaming as I couldn't provide a proper rational for it and it didn't seem to be necessary. I now realize I was wrong. After resubmitting the quirk Thinh Nguyen pointed out that it shouldn't be a quirk and it is actually mentioned in the programming guide that it should be done when switching modes in DRD. So, to avoid these !COREIDLE lockups seen on HiKey960, this patch issues GCTL soft reset when switching modes if the controller is in DRD mode. Cc: Felipe Balbi Cc: Tejas Joglekar Cc: Yang Fei Cc: YongQin Liu Cc: Andrzej Pietrasiewicz Cc: Thinh Nguyen Cc: Jun Li Cc: Mauro Carvalho Chehab Cc: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org Signed-off-by: Yu Chen Signed-off-by: John Stultz --- v2: * Rework to always call the GCTL soft reset in DRD mode, rather then using a quirk as suggested by Thinh Nguyen --- drivers/usb/dwc3/core.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) -- 2.17.1 diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index bdf0925da6b6..ca94f3a2a83c 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -114,10 +114,24 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode) dwc->current_dr_role = mode; } +static void dwc3_gctl_core_soft_reset(struct dwc3 *dwc) +{ + int reg; + + reg = dwc3_readl(dwc->regs, DWC3_GCTL); + reg |= (DWC3_GCTL_CORESOFTRESET); + dwc3_writel(dwc->regs, DWC3_GCTL, reg); + + reg = dwc3_readl(dwc->regs, DWC3_GCTL); + reg &= ~(DWC3_GCTL_CORESOFTRESET); + dwc3_writel(dwc->regs, DWC3_GCTL, reg); +} + static void __dwc3_set_mode(struct work_struct *work) { struct dwc3 *dwc = work_to_dwc(work); unsigned long flags; + int hw_mode; int ret; u32 reg; @@ -154,6 +168,11 @@ static void __dwc3_set_mode(struct work_struct *work) break; } + /* Execute a GCTL Core Soft Reset when switch mode in DRD*/ + hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); + if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD) + dwc3_gctl_core_soft_reset(dwc); + spin_lock_irqsave(&dwc->lock, flags); dwc3_set_prtcap(dwc, dwc->desired_dr_role);