From patchwork Tue Jun 10 09:13:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Kurapati X-Patchwork-Id: 896775 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 1791028C001 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=1749546852; cv=none; b=boiZ9tp7zHo9wVqNBl0A6Ys5mFiRZBj1G/AuHrAWuVTQWrTBMUzf5Vp3k0Er/TxxdhiT4tqaUaGE79TZ0dWRbBR1SqJS1XMJykYbUvutbqSGKQrvI26CYzAXI0McDXzRJ7s0V9lxK/ZRUHhex9ttRwPnzS9GwcqZzN5zCP+RO1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749546852; c=relaxed/simple; bh=LU0jOvl5YW/dqrJCbHPNKCEBE+8gLqoX0Lq/MwWLwEo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L+kjo/rXAchLSAyilN3SHIGGRb0V85d+VD/4RjuIl9TovZ9OL3er0OD2XqBqETeWoJ1pKYXtlO4/XDvJyNnazM2Cem/IIivdbMxmvmJRN5fFOp5wYBb1KkjbGn6EcIMIc3PngHHRx82kprSQItnepJVnvJLhaaFgGyySPACmbzs= 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 (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 559MfPnH008107 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-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 474d120x07-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-f71.google.com with SMTP id 98e67ed59e1d1-311a6b43ed7so4590542a91.1 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=QiuFZ7s9nZG5EC7QB81m9gw4c7kpS/nBrx8GiYg53eqFUnJQa5YQE6C/lPQWVZ7dDe hIl4NXhwI2zzaGmt3Np7RVziJr5vvVqLSpos2jaVfTNxKTBZRyTn/RWQZ0X+7qQN0e9X 26eh47rtE1o5jnTBvPU9vaTN6yFg3/Tq73zsiZriR0gQ613I2znkYB8sq7JLNcwrmyU/ wFZ2Qxp4SGdbnuGmUP811D1H4dLBi12v7phpZ257uvEhRQHezcdcsnUMXYIYVrjQTf+n chNb1jwK++l5mFOsWFirNIZVm7rwbBUbYCU8vub6neOgQHQmpwT2JVNqhEJfQP/jYK5v Gk3w== X-Gm-Message-State: AOJu0Yxht1ZnckK5uyCkySU4rMEyrg80bCpl0Dov60lSSP0LWkIBsWyX +kJBTtcxeJLDO/+Yfhk1ZnvYav/+a6ZvYwBvrzlpUt6B3T+PPdT4nfX1opAsnLWV+IvXTOeUPDd /krQM2K0RXvzj3tDK9tilpNWDaJqUU8OfEKepjqTaHavDtcSacT3XS497Td14+RNQeaLt X-Gm-Gg: ASbGnctDWWVCegWchoWMMGhrilWA0Kub2RKuNHPt+eVY/O+EHf411rfaLtHvjRR5NVR Eaj/RGQJ3QZ3VRSgj648bRkHaLxEskbC7NfB8otemN154bkgZYIYK0Vn80dSgMQmtP+TZRkcf2v 5szLRKXG51PMxRzbBrx/cq2BSAyAgSoHTIw+TmEAdWa2demmx/DuTUn4GmO+owDPUKWcaDS9j/H 6t804oEh9QoXI0EIDgipd3FWTjM+qkQKMExtAeSyT+Om0qeevZRScWh/3RxSTAmkclGWVdwc4H9 qZrM6/oJ0g682HNxHmpG7gBLwYNzt3CupU1UJmy9gwXWUQj9WNluPczh4SJ+ X-Received: by 2002:a17:90b:4ac4:b0:311:df4b:4b8a with SMTP id 98e67ed59e1d1-313472d6addmr21278029a91.3.1749546848223; 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-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: 5tw7MDNTS3WTEQ2lstQqqlccnUvCdglg X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjEwMDA3MCBTYWx0ZWRfX0m5oUp2ka2Ib oUaegGhlxXoQcf3zBwDMN6kx+ILNox2aB1MHUWFgOQmHYMSyBbXm0+6PNZIkqaDqFJ7wwEhkciE Phl14ZGo2XmikHbCVjAYPV90WV0ZkCZwP0HmVmlBeE+TdLYBZ6Ue+dFInps/3duvEgzjmBTnaGP EMU4IObR2mgmpBD4fkoW9XxUL+Hlf8j6zwgyQLHBiffu7DTYz1K+TxCOcF/5Srs7mMkXF9QqUZd 9u5obg+IGY41zmpNPk3cUtLB5tA2CGYtotLSFwueOJrhaeAFqgHayL6nNZh1VFBVAYnhq9P9O57 VDP3fMamnUJVF5f1VO4SMs1pIPlHAPVM07s2Eiuna/boZc3ayhCYa9vtgPmoeBIBCs1kIKUhGHA fAIQUZ6dGDJtWmVghvjvJoQoJ0uoNiCaJdXqwNEb2SYtTdJ1GZcKHY0//F8JRIWvgV8U1V7N X-Authority-Analysis: v=2.4 cv=GYkXnRXL c=1 sm=1 tr=0 ts=6847f761 cx=c_pps a=UNFcQwm+pnOIJct1K4W+Mw==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=6IFa9wvqVegA:10 a=EUspDBNiAAAA:8 a=9UFxAfr_hboBSpCGZXUA:9 a=uKXjsCUrEbL0IQVhDsJ9:22 X-Proofpoint-ORIG-GUID: 5tw7MDNTS3WTEQ2lstQqqlccnUvCdglg 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 suspectscore=0 phishscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 impostorscore=0 clxscore=1015 malwarescore=0 priorityscore=1501 mlxscore=0 adultscore=0 lowpriorityscore=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 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; dwc->dev = &pdev->dev; + dwc->glue_ops = NULL; probe_data.dwc = dwc; probe_data.res = 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]; }; +/* + * 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; }; #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); +static inline void dwc3_notify_set_role(struct dwc3 *dwc, enum usb_role role) +{ + 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_ROLE) int dwc3_host_init(struct dwc3 *dwc); void dwc3_host_exit(struct dwc3 *dwc); diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index 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_switch *sw, break; } + 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); + dwc3_notify_run_stop(dwc, is_on); reg = dwc3_readl(dwc->regs, DWC3_DCTL); if (is_on) { if (DWC3_VER_IS_WITHIN(DWC3, ANY, 187A)) { From patchwork Tue Jun 10 09:13:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Kurapati X-Patchwork-Id: 895300 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 82FD528C2CE for ; Tue, 10 Jun 2025 09:14:13 +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=1749546855; cv=none; b=H/ZmoxZvvDeELVsitW9ePLsUZtp9nZ5qXYnOBPKAtpbv7jAKPPHCzayv1vZ1ZliRNPPyRopXcvRukBKYDlymrl+Rhb5/17NlJgRYL4ZdrX+I/NyoG/0MeV+LfZOi342aM2sYJoDFrZvej1Kyxh5bqXLds/bQqFkqVmoScq5XLBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749546855; c=relaxed/simple; bh=XZz8NYJcJqcKiaoFso9j55BbEfdRP7VRJYZy6cqw9xI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tK3ipqKNRaqyDaNm55xnuX9nGaTbfZa69GdQblrLO+Te320T6uuTvZ1wjRdVvUqfkpgnByJlAs+utBCu7nH16pqlyc6TFEfR0nPfVfnATcXu7SsifaxoHM4dBdUH72FO1Qcpd887SL8xYW9DGcCNfOtGKewEs6g0t9s+LqewAiM= 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.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="C6nEv3E+" 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 55A8QBh0012939 for ; Tue, 10 Jun 2025 09:14:12 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-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 474eqcgpd6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 10 Jun 2025 09:14:12 +0000 (GMT) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2350804a43eso84505745ad.0 for ; Tue, 10 Jun 2025 02:14:12 -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=hohCoByUHd79K219ByiR3D5Rdp2xsI69/POnRrWmlFiyR3Tal0tEsXm8m3+wEJkOR2 OR7QtBhCMvUtRBxnl+DqdOytd9vq84d6pKbCUJBqzXCJJtkq+04/iwA4r3vYbHlewv9z zu2wiSBy7kQPhbrGA4yQiT7eMimT25CpjcuC7hLEkxwmuFpqItVvBh+C0Tnmla5pFYZC ZAjEELmIHOk6MhkjBYLX0CreuyHWGyYkulig4Izod97VYRtidRfBf/J7GrND4sq6BF6u YrKqK9wH93v2aZ7bLIC0WmpoEvv4E1zDidfEDwDGppXAUxTrB4NQT+Um8hSd5ga+5Rxi l2WA== X-Gm-Message-State: AOJu0YybBioyhiPCL9DjaZRMYvgp/5UBFjdpKeFGTrxlz43ATWjWvMx3 e120znQkGX10X5XG+/54MLMGwUgBDedRAeW+aE963fTEpGVmAfWVAxJgsxzeRSZId7nldOdrTFh xn3HROgY2N+gHsDK8mwd2xA7aGKVXeap2szh6wL4rwWrHXdXXTNVqXhrvcbbs2tWyiipCcjqy0H CQ X-Gm-Gg: ASbGncuPFmI8bwQG81XIODMUkvYstVE5pW2ZWdQI1WkjySQURw9wG2CFxY3zlNfU3Ms fjbNTtB/FEcosb5CZQrfrJDw44g79bxEMpGRoKxmFpe0/f95OeeMdI5QmHgxznwFzZ2EkotNjgs 4r+UYHaBAOGWwkeAuUhtfjiZNnyzdkpQzKwouvByTp8L94hS42IxycjaUZ5f9luhvGYdXmTQlQD +Bt2MvaFK1BEj71iFd46eOsfeWBb4MEU4JO1OYP/4RS8j8jn1F998SxXEUmYZNDolgBJfB8FnPG 0+AINE0dhZJlVx13939R8gEMRGjEcTfdLNrXu3SljkXdv0ZzvNkQn7k4vYSq X-Received: by 2002:a17:902:e742:b0:235:1706:1ff6 with SMTP id d9443c01a7336-23601b49d15mr242506675ad.0.1749546851532; 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-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjEwMDA3MCBTYWx0ZWRfXwl0cfWFywlyd 2FDrKgr73jPMw6/X+HjZmFy8F06u6RZq/yb3xlvrfzXHUqLlkk+Er6dr7ffQHyxNuhAhg0oOUje rUBkoCslSxoN3YdQyi4RMUaXHJjc89khVVM/9rDxP3HVbxnPYQ1tNSIKek3dlBTh5aKUY0y8Z++ vF//33CJ9EvLysDmTqyjxhLxRTvNRKpqF2ylh+KU/u0kvAR8bGY82HXTWE8UK1e0ktiTSkDA0C3 O6s2zWYmw3v+UFvQWjeI3fYAW7Dr2+5yMHHS0vXqqzi2jp7T671iETVWVhsHBuxnfz2DPOruaR5 CB5FunJAajZdT2+siOIbQiSuI5UXVplNX4jSwTRHb/7iK0BsiWWUHIZRWUqJAH8lBmOuiqw9cuN 8waNDi5ejM8K12XQnTuFBwW0kY7TVBDhABLj1OKre1xUzUdyR5NfEeLqeQqjSRxJjqjbeKzh X-Authority-Analysis: v=2.4 cv=Q7TS452a c=1 sm=1 tr=0 ts=6847f764 cx=c_pps a=IZJwPbhc+fLeJZngyXXI0A==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=6IFa9wvqVegA:10 a=EUspDBNiAAAA:8 a=ProRYBKZBCDr5nQBVQAA:9 a=uG9DUKGECoFWVXl0Dc02:22 X-Proofpoint-GUID: aQ0noTepTsgO5hriAIt08hDwaO0Gwa6O X-Proofpoint-ORIG-GUID: aQ0noTepTsgO5hriAIt08hDwaO0Gwa6O 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 suspectscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 clxscore=1011 lowpriorityscore=0 adultscore=0 impostorscore=0 priorityscore=1501 malwarescore=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 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; }; #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) } /* - * 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 + * 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 enable) { @@ -641,6 +647,53 @@ static int dwc3_qcom_setup_irq(struct dwc3_qcom *qcom, struct platform_device *p return 0; } +static void dwc3_qcom_set_role_notifier(struct dwc3 *dwc, enum usb_role next_role) +{ + struct dwc3_qcom *qcom = to_dwc3_qcom(dwc); + + if (qcom->current_role == 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 == USB_ROLE_DEVICE && + next_role != USB_ROLE_DEVICE) + dwc3_qcom_vbus_override_enable(qcom, false); + else if ((qcom->current_role != USB_ROLE_DEVICE) && + (next_role == 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 = next_role; +} + +static void dwc3_qcom_run_stop_notifier(struct dwc3 *dwc, bool is_on) +{ + struct dwc3_qcom *qcom = 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 = { + .notify_set_role = dwc3_qcom_set_role_notifier, + .notify_run_stop = dwc3_qcom_run_stop_notifier, +}; + static int dwc3_qcom_probe(struct platform_device *pdev) { struct dwc3_probe_data probe_data = {}; @@ -717,6 +770,23 @@ static int dwc3_qcom_probe(struct platform_device *pdev) if (ignore_pipe_clk) dwc3_qcom_select_utmi_clk(qcom); + qcom->mode = usb_get_dr_mode(dev); + + if (qcom->mode == USB_DR_MODE_HOST) { + qcom->current_role = USB_ROLE_HOST; + } else if (qcom->mode == USB_DR_MODE_PERIPHERAL) { + qcom->current_role = USB_ROLE_DEVICE; + dwc3_qcom_vbus_override_enable(qcom, true); + } else if (qcom->mode == USB_DR_MODE_OTG) { + if ((device_property_read_bool(dev, "usb-role-switch")) && + (usb_get_role_switch_default_mode(dev) == USB_DR_MODE_HOST)) + qcom->current_role = USB_ROLE_HOST; + else + qcom->current_role = USB_ROLE_DEVICE; + } + + qcom->dwc.glue_ops = &dwc3_qcom_glue_ops; + qcom->dwc.dev = dev; probe_data.dwc = &qcom->dwc; probe_data.res = &res; @@ -731,12 +801,6 @@ static int dwc3_qcom_probe(struct platform_device *pdev) if (ret) goto remove_core; - qcom->mode = usb_get_dr_mode(dev); - - /* enable vbus override for device mode */ - if (qcom->mode != USB_DR_MODE_HOST) - dwc3_qcom_vbus_override_enable(qcom, true); - /* register extcon to override sw_vbus on Vbus change later */ ret = dwc3_qcom_register_extcon(qcom); if (ret) From patchwork Tue Jun 10 09:13:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Kurapati X-Patchwork-Id: 896774 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 4DEF028C02F for ; Tue, 10 Jun 2025 09:14:16 +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=1749546858; cv=none; b=LSfjXNyG6n/5AH+1x+fiFuKRNY29z2Z4mUrkI4sNvz8+IQrmc+t7YB7dR+wJ91BOk/rx2srkyjwX9oVUOY3en8Nkqr38ncjNiRNvsQDyt1ieGaiBPEbJoVS+/SHDTbASPqw7ipUwj5+4qa+xFIjcOxlRva/FwphUOOdHyujLsA4= 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.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="mhZcr6mL" Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 55A6e1RU020098 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-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 476fmn8dhx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 10 Jun 2025 09:14:15 +0000 (GMT) Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2356ce66d7cso66415535ad.1 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=d+mwQh/wueMjmnEk/KtTOVd7zaTdXuPrg3XkhOp80yCWwS6qR4ev3AVv7xGirR9QjT +4s34XdPjO/Jim1KRsdw09d+NzNfRY2AWLjNUbez4TGoLt4CcK8oFJf6VsNnN7Sw/01p 5OywFzYZTEaX9ENizZ6K4DVPGB912LRoIHkVRiRRd6jBqqzqTURLG88nkXyXdj4HCfEM +6UfyKGJkhXbRDSfTZTMQ9ZcWwCb96+IbD9TlfuIUQeAfRkIcuyT2cOP+t/AlcUyRhuh nDLbPs0sNLbxRmJni/vO6zVMi6O9GJBPNcPBYTeBJ5Mi+VTeyRPdI2NfP3tTPlbWAT63 24Tg== X-Gm-Message-State: AOJu0YyouhZI4O2TL2stnopxjKr4wffA2jBntJqLYJoJImfITf3W8sY0 zp814qqBlUBlRsaj51iMgRC7QSm2u5oAgN4JXDeHSdY2kJ05PYOfdFlxu0UcasFTXXRJlYtB4nd B93S0pFYID/8/S3pwvh7DWh4EwtWVv9tG9XWNMQSDx6ZGeXhPFGopCSFtfFGJknPQgpO/ X-Gm-Gg: ASbGncvY45J4/u451gownRfI66n6i8w7LlJSAOz8ZLXHD697/bXPKLUWQhJvDYtQBBV gSWVmNM6uuogYKwAaAE07zeyrVY58wH5xEVbZ6iezcw4DydPV24cDIeoIoVDRmOvXCY010cu6mi GXvE28JzaXmgDivEjWimOEmpHp9RiETTcLDBTBTgts9tHT6NHVL65b7B6ptEahNh4hcM5fLifmf i3RFbWQVqRwG9aJ37KKKl3Lz3VTWsVz9xEKicrvx8Vd2aKyR3r9MoyEJMEQJgKtjy7gQIBxcJmM PyacWhDFuOZzU29OVmknTdNQriJdZbZ7o3toeOoSaooR73pwy/5ctI3LmZ9C X-Received: by 2002:a17:902:ecc5:b0:235:eb71:a398 with SMTP id d9443c01a7336-23601deb495mr246989575ad.53.1749546854788; 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-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 5yv204Z-VRfS9Qx3M5NufUBKTO7X4yF6 X-Proofpoint-GUID: 5yv204Z-VRfS9Qx3M5NufUBKTO7X4yF6 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjEwMDA3MCBTYWx0ZWRfX9IXhjvHUnFqL D3A4IqlhnMHNmb8XhCAozKhBQio3nukv8zB3COt0d2m16j21D/fMvpWgYnbMak6MGA+/fklupO9 lmcOCD2uGnqnpVeSBAhE6rqfXK1N8qbMiDx5Nqnn+f8nhJlaZ/czccViTszoRAUc3aZ62AnXw2X VFW3txQ67XYmVqDOAFZusGL2ECpVzyCQ26HmrytFIoRY/g9v6SDR4W8b5HYt2e2JVcWubuVVFK7 OKB2bmksq5bKn0E8MRQZzqD3lS6zM0qsEJkzcxHE3crjN557QaUgw/+A51+o0usDzom4/vqkgyU +x9LyIGS11mvnh8PXLWoZ6kvgUKoZMwDmeP8erjQS3+iryx34u0hVSJkneRn++oN8FCUl/vg8ls EEcy8znEMD3Y6Wt4zLda31XGf9GJ9ImUXUNdzZPtQZan550/5liUMnFCbXIZVYkHE4Bpthrw X-Authority-Analysis: v=2.4 cv=K8wiHzWI c=1 sm=1 tr=0 ts=6847f767 cx=c_pps a=MTSHoo12Qbhz2p7MsH1ifg==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=6IFa9wvqVegA:10 a=EUspDBNiAAAA:8 a=5CM_793GkT3ZRPfwn_AA:9 a=GvdueXVYPmCkWapjIL-Q:22 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 clxscore=1015 mlxscore=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 malwarescore=0 adultscore=0 bulkscore=0 spamscore=0 impostorscore=0 priorityscore=1501 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 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; }; #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; } +static int dwc3_xhci_event_notifier(struct notifier_block *nb, + unsigned long event, void *ptr) +{ + struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, xhci_nb); + struct dwc3 *dwc = &qcom->dwc; + struct usb_bus *ubus = ptr; + struct usb_hcd *hcd; + + if (!dwc->xhci) + goto done; + + hcd = platform_get_drvdata(dwc->xhci); + if (!hcd) + goto done; + + if (event != USB_BUS_ADD) + goto done; + + if (strcmp(dev_name(ubus->sysdev), dev_name(dwc->sysdev)) != 0) + goto done; + + if (event == 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 next_role) { struct dwc3_qcom *qcom = to_dwc3_qcom(dwc); @@ -659,12 +694,22 @@ static void dwc3_qcom_set_role_notifier(struct dwc3 *dwc, enum usb_role next_rol return; } - if (qcom->current_role == USB_ROLE_DEVICE && - next_role != USB_ROLE_DEVICE) + if (qcom->current_role == USB_ROLE_NONE) { + if (next_role == USB_ROLE_DEVICE) { + dwc3_qcom_vbus_override_enable(qcom, true); + } else if (next_role == USB_ROLE_HOST) { + qcom->xhci_nb.notifier_call = dwc3_xhci_event_notifier; + usb_register_notify(&qcom->xhci_nb); + } + } else if (qcom->current_role == USB_ROLE_DEVICE && + next_role != USB_ROLE_DEVICE) { dwc3_qcom_vbus_override_enable(qcom, false); - else if ((qcom->current_role != USB_ROLE_DEVICE) && - (next_role == USB_ROLE_DEVICE)) - dwc3_qcom_vbus_override_enable(qcom, true); + } else if (qcom->current_role == USB_ROLE_HOST) { + if (next_role == USB_ROLE_NONE) + usb_unregister_notify(&qcom->xhci_nb); + else if (next_role == USB_ROLE_DEVICE) + dwc3_qcom_vbus_override_enable(qcom, true); + } 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) if (qcom->mode == USB_DR_MODE_HOST) { qcom->current_role = USB_ROLE_HOST; + qcom->xhci_nb.notifier_call = dwc3_xhci_event_notifier; + usb_register_notify(&qcom->xhci_nb); } else if (qcom->mode == USB_DR_MODE_PERIPHERAL) { qcom->current_role = USB_ROLE_DEVICE; dwc3_qcom_vbus_override_enable(qcom, true); @@ -794,7 +841,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev) ret = dwc3_core_probe(&probe_data); if (ret) { ret = dev_err_probe(dev, ret, "failed to register DWC3 Core\n"); - goto clk_disable; + goto unregister_notify; } ret = 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 == USB_DR_MODE_HOST) + usb_unregister_notify(&qcom->xhci_nb); clk_disable: clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks); From patchwork Tue Jun 10 09:13:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Kurapati X-Patchwork-Id: 895299 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 711CD28CF69 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 (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 55A6XvlW026905 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-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4762tg26ug-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-f70.google.com with SMTP id 98e67ed59e1d1-31218e2d5b0so7705288a91.2 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=ARCFcK89CZMaRoOVdvuNepyozEDWShC64GvwYCj50loUscmKEPo1KDqbWdI09/JGa3 tIucOzvphjwLk2fv/1bBJOjDHziolRN9QgySNx6FePojjLfO9vp3NP5+ObeYPP0EzvXQ px7XafzvwcyBXkZN9XNx8G+k99OcI5cbNUhG2hHZhBswKy207LAKh17ELXWUpin/4oaJ SRj+mza6WLz/RJZ2+eU6wtpPBn3m0Yme5d86JDLB73Nu1XC9v4zrprZ9VadrTdyXIKpP 5vd6MYuO2DO6qnu/+duw0aXJ8qrKGHb72FBvt3RC+qMD783Pr6kanrcyUfjRSCfoF60o Y7AA== X-Gm-Message-State: AOJu0Yw6vHpIyyVKqtcdf3KiD2WBe0nTxRn4Q5P/GK5WNGmEjmWtW8vX /XO+5PHRyOu4wz7VtXkuW9pYlfERWUteMbczB70OVAokkeJwxqID9CdFwo+I1dSrYgEANzgfKw+ QNOoqo5sQfu1G8Rn5Cuk4JIVmbbrue/Xpj74m750ALdgxKNGQkMfJdiKLRLPrceUgWblv X-Gm-Gg: ASbGnctH346EynL6CgTKbQz/MZhW8d643VjN8mHYLlpPq9qVg+7oC7NC7ztmyG3oBE3 xZE+Z5iF+A7ObxYl4QbpwNJQMQ78jbfgichwoRxFDtBQgfaQtLHcIvKrigg6RKrDnvNQE5eP5qB TWliM2XWhLSGgfmLDHvzIkXEZaWieyfe8F0T9wS7HJG8AMLW1TxTYaOWsYq/uEUG5LJbOUYKfLy vZywYDomstyR4BO0hPETkOuwP2lhMF2uVV/lRfaCy1nVYOKOhM2GAPXMHo8nPzhIJypGsdPdjtT oOsEFhry2vf5nAmDssHW+ohHemwvAk+deOsX8Nu/e2pFGPF3Hc9usTK6F/MN X-Received: by 2002:a17:90b:3b92:b0:311:a4d6:30f8 with SMTP id 98e67ed59e1d1-313472ec763mr22830128a91.13.1749546857934; 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-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Authority-Analysis: v=2.4 cv=OqZPyz/t c=1 sm=1 tr=0 ts=6847f76b cx=c_pps a=0uOsjrqzRL749jD1oC5vDA==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=6IFa9wvqVegA:10 a=EUspDBNiAAAA:8 a=HsaRtseu1FE5unmruSMA:9 a=mQ_c8vxmzFEMiUWkPHU9:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjEwMDA3MCBTYWx0ZWRfX3WDbK0vsFNqi QH5Ej3v+ED+dI/FYEI+pTyl8fkxzdrhGtjUsHz/42Bt5i3AfgbJQjT69DKdPfWV6sixjJTrk7EF 0R3GLjhilI2wREAUpE4FyQNHq9ZSfKZr883zh1GimnSt82RZV7LCVMscd5L49ho/JJVwwaxGf/H mdS23zo1l6HyMRTFMi9OcdZCMBqqDn9WPtf1HcbrrEUSaK23I4pMDU9sc0tMjwlbd5db0tT/pBP +Xe4YRYaNVLdZ+CVa1xaKZJN2QmVIiOJTFmjz1g3x/KW4tciTXzBGDSJURLK4r4ZDAWIWhFGGWG Sd1y3/DVKJ+5knvSbSQZ94UvIJy96szLee3PGjtz0BCGgRh2vgj6bwWF00fmx6w68+FZJvgxWgn +K/Bs7jELNPTk+1eBXKTCJSmMrvAhJRUKFtlrbScbijs+h+IzXdCcbS0pqfDwoX9PTlWMfCS X-Proofpoint-ORIG-GUID: oadkBcUOpLkRgHh_5xdM59uvV-wn91Yz X-Proofpoint-GUID: oadkBcUOpLkRgHh_5xdM59uvV-wn91Yz 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=1011 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 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; - 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 *base, u32 offset, u32 val) readl(base + offset); } -/* - * 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 enable) { if (enable) { @@ -145,80 +135,6 @@ static void dwc3_qcom_vbus_override_enable(struct dwc3_qcom *qcom, bool enable) } } -static int dwc3_qcom_vbus_notifier(struct notifier_block *nb, - unsigned long event, void *ptr) -{ - struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, vbus_nb); - - /* enable vbus override for device mode */ - dwc3_qcom_vbus_override_enable(qcom, event); - qcom->mode = 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 = container_of(nb, struct dwc3_qcom, host_nb); - - /* disable vbus override in host mode */ - dwc3_qcom_vbus_override_enable(qcom, !event); - qcom->mode = 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 = qcom->dev; - struct extcon_dev *host_edev; - int ret; - - if (!of_property_present(dev->of_node, "extcon")) - return 0; - - qcom->edev = 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 = dwc3_qcom_vbus_notifier; - - qcom->host_edev = extcon_get_edev_by_phandle(dev, 1); - if (IS_ERR(qcom->host_edev)) - qcom->host_edev = NULL; - - ret = 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 = qcom->host_edev; - else - host_edev = qcom->edev; - - qcom->host_nb.notifier_call = dwc3_qcom_host_notifier; - ret = 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 *pdev) if (ret) goto remove_core; - /* register extcon to override sw_vbus on Vbus change later */ - ret = dwc3_qcom_register_extcon(qcom); - if (ret) - goto interconnect_exit; - wakeup_source = of_property_read_bool(dev->of_node, "wakeup-source"); device_init_wakeup(&pdev->dev, wakeup_source); @@ -860,8 +771,6 @@ static int dwc3_qcom_probe(struct platform_device *pdev) return 0; -interconnect_exit: - dwc3_qcom_interconnect_exit(qcom); remove_core: dwc3_core_remove(&qcom->dwc); unregister_notify: