From nobody Tue Sep 9 16:21:02 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C52E129A32D for ; Sun, 7 Sep 2025 18:14:24 +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=1757268866; cv=none; b=Ah4uAlgDFOy+UBgwpzGxPATfIlfQ6XeJx5H9yRs5/VVFgIhfNTmzmkjojyOjhc/rORaFdZL/aLbJhrpfNx47EopElsiNWR938bt8fa8ZIo+FVBnlYBDLetH/OUjn8vvo9G38OgBk1TpGmJqbcvlwAfKEI/4q7seZd4C7EuLVvLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757268866; c=relaxed/simple; bh=FWBE8TbnpDoILTgny5SLZBpQh7y0VgQZiXP6ZqS4dy4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fOORcfHdaA8zJIb4w8oue78sIywbS1eaPDCchPbBZBx4y7thXmB9fl1OJjooPLZo1XHbgBA8H9YWyEyu136isct4/UfATuo0yT1oAOApRv2qp2nataIvx+v+LaWsJWrOBl5v1oUXSkDR4qQSUAPhyAAFQqNY7F0LKP2zk+6xw0Q= 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=aQqyvQc0; 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="aQqyvQc0" 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 587Eb6jw011809 for ; Sun, 7 Sep 2025 18:14:24 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=zXbvHhAHt3e XLIh4fGNwnDZCLikwnim4WFNUvEbF34I=; b=aQqyvQc0HXfZCig0yNWtZPUzqtV XRX51ydJPaziJ4FujVFMTVQ7z7X+ZOEZhyKz1Rflhul7xtyzBNBPxoeIvfpLVij/ /ktL6/Ey6vFSljnVqj+uAOhHa/BK+L2D1ddSLw2GrWq5oXd+C5/D7i96E/Tz/8Ck 4MIUsq3ifXW1DWM2AWHvepeSV4oeWF3c8ZxnVw8CBZ8wVwsxvQdUo9yuRibLDtGk 9Ks+bDko+jCpJDJQsKO8Iqpm1s44brak2bSY6pNKYaO3voDOQWTKc5SK053Tg3Nq kRftvkvhRcX4pyiOFRGuTQY6KzIuYCLx47HbGXPoMbPslFHG4sFlFs2ewMA== 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 490dqftc4s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Sun, 07 Sep 2025 18:14:24 +0000 (GMT) Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-24d4ab50385so35376725ad.0 for ; Sun, 07 Sep 2025 11:14:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757268863; x=1757873663; 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=zXbvHhAHt3eXLIh4fGNwnDZCLikwnim4WFNUvEbF34I=; b=t5pCMXH2k01h7NHjLIgQ3j/WvFFifUvza7xKdjxlk1mlISz8TGPvYhGnDtTXf5zndu ZVowVqtcLA6lJab/ChUa6qW169u87TlSetFkjXmbmVA38MLWDmtT5QVraW9ExmA70Y6j TV9tOrRq6y3qqFZGDmQfPEgHMEx+knn3mG7r+qbbs+RoQiVoiLc07tdrI+jg5Q7YidV4 /vGo8VhdSxmLvdfTVz+6lwgm02Da1lIUJidOOmPf3LXjBXpwnLMKhJC4DoWUGMrjg0Na eT3Z9QHYH+xLEPmAwqui1Jw0WK5A3ByxtMWK/9WQnTq2VZJEDwE9a2gmqDhC3m/7zujm 5Bcw== X-Forwarded-Encrypted: i=1; AJvYcCUXPm5/oEo6euu94Claxz3slNrLVp/VYsUJ8Ra+z7rEj9qBzgoYDMSdcASzBTMsV0JW209BZFhjaIHo9C8=@vger.kernel.org X-Gm-Message-State: AOJu0YxDhXIqW38zCdcef1NKWX6fM8PseDGOPacZR5cIZgnLB673q07V 4ucJpYlkHfTjaGSx6HMYiwnxJRHZW5C4rKYW+Die2xDvBOMDtu4cMOLSXcsFLBZUswc1PvejVwF +qZgBD2HcXFXb2aQy0kzRmoJK8GNVhfonjol6wNsfX1GPBQ7zVmYDdjvypodXLxXmNgc= X-Gm-Gg: ASbGncsXL82sMnCKkLTklZyIsROsoGuBEoEJ0fT9Nejt7h/YUU2mc9K7Zwk/S5pE0PM 3ltvbsA6epQH4PcHxdDjPcvtkN9PQVM9IODAz2SwiTWJQgiKwiDKKVH61s+zz2unZ4UpYjfzgY2 x1VAzMy3UYyNCvHjQ4sXVXtV2n6HxdSwZrWAQsRTzk9ENDfuIUfTXWPFPO5t7DHXRVlUueWT02c k8HZkMtDmERUihKnpp9dE4J27whXefj9H1cIyUQBrBQ2dWU4YoKz0lI2jQE/Jh0cIdo1RSpoIWl 7y07lH7av0fEM9u1Rktk1W1+IfYRQo5KPzMTiJxuDG1YOLUm6qKQfP9tmu5QwchLAPtdRNo+VIA fDw== X-Received: by 2002:a17:903:1905:b0:24b:1585:6350 with SMTP id d9443c01a7336-25175f6e65emr79397075ad.11.1757268863157; Sun, 07 Sep 2025 11:14:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfb9X7Y0iEuBI2GhrDyKdeAQMyHma5HcIN4lLPMF+QE9VYRSDXVNdwO2//mXVcLKZed3gAiw== X-Received: by 2002:a17:903:1905:b0:24b:1585:6350 with SMTP id d9443c01a7336-25175f6e65emr79396855ad.11.1757268862650; Sun, 07 Sep 2025 11:14:22 -0700 (PDT) Received: from hu-kriskura-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-24cde5b6484sm84074765ad.19.2025.09.07.11.14.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Sep 2025 11:14:22 -0700 (PDT) From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman Cc: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, dmitry.baryshkov@oss.qualcomm.com, konrad.dybcio@oss.qualcomm.com, Krishna Kurapati Subject: [PATCH v5 1/2] usb: dwc3: core: Introduce glue callbacks for flattened implementations Date: Sun, 7 Sep 2025 23:44:11 +0530 Message-Id: <20250907181412.2174616-2-krishna.kurapati@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250907181412.2174616-1-krishna.kurapati@oss.qualcomm.com> References: <20250907181412.2174616-1-krishna.kurapati@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: sFxZif2BpfgF35Eiy_JwckA9KpA0JieO X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwOTA2MDAzNSBTYWx0ZWRfXxv0+PXoNY2t8 sHHwIfrw9BdjW7Wp6JU4ZiN/bNtQ+rDlNiFYfyZHbr1RGUzzFmqi7aLthnDXqsMCbOLf9ksAK9+ gBvooXvYkGLqIpPKD6HOBpmPwzTO7OO9nR4o2C/hBlgMc+Xhf4rsKYkULb7YxzWMkd146Tc3IPU qqkWxGc3BFGD8XE4Tl9FrJU1Go1J6cA0bcQms3UfBFwNAaHzAwo9svmnOWA5brCGm4AJ+w0QJVO 65cGticCtLvBWNK91umwEXtR+3dmIYK5exYAemwwG5u/sNupVACxoGJufPHwJGjDlnd3lbREMQC VtL/AgWYITYLyqYu74M6B1RqTbnkG4VDHwyYMlZXOJqEn60bv5piRDjLlGDUuQzYSyRyeRYlws0 ba8VCZ2q X-Proofpoint-GUID: sFxZif2BpfgF35Eiy_JwckA9KpA0JieO X-Authority-Analysis: v=2.4 cv=N8UpF39B c=1 sm=1 tr=0 ts=68bdcb80 cx=c_pps a=JL+w9abYAAE89/QcEU+0QA==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=yJojWOMRYYMA:10 a=jIQo8A4GAAAA:8 a=EUspDBNiAAAA:8 a=9UFxAfr_hboBSpCGZXUA:9 a=324X-CrmTo6CU4MGRt3R:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-09-07_07,2025-09-04_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 malwarescore=0 clxscore=1015 bulkscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2507300000 definitions=main-2509060035 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. Acked-by: Thinh Nguyen 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 370fc524a468..ae140c356295 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -2352,6 +2352,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..a5fc92c4ffa3 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 + * @pre_set_role: Notify glue of role switch notifications + * @pre_run_stop: Notify run stop enable/disable information to glue + */ +struct dwc3_glue_ops { + void (*pre_set_role)(struct dwc3 *dwc, enum usb_role role); + void (*pre_run_stop)(struct dwc3 *dwc, bool is_on); +}; + /** * struct dwc3 - representation of our controller * @drd_work: workqueue used for role swapping @@ -1012,6 +1023,7 @@ struct dwc3_scratchpad_array { * @eps: endpoint array * @gadget: device side representation of the peripheral controller * @gadget_driver: pointer to the gadget driver + * @glue_ops: Vendor callbacks for flattened device implementations. * @bus_clk: clock for accessing the registers * @ref_clk: reference clock * @susp_clk: clock used when the SS phy is in low power (S3) state @@ -1197,6 +1209,8 @@ struct dwc3 { struct usb_gadget *gadget; struct usb_gadget_driver *gadget_driver; =20 + const struct dwc3_glue_ops *glue_ops; + struct clk *bus_clk; struct clk *ref_clk; struct clk *susp_clk; @@ -1614,6 +1628,18 @@ void dwc3_event_buffers_cleanup(struct dwc3 *dwc); int dwc3_core_soft_reset(struct dwc3 *dwc); void dwc3_enable_susphy(struct dwc3 *dwc, bool enable); =20 +static inline void dwc3_pre_set_role(struct dwc3 *dwc, enum usb_role role) +{ + if (dwc->glue_ops && dwc->glue_ops->pre_set_role) + dwc->glue_ops->pre_set_role(dwc, role); +} + +static inline void dwc3_pre_run_stop(struct dwc3 *dwc, bool is_on) +{ + if (dwc->glue_ops && dwc->glue_ops->pre_run_stop) + dwc->glue_ops->pre_run_stop(dwc, is_on); +} + #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_RO= LE) int dwc3_host_init(struct dwc3 *dwc); void dwc3_host_exit(struct dwc3 *dwc); diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index 7977860932b1..4c91240eb429 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -464,6 +464,7 @@ static int dwc3_usb_role_switch_set(struct usb_role_swi= tch *sw, break; } =20 + dwc3_pre_set_role(dwc, role); dwc3_set_mode(dwc, mode); return 0; } diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 554f997eb8c4..6f18b4840a25 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2662,6 +2662,7 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int= is_on) dwc->pullups_connected =3D false; } =20 + dwc3_pre_run_stop(dwc, is_on); dwc3_gadget_dctl_write_safe(dwc, reg); =20 do { --=20 2.34.1 From nobody Tue Sep 9 16:21:02 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8731829BDB6 for ; Sun, 7 Sep 2025 18:14:29 +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=1757268871; cv=none; b=Vh8idyYzdi3iyeIRLlyYl6BzVyUyCk8IaFlg5w3ueFAhfhGtvwXVtnryyVcJYTv5nbZwW4nTpEfOJXr6PBw48TQL/mOAFL6h0nBh+9SDk7RNozMO3VNIrCSdTh0JJpzusqo4aQRP8ckPqUkhSUT49qAJCufNGr3HeaZ996FuBHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757268871; c=relaxed/simple; bh=R6KKjfE0n/H51wIYeESx4WmybdDuxempHU7GWuXURpg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WMSyJns5XuGXwG4nanEPb4axuEG3MonFsZ3P3IAjy8NUKsE4JVJvJF3TiQYoMc3F+P3NTM6h75YcJc28Jzd7XPkxskzSRgROPheousZDV0E8sZnH0tOFFXV/8/V1ESGEXMAs26dNWkCra978DxKP/Y7tmPBL+CXeZNWuyQ0sdGc= 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=jZuiEqgn; 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="jZuiEqgn" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 587IES8I006217; Sun, 7 Sep 2025 18:14:28 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=HqVMPP7bx9r Rkhe1pncl2vK9OwnV++uC7gBR+2Ge7ck=; b=jZuiEqgnGmrXFfS6XPlL92fqqQj EqfFMKdp3IJqTX9DChqyIRrbDA6gY3cwEp4/6PcLrpTs90RqZKD1GsEP1wvrEOV5 f8MXc28eTc8W8yjvRaDohOiaYMzi/BiIgoeBMmyZlD+IAFUFykMyNcmphfE+Cv3j KqWOWUcP1FfOIe/Wh1zAnD38nHLxXwMcIudTCQfDxFz1JBq6qJxT1hZnb0hmNI52 ZlWX3j9f60L+13VqgIAUX98XbgBN0naZTWVWgyai/IfCy773ciuAOMFZYv2vvBwi LMaaQhN6zrBNL630hLtPjlubylLT5pj1DZ9nByWnJ0fkyXwsNUk22OwyrKQ== 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 490d63ad82-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Sun, 07 Sep 2025 18:14:28 +0000 (GMT) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-24458274406so74667115ad.3 for ; Sun, 07 Sep 2025 11:14:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757268868; x=1757873668; 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=HqVMPP7bx9rRkhe1pncl2vK9OwnV++uC7gBR+2Ge7ck=; b=eP5w0NZcl80Q6ZSP2cFKxfk2zDtjBrmcLpgjh9mm9oaySoMkO1QKxlGv1aZu7kP66/ o9zLvn+B7Ih8jP1qZGXMskoKrOsl9Bv8br2PZ+D5Dbc3KVv7UjzoXrXPQRaI4NBbNdtL /opbQLptyGKnKxzx7MljgLxyI31KysgpNcx9313SAKlzrswtg5FVApdgkHiyTw1aOIFh hirTj178DPMLYv0m/TdbOGKo8zbxz6UjpRK1CIGozNeZwO0VAFPAtLHbkB1ZHdJzEaMs HKSMvbI2Xnilvi/vQjbH+3nNgfFOyMnUnpolqTqksKqaeili+/mn/xYoFmPB55HOmRER NzRw== X-Forwarded-Encrypted: i=1; AJvYcCWMw6G0lUQPJXQ3lzEu/siV8UwGiRSjnBmblJGDhvcBG3u5GpSQUNPmg4obmuMQ9rp0BSNUIUeB0X0BSZQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxhdsJM20w7Ve8pPLsxa7pMZELYFPB+r++XBnWafdlZptOkmni+ 3MUe6G46YlmnrFk+jANaHfGSL5pXARInhdsEIOSDdvS+62Moyjidbu+jK5Sz/7VNVdiQwUjLFwk nDB9T3S8p3HwDk5ekSWqw1pSARqebGTrgMAtDz7TW6u4cPcZyP0TCVM2BHRVDbbd+THY= X-Gm-Gg: ASbGncvXgfpY0rPo2Venrrel+taBvWr1b4Jry1JyeVMAOxPRvKLYQ6/NPj8pkXaL1I9 Bgk36dlbQ87QJVhUzNMIPM9sueL0XudRWMRbNvjhTGNMQGWGYk/5t1ve9b9DIwBP9WjjEwc2x1p PRnY90vwbw1aU9hRQD7wAM3pLnUOkXwgo7c+CkWjIOqX3ByWzaNGhFT/WZv1s+9DallVbAwTiyS 9RKetKtND1x4tuakcEtPP8LOr2WNOVFdIIgqxhX3rEo61a2b8cUO/3Ev57HNezBy1+YuqH5MnIC c/akl89oZpfyyyBsqqrKU0Zx7kNCleNJRMiE04Mxks6eeke1DAcS4Ec2L+PA+wbaTZVK8FtWAol dig== X-Received: by 2002:a17:903:1b64:b0:24b:2b07:5f72 with SMTP id d9443c01a7336-251736df041mr62517365ad.28.1757268867491; Sun, 07 Sep 2025 11:14:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExzyBRYl6czyYwC9M0nmWMqo3nas+FD4zYM1tcPoUdDpDX4XkmMGGylyH9dVar7eL9Jvbg1Q== X-Received: by 2002:a17:903:1b64:b0:24b:2b07:5f72 with SMTP id d9443c01a7336-251736df041mr62517165ad.28.1757268867005; Sun, 07 Sep 2025 11:14:27 -0700 (PDT) Received: from hu-kriskura-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-24cde5b6484sm84074765ad.19.2025.09.07.11.14.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Sep 2025 11:14:26 -0700 (PDT) From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman Cc: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, dmitry.baryshkov@oss.qualcomm.com, konrad.dybcio@oss.qualcomm.com, Krishna Kurapati Subject: [PATCH v5 2/2] usb: dwc3: qcom: Implement glue callbacks to facilitate runtime suspend Date: Sun, 7 Sep 2025 23:44:12 +0530 Message-Id: <20250907181412.2174616-3-krishna.kurapati@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250907181412.2174616-1-krishna.kurapati@oss.qualcomm.com> References: <20250907181412.2174616-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-Spam-Details-Enc: AW1haW4tMjUwOTA2MDAyOSBTYWx0ZWRfX24JhYZLCcWGZ YVK0XQWUFLIfO1XO9/Mrhr/izryGkiYQ9tNCm2ipIZd6RX1Jl+Yen+VhOPbQ4hl29jmujCKcnEy RJx6CxuBtZD/0rHf4CcN9z6LTM7d1eLm0LsSIwRRUTxSs5wdbHVwMAB0c1sqZhBR8CO3RURY/ap sloC+Y41HeBnBgFer+1NJCnfu48ogxT0woAlu7VXw905HU/57A/S4AyniV2aY+acKimV1URdRnS 5nNARy1jjE7sGH1VKGYgDKpq7fPlPfgqgY/MifVTMRoUfVCR56ddlbTejt3ek/rLC0sC8o+sEqH eBOr7jiWGqVxObKGvPChjmd4TiP2pOZUiatwN1S9lvZqxcj18JWH6U6DymbbF0Oo1ITP0cyzSfu /oA7PoYu X-Proofpoint-GUID: A0Rdny5rxZaPzOy9LEtqQ70zm9Ftdpf- X-Proofpoint-ORIG-GUID: A0Rdny5rxZaPzOy9LEtqQ70zm9Ftdpf- X-Authority-Analysis: v=2.4 cv=DYgXqutW c=1 sm=1 tr=0 ts=68bdcb84 cx=c_pps a=cmESyDAEBpBGqyK7t0alAg==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=yJojWOMRYYMA:10 a=jIQo8A4GAAAA:8 a=EUspDBNiAAAA:8 a=ProRYBKZBCDr5nQBVQAA:9 a=1OuFwYUASf3TG4hYMiVC:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-09-07_07,2025-09-04_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 spamscore=0 impostorscore=0 malwarescore=0 bulkscore=0 suspectscore=0 adultscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2507300000 definitions=main-2509060029 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. Acked-by: Thinh Nguyen Signed-off-by: Krishna Kurapati --- drivers/usb/dwc3/dwc3-qcom.c | 78 +++++++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 10 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 8a9018ca650c..ded2ca86670c 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -83,6 +83,8 @@ struct dwc3_qcom { bool pm_suspended; struct icc_path *icc_path_ddr; struct icc_path *icc_path_apps; + + enum usb_role current_role; }; =20 #define to_dwc3_qcom(d) container_of((d), struct dwc3_qcom, dwc) @@ -111,10 +113,6 @@ static inline void dwc3_qcom_clrbits(void __iomem *bas= e, u32 offset, u32 val) readl(base + offset); } =20 -/* - * TODO: Make the in-core role switching code invoke dwc3_qcom_vbus_overri= de_enable(), - * validate that the in-core extcon support is functional - */ static void dwc3_qcom_vbus_override_enable(struct dwc3_qcom *qcom, bool en= able) { if (enable) { @@ -560,6 +558,55 @@ 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)) { + dev_dbg(qcom->dev, "Failed to resume device\n"); + return; + } + + if (qcom->current_role =3D=3D USB_ROLE_DEVICE) + dwc3_qcom_vbus_override_enable(qcom, false); + else if (qcom->current_role !=3D USB_ROLE_DEVICE) + dwc3_qcom_vbus_override_enable(qcom, true); + + pm_runtime_mark_last_busy(qcom->dev); + pm_runtime_put_sync(qcom->dev); + + /* + * Current role changes via usb_role_switch_set_role callback protected + * internally by mutex lock. + */ + qcom->current_role =3D next_role; +} + +static void dwc3_qcom_run_stop_notifier(struct dwc3 *dwc, bool is_on) +{ + struct dwc3_qcom *qcom =3D to_dwc3_qcom(dwc); + + /* + * When autosuspend is enabled and controller goes to suspend + * after removing UDC from userspace, the next UDC write needs + * setting of QSCRATCH VBUS_VALID to "1" to generate a connect + * done event. + */ + if (!is_on) + return; + + dwc3_qcom_vbus_override_enable(qcom, true); + pm_runtime_mark_last_busy(qcom->dev); +} + +struct dwc3_glue_ops dwc3_qcom_glue_ops =3D { + .pre_set_role =3D dwc3_qcom_set_role_notifier, + .pre_run_stop =3D dwc3_qcom_run_stop_notifier, +}; + static int dwc3_qcom_probe(struct platform_device *pdev) { struct dwc3_probe_data probe_data =3D {}; @@ -636,6 +683,23 @@ static int dwc3_qcom_probe(struct platform_device *pde= v) if (ignore_pipe_clk) dwc3_qcom_select_utmi_clk(qcom); =20 + qcom->mode =3D usb_get_dr_mode(dev); + + if (qcom->mode =3D=3D USB_DR_MODE_HOST) { + qcom->current_role =3D USB_ROLE_HOST; + } else if (qcom->mode =3D=3D USB_DR_MODE_PERIPHERAL) { + qcom->current_role =3D USB_ROLE_DEVICE; + dwc3_qcom_vbus_override_enable(qcom, true); + } else { + if ((device_property_read_bool(dev, "usb-role-switch")) && + (usb_get_role_switch_default_mode(dev) =3D=3D USB_DR_MODE_HOST)) + qcom->current_role =3D USB_ROLE_HOST; + else + qcom->current_role =3D USB_ROLE_DEVICE; + } + + qcom->dwc.glue_ops =3D &dwc3_qcom_glue_ops; + qcom->dwc.dev =3D dev; probe_data.dwc =3D &qcom->dwc; probe_data.res =3D &res; @@ -650,12 +714,6 @@ static int dwc3_qcom_probe(struct platform_device *pde= v) if (ret) goto remove_core; =20 - qcom->mode =3D usb_get_dr_mode(dev); - - /* enable vbus override for device mode */ - if (qcom->mode !=3D USB_DR_MODE_HOST) - dwc3_qcom_vbus_override_enable(qcom, true); - wakeup_source =3D of_property_read_bool(dev->of_node, "wakeup-source"); device_init_wakeup(&pdev->dev, wakeup_source); =20 --=20 2.34.1