From patchwork Fri Apr 11 03:50:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 880525 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 6401E27CB3E for ; Fri, 11 Apr 2025 03:50:28 +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=1744343430; cv=none; b=D4nWsvMrCCh333QrijjdeOh+3EJgn8i2STO2mgheJNXNBVH2ikAA6tctrejA+Rg6kTYL2tE9u6cwO3ym8ztSA6UmMslF11BHbip09JifzGBuYJB/SRKgRT865mc9Sn6pxqUhfMYzEIfqgACCsRdzFjVidGSKY9bhhoYKBo9Axec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744343430; c=relaxed/simple; bh=YWW7h0HqgMyquql1fS+ddwkaCtxiI0GAg99bBKTcrm4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j1aEu+TQWl2zKVWCdZ1J6/h9MNS98G7EXdaGxzwrs7BxtkhOJZqUdVT4gA0W9yQPc1ZpMr7Da7Haq+ifDGwjjiLRWHYoydnEuVONyj1DUdTf9fEHb0iWFkMIXr7nEfBKDYfqR49QgHcSz5oKL7IO/g1ERGHvxW2Dyq8B3QZTRqQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=CR8uSCmr; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="CR8uSCmr" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53AFpdm6013884 for ; Fri, 11 Apr 2025 03:50:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= mibg4A5wcjWCC2c2KQWPOXgTNM8hWkyl49cSAZ9jgiw=; b=CR8uSCmrcDtI+eUo EeD38A63gW9oMEb/C5DCXy04RSECBUzDgHpCgUa66fr6uMCdyP2LEM1wPXJuMZ23 CSFpQ1m/3qLf9S+gyDX8xKQdGACQgQs3tyk0Ax+/7Bks5DaXV9WNegtbb7O+RJsC Xx4Koo8yuatJt9Y8mtvskps/O42QP+Oy41UrLcmqZdn4rj/88j9d2SUv8jJMqhLX JqDDtNKeTySKnK9sxm0hEMNgVpC0Z7QFqXZsz+4VSUgM6W5zef+8joszdCNuSxJN g+POpTyZJRsSa0ho2k2cLmchgLUUbtBM2HpSg/Ces1MJJ8TIX1LVd5oaXbrA4PET eeGHlQ== Received: from mail-oa1-f69.google.com (mail-oa1-f69.google.com [209.85.160.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 45twbeh4jp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 11 Apr 2025 03:50:27 +0000 (GMT) Received: by mail-oa1-f69.google.com with SMTP id 586e51a60fabf-2c2a9abc5b2so441030fac.1 for ; Thu, 10 Apr 2025 20:50:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744343426; x=1744948226; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mibg4A5wcjWCC2c2KQWPOXgTNM8hWkyl49cSAZ9jgiw=; b=R5pok7dEASFuVVEYEyGWsb1UUCdA90Ps6GAKNqsGRj7Vnm5ZhItwuBQAVy6ltSYJJJ BQMgmbHAhCZC5KUzo0QOCK1mDKoIpL+Xh8TNEv2yTAAxr27+SIzKUdDmWQteJojpLQhs d30Qdh3wygC0q13/CktszgmiWRM5B4ZrLvFQnrGyBaOq+7gklBDI4xr2W/KQP3GyQY3c 7AqdD+V6dtkqfMjHRF/jCrYUkKOb8Fy2Dt1PTbmDXWWppRd0IT/7J2ZHPoYazRcwR/ns q5P1wLOKoavBGaHAY6n3m2X3f8hkKIT0iIyHmTJUFObTGCWdD76gSMoKgIDn5CEaP1b6 Ysow== X-Forwarded-Encrypted: i=1; AJvYcCXsWrIS1leVgNiF/tDO1fmgc6WgY0x2awJccndMp9c4vpv1l8UkcqUphAox/kCts6ZkdpCGtXMZ5vs=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8IBjvScF0IEn2TMA+JzOR/aXXsTT7H53AgaxW9oANempmu6ty QbfOIckn5s3bTY2A3FtZHKHv/pU4gK+qYf5qTeqRs/nLMUuJ1uV1u144PUj4wKXl1GNi/bZATO2 m9MtVE5e6UHSDN9q1FDAx7i++Q+/hM7ms1nuFscKkbZxBnsEWU7pNMXuqbTw= X-Gm-Gg: ASbGncvBoRE+06FStshnBs7wUGxgL/Ud7wY5FqkgYplGIhboBWxb56n+v2Np6lnSl1E z4O+VwioE/vT2CExApZGgI5F0MOi/AjkFhhoQQ3+WWbU+ztgxu/RNI4cmVtgxaulME7R+28NxWH t2uU45ffJ/JgQWmHHkhDN8fJDSceDH2p3TQ9uLBU5mBhfCoZIPTYsaOqUW6hXF3NDldHDDTDVB0 F5Qv6kCXbBCY4vJ9RNuMUCyVwIkcMe+xurJ+90wOuyTco4L6Ob0/Hmgja0Aqju0ojV8tW/KTBpx l9ZmrnzAnNKwkvE7DwWax7cDnEvgxEfXeqHgDsTKNU1ms0G5y0kiHvkjDxLAVCpeS+xxi7ZfQV3 CWdqpI7r1yLA= X-Received: by 2002:a05:6871:a582:b0:2c2:c92a:5781 with SMTP id 586e51a60fabf-2d0d5ed9bc6mr710730fac.27.1744343426206; Thu, 10 Apr 2025 20:50:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCM5uRUxNmo8OjmkNzjASsAxb0t8uZgMe3M00GtjrExTBzyerRFo2u5RUSvt3F5lRIC2xwBA== X-Received: by 2002:a05:6871:a582:b0:2c2:c92a:5781 with SMTP id 586e51a60fabf-2d0d5ed9bc6mr710726fac.27.1744343425793; Thu, 10 Apr 2025 20:50:25 -0700 (PDT) Received: from [192.168.86.65] (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-2d0969589basm958677fac.19.2025.04.10.20.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 20:50:25 -0700 (PDT) From: Bjorn Andersson Date: Thu, 10 Apr 2025 22:50:14 -0500 Subject: [PATCH v6 3/6] usb: dwc3: core: Expose core driver as library Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250410-dwc3-refactor-v6-3-dc0d1b336135@oss.qualcomm.com> References: <20250410-dwc3-refactor-v6-0-dc0d1b336135@oss.qualcomm.com> In-Reply-To: <20250410-dwc3-refactor-v6-0-dc0d1b336135@oss.qualcomm.com> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Felipe Balbi , Wesley Cheng , Saravana Kannan , Thinh Nguyen , Philipp Zabel , Bjorn Andersson , Konrad Dybcio , Frank Li Cc: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Andersson X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=10188; i=bjorn.andersson@oss.qualcomm.com; h=from:subject:message-id; bh=YWW7h0HqgMyquql1fS+ddwkaCtxiI0GAg99bBKTcrm4=; b=owEBgwJ8/ZANAwAIAQsfOT8Nma3FAcsmYgBn+JF9VxuKSCf5swaUGAlT+Y3KpsZkiVLxVd+bZ hqnC9HS9lOJAkkEAAEIADMWIQQF3gPMXzXqTwlm1SULHzk/DZmtxQUCZ/iRfRUcYW5kZXJzc29u QGtlcm5lbC5vcmcACgkQCx85Pw2ZrcVOMw//T6LuVh86V0bhjrPCzBaAXUxmKY2kr0oZxapsbGm XA9rgPdPqZyLamGOT54gDLlvR7ik/1vciKtKoJUir3AxMdmw9Y6ZCw8Fs88ryc03QmogZh4yh/T ZYa/xC9gemSquvSGTzadllCK2am0Pb860fIwLE3VuQL0lMwFVrzkrmWCjaX7UmxmvZ1T02RSK8g CDYYdb8siK1XFFe/ALgU8L2XVqzPwNKfGJdNzzLklO5Y0MT7QhI6Td7aVplhPcLR7PlIjRRs/cV TnS1riHqW6Wb6pC6Go8rAvCjovBk4ionp2kCe+YSl0jf74teJClB6vz4H7nqMHsfaSc+omeAiim q03qSyl3TsGqngMLyFxNwa6E+kYdjDJ4Fv8RqGbmnyKut3qaeHgw4vslxXUIN3E/Sj3sveVvNLq MrR2n4vo4RXd2Avcw0qfsGaDiVFGLJL7tmTH18tmGqEKU9RdbPd8HSDgg8UKkJsQnS0YcEf/c09 /vuUw8D9mzV+hckjTZvdA5FdvVnNlK/N1HPfl+HPLXf5oQ2y/qmtPT2cDkt7cQYtjRvwFenOe1C TAEyBSgPGKR4K9x6eo9EOZAVp1cuG0VjTaJjBS+odV+aujGU6sVJI0742v8BR0PS3GHRII+9V6n zBD1KTWMCZ6+Ft0F2nShQxvqXL0fE5qMF9T/ojlCf42k= X-Developer-Key: i=bjorn.andersson@oss.qualcomm.com; a=openpgp; fpr=05DE03CC5F35EA4F0966D5250B1F393F0D99ADC5 X-Proofpoint-GUID: w4GR_e8kfYZMgcvOEtO-51Ff-YtFq8QF X-Authority-Analysis: v=2.4 cv=T7OMT+KQ c=1 sm=1 tr=0 ts=67f89183 cx=c_pps a=zPxD6eHSjdtQ/OcAcrOFGw==:117 a=DaeiM5VmU20ml6RIjrOvYw==:17 a=IkcTkHD0fZMA:10 a=XR8D0OoHHMoA:10 a=jIQo8A4GAAAA:8 a=EUspDBNiAAAA:8 a=bGkOf_LmPnIWPiKmcZAA:9 a=QEXdDO2ut3YA:10 a=y8BKWJGFn5sdPF1Y92-H:22 X-Proofpoint-ORIG-GUID: w4GR_e8kfYZMgcvOEtO-51Ff-YtFq8QF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-11_01,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 adultscore=0 phishscore=0 bulkscore=0 mlxscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 spamscore=0 clxscore=1015 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2504110026 The DWC3 IP block is handled by three distinct device drivers: XHCI, DWC3 core and a platform specific (optional) DWC3 glue driver. This has resulted in, at least in the case of the Qualcomm glue, the presence of a number of layering violations, where the glue code either can't handle, or has to work around, the fact that core might not probe deterministically. An example of this is that the suspend path should operate slightly different depending on the device operating in host or peripheral mode, and the only way to determine the operating state is to peek into the core's drvdata. The Qualcomm glue driver is expected to make updates in the qscratch register region (the "glue" region) during role switch events, but with the glue and core split using the driver model, there is no reasonable way to introduce listeners for mode changes. Split the dwc3 core platform_driver callbacks and their implementation and export the implementation, to make it possible to deterministically instantiate the dwc3 core as part of the dwc3 glue drivers and to allow flattening of the DeviceTree representation. Acked-by: Thinh Nguyen Signed-off-by: Bjorn Andersson --- drivers/usb/dwc3/core.c | 142 +++++++++++++++++++++++++++++++++--------------- drivers/usb/dwc3/glue.h | 32 +++++++++++ 2 files changed, 129 insertions(+), 45 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 66a08b5271653abd458f9ec85ca730afd7779d71..b428b6fc3d0a55811e2f75d33d79df4b0c67dcac 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -36,6 +36,7 @@ #include "core.h" #include "gadget.h" +#include "glue.h" #include "io.h" #include "debug.h" @@ -2148,27 +2149,16 @@ static struct power_supply *dwc3_get_usb_power_supply(struct dwc3 *dwc) return usb_psy; } -static int dwc3_probe(struct platform_device *pdev) +int dwc3_core_probe(const struct dwc3_probe_data *data) { - struct device *dev = &pdev->dev; - struct resource *res, dwc_res; + struct dwc3 *dwc = data->dwc; + struct device *dev = dwc->dev; + struct resource dwc_res; unsigned int hw_mode; void __iomem *regs; - struct dwc3 *dwc; + struct resource *res = data->res; int ret; - dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); - if (!dwc) - return -ENOMEM; - - dwc->dev = dev; - - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - dev_err(dev, "missing memory resource\n"); - return -ENODEV; - } - dwc->xhci_resources[0].start = res->start; dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + DWC3_XHCI_REGS_END; @@ -2232,7 +2222,7 @@ static int dwc3_probe(struct platform_device *pdev) goto err_disable_clks; } - platform_set_drvdata(pdev, dwc); + dev_set_drvdata(dev, dwc); dwc3_cache_hwparams(dwc); if (!dwc->sysdev_is_parent && @@ -2327,12 +2317,35 @@ static int dwc3_probe(struct platform_device *pdev) return ret; } +EXPORT_SYMBOL_GPL(dwc3_core_probe); -static void dwc3_remove(struct platform_device *pdev) +static int dwc3_probe(struct platform_device *pdev) { - struct dwc3 *dwc = platform_get_drvdata(pdev); + struct dwc3_probe_data probe_data; + struct resource *res; + struct dwc3 *dwc; - pm_runtime_get_sync(&pdev->dev); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(&pdev->dev, "missing memory resource\n"); + return -ENODEV; + } + + dwc = devm_kzalloc(&pdev->dev, sizeof(*dwc), GFP_KERNEL); + if (!dwc) + return -ENOMEM; + + dwc->dev = &pdev->dev; + + probe_data.dwc = dwc; + probe_data.res = res; + + return dwc3_core_probe(&probe_data); +} + +void dwc3_core_remove(struct dwc3 *dwc) +{ + pm_runtime_get_sync(dwc->dev); dwc3_core_exit_mode(dwc); dwc3_debugfs_exit(dwc); @@ -2340,22 +2353,28 @@ static void dwc3_remove(struct platform_device *pdev) dwc3_core_exit(dwc); dwc3_ulpi_exit(dwc); - pm_runtime_allow(&pdev->dev); - pm_runtime_disable(&pdev->dev); - pm_runtime_dont_use_autosuspend(&pdev->dev); - pm_runtime_put_noidle(&pdev->dev); + pm_runtime_allow(dwc->dev); + pm_runtime_disable(dwc->dev); + pm_runtime_dont_use_autosuspend(dwc->dev); + pm_runtime_put_noidle(dwc->dev); /* * HACK: Clear the driver data, which is currently accessed by parent * glue drivers, before allowing the parent to suspend. */ - platform_set_drvdata(pdev, NULL); - pm_runtime_set_suspended(&pdev->dev); + dev_set_drvdata(dwc->dev, NULL); + pm_runtime_set_suspended(dwc->dev); dwc3_free_event_buffers(dwc); if (dwc->usb_psy) power_supply_put(dwc->usb_psy); } +EXPORT_SYMBOL_GPL(dwc3_core_remove); + +static void dwc3_remove(struct platform_device *pdev) +{ + dwc3_core_remove(platform_get_drvdata(pdev)); +} #ifdef CONFIG_PM static int dwc3_core_init_for_resume(struct dwc3 *dwc) @@ -2544,9 +2563,8 @@ static int dwc3_runtime_checks(struct dwc3 *dwc) return 0; } -static int dwc3_runtime_suspend(struct device *dev) +int dwc3_runtime_suspend(struct dwc3 *dwc) { - struct dwc3 *dwc = dev_get_drvdata(dev); int ret; if (dwc3_runtime_checks(dwc)) @@ -2558,10 +2576,11 @@ static int dwc3_runtime_suspend(struct device *dev) return 0; } +EXPORT_SYMBOL_GPL(dwc3_runtime_suspend); -static int dwc3_runtime_resume(struct device *dev) +int dwc3_runtime_resume(struct dwc3 *dwc) { - struct dwc3 *dwc = dev_get_drvdata(dev); + struct device *dev = dwc->dev; int ret; ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME); @@ -2571,7 +2590,7 @@ static int dwc3_runtime_resume(struct device *dev) switch (dwc->current_dr_role) { case DWC3_GCTL_PRTCAP_DEVICE: if (dwc->pending_events) { - pm_runtime_put(dwc->dev); + pm_runtime_put(dev); dwc->pending_events = false; enable_irq(dwc->irq_gadget); } @@ -2586,10 +2605,11 @@ static int dwc3_runtime_resume(struct device *dev) return 0; } +EXPORT_SYMBOL_GPL(dwc3_runtime_resume); -static int dwc3_runtime_idle(struct device *dev) +int dwc3_runtime_idle(struct dwc3 *dwc) { - struct dwc3 *dwc = dev_get_drvdata(dev); + struct device *dev = dwc->dev; switch (dwc->current_dr_role) { case DWC3_GCTL_PRTCAP_DEVICE: @@ -2607,12 +2627,28 @@ static int dwc3_runtime_idle(struct device *dev) return 0; } +EXPORT_SYMBOL_GPL(dwc3_runtime_idle); + +static int dwc3_plat_runtime_suspend(struct device *dev) +{ + return dwc3_runtime_suspend(dev_get_drvdata(dev)); +} + +static int dwc3_plat_runtime_resume(struct device *dev) +{ + return dwc3_runtime_resume(dev_get_drvdata(dev)); +} + +static int dwc3_plat_runtime_idle(struct device *dev) +{ + return dwc3_runtime_idle(dev_get_drvdata(dev)); +} #endif /* CONFIG_PM */ #ifdef CONFIG_PM_SLEEP -static int dwc3_suspend(struct device *dev) +int dwc3_pm_suspend(struct dwc3 *dwc) { - struct dwc3 *dwc = dev_get_drvdata(dev); + struct device *dev = dwc->dev; int ret; ret = dwc3_suspend_common(dwc, PMSG_SUSPEND); @@ -2623,10 +2659,11 @@ static int dwc3_suspend(struct device *dev) return 0; } +EXPORT_SYMBOL_GPL(dwc3_pm_suspend); -static int dwc3_resume(struct device *dev) +int dwc3_pm_resume(struct dwc3 *dwc) { - struct dwc3 *dwc = dev_get_drvdata(dev); + struct device *dev = dwc->dev; int ret = 0; pinctrl_pm_select_default_state(dev); @@ -2645,10 +2682,10 @@ static int dwc3_resume(struct device *dev) return ret; } +EXPORT_SYMBOL_GPL(dwc3_pm_resume); -static void dwc3_complete(struct device *dev) +void dwc3_pm_complete(struct dwc3 *dwc) { - struct dwc3 *dwc = dev_get_drvdata(dev); u32 reg; if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && @@ -2658,21 +2695,36 @@ static void dwc3_complete(struct device *dev) dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); } } +EXPORT_SYMBOL_GPL(dwc3_pm_complete); + +static int dwc3_plat_suspend(struct device *dev) +{ + return dwc3_pm_suspend(dev_get_drvdata(dev)); +} + +static int dwc3_plat_resume(struct device *dev) +{ + return dwc3_pm_resume(dev_get_drvdata(dev)); +} + +static void dwc3_plat_complete(struct device *dev) +{ + dwc3_pm_complete(dev_get_drvdata(dev)); +} #else -#define dwc3_complete NULL +#define dwc3_plat_complete NULL #endif /* CONFIG_PM_SLEEP */ static const struct dev_pm_ops dwc3_dev_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume) - .complete = dwc3_complete, - + SET_SYSTEM_SLEEP_PM_OPS(dwc3_plat_suspend, dwc3_plat_resume) + .complete = dwc3_plat_complete, /* * Runtime suspend halts the controller on disconnection. It relies on * platforms with custom connection notification to start the controller * again. */ - SET_RUNTIME_PM_OPS(dwc3_runtime_suspend, dwc3_runtime_resume, - dwc3_runtime_idle) + SET_RUNTIME_PM_OPS(dwc3_plat_runtime_suspend, dwc3_plat_runtime_resume, + dwc3_plat_runtime_idle) }; #ifdef CONFIG_OF diff --git a/drivers/usb/dwc3/glue.h b/drivers/usb/dwc3/glue.h new file mode 100644 index 0000000000000000000000000000000000000000..e73cfc466012f07214291abe56454934ab014013 --- /dev/null +++ b/drivers/usb/dwc3/glue.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * glue.h - DesignWare USB3 DRD glue header + */ + +#ifndef __DRIVERS_USB_DWC3_GLUE_H +#define __DRIVERS_USB_DWC3_GLUE_H + +#include +#include "core.h" + +/** + * dwc3_probe_data: Initialization parameters passed to dwc3_core_probe() + * @dwc: Reference to dwc3 context structure + * @res: resource for the DWC3 core mmio region + */ +struct dwc3_probe_data { + struct dwc3 *dwc; + struct resource *res; +}; + +int dwc3_core_probe(const struct dwc3_probe_data *data); +void dwc3_core_remove(struct dwc3 *dwc); + +int dwc3_runtime_suspend(struct dwc3 *dwc); +int dwc3_runtime_resume(struct dwc3 *dwc); +int dwc3_runtime_idle(struct dwc3 *dwc); +int dwc3_pm_suspend(struct dwc3 *dwc); +int dwc3_pm_resume(struct dwc3 *dwc); +void dwc3_pm_complete(struct dwc3 *dwc); + +#endif From patchwork Fri Apr 11 03:50:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 880524 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 9922F27CCE1 for ; Fri, 11 Apr 2025 03:50:30 +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=1744343432; cv=none; b=ZJ3T6iHq+9jJcI5E3fNW0JKr9P8OisLkmtVx9XE5f5d0pe/w3CQWpXHP/Yz1Vh6TaNEemI4V9OGM3+X7AmdBvak2xidEGzHFlAjfU4fPIjhFNsLLVk5EuGR9QC5RcYTXXm9E4l3RFQfXew/+DIYm2xMuvAVT/MY5wk21WoWpjNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744343432; c=relaxed/simple; bh=RSuxk/dHzfMuHqU3U1cL04m7MqJ/Ml8N36LwtwzR9Og=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cpcWcpTKIDdnZDdsBXnjqaDB2bQSes9G0wg7We22tK5aOFLP1Q72vTpM7rj5+JdoHQuF+6Rakjpu73Ys24rdlPOlHLYvsrlIU7UxX7LK+OzIBL2rVzGYRbt6RKOrK+X72NL6RKudzTLi/RFUqXpYrONtsjFiOktWOIGDyyiEYsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=CgqcpvLZ; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="CgqcpvLZ" Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53AFwKme000667 for ; Fri, 11 Apr 2025 03:50:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= JckVC7d5iC7VbTaEcWk7JXOw9O2E+TUPpabbS6XiWDk=; b=CgqcpvLZVJbpDU1+ +Bhgqu/15PuwojDTusH3MJle/XMyPvIBMnIHh8tZRT/Eb1lgslizxYxsZAgiXjVv DqApkrlysv24jpzcAdwM+450aDqTPfBtTpkTZOedjE3fMLkThq8cBnP5soMMvoGP dKV9qeNOoiQrOeWo6p2Bdx8ONiv15XoA7Gs8bLF3RfschVM46XV9pVBFzYVxqCgE 7tp11kg8nc8whCaMgu1J0EWcCiD4taDS5u8gBo6BLpquX2rJz5OR6IMqvTAxyyxO Got5gCvk4rHRVxzRiURggZGsHQZpwPD3S/qtSnr47ksDNWBUh500NDWGuvsqgXFz dCv/Qw== Received: from mail-oa1-f72.google.com (mail-oa1-f72.google.com [209.85.160.72]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 45twd3121d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 11 Apr 2025 03:50:29 +0000 (GMT) Received: by mail-oa1-f72.google.com with SMTP id 586e51a60fabf-2c83a8ab786so1326468fac.1 for ; Thu, 10 Apr 2025 20:50:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744343428; x=1744948228; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JckVC7d5iC7VbTaEcWk7JXOw9O2E+TUPpabbS6XiWDk=; b=LNjhsLc5Ab8XGOyKtEMaRbnOV6jUbW5U6oTFBdIrqX+vO184BKejatBA3OlwrAJ+Oc Ni4rk8WQrK2TGVLpMraw7Wi2OfVGZCxulL7JmOvu8cBInw+8J/YCQlp1x6/xMGTGJMZc 1716ijcDj8JRJeDV7yRdtyt9L9DKyZs2DWXlNPDK9YFO9VogV/oS6g19Kc44ldNWmOjb LjLme+VisXFaTMauuP9YQFwDOOGUMd5T5hXbhVIKABCTzfwbs8Uq4e1yqYrTQ1ew9OcB fgONaxBWUsGanyDjXp+X9jau7DWSegdVQKA2N4WWjZiQLA/xYoCR2Y4r8qpPWgN5OdZN Pj5w== X-Forwarded-Encrypted: i=1; AJvYcCVHM+92h1wQlpi395kuUIb01xCTjBkIoZyZcqV2Sj1s4jK82z+1gAukN1Ks149ATgVcDLxnkEyHNso=@vger.kernel.org X-Gm-Message-State: AOJu0YworRZWVqKUMr7vcRVwaTSnZG3vdULfEKJZF7rx6RPXMWnIe1o1 e257PfTkBMCXAZaDmkcuQMmH1uSAyiOvr/n7A7qwIgGGRKn42w6J3JIsFtaorIhrsmam4J9q2vv 6avEasyCQG7zAq+vaN26FAtYrTIbM/bflu+ofxSnAtr+cFzMLVfsTr8hRKy0= X-Gm-Gg: ASbGnctqF9tyASQjSpXsC9d5ee/Z5fjAMrx4RwlBHbezemzuhQ4BZc2J+4fqZ95rceE 1a6iyja+xbqkWG3FhL5ehkkXahSxzMyIR5fbrJ+TmQOVRw7uw6fSARodBgEkVg5HgTbOAlA5mQg i3aZYvyuXepx8AiAOIvqsMzPzXKgPlTxN06QL9CSdSzpJ/MtzKQau/Qaz3+8q+wtvBtjN6JTGBz /kdqpzmwh0zZym5nbvnXn1jhfIo4HoIQ0xF/e6zMCF8QlaWSuxxy/VwkPUpmIk7mCOK7FPYS2NX GzRwX5eN+6z9J8nk2j91wmC5TcHojrKQb76cpdBTyCe7zqbnLSBEK+n30LdU0uNl/OHdcX4QFze bhbFCgYZAoSw= X-Received: by 2002:a05:6871:50c7:b0:29e:5297:a2a7 with SMTP id 586e51a60fabf-2d0d5ef2c0cmr675831fac.30.1744343428217; Thu, 10 Apr 2025 20:50:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTEJqA//s2MSMQfQAqTLDtmK7DVSU2dp4MjfLg6qT58X3b36bH8Wo7QjGpbBgWsGTxZGlmLQ== X-Received: by 2002:a05:6871:50c7:b0:29e:5297:a2a7 with SMTP id 586e51a60fabf-2d0d5ef2c0cmr675811fac.30.1744343427808; Thu, 10 Apr 2025 20:50:27 -0700 (PDT) Received: from [192.168.86.65] (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-2d0969589basm958677fac.19.2025.04.10.20.50.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 20:50:27 -0700 (PDT) From: Bjorn Andersson Date: Thu, 10 Apr 2025 22:50:16 -0500 Subject: [PATCH v6 5/6] usb: dwc3: qcom: Don't rely on drvdata during probe Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250410-dwc3-refactor-v6-5-dc0d1b336135@oss.qualcomm.com> References: <20250410-dwc3-refactor-v6-0-dc0d1b336135@oss.qualcomm.com> In-Reply-To: <20250410-dwc3-refactor-v6-0-dc0d1b336135@oss.qualcomm.com> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Felipe Balbi , Wesley Cheng , Saravana Kannan , Thinh Nguyen , Philipp Zabel , Bjorn Andersson , Konrad Dybcio , Frank Li Cc: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Andersson X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3136; i=bjorn.andersson@oss.qualcomm.com; h=from:subject:message-id; bh=RSuxk/dHzfMuHqU3U1cL04m7MqJ/Ml8N36LwtwzR9Og=; b=owEBgwJ8/ZANAwAIAQsfOT8Nma3FAcsmYgBn+JF9qiL5G7nhdRn0u6cP1Jl7oF5pjHpLTc1Ut b2tAJuY2GuJAkkEAAEIADMWIQQF3gPMXzXqTwlm1SULHzk/DZmtxQUCZ/iRfRUcYW5kZXJzc29u QGtlcm5lbC5vcmcACgkQCx85Pw2ZrcV3FQ/+PsV3vdTXi8T+b41VDzzOy0p8rFRKUvPN8x480LO tjt/YfilpIndvUZagukl92ZMdTlH9Kil18eJGuyK9uwsjG9kZ7SOsvd9eMg7qSlKekj3kDkMA9J 236qsQIWH9YqOT0DXaswHJiVqNl96TyfZw6l1EtZYQl8CSCOyqiZtXLEI49rYwocaOwjCEjmGgt LX3HLOpuWhlwu1l2bPhg1G0JRTxlJzGc+gelHYuT1DdGMJDOROz2i+yDYjU1X7q70Vi7xgxSIrw gpUd77j28R4eB2agSO7id2ewsMhwB+6NhN9STZ9U+5rfXrFG+MkGbaqsztdqH850lXRrmh2sjj2 cce3/RWdT+x3/dizxxk8QQr824dF9sYa2jiwjtf9Ct6k6QKgbG1ew6a2tf4xWXIdnJdaASK8h+x 3TIoFgMuJVlrp+6LrjSbn+x0WruBO5ZJRbpVEiwD9IygAj14UHyIg9mwojCeWO7J2XlYrPt4+/W a0zDeHNz1FKRqQXUHzvzUef8MjxvELWYxAs3MdTOLah+Camprkc/uCPVEMAEvipdTZXMcl4qbce s55datCM/lYZDPUII3EDpA1CYIierVskd+8vhr7tTyLptjEbJUCqGOicqWRLM7bJzbT/L/u73Bu zWpE9yod4VOu7okl9xigZmH4smAQQBjp72u+PZQY4vxY= X-Developer-Key: i=bjorn.andersson@oss.qualcomm.com; a=openpgp; fpr=05DE03CC5F35EA4F0966D5250B1F393F0D99ADC5 X-Proofpoint-ORIG-GUID: kLsH5-MhtTkD-aU_H0t1KRWSfvblXvSV X-Proofpoint-GUID: kLsH5-MhtTkD-aU_H0t1KRWSfvblXvSV X-Authority-Analysis: v=2.4 cv=NaLm13D4 c=1 sm=1 tr=0 ts=67f89185 cx=c_pps a=Z3eh007fzM5o9awBa1HkYQ==:117 a=DaeiM5VmU20ml6RIjrOvYw==:17 a=IkcTkHD0fZMA:10 a=XR8D0OoHHMoA:10 a=jIQo8A4GAAAA:8 a=EUspDBNiAAAA:8 a=0UB9HjPGtwcCTtCM8zIA:9 a=QEXdDO2ut3YA:10 a=eBU8X_Hb5SQ8N-bgNfv4:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-11_01,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 impostorscore=0 priorityscore=1501 adultscore=0 malwarescore=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 spamscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2504110026 With the upcoming transition to a model where DWC3 core and glue operate on a single struct device the drvdata datatype will change to be owned by the core. The drvdata is however used by the Qualcomm DWC3 glue to pass the qcom glue context around before the core is allocated. Remove this problem, and clean up the code, by passing the dwc3_qcom struct around during probe, instead of acquiring it from the drvdata. Acked-by: Thinh Nguyen Signed-off-by: Bjorn Andersson --- drivers/usb/dwc3/dwc3-qcom.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 79f3600f25c41a5ed770f164a03c7dc424b01440..9d04c2457433bd6bcd96c445f59d7f2a3c6fdf24 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -547,9 +547,10 @@ static int dwc3_qcom_request_irq(struct dwc3_qcom *qcom, int irq, return ret; } -static int dwc3_qcom_setup_port_irq(struct platform_device *pdev, int port_index, bool is_multiport) +static int dwc3_qcom_setup_port_irq(struct dwc3_qcom *qcom, + struct platform_device *pdev, + int port_index, bool is_multiport) { - struct dwc3_qcom *qcom = platform_get_drvdata(pdev); const char *irq_name; int irq; int ret; @@ -634,9 +635,8 @@ static int dwc3_qcom_find_num_ports(struct platform_device *pdev) return DWC3_QCOM_MAX_PORTS; } -static int dwc3_qcom_setup_irq(struct platform_device *pdev) +static int dwc3_qcom_setup_irq(struct dwc3_qcom *qcom, struct platform_device *pdev) { - struct dwc3_qcom *qcom = platform_get_drvdata(pdev); bool is_multiport; int ret; int i; @@ -645,7 +645,7 @@ static int dwc3_qcom_setup_irq(struct platform_device *pdev) is_multiport = (qcom->num_ports > 1); for (i = 0; i < qcom->num_ports; i++) { - ret = dwc3_qcom_setup_port_irq(pdev, i, is_multiport); + ret = dwc3_qcom_setup_port_irq(qcom, pdev, i, is_multiport); if (ret) return ret; } @@ -700,9 +700,8 @@ static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom, int count) return 0; } -static int dwc3_qcom_of_register_core(struct platform_device *pdev) +static int dwc3_qcom_of_register_core(struct dwc3_qcom *qcom, struct platform_device *pdev) { - struct dwc3_qcom *qcom = platform_get_drvdata(pdev); struct device_node *np = pdev->dev.of_node; struct device *dev = &pdev->dev; int ret; @@ -778,7 +777,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev) goto clk_disable; } - ret = dwc3_qcom_setup_irq(pdev); + ret = dwc3_qcom_setup_irq(qcom, pdev); if (ret) { dev_err(dev, "failed to setup IRQs, err=%d\n", ret); goto clk_disable; @@ -793,7 +792,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev) if (ignore_pipe_clk) dwc3_qcom_select_utmi_clk(qcom); - ret = dwc3_qcom_of_register_core(pdev); + ret = dwc3_qcom_of_register_core(qcom, pdev); if (ret) { dev_err(dev, "failed to register DWC3 Core, err=%d\n", ret); goto clk_disable; From patchwork Fri Apr 11 03:50:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 880523 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 8531A27D769 for ; Fri, 11 Apr 2025 03:50:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744343434; cv=none; b=elhcSlIOX0zVbXq2TaUbtIFIiMlXz7xXPmYAqLhLTPu2Ix+XCsdxNsSKzKn+RcTGekqDvYi1ukIhJ1SHTnJItMl5suLtYG6Im8mBLW2+nOnWnzETIFH5hnN4hXFEEDgQapwD0ciXAxO2FAjlPcVzCUUIFHxC5FEzivSEDcfjui4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744343434; c=relaxed/simple; bh=JvFdgODbjBbS+ZvrfFLarjzmj9NETKrOx4wtULiGSAA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YJoJ1wxEubdMz4ouBv7GzZGf25j3C3k16jUg1+4uHNUR52onWuwlHPTOzjOHMPNdfH/ExlxvOpAiQ3GbZBT5ElTbBtf1vfCAG2rJL5m3PvluBkZoTw9h1n2xKklcvSvXVImka+VNXUxV9FotwCxRcfJzTwdhKJ9bZhntEtiOHk0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=m2Tg1jOz; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="m2Tg1jOz" Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53AFc51C016330 for ; Fri, 11 Apr 2025 03:50:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= RSLMzHFcwgOEI1rXbDjysCvllpQroAwA/BFevvmuG/g=; b=m2Tg1jOz2zWQvPf9 MDTG+F9qyDH0cGH/ms/QK6Txe7nx29GNdIMTM2yCLKivsW2thgTRuoQeY7Hw8Uf9 SFjcs5Eex9MXGgRajDvt3Zyj+lxZpJc2y6oAdNn9Tqb54y1MJ5WPVc3RBwU+oxNw E0ayhxHcD2hz/6WuIMNpOQWQLhltlRl571KifGZ5JlYDi8r0KI/T8s3ecYk1qm3z AXMxbz4G4KvOlajIHHT4Cz4vK2+2bhQ/expZ50b1+J52aH/ajprM6QdsQefXwJjV 3wdNhZMoVddS+Yrm5289oRV3Hu8sdpmVHyRwBPJgwpc+9/B+1VXVflZmAQ3YVY4Q G9keHg== Received: from mail-oa1-f70.google.com (mail-oa1-f70.google.com [209.85.160.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 45twc1rvxf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 11 Apr 2025 03:50:30 +0000 (GMT) Received: by mail-oa1-f70.google.com with SMTP id 586e51a60fabf-2c76ed410d3so1312351fac.2 for ; Thu, 10 Apr 2025 20:50:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744343429; x=1744948229; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RSLMzHFcwgOEI1rXbDjysCvllpQroAwA/BFevvmuG/g=; b=gmOz33WxhJaz6bV4uOznJVlvenq8L2SZtcKzpO3/w/Ca296ZiACfR59iO3xabU/Ava RJIzO1snAj+GZwLXz5BVo/k13LaHzTb7bTb168jSmhYkaK4xHf30mxQ6vV42todHu7pi 0qHPOEYSg+cOTRhSrnPaHEZDc7buRPl1ArSZJKCgWlowS5o4n2K5fwkUQ/erGWKA0Gjt VKWomIyXyzWOf2jHyb/RBjBMXgcZRWm8yIUs/+1H08TUhXwBTg2SZ3l68V5Wyan9/4/a WuXiEBh1qd5A1AOuyGBBkcSXwqxIAtXss0jn+34u2RAqU93kshQygY7Cq4e2E4T1XiQh AWQQ== X-Forwarded-Encrypted: i=1; AJvYcCVWJiih1oGnaE4CaK5rTgZ7pgg6BHXiLrGktRcwUtLVS0yqXwTu1aWnG1L2/yxeL71VDeKKOCrA8W8=@vger.kernel.org X-Gm-Message-State: AOJu0YxL4NtqwzA8LdXHJW4PXqSF+aM4v0MJd6CAWexCoB41+1VJjBSG LI1u8r9Lg4Qjd+ODnZjhG425s+77UpF5ufE9Iq/zWqkkjW/LfH1YIe6dHUMQUmEKKezMJeUhMnj zKaWZPSnuj9jB6Ek7O+MyMHQZi9nYORyW+jCHw8VgQm02q2dsRSBym2cSn/M= X-Gm-Gg: ASbGnctQaWQXq1oAPDZLV+HaC2KTreRtCrcEsJ0uwsF1uUc8Htu+9BnFwToHHMlPBbg CX+hdrubZeU3GX68rEQ2qOzSLX2Gas3kR/pMMGi4Cw/xLjSOStATLbg0i2Ml/B1VlEq4qOHnTuf TILmoQfjYpnN0r1aqCvhJXrWlhk4CcdsFTSvMZIRKZ6t+01lNpRqsG2VpqQqDa2ObzB84lDECB6 AlKjOPpryLL254LNwCW8KaIcw+8gdZJll4HbEPFvuxQtUvlMcTl7ohUDAJFXaR3RWnzA0jWYL/s QZU00hNZBjdJ5XA0y4Jizh6i5c7fHWdq9ihlh22+y/rWM2KBn3nqORpnHhhPpMoyCF8QdIwPnbH qXvUvJxyUyCo= X-Received: by 2002:a05:6871:a406:b0:29e:6f32:6da1 with SMTP id 586e51a60fabf-2d0d5ef2360mr627983fac.31.1744343429326; Thu, 10 Apr 2025 20:50:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlQ5Qts3Lb+im3lqXm8gZVJFaLJjaEmOLRVqLdfs2JoQVX8YjKMatifna7YpZbd8VzKm1BKw== X-Received: by 2002:a05:6871:a406:b0:29e:6f32:6da1 with SMTP id 586e51a60fabf-2d0d5ef2360mr627973fac.31.1744343428883; Thu, 10 Apr 2025 20:50:28 -0700 (PDT) Received: from [192.168.86.65] (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-2d0969589basm958677fac.19.2025.04.10.20.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 20:50:28 -0700 (PDT) From: Bjorn Andersson Date: Thu, 10 Apr 2025 22:50:17 -0500 Subject: [PATCH v6 6/6] usb: dwc3: qcom: Transition to flattened model Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250410-dwc3-refactor-v6-6-dc0d1b336135@oss.qualcomm.com> References: <20250410-dwc3-refactor-v6-0-dc0d1b336135@oss.qualcomm.com> In-Reply-To: <20250410-dwc3-refactor-v6-0-dc0d1b336135@oss.qualcomm.com> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Felipe Balbi , Wesley Cheng , Saravana Kannan , Thinh Nguyen , Philipp Zabel , Bjorn Andersson , Konrad Dybcio , Frank Li Cc: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Andersson X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=12567; i=bjorn.andersson@oss.qualcomm.com; h=from:subject:message-id; bh=JvFdgODbjBbS+ZvrfFLarjzmj9NETKrOx4wtULiGSAA=; b=owEBgwJ8/ZANAwAIAQsfOT8Nma3FAcsmYgBn+JF9eHa3ioDQ9ZpBdgq83qklg1RMCYlVjUneV UEhw4Uv+1yJAkkEAAEIADMWIQQF3gPMXzXqTwlm1SULHzk/DZmtxQUCZ/iRfRUcYW5kZXJzc29u QGtlcm5lbC5vcmcACgkQCx85Pw2ZrcXF+w//Z3MS8HtJShmjCcGq3htHOqqww0KJin0D7YbCI5s APCXkxwqXQlHtpGFHMKZ4bmlfJesj5ouU3odeyElQoB/gOhS4sQhmp+L/QNPXPGUGFGfWtxSi5e 5boZAoFy0jQ26ljjWGhIBeRcbNRUGyeN8CstRZtskgOeqDny8zCs9UdhnnQb37stc1l5r20FLpA C+dXQI8l3p5Q9KM73Pc/1uACZySDP46SThcRdoc8g8JxGkNctZYW2nuF6LQdZcsIq5BnYeF8lbo zPl36gWI/YMDQVJqilcjklsh2LcAjk6KtKNs9BLQ9EasliaRo09S5GuSbXJhDoKdGpNrXWoLCsR +s8g3J1I/qyvmuzdLOgceozyFJRgt+kmc61bVH80phTitRpTgPPS77Kc4VWw/F+5GrvXlTv93ZO 8lV4IxEe7AjTzHp6cTOGYXLIMYjgx4MHh6QWsOo8zwAcWamlB405IhdQT5h1GSkWxnxwubIRzhG eFGU84cnUwXZ2oQAUoz9w/Lyn0hSr1UxRjDQBVR/1ym+wBhqcKpBJcuoIB+L6yMu2SybSmTEoE4 grNVPWpI2iOPWtF5mpsbOixg6rwch3IRxB4++gcX7PbHNCAt5xRcnTEa3OZGKuwnJlDvbZtxAax 0emHpb0mFSpGEYIZlHz4bilWqQp7h0JwjESEkHCbQhs8= X-Developer-Key: i=bjorn.andersson@oss.qualcomm.com; a=openpgp; fpr=05DE03CC5F35EA4F0966D5250B1F393F0D99ADC5 X-Proofpoint-ORIG-GUID: g_NOw9gS4NrvgT9sIGPVm4Pi0TItmEqa X-Authority-Analysis: v=2.4 cv=KtdN2XWN c=1 sm=1 tr=0 ts=67f89186 cx=c_pps a=nSjmGuzVYOmhOUYzIAhsAg==:117 a=DaeiM5VmU20ml6RIjrOvYw==:17 a=IkcTkHD0fZMA:10 a=XR8D0OoHHMoA:10 a=EUspDBNiAAAA:8 a=oNyuIvTq0u59PHEm3sEA:9 a=QEXdDO2ut3YA:10 a=1zu1i0D7hVQfj8NKfPKu:22 X-Proofpoint-GUID: g_NOw9gS4NrvgT9sIGPVm4Pi0TItmEqa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-11_01,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 priorityscore=1501 phishscore=0 bulkscore=0 suspectscore=0 spamscore=0 malwarescore=0 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2504110026 The USB IP-block found in most Qualcomm platforms is modelled in the Linux kernel as 3 different independent device drivers, but as shown by the already existing layering violations in the Qualcomm glue driver they can not be operated independently. With the current implementation, the glue driver registers the core and has no way to know when this is done. As a result, e.g. the suspend callbacks needs to guard against NULL pointer dereferences when trying to peek into the struct dwc3 found in the drvdata of the child. Even with these checks, there are no way to fully protect ourselves from the race conditions that occur if the DWC3 is unbound. Missing from the upstream Qualcomm USB support is handling of role switching, in which the glue needs to be notified upon DRD mode changes. Several attempts has been made through the years to register callbacks etc, but they always fall short when it comes to handling of the core's probe deferral on resources etc. Moving to a model where the DWC3 core is instantiated in a synchronous fashion avoids above described race conditions. It is however not feasible to do so without also flattening the DeviceTree binding, as assumptions are made in the DWC3 core and frameworks used that the device's associated of_node will the that of the core. Furthermore, the DeviceTree binding is a direct representation of the Linux driver model, and doesn't necessarily describe "the USB IP-block". The Qualcomm DWC3 glue driver is therefor transitioned to initialize and operate the DWC3 within the one device context, in synchronous fashion. To provide a limited time backwards compatibility, a snapshot of the driver is retained in a previous commit. As such no care is taken in the dwc3-qcom driver for the qcom,dwc3 backwards compatibility. Signed-off-by: Bjorn Andersson --- drivers/usb/dwc3/dwc3-qcom.c | 168 +++++++++++++++++++++++-------------------- 1 file changed, 90 insertions(+), 78 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 9d04c2457433bd6bcd96c445f59d7f2a3c6fdf24..59a3117b0f6b66949643f2b563fd6dc27c6a2fbf 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -4,7 +4,6 @@ * Inspired by dwc3-of-simple.c */ -#include #include #include #include @@ -14,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -23,6 +21,7 @@ #include #include #include "core.h" +#include "glue.h" /* USB QSCRATCH Hardware registers */ #define QSCRATCH_HS_PHY_CTRL 0x10 @@ -73,7 +72,7 @@ struct dwc3_qcom_port { struct dwc3_qcom { struct device *dev; void __iomem *qscratch_base; - struct platform_device *dwc3; + struct dwc3 dwc; struct clk **clks; int num_clocks; struct reset_control *resets; @@ -92,6 +91,8 @@ struct dwc3_qcom { struct icc_path *icc_path_apps; }; +#define to_dwc3_qcom(d) container_of((d), struct dwc3_qcom, dwc) + static inline void dwc3_qcom_setbits(void __iomem *base, u32 offset, u32 val) { u32 reg; @@ -116,6 +117,11 @@ static inline void dwc3_qcom_clrbits(void __iomem *base, u32 offset, u32 val) readl(base + offset); } +/* + * TODO: Make the in-core role switching code invoke dwc3_qcom_vbus_override_enable(), + * validate that the in-core extcon support is functional, and drop extcon + * handling from the glue + */ static void dwc3_qcom_vbus_override_enable(struct dwc3_qcom *qcom, bool enable) { if (enable) { @@ -260,7 +266,7 @@ static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom) goto put_path_ddr; } - max_speed = usb_get_maximum_speed(&qcom->dwc3->dev); + max_speed = usb_get_maximum_speed(qcom->dwc.dev); if (max_speed >= USB_SPEED_SUPER || max_speed == USB_SPEED_UNKNOWN) { ret = icc_set_bw(qcom->icc_path_ddr, USB_MEMORY_AVG_SS_BW, USB_MEMORY_PEAK_SS_BW); @@ -303,25 +309,14 @@ static void dwc3_qcom_interconnect_exit(struct dwc3_qcom *qcom) /* Only usable in contexts where the role can not change. */ static bool dwc3_qcom_is_host(struct dwc3_qcom *qcom) { - struct dwc3 *dwc; - - /* - * FIXME: Fix this layering violation. - */ - dwc = platform_get_drvdata(qcom->dwc3); - - /* Core driver may not have probed yet. */ - if (!dwc) - return false; - - return dwc->xhci; + return qcom->dwc.xhci; } static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom, int port_index) { - struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3); struct usb_device *udev; struct usb_hcd __maybe_unused *hcd; + struct dwc3 *dwc = &qcom->dwc; /* * FIXME: Fix this layering violation. @@ -498,7 +493,7 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup) static irqreturn_t qcom_dwc3_resume_irq(int irq, void *data) { struct dwc3_qcom *qcom = data; - struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3); + struct dwc3 *dwc = &qcom->dwc; /* If pm_suspended then let pm_resume take care of resuming h/w */ if (qcom->pm_suspended) @@ -700,40 +695,14 @@ static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom, int count) return 0; } -static int dwc3_qcom_of_register_core(struct dwc3_qcom *qcom, struct platform_device *pdev) -{ - struct device_node *np = pdev->dev.of_node; - struct device *dev = &pdev->dev; - int ret; - - struct device_node *dwc3_np __free(device_node) = of_get_compatible_child(np, - "snps,dwc3"); - if (!dwc3_np) { - dev_err(dev, "failed to find dwc3 core child\n"); - return -ENODEV; - } - - ret = of_platform_populate(np, NULL, NULL, dev); - if (ret) { - dev_err(dev, "failed to register dwc3 core - %d\n", ret); - return ret; - } - - qcom->dwc3 = of_find_device_by_node(dwc3_np); - if (!qcom->dwc3) { - ret = -ENODEV; - dev_err(dev, "failed to get dwc3 platform device\n"); - of_platform_depopulate(dev); - } - - return ret; -} - static int dwc3_qcom_probe(struct platform_device *pdev) { + struct dwc3_probe_data probe_data = {}; struct device_node *np = pdev->dev.of_node; struct device *dev = &pdev->dev; struct dwc3_qcom *qcom; + struct resource res; + struct resource *r; int ret, i; bool ignore_pipe_clk; bool wakeup_source; @@ -742,7 +711,6 @@ static int dwc3_qcom_probe(struct platform_device *pdev) if (!qcom) return -ENOMEM; - platform_set_drvdata(pdev, qcom); qcom->dev = &pdev->dev; qcom->resets = devm_reset_control_array_get_optional_exclusive(dev); @@ -771,8 +739,15 @@ static int dwc3_qcom_probe(struct platform_device *pdev) goto reset_assert; } - qcom->qscratch_base = devm_platform_ioremap_resource(pdev, 0); + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!r) + goto clk_disable; + res = *r; + res.end = res.start + SDM845_QSCRATCH_BASE_OFFSET; + + qcom->qscratch_base = devm_ioremap(dev, res.end, SDM845_QSCRATCH_SIZE); if (IS_ERR(qcom->qscratch_base)) { + dev_err(dev, "failed to map qscratch region: %pe\n", qcom->qscratch_base); ret = PTR_ERR(qcom->qscratch_base); goto clk_disable; } @@ -792,17 +767,21 @@ static int dwc3_qcom_probe(struct platform_device *pdev) if (ignore_pipe_clk) dwc3_qcom_select_utmi_clk(qcom); - ret = dwc3_qcom_of_register_core(qcom, pdev); - if (ret) { - dev_err(dev, "failed to register DWC3 Core, err=%d\n", ret); + qcom->dwc.dev = dev; + probe_data.dwc = &qcom->dwc; + probe_data.res = &res; + probe_data.ignore_clocks_and_resets = true; + ret = dwc3_core_probe(&probe_data); + if (ret) { + ret = dev_err_probe(dev, ret, "failed to register DWC3 Core\n"); goto clk_disable; } ret = dwc3_qcom_interconnect_init(qcom); if (ret) - goto depopulate; + goto remove_core; - qcom->mode = usb_get_dr_mode(&qcom->dwc3->dev); + qcom->mode = usb_get_dr_mode(dev); /* enable vbus override for device mode */ if (qcom->mode != USB_DR_MODE_HOST) @@ -815,20 +794,15 @@ static int dwc3_qcom_probe(struct platform_device *pdev) wakeup_source = of_property_read_bool(dev->of_node, "wakeup-source"); device_init_wakeup(&pdev->dev, wakeup_source); - device_init_wakeup(&qcom->dwc3->dev, wakeup_source); qcom->is_suspended = false; - pm_runtime_set_active(dev); - pm_runtime_enable(dev); - pm_runtime_forbid(dev); return 0; interconnect_exit: dwc3_qcom_interconnect_exit(qcom); -depopulate: - of_platform_depopulate(&pdev->dev); - platform_device_put(qcom->dwc3); +remove_core: + dwc3_core_remove(&qcom->dwc); clk_disable: for (i = qcom->num_clocks - 1; i >= 0; i--) { clk_disable_unprepare(qcom->clks[i]); @@ -842,12 +816,11 @@ static int dwc3_qcom_probe(struct platform_device *pdev) static void dwc3_qcom_remove(struct platform_device *pdev) { - struct dwc3_qcom *qcom = platform_get_drvdata(pdev); - struct device *dev = &pdev->dev; + struct dwc3 *dwc = platform_get_drvdata(pdev); + struct dwc3_qcom *qcom = to_dwc3_qcom(dwc); int i; - of_platform_depopulate(&pdev->dev); - platform_device_put(qcom->dwc3); + dwc3_core_remove(&qcom->dwc); for (i = qcom->num_clocks - 1; i >= 0; i--) { clk_disable_unprepare(qcom->clks[i]); @@ -857,17 +830,20 @@ static void dwc3_qcom_remove(struct platform_device *pdev) dwc3_qcom_interconnect_exit(qcom); reset_control_assert(qcom->resets); - - pm_runtime_allow(dev); - pm_runtime_disable(dev); } -static int __maybe_unused dwc3_qcom_pm_suspend(struct device *dev) +#ifdef CONFIG_PM_SLEEP +static int dwc3_qcom_pm_suspend(struct device *dev) { - struct dwc3_qcom *qcom = dev_get_drvdata(dev); + struct dwc3 *dwc = dev_get_drvdata(dev); + struct dwc3_qcom *qcom = to_dwc3_qcom(dwc); bool wakeup = device_may_wakeup(dev); int ret; + ret = dwc3_pm_suspend(&qcom->dwc); + if (ret) + return ret; + ret = dwc3_qcom_suspend(qcom, wakeup); if (ret) return ret; @@ -877,9 +853,10 @@ static int __maybe_unused dwc3_qcom_pm_suspend(struct device *dev) return 0; } -static int __maybe_unused dwc3_qcom_pm_resume(struct device *dev) +static int dwc3_qcom_pm_resume(struct device *dev) { - struct dwc3_qcom *qcom = dev_get_drvdata(dev); + struct dwc3 *dwc = dev_get_drvdata(dev); + struct dwc3_qcom *qcom = to_dwc3_qcom(dwc); bool wakeup = device_may_wakeup(dev); int ret; @@ -889,30 +866,65 @@ static int __maybe_unused dwc3_qcom_pm_resume(struct device *dev) qcom->pm_suspended = false; + ret = dwc3_pm_resume(&qcom->dwc); + if (ret) + return ret; + return 0; } -static int __maybe_unused dwc3_qcom_runtime_suspend(struct device *dev) +static void dwc3_qcom_complete(struct device *dev) { - struct dwc3_qcom *qcom = dev_get_drvdata(dev); + struct dwc3 *dwc = dev_get_drvdata(dev); + + dwc3_pm_complete(dwc); +} +#else +#define dwc3_qcom_complete NULL +#endif /* CONFIG_PM_SLEEP */ + +#ifdef CONFIG_PM +static int dwc3_qcom_runtime_suspend(struct device *dev) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + struct dwc3_qcom *qcom = to_dwc3_qcom(dwc); + int ret; + + ret = dwc3_runtime_suspend(&qcom->dwc); + if (ret) + return ret; return dwc3_qcom_suspend(qcom, true); } -static int __maybe_unused dwc3_qcom_runtime_resume(struct device *dev) +static int dwc3_qcom_runtime_resume(struct device *dev) { - struct dwc3_qcom *qcom = dev_get_drvdata(dev); + struct dwc3 *dwc = dev_get_drvdata(dev); + struct dwc3_qcom *qcom = to_dwc3_qcom(dwc); + int ret; - return dwc3_qcom_resume(qcom, true); + ret = dwc3_qcom_resume(qcom, true); + if (ret) + return ret; + + return dwc3_runtime_resume(&qcom->dwc); +} + +static int dwc3_qcom_runtime_idle(struct device *dev) +{ + return dwc3_runtime_idle(dev_get_drvdata(dev)); } +#endif /* CONFIG_PM */ static const struct dev_pm_ops dwc3_qcom_dev_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(dwc3_qcom_pm_suspend, dwc3_qcom_pm_resume) SET_RUNTIME_PM_OPS(dwc3_qcom_runtime_suspend, dwc3_qcom_runtime_resume, - NULL) + dwc3_qcom_runtime_idle) + .complete = dwc3_qcom_complete, }; static const struct of_device_id dwc3_qcom_of_match[] = { + { .compatible = "qcom,snps-dwc3" }, { } }; MODULE_DEVICE_TABLE(of, dwc3_qcom_of_match);