From nobody Mon Feb 9 23:00:54 2026 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 BBA4A3203B4 for ; Fri, 16 Jan 2026 23:21:15 +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=1768605680; cv=none; b=CCS1skTT5L1Ab6ZAr1UN4XN1zwzWJlA3QftS4DxaS2h3iaWyRvifAIqIP1BPJKYwdRiKw9lOcbyHf3sodlOFbtDQCmQK/Esx0CCQVnHrLwMiBwBThnuIjesKnRlAWZW+Ir0mU6IRizzCsUnwaU2sy2Qi+tr3rkZpob++4aJM3/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768605680; c=relaxed/simple; bh=r1bqX+YKzW7Wo7iz/2rkXvfUlo4SFKFYbrl1Eh5BoSQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KYeSWJpN0h37JMsGI5k9kOgRdjVMdR2OpnOLD8d1g7pNzPbrR8I9UNPdNTThZxqKnshbyBrCnz/WlhYcRDFlRGRqYHKGL3fmmZqCOF/WhT0L7ORSozzNW4iNO3t/j4v2WZglZtPW+Js90+CaE2zhnwTOom+ZlHLfI0mO754AHlA= 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=RXB8wg6M; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=dfc+R59n; 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="RXB8wg6M"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="dfc+R59n" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 60GND0m02527079 for ; Fri, 16 Jan 2026 23:21:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=nLNoInJmlgi CyTSp0s0aDwUKBeAC7fdewIAWrT/v+x8=; b=RXB8wg6M1UqjDyu5uY1Jpz9/GxI hrey0kk7FfZZrAqcc77EesVLivRtsdSP3Y+UH+uTOgb6ue5tUVpjBw8rePqNQAQh BGjqRQM2KKMaq4Lo/Bf2Q+Za/H6C9ziZKuwkFWVJBkVLDI7eI6JiDBGrXmOLiiVp QEG2CAZi/NrilZPFmEFeSvcXrvLlBR93Ns1HbpnrUDCh6d38bTSPVd3YDPcXfSwY 4ES7HOOPeO3mqyjvHz+28QS1/4Vg7I9tN1UA1LbOZAPPi3pcyC8jfvKXLMxxGCDf F7Y+9Khm/2uN/va2qcr/4v4qkKt1wgDa+LXBpdID/0sQfxC4g0fmfdEc31g== Received: from mail-dl1-f69.google.com (mail-dl1-f69.google.com [74.125.82.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4bqvevgbe1-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 16 Jan 2026 23:21:13 +0000 (GMT) Received: by mail-dl1-f69.google.com with SMTP id a92af1059eb24-1219f27037fso1493773c88.1 for ; Fri, 16 Jan 2026 15:21:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1768605673; x=1769210473; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nLNoInJmlgiCyTSp0s0aDwUKBeAC7fdewIAWrT/v+x8=; b=dfc+R59nKfMeRZv+Jf0hT6tKkSc0cdbC+4zH7dCtSy214k69AM/wczyXzwz6FicgDS iDH90QRNWH1uCg/fzGKnjqBDSg9I0gLVe6bOyfWjBPbQ7gatLxLNBOtr6rDZBjnYZmRg uzMYMrSosBXDj4oZkgBe4euoxCRV0cjPwY6yQxr0Do4gjHIMU9d56y04D7qg2PtWnlNW awyJwFjVJM+MIYCWyHqtF1R4y6AoAh9YYArGkLPsynxoaLL/YkDwLJEBIURQ6JIMbdE6 ju4+/ZR4ZQTQcYEGx+PjTclgQYjSpgp0PKsbdkedPqbFIlV2anF3TLqGoeKoawvnWfb2 N9vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768605673; x=1769210473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nLNoInJmlgiCyTSp0s0aDwUKBeAC7fdewIAWrT/v+x8=; b=w8XCqt2ydDLtTyWxKMXyN6vlFklSrKR5aij19Sf5fmzOeRHWxsjork32qwrPYfbNwW T3zi1W6l4qdMvAfiF+fiA2gM5w85TMsS3jeAxNfaIGoTmP19puECTMXZOiWpWgTIPPxU w9HueM5CtDUuIkW1aOr2EYh5bq9NZ370204CpdAbUiTTd6gs4shoiYABxUUwG+2lCcdt Ab+bCU9YeuzuG0jPfPDyv8c8fl0jnHXCkmqVHueKvJR9ooRnYG4tYenjP9GMQjP3xTel r+sBhKo0DBI7sm8b4N0bc5Atmg3tMdw8xJVWddLC3dqkT/7qCX5FZnLZWQHwpS5xcNmM ZXHA== X-Forwarded-Encrypted: i=1; AJvYcCVITVTemekyuy0fqIOHlQWbtDUZfF3w+zqdzEzn7wJlwXivQJPQzwYA4VbErKZXPhH3SwQxrtRNRyn9U2E=@vger.kernel.org X-Gm-Message-State: AOJu0YxdzgfU+AEIQKSj1rG52S7W8Wz9sKFR2a3KRBvYpv3/ekFoselN 67hx5nFoe7MbCTla1HF4DXwnkmx5yYfPYr/fI6y6QXKke7u2OutrR90SK2pRrGhIM5s4MFzIM8s GVoYIqlfkkPbcBPtpHIqgU7/ud8fcfwec4pJHjl80wr9H1SyIZWirLy4BDPBWcabPMig= X-Gm-Gg: AY/fxX7EYv+HT3LfazGLY+dAC34Ow/5Bj0hlgrV508kVVDna4RSu41WqEqSQMKO9mdj iD5wcRS9div4YR+r2vxluU8nPYX1K+jybMqXL4czbIn9yp1u+DyWwnKeLzZHyGCMxZ63GXjQxqd xM7LbNAMo3EWQudV2WJzUL+h6VXods2MEGL9EuasCsz/OE2WTmT4cfBgKXd9Xr3bjrcn0B4qIQR UCP85LqjMsE60rcwWjGl9gjEhC5ZpSOGmF7oi/lTfhKIAi1RgI8gtAI7+h+jO7wukUcfapNG/jr fxihw0vM9o/BJmZPsaXJtQ8tMtGWs0/V7JDnhSyIgM7cQE66YNxkHmun96CbDHW3jXO/hpV+CcX NUngrHMJWtzdJUPrXyjXKTiDE12MsVZTwhB/I/w9n/HctCwFM5YAa13JIYulJzyE= X-Received: by 2002:a05:7022:660b:b0:123:3360:aa99 with SMTP id a92af1059eb24-1244a75ea1cmr4361082c88.47.1768605672814; Fri, 16 Jan 2026 15:21:12 -0800 (PST) X-Received: by 2002:a05:7022:660b:b0:123:3360:aa99 with SMTP id a92af1059eb24-1244a75ea1cmr4361064c88.47.1768605672348; Fri, 16 Jan 2026 15:21:12 -0800 (PST) Received: from hu-eserrao-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1244af10e21sm4611267c88.16.2026.01.16.15.21.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jan 2026 15:21:11 -0800 (PST) From: Elson Serrao To: Greg Kroah-Hartman , Bjorn Andersson , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Souradeep Chowdhury Cc: linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/9] usb: misc: qcom_eud: add host mode coordination Date: Fri, 16 Jan 2026 15:21:03 -0800 Message-Id: <20260116232106.2234978-7-elson.serrao@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260116232106.2234978-1-elson.serrao@oss.qualcomm.com> References: <20260116232106.2234978-1-elson.serrao@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: AW1haW4tMjYwMTE2MDE3NSBTYWx0ZWRfX7PVXFbkNL6W8 SoEtvcOZibvRP4DHITBZbMbRsm2WDJ5390PRtx4ctbZSyD71T6ZiEJERYnha8Y1BLTtA/DwK/J8 13vZM5b7rawxc9CoOJUBIDnbtctKI/Z+UMf1yraCOANJJu0l4TDbaFrCxk6/UVUEYn5v85Vbe3d huDNEmcr5TS7pm2qj2+HL1XCSGjplTR7ghXfyrywyO71Rc+mO1RTfxqOrG6U6AZUcwGr2Jd5P2m lpbdUM8EoJBjK9qNLa7znnQPSjJnEhf/O9mUmB3BihKwvA+TTrkowGxtGypeetUAX9VEN2SImpW cUpDq13rJCT3dMGOV4n5/1Vv9AgLXQ01wgdw03+HBiEC36DHsQlVV2+Bhp75LYSUIX+2q6V0lf9 /0JtwQEMGhlz3N9g61w7PJIIWDGmyoRPOEi1+qLKUv4Yt7BZEo8B+8RmArRl25CXSKA39eOMPp/ uNgpEI1vZHae0ivreiA== X-Proofpoint-GUID: I1Rtv5rQrAigjqIoDVWhCNZupos2J1v6 X-Authority-Analysis: v=2.4 cv=faugCkQF c=1 sm=1 tr=0 ts=696ac7e9 cx=c_pps a=kVLUcbK0zfr7ocalXnG1qA==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=vUbySO9Y5rIA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=EUspDBNiAAAA:8 a=0DRR6HtdnbDkULtDn-kA:9 a=vr4QvYf-bLy2KjpDp97w:22 X-Proofpoint-ORIG-GUID: I1Rtv5rQrAigjqIoDVWhCNZupos2J1v6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2026-01-16_08,2026-01-15_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 suspectscore=0 spamscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 clxscore=1015 phishscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2601160175 Content-Type: text/plain; charset="utf-8" EUD functions by presenting itself as a USB device to the host PC for debugging, making it incompatible in USB host mode configurations. Enabling EUD, when in host mode can also cause the USB controller to misbehave as the EUD hub can only have one upstream facing port. Handle below two scenarios to prevent these conflicts: 1. Prevent user from enabling EUD via sysfs when the USB port is in host mode. 2. Automatically disable EUD when USB port switches to host mode and re-enable it when exiting host mode. This ensures consistent state management without creating conflicts between the EUD debug hub and the USB controller. Signed-off-by: Elson Serrao --- drivers/usb/misc/qcom_eud.c | 79 ++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/drivers/usb/misc/qcom_eud.c b/drivers/usb/misc/qcom_eud.c index 0ea6491f963c..3f1cc7ea2a6a 100644 --- a/drivers/usb/misc/qcom_eud.c +++ b/drivers/usb/misc/qcom_eud.c @@ -49,12 +49,15 @@ struct eud_chip { struct device *dev; void __iomem *base; struct eud_path *paths[EUD_MAX_PORTS]; + /* serializes EUD control operations */ + struct mutex state_lock; phys_addr_t mode_mgr; unsigned int int_status; int irq; bool enabled; bool usb_attached; bool phy_enabled; + bool eud_disabled_for_host; u8 port_idx; }; =20 @@ -162,32 +165,66 @@ static ssize_t enable_store(struct device *dev, const char *buf, size_t count) { struct eud_chip *chip =3D dev_get_drvdata(dev); + struct eud_path *path; bool enable; int ret; =20 if (kstrtobool(buf, &enable)) return -EINVAL; =20 + mutex_lock(&chip->state_lock); + /* Skip operation if already in desired state */ - if (chip->enabled =3D=3D enable) + if (chip->enabled =3D=3D enable) { + mutex_unlock(&chip->state_lock); return count; + } + + /* + * Handle double-disable scenario: User is disabling EUD that was already + * disabled due to host mode. Since the hardware is already disabled, we + * only need to clear the host-disabled flag to prevent unwanted re-enabl= ing + * when exiting host mode. This respects the user's explicit disable requ= est. + */ + if (!enable && chip->eud_disabled_for_host) { + chip->eud_disabled_for_host =3D false; + chip->enabled =3D false; + mutex_unlock(&chip->state_lock); + return count; + } =20 if (enable) { + /* + * EUD functions by presenting itself as a USB device to the host PC for + * debugging, making it incompatible in USB host mode configuration. + * Prevent enabling EUD in this configuration to avoid hardware conflict= s. + */ + path =3D chip->paths[chip->port_idx]; + if (path && path->curr_role =3D=3D USB_ROLE_HOST) { + dev_err(chip->dev, "EUD not usable in host mode configuration\n"); + mutex_unlock(&chip->state_lock); + return -EBUSY; + } + ret =3D enable_eud(chip); if (ret) { dev_err(chip->dev, "failed to enable eud\n"); + mutex_unlock(&chip->state_lock); return ret; } } else { ret =3D disable_eud(chip); if (ret) { dev_err(chip->dev, "failed to disable eud\n"); + mutex_unlock(&chip->state_lock); return ret; } } =20 chip->enabled =3D enable; =20 + mutex_unlock(&chip->state_lock); + return count; } =20 @@ -324,18 +361,56 @@ static irqreturn_t handle_eud_irq_thread(int irq, voi= d *data) static int eud_role_switch_set(struct usb_role_switch *sw, enum usb_role r= ole) { struct eud_path *path =3D usb_role_switch_get_drvdata(sw); + struct eud_chip *chip =3D path->chip; int ret; =20 + mutex_lock(&chip->state_lock); + + /* + * EUD must be disabled when USB operates in host mode. EUD functions by + * presenting itself as a USB device to the host PC for debugging, making + * it incompatible in host mode configuration. + * + * chip->enabled preserves user's sysfs configuration and is not modified + * during host mode transitions to maintain user intent. + */ + + /* Only act if EUD is enabled and this is the active path */ + if (chip->enabled && path->num =3D=3D chip->port_idx) { + if (role =3D=3D USB_ROLE_HOST && !chip->eud_disabled_for_host) { + ret =3D disable_eud(chip); + if (ret) { + dev_err(chip->dev, "Failed to disable EUD for host mode: %d\n", + ret); + mutex_unlock(&chip->state_lock); + return ret; + } + chip->eud_disabled_for_host =3D true; + } else if (role !=3D USB_ROLE_HOST && chip->eud_disabled_for_host) { + ret =3D enable_eud(chip); + if (ret) { + dev_err(chip->dev, "Failed to re-enable EUD after host mode: %d\n", + ret); + mutex_unlock(&chip->state_lock); + return ret; + } + chip->eud_disabled_for_host =3D false; + } + } + /* Forward the role request to the USB controller */ ret =3D usb_role_switch_set_role(path->controller_sw, role); if (ret) { dev_err(path->chip->dev, "Failed to set role %s for port %u: %d\n", usb_role_string(role), path->num, ret); + mutex_unlock(&chip->state_lock); return ret; } =20 path->curr_role =3D role; =20 + mutex_unlock(&chip->state_lock); + return 0; } =20 @@ -433,6 +508,8 @@ static int eud_probe(struct platform_device *pdev) =20 chip->dev =3D &pdev->dev; =20 + mutex_init(&chip->state_lock); + ret =3D devm_add_action_or_reset(chip->dev, eud_role_switch_release, chip= ); if (ret) return ret; --=20 2.34.1