From nobody Sun Oct 5 09:11:00 2025 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 8A65328A72D for ; Wed, 6 Aug 2025 09:58:44 +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=1754474326; cv=none; b=H/k6Jt88PdEpMffll+eqHALkwVa/jmamR1QUVX2jn2T/gQV/DKAWsB23LVlDt1N9DS+yj+TDsOuMl2tqkUnCQaEplOtcYeBlw9/Wn9A0ZzWGo1N03OkkXdLTXBius7oZaTyCxrg4A7CjkCQE1zmFinhtrb4YOcWLcdu91CCNMpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754474326; c=relaxed/simple; bh=ju/IORgQMB5tw2a5Yi2XNxvS1dzi7whPBV6L6KZ0pV0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j7BCao3So6JusWY/+5BVPmllYFJPLZoaiTF6RnFcxS+h3gnsEv1aGeRAqQImhh9gRbF7xUs0mTvms/7TbQ/JYnspgubVSgLuUY8h1P77JyaUYlS2k/PVVexKPm/YcTGZ/q5aAfmHDKzsJ1A32LJRqZASt9JtJ1c2zNS2mgH8DTw= 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=Wxi+Htik; 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="Wxi+Htik" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5769ekpC032245 for ; Wed, 6 Aug 2025 09:58:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=x7ELA2sx/Md WoybRTVV3B4u5eWgexiePTdCJcLkR0o0=; b=Wxi+HtiknpYF6cQ0xPD0k0Z/0mI tiUZI+pbXoa+NEbiDqS5fk7jNdPTaSViK5KVkk3ex4D6mrr66QUOfsFg6i0Oj9OH TuU5ofrI3XzGRYkKMIx4T+HuFrp/sjmg/Tw4rzUECwQjtWbPmk9qkos87AYVqGGU 3hK3jLcbaLQZOizGvPVlcCkkvekQIBCV8CVFLuP0ADJ7JjOOjqGxw8wCFSVlIMym E0gb5pVtL911GdHFBoLQrdzm0LMzbwkZgkXqEfP+Yb/Pwb4/yzgp3B3qix5eAfwE yBhd354VTFfIK3pBqhvM35XQb8cgYVAJex+4Ht4jaVoIEPj0f7tWvXmhwxg== Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 48bpw2tc4w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 06 Aug 2025 09:58:43 +0000 (GMT) Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-31f65d519d3so10529626a91.2 for ; Wed, 06 Aug 2025 02:58:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754474322; x=1755079122; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x7ELA2sx/MdWoybRTVV3B4u5eWgexiePTdCJcLkR0o0=; b=AnSkzHZTAznWbZxrGgNh+dlGMN8hATwZUWCKIRSJ0hZjLG0R13UNdAm+RogO12iZso I5Y6/mVIpai9w/Id9NOVm5Lg53f30Z1xaVpad6pxjhI3Bhm9vo+YvZfJ/CeF8qEPbwcK 5rbpqyHom/Npzd1QckyKkFu5lru74mdtl1dzr4vOYD8XxAjukqOvCsZ/TAR8NKgIxar6 E1XxgcCYW+JWOgfziT8dvQh7B/5Ak4EbJoFV3Xo6UhN2TdQPW39D+jAJ7xoKhwBfkNzI Whhp19i+qsv3dZj/9w7ZTGuAqlL5M75KSsH7fErPQ1D3jCTYdl65IQ1ZEvDFaS8rl/h2 mF0w== X-Forwarded-Encrypted: i=1; AJvYcCWinLIFhQvEhzuZJKm+z5aeyAZrxu/F8QUnpeTuFlOQzSPGiAeRZgC3qQ1cyR7Ez95437eAxw1hVd9+N8c=@vger.kernel.org X-Gm-Message-State: AOJu0YzNirREX37uEUM75ldp08JXEdCkHMu2JcoLomeDH+iX0JAP9prS Y8po/Mdojf3iwKzAFXRkL9w1hPe56DHL3GUiWnhpDmnKr+edEqXjNkbfbIga8w76PDyMbWS3QUJ MYRj/3EIT8GhgfitaPu6JLKSYJRHwZPfqBMsfFQ9CdmRAoohEhzceJVWeYPJ7B3bPwRM= X-Gm-Gg: ASbGnctcS63K6nZINWMV5Ecu5urgoOEYwrK54QxLun5bI71iRHtDc4NpkifGP/+QJhn zUaj21CH8Wbgx2hK1zUf2cGjyLIY4pn2Orh+ybA9d7dDdK1tcBUzy2PzeqDmHyuNM6Ud4Bvcu7Z VdISujYRQcLe5VfB3bDk1PULkE63pztoxbNuPsnUqkrmJ+PXvIWGWscputJvibJkqThTpMsenrn SnaA7Ln++TMi9ZT46z9WUbZXfCS3UfHbmy0eQX+dF1nuXu21LzR1q6tAAqIrvmYI+s07MyQur0q jTziM31lYd7aoWz1h/rEqQSTUaUibmSHHBLP0M3AMLwKsA9wbCCdcuGs6O9JqQxs3X10OBPwg2s uNA== X-Received: by 2002:a17:902:e748:b0:242:9bca:863d with SMTP id d9443c01a7336-2429f59ce44mr27650285ad.55.1754474322024; Wed, 06 Aug 2025 02:58:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuMxZalx+X0hAPVDbFCyTqiK4CqecAEXQQJUNlBXvwPtaAOHPwbvTXEoeeBROEhQvq+lkCKg== X-Received: by 2002:a17:902:e748:b0:242:9bca:863d with SMTP id d9443c01a7336-2429f59ce44mr27649955ad.55.1754474321497; Wed, 06 Aug 2025 02:58:41 -0700 (PDT) Received: from hu-kriskura-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b422b7bb0c0sm12908799a12.20.2025.08.06.02.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Aug 2025 02:58:41 -0700 (PDT) From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Mathias Nyman , Bjorn Andersson , Dmitry Baryshkov , Konrad Dybcio Cc: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Krishna Kurapati Subject: [PATCH v3 1/3] usb: dwc3: core: Introduce glue callbacks for flattened implementations Date: Wed, 6 Aug 2025 15:28:26 +0530 Message-Id: <20250806095828.1582917-2-krishna.kurapati@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250806095828.1582917-1-krishna.kurapati@oss.qualcomm.com> References: <20250806095828.1582917-1-krishna.kurapati@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=Vbz3PEp9 c=1 sm=1 tr=0 ts=68932753 cx=c_pps a=vVfyC5vLCtgYJKYeQD43oA==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=2OwXVqhp2XgA:10 a=EUspDBNiAAAA:8 a=9UFxAfr_hboBSpCGZXUA:9 a=rl5im9kqc5Lf4LNbBjHf:22 X-Proofpoint-ORIG-GUID: VwhsSv3JFLaQMDuKEgzy5-Bxxh-NI9Uw X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwODA2MDAwOCBTYWx0ZWRfX5AvCILsXUSdH L0N1Use1ioPQqv9MYw3vSmtuBPUHMtPi7tjiOujSqE63H9od5ntOBoXRRmMQ3ViQ0ZbzXiM3zBK t83la2pgSCWttg/VufFqwlxK/gs6xBcvyw9QWcaY8+vC3GdnCd/nfPgCzM36WS2JhQ0fS+RXOmf gBtqhMdwyley/8JKFZ2KU3jr2+67UOCjFt3JMFFd+ZIxgLLPzmPalLqGddQfFbsNiR0ulV1WHWd z14Vpbjhx4u3Qvzbm4Ovouh1oernv2iMXBoKXQYnLfYZOc9eMdoTmyVmvySAfzfRl7iaRheyoUV BlpTfRX0VRU8WfdGTmvb8xJoR3s9oTwDeJH7DhAKX3qVNYUs46VXH5ulK8L/UzvMjJCvUUd4YmB l81ot59s X-Proofpoint-GUID: VwhsSv3JFLaQMDuKEgzy5-Bxxh-NI9Uw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-08-06_02,2025-08-04_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 adultscore=0 suspectscore=0 bulkscore=0 phishscore=0 priorityscore=1501 spamscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2507300000 definitions=main-2508060008 Content-Type: text/plain; charset="utf-8" In certain situations like role switching, the glue layers need to be informed of these events, so that they can take any necessary action. But in non-flattened implementations, the glue drivers have no data on when the core driver probe was successful post invoking of_platform_ populate. Now that the core driver supports flattened implementations as well, introduce vendor callbacks that can be passed on from glue to core before invoking dwc3_core_probe. Introduce callbacks to notify glue layer of role_switch and run_stop changes. These can be used by flattened implementation of Qualcomm glue layer to generate connect/disconnect events in controller during cable connect and run stop modifications by udc in device mode. Signed-off-by: Krishna Kurapati --- drivers/usb/dwc3/core.c | 1 + drivers/usb/dwc3/core.h | 26 ++++++++++++++++++++++++++ drivers/usb/dwc3/drd.c | 1 + drivers/usb/dwc3/gadget.c | 1 + 4 files changed, 29 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 8002c23a5a02..392ba86c69f5 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -2351,6 +2351,7 @@ static int dwc3_probe(struct platform_device *pdev) return -ENOMEM; =20 dwc->dev =3D &pdev->dev; + dwc->glue_ops =3D NULL; =20 probe_data.dwc =3D dwc; probe_data.res =3D res; diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index d5b985fa12f4..095311e636c5 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -992,6 +992,17 @@ struct dwc3_scratchpad_array { __le64 dma_adr[DWC3_MAX_HIBER_SCRATCHBUFS]; }; =20 +/** + * struct dwc3_glue_ops - The ops indicate the notifications that + * need to be passed on to glue layer + * @notify_set_role: Notify glue of role switch notifications + * @notify_run_stop: Notify run stop enable/disable information to glue + */ +struct dwc3_glue_ops { + void (*pre_set_role)(struct dwc3 *dwc, enum usb_role role); + void (*pre_run_stop)(struct dwc3 *dwc, bool is_on); +}; + /** * struct dwc3 - representation of our controller * @drd_work: workqueue used for role swapping @@ -1168,6 +1179,7 @@ struct dwc3_scratchpad_array { * @wakeup_pending_funcs: Indicates whether any interface has requested for * function wakeup in bitmap format where bit position * represents interface_id. + * @glue_ops: Vendor callbacks for flattened device implementations. */ struct dwc3 { struct work_struct drd_work; @@ -1197,6 +1209,8 @@ struct dwc3 { struct usb_gadget *gadget; struct usb_gadget_driver *gadget_driver; =20 + const struct dwc3_glue_ops *glue_ops; + struct clk *bus_clk; struct clk *ref_clk; struct clk *susp_clk; @@ -1614,6 +1628,18 @@ void dwc3_event_buffers_cleanup(struct dwc3 *dwc); int dwc3_core_soft_reset(struct dwc3 *dwc); void dwc3_enable_susphy(struct dwc3 *dwc, bool enable); =20 +static inline void dwc3_pre_set_role(struct dwc3 *dwc, enum usb_role role) +{ + if (dwc->glue_ops && dwc->glue_ops->pre_set_role) + dwc->glue_ops->pre_set_role(dwc, role); +} + +static inline void dwc3_pre_run_stop(struct dwc3 *dwc, bool is_on) +{ + if (dwc->glue_ops && dwc->glue_ops->pre_run_stop) + dwc->glue_ops->pre_run_stop(dwc, is_on); +} + #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_RO= LE) 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 7977860932b1..4c91240eb429 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -464,6 +464,7 @@ static int dwc3_usb_role_switch_set(struct usb_role_swi= tch *sw, break; } =20 + dwc3_pre_set_role(dwc, role); dwc3_set_mode(dwc, mode); return 0; } diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 25db36c63951..999b2e436622 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2658,6 +2658,7 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int= is_on) dwc->pullups_connected =3D false; } =20 + dwc3_pre_run_stop(dwc, is_on); dwc3_gadget_dctl_write_safe(dwc, reg); =20 do { --=20 2.34.1 From nobody Sun Oct 5 09:11:00 2025 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 E946428AB15 for ; Wed, 6 Aug 2025 09:58:47 +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=1754474329; cv=none; b=A9JzKF5NJNbmS14RVZ7lZkcTam5HRK3aMb5tYEwztLaetZBgrxrg+IvNhaF9JEmrWrQ4nKE0gCl37ER1g5gwYQwvG83a/jkNmCACeYl+I88IvqHnecuZgqqPX6QQ0EFcsugCfiMu1tHRaP17PlEod0uzMGMugpdu0LVhiyc0I9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754474329; c=relaxed/simple; bh=Q0jotWCx8lw3kiOXHdKfvvEsJG6bqzwDNL4jvrq7Dm0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eOM+liXoiwlG0WDVpS8C9OJuPj9KddVabJkh9tOQGw0+wL09g3nUSFcaOKwyp+o2V4XhwUefXHpg1fJgunEj1hXTaUGCEYruF6oRS1zQf6m1a5F0iqixaTBogxIkQzTWtX5nWB6NZ2NLNukLjQyX3/wsALaur6nMqlU8mL5r+P8= 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=H2QXKArM; 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="H2QXKArM" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5766RGkH019544 for ; Wed, 6 Aug 2025 09:58:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=fVZRycOyI4f TiPSxxA8gtUsZQNfxtdl12OYtC9dsMbk=; b=H2QXKArMU1NTPbiwlrdZx2neW5K PfYDAWx++MMcD1Rh2PhtnxdexI0K+fm3mHsPLKCyHg75s1YtYiGNIkaCZ1/jQDoy PZ5gy+fZow8eR5+uwaQiualVzOAw9VwccdgVsXXD0xhfE4yQxFk+TO4bweYMMza3 3pcrvufr5vkCoiDghVWYMePjcdTFLZD01dr52HW9JiFRshkOKS47sQAq/SVT2w7I ziPXOl9xSrCZ835i6S2gdLTeGQ0Tw5+AxmHENbb996iHToHDxyqKS8fZz7zzkSMI oMXwwAYErM/yfeE94oBLmiA1P5C4S+5LeKwLmCN/VBLVsexcJUea200ZWjw== Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 48bpy6t7sx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 06 Aug 2025 09:58:47 +0000 (GMT) Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-b2fa1a84566so5198012a12.1 for ; Wed, 06 Aug 2025 02:58:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754474326; x=1755079126; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fVZRycOyI4fTiPSxxA8gtUsZQNfxtdl12OYtC9dsMbk=; b=JyfsAhZuZWHUxx9mOLQVErrG8epLwHQcis7DR1CeLj/ZT76qQbdPCDqOrKUkDyGfp7 J1RzIUz/O1fmgErXGeH57+5pfaIs4v1DeysXasvwPzexG48dZgqFFCGoPEMIm8zifpGp qBTibK1+ub1C0av+xgDLTDxAfczffGERZgcBKzUE08OOpxFh9wLzQJJZ/GXogbiiq6Ri J1iOq9rCUb5/lcFTfLtT2xj0c+dwHA21PjdMaMH1/oRyYYxORlR+yT/kZmC/b+Qhohu4 7MYby4vgY0+jxx7JIguWHYW9AABeDBSeTYnBEKbmZHMHBiTCIjNKob7EVjWuzQl3VeDm SAiQ== X-Forwarded-Encrypted: i=1; AJvYcCWZGKDWe1cMJxYzH8NamoSKkRWduAM6DA9JsU31GjhebWN3K098FiWxnTyd6LjX1reT5YIV+OdXPJ2pD/c=@vger.kernel.org X-Gm-Message-State: AOJu0Yzus1nAlH1LTQ8K99HvHvcjJqJ7Oc4celLthS8NpFVAN7OklkL2 zkKn4ou1Lbf9y3LpZ9mPMJT35hNvWr3GA//l4Vs+1zi6PDCR+pQu2k3iX09MeP0mPePOjIP1SNH 0L5jzNP/J98sACinmgZgIyFbx7LM8pu2Ph6k/iOmXbKH6Wcu7wOAS92Hn0W6aRs2eYF0= X-Gm-Gg: ASbGncsFF7ANsyIIE0laICSnAKAczP6fO7O/rfVUHypYbOtvZGkRrVjXQQv7rfd09qN 4rsghfa9iN3WQnOZSMz1//OZEd8ZYEiljc+1WV9U8Hx6hYvO4ZR2796NB1jIxD/anwydhYzmgE8 HqVJlQFScqp168D9Q0uD411VcJQ0IPwjatrHZWPYMURC+BLHvaHnzmofTso0490GxgjyGpul3NR s4aOpZd42fcjWRtDBeSGFYUp6O/XRnsWGIVnfYsYBRYyvpDmDA4hXiRy4/j2+m4EJWbLBbtpB34 NtaWBL67/ldNyiZ1PWFYYadrDVfW8OpjzM9RdVQDA2v+DnMCbjCfPTlBK73/Ivp9oNFYpNk5paT lXQ== X-Received: by 2002:a05:6a20:7f92:b0:240:265f:4eca with SMTP id adf61e73a8af0-240315267eemr2940577637.36.1754474326220; Wed, 06 Aug 2025 02:58:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFq+jEQLnn5Gmoqfhh5VZvBN75Iy0ukWpVZT97ZuZa6Zzjx8vgThnl/2jLYYF3bsWLTSmbQbQ== X-Received: by 2002:a05:6a20:7f92:b0:240:265f:4eca with SMTP id adf61e73a8af0-240315267eemr2940551637.36.1754474325781; Wed, 06 Aug 2025 02:58:45 -0700 (PDT) Received: from hu-kriskura-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b422b7bb0c0sm12908799a12.20.2025.08.06.02.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Aug 2025 02:58:45 -0700 (PDT) From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Mathias Nyman , Bjorn Andersson , Dmitry Baryshkov , Konrad Dybcio Cc: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Krishna Kurapati Subject: [PATCH v3 2/3] usb: dwc3: qcom: Implement glue callbacks to facilitate runtime suspend Date: Wed, 6 Aug 2025 15:28:27 +0530 Message-Id: <20250806095828.1582917-3-krishna.kurapati@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250806095828.1582917-1-krishna.kurapati@oss.qualcomm.com> References: <20250806095828.1582917-1-krishna.kurapati@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: 4xc-hyfrIhDRV_cPEwafPbDzWXNYmtGG X-Proofpoint-GUID: 4xc-hyfrIhDRV_cPEwafPbDzWXNYmtGG X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwODA2MDAwOSBTYWx0ZWRfXyVpGKgTZBKfj FKZJj9kt5VboOUetNF36HHqkLQ9sY0RpeIOkvhd3nyck7TPV+T1rdqOB6ZdY/vothtYOVYsWb7F fiMHH7Hyfd/8o8tidC8mOJvpSF7V4xLOypSzp6v2K2khYV+1Pd9IJVAOqe9Jvu/gIsHxnrTPslV bFtrigW7lWC6ugRP+N+RxT3zE8NJ2lAEFqtHSrr1+JYMTBC3tQqfepbkKYNYTlMpwbtZdScGhvO qwAENutu6jaRsvrYcQEgKQEeMa7aMdHz/Nfy5awgnotYQVtGTq2sTn+1yZxbvBGP7OEDSJc65/P ih7OKFwBn+wm/xJaOtPy/llRrsJbP5vE8jF1bq6PrmObL+294eFtxamgCDbpYhda1iQT13VZgNN q59saQnr X-Authority-Analysis: v=2.4 cv=LNVmQIW9 c=1 sm=1 tr=0 ts=68932757 cx=c_pps a=rz3CxIlbcmazkYymdCej/Q==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=2OwXVqhp2XgA:10 a=EUspDBNiAAAA:8 a=ProRYBKZBCDr5nQBVQAA:9 a=bFCP_H2QrGi7Okbo017w:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-08-06_02,2025-08-04_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 clxscore=1015 malwarescore=0 adultscore=0 phishscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2507300000 definitions=main-2508060009 Content-Type: text/plain; charset="utf-8" On Qualcomm DWC3 dual-role controllers, the conndone/disconnect events in device mode are generated by controller when software writes to QSCRATCH registers in Qualcomm Glue layer rather than the vbus line being routed to dwc3 core IP for it to recognize and generate these events. UTMI_OTG_VBUS_VALID bit of QSCRATCH_HS_PHY_CTRL register needs to be set to generate a connection done event and to be cleared for the controller to generate a disconnect event during cable removal. When the disconnect is not generated upon cable removal, the "connected" flag of dwc3 is left marked as "true" and it blocks suspend routines and for that to happen upon cable removal, the cable disconnect notification coming in via set_role call need to be provided to the Qualcomm glue layer as well. Currently, the way DWC3 core and Qualcomm legacy glue driver are designed, there is no mechanism through which the DWC3 core can notify the Qualcomm glue layer of any role changes which it receives via role switch. To register these glue callbacks at probe time, for enabling core to notify glue layer, the legacy Qualcomm driver has no way to find out when the child driver probe was successful since it does not check for the same during of_platform_populate. Hence implement the following glue callbacks for flattened Qualcomm glue driver: 1. set_role: To pass role switching information from drd layer to glue. This information is needed to identify NONE/DEVICE mode switch and modify QSCRATCH to generate connect-done event on device mode entry and disconnect event on cable removal in device mode. 2. run_stop: When booting up in device mode, if autouspend is enabled and userspace doesn't write UDC on boot, controller enters autosuspend. After this, if the userspace writes to UDC in the future, run_stop notifier is required to enable UTMI_OTG_VBUS_VALID of QSCRATCH so that connect done event is generated after run_stop(1) is done to finish enumeration. Signed-off-by: Krishna Kurapati --- drivers/usb/dwc3/dwc3-qcom.c | 80 +++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 10 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index a7eaefaeec4d..5195267cd34d 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -83,6 +83,8 @@ struct dwc3_qcom { bool pm_suspended; struct icc_path *icc_path_ddr; struct icc_path *icc_path_apps; + + enum usb_role current_role; }; =20 #define to_dwc3_qcom(d) container_of((d), struct dwc3_qcom, dwc) @@ -111,10 +113,6 @@ static inline void dwc3_qcom_clrbits(void __iomem *bas= e, u32 offset, u32 val) readl(base + offset); } =20 -/* - * TODO: Make the in-core role switching code invoke dwc3_qcom_vbus_overri= de_enable(), - * validate that the in-core extcon support is functional - */ static void dwc3_qcom_vbus_override_enable(struct dwc3_qcom *qcom, bool en= able) { if (enable) { @@ -560,6 +558,57 @@ static int dwc3_qcom_setup_irq(struct dwc3_qcom *qcom,= struct platform_device *p return 0; } =20 +static void dwc3_qcom_set_role_notifier(struct dwc3 *dwc, enum usb_role ne= xt_role) +{ + struct dwc3_qcom *qcom =3D to_dwc3_qcom(dwc); + + if (qcom->current_role =3D=3D next_role) + return; + + if (pm_runtime_resume_and_get(qcom->dev) < 0) { + dev_dbg(qcom->dev, "Failed to resume device\n"); + return; + } + + if (qcom->current_role =3D=3D USB_ROLE_DEVICE && + next_role !=3D USB_ROLE_DEVICE) + dwc3_qcom_vbus_override_enable(qcom, false); + else if ((qcom->current_role !=3D USB_ROLE_DEVICE) && + (next_role =3D=3D USB_ROLE_DEVICE)) + dwc3_qcom_vbus_override_enable(qcom, true); + + pm_runtime_mark_last_busy(qcom->dev); + pm_runtime_put_sync(qcom->dev); + + /* + * Current role changes via usb_role_switch_set_role callback protected + * internally by mutex lock. + */ + qcom->current_role =3D next_role; +} + +static void dwc3_qcom_run_stop_notifier(struct dwc3 *dwc, bool is_on) +{ + struct dwc3_qcom *qcom =3D to_dwc3_qcom(dwc); + + /* + * When autosuspend is enabled and controller goes to suspend + * after removing UDC from userspace, the next UDC write needs + * setting of QSCRATCH VBUS_VALID to "1" to generate a connect + * done event. + */ + if (!is_on) + return; + + dwc3_qcom_vbus_override_enable(qcom, is_on); + pm_runtime_mark_last_busy(qcom->dev); +} + +struct dwc3_glue_ops dwc3_qcom_glue_ops =3D { + .pre_set_role =3D dwc3_qcom_set_role_notifier, + .pre_run_stop =3D dwc3_qcom_run_stop_notifier, +}; + static int dwc3_qcom_probe(struct platform_device *pdev) { struct dwc3_probe_data probe_data =3D {}; @@ -636,6 +685,23 @@ static int dwc3_qcom_probe(struct platform_device *pde= v) if (ignore_pipe_clk) dwc3_qcom_select_utmi_clk(qcom); =20 + qcom->mode =3D usb_get_dr_mode(dev); + + if (qcom->mode =3D=3D USB_DR_MODE_HOST) { + qcom->current_role =3D USB_ROLE_HOST; + } else if (qcom->mode =3D=3D USB_DR_MODE_PERIPHERAL) { + qcom->current_role =3D USB_ROLE_DEVICE; + dwc3_qcom_vbus_override_enable(qcom, true); + } else { + if ((device_property_read_bool(dev, "usb-role-switch")) && + (usb_get_role_switch_default_mode(dev) =3D=3D USB_DR_MODE_HOST)) + qcom->current_role =3D USB_ROLE_HOST; + else + qcom->current_role =3D USB_ROLE_DEVICE; + } + + qcom->dwc.glue_ops =3D &dwc3_qcom_glue_ops; + qcom->dwc.dev =3D dev; probe_data.dwc =3D &qcom->dwc; probe_data.res =3D &res; @@ -650,12 +716,6 @@ static int dwc3_qcom_probe(struct platform_device *pde= v) if (ret) goto remove_core; =20 - qcom->mode =3D usb_get_dr_mode(dev); - - /* enable vbus override for device mode */ - if (qcom->mode !=3D USB_DR_MODE_HOST) - dwc3_qcom_vbus_override_enable(qcom, true); - wakeup_source =3D of_property_read_bool(dev->of_node, "wakeup-source"); device_init_wakeup(&pdev->dev, wakeup_source); =20 --=20 2.34.1 From nobody Sun Oct 5 09:11:00 2025 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 A1A0928B4F4 for ; Wed, 6 Aug 2025 09:58:51 +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=1754474333; cv=none; b=Xrk10pPeaNhFLQ2isc3p3Cyz4RNoq5H3wW7sDmI83jCkYnSIo0Q15uCOm8OfSoFyp3YNKgWd0iV7ieHstm1uQGdLTJPfGdhJhIEm7z2s8dn66b5/AFYSZ5cH0ssX+W5ascEKyLt3rKz0yAziDEeG3HnpQxRrv6ayq0NaD1yN6Zw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754474333; c=relaxed/simple; bh=7C5wlqfUGlNAOlcMWP3UIoJSoU7F5CfXh7HAySLy7vw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TWvNe+2YboKrQXkvh+QO+nVfzh2CukjUnnfPxAGq3XOBI7EreAnnHvdNGiZcfu4ltlO8JWPVYDc/S/YXmMLWUwg1coh2Z+shwW/sD4HY/bqG1Jy7EEJH1UbBw3QdCoe08Z7k5+K0egeelPPA3lL601iI1IszK3x6udQn8k787Ns= 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=O0FWgY0j; 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="O0FWgY0j" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5766F2Oi013679 for ; Wed, 6 Aug 2025 09:58:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=B19nWzff1hv gEWIyyHXO3w1PVc/KbOyGfSQee+KWYZs=; b=O0FWgY0jMXuZvT8INsirFECgW5K yAvTdwuWQpyn+n+3PbrSYZfbh9xUk5G+1zIamaYqLy3mmuB/9a1XkqsA4p+K0ZfD tk632x+Q96nyU08O5uBtOota5YhqzwYOFbYlpYQdhdeNZIuzM+8TfZMkJ2k3jXaH zAFOFEdouJCxRI0KuhlNCIgaFq0tNR9YEXcuv+6uK4WbbWpIlOmB+Rjx5+zsXKCt MVyeesfOaQdOUN03gx3/Myawm614X5Tw2yJiiMLZpKMAZYGgojEXH67bf+8WF0Jn KxXUsEuKyXV6wKOHb+q9WqOEO9b5AkXstsASyu3+HenRO2sQtBgjTJKiHgA== Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 48bpyct7de-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 06 Aug 2025 09:58:51 +0000 (GMT) Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-b38ec062983so4402254a12.3 for ; Wed, 06 Aug 2025 02:58:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754474330; x=1755079130; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B19nWzff1hvgEWIyyHXO3w1PVc/KbOyGfSQee+KWYZs=; b=T9MLgyPLSkK+c6cck32RT/lsZdvWq87Eru0KASbFmfTEN9JOHi0cg822L0m6W/fQiM +Uff+7ijVsv9+AHlPxoK3GT2hlC3JvC5bNvh3KXbzwU8DEU3WdC2QRuZ+W9Fm8pIfilv 7Q0WLMuAnHiwR386zjKCyTPSKNTqeR/w+G1lnYIL1f0k7ol/pneknRYhXDONQ2f45PWi oc1LpZ8RzPVBSBNdM1XeBWoQcv7xsLXhYvJvXbXaKroDujHI+rlk1gTeDjm3U6hf/ZHY 15BQ+N9km4EwibAYN8VyoVc/YV+BR07B8iDfqw17ePhv6ohWzvRQh4vHziLW8uKDSUxx iGzQ== X-Forwarded-Encrypted: i=1; AJvYcCVaeUXL9taeBkh0+bZfkZDT8FboAsE6Nz1/A6JXafYwb+q5Y1OGIpG9saw1snUh/dCwBG9hcY+leWQf8HU=@vger.kernel.org X-Gm-Message-State: AOJu0YzndPAtmURRS2RI+fK/zA5UNNZGwSw51r7pyebQFAx8iuvr3/4i K/UvuDYu6/liS7cJTH0NYXA8FLrF1QT/JgdbbRITuide1jJtiwCZmogiFGBHJ4lptoGior07IBr R4v5VzwQB5D4r/1bOu1BGhW9OILyT+zToxHdBS1Nmd9xE5N+M8ey4ZtSzBhWzQLqw3jw= X-Gm-Gg: ASbGncvYO67HrHbFIDQE6u5gAu0v6yvbBLxxuWb9IDAdE5StgOFiZfG5v9W1epnFYPL T1hIaWVq2iDugRTpO9rYxIxJu9eeRm0J53F1OskJmI+vwIzd8CHixWnOm7Bh+FkpSPYJRrnHY3s BMJe3x8nPu7O8w83TZRorJH+PLVBRN5uBM6G0zE+su2duDtcXpMoklNUjRex66+G0EwcyT1AZKI 24OxQYc0b45sLShQnWBRjjpQ9t9IFx/yemcOadbMub9fgA+2SqR9CyVRNgtrXeGEGwjYRuDqmn1 4xHf/SZ/HihYX3bzy91PW9UD/lfHtAdjQ5/20+WNmOpfoZl6TH+oSFP9BvgIKVZXM+5/X2gCyyw Juw== X-Received: by 2002:a05:6a20:2444:b0:240:168b:31b with SMTP id adf61e73a8af0-240313ba206mr3530574637.16.1754474330148; Wed, 06 Aug 2025 02:58:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/N/vlYYg4Dqy9ayFzEBj2EPPs7KLWGVpyO2t2adkmVNL/8seoql8c6zh6YHE7zaDAdVt5Bg== X-Received: by 2002:a05:6a20:2444:b0:240:168b:31b with SMTP id adf61e73a8af0-240313ba206mr3530546637.16.1754474329760; Wed, 06 Aug 2025 02:58:49 -0700 (PDT) Received: from hu-kriskura-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b422b7bb0c0sm12908799a12.20.2025.08.06.02.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Aug 2025 02:58:49 -0700 (PDT) From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Mathias Nyman , Bjorn Andersson , Dmitry Baryshkov , Konrad Dybcio Cc: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Krishna Kurapati Subject: [PATCH v3 3/3] usb: xhci: plat: Facilitate using autosuspend for xhci plat devices Date: Wed, 6 Aug 2025 15:28:28 +0530 Message-Id: <20250806095828.1582917-4-krishna.kurapati@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250806095828.1582917-1-krishna.kurapati@oss.qualcomm.com> References: <20250806095828.1582917-1-krishna.kurapati@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: wDQmoCTUe-10Mi4qL3iN8VTxqw4nBGGW X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwODA2MDAwOCBTYWx0ZWRfXybyz/dCPdO5A SUurhlpXwtfhfd0taous9bx4ElKYDqGWPIhKq4dlWEMJ0Wmhajae3cY6g+7ISBdkzlJutOoGFZn K9u8+p5WfzPbTivZypYbVlZU7J0oQBBYilpPQ8F4IZdtn4hOehUCvSIZm145jfkjVitwbUddVk7 brzFF19F3YaSy3hMBrbRQFH6rMBLft5htBFUMK4nA0xJxO6B9OCHijaJaM1aYr6rWEN4FP6tQW9 wv4sfkBdoWnA3asLbpYjrGSC3Aub7glDrpTVtrIWRprd/A9zbvwK8/FsbWGsJiSTZdz5T/4g2DW 4YRJ6SqTscmdSoad0/cTSmylM5qBvGYUO3Nz93PA6P6Sbd2f/Dx0AjiHCv/XOp5NGT7Ggxy3qUb 6ruwhXSm X-Authority-Analysis: v=2.4 cv=JIo7s9Kb c=1 sm=1 tr=0 ts=6893275b cx=c_pps a=Qgeoaf8Lrialg5Z894R3/Q==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=2OwXVqhp2XgA:10 a=EUspDBNiAAAA:8 a=dywq_Bg9ifu0WOeA0n0A:9 a=x9snwWr2DeNwDh03kgHS:22 X-Proofpoint-GUID: wDQmoCTUe-10Mi4qL3iN8VTxqw4nBGGW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-08-06_02,2025-08-04_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 adultscore=0 clxscore=1015 impostorscore=0 suspectscore=0 bulkscore=0 malwarescore=0 phishscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2507300000 definitions=main-2508060008 Content-Type: text/plain; charset="utf-8" Allow autosuspend to be used by xhci plat device. For Qualcomm SoCs, when in host mode, it is intended that the controller goes to suspend state to save power and wait for interrupts from connected peripheral to wake it up. This is particularly used in cases where a HID or Audio device is connected. In such scenarios, the usb controller can enter auto suspend and resume action after getting interrupts from the connected device. Signed-off-by: Krishna Kurapati --- drivers/usb/host/xhci-plat.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 5eb51797de32..dd57ffedcaa2 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -171,6 +171,7 @@ int xhci_plat_probe(struct platform_device *pdev, struc= t device *sysdev, const s return ret; =20 pm_runtime_set_active(&pdev->dev); + pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_enable(&pdev->dev); pm_runtime_get_noresume(&pdev->dev); =20 --=20 2.34.1