Message ID | 20240216005756.762712-3-quic_kriskura@quicinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-67919-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp221712dyb; Thu, 15 Feb 2024 17:01:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV0Xdr7G/BJ1gMPemy60lMJB42rUGBtDJb3UBdH5i7L31owASZB+8G579xtX0gBc4LWF0gIaJFwSEh5VKap+sExOXw6pA== X-Google-Smtp-Source: AGHT+IFYcaG8SDLfE5fYFzpwYKdKh+fkPBwdB0LhuljeOJqLUjcFWTmWxkin8j0B969oBzD4eCpb X-Received: by 2002:ac8:7fce:0:b0:42c:80e7:b33 with SMTP id b14-20020ac87fce000000b0042c80e70b33mr4583975qtk.16.1708045300156; Thu, 15 Feb 2024 17:01:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708045300; cv=pass; d=google.com; s=arc-20160816; b=LX4FYexYrC/dTvFj0sFTVYAM30XlyWFGv+DUMN2R8p9PvksKzN9mSupTchCFqiYBrr Ca7zCvy7d93Hjx1VKf4GzDa1o6VtZmy1YjOjB/LgStyvJyrx0GauvbfjHKAlgNOHYA5q /1IdPQRu5s5HNg0+A9cYsq2UT28m6CHSAJtiKCMklFljLdGlgPYm7cLEn/Y4rDXAN4YX kbkzzbGVV289+gXRbKKJg8Gk8VmEs+DmaRbYuP9KNMAz/4Hla5z64hK5PEhQ3NoWB1Se 9+QnKPFoYZhWGozXiOWAdnNUEsCZw2dncUIJ+6CNGovkZa8OmbE3xsswp77xu2KB2qMg qpmg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=cX7XaCfk5cXtvXLOtzatFF0l0bumfbDW5YT48MSXcSo=; fh=wj4fpoitfUuT9lnmxYpjWQofo4DRhMPmJ4OckgOzWCU=; b=NTe0rpluxIGQQZ+yaiYLPJF23S9YF5KTrFdbmwMR7ELgpCBN95JJWK9IIkI382Picc DR6SpO1qv4opnRIX6drtLY0u/vDHvKY6rThbQyDuvhMiJuqJX12IXUNvuC2x5RWV9k02 BxQGS19lRy4wW3gddFq1GWoN676m7Q2oN6herQM0NhDeR5+3MSSRePUT+ShwMKcGibyy QBtUrmBnAB+TvKLAnIIR4kF5VwuB8fEXeJelezrBDftZmCuup0qar27zAZ/NNgyQOIY2 Y/DYPzvfyXjJzeHwaWWBMv+4JefLMQFhgsmpZRlAHdOqtNqH5EDmtZ9CuRqPOA+ZVRtB pYtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=dOclFpGJ; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-67919-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67919-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bb6-20020a05622a1b0600b0042dc21b53f5si2994773qtb.641.2024.02.15.17.01.40 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 17:01:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67919-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=dOclFpGJ; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-67919-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67919-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B81EC1C20FE6 for <ouuuleilei@gmail.com>; Fri, 16 Feb 2024 01:01:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C6D81401F; Fri, 16 Feb 2024 00:58:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="dOclFpGJ" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 A95A1134A5; Fri, 16 Feb 2024 00:58:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708045113; cv=none; b=BmDAS9XYzezVxruazNi0ILxT9fj1SGaQsqGWWMf1wdlJV4VBSuxwLVnGVk9feH/4X5cPB2EO7v4bujPCnc+F8fyLTUQHa5o1UZS8HVj/Qp0kl6OLoTCnNIh3buCX1aoew/v80EBpfjS6U+8MEdrJLsBFa+AxP58MQ6KSCiQputg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708045113; c=relaxed/simple; bh=1MPWzDyrwhhx+VsviNDLAKGKAnMcGgAqyVi95dq52fM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lHEXVySeFRyWnZEAnOtnJF3hlfK+r3z2s/wZ8z1JVqAkllFabg2j+lpTB+mI+APfb9s6t8lvf4nWLE6c08ZjQ7H9w2/Qyi2XO8ynwk2wQHUQb3g9ok4becWXEuKvlQn3FtmAOx0MhiyvIUEzFqHzkMFbg2Hc3wuMddzn7Rh0b0s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=dOclFpGJ; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41FNj4G2020677; Fri, 16 Feb 2024 00:58:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=cX7XaCfk5cXtvXLOtzatFF0l0bumfbDW5YT48MSXcSo=; b=dO clFpGJAPG/j+/JPCtpCdVlz3J/UXQABPT93t8sB+xygp++FzFdG6/4iVC/1mGbLQ b4zf2udCqtiZBCsbM20viWX5QoGBWaUlb6ZwFTVa8ygUOd9112cVKhxt9r7+cFMU qqhVMtdOLpR5KF9gTd9XuXicLLrjj6t/Us19EvdqJnrArG2mH9mdngXy7wNYXc5R XBWkakJOv+jx2E+PLEF/1BALgQPkpfzYr9g8ip4hYmfqW+qDt3Lh3+Lsk/ZfaQ6x Y7aFDfgL5n14vsDug29jrfI4EMrQn76oZwl1ZQPnOqIufnS+o4l5JTRW75ytuejL nincWHIYjhPRye5rJ6BQ== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w9e4h2ega-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 00:58:25 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41G0wPij003845 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 00:58:25 GMT Received: from hu-kriskura-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 15 Feb 2024 16:58:20 -0800 From: Krishna Kurapati <quic_kriskura@quicinc.com> To: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Rob Herring <robh+dt@kernel.org>, Bjorn Andersson <andersson@kernel.org>, Wesley Cheng <quic_wcheng@quicinc.com>, Konrad Dybcio <konrad.dybcio@linaro.org>, "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>, Conor Dooley <conor+dt@kernel.org>, Thinh Nguyen <Thinh.Nguyen@synopsys.com>, Felipe Balbi <balbi@kernel.org>, Johan Hovold <johan@kernel.org> CC: <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>, Krishna Kurapati <quic_kriskura@quicinc.com> Subject: [PATCH v15 2/9] usb: dwc3: core: Access XHCI address space temporarily to read port info Date: Fri, 16 Feb 2024 06:27:49 +0530 Message-ID: <20240216005756.762712-3-quic_kriskura@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240216005756.762712-1-quic_kriskura@quicinc.com> References: <20240216005756.762712-1-quic_kriskura@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: gcKPsaEUBM_usPG2_ki0D6Gwd_IR7u8s X-Proofpoint-ORIG-GUID: gcKPsaEUBM_usPG2_ki0D6Gwd_IR7u8s X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-15_24,2024-02-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 impostorscore=0 adultscore=0 mlxscore=0 phishscore=0 malwarescore=0 priorityscore=1501 suspectscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402160006 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791015308540395179 X-GMAIL-MSGID: 1791015308540395179 |
Series |
Add multiport support for DWC3 controllers
|
|
Commit Message
Krishna Kurapati
Feb. 16, 2024, 12:57 a.m. UTC
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 <quic_kriskura@quicinc.com> Reviewed-by: Bjorn Andersson <andersson@kernel.org> Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com> --- drivers/usb/dwc3/core.c | 62 +++++++++++++++++++++++++++++++++++++++++ drivers/usb/dwc3/core.h | 5 ++++ 2 files changed, 67 insertions(+)
Comments
On Fri, Feb 16, 2024 at 06:27:49AM +0530, Krishna Kurapati wrote: > Currently Multiport DWC3 controllers are host-only capable. I already asked you to rephrase this so that it becomes clear that you are describing a property of the current hardware (and similar throughout the series): https://lore.kernel.org/all/ZTI7AtCJWgAnACSh@hovoldconsulting.com/ > +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", I still think you should merge this with the previous line even if you end up with 83 chars. > + major_revision); > + } > + } while (1); > + /* > + * Currently only DWC3 controllers that are host-only capable > + * support Multiport. > + */ So again, also here, rephrase the comment so that it is clear that you are referring to a property of the current hardware. > + 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; > + } Johan
On 2/29/2024 3:17 PM, Johan Hovold wrote: > On Fri, Feb 16, 2024 at 06:27:49AM +0530, Krishna Kurapati wrote: >> Currently Multiport DWC3 controllers are host-only capable. > > I already asked you to rephrase this so that it becomes clear that you > are describing a property of the current hardware (and similar > throughout the series): > > https://lore.kernel.org/all/ZTI7AtCJWgAnACSh@hovoldconsulting.com/ Hi Johan. Thanks for the review. IMO, the statement is describing a property unique to current hardware, that "If it is a multiport controller, it is then host-only capable" I used the word "Currently" to indicate that "Today, the multiport devices present...". Let me know if there is any ambiguity in the sentence. In v13, I wrote: "Currently host-only capable DWC3 controllers support Multiport." You were right. It was ambiguous as it might refer to even single port controllers. So I changed it saying all the DWC3 multiport controllers are host only capable. How about: "All the DWC3 Multi Port controllers that exist today only support host mode" > >> +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", > > I still think you should merge this with the previous line even if you > end up with 83 chars. > >> + major_revision); >> + } >> + } while (1); > >> + /* >> + * Currently only DWC3 controllers that are host-only capable >> + * support Multiport. >> + */ > > So again, also here, rephrase the comment so that it is clear that you > are referring to a property of the current hardware. I put the comment this way to indicate that we don't want to check for existence of multiple ports if the controller is not "host-only" capable. We should only check for multport support only if we are host-only capable. I think the statement clearly tells that "check for host-only" configuration before proceeding to check for xhci register reads. I replied the same on: https://lore.kernel.org/all/279a54f2-7260-4270-83c7-d6f5c5ba0873@quicinc.com/ And since you didn't mention anything else at this part of code in your return reply in: https://lore.kernel.org/all/ZTYyXhyZN3jBXEfm@hovoldconsulting.com/ I thought this statement was fine to go. > >> + 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; >> + } > Thanks for the review. Can you help let me know your review on the other patches as well. Regards, Krishna,
On Thu, Feb 29, 2024 at 05:23:08PM +0530, Krishna Kurapati PSSNV wrote: > On 2/29/2024 3:17 PM, Johan Hovold wrote: > > On Fri, Feb 16, 2024 at 06:27:49AM +0530, Krishna Kurapati wrote: > >> Currently Multiport DWC3 controllers are host-only capable. > > > > I already asked you to rephrase this so that it becomes clear that you > > are describing a property of the current hardware (and similar > > throughout the series): > > > > https://lore.kernel.org/all/ZTI7AtCJWgAnACSh@hovoldconsulting.com/ > IMO, the statement is describing a property unique to current hardware, > that "If it is a multiport controller, it is then host-only capable" > > I used the word "Currently" to indicate that "Today, the multiport > devices present...". Let me know if there is any ambiguity in the sentence. > > In v13, I wrote: > "Currently host-only capable DWC3 controllers support Multiport." > You were right. It was ambiguous as it might refer to even single port > controllers. > > So I changed it saying all the DWC3 multiport controllers are host only > capable. > > How about: > > "All the DWC3 Multi Port controllers that exist today only support host > mode" That should be clear enough, thanks. > >> + /* > >> + * Currently only DWC3 controllers that are host-only capable > >> + * support Multiport. > >> + */ > > > > So again, also here, rephrase the comment so that it is clear that you > > are referring to a property of the current hardware. > > I put the comment this way to indicate that we don't want to check for > existence of multiple ports if the controller is not "host-only" > capable. We should only check for multport support only if we are > host-only capable. I think the statement clearly tells that "check for > host-only" configuration before proceeding to check for xhci register reads. Fair enough, this comment could be considered to apply only to the implementation. Perhaps the following would be more clear though: Currently only DWC3 controllers that are host-only capable can have more than one port. or simply Host-only capable controllers can have more than one port. Both of these also gives a hint that this is a property of the hardware. > I replied the same on: > https://lore.kernel.org/all/279a54f2-7260-4270-83c7-d6f5c5ba0873@quicinc.com/ > > And since you didn't mention anything else at this part of code in your > return reply in: > https://lore.kernel.org/all/ZTYyXhyZN3jBXEfm@hovoldconsulting.com/ I left in the following quote on purpose in that reply: > > Please rephrase accordingly throughout so that this becomes clear. Johan
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;