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: 895508 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 0975928C000 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 (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 55A8d2Uq017798 for ; Tue, 10 Jun 2025 09:14:09 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 4766mchjfw-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-3132e7266d3so5153946a91.2 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=ouvIAiAXTo//z2L+YxlEAIrCh00cX2Ft8K5tR5cBOkR3gGCz9WzJW+/B7yaRvpnc33 FM9qUzFXEJ4Dt12Xgf23hJhHU/9LKTjQ3alUmL70hMHGOqz5WYcgv+WTEaQbVbCwj6qQ /0dUPBylGqq+HBtnc5ybWVjBB0h7ieGX7ajD9oOaUibQHW4vZC4PVGC54rkBURRoV8rN p20KRUgR/EgtGf/bLeTU7jnSFxcw8Dz1Qm/2RpwDLTwm3IGehxke7W/Xw20GNLMJS2gO qcSJRLnROGIS1pwJbM0F3Qdv8o1jxyGwZMAj/U0yFGNBPfW0ojJleysiGF2+bwUcUqfu czuw== X-Forwarded-Encrypted: i=1; AJvYcCX7PGIj3FgrMMvQCqCf5Og4mWjk6Tdl3nymmXsPY/zn5CR/Kl4wwlDsfMf6upGUUokgN6yEprZkHw8=@vger.kernel.org X-Gm-Message-State: AOJu0YxUl5Y45/nu7Ru2ofAqi5O/PzD4fC1w3ZVITAAV/vyiCGjQmj9v 7q9VSIvE9DY0/52UTqTFz2OZVZZeuuW/r41zkdV/dDHudQdYkDmwrReDHiMzgksiTzRr31yc09R zftngpZ/Vt0l1cU/dATDX/XhXjlnZFpzqUcQB5uuY2YlHsgrYTMgVanRAE2sJoWE= X-Gm-Gg: ASbGncvBLgT0LXQp2wqPXD+/qvG+sK8to8TWgN0T1UHS98FI+Kq2z0giXhKom1gTZxc YGq22/B97tx6dURimQygpLkxDbDipRPNxfLbll3wRIE7qTQXzTG4VnPbIm2S3s7crhVRgFHRfCn OJh1BIYPlg+8nzq8+HdF4fL05q2JqpfECWGugMGANBBr8jHyxCSoNL0s8y/tC8cMQPAsgY7nyFQ 0XQjiPNDaCAw86rTiTzFqSbG8Ir0a2aJXuuwk0+cZZo1H6fWpY0aafY7K8K91yAGSIP8+l0qKtj ON/156YV68atJXadatxyUMZsgfbHpUSOulmDk/QXgFyVzQUi2HprttroOvmj X-Received: by 2002:a17:90b:4ac4:b0:311:df4b:4b8a with SMTP id 98e67ed59e1d1-313472d6addmr21278034a91.3.1749546848236; 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-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Authority-Analysis: v=2.4 cv=T8KMT+KQ 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-ORIG-GUID: ZL4elc4kt17JbpaS4PCOaYXu4cZbGpqK X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjEwMDA3MCBTYWx0ZWRfXyxxSmSwxxp/p ZO7WLjVcs9zI3AhbmpxkKKGUcZ+I0wt+Hc6YTNq7WGvsU5372Klbuq7JEuqVmsu6cgscRHF3YdL ky2ah78gavPyYfMTCCGUqZnbAZGEj8+n47TDYZ2MxXa2Yl4cNdwu/+t8yxqJQ8KFrDB0nBJUuHR xGVYqUw4JEdaea36aSJdlnMPlVQjPnAnYibPxjG7HKmkZlRT3t3+pGl+GV1OnuvlZb8IkxLYY5c HcmlAP04geE/TVW9tXfsDbVArWI78mPaf/AXqJjpLWI6oLkglninvfn/IovZP68Tjoe69kEde36 /631Cw4W2W7kj6o1YwAB9PyVOxsxhH4j+N49n5U3hPL1Ry6rWNAZgpxFISEJ/9B6zUTUkWQvg0n n3woTSGPDHvhLmU9SIZmOLNRoanqWkIrPCjjfIZul43/NXqtTiTihfM0zqfUMuee9nIyWJKa X-Proofpoint-GUID: ZL4elc4kt17JbpaS4PCOaYXu4cZbGpqK 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 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: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: 895507 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 827D628C033 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=1749546861; cv=none; b=H5hXxcRNBBqpWWwg5r/UuSr7SbVUWz+4bWLeGHUhexfEiCn2qJIWRhyHTyTKHfnaEBpzAUt63cF8wRZYH+s9yObYhollRR0zDV/nR6jk+NZ7UGv4aR2rs0VpTCk9d75j60bjkvrNx08A5Hfis+JHWZ7qpSRkTVk2fODg8TXONHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749546861; c=relaxed/simple; bh=iru2/JKFS5VA0xmf3oFMPSCbMsMXc0mxSWJDqq5yqUA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Fpw1rvAEFnkbk0tYoJQLE77jMe7S2/6p3l6MixCOn1nNK/02W+urxzJbnjVv5cZuGk7BkmDQ6d/nbg8I7XCf3TPJdfB18nV3Fdf33igcZPnGXwcKDC9ZrBUowQkeiFrBh6U39B+P1abmywGQKh1ORwrHincVnC4D59QHsYHxE6Y= 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 (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 55A6huo6001837 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 475v2tbgqb-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-f198.google.com with SMTP id d9443c01a7336-23536f7c2d7so81745625ad.2 for ; Tue, 10 Jun 2025 02:14:16 -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=W3LVtyI2cSQ2mcCYj71YZ6wMIUpiqS1LOsqfiAOpL//yaxz+sqN8/8jjK3AJV/5HRy r4aNG+vlnKO2XzqmiV6PvKmaS3taODoABUe0CEwQiprf5gNwK/3LatcrCpJDoVBD0uqq pKkRZr7sbO+HQMe96KQNVJ4WStboanePUoiHjMMUbdclozsRfmJ+WIx6MV51JRV0HLe6 kBGaOdqU5zSr1zyMztI9HQD6oNTV2BG94gkmoA2xcKL+W+xEjkAthIbm32zJ+yxjPuKB fSTGnv2KpJiw2pS0o/z8jsqAmvXPft7B/GstZ2jUDUbGtFeDAcsrHZqJs/DtmdrQ1LaF MvjQ== X-Forwarded-Encrypted: i=1; AJvYcCXDwSZM9VwqlEcU5XwOyQZtlbrZvLgfL9NRnmTuHj/1f70LZFwG2eo4F9hnsb9mFGciFlFLeVFB9aU=@vger.kernel.org X-Gm-Message-State: AOJu0YxeofUMKPmSS0bgpVwBQJU+zsL/PVb0iF2J9tR1Q5BLVFSaFdHr TdAnwqWp9NGdcrXJbo/9X6VtqU7eMYsiYEErAye43yY/EYK9UwnMUcpBqQIeb1pntgyCMjmSWnG 6PkYaIy0VzqKbEFZz+TvLPZVCOMN0UBsS2SegUWhfjUq1pHtIRIyV7LieTX8AoHGqJOU7SQg= X-Gm-Gg: ASbGncvcbVRHhtprv5YhIQSDWLSir0rqD16vymbD9SwjnQOS4pJKyYFfMGgWrWngL6G QOFZ3NIxPFpTEz1sk4T/nnWKo1H4rPd9+NfEVw1y5ARMrrValsmJNy5/r8nWNO2C8if7V7zLjU9 ypVqbilNfi/JwHQZRrxgjjZ0nZhfeGpQ7GVzLM3DXutTmyVsemrcigmuB4VIDkjnrPc51GFxaBL Z4SYt4lt1ercs7xrO2lKJntgurLPJZpNlRUVmfYf6ns9eOGWeEWFHr8zHfiVsZfKD5ojfAEzexs Z5oWys2VipK2WG7XADu3GDNWqXKrId6P915UpmWJZ93rejNzqmPf9X/LTbC8 X-Received: by 2002:a17:902:ecc5:b0:235:eb71:a398 with SMTP id d9443c01a7336-23601deb495mr246989605ad.53.1749546854792; 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-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: VUjg6NU_0BaSEPr0OapwMVRSNqeUKrdt X-Authority-Analysis: v=2.4 cv=GoxC+l1C c=1 sm=1 tr=0 ts=6847f768 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-ORIG-GUID: VUjg6NU_0BaSEPr0OapwMVRSNqeUKrdt X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjEwMDA3MCBTYWx0ZWRfX5zY+iZgUCH/6 xk+XPHgtE4QCVN26eaSFf2btoJ2t3hND/kkzEQp0HwLiSQkJDIAKM/9K3AxQ8aykdUjfhmB3d3O tGzEGuXPyGLQsBBaproHt19CoNZrhvrUWB6eXCqTKnwqos6x8pdq93peNbCGYeMDSdkon3wvbJj oYeeGqVVbQmUwcjvvBIjvI7uFHME24C7HuIcdpI/sN7YFScfHpiTt52KwvTktQPN+/DtNB9VlEX IJiU9ylugeaPbaKV7ywF9FSDnaeDsmynqqeqIElQCDWd1d1OxF8qDij4/7IpNcts5qd6ZEvARPO aTtqIwiEyDvPBWrc5uXJDNlQPVTC+eqQWr7xvMmVfyvICfAqJkmHf7lRMpwtshx90y12RO6oz90 FEJHseNmqetOEK/FUGeWeP5LwVV9tAepvzW34du0oE4dT6V+58uPwyZG8mPNeecsZUO524BI 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 mlxlogscore=999 adultscore=0 impostorscore=0 malwarescore=0 mlxscore=0 suspectscore=0 phishscore=0 priorityscore=1501 bulkscore=0 spamscore=0 clxscore=1015 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 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);