From patchwork Thu Oct 22 03:25:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 318892 Delivered-To: patches@linaro.org Received: by 2002:a92:d1d1:0:0:0:0:0 with SMTP id u17csp2705189ilg; Wed, 21 Oct 2020 20:25:51 -0700 (PDT) X-Received: by 2002:a62:1dd7:0:b029:154:dde2:ddcb with SMTP id d206-20020a621dd70000b0290154dde2ddcbmr544140pfd.30.1603337151023; Wed, 21 Oct 2020 20:25:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603337151; cv=none; d=google.com; s=arc-20160816; b=LtNlvxgq5kFMXnEXaC+OKHTb+apkQp09xbfUvApVFXTNjPMU2GN06BKj0v/97QI481 PBvNdANiwqSYEWXJ9C/cbnBDGyXHZU/UN/vkoJIQgYhQCBb2ONK9sU3wUwzz2PrLBkbN F+75mgPGFhpC33p52Kvge4YF2ioLVcrGYjwZ7PBoOXDmuwRf9pRSASrz7PHZs9y9di4e Ef8yKuAJH/4vTaapFN5UKk8EEguDKztK74GOyXs5j75GrLDnP0cxC+knV/oSdZBdW5bs lAAPdZwnCBOdyYfcTZ/VrrNvyKP8zB1yfyJfer9yR6hnlMuGHdlo/WgDDPlfyHihqU0p Ro+w== 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=jxxvL7wHWoXhk6pG78uaYuFXq7yBkOv3Nog2ApQvK5U=; b=eQL6aM1YXYpIdKNdki/EiqvBCptg96tfkibtgQKyfDmL2FDiOQC3UXvXVDXymoxNmA q5mv+PLrKvUKl0/BhJu67rcIad0ThPMkprQkWF9hqJtmOqlGvEeLlTUIp+8FIdTACmGE w/zPtvgLRP1XBPXFyiMhGNMaCMe5qBW+xTJrdq/SFcNkz2wzzGkynS+mwDhvw3cqkJoB +Al5SsmV/VE5AFrj0Xy7Oq6f3jspL4vE1u5qf+HBCdi8KW5lG2aP4rI8Ha9NOGyovoWQ TPfpS7dfwaDclHVi3wD/q1qBdyhElAYaCh68GvCE9NQyWHv0HZ8Jp78cWKmQSwa6hgYU JKMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KTNMPTmQ; 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 p1sor216880pls.49.2020.10.21.20.25.50 for (Google Transport Security); Wed, 21 Oct 2020 20:25:51 -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=KTNMPTmQ; 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=jxxvL7wHWoXhk6pG78uaYuFXq7yBkOv3Nog2ApQvK5U=; b=KTNMPTmQjVQ+eKLVfLK3r90I04XTr6E2Lp+f4wiQigFNl+q9XKvdYXq9u5bRftgVmA 1YHl144OodsejN1Mhdq94j0yy/nVcjhBZuQXZquW1LaKVtfg/4SzwofPO5ghWaogwzVB /2tTtrAZcY+a3L+tx4aQw9QJPrUldMK7bGHv01faJl4qIgLGDmYatxV048104MplImeF DM5blLTD7oZd+hmjDuSkGIWYQEjPhBEmbPTab3NF0pvXgufXmZa9KuNasGTBdclyTE4R YdHTREf6PaQT/to8AQr1jU4et6jWm63Z0jBBIsuVWbiUrPQkyGdnDNx4Q7Vub8Hvj+HK PNQg== 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=jxxvL7wHWoXhk6pG78uaYuFXq7yBkOv3Nog2ApQvK5U=; b=LcFQyUrsCg41lnX/RIWR4WNhPa6woI6qcBB4CwAjcHWOJeOTvUld4KDMc83Lfxcw8V Cuh7o7nQxcDU3VtI9JS7edKeCv4Jn6YBrKzZlk7iA23HgdNaj3tLMnpUr4dSpAm189PM IGrrQ3JzxOqbyw4KO1V0hOXZ1ZEMKkzRkAaaa7tVeLAIAY5YMBTPJzw/zEC17hGkFanO BwOYsrDa//ZEHSCn94k8AuXPNxI+JukcB2bt18YOrvIUAIsZuHbaGq1bu1BN6r8IfEQt E6vRGk+xtVXSqDKelAN4P3KQuk4E61dgDdQwqiFfj/PNM/BvCjyCz0tyEaUjpoMriDfw Zwxg== X-Gm-Message-State: AOAM531WoyqwKdKNWXU6njsgwE/tqUCoZ9EAwY0wagv9JjEzMFSwJ5ag guNpL8OEaPFDrZmO9QrKrqh1w6Z+ X-Google-Smtp-Source: ABdhPJxfsBZBWLBiB1mMmr8WfNcJLp2tjq2bb5j4pqYF63xlczSZJGtdcuQNbywuWOsvmw9WP+7TWA== X-Received: by 2002:a17:902:d20a:b029:d4:c79c:b156 with SMTP id t10-20020a170902d20ab02900d4c79cb156mr526526ply.46.1603337150600; Wed, 21 Oct 2020 20:25:50 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id 38sm277478pgx.43.2020.10.21.20.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 20:25:49 -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 v3 1/2] usb: dwc3: Trigger a GCTL soft reset when switching modes in DRD Date: Thu, 22 Oct 2020 03:25:46 +0000 Message-Id: <20201022032547.92704-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 at all 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 v3: * Move GCTL soft reset under the spinlock 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..a2a88284a95b 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; @@ -156,6 +170,11 @@ static void __dwc3_set_mode(struct work_struct *work) spin_lock_irqsave(&dwc->lock, flags); + /* 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); + dwc3_set_prtcap(dwc, dwc->desired_dr_role); spin_unlock_irqrestore(&dwc->lock, flags); From patchwork Thu Oct 22 03:25:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 318893 Delivered-To: patches@linaro.org Received: by 2002:a92:d1d1:0:0:0:0:0 with SMTP id u17csp2705207ilg; Wed, 21 Oct 2020 20:25:56 -0700 (PDT) X-Received: by 2002:a65:6553:: with SMTP id a19mr554521pgw.373.1603337155912; Wed, 21 Oct 2020 20:25:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603337155; cv=none; d=google.com; s=arc-20160816; b=uuvc+QOZ8oMgCEpi5PR1+VFg8KwlOO8NUSEfUucPS7yclSIHCNtjkcqrYZi8R+nTa4 q9+uOFx6yRHl9cQqhbNabDobpetGehQP6sAJI7gvJUHbmjJBj8X0llYxIByjsxFSbFY3 rGG/OCXHIQOPiZbCti8zF77j6p1HaFb75e0F5y7yCIq5z268mrWZY2YydQbizAQpW+CO xtHCdDmbZrKvepOkl3L/wJl80iQt6C7TFDWNegnihQmEWQNB++ucuDeDyudj6aAVha3A oHHeW8qxGdchOv+HgvIyHG5NfyQ7CtuW0Q3ozivI/xIQFegqqU6pWLXF5sEZCf9MYX42 EB+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ngSdRwMa25UhXHnCwnmxdkdheVQeg1wNUdsVKJm9YQM=; b=H/InGJn9aS5QsFW4nARzy99Ys8sggeNT4wOgdsbJikWmdsn2a4aiwZjeN4LhamEQdw WafWVI23aShy8C/eQjH0qZrPPfPPVINAC238MVJ3igLDUfs/6nGtaz5qzxUCkbSaD89l +SaHA8oUQfEORd0DmECFmRR3tcDzBiGzqnmXN9YIDNtPcq+rvCRUTO3yUwMfwE2pNS8v /q3X5vJVwVb7xHXq6dM6XvkX833DAM9JloUK0gmUqO/9K+mUCTtbSLqXsVj+Bg+OzLQA XA/Y94oWApzW/53aJ3kfgK0qEm5GADpRvQRgefhLJUA1tE0daI6PsCcjNDbs10yf5cKO NyHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=haD2xKf2; 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 kn18sor189120pjb.41.2020.10.21.20.25.55 for (Google Transport Security); Wed, 21 Oct 2020 20:25:55 -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=haD2xKf2; 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:in-reply-to:references; bh=ngSdRwMa25UhXHnCwnmxdkdheVQeg1wNUdsVKJm9YQM=; b=haD2xKf2ynvjI+pEYi/hxeNtcvmlNEFg29lkUjgwDGT8SxV1YDk+fyC+Q0hfRaylHi ahYmg4oBiAFd3cnamNF97VeIXfHWuUjSa8vjn5Kxh8oSAYRUd4NHFlSDQUU6NSG+eliW 9e4QHB3QVJUeVFmiYQekryl7aaYyKWGfl8bbhfFT6DTWYIi9EVKvXwrEzSlfhp8+7R9f fqFlnKxy4kcQBuwVM7Y5S3RoRSNtD+8opMLMXwwdJCXQBPnfwFe7gN85ghWKATBym7Rt A29qvhvHDDqbFtXmR2Fh3I3nrtvwfGjhgPpTFXWPBhAwzydQ3YYmTDPIRxCAN0I+pYFm pmaw== 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:in-reply-to :references; bh=ngSdRwMa25UhXHnCwnmxdkdheVQeg1wNUdsVKJm9YQM=; b=FT4lE/c30li7fnFvoEvLbp7sdy/z4RqXBJernq/zpu8DzQ+k48DDCz0q/FB16FJs2D p6len/+8XBKK0KgWu7yGw3tD04yRHPBHo2UPC/Pc3gCUe8hEQgHCK4xlK1B1oo194Kh9 6CRgXeXWrzHydjHyQYLzrlM84C0JRC5zCTuGdoqA1a8opv4u6huBFFNXl4TJFEu5NO0i GPJJ/4u3cmsJYEyGm1Hz5SwJ2CW2lYYI24ynDMrc7E0iMSALb/aF64sJ0JH/kbY+Jlm6 jRXiU0lVsNUYeZ1f4ZL17yr3Cv10ekz3NlCgH8HdHOdNTT1D17omwr+HylU/reBarRiV p3yg== X-Gm-Message-State: AOAM532OwTql2gVbxoJJ3kHj5QwMLmKPFmElYlXeddEumKUqRoehHDbz DoJXbXProdNihbXB4f3ilrxa6ZCh X-Google-Smtp-Source: ABdhPJxL442674qgXukUAHwueJ+DfOYjsMW4FOKi1EMZzt45PqOHGGYVFYTElJaQjPOCgUjzWoDwYA== X-Received: by 2002:a17:90a:3f0f:: with SMTP id l15mr511280pjc.190.1603337155653; Wed, 21 Oct 2020 20:25:55 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id 38sm277478pgx.43.2020.10.21.20.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 20:25:54 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , 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 Subject: [PATCH v3 2/2] usb: dwc3: Fix DRD mode change sequence following programming guide Date: Thu, 22 Oct 2020 03:25:47 +0000 Message-Id: <20201022032547.92704-2-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201022032547.92704-1-john.stultz@linaro.org> References: <20201022032547.92704-1-john.stultz@linaro.org> In reviewing the previous patch, Thinh Nguyen pointed out that the DRD mode change sequence should be like the following when switching from host -> device according to the programming guide (for all DRD IPs): 1. Reset controller with GCTL.CoreSoftReset 2. Set GCTL.PrtCapDir(device) 3. Soft reset with DCTL.CSftRst 4. Then follow up with the initializing registers sequence The current code does: a. Soft reset with DCTL.CSftRst on driver probe b. Reset controller with GCTL.CoreSoftReset (added in previous patch) c. Set GCTL.PrtCapDir(device) d. < missing DCTL.CSftRst > e. Then follow up with initializing registers sequence So this patch adds the DCTL.CSftRst soft reset that was currently missing from the dwc3 mode switching. 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: John Stultz --- Feedback would be appreciated. I'm a little worried I should be conditionalizing the DCTL.CSftRst on DRD mode controllers, but I'm really not sure what the right thing to do is for non-DRD mode controllers. --- drivers/usb/dwc3/core.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.17.1 diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index a2a88284a95b..c87d8add19e4 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -40,6 +40,8 @@ #define DWC3_DEFAULT_AUTOSUSPEND_DELAY 5000 /* ms */ +static int dwc3_core_soft_reset(struct dwc3 *dwc); + /** * dwc3_get_dr_mode - Validates and sets dr_mode * @dwc: pointer to our context structure @@ -177,6 +179,7 @@ static void __dwc3_set_mode(struct work_struct *work) dwc3_set_prtcap(dwc, dwc->desired_dr_role); + dwc3_core_soft_reset(dwc); spin_unlock_irqrestore(&dwc->lock, flags); switch (dwc->desired_dr_role) {