From patchwork Tue Oct 17 13:18:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Kurapati X-Patchwork-Id: 734987 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 05297436A0; Tue, 17 Oct 2023 13:19:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="E4Em0O5+" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF57CF1; Tue, 17 Oct 2023 06:19:32 -0700 (PDT) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HD7Iih005166; Tue, 17 Oct 2023 13:19: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=gbjM2IVLBNGvsGAFYv/I5yJ/kDV3NlIrf+H28JhetGY=; b=E4Em0O5+8I4UWlOK+btiOG3LYqDZMGNfN6wHe3hQc83E0LO4BOfO7Vbi1v2S6VU+9dKJ REAcVWtBTpHs+H9i45Ykww/JDI2oH1YFP12vwYsGNIVAax16XuaEqVgSkJt3brpDtvQu JwvEFIAOFfUW7T4qaqD2DqE3/hS8bJHyt3JpLyuAXLlLzZrm0Z9Usr0lhMpUeifmKqHj tO9khrp7RwK8izFaAmU3AGTtiubGGc6po37UIneq5sbsiNiKvd4tDPrKZ1kikE60QOIi pUZRZ51H8TA7j4mm4leOuvvd5Xh4gvL9zk+4nVaWxcjdVE8hWEixTzj3fwql7f1+uaQK 7A== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tstv9r0tj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 13:19:25 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39HDJArp002299 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 13:19:10 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.39; Tue, 17 Oct 2023 06:19:05 -0700 From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Philipp Zabel , "Andy Gross" , Bjorn Andersson , "Konrad Dybcio" , Rob Herring , Krzysztof Kozlowski , Conor Dooley , CC: , , , , , , Krishna Kurapati Subject: [RFC 1/8] dt-bindings: usb: qcom, dwc3: Add bindings to enable runtime Date: Tue, 17 Oct 2023 18:48:45 +0530 Message-ID: <20231017131851.8299-2-quic_kriskura@quicinc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017131851.8299-1-quic_kriskura@quicinc.com> References: <20231017131851.8299-1-quic_kriskura@quicinc.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] 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: JSVT3efDXhg8gJmkbeFVo0y2yCNmFAIm X-Proofpoint-ORIG-GUID: JSVT3efDXhg8gJmkbeFVo0y2yCNmFAIm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-17_02,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 priorityscore=1501 mlxlogscore=660 impostorscore=0 suspectscore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 malwarescore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170113 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Add enable-rt binding to let the device register vendor hooks to core and facilitate runtime suspend and resume. Signed-off-by: Krishna Kurapati --- Documentation/devicetree/bindings/usb/qcom,dwc3.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/qcom,dwc3.yaml b/Documentation/devicetree/bindings/usb/qcom,dwc3.yaml index cb50261c6a36..788d9c510abc 100644 --- a/Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +++ b/Documentation/devicetree/bindings/usb/qcom,dwc3.yaml @@ -151,6 +151,11 @@ properties: HS/FS/LS modes are supported. type: boolean + qcom,enable-rt: + description: + If present, register vendor hooks to facilitate runtime suspend/resume + type: boolean + wakeup-source: true # Required child node: From patchwork Tue Oct 17 13:18:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Kurapati X-Patchwork-Id: 734988 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 242B142C1D; Tue, 17 Oct 2023 13:19:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="g443ruVI" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEC65FE; Tue, 17 Oct 2023 06:19:27 -0700 (PDT) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39H7ma5t026891; Tue, 17 Oct 2023 13:19:18 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=rgMWQvDIlBZ3I4lsQBtNwRv/iqSA1kwp0/GIONZOCzk=; b=g443ruVIIFwcRAmuu8TfxKDPsKZBnWFG26eSCCv+9QpkmJQpRYrJgWhttNNamgzbuDlA 4S/NndHDSscbWTR27bl7EotjarkOOvFgbxG8KILqlPUHPvutEhbr5dYg+n5X2G56heft fj/vA+ZapDnxaLOp2UDbXwZMyTrYnSTAZnSgEbGllEoYNtaVBTqvpBd61tqjTYpe7+Ub ji+EqP44NfckS7WOo65PkxXQxxzar3dELuEOBjvZFcKiByvs87G8kbHzyR7zjm5FQIg0 5euLWYtKfYdCWtMaeMllrJuKmsv5OKRGPr0SuJ72AB6w2qy96ISp1pgmNh9tNctBNr47 yQ== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tsd1rsq9y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 13:19:18 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39HDJFfU030793 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 13:19:15 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.39; Tue, 17 Oct 2023 06:19:11 -0700 From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Philipp Zabel , "Andy Gross" , Bjorn Andersson , "Konrad Dybcio" , Rob Herring , Krzysztof Kozlowski , Conor Dooley , CC: , , , , , , Krishna Kurapati Subject: [RFC 2/8] usb: dwc3: core: Register vendor hooks for dwc3-qcom Date: Tue, 17 Oct 2023 18:48:46 +0530 Message-ID: <20231017131851.8299-3-quic_kriskura@quicinc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017131851.8299-1-quic_kriskura@quicinc.com> References: <20231017131851.8299-1-quic_kriskura@quicinc.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] 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: 5nADOxH7sYXhkYGnJO-JCK19HEv24HaR X-Proofpoint-ORIG-GUID: 5nADOxH7sYXhkYGnJO-JCK19HEv24HaR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-17_02,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxscore=0 bulkscore=0 adultscore=0 clxscore=1015 mlxlogscore=944 spamscore=0 lowpriorityscore=0 suspectscore=0 phishscore=0 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170113 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Currently on QC targets, the conndone/disconnect events in device mode are generated by controller when software writes to QSCRATCH registers in qcom glue layer rather than the vbus line being routed to dwc3 core IP for it to recognize and generate these events. We need to write '1' to UTMI_OTG_VBUS_VALID bit of QSCRATCH_HS_PHY_CTRL register to generate a connection done event and "0" if we need to generate a disconnect event during cable removal or mode switch. Exactly what is done by "dwc3_qcom_vbus_override_enable" call in dwc3-qcom. When the disconnect is not generated upon cable removal, the connected flag of dwc3 is left marked as "true" and it blocks runtime suspend. The goal of these vendor hooks is to let the mode change and cable removal notifications from core reach the glue layers so that glue can take necessary action. Before flattening the device tree, glue driver is not sure when the core probe was completed as core probe can be deferred. In this case, glue is not sure when to register vendor hooks. So mandate enabling runtime only for flattened device node platforms so that glue can know when to register vendor hooks. The following are the requirements aimed in this implementation: 1. When enum in device mode, Glue/core must stay active. 2. When cable is connected but UDC is not written yet, then glue/core must be suspended. 3. Upon removing cable in device mode, the disconnect event must be generated and unblock runtime suspend for dwc3 core. Signed-off-by: Krishna Kurapati --- drivers/usb/dwc3/core.c | 15 ++++++- drivers/usb/dwc3/core.h | 39 +++++++++++++++++- drivers/usb/dwc3/drd.c | 9 ++++ drivers/usb/dwc3/dwc3-qcom.c | 79 ++++++++++++++++++++++++++++++++++-- 4 files changed, 136 insertions(+), 6 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 923a6c623850..53a8d92ad663 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -137,6 +137,8 @@ static void __dwc3_set_mode(struct work_struct *work) if (!desired_dr_role) goto out; + dwc3_notify_set_mode(dwc, desired_dr_role); + if (desired_dr_role == dwc->current_dr_role) goto out; @@ -1751,7 +1753,8 @@ static int dwc3_get_clocks(struct dwc3 *dwc) return 0; } -struct dwc3 *dwc3_probe(struct platform_device *pdev) +struct dwc3 *dwc3_probe(struct platform_device *pdev, + struct dwc3_glue_data *glue_data) { struct device *dev = &pdev->dev; struct resource *res, dwc_res; @@ -1765,6 +1768,11 @@ struct dwc3 *dwc3_probe(struct platform_device *pdev) dwc->dev = dev; + if (glue_data) { + dwc->glue_data = glue_data->glue_data; + dwc->glue_ops = glue_data->ops; + } + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(dev, "missing memory resource\n"); @@ -1914,7 +1922,7 @@ static int dwc3_plat_probe(struct platform_device *pdev) { struct dwc3 *dwc; - dwc = dwc3_probe(pdev); + dwc = dwc3_probe(pdev, NULL); if (IS_ERR(dwc)) return PTR_ERR(dwc); @@ -1925,6 +1933,9 @@ static int dwc3_plat_probe(struct platform_device *pdev) void dwc3_remove(struct dwc3 *dwc) { + dwc->glue_data = NULL; + dwc->glue_ops = NULL; + pm_runtime_get_sync(dwc->dev); dwc3_core_exit_mode(dwc); diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 3ec4a961befe..aefcb0d388b7 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -968,6 +968,23 @@ struct dwc3_scratchpad_array { __le64 dma_adr[DWC3_MAX_HIBER_SCRATCHBUFS]; }; +/* + * struct dwc3_glue_ops - The ops indicate the notifications that + * need to be passed on to glue layer. + * @notify_cable_disconnect: Notify glue of cable removal + * irrespective of host or device mode. + * @set_mode: Notify glue before mode change is about to happen. + */ +struct dwc3_glue_ops { + void (*notify_cable_disconnect)(void *glue_data); + void (*set_mode)(void *glue_data, u32 desired_dr_role); +}; + +struct dwc3_glue_data { + void *glue_data; + struct dwc3_glue_ops *ops; +}; + /** * struct dwc3 - representation of our controller * @drd_work: workqueue used for role swapping @@ -1124,6 +1141,9 @@ struct dwc3_scratchpad_array { * @num_ep_resized: carries the current number endpoints which have had its tx * fifo resized. * @debug_root: root debugfs directory for this device to put its files in. + * @glue_data: Private data stored by core to be passed on to glue during + * role switch notifications. + * @glue_ops: Store pointers to glue notifcation callbacks. */ struct dwc3 { struct work_struct drd_work; @@ -1340,6 +1360,9 @@ struct dwc3 { int last_fifo_depth; int num_ep_resized; struct dentry *debug_root; + + void *glue_data; + const struct dwc3_glue_ops *glue_ops; }; #define INCRX_BURST_MODE 0 @@ -1553,7 +1576,8 @@ void dwc3_event_buffers_cleanup(struct dwc3 *dwc); int dwc3_core_soft_reset(struct dwc3 *dwc); -struct dwc3 *dwc3_probe(struct platform_device *pdev); +struct dwc3 *dwc3_probe(struct platform_device *pdev, + struct dwc3_glue_data *glue_data); void dwc3_remove(struct dwc3 *dwc); int dwc3_runtime_suspend(struct dwc3 *dwc); @@ -1563,6 +1587,19 @@ int dwc3_suspend(struct dwc3 *dwc); int dwc3_resume(struct dwc3 *dwc); void dwc3_complete(struct dwc3 *dwc); +static inline void dwc3_notify_cable_disconnect(struct dwc3 *dwc) +{ + if (dwc->glue_ops && dwc->glue_ops->notify_cable_disconnect) + dwc->glue_ops->notify_cable_disconnect(dwc->glue_data); +} + +static inline void dwc3_notify_set_mode(struct dwc3 *dwc, + u32 desired_dr_role) +{ + if (dwc->glue_ops && dwc->glue_ops->set_mode) + dwc->glue_ops->set_mode(dwc->glue_data, desired_dr_role); +} + #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) int dwc3_host_init(struct dwc3 *dwc); void dwc3_host_exit(struct dwc3 *dwc); diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index 039bf241769a..947faeef0e4d 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -461,6 +461,15 @@ static int dwc3_usb_role_switch_set(struct usb_role_switch *sw, break; } + /* + * When cable is removed, the role changes to default mode. + * In the case we are in device mode and removed the cable, the + * glue needs to know that we are disconnected. It must not notify + * the change of mode to default mode. + */ + if (role == USB_ROLE_NONE) + dwc3_notify_cable_disconnect(dwc); + dwc3_set_mode(dwc, mode); return 0; } diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 3c9a2b5cd559..4013a5e6c6c0 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -88,6 +88,9 @@ struct dwc3_qcom { bool pm_suspended; struct icc_path *icc_path_ddr; struct icc_path *icc_path_apps; + + bool enable_rt; + enum usb_role current_role; }; static inline void dwc3_qcom_setbits(void __iomem *base, u32 offset, u32 val) @@ -673,16 +676,71 @@ static const struct software_node dwc3_qcom_swnode = { .properties = dwc3_qcom_acpi_properties, }; +static void dwc3_qcom_handle_cable_disconnect(void *data) +{ + struct dwc3_qcom *qcom = (struct dwc3_qcom *)data; + /* + * If we are in device mode and get a cable disconnect, + * handle it by clearing OTG_VBUS_VALID bit in wrapper. + * The next set_mode to default role can be ignored. + */ + if (qcom->current_role == USB_ROLE_DEVICE) { + pm_runtime_get_sync(qcom->dev); + dwc3_qcom_vbus_override_enable(qcom, false); + pm_runtime_put_autosuspend(qcom->dev); + } + + pm_runtime_mark_last_busy(qcom->dev); + qcom->current_role = USB_ROLE_NONE; +} + +static void dwc3_qcom_handle_set_mode(void *data, u32 desired_dr_role) +{ + struct dwc3_qcom *qcom = (struct dwc3_qcom *)data; + + /* + * If we are in device mode and get a cable disconnect, + * handle it by clearing OTG_VBUS_VALID bit in wrapper. + * The next set_mode to default role can be ignored and + * so the OTG_VBUS_VALID should be set iff the current role + * is NONE and we need to enter DEVICE mode. + */ + if ((qcom->current_role == USB_ROLE_NONE) && + (desired_dr_role == DWC3_GCTL_PRTCAP_DEVICE)) { + dwc3_qcom_vbus_override_enable(qcom, true); + qcom->current_role = USB_ROLE_DEVICE; + } else if ((desired_dr_role == DWC3_GCTL_PRTCAP_HOST) && + (qcom->current_role != USB_ROLE_HOST)) { + qcom->current_role = USB_ROLE_HOST; + } + + pm_runtime_mark_last_busy(qcom->dev); +} + +struct dwc3_glue_ops dwc3_qcom_glue_hooks = { + .notify_cable_disconnect = dwc3_qcom_handle_cable_disconnect, + .set_mode = dwc3_qcom_handle_set_mode, +}; + static int dwc3_qcom_probe_core(struct platform_device *pdev, struct dwc3_qcom *qcom) { struct dwc3 *dwc; - dwc = dwc3_probe(pdev); + struct dwc3_glue_data qcom_glue_data = { + .glue_data = qcom, + .ops = &dwc3_qcom_glue_hooks, + }; + + dwc = dwc3_probe(pdev, + qcom->enable_rt ? &qcom_glue_data : NULL); if (IS_ERR(dwc)) return PTR_ERR(dwc); qcom->dwc = dwc; + if (qcom->enable_rt) + pm_runtime_allow(qcom->dev); + return 0; } @@ -897,6 +955,23 @@ static int dwc3_qcom_probe(struct platform_device *pdev) if (ignore_pipe_clk) dwc3_qcom_select_utmi_clk(qcom); + qcom->enable_rt = device_property_read_bool(dev, + "qcom,enable-rt"); + if (!legacy_binding) { + /* + * If we are enabling runtime, then we are using flattened + * device implementation. + */ + qcom->mode = usb_get_dr_mode(dev); + + if (qcom->mode == USB_DR_MODE_HOST) + qcom->current_role = USB_ROLE_HOST; + else if (qcom->mode == USB_DR_MODE_PERIPHERAL) + qcom->current_role = USB_ROLE_DEVICE; + else + qcom->current_role = USB_ROLE_NONE; + } + if (legacy_binding) ret = dwc3_qcom_of_register_core(pdev); else @@ -913,8 +988,6 @@ static int dwc3_qcom_probe(struct platform_device *pdev) if (qcom->dwc_dev) qcom->mode = usb_get_dr_mode(&qcom->dwc_dev->dev); - else - qcom->mode = usb_get_dr_mode(dev); /* enable vbus override for device mode */ if (qcom->mode != USB_DR_MODE_HOST) From patchwork Tue Oct 17 13:18:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Kurapati X-Patchwork-Id: 735484 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 6E27442C1F; Tue, 17 Oct 2023 13:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="T65StbMH" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D96F510D; Tue, 17 Oct 2023 06:19:29 -0700 (PDT) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HCkmh4011698; Tue, 17 Oct 2023 13:19:22 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=+d1KRSggdTGEKfw6LpfvQegBYY+tc+X8fQ3kuYQ0mLA=; b=T65StbMHYtx4559usWL+NwvaTnU0wrS7tbFtHTtTx2rZKlcK7f26a/aONu3w42gZU34T rVmvc9uhKUHrcAx7lKBYNdmv0lsN/DlksLypQIUGDptckphbcMvoLwDruhjP5Kp4kOkU RTHc11sYfN/LFxIlIXycKqv9MF2QjRKTvIBjvG0dBNCEXuGc77ryeVbSjnRurYUNWzrf Sn+aXoMF8UG9ItDxWMzgO2OgbN33lVer22DM/AYoqOrfWC3Hl0Q2GkXqrXRRB+zcp6Nh G6qpxiQkPvtcR4O2rrEcQd7y0xtUpIvWSTaIKjqXWb8uYOt0vxquV4DKQY5aDwXAaOrw JA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tsb3xsyr1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 13:19:22 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39HDJLl8009197 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 13:19:21 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.39; Tue, 17 Oct 2023 06:19:16 -0700 From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Philipp Zabel , "Andy Gross" , Bjorn Andersson , "Konrad Dybcio" , Rob Herring , Krzysztof Kozlowski , Conor Dooley , CC: , , , , , , Krishna Kurapati Subject: [RFC 3/8] usb: dwc3: qcom: Enable autosuspend for host mode Date: Tue, 17 Oct 2023 18:48:47 +0530 Message-ID: <20231017131851.8299-4-quic_kriskura@quicinc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017131851.8299-1-quic_kriskura@quicinc.com> References: <20231017131851.8299-1-quic_kriskura@quicinc.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] 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: vGCiM_K0LPQoQeiAwMfksFbnVTl5ewS9 X-Proofpoint-ORIG-GUID: vGCiM_K0LPQoQeiAwMfksFbnVTl5ewS9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-17_02,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 impostorscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 priorityscore=1501 mlxscore=0 adultscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170113 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net When in host mode, enable autosuspend for xhci and root hubs. a) Register a vendor call back to get information of successful role change by core. When xhci is enumerated successfully, configure it to use_autosuspend. The decision of whether or not to do runtime_allow for xhci node is left to userspace: (echo auto > */xhci-auto/power/control). b) Register to usb-core notifications in set_mode vendor callback to identify when root hubs are being created. Configure them to use_autosuspend accordingly. c) Configure any connected device to use_autosuspend. In general for mobile use cases, autosuspend is enabled and wakeup is enabled only for hubs and audio devices. So let userspace choose to configure autosuspend_delay and wakeup capability of connected devices. Signed-off-by: Krishna Kurapati --- drivers/usb/dwc3/core.c | 3 +++ drivers/usb/dwc3/core.h | 9 ++++++++ drivers/usb/dwc3/dwc3-qcom.c | 42 ++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 53a8d92ad663..b4d1d1c98dd5 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -233,6 +233,9 @@ static void __dwc3_set_mode(struct work_struct *work) break; } + if (!ret) + dwc3_notify_mode_changed(dwc, dwc->current_dr_role); + out: pm_runtime_mark_last_busy(dwc->dev); pm_runtime_put_autosuspend(dwc->dev); diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index aefcb0d388b7..5ed7fd5eb776 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -974,10 +974,12 @@ struct dwc3_scratchpad_array { * @notify_cable_disconnect: Notify glue of cable removal * irrespective of host or device mode. * @set_mode: Notify glue before mode change is about to happen. + * @mode_changed: Notify glue that mode change was done successfully */ struct dwc3_glue_ops { void (*notify_cable_disconnect)(void *glue_data); void (*set_mode)(void *glue_data, u32 desired_dr_role); + void (*mode_changed)(void *glue_data, u32 current_dr_role); }; struct dwc3_glue_data { @@ -1600,6 +1602,13 @@ static inline void dwc3_notify_set_mode(struct dwc3 *dwc, dwc->glue_ops->set_mode(dwc->glue_data, desired_dr_role); } +static inline void dwc3_notify_mode_changed(struct dwc3 *dwc, + u32 current_dr_role) +{ + if (dwc->glue_ops && dwc->glue_ops->mode_changed) + dwc->glue_ops->mode_changed(dwc->glue_data, current_dr_role); +} + #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) int dwc3_host_init(struct dwc3 *dwc); void dwc3_host_exit(struct dwc3 *dwc); diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 4013a5e6c6c0..9c7b23888f11 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -91,6 +91,7 @@ struct dwc3_qcom { bool enable_rt; enum usb_role current_role; + struct notifier_block xhci_nb; }; static inline void dwc3_qcom_setbits(void __iomem *base, u32 offset, u32 val) @@ -676,6 +677,27 @@ static const struct software_node dwc3_qcom_swnode = { .properties = dwc3_qcom_acpi_properties, }; +static int dwc3_xhci_event_notifier(struct notifier_block *nb, + unsigned long event, void *ptr) +{ + struct usb_device *udev = ptr; + + if (event != USB_DEVICE_ADD) + return NOTIFY_DONE; + + /* + * If this is a roothub corresponding to this controller, enable autosuspend + */ + if (!udev->parent) { + pm_runtime_use_autosuspend(&udev->dev); + pm_runtime_set_autosuspend_delay(&udev->dev, 1000); + } + + usb_mark_last_busy(udev); + + return NOTIFY_DONE; +} + static void dwc3_qcom_handle_cable_disconnect(void *data) { struct dwc3_qcom *qcom = (struct dwc3_qcom *)data; @@ -688,6 +710,8 @@ static void dwc3_qcom_handle_cable_disconnect(void *data) pm_runtime_get_sync(qcom->dev); dwc3_qcom_vbus_override_enable(qcom, false); pm_runtime_put_autosuspend(qcom->dev); + } else if (qcom->current_role == USB_ROLE_HOST) { + usb_unregister_notify(&qcom->xhci_nb); } pm_runtime_mark_last_busy(qcom->dev); @@ -711,15 +735,33 @@ static void dwc3_qcom_handle_set_mode(void *data, u32 desired_dr_role) qcom->current_role = USB_ROLE_DEVICE; } else if ((desired_dr_role == DWC3_GCTL_PRTCAP_HOST) && (qcom->current_role != USB_ROLE_HOST)) { + qcom->xhci_nb.notifier_call = dwc3_xhci_event_notifier; + usb_register_notify(&qcom->xhci_nb); qcom->current_role = USB_ROLE_HOST; } pm_runtime_mark_last_busy(qcom->dev); } +static void dwc3_qcom_handle_mode_changed(void *data, u32 current_dr_role) +{ + struct dwc3_qcom *qcom = (struct dwc3_qcom *)data; + + /* + * XHCI platform device is allocated upon host init. + * So ensure we are in host mode before enabling autosuspend. + */ + if ((current_dr_role == DWC3_GCTL_PRTCAP_HOST) && + (qcom->current_role == USB_ROLE_HOST)) { + pm_runtime_use_autosuspend(&qcom->dwc->xhci->dev); + pm_runtime_set_autosuspend_delay(&qcom->dwc->xhci->dev, 0); + } +} + struct dwc3_glue_ops dwc3_qcom_glue_hooks = { .notify_cable_disconnect = dwc3_qcom_handle_cable_disconnect, .set_mode = dwc3_qcom_handle_set_mode, + .mode_changed = dwc3_qcom_handle_mode_changed, }; static int dwc3_qcom_probe_core(struct platform_device *pdev, struct dwc3_qcom *qcom) From patchwork Tue Oct 17 13:18:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Kurapati X-Patchwork-Id: 735483 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 357A6436AF; Tue, 17 Oct 2023 13:19:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="FE5bLa9t" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FBB5F5; Tue, 17 Oct 2023 06:19:34 -0700 (PDT) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HCpJkd022076; Tue, 17 Oct 2023 13:19:27 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=ONAL9UCkf5t/qAN+nBfJPyvjjZ888xT+v1gaPYIWAIA=; b=FE5bLa9t+bRax+EmiSk0cMSx0EgmQkP63ffY1zppC8cBuGvn6ossUttbXLfbbeXUnUee ludaQqsp2Po2QIgpWUVl0ZdE8wjZ4aPQW0kJmxioIh/dQTOdl84AioIkHzU4+lQkpIkZ XyYNUX0Knih9qkFVWlDlaAhBCKUTgpsnFNaJvgPR8f3nbdhszmzx2v8IS0CbIybUVLcb 5ZTjYaSJaAF27oNu++km4pqfkZdDHfdLbZTRFpkvFMB7zKiqqbJrQsnu4plMdpxyOvKI DXh+KpgPbBB/zCV3ohyPKfUUw0bNjrLhOchPj72ry5tgc+zTcwTy4CfTxMxLzlIPHsYZ EQ== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tsb3xsyra-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 13:19:27 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39HDJQWT002471 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 13:19:26 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.39; Tue, 17 Oct 2023 06:19:21 -0700 From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Philipp Zabel , "Andy Gross" , Bjorn Andersson , "Konrad Dybcio" , Rob Herring , Krzysztof Kozlowski , Conor Dooley , CC: , , , , , , Krishna Kurapati Subject: [RFC 5/8] arm64: dts: qcom: Flatten sm8450 usb device node Date: Tue, 17 Oct 2023 18:48:48 +0530 Message-ID: <20231017131851.8299-5-quic_kriskura@quicinc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017131851.8299-1-quic_kriskura@quicinc.com> References: <20231017131851.8299-1-quic_kriskura@quicinc.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] 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: 6Hx4aTXhrPS7KcMtC4E59yCFhNyy10HO X-Proofpoint-ORIG-GUID: 6Hx4aTXhrPS7KcMtC4E59yCFhNyy10HO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-17_02,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 impostorscore=0 phishscore=0 mlxlogscore=882 malwarescore=0 priorityscore=1501 mlxscore=0 adultscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170113 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Flatten usb device node by removing usb_1_dwc3 node. Verified working of ADB in device mode and enumeration of headset in host mode. Signed-off-by: Krishna Kurapati --- arch/arm64/boot/dts/qcom/sm8450-hdk.dts | 3 -- arch/arm64/boot/dts/qcom/sm8450-qrd.dts | 3 -- .../dts/qcom/sm8450-sony-xperia-nagara.dtsi | 3 -- arch/arm64/boot/dts/qcom/sm8450.dtsi | 44 +++++++++---------- 4 files changed, 21 insertions(+), 32 deletions(-) diff --git a/arch/arm64/boot/dts/qcom/sm8450-hdk.dts b/arch/arm64/boot/dts/qcom/sm8450-hdk.dts index bc4c125d1832..73b7c4f5276c 100644 --- a/arch/arm64/boot/dts/qcom/sm8450-hdk.dts +++ b/arch/arm64/boot/dts/qcom/sm8450-hdk.dts @@ -805,9 +805,6 @@ &ufs_mem_phy { &usb_1 { status = "okay"; -}; - -&usb_1_dwc3 { dr_mode = "otg"; usb-role-switch; }; diff --git a/arch/arm64/boot/dts/qcom/sm8450-qrd.dts b/arch/arm64/boot/dts/qcom/sm8450-qrd.dts index 65a94dfaf5ae..fb800d24b00b 100644 --- a/arch/arm64/boot/dts/qcom/sm8450-qrd.dts +++ b/arch/arm64/boot/dts/qcom/sm8450-qrd.dts @@ -453,9 +453,6 @@ &ufs_mem_phy { &usb_1 { status = "okay"; -}; - -&usb_1_dwc3 { dr_mode = "peripheral"; }; diff --git a/arch/arm64/boot/dts/qcom/sm8450-sony-xperia-nagara.dtsi b/arch/arm64/boot/dts/qcom/sm8450-sony-xperia-nagara.dtsi index 001fb2723fbb..9ba6db3d54f8 100644 --- a/arch/arm64/boot/dts/qcom/sm8450-sony-xperia-nagara.dtsi +++ b/arch/arm64/boot/dts/qcom/sm8450-sony-xperia-nagara.dtsi @@ -778,9 +778,6 @@ &uart7 { &usb_1 { status = "okay"; -}; - -&usb_1_dwc3 { dr_mode = "peripheral"; }; diff --git a/arch/arm64/boot/dts/qcom/sm8450.dtsi b/arch/arm64/boot/dts/qcom/sm8450.dtsi index 5cd7296c7660..3785a4625aff 100644 --- a/arch/arm64/boot/dts/qcom/sm8450.dtsi +++ b/arch/arm64/boot/dts/qcom/sm8450.dtsi @@ -4270,7 +4270,7 @@ opp-202000000 { usb_1: usb@a6f8800 { compatible = "qcom,sm8450-dwc3", "qcom,dwc3"; - reg = <0 0x0a6f8800 0 0x400>; + reg = <0 0x0a600000 0 0x200000>; status = "disabled"; #address-cells = <2>; #size-cells = <2>; @@ -4293,11 +4293,13 @@ usb_1: usb@a6f8800 { <&gcc GCC_USB30_PRIM_MASTER_CLK>; assigned-clock-rates = <19200000>, <200000000>; - interrupts-extended = <&intc GIC_SPI 130 IRQ_TYPE_LEVEL_HIGH>, + interrupts-extended = <&intc GIC_SPI 133 IRQ_TYPE_LEVEL_HIGH>, + <&intc GIC_SPI 130 IRQ_TYPE_LEVEL_HIGH>, <&pdc 17 IRQ_TYPE_LEVEL_HIGH>, <&pdc 15 IRQ_TYPE_EDGE_BOTH>, <&pdc 14 IRQ_TYPE_EDGE_BOTH>; - interrupt-names = "hs_phy_irq", + interrupt-names = "dwc_usb3", + "hs_phy_irq", "ss_phy_irq", "dm_hs_phy_irq", "dp_hs_phy_irq"; @@ -4310,32 +4312,28 @@ usb_1: usb@a6f8800 { <&gem_noc MASTER_APPSS_PROC 0 &config_noc SLAVE_USB3_0 0>; interconnect-names = "usb-ddr", "apps-usb"; - usb_1_dwc3: usb@a600000 { - compatible = "snps,dwc3"; - reg = <0 0x0a600000 0 0xcd00>; - interrupts = ; - iommus = <&apps_smmu 0x0 0x0>; - snps,dis_u2_susphy_quirk; - snps,dis_enblslpm_quirk; - phys = <&usb_1_hsphy>, <&usb_1_qmpphy QMP_USB43DP_USB3_PHY>; - phy-names = "usb2-phy", "usb3-phy"; + iommus = <&apps_smmu 0x0 0x0>; + snps,dis_u2_susphy_quirk; + snps,dis_enblslpm_quirk; - ports { - #address-cells = <1>; - #size-cells = <0>; + phys = <&usb_1_hsphy>, <&usb_1_qmpphy QMP_USB43DP_USB3_PHY>; + phy-names = "usb2-phy", "usb3-phy"; - port@0 { - reg = <0>; + ports { + #address-cells = <1>; + #size-cells = <0>; - usb_1_dwc3_hs: endpoint { - }; + port@0 { + reg = <0>; + + usb_1_dwc3_hs: endpoint { }; + }; - port@1 { - reg = <1>; + port@1 { + reg = <1>; - usb_1_dwc3_ss: endpoint { - }; + usb_1_dwc3_ss: endpoint { }; }; }; From patchwork Tue Oct 17 13:18:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Kurapati X-Patchwork-Id: 734986 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 9A91E43684; Tue, 17 Oct 2023 13:19:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="ewCerEXQ" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E7F7122; Tue, 17 Oct 2023 06:19:39 -0700 (PDT) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HD78Yq004257; Tue, 17 Oct 2023 13:19:32 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=omuWM003BT3MJQaVLbit0OGTV2xNjQ09oSQOKrMSkGI=; b=ewCerEXQ4xLmmpMWnu7c+BemPnOeyC5mL72uG4FTqb9Z3C0ba1BnVPw8jbKTH/GXZmpP drxm5uHy/efAn4C91v50K4v4rrzvFf2RMxqpsjwu6suDx0b2nPieJJoYniwWfO2wyg36 8coJ6mw+IW1qFQL+6am79IPRI4XVfpQBmFwP9ZzN2+m98CTssgY9wpQF1Gb0xHk1A58r fRaHWMIA3e5/dfyR2zpL0SpiGji3m56V4VlLXVio9kVc1+qGzSR/Zxd1oPR5+1WG50LF BkP1lzkBEAa/9QqcsPVvu620yTjbWE9C1MPShn5GPtgbx2WC9BFKD2D0FGRMfzeLIdns Bw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tstv9r0un-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 13:19:32 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39HDJVLU009503 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 13:19:32 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.39; Tue, 17 Oct 2023 06:19:26 -0700 From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Philipp Zabel , "Andy Gross" , Bjorn Andersson , "Konrad Dybcio" , Rob Herring , Krzysztof Kozlowski , Conor Dooley , CC: , , , , , , Krishna Kurapati Subject: [RFC 6/8] arm: dts: qcom: Add pmic glink support for sm8450-qrd Date: Tue, 17 Oct 2023 18:48:49 +0530 Message-ID: <20231017131851.8299-6-quic_kriskura@quicinc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017131851.8299-1-quic_kriskura@quicinc.com> References: <20231017131851.8299-1-quic_kriskura@quicinc.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] 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: rGxtpp6Tl0RSZ_77yb1HVCqPdr0OpooL X-Proofpoint-ORIG-GUID: rGxtpp6Tl0RSZ_77yb1HVCqPdr0OpooL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-17_02,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 priorityscore=1501 mlxlogscore=684 impostorscore=0 suspectscore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 malwarescore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170113 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Add Pmic Glink support for sm8450-qrd to facilitate passing of roe switch notifications generated by ADSP to dwc3 core via ucsi and pmic glink's. Signed-off-by: Krishna Kurapati Reviewed-by: Krzysztof Kozlowski --- arch/arm64/boot/dts/qcom/sm8450-qrd.dts | 46 ++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/qcom/sm8450-qrd.dts b/arch/arm64/boot/dts/qcom/sm8450-qrd.dts index fb800d24b00b..aec47e45284e 100644 --- a/arch/arm64/boot/dts/qcom/sm8450-qrd.dts +++ b/arch/arm64/boot/dts/qcom/sm8450-qrd.dts @@ -27,6 +27,40 @@ chosen { stdout-path = "serial0:115200n8"; }; + pmic-glink { + compatible = "qcom,sm8450-pmic-glink", "qcom,pmic-glink"; + #address-cells = <1>; + #size-cells = <0>; + + connector@0 { + compatible = "usb-c-connector"; + reg = <0>; + power-role = "dual"; + data-role = "dual"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + pmic_glink_hs_in: endpoint { + remote-endpoint = <&usb_1_dwc3_hs>; + }; + }; + + port@1 { + reg = <1>; + + pmic_glink_ss_in: endpoint { + remote-endpoint = <&usb_1_dwc3_ss>; + }; + }; + }; + }; + }; + vph_pwr: vph-pwr-regulator { compatible = "regulator-fixed"; regulator-name = "vph_pwr"; @@ -453,7 +487,17 @@ &ufs_mem_phy { &usb_1 { status = "okay"; - dr_mode = "peripheral"; + + dr_mode = "otg"; + usb-role-switch; +}; + +&usb_1_dwc3_hs { + remote-endpoint = <&pmic_glink_hs_in>; +}; + +&usb_1_dwc3_ss { + remote-endpoint = <&pmic_glink_ss_in>; }; &usb_1_hsphy { From patchwork Tue Oct 17 13:18:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Kurapati X-Patchwork-Id: 735482 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 30B9B3B2B1; Tue, 17 Oct 2023 13:19:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="VYAGxS60" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8633310D; Tue, 17 Oct 2023 06:19:45 -0700 (PDT) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HD7r7m005672; Tue, 17 Oct 2023 13:19:38 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=NeT+IRRuva6DpKf1d3DVM+LAzJk7rHkcj0Io7+v/HYY=; b=VYAGxS60/dK4hI97FRD4Lmmc6y4gcce1kEla4froM0dEdsTrfmGd4P0iBIMC9hfCidIV Kq4Dqhvd/sVYs8IIBedfjoaFOpKEpS7KVT1WRVObwwF0tmJtozRVx5ViN5pcnWHyG8HA WLLfi6JyAH5/IEKB4qwvVLvaphRJim65i38w/tYFevUctVRJtflcmcRk5/vQWXFIca+0 rvMmczBrUljsyPuXLznSZZ0B+jGjbAGIvbuDpg2juqjzmZu837bUBHGFAJILLGLbAbZA YJFiEQkgS8NlAiKo5uFw6ZIPxtMGLYex7CNtz6caggggjGOEpC6oBiddir2x9JhNkhtQ vA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tstv9r0v3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 13:19:37 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39HDJbJb009518 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 13:19:37 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.39; Tue, 17 Oct 2023 06:19:32 -0700 From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Philipp Zabel , "Andy Gross" , Bjorn Andersson , "Konrad Dybcio" , Rob Herring , Krzysztof Kozlowski , Conor Dooley , CC: , , , , , , Krishna Kurapati Subject: [RFC 7/8] arm: dts: qcom: Enable runtime for SM8450 QRD Date: Tue, 17 Oct 2023 18:48:50 +0530 Message-ID: <20231017131851.8299-7-quic_kriskura@quicinc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017131851.8299-1-quic_kriskura@quicinc.com> References: <20231017131851.8299-1-quic_kriskura@quicinc.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] 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: OPQNKBZ_sU67acFWmnqY8aHU4VFZHiYT X-Proofpoint-ORIG-GUID: OPQNKBZ_sU67acFWmnqY8aHU4VFZHiYT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-17_02,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 priorityscore=1501 mlxlogscore=450 impostorscore=0 suspectscore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 malwarescore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170113 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Enable runtime and wakeup source for SM8450 QRD platform. Signed-off-by: Krishna Kurapati --- arch/arm64/boot/dts/qcom/sm8450-qrd.dts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/boot/dts/qcom/sm8450-qrd.dts b/arch/arm64/boot/dts/qcom/sm8450-qrd.dts index aec47e45284e..d3e8fe7a37ec 100644 --- a/arch/arm64/boot/dts/qcom/sm8450-qrd.dts +++ b/arch/arm64/boot/dts/qcom/sm8450-qrd.dts @@ -490,6 +490,9 @@ &usb_1 { dr_mode = "otg"; usb-role-switch; + + qcom,enable-rt; + wakeup-source; }; &usb_1_dwc3_hs { From patchwork Tue Oct 17 13:18:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Kurapati X-Patchwork-Id: 734985 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 C67E542C1E; Tue, 17 Oct 2023 13:19:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="hTtTMYMp" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACAC9198; Tue, 17 Oct 2023 06:19:50 -0700 (PDT) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HCiLAE029249; Tue, 17 Oct 2023 13:19:43 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=AlcgEQhkV+CHWGIIVMx9+hfGbBgrSjeMLC+vJ2luDV4=; b=hTtTMYMp2TLd/LsJrkqlcYy18gI9gDFly+1vM9OonK4kLHsTlF6H1b0dPbkdNGyG0Nf6 soj7OsdcKxoLb/bhoy/OJGsKtbuiobQ2Cdpgk8dqN8AAHo9EVuHtVKcgOGdc2mTqQ/Zy 4N07/1cDfKTsQ9GYm3EytZmo35UdggUijspNLtVvJ9Rc+9+8pKwbWkEQLm0uLq0iDnLR 1dYQoVirWbNnU710ErIy08U5xvgKzPI0rXUEZbgM6KWM1/k3A+r+FtCE4C6WMN/JSeg5 ZHyFUhXNK8FFiJRld0eJiZYsEGk7ua+evQPdFdyGyoHLT5BWpSnDsrLunVs7O3xXtljt 2A== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tsnearqfy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 13:19:43 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39HDJffC031191 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 13:19:41 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.39; Tue, 17 Oct 2023 06:19:37 -0700 From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Philipp Zabel , "Andy Gross" , Bjorn Andersson , "Konrad Dybcio" , Rob Herring , Krzysztof Kozlowski , Conor Dooley , CC: , , , , , , Krishna Kurapati Subject: [RFC 8/8] usb: dwc3: core: Skip set_mode notification if cable is disconnected Date: Tue, 17 Oct 2023 18:48:51 +0530 Message-ID: <20231017131851.8299-8-quic_kriskura@quicinc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017131851.8299-1-quic_kriskura@quicinc.com> References: <20231017131851.8299-1-quic_kriskura@quicinc.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] 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: nbexWgWYIv3y0j0BHEC-vxIxYccZY9hc X-Proofpoint-ORIG-GUID: nbexWgWYIv3y0j0BHEC-vxIxYccZY9hc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-17_02,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 phishscore=0 impostorscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 mlxscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170113 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net In device mode use cases, the following sequence of actions are observed: 1. Cable disconnect happens and clears qscratch HS_PHY_CTRL_REG properly 2. Disconnect event is generated and "connected" flag turns false. 3. Then the setmode notification from core goes to glue 4. Glue will set back the qscratch HS_PHY_CTRL_REG bits again. At this point, since the cable is removed, setting qscratch bits shouldn't affect anything. But it is observed that after setting this bits, the controller generated Event-0x101 and Event-0x30601 (bus reset and suspend) in order. In bus reset, we set back the "connected" flag and this blocks suspend again. So send set_mode call only if the cable is connected, else skip it. Signed-off-by: Krishna Kurapati --- drivers/usb/dwc3/core.c | 3 ++- drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/drd.c | 6 +++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index b4d1d1c98dd5..6ef1e3558384 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -137,7 +137,8 @@ static void __dwc3_set_mode(struct work_struct *work) if (!desired_dr_role) goto out; - dwc3_notify_set_mode(dwc, desired_dr_role); + if (dwc->cable_disconnected == false) + dwc3_notify_set_mode(dwc, desired_dr_role); if (desired_dr_role == dwc->current_dr_role) goto out; diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 5ed7fd5eb776..1b79c407a798 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1365,6 +1365,8 @@ struct dwc3 { void *glue_data; const struct dwc3_glue_ops *glue_ops; + + bool cable_disconnected; }; #define INCRX_BURST_MODE 0 diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index 947faeef0e4d..b3a87c40c4f1 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -446,6 +446,8 @@ static int dwc3_usb_role_switch_set(struct usb_role_switch *sw, struct dwc3 *dwc = usb_role_switch_get_drvdata(sw); u32 mode; + dwc->cable_disconnected = false; + switch (role) { case USB_ROLE_HOST: mode = DWC3_GCTL_PRTCAP_HOST; @@ -467,8 +469,10 @@ static int dwc3_usb_role_switch_set(struct usb_role_switch *sw, * glue needs to know that we are disconnected. It must not notify * the change of mode to default mode. */ - if (role == USB_ROLE_NONE) + if (role == USB_ROLE_NONE) { + dwc->cable_disconnected = true; dwc3_notify_cable_disconnect(dwc); + } dwc3_set_mode(dwc, mode); return 0;