From patchwork Sat Jun 4 02:48:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12869524 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E928ECCA473 for ; Sat, 4 Jun 2022 02:48:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350219AbiFDCsO (ORCPT ); Fri, 3 Jun 2022 22:48:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231513AbiFDCsM (ORCPT ); Fri, 3 Jun 2022 22:48:12 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68D0D1E3EE; Fri, 3 Jun 2022 19:48:12 -0700 (PDT) Received: from mailhost.synopsys.com (sv1-mailhost2.synopsys.com [10.205.2.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id F3D6B4022B; Sat, 4 Jun 2022 02:48:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1654310892; bh=xZvSInX2sjlaTumbQ9XqBq4EUsvUia+nprlzKxJFyaI=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=R8dpE2rrnPXAGT3iPTNnbI9Axe2BJKIUWezERVetuZcb2WYxj6/Aw+8ZJpVHm6rMh wPFHXJ+Tg0YlSr2eDVPGHLxVu08KjCCkPUZ21qiIi+K4i7BoeybjEvp2AEi4Ctr9ez EROlYw0cOmKQy9EM5FSwAT+IK7DTpPIyagIVa+65qBzCvb0HP3F48LqXSr2xieXkNS /TRY8sdhQko6Ydy9XohqsBQEVkd9CGmz7myOZ/qIcmlFwyW9p8R9Bwd2QEYczaa1N+ V7JOy1qL4B+3vaB9HAbHNpzn91Je9CvSaQuLsAPcTsnUy9WtnuslsAcGQwcUTrciCy CwIt+ynLDxxsw== Received: from te-lab15 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id F3D34A008D; Sat, 4 Jun 2022 02:48:08 +0000 (UTC) Received: by te-lab15 (sSMTP sendmail emulation); Fri, 03 Jun 2022 19:48:08 -0700 Date: Fri, 03 Jun 2022 19:48:08 -0700 Message-Id: <1ff0422b36c32c0b8b76f99333ac785f275edd4d.1654310542.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [RFC PATCH 1/4] dt-bindings: usb: usb-xhci: Add xhci-snps-quirks To: Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Mathias Nyman Cc: John Youn , Thinh Nguyen , Pavan Kondeti Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Set this property to use xhci-snps extension to handle common Synopsys DWC_usb3x host quirks. Signed-off-by: Thinh Nguyen --- Documentation/devicetree/bindings/usb/usb-xhci.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/usb-xhci.yaml b/Documentation/devicetree/bindings/usb/usb-xhci.yaml index 965f87fef702..540044a087a7 100644 --- a/Documentation/devicetree/bindings/usb/usb-xhci.yaml +++ b/Documentation/devicetree/bindings/usb/usb-xhci.yaml @@ -29,6 +29,10 @@ properties: description: Interrupt moderation interval default: 5000 + xhci-snps-quirks: + description: Handles common Synopsys DWC_usb3x host quirks + type: boolean + additionalProperties: true examples: From patchwork Sat Jun 4 02:48:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12869523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2DBAC43334 for ; Sat, 4 Jun 2022 02:48:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350236AbiFDCsT (ORCPT ); Fri, 3 Jun 2022 22:48:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231513AbiFDCsR (ORCPT ); Fri, 3 Jun 2022 22:48:17 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5036F56FBB for ; Fri, 3 Jun 2022 19:48:17 -0700 (PDT) Received: from mailhost.synopsys.com (sv1-mailhost2.synopsys.com [10.205.2.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 18D514023B; Sat, 4 Jun 2022 02:48:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1654310897; bh=4SShO/Lse3K6Iqf6rRt5m2mof0bGN092KpISmP3UyhE=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=GHUM1qxrUUQVbwC/s7mM9Buaa8u8f+cSoGvK+rmOppG5+AcU4DNftbPa8FRnhN93I qDWmtkOHyPew07g+1AoaGScyXOsVte7LxC/uwWuj9r5aj1RAnuCK1/4jhC3TRsR3wc b4+l7Oy6t7/axviI4ZeVbrruArhHIBHA1X/nGOEHAWgodwV9d6lFzP+2wCuuJKzkPW igNFHwh9kr6QWLBmrK70DWER82Rc1Dj3okXp+oR2a4svTX2vs+MSf2YqKuH389XH6w pxPY7y1Mj/lNR2T7D9S42wXc3grCzt/Zbt57m+M8m+MnuYaua0J2sJ9JcpGTUgLXB/ njWb1pMn5keRQ== Received: from te-lab15 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id F1468A008D; Sat, 4 Jun 2022 02:48:15 +0000 (UTC) Received: by te-lab15 (sSMTP sendmail emulation); Fri, 03 Jun 2022 19:48:15 -0700 Date: Fri, 03 Jun 2022 19:48:15 -0700 Message-Id: <3980819b8b7ca377896e0e3de93862f3057694e9.1654310542.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [RFC PATCH 2/4] usb: dwc3: host: Always set xhci-snps-quirks To: Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org Cc: John Youn , Thinh Nguyen Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Always enable xhci-snps-quirks to use xhci-snps glue extension. The xhci-snps extension can fine tune xhci driver to better handle Synopsys DWC_usb3x IPs. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/host.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c index f56c30cf151e..ce359862f9aa 100644 --- a/drivers/usb/dwc3/host.c +++ b/drivers/usb/dwc3/host.c @@ -66,7 +66,7 @@ static int dwc3_host_get_irq(struct dwc3 *dwc) int dwc3_host_init(struct dwc3 *dwc) { - struct property_entry props[4]; + struct property_entry props[5]; struct platform_device *xhci; int ret, irq; int prop_idx = 0; @@ -94,6 +94,8 @@ int dwc3_host_init(struct dwc3 *dwc) memset(props, 0, sizeof(struct property_entry) * ARRAY_SIZE(props)); + props[prop_idx++] = PROPERTY_ENTRY_BOOL("xhci-snps-quirks"); + if (dwc->usb3_lpm_capable) props[prop_idx++] = PROPERTY_ENTRY_BOOL("usb3-lpm-capable"); From patchwork Sat Jun 4 02:48:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12869525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75E17C433EF for ; Sat, 4 Jun 2022 02:48:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350247AbiFDCsZ (ORCPT ); Fri, 3 Jun 2022 22:48:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350184AbiFDCsY (ORCPT ); Fri, 3 Jun 2022 22:48:24 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 944DA56FA6 for ; Fri, 3 Jun 2022 19:48:23 -0700 (PDT) Received: from mailhost.synopsys.com (sv1-mailhost1.synopsys.com [10.205.2.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 4A3B9C06ED; Sat, 4 Jun 2022 02:48:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1654310903; bh=+yAZBCZ2Atg2eL0GnW1+jtZa2BPfTK3DmRPZGSGEvXU=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=BmNhXcuaRYZyiEBcjUNXWZKHGobTvzxL5+T1kt630WXuTsBUDK7bcS02oy6BNCe4v uEqhiarFRBJV7TMGBmnk85HFYaJHBAkxLypqPEgF9ZrtY9QTwfE8ozAd2ivo2yQZi8 WSbyv+CgArzVEbry8hDfGyIl+ER0yRLrki7KkXsDNqpb1Ku+qVH2s7/ylyjYygUGKH 4qK/P8O0lAf+jHfgOppZhkKUXf2qoVmFGB+qx3kYSNO0N2+OuD5joOWUn5Hzo4neSt rVMyJAJoi7qfpNTNkhnwK5yUiWW/pmfZ3XQDfgJf+K7zmXSeyKdfLFCUCUqZXQpHM4 bQxLctRgMa9hw== Received: from te-lab15 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 1537FA0085; Sat, 4 Jun 2022 02:48:22 +0000 (UTC) Received: by te-lab15 (sSMTP sendmail emulation); Fri, 03 Jun 2022 19:48:22 -0700 Date: Fri, 03 Jun 2022 19:48:22 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [RFC PATCH 3/4] usb: dwc3: core: Share global register access with xhci driver To: Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org Cc: John Youn , Thinh Nguyen , Pavan Kondeti Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When the dwc3 driver create a xhci platform device and pass its control to the xhci driver, allow it to also have access to dwc3 global registers. The xhci-snps needs access to the global register parameters to handle some quirks. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index e027c0420dc3..b19b7b540182 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1697,7 +1697,7 @@ static int dwc3_probe(struct platform_device *pdev) dwc->xhci_resources[0].start = res->start; dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + - DWC3_XHCI_REGS_END; + DWC3_GLOBALS_REGS_END; dwc->xhci_resources[0].flags = res->flags; dwc->xhci_resources[0].name = res->name; @@ -1708,7 +1708,7 @@ static int dwc3_probe(struct platform_device *pdev) dwc_res = *res; dwc_res.start += DWC3_GLOBALS_REGS_START; - regs = devm_ioremap_resource(dev, &dwc_res); + regs = devm_ioremap(dev, dwc_res.start, resource_size(&dwc_res)); if (IS_ERR(regs)) return PTR_ERR(regs); From patchwork Sat Jun 4 02:48:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12869526 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F62BC433EF for ; Sat, 4 Jun 2022 02:48:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350278AbiFDCse (ORCPT ); Fri, 3 Jun 2022 22:48:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231513AbiFDCsc (ORCPT ); Fri, 3 Jun 2022 22:48:32 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00AE2201AF for ; Fri, 3 Jun 2022 19:48:30 -0700 (PDT) Received: from mailhost.synopsys.com (sv2-mailhost2.synopsys.com [10.205.2.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id A925EC06ED; Sat, 4 Jun 2022 02:48:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1654310910; bh=LVmDH0xWzSHU0E069yuBYelSJw4UX3PDAZOspgXap3U=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Ykt+fqGmDyMMqJip9/ISjtSpRQXcV1gjLempin4a2aMQzN0WgaP6hIprPmRikwjWf Rign/EP7x5rtwzFmsVApJi57a8aNR+E1i2F3RqsgQin//lcMLRpbGvr4r6lljzG3GA hWSaQk6bQvu0To/IZA50HZ4c4XZwSzDBjPWu4JghCD0+dRPtC87DPolrx5yogp58ig PY1QlMX3uUIb9IbhN9aPtVvm5W3wLc5GLUFIpBAQntzfN4cR1ByQNBmJ0PTZ6HmBrF 9rbFdH8mThbroPkm4COgIKWjoaGM2kfvywGbPvF/PymU3pSWqmdFX3rKIzVX29+/Iv cntWpYDPucg8w== Received: from te-lab15 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 8E1DBA00A0; Sat, 4 Jun 2022 02:48:28 +0000 (UTC) Received: by te-lab15 (sSMTP sendmail emulation); Fri, 03 Jun 2022 19:48:28 -0700 Date: Fri, 03 Jun 2022 19:48:28 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [RFC PATCH 4/4] usb: xhci: Introduce Synopsys glue extension for DWC_usb3x To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Mathias Nyman , Matthias Kaehlcke , Lukas Bulwahn , Krzysztof Kozlowski , Juergen Gross Cc: John Youn , Pavan Kondeti Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Synopsys DWC_usb3x IPs are used on many different platforms. Since they share the same IP, often the quirks are common across different platforms and versions. This drives the need to find a way to handle all the common (and platform specific) quirks and separate its logic from dwc3 and xhci core logic. Hopefully this helps reduce introducing new device properties while maintaining abstraction. So, let's create a xhci-snps glue extension that can apply to xhci-plat and xhci-pci glue drivers and teach it to handle DWC_usb3x hosts. For this particular change, we'll start with xhci-plat glue driver. Signed-off-by: Thinh Nguyen --- drivers/usb/host/Kconfig | 8 ++ drivers/usb/host/Makefile | 3 + drivers/usb/host/xhci-plat.c | 40 ++++++++ drivers/usb/host/xhci-plat.h | 3 + drivers/usb/host/xhci-snps.c | 185 +++++++++++++++++++++++++++++++++++ drivers/usb/host/xhci-snps.h | 32 ++++++ 6 files changed, 271 insertions(+) create mode 100644 drivers/usb/host/xhci-snps.c create mode 100644 drivers/usb/host/xhci-snps.h diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 57ca5f97a3dc..efbfb79baf44 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -62,6 +62,14 @@ config USB_XHCI_PLATFORM If unsure, say N. +config USB_XHCI_SNPS + bool "xHCI fine tune for Synopsys platforms" + help + Say 'Y' to enable additional fine tune for Synopsys DWC_usb3x xHCI + controllers. + + If unsure, say N. + config USB_XHCI_HISTB tristate "xHCI support for HiSilicon STB SoCs" depends on USB_XHCI_PLATFORM && (ARCH_HISI || COMPILE_TEST) diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 2948983618fb..066b78fbc1d1 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile @@ -28,6 +28,9 @@ endif ifneq ($(CONFIG_USB_XHCI_RCAR), ) xhci-plat-hcd-y += xhci-rcar.o endif +ifneq ($(CONFIG_USB_XHCI_SNPS), ) + xhci-plat-hcd-y += xhci-snps.o +endif ifneq ($(CONFIG_DEBUG_FS),) xhci-hcd-y += xhci-debugfs.o diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 044855818cb1..73cc0262cc75 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -24,16 +24,20 @@ #include "xhci-plat.h" #include "xhci-mvebu.h" #include "xhci-rcar.h" +#include "xhci-snps.h" static struct hc_driver __read_mostly xhci_plat_hc_driver; static int xhci_plat_setup(struct usb_hcd *hcd); static int xhci_plat_start(struct usb_hcd *hcd); +static int xhci_plat_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, + struct usb_host_endpoint *ep); static const struct xhci_driver_overrides xhci_plat_overrides __initconst = { .extra_priv_size = sizeof(struct xhci_plat_priv), .reset = xhci_plat_setup, .start = xhci_plat_start, + .add_endpoint = xhci_plat_add_endpoint, }; static void xhci_priv_plat_start(struct usb_hcd *hcd) @@ -105,6 +109,20 @@ static int xhci_plat_start(struct usb_hcd *hcd) return xhci_run(hcd); } +static int xhci_plat_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, + struct usb_host_endpoint *ep) +{ + struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); + int ret; + + if (priv && priv->add_endpoint_quirk) + ret = priv->add_endpoint_quirk(hcd, udev, ep); + else + ret = xhci_add_endpoint(hcd, udev, ep); + + return ret; +} + #ifdef CONFIG_OF static const struct xhci_plat_priv xhci_plat_marvell_armada = { .init_quirk = xhci_mvebu_mbus_init_quirk, @@ -173,6 +191,25 @@ static const struct of_device_id usb_xhci_of_match[] = { MODULE_DEVICE_TABLE(of, usb_xhci_of_match); #endif +static int xhci_plat_setup_snps_quirks(struct usb_hcd *hcd) +{ + struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); + int ret; + + if (!IS_ENABLED(CONFIG_USB_XHCI_SNPS)) + return 0; + + ret = xhci_snps_init(hcd); + if (ret) { + dev_err(hcd->self.controller, "SNPS extension setup fails\n"); + return ret; + } + + priv->init_quirk = &xhci_snps_setup; + priv->add_endpoint_quirk = &xhci_snps_add_endpoint; + return 0; +} + static int xhci_plat_probe(struct platform_device *pdev) { const struct xhci_plat_priv *priv_match; @@ -301,6 +338,9 @@ static int xhci_plat_probe(struct platform_device *pdev) if (device_property_read_bool(tmpdev, "quirk-broken-port-ped")) xhci->quirks |= XHCI_BROKEN_PORT_PED; + if (device_property_read_bool(tmpdev, "xhci-snps-quirks")) + xhci_plat_setup_snps_quirks(hcd); + device_property_read_u32(tmpdev, "imod-interval-ns", &xhci->imod_interval); } diff --git a/drivers/usb/host/xhci-plat.h b/drivers/usb/host/xhci-plat.h index 1fb149d1fbce..7b49aba73833 100644 --- a/drivers/usb/host/xhci-plat.h +++ b/drivers/usb/host/xhci-plat.h @@ -17,6 +17,9 @@ struct xhci_plat_priv { int (*init_quirk)(struct usb_hcd *); int (*suspend_quirk)(struct usb_hcd *); int (*resume_quirk)(struct usb_hcd *); + int (*add_endpoint_quirk)(struct usb_hcd *hcd, + struct usb_device *udev, + struct usb_host_endpoint *ep); }; #define hcd_to_xhci_priv(h) ((struct xhci_plat_priv *)hcd_to_xhci(h)->priv) diff --git a/drivers/usb/host/xhci-snps.c b/drivers/usb/host/xhci-snps.c new file mode 100644 index 000000000000..932d914a090a --- /dev/null +++ b/drivers/usb/host/xhci-snps.c @@ -0,0 +1,185 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * xhci-snps.c - xHCI glue extension for Synopsys DWC_usb3x IPs. + * + * Copyright (C) 2022 Synopsys Inc. + * + * Author: Thinh Nguyen + * + * Contains some borrowed code from dwc3 driver. + */ + +#include "xhci.h" +#include "xhci-snps.h" + +#define DWC3_GSNPSID 0xc120 +#define DWC3_VER_NUMBER 0xc1a0 +#define DWC3_VER_TYPE 0xc1a4 + +#define DWC3_GLOBALS_REGS_END 0xc6ff + +#define DWC3_GSNPSID_MASK 0xffff0000 +#define DWC3_GSNPS_ID(p) (((p) & DWC3_GSNPSID_MASK) >> 16) + +#define DWC3_IP 0x5533 +#define DWC31_IP 0x3331 +#define DWC32_IP 0x3332 + +#define DWC3_REVISION_ANY 0x0 +#define DWC3_REVISION_173A 0x5533173a +#define DWC3_REVISION_175A 0x5533175a +#define DWC3_REVISION_180A 0x5533180a +#define DWC3_REVISION_183A 0x5533183a +#define DWC3_REVISION_185A 0x5533185a +#define DWC3_REVISION_187A 0x5533187a +#define DWC3_REVISION_188A 0x5533188a +#define DWC3_REVISION_190A 0x5533190a +#define DWC3_REVISION_194A 0x5533194a +#define DWC3_REVISION_200A 0x5533200a +#define DWC3_REVISION_202A 0x5533202a +#define DWC3_REVISION_210A 0x5533210a +#define DWC3_REVISION_220A 0x5533220a +#define DWC3_REVISION_230A 0x5533230a +#define DWC3_REVISION_240A 0x5533240a +#define DWC3_REVISION_250A 0x5533250a +#define DWC3_REVISION_260A 0x5533260a +#define DWC3_REVISION_270A 0x5533270a +#define DWC3_REVISION_280A 0x5533280a +#define DWC3_REVISION_290A 0x5533290a +#define DWC3_REVISION_300A 0x5533300a +#define DWC3_REVISION_310A 0x5533310a +#define DWC3_REVISION_330A 0x5533330a + +#define DWC31_REVISION_ANY 0x0 +#define DWC31_REVISION_110A 0x3131302a +#define DWC31_REVISION_120A 0x3132302a +#define DWC31_REVISION_160A 0x3136302a +#define DWC31_REVISION_170A 0x3137302a +#define DWC31_REVISION_180A 0x3138302a +#define DWC31_REVISION_190A 0x3139302a + +#define DWC32_REVISION_ANY 0x0 +#define DWC32_REVISION_100A 0x3130302a + +#define DWC31_VERSIONTYPE_ANY 0x0 +#define DWC31_VERSIONTYPE_EA01 0x65613031 +#define DWC31_VERSIONTYPE_EA02 0x65613032 +#define DWC31_VERSIONTYPE_EA03 0x65613033 +#define DWC31_VERSIONTYPE_EA04 0x65613034 +#define DWC31_VERSIONTYPE_EA05 0x65613035 +#define DWC31_VERSIONTYPE_EA06 0x65613036 + +#define DWC3_IP_IS(_ip) \ + (snps->ip == _ip##_IP) + +#define DWC3_VER_IS(_ip, _ver) \ + (DWC3_IP_IS(_ip) && snps->revision == _ip##_REVISION_##_ver) + +#define DWC3_VER_IS_PRIOR(_ip, _ver) \ + (DWC3_IP_IS(_ip) && snps->revision < _ip##_REVISION_##_ver) + +#define DWC3_VER_IS_WITHIN(_ip, _from, _to) \ + (DWC3_IP_IS(_ip) && \ + snps->revision >= _ip##_REVISION_##_from && \ + (!(_ip##_REVISION_##_to) || \ + snps->revision <= _ip##_REVISION_##_to)) + +#define DWC3_VER_TYPE_IS_WITHIN(_ip, _ver, _from, _to) \ + (DWC3_VER_IS(_ip, _ver) && \ + snps->version_type >= _ip##_VERSIONTYPE_##_from && \ + (!(_ip##_VERSIONTYPE_##_to) || \ + snps->version_type <= _ip##_VERSIONTYPE_##_to)) + +/** + * struct xhci_snps - Wrapper for DWC_usb3x host controller + * @hcd: the main host device + * @ip: controller's ID + * @revision: controller's version of an IP + * @version_type: VERSIONTYPE register contents, a sub release of a revision + */ +struct xhci_snps { + struct usb_hcd *hcd; + u32 ip; + u32 revision; + u32 version_type; +}; + +#define dev_to_xhci_snps(p) (container_of((p), struct xhci_snps, dev)) + +int xhci_snps_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, + struct usb_host_endpoint *ep) +{ + struct xhci_snps *snps = dev_get_drvdata(hcd->self.controller); + + if (DWC3_VER_IS_WITHIN(DWC31, ANY, 190A) && + usb_endpoint_xfer_int(&ep->desc) && + udev->speed == USB_SPEED_FULL && ep->desc.bInterval == 6) + ep->desc.bInterval = 5; + + return xhci_add_endpoint(hcd, udev, ep); +} + +static bool xhci_is_snps(struct usb_hcd *hcd) +{ + u32 id; + + if (hcd->rsrc_len < DWC3_GLOBALS_REGS_END) + return false; + + id = DWC3_GSNPS_ID(readl(hcd->regs + DWC3_GSNPSID)); + + return (id == DWC3_IP || id == DWC31_IP || id == DWC32_IP); +} + +static int xhci_snps_init_version(struct xhci_snps *snps) +{ + void __iomem *regs = snps->hcd->regs; + u32 reg; + + reg = readl(regs + DWC3_GSNPSID); + snps->ip = DWC3_GSNPS_ID(reg); + + if (DWC3_IP_IS(DWC3)) { + snps->revision = reg; + } else if (DWC3_IP_IS(DWC31) || DWC3_IP_IS(DWC32)) { + snps->revision = readl(regs + DWC3_VER_NUMBER); + snps->version_type = readl(regs + DWC3_VER_TYPE); + } else { + return -EINVAL; + } + + return 0; +} + +int xhci_snps_setup(struct usb_hcd *hcd) +{ + struct xhci_hcd *xhci = hcd_to_xhci(hcd); + + /* These quirks are applicable to all DWC_usb3x IPs and versions */ + xhci->quirks |= XHCI_SKIP_PHY_INIT | XHCI_SG_TRB_CACHE_SIZE_QUIRK; + + return 0; +} + +int xhci_snps_init(struct usb_hcd *hcd) +{ + struct device *dev = hcd->self.controller; + struct xhci_snps *snps; + int ret; + + if (!xhci_is_snps(hcd)) + return -EINVAL; + + snps = devm_kzalloc(dev, sizeof(*snps), GFP_KERNEL); + if (!snps) + return -ENOMEM; + + snps->hcd = hcd; + + ret = xhci_snps_init_version(snps); + if (ret) + return ret; + + dev_set_drvdata(dev, snps); + return 0; +} diff --git a/drivers/usb/host/xhci-snps.h b/drivers/usb/host/xhci-snps.h new file mode 100644 index 000000000000..c35a7ffdeaa3 --- /dev/null +++ b/drivers/usb/host/xhci-snps.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2022 Synopsys Inc. + */ + +#ifndef _XHCI_SNPS_H +#define _XHCI_SNPS_H + +#if IS_ENABLED(CONFIG_USB_XHCI_SNPS) +int xhci_snps_init(struct usb_hcd *hcd); +int xhci_snps_setup(struct usb_hcd *hcd); +int xhci_snps_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, + struct usb_host_endpoint *ep); +#else +static inline int xhci_snps_init(struct usb_hcd *hcd) +{ + return 0; +} + +static inline int xhci_snps_setup(struct usb_hcd *hcd) +{ + return 0; +} + +static int xhci_snps_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, + struct usb_host_endpoint *ep) +{ + return 0; +} +#endif + +#endif /* _XHCI_SNPS_H */