Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp670402rdb; Thu, 8 Feb 2024 18:45:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYjUJBdsDlB3c6BxAMVr4HD1J35Lz0UQDTDvtEPcakskqWI5lx1ye9vRcgYq24bx/92mNu X-Received: by 2002:a17:906:2788:b0:a35:65c3:50f7 with SMTP id j8-20020a170906278800b00a3565c350f7mr126564ejc.28.1707446743101; Thu, 08 Feb 2024 18:45:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707446743; cv=pass; d=google.com; s=arc-20160816; b=wWoS0IcGRHspPKAUacTJYGnPffKAu738XVs5rUnoN2iuXvTj4Ukiy15e6OvzoM3koV EjuKzqy4wAw0GNUM4LY/edck6ceQQwqP5Mxlm8P/Z8lkuIABeyBW0kK2yIrdFVJfmSKS X+icHAo9KL0xzuVSrfEpwWjYFQsEq5y5XGibSeXOpJtOR6hz4DVFBhmXi0O+rs6WmoAq ASvSBxodIIScDD4MTsjURRiiuWw5tJJyvGJf9JQoBRN2mL+gOexLBqyOVdFHUnbIph9L UN86SxlvuoHYgOrW3ovBmNFaLp8jdj+7ECjM2v8Kd0PQ8cdyMRcUXTzO4GeCX5bpcT+B CjVg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=xktnTqABnYeCAWDbDjYAKl8envP1/wmvZ4iCyIBwk5E=; fh=7UwAb8xr/nneUWdZ8FmRir1JVmha6pVIIjXk8zsDahw=; b=dFZO5wR1W3HJwc2nFG1YPkyO5nz+5Cz54YHEnlsfrLmG0N7xd1MNiXpCH3tWZn0e87 qp7L+ylcLtz2iTMAaz2HTDNPwR6T5CaNFgIhAStWP/uSIKzORPFcH+xRFMnSRoepF0/1 5nwe+H3d/NSA1QQEPEoMFxf3VOAy/FaUULszFCIibJNVEiUFAs8dbFM53UifHr550g+W 1aL4tZTZxmW/4RfxTYl1fTOMnffbjgdtO6S5CFvNFajaWcb6qhH4Gq3LWwVTYjIf8BKy w9AcHSiGkiS0Yb2tR1lAMo+zgMFSn3xMHf+927iabuNzKpEGuWCV3BC9zicItSQgjpFu NYFQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L6vaBWuT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-58945-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58945-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCWG69dL9QXhx/k9cBWqJp0nUYQpmBbnXSrpUkcrjBZNXR02kIyjJ7gwMIXlVmkT2Dfbs7lk70DzPMmTpBP1O7bc9MWClGN/2A21Q5waYA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id pw11-20020a17090720ab00b00a3845364c65si304262ejb.607.2024.02.08.18.45.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 18:45:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58945-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L6vaBWuT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-58945-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58945-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A93F61F2880A for ; Fri, 9 Feb 2024 02:45:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 464AB2F56; Fri, 9 Feb 2024 02:45:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="L6vaBWuT" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E894184D; Fri, 9 Feb 2024 02:45:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707446728; cv=none; b=L99htrWENP1WwvqA6DT9aOoPef3dbzL/u+5lbZd2UpGpIy23JSHj0Cu0ITe9U+ZzpzseXVsSDUzBwUdR1TRIIOl5B4ZjjSM+sDKOSwsVfxMwOhZgTtojRjw97/HiCIEQ4G8ugreLn4/CKuiCF05bj+rRH2pFySfETX3mFBAphuI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707446728; c=relaxed/simple; bh=/8Q/nYuQTqu6NNBojz8w5KEHc5rcFmsl8myuFXcGOss=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OoL8C0DA9eVtd10ImqgS1IBdB+kCpNkNebteLjsYATb0R20svhD07jgtgZjyYWmk3zd24EVZ7SU+I/TkQFsyeLjvvntRheYkkre9KxgJ8BMGofjZIgkODKRuUskXG4/rhtFbinPnP6yfeRQB/5Z3bkriebzeDEdnShtXETfFPwk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L6vaBWuT; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A59BBC433F1; Fri, 9 Feb 2024 02:45:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707446727; bh=/8Q/nYuQTqu6NNBojz8w5KEHc5rcFmsl8myuFXcGOss=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=L6vaBWuT+3HAFpr98ZyZLkW8V+AZT1Km7ggHYwtp4Xn8rEFw3Lk0jBxBwOC3EDN2y hGzp4cen9p3ZbXbz2GovMH5EXVeRtVUAXuGgdW9IKKkKE6sotr674BPfKn+d19ih3l Gx5qJiZezfvTdppvR8dgGEF1U2eL3giO2pOly57ZxfKMCpKtrWOG3mdIijXReN385Z VNS2QJ0/xjQE9XprgYiP1KjdHalGAKHK+MeE7y94NBu6Co9cDEfyPHq/hcnNfyhk0k O1Va87KDBPVqp9YUV/NFdIVVHAhCqHgr7VYW3u3c0xjiyqE/bxdtWOhfeSK4WhevHS VHLEvACW4QI2A== Date: Thu, 8 Feb 2024 20:45:24 -0600 From: Bjorn Andersson To: Krishna Kurapati Cc: Krzysztof Kozlowski , Rob Herring , Wesley Cheng , Konrad Dybcio , Greg Kroah-Hartman , Conor Dooley , Thinh Nguyen , Felipe Balbi , devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, quic_ppratap@quicinc.com, quic_jackp@quicinc.com Subject: Re: [PATCH v14 2/9] usb: dwc3: core: Access XHCI address space temporarily to read port info Message-ID: References: <20240206051825.1038685-1-quic_kriskura@quicinc.com> <20240206051825.1038685-3-quic_kriskura@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240206051825.1038685-3-quic_kriskura@quicinc.com> On Tue, Feb 06, 2024 at 10:48:18AM +0530, Krishna Kurapati wrote: > Currently Multiport DWC3 controllers are host-only capable. > Temporarily map XHCI address space for host-only controllers and parse > XHCI Extended Capabilities registers to read number of usb2 ports and > usb3 ports present on multiport controller. Each USB Port is at least HS > capable. > > The port info for usb2 and usb3 phy are identified as num_usb2_ports > and num_usb3_ports. The intention is as follows: > > Wherever we need to perform phy operations like: > > LOOP_OVER_NUMBER_OF_AVAILABLE_PORTS() > { > phy_set_mode(dwc->usb2_generic_phy[i], PHY_MODE_USB_HOST); > phy_set_mode(dwc->usb3_generic_phy[i], PHY_MODE_USB_HOST); > } > > If number of usb2 ports is 3, loop can go from index 0-2 for > usb2_generic_phy. If number of usb3-ports is 2, we don't know for sure, > if the first 2 ports are SS capable or some other ports like (2 and 3) > are SS capable. So instead, num_usb2_ports is used to loop around all > phy's (both hs and ss) for performing phy operations. If any > usb3_generic_phy turns out to be NULL, phy operation just bails out. > num_usb3_ports is used to modify GUSB3PIPECTL registers while setting up > phy's as we need to know how many SS capable ports are there for this. > > Signed-off-by: Krishna Kurapati Reviewed-by: Bjorn Andersson Regards, Bjorn > --- > drivers/usb/dwc3/core.c | 62 +++++++++++++++++++++++++++++++++++++++++ > drivers/usb/dwc3/core.h | 5 ++++ > 2 files changed, 67 insertions(+) > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c > index 3b68e8e45b8b..965eaad195fb 100644 > --- a/drivers/usb/dwc3/core.c > +++ b/drivers/usb/dwc3/core.c > @@ -39,6 +39,7 @@ > #include "io.h" > > #include "debug.h" > +#include "../host/xhci-ext-caps.h" > > #define DWC3_DEFAULT_AUTOSUSPEND_DELAY 5000 /* ms */ > > @@ -1882,10 +1883,57 @@ static int dwc3_get_clocks(struct dwc3 *dwc) > return 0; > } > > +static int dwc3_read_port_info(struct dwc3 *dwc) > +{ > + void __iomem *base; > + u8 major_revision; > + u32 offset; > + u32 val; > + > + /* > + * Remap xHCI address space to access XHCI ext cap regs since it is > + * needed to get information on number of ports present. > + */ > + base = ioremap(dwc->xhci_resources[0].start, > + resource_size(&dwc->xhci_resources[0])); > + if (IS_ERR(base)) > + return PTR_ERR(base); > + > + offset = 0; > + do { > + offset = xhci_find_next_ext_cap(base, offset, > + XHCI_EXT_CAPS_PROTOCOL); > + if (!offset) > + break; > + > + val = readl(base + offset); > + major_revision = XHCI_EXT_PORT_MAJOR(val); > + > + val = readl(base + offset + 0x08); > + if (major_revision == 0x03) { > + dwc->num_usb3_ports += XHCI_EXT_PORT_COUNT(val); > + } else if (major_revision <= 0x02) { > + dwc->num_usb2_ports += XHCI_EXT_PORT_COUNT(val); > + } else { > + dev_warn(dwc->dev, > + "unrecognized port major revision %d\n", > + major_revision); > + } > + } while (1); > + > + dev_dbg(dwc->dev, "hs-ports: %u ss-ports: %u\n", > + dwc->num_usb2_ports, dwc->num_usb3_ports); > + > + iounmap(base); > + > + return 0; > +} > + > static int dwc3_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > struct resource *res, dwc_res; > + unsigned int hw_mode; > void __iomem *regs; > struct dwc3 *dwc; > int ret; > @@ -1969,6 +2017,20 @@ static int dwc3_probe(struct platform_device *pdev) > goto err_disable_clks; > } > > + /* > + * Currently only DWC3 controllers that are host-only capable > + * support Multiport. > + */ > + hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); > + if (hw_mode == DWC3_GHWPARAMS0_MODE_HOST) { > + ret = dwc3_read_port_info(dwc); > + if (ret) > + goto err_disable_clks; > + } else { > + dwc->num_usb2_ports = 1; > + dwc->num_usb3_ports = 1; > + } > + > spin_lock_init(&dwc->lock); > mutex_init(&dwc->mutex); > > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h > index df544ec730d2..4c52fef99838 100644 > --- a/drivers/usb/dwc3/core.h > +++ b/drivers/usb/dwc3/core.h > @@ -1039,6 +1039,8 @@ struct dwc3_scratchpad_array { > * @usb3_phy: pointer to USB3 PHY > * @usb2_generic_phy: pointer to USB2 PHY > * @usb3_generic_phy: pointer to USB3 PHY > + * @num_usb2_ports: number of USB2 ports > + * @num_usb3_ports: number of USB3 ports > * @phys_ready: flag to indicate that PHYs are ready > * @ulpi: pointer to ulpi interface > * @ulpi_ready: flag to indicate that ULPI is initialized > @@ -1187,6 +1189,9 @@ struct dwc3 { > struct phy *usb2_generic_phy; > struct phy *usb3_generic_phy; > > + u8 num_usb2_ports; > + u8 num_usb3_ports; > + > bool phys_ready; > > struct ulpi *ulpi; > -- > 2.34.1 >