From nobody Mon Feb 9 06:46:20 2026 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 096C828BABC for ; Tue, 10 Jun 2025 09:14:10 +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=1749546853; cv=none; b=RBay4NUlxv12OWShKPIJdV2lEYhGwHByVfSnO0vcXwUWVAPVXWaEn20Jt/5GXOxkPfBDRk36bQ2RpGAAfYOtx++8oo5UhRoY5m/riB3rElHO5Pl8abbaIdDZNSUPLB1cX7u96NgplvlFHkjODbG/l3TFaaKgZzSrIkqVmMhlXoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749546853; c=relaxed/simple; bh=LU0jOvl5YW/dqrJCbHPNKCEBE+8gLqoX0Lq/MwWLwEo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=o4tgn6k2SKRwVp7DfKFZvjumeugWHp/4BhRiAmhvGFoOOTg+unqC+Q+k+v2vbN6wdidt9tPqaU1+Qfgj9he76vI3p8YL4gy2AieOga744jIbpwwuYyrOqOGMS7WBvlprHhEE0fGnBgLI63XjgyTwyQAW4xuS8eWjKGVh1MjBx9M= 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=KYlS/g/d; 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="KYlS/g/d" Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 55A6UG2x026520 for ; Tue, 10 Jun 2025 09:14:10 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=IW2IaMKIFv6 KGfpt4IaYl1TH13UIgVTld4UW1lGpRAk=; b=KYlS/g/ddgQSq49iU6ixlGAJOnf xHww1879n5trB08f1UB2DI8vvUlxUikDaaAwWb4oxIPKcSE3biNxbilBrctVZcw+ poKhzM9eze4HF6JB1LNAYyuooHRZVwizesH/EAPjCsilirv37TSvUg2VmQTvUDee Kh4RlnyV8ss+KoY9LEfsgYWCrDJU4NMkPQCksZ4cANNV5zynzUZYu8rrQhFfZCkk +pUw9kEQeeY9VpjECKaaZCDXCOsE959hz6o5I4YH7AtiZ0B8X/KZVh37pLHWxe1w 5e7F9Nnytr+ukfHj4yEYZIUhB/NTZiF0Andrj1rw7efqwgF4aChv9B1z8Ww== Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4762tg26u3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 10 Jun 2025 09:14:09 +0000 (GMT) Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-311d670ad35so4935861a91.3 for ; Tue, 10 Jun 2025 02:14:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749546848; x=1750151648; 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=IW2IaMKIFv6KGfpt4IaYl1TH13UIgVTld4UW1lGpRAk=; b=IJUFVj4bcmt7R1QPjIwjSS7ZNs3l4wvK0gn/FWqAFiQLIZkfRqvypxmuqPpP7fwYzt I91nZ4tCzjhIL3TcqZvJpM42J72k3/q8FLDyl9H0kOPnWKmbbK6MJczQf9/aS6XtiSR1 UVil8MmJr+w4pad/K5eme2aoJN1aZfF25uos5SpNL/eNucruo/NPu0AP2VEeJgB/aRE2 F0W6myBjdYxPaNfM+5R3bV2IAyEygLqVinXzqWZ1H569hAG6nUZalwAHv4DWvl8ZXhxs eqEdwubPY6vOxs3NmXE/Pb7S/YrCDwYp/ezUzB7iUgInPXdlBFQXzyu+0XlrGVfppq8L 98zA== X-Forwarded-Encrypted: i=1; AJvYcCVdUXkitzIkWVuIOlQmBuHYsiIXhpzXYwSU0BuHrNek2rkP9BzVYT/vfgxw+qGLhdOSvoCd7kqVZhzckEo=@vger.kernel.org X-Gm-Message-State: AOJu0YzB4kEewmjtfTM0KKyVBULGDO5qPpT2Lv5nStGLayiW16j7nuJ4 cYztKZxx3NcD45wyit4Y/NVZHa59r3hdvnem989WPX7fjKvuYDOo8z01OpwF196ChCgIoZEhZLe UfPD0y+2SI5FYsiOv4hnf27qma1kSFZtZCd9fx1vVX0BguUaDHmbGGaRGZu/CB2Yn66r/tMFrx6 o= X-Gm-Gg: ASbGncur0CAmqZ78p7ejVbk7YVDNWIP+FYy/99yTBi0etRly4VkeHkamd4HM1O2BQK4 6/ifQ26VIeSrHglbr0WUoqC/cDt9jGfB2ogZFcx7hv1b3TjfjpRy2Roi4vrPqiqBnfWfobaOqAm NNetiJqhfzDJWBYaHQ9IFKYfQvOKCzVGi/St2nFNEj13uSgt/IIijiyonrcv+dn1Qn0FCzntGKx W45GRkLjwqLFFRQmLQPbzh4sDkMrLv5wujmCb5IVyNaMvaCSmSAiRYjP5mmz8YpYvJPciOYZKpK IJrSB9Jp2whLOKbLtxk47dcgeNGSw6M1fdLQxi1ySdBb4Ewp35AHTeNHD029 X-Received: by 2002:a17:90b:4ac4:b0:311:df4b:4b8a with SMTP id 98e67ed59e1d1-313472d6addmr21278030a91.3.1749546848228; Tue, 10 Jun 2025 02:14:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsG1LuXcHwnJ4beYC1YR8EHTHc+dLRuDKscJNuMFCK8a7ACZsEE7fua0rYmQ7NPTqLSZUWDg== X-Received: by 2002:a17:90b:4ac4:b0:311:df4b:4b8a with SMTP id 98e67ed59e1d1-313472d6addmr21278005a91.3.1749546847840; Tue, 10 Jun 2025 02:14:07 -0700 (PDT) Received: from hu-kriskura-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31349fc3e72sm6913550a91.31.2025.06.10.02.14.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 02:14:07 -0700 (PDT) From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Bjorn Andersson Cc: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Krishna Kurapati Subject: [PATCH v2 1/4] usb: dwc3: core: Introduce glue callbacks for flattened implementations Date: Tue, 10 Jun 2025 14:43:54 +0530 Message-Id: <20250610091357.2983085-2-krishna.kurapati@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250610091357.2983085-1-krishna.kurapati@oss.qualcomm.com> References: <20250610091357.2983085-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=OqZPyz/t c=1 sm=1 tr=0 ts=6847f761 cx=c_pps a=0uOsjrqzRL749jD1oC5vDA==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=6IFa9wvqVegA:10 a=EUspDBNiAAAA:8 a=9UFxAfr_hboBSpCGZXUA:9 a=mQ_c8vxmzFEMiUWkPHU9:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjEwMDA3MCBTYWx0ZWRfXxsbB9hMZuBND jZefU6qrfm/aP4ASy1rfj9wxQ055MULSDEZgCCJ6Zva61T2swqegd6kX5xdM5aS00IIMib8JhWR /Wgv2mbchfpqYpPQbw7VhSSy39be17ZMWyuxz0HmRdHrpysFOTgM5sNHhW3FpfAwa3R7Ffxuab+ gL7XIEY4Ykpj8xn1nryOmI5ABxKrQVZ7x7VB8xjRdu1kVLLZJbs92lOrSXA9dB/LzPJynGu3Qoc w6cQ/09xOSVc3OyM2X0aEedmlx/uNGj2FELbHFBrGyz1qxzFOkQzpFAh+/Ipuub3cx2cufC2k6A iit2G3poqFGfToB8b2un4nNJ071uE6CAVmaPT6LKr6aHSe/J5K6zYqda20Kl7QMFoBHXqMS5o/G Vp7FW8Pgv1odUDqiC5OviMTm2Jd44xK4XxREpShKXm4hmf9ItHUI37T+sWU30cplZc/yUCfK X-Proofpoint-ORIG-GUID: YwCdcT61-g9AWS3r2FUbAxWcdjC1ZUYF X-Proofpoint-GUID: YwCdcT61-g9AWS3r2FUbAxWcdjC1ZUYF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-10_03,2025-06-09_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 clxscore=1015 phishscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 priorityscore=1501 impostorscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2505280000 definitions=main-2506100070 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 2bc775a747f2..c01b15e3710f 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..a803884be4ed 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 (*notify_set_role)(struct dwc3 *dwc, enum usb_role role); + void (*notify_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; @@ -1400,6 +1412,8 @@ struct dwc3 { struct dentry *debug_root; u32 gsbuscfg0_reqinfo; u32 wakeup_pending_funcs; + + struct dwc3_glue_ops *glue_ops; }; =20 #define INCRX_BURST_MODE 0 @@ -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_notify_set_role(struct dwc3 *dwc, enum usb_role ro= le) +{ + if (dwc->glue_ops && dwc->glue_ops->notify_set_role) + dwc->glue_ops->notify_set_role(dwc, role); +} + +static inline void dwc3_notify_run_stop(struct dwc3 *dwc, bool is_on) +{ + if (dwc->glue_ops && dwc->glue_ops->notify_run_stop) + dwc->glue_ops->notify_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..408551768a95 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_notify_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 321361288935..73bed11bccaf 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2641,6 +2641,7 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int= is_on) if (saved_config) dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); =20 + dwc3_notify_run_stop(dwc, is_on); reg =3D dwc3_readl(dwc->regs, DWC3_DCTL); if (is_on) { if (DWC3_VER_IS_WITHIN(DWC3, ANY, 187A)) { --=20 2.34.1 From nobody Mon Feb 9 06:46:20 2026 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 AB6C728C5D8 for ; Tue, 10 Jun 2025 09:14:14 +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=1749546856; cv=none; b=Py17ARj3FvMY4Gslx2gLvI47LN8xQaQG80ttDOgHoKmSkfsfaP2iUONuyQ/sS+rlc4gZukiSZWrGH9QnWifRh9JbQno6sJaWuPJ9sLh8ilyH88K9TFDaLM1j6/phhnrAgatyqNrkdMpK+BdvH6m5RwuITRPH+llRaTK/fbcn81M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749546856; c=relaxed/simple; bh=XZz8NYJcJqcKiaoFso9j55BbEfdRP7VRJYZy6cqw9xI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=brMBgq0ApXVWSlrMUoJ/g2mT8k11iVKaIpqhxwMI9t8JxbkJ7a2ypLSgO1xiY7T1yVRIRkv/Du19xc1kjczahxjG3SLFSYjUMHbdMpgu7LEgmajS0Xu4hH3iH3Q5QdMtTdNvvdMMYjQuATb/xFnq+C/KSxSKZwW4OysBhPh4t6Q= 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=C6nEv3E+; 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="C6nEv3E+" 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 55A96MXd019609 for ; Tue, 10 Jun 2025 09:14:13 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=Ga2rUmJ+JCY bbNKq4VW4zGbDsFYBkFaP6dwRBff0Hrg=; b=C6nEv3E+F/xziSyANiQLmI1N/zp 1OP27zq0xf0ufBmPp/uuWWtPRfvSilvGEplbxaSmwx7CvtjfW5Rvz98Le7kXZnV3 i53jP9cddMc3q2VpbxtYb0lWZZPX80A3PR7L2e1z5cfuRd6ilsREItjPh7QxsT9I 3VoU0+zO7NzOTvVwaWUTlcR64wbKTobKAa3XwCVkgjRGrTtC8IcG2WWON9R0Rml1 vVUhdN/S62cvQeOeXvy/dhQWjqXsJRBeRDwfzrywUe/BHtYfAAUpIsSQPNqJ4Rbj VSmeKesAh2YUe1wXGBZfex7010Azfwh22ChNwnQH3BCLvt1Ua/oU6koXkyg== Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 474ce9rvdx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 10 Jun 2025 09:14:13 +0000 (GMT) Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-231d13ac4d4so80930215ad.3 for ; Tue, 10 Jun 2025 02:14:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749546851; x=1750151651; 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=Ga2rUmJ+JCYbbNKq4VW4zGbDsFYBkFaP6dwRBff0Hrg=; b=v21SjaEZc+XaFAUWv/FYk4TjLCOvm3hZrLZLuDmZdg4IFJ10/hnLnv1CzBRWi2jRWg sGhiCAdFxk0JBrRsBQ8eghA5iVKCVM3XovpWCecMQF/qmKo2y6f8Mqs3VtIhREE3dZOY t3rharLTIEB1fLt81jzoQk0PkN7Pcy8i7TYGI1Yd+DYeG8OyaM/QK5ArcqIaxHyR08eS fQxn1D2k/KBooQ1zYACW07HjGISVC7mfrIplIegnLda73cWr+0ck2hEZDqi8xrSewN46 R4ki8DFOoT0xGeCXOSP+1BjbXNGIc9D6D/jsMWxLIQyit0LSlq1AzfunFKeCvtcs4OZu QEVw== X-Forwarded-Encrypted: i=1; AJvYcCWj0Sm8EFBDXDgNhjGtdfYJHSukVAx3A2vKK/vBxdPnwP3SxVm37Ffz1lRIjf5a5B9bUszOvcyoh97iSqE=@vger.kernel.org X-Gm-Message-State: AOJu0YwZgItZqr+TXwoZVr4Ph2U3s6MtbPJwaXR5aLeImuo5VG9802QA v4XTRgomEHrB85DuN71fGMCCpI2h9qV/Ol0+vVBJ7mDR5TE27VdGrFPDpU8r2lM9rirXuoKszj2 wwh7QCtFWQ5jWdQDtpQdUxTUwQLsSarnXIgkDBkS4AsES8UWnNNPWFooX5aMFScrYTvI= X-Gm-Gg: ASbGncurPc90Byu/fsJI1usFVngMzu+GexLSv8T7eO5RV6T7QptHX3Bio7Q+dJiShT6 efJFrm2VIlCKRSL8+/ErDM1vfLUgcCvZ6eDIILLL4UaMeqotWYUA0y2m5bL3bAU8/brFjyAKvpF 0Ako/IHc5/E8fykPTu6ZQS2CUx40D3gV+D8hOg1hXmR1H/BKP8TDxzJHP9T++f2umQk49U4koQ5 pC+iu8VeopZwW9jk5DBQeNknifsYNAHefqMnw9q0SglIrk8YOOUUb05syFAcWEb1yEJMxh2BCEq DHvlqAhDdn+hT4085uzszJy9y2yjs3ubpMNBm0B3C4l9N80zQ2qy0I/FNh78 X-Received: by 2002:a17:902:e742:b0:235:1706:1ff6 with SMTP id d9443c01a7336-23601b49d15mr242506655ad.0.1749546851530; Tue, 10 Jun 2025 02:14:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOwMPNGYBQKcN+lk7fWsFHzfkA7PJwctZFoqHIwgQuY6QdCy4j8d4zLM9Q0vh1s9frun+smg== X-Received: by 2002:a17:902:e742:b0:235:1706:1ff6 with SMTP id d9443c01a7336-23601b49d15mr242506245ad.0.1749546851127; Tue, 10 Jun 2025 02:14:11 -0700 (PDT) Received: from hu-kriskura-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31349fc3e72sm6913550a91.31.2025.06.10.02.14.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 02:14:10 -0700 (PDT) From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Bjorn Andersson Cc: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Krishna Kurapati Subject: [PATCH v2 2/4] usb: dwc3: qcom: Implement glue callbacks to facilitate runtime suspend Date: Tue, 10 Jun 2025 14:43:55 +0530 Message-Id: <20250610091357.2983085-3-krishna.kurapati@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250610091357.2983085-1-krishna.kurapati@oss.qualcomm.com> References: <20250610091357.2983085-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-GUID: FxCHImyomHko6jvGahlbaaBWuvBHpDdo X-Authority-Analysis: v=2.4 cv=drjbC0g4 c=1 sm=1 tr=0 ts=6847f765 cx=c_pps a=JL+w9abYAAE89/QcEU+0QA==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=6IFa9wvqVegA:10 a=EUspDBNiAAAA:8 a=ProRYBKZBCDr5nQBVQAA:9 a=324X-CrmTo6CU4MGRt3R:22 X-Proofpoint-ORIG-GUID: FxCHImyomHko6jvGahlbaaBWuvBHpDdo X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjEwMDA3MCBTYWx0ZWRfX72rqTfnGcacM Q+88DJZ7cfHeInzcwdSsCa+omhl0X6m4oFBJH5ya8TyCGz6gVorGcf/aGmHqWDTynkBMWaVTWq0 4l/hRIy/Mo0tOC6VaqcccVY0Yr7PYBdA6wQ0bhcJ6pG2/ZCSnWW6ARU6qyNvnnvwaIHG+VapqIr rs5plRAduv2ftpuUPX+HU42UBHS9vaS43u3dCKRPCyj7IP9K+jjkzETTpAsdpE+CWrcxnvzbKeh 7whpIjU5auBmBX6jeThVnM0KucN4htCRZA6gjITpQyx6dHbwPBCrmg8vCcq2MnsXqfUtdcjXtM9 lXGE1d+0lVIHuz5cPnyh5SZ1/PORUJ7uXW/+X086A01GvkLuGTczkEepaR/eJyx2vsjNMFT6ZVm s8r00tyuzA9qrJ4JTyAlVwyvLsiB81HpOZWgo0juzt8kGATnoSfet1wSk1ptaukOUzbyuXIu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-10_03,2025-06-09_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 suspectscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 phishscore=0 mlxscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2505280000 definitions=main-2506100070 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 | 82 ++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 9 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index ca7e1c02773a..d40b52e2ba01 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -89,6 +89,12 @@ struct dwc3_qcom { bool pm_suspended; struct icc_path *icc_path_ddr; struct icc_path *icc_path_apps; + + /* + * Current role changes via usb_role_switch_set_role callback protected + * internally by mutex lock. + */ + enum usb_role current_role; }; =20 #define to_dwc3_qcom(d) container_of((d), struct dwc3_qcom, dwc) @@ -118,9 +124,9 @@ static inline void dwc3_qcom_clrbits(void __iomem *base= , u32 offset, u32 val) } =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, and drop extcon - * handling from the glue + * TODO: Validate that the in-core extcon support is functional, and drop + * extcon handling from the glue. Make in-core extcon invoke + * dwc3_qcom_vbus_override_enable() */ static void dwc3_qcom_vbus_override_enable(struct dwc3_qcom *qcom, bool en= able) { @@ -641,6 +647,53 @@ 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); + + 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 { + .notify_set_role =3D dwc3_qcom_set_role_notifier, + .notify_run_stop =3D dwc3_qcom_run_stop_notifier, +}; + static int dwc3_qcom_probe(struct platform_device *pdev) { struct dwc3_probe_data probe_data =3D {}; @@ -717,6 +770,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 (qcom->mode =3D=3D USB_DR_MODE_OTG) { + 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; @@ -731,12 +801,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); - /* register extcon to override sw_vbus on Vbus change later */ ret =3D dwc3_qcom_register_extcon(qcom); if (ret) --=20 2.34.1 From nobody Mon Feb 9 06:46:20 2026 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 551BC28C87E for ; Tue, 10 Jun 2025 09:14:17 +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=1749546858; cv=none; b=m+75nQHiOuCdslEkW8jvqDnbjmL+/bD8Mm7QEhD3D6yyuf5AEUL5DwEA0PGCDLUgBj5MnNU6mFiGhpaRqZ9uaTcHitH32JX31dAwkwBjp7KP8KLmCqZEyuddT1IGjzPj/kzlj4MOwlXQ9k+DtM6vTxi3i51gQkqZAcv3Apg+EYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749546858; c=relaxed/simple; bh=iru2/JKFS5VA0xmf3oFMPSCbMsMXc0mxSWJDqq5yqUA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e82YdfZAKVkR1fVxnGpyuVB/7fcy1uTOq9/KMlTZW8shEVnDGDNmMTmptnIRyRFczrIVveJh3UQgbd/PoFPeKZnlzEggbvEdMBOpcauZYdRjwILrYW4Afs2J3giz7EmnKglGWIyQMvW/EXyz1IIyzIZ/zxeniDQ1hNIKoiSEs9U= 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=mhZcr6mL; 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="mhZcr6mL" 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 559MLpX6026500 for ; Tue, 10 Jun 2025 09:14:16 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=RnvvbqWSyaQ 3j/Id/nFgBao1+PiRTLwvAm3KqEZeyH4=; b=mhZcr6mLXGhdMTrkWimSjOHFr99 S6yb2YI/nu54D5M8lD+GyQe6OmMA2umhEzUPs4kLak8vIE6ds0hXw6gaaOAIzHYy 1+JrtpfY7qvHWG3KWxN3Shq1RrL2XYD1duvxXUz30+C49jWA/gVFqy9PNcTccI6I 0EcsJLpm4NbgkFXjXhH4zkx8EvTnaDoOCp6TZBIlIVzHz5h3yglLLG6rXR9jCI7q CyPCOIRpFet85S2B64oNnSNDtpoEcHcrk2qBv13V5Q7++1m90lSmafT3O1RRfm2M pbRmN3Y5OWOudPB3r1uX3yxcwUFfQExNazlumfD1M9pDXNaQ8R7x/vP8WdA== Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 474ce9rve1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 10 Jun 2025 09:14:16 +0000 (GMT) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2350804a43eso84506455ad.0 for ; Tue, 10 Jun 2025 02:14:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749546855; x=1750151655; 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=RnvvbqWSyaQ3j/Id/nFgBao1+PiRTLwvAm3KqEZeyH4=; b=GqrT7oWStfQ8NAWRAraHHfrhxEY7+SRpqqaI7qE39m032LByx4GuLFsT3tjPUpNN+n 9dOex+GCz1mCaK8GF9F5OroM+qpu0EjuhP6+FSzRCdawI0fszooNM+0URLMHX06sKQ9P H7tvMtjhmLn641CvZPdFX5a4k6FrRn9mGpamnUBOKL872rK9AyvC1eiKwkUtr1gqsJoE u+EkjywODpcFFFOPbSHCMo+hZJLXUsE0PyLR2VA9h/53OX3Jrq3Q4PXkS2bC/GCunvVB SG+/t3EVM4QUHZlpd/XyK3D5pLzcDTZ50M3e85inT/8OVMQcH8Zcb8wHgwi1UwCuacIO 8dPQ== X-Forwarded-Encrypted: i=1; AJvYcCVXZoGENvUfUKYGvmoFh3AHiORkNgHQXNNBzCJLML/HkZyc513RZq06vhjRR2Y+O/4CKZBkGlxySEgGN90=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9i2DdSmz1T4hDJLUAkeuouMHaAHIhAbf7XKH5DMkA8U1tGxvy /IHDePsifCYIIBwofeiEc28/WTPVtcE+suZY0Q9DFVWx9FKgvcgURiGBjqxoTNqL5S2+poQIfOM UvfAub+uvY7SW7SUWd7/FI0EM5qlUxczLCF+dZZqbIUUG8gBfWvj01tjfJmmHFJPPK00= X-Gm-Gg: ASbGncs1GVnLP/6nt+jv28TkwbXJz9yV/3F8+hxHWq6C7xHORk8IzD5e1JfFuPMFj5f IwHMqp9QLCB87erpOKNfll7BZTaJIE6D5pBiR3F0XnPyvsrF0QiZSwCynjje5pGDbqCiGNeY8gb wxbBJfTrQ2MC0HUtxpuh5OjpINfhgUjBmDO8YTihl1GtS0PKgFgDCkcA2ljLibNrBecVTM01Bmg v/MoW8V6wcOrjSxGJLIWl4S1QjaL7D2ySPfjMD9kHaUuWuw5CbqWgaQuFljbql9G+IwZ9rcf0Ou jDh8n7OwgpLk6i2ujKA2LSdnbkXmDTUC7DYS8KU25IVeDmBQi1KvpNmcDYux X-Received: by 2002:a17:902:ecc5:b0:235:eb71:a398 with SMTP id d9443c01a7336-23601deb495mr246989585ad.53.1749546854791; Tue, 10 Jun 2025 02:14:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQwCxRk7YOVwl4mE79Lsr5OwMTss00V2UBmwFjYouuPybuq+HoxmG2443b8pdtM1P9I7UPTQ== X-Received: by 2002:a17:902:ecc5:b0:235:eb71:a398 with SMTP id d9443c01a7336-23601deb495mr246989165ad.53.1749546854336; Tue, 10 Jun 2025 02:14:14 -0700 (PDT) Received: from hu-kriskura-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31349fc3e72sm6913550a91.31.2025.06.10.02.14.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 02:14:14 -0700 (PDT) From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Bjorn Andersson Cc: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Krishna Kurapati Subject: [PATCH v2 3/4] usb: dwc3: qcom: Facilitate autosuspend during host mode Date: Tue, 10 Jun 2025 14:43:56 +0530 Message-Id: <20250610091357.2983085-4-krishna.kurapati@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250610091357.2983085-1-krishna.kurapati@oss.qualcomm.com> References: <20250610091357.2983085-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-GUID: 46-D0UQX_KeDpx_WxEHEtdtcelvtT49F X-Authority-Analysis: v=2.4 cv=drjbC0g4 c=1 sm=1 tr=0 ts=6847f768 cx=c_pps a=cmESyDAEBpBGqyK7t0alAg==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=6IFa9wvqVegA:10 a=EUspDBNiAAAA:8 a=5CM_793GkT3ZRPfwn_AA:9 a=1OuFwYUASf3TG4hYMiVC:22 X-Proofpoint-ORIG-GUID: 46-D0UQX_KeDpx_WxEHEtdtcelvtT49F X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjEwMDA3MCBTYWx0ZWRfX1fZ7IGEOpbD4 a3Dr83jDdSJmnbTop6hJkkUxGRmXjU8FUAHrucS/iwJYyEWpB8u/SyAs5g4V0+nXouRrMCE9qUI o4xwSM/0/QzUpXyMCiaftr1AAoQvVe141p4Z/qkBNEKcYzVx9zAXlBKFlzEKTtsi8GtF2hfn8XT 8rQMgjKgXJk1xyUjMxCPqJ/Ik7jeK4HggOBKjGdzb29IAKC9Cw+bWIdYDrKEC1df403TNfWER+R tOWXgXX272+oCw31ji67Z0cDTS2cKZlwfjHoXLfoDKrGqLl7ovKCh/CH07r/femd1qjK2B7Kyal YMWc4Aviz43e5+UWD3bV9jWMOHT2PuL6Qc9Ve4cgFnZM8CbYOj25y96Z2WoGIslOBsA1igdGcTA fsiftIxoglnTxjvHNLXzKOPM9vhGKnt7sUoApmVHb9j1q6Rs4tdL3GkckP7SOiXhnHYGNQy+ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-10_03,2025-06-09_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 suspectscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 phishscore=0 mlxscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2505280000 definitions=main-2506100070 Content-Type: text/plain; charset="utf-8" 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. Allow autosuspend for and xhci device and allow userspace to decide whether to enable this functionality. a) Register to usb-core notifications in set_role vendor callback to identify when root hubs are being created. Configure them to use_autosuspend. b) Identify usb core notifications where the HCD is being added and enable autosuspend for that particular xhci device. Signed-off-by: Krishna Kurapati --- drivers/usb/dwc3/dwc3-qcom.c | 62 ++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index d40b52e2ba01..17bbd5a06c08 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -95,6 +95,8 @@ struct dwc3_qcom { * internally by mutex lock. */ enum usb_role current_role; + + struct notifier_block xhci_nb; }; =20 #define to_dwc3_qcom(d) container_of((d), struct dwc3_qcom, dwc) @@ -647,6 +649,39 @@ static int dwc3_qcom_setup_irq(struct dwc3_qcom *qcom,= struct platform_device *p return 0; } =20 +static int dwc3_xhci_event_notifier(struct notifier_block *nb, + unsigned long event, void *ptr) +{ + struct dwc3_qcom *qcom =3D container_of(nb, struct dwc3_qcom, xhci_nb); + struct dwc3 *dwc =3D &qcom->dwc; + struct usb_bus *ubus =3D ptr; + struct usb_hcd *hcd; + + if (!dwc->xhci) + goto done; + + hcd =3D platform_get_drvdata(dwc->xhci); + if (!hcd) + goto done; + + if (event !=3D USB_BUS_ADD) + goto done; + + if (strcmp(dev_name(ubus->sysdev), dev_name(dwc->sysdev)) !=3D 0) + goto done; + + if (event =3D=3D USB_BUS_ADD) { + /* + * Identify instant of creation of primary hcd and + * mark xhci as autosuspend capable at this point. + */ + pm_runtime_use_autosuspend(&dwc->xhci->dev); + } + +done: + return NOTIFY_DONE; +} + 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); @@ -659,12 +694,22 @@ static void dwc3_qcom_set_role_notifier(struct dwc3 *= dwc, enum usb_role next_rol return; } =20 - if (qcom->current_role =3D=3D USB_ROLE_DEVICE && - next_role !=3D USB_ROLE_DEVICE) + if (qcom->current_role =3D=3D USB_ROLE_NONE) { + if (next_role =3D=3D USB_ROLE_DEVICE) { + dwc3_qcom_vbus_override_enable(qcom, true); + } else if (next_role =3D=3D USB_ROLE_HOST) { + qcom->xhci_nb.notifier_call =3D dwc3_xhci_event_notifier; + usb_register_notify(&qcom->xhci_nb); + } + } else 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); + } else if (qcom->current_role =3D=3D USB_ROLE_HOST) { + if (next_role =3D=3D USB_ROLE_NONE) + usb_unregister_notify(&qcom->xhci_nb); + else if (next_role =3D=3D USB_ROLE_DEVICE) + dwc3_qcom_vbus_override_enable(qcom, true); + } =20 pm_runtime_mark_last_busy(qcom->dev); pm_runtime_put_sync(qcom->dev); @@ -774,6 +819,8 @@ static int dwc3_qcom_probe(struct platform_device *pdev) =20 if (qcom->mode =3D=3D USB_DR_MODE_HOST) { qcom->current_role =3D USB_ROLE_HOST; + qcom->xhci_nb.notifier_call =3D dwc3_xhci_event_notifier; + usb_register_notify(&qcom->xhci_nb); } else if (qcom->mode =3D=3D USB_DR_MODE_PERIPHERAL) { qcom->current_role =3D USB_ROLE_DEVICE; dwc3_qcom_vbus_override_enable(qcom, true); @@ -794,7 +841,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev) ret =3D dwc3_core_probe(&probe_data); if (ret) { ret =3D dev_err_probe(dev, ret, "failed to register DWC3 Core\n"); - goto clk_disable; + goto unregister_notify; } =20 ret =3D dwc3_qcom_interconnect_init(qcom); @@ -817,6 +864,9 @@ static int dwc3_qcom_probe(struct platform_device *pdev) dwc3_qcom_interconnect_exit(qcom); remove_core: dwc3_core_remove(&qcom->dwc); +unregister_notify: + if (qcom->mode =3D=3D USB_DR_MODE_HOST) + usb_unregister_notify(&qcom->xhci_nb); clk_disable: clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks); =20 --=20 2.34.1 From nobody Mon Feb 9 06:46:20 2026 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 B606328CF60 for ; Tue, 10 Jun 2025 09:14:20 +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=1749546862; cv=none; b=a0405dijHeyCS+yzLK+ToOfbpIWtKWiWLYx1dH/WYAg1TshHJfp+CoSZ3E4zq9bzLi3lUzKt+gLt2Gg6OghCBE8QX8grZw1LqIBpQjzY/BlyLpzVeCGydSxJwZsZEsWP8UWstrhi/va71SfpmjjCrUAhFrfvXS2v15WWUJ4GitA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749546862; c=relaxed/simple; bh=euV+fbYXNTbYMl4eJVb4KK0RriCHNxifXVblrf9rQ20=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Pj0ZTRCbeNgGmztesYLuQvZd9AJwvyHhoB7KZuKQzcPxEd1CH1R/j5V6Xj0CL3S/Q6C/SF6eUI6+bDx7O2ORwRCbGavsfkAAWKqN7UsI3VwB6vealxDi6xH9SfyOsAjQh2oKzj9QPHXcQKuXZWYLtcRb/G/CvprQv71XgMWF8ew= 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=O4ZgTby1; 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="O4ZgTby1" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 55A8fL1g017716 for ; Tue, 10 Jun 2025 09:14:19 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=Nk+S4I0TlH2 z4qmWoHPeH+Psft3DzglIZdxip0XMeN4=; b=O4ZgTby1v4QYeaY5EhV/Dd34Wk1 js7nNev59Imtwd6iJxpmJ8o/tRsBPGai++SeTGVR3cRX/s+7ZZY+QL+r+yclVOZM 4AmS5Te677kWH8TEnpn42kVt8paOMzlGAzDpc5G+4z/5pX/uc2j+vX2irLhsVtub NFzf+1E2wbqiQesZyZnQ8eYDaRyuYBKo8lT6791ZBd8t9WYkgIUciXSoxpxccjCq 4ZqtMur5b/w+Xf6sRjlGRwfFklPo8e5wY21xH97F6JvMQU+tA4oZo9IksN/cT0C0 55OnPUMgYmvYDaG98bR5fPGYI7uGUnHlDFjwITYSYwG84r11oWy/q8M8PjQ== Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4766mchjgg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 10 Jun 2025 09:14:19 +0000 (GMT) Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-3122368d82bso8127705a91.0 for ; Tue, 10 Jun 2025 02:14:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749546858; x=1750151658; 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=Nk+S4I0TlH2z4qmWoHPeH+Psft3DzglIZdxip0XMeN4=; b=hZw+G/xf3v/kDzEQdlMhOASl+XPbuloIsVbMo+NTMGAk/Juf6SOEWFxWqcA6KVc3Xd cy7ZBrhje36i605UVT9E1XTAefvmizepWaJkzEP6AHe6Clnj6rL1pyLThhLXPFZxyBZV XcjFXji3IveCDweJlgr+SwP6WRlfBL2yoP39bviCEDv4BQwlKnf0S/B/jsvaYJoUjlBN ZznsdVwA3cW9li2WUE+ZEKTVOy0hkKA2HcQqTd7ez6r0GQiXl+wQQploXzn83bbpYFyh i7crXw1kp/Uiw/hhLK0P8kCieGJLUyS66A9/lensAc4kySb9Q0JUdJAUUgSE7DwGFM5P FeRA== X-Forwarded-Encrypted: i=1; AJvYcCXzTLZKqVupVrqbFQ8kHGZ1wdCgxfEKjrURAJUj5xJtMCcYq5pIfq3Yx/WZnijdgyd3WX4dNUHSv/i3ksg=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8yiUzvc/42Ul3u12Lt7lAowglvU0enQZVYX4nbEDMeCyAf/71 hoAenKk7kNqzrUWgGBOdKG642+BlMm7A738Nbm0Wil5JFd043AZDRefDQGPLaER6ZlT0AHoUG/m TFwAGiEAuk4CTTH5f2d5nyCbK9P4aA1r0dTSJyQcrL3uwsCx2ah0VWjMwgIh36VWlnu4= X-Gm-Gg: ASbGncv5jWUFwo69WVa77gj/rC0MmStXnCMb8AUfe2DOMsiadlWbR8quiEWh002Cmmc 5zBln2wfBksdXp2m59Yd5U8QOaLYaEJKPr3r1Xvl/y8i4cHdxJCaSvRXVhR21aKV1e5kPhkbbjV 2mOF1XhQCE05lIJZg3xi3av20YzjxKkjgMf33UL9i8jwzRWwwXLFn9d7qMPgJEhlen8/O8/3JT2 i6/WmJLCda//HCpCB2Nra2BvqssgbQvNTNZaHFVtmgrlnhe8rkw6L63io/ZBQEHHSJOVGk6nvem 5yRlKAFgM9AUd3QsIl9/FdLVHHuPnMoSpGBJszSTYgyDwAv979RpVCnjO1Iz X-Received: by 2002:a17:90b:3b92:b0:311:a4d6:30f8 with SMTP id 98e67ed59e1d1-313472ec763mr22830132a91.13.1749546857950; Tue, 10 Jun 2025 02:14:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELox5dA0ziiallWsp271HuMBN3cbaKKMWH6TLzvTwcc9o/ILNrURvqAD8FhsIAGvrwut4eEw== X-Received: by 2002:a17:90b:3b92:b0:311:a4d6:30f8 with SMTP id 98e67ed59e1d1-313472ec763mr22830082a91.13.1749546857459; Tue, 10 Jun 2025 02:14:17 -0700 (PDT) Received: from hu-kriskura-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31349fc3e72sm6913550a91.31.2025.06.10.02.14.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 02:14:17 -0700 (PDT) From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Bjorn Andersson Cc: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Krishna Kurapati Subject: [PATCH v2 4/4] usb: dwc3: qcom: Remove extcon functionality from glue Date: Tue, 10 Jun 2025 14:43:57 +0530 Message-Id: <20250610091357.2983085-5-krishna.kurapati@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250610091357.2983085-1-krishna.kurapati@oss.qualcomm.com> References: <20250610091357.2983085-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=T8KMT+KQ c=1 sm=1 tr=0 ts=6847f76b cx=c_pps a=RP+M6JBNLl+fLTcSJhASfg==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=6IFa9wvqVegA:10 a=EUspDBNiAAAA:8 a=HsaRtseu1FE5unmruSMA:9 a=iS9zxrgQBfv6-_F4QbHw:22 X-Proofpoint-ORIG-GUID: f6K1FklQACTJ4l8dBUTGoRVu7RluC2Bp X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjEwMDA3MCBTYWx0ZWRfXwCkaRm1+0bYj WbSErJhjs5WzCpqvVJghYwNMu2sO5RgwJ1K5bk0GIcb1h0fjvnzy3dTM7LgijT7hU4c7cO/ntEX U8X93fZNhpd90hRuz8SGYCREc/YWNkUWlaReo5/zbEiOO72CUAOyLV0bxzkGNPSywt8190b6vJJ zZ+MNObBtvYtYPA2DUghxHlfBmWveL6XVgvAJAkFYA10xF97UY3d/A9P/z0ighZDCneFiVMHRwc LC7J8/m/XQcOpA5sGRfzBGTyE/+tD47AtQoeYhUign1srUiKVu0n7szpf0v9vNWOB/WYkVAc7g0 o9RDtePU+HldbI8WBl27oCOYMI9sym6UZdSBHBvPZINx/zdGUxRvcHbTPnzyAszjzk/94icpeM+ w9in136niBqowJ6c013I/+9opWrwEulfxKCMj1nmeP0wTgAYR7WYj8AYK30EN7UB6fWJlrY2 X-Proofpoint-GUID: f6K1FklQACTJ4l8dBUTGoRVu7RluC2Bp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-10_03,2025-06-09_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 bulkscore=0 clxscore=1015 malwarescore=0 impostorscore=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2505280000 definitions=main-2506100070 Content-Type: text/plain; charset="utf-8" Deprecate usage of extcon functionality from the glue driver. Now that the glue driver is a flattened implementation, all existing DTs would eventually move to new bindings. While doing so let them make use of role-switch/ typec frameworks to provide role data rather than using extcon. On upstream, summary of targets/platforms using extcon is as follows: 1. MSM8916 and MSM8939 use Chipidea controller, hence the changes have no effect on them. 2. Of the other extcon users, most of them use "linux,extcon-usb-gpio" driver which relies on id/vbus gpios to inform role changes. This can be transitioned to role switch based driver (usb-conn-gpio) while flattening those platforms to move away from extcon and rely on role switching. 3. The one target that uses dwc3 controller and extcon and is not based on reading gpios is "arch/arm64/boot/dts/qcom/msm8996-xiaomi-common.dtsi". This platform uses TI chip to provide extcon. If usb on this platform is being flattneed, then effort should be put in to define a usb-c-connector device in DT and make use of role switch functionality in TUSB320L driver. Signed-off-by: Krishna Kurapati Reviewed-by: Dmitry Baryshkov --- drivers/usb/dwc3/dwc3-qcom.c | 91 ------------------------------------ 1 file changed, 91 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 17bbd5a06c08..1a73a7797d41 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -79,11 +79,6 @@ struct dwc3_qcom { struct dwc3_qcom_port ports[DWC3_QCOM_MAX_PORTS]; u8 num_ports; =20 - struct extcon_dev *edev; - struct extcon_dev *host_edev; - struct notifier_block vbus_nb; - struct notifier_block host_nb; - enum usb_dr_mode mode; bool is_suspended; bool pm_suspended; @@ -125,11 +120,6 @@ static inline void dwc3_qcom_clrbits(void __iomem *bas= e, u32 offset, u32 val) readl(base + offset); } =20 -/* - * TODO: Validate that the in-core extcon support is functional, and drop - * extcon handling from the glue. Make in-core extcon invoke - * dwc3_qcom_vbus_override_enable() - */ static void dwc3_qcom_vbus_override_enable(struct dwc3_qcom *qcom, bool en= able) { if (enable) { @@ -145,80 +135,6 @@ static void dwc3_qcom_vbus_override_enable(struct dwc3= _qcom *qcom, bool enable) } } =20 -static int dwc3_qcom_vbus_notifier(struct notifier_block *nb, - unsigned long event, void *ptr) -{ - struct dwc3_qcom *qcom =3D container_of(nb, struct dwc3_qcom, vbus_nb); - - /* enable vbus override for device mode */ - dwc3_qcom_vbus_override_enable(qcom, event); - qcom->mode =3D event ? USB_DR_MODE_PERIPHERAL : USB_DR_MODE_HOST; - - return NOTIFY_DONE; -} - -static int dwc3_qcom_host_notifier(struct notifier_block *nb, - unsigned long event, void *ptr) -{ - struct dwc3_qcom *qcom =3D container_of(nb, struct dwc3_qcom, host_nb); - - /* disable vbus override in host mode */ - dwc3_qcom_vbus_override_enable(qcom, !event); - qcom->mode =3D event ? USB_DR_MODE_HOST : USB_DR_MODE_PERIPHERAL; - - return NOTIFY_DONE; -} - -static int dwc3_qcom_register_extcon(struct dwc3_qcom *qcom) -{ - struct device *dev =3D qcom->dev; - struct extcon_dev *host_edev; - int ret; - - if (!of_property_present(dev->of_node, "extcon")) - return 0; - - qcom->edev =3D extcon_get_edev_by_phandle(dev, 0); - if (IS_ERR(qcom->edev)) - return dev_err_probe(dev, PTR_ERR(qcom->edev), - "Failed to get extcon\n"); - - qcom->vbus_nb.notifier_call =3D dwc3_qcom_vbus_notifier; - - qcom->host_edev =3D extcon_get_edev_by_phandle(dev, 1); - if (IS_ERR(qcom->host_edev)) - qcom->host_edev =3D NULL; - - ret =3D devm_extcon_register_notifier(dev, qcom->edev, EXTCON_USB, - &qcom->vbus_nb); - if (ret < 0) { - dev_err(dev, "VBUS notifier register failed\n"); - return ret; - } - - if (qcom->host_edev) - host_edev =3D qcom->host_edev; - else - host_edev =3D qcom->edev; - - qcom->host_nb.notifier_call =3D dwc3_qcom_host_notifier; - ret =3D devm_extcon_register_notifier(dev, host_edev, EXTCON_USB_HOST, - &qcom->host_nb); - if (ret < 0) { - dev_err(dev, "Host notifier register failed\n"); - return ret; - } - - /* Update initial VBUS override based on extcon state */ - if (extcon_get_state(qcom->edev, EXTCON_USB) || - !extcon_get_state(host_edev, EXTCON_USB_HOST)) - dwc3_qcom_vbus_notifier(&qcom->vbus_nb, true, qcom->edev); - else - dwc3_qcom_vbus_notifier(&qcom->vbus_nb, false, qcom->edev); - - return 0; -} - static int dwc3_qcom_interconnect_enable(struct dwc3_qcom *qcom) { int ret; @@ -848,11 +764,6 @@ static int dwc3_qcom_probe(struct platform_device *pde= v) if (ret) goto remove_core; =20 - /* register extcon to override sw_vbus on Vbus change later */ - ret =3D dwc3_qcom_register_extcon(qcom); - if (ret) - goto interconnect_exit; - wakeup_source =3D of_property_read_bool(dev->of_node, "wakeup-source"); device_init_wakeup(&pdev->dev, wakeup_source); =20 @@ -860,8 +771,6 @@ static int dwc3_qcom_probe(struct platform_device *pdev) =20 return 0; =20 -interconnect_exit: - dwc3_qcom_interconnect_exit(qcom); remove_core: dwc3_core_remove(&qcom->dwc); unregister_notify: --=20 2.34.1