From nobody Mon Feb 9 17:35:40 2026 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 974143128CB for ; Mon, 26 Jan 2026 23:38:39 +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=1769470722; cv=none; b=qxD1qykSVGAGsUQuFSxd6ZALOQNfDUyGMneRWjHBVkRYtM/O7JBDgQa2wqUB5iIp1cpc40yGsxPGC9U9NX9jb7y1HNv8aGuJmaRMUvA0DFLvdPmTQQK20TWhn1fekPbWDhisJFyMUnpWeU/498SRPiunCu94WoOUg/Umy6eXm8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769470722; c=relaxed/simple; bh=r1bqX+YKzW7Wo7iz/2rkXvfUlo4SFKFYbrl1Eh5BoSQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FtegZ9Kz5lOlLC05zBpkiEEK3vY/S17gJj9DCfNTzG7+n60t9JS26hpYCXYudU+xqUK4nq10NtX4cxlTiWZJE+6g46icclBsgKYi1HviCVDv1DgYwqL1iIDuAQYV/Ni8qi8k37Vh1z/9baq7mHTkCoVTdSeaZsNf8BNKaMWG2gA= 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=X4KwaqLC; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=h/AbITzY; 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="X4KwaqLC"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="h/AbITzY" Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 60QKgCPN2880085 for ; Mon, 26 Jan 2026 23:38:38 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=X4KwaqLC9LLCemO57LUhqgJjAMq B2+jhNok4UWzP7eKmowXMNqX8eflul5TxLtd8wx+zHAiJg+Buw9B70nhTnActyOJ gYSU/O899BmWhDhxAjDMVImicSUXH+tFsZkE+DHm7zjgbvfp9ZrhBrctUJucF5Hl In62/ROlblEDIup1Szjhs7//gcYIC4wusGOulWh0AIqVl63Jyj39NJQNMcfmFOxE PK2qvdd+ynPl7SkKdHlpXSS38jn5NFW+mHhcbXwO9nmBBbK2+P1pxQx2F9EIK//E F2Tnk6IZjOpAvyLa2bwRYEp2PQmI6P8tJ8Ehslm3+GLu2oBrnelBKhdl9AA== Received: from mail-dl1-f72.google.com (mail-dl1-f72.google.com [74.125.82.72]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4bxffs0ct9-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 26 Jan 2026 23:38:38 +0000 (GMT) Received: by mail-dl1-f72.google.com with SMTP id a92af1059eb24-12337114f3fso7033635c88.0 for ; Mon, 26 Jan 2026 15:38:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1769470718; x=1770075518; 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=h/AbITzYvNoSLuacqnaGFqyw10AqpkH12dHFNEahRsbfO7B8gBye5mnqKFMKc5XRNH BC+xi7NJa3QfAoxMEZ6xpGeNF5bJ0k9Xc+4VjplT1KNv/FD5IeWMy3ROcGkzot7M4b5m DjfQLUXcBemIjadmHNemhScqL0PTzpapV11n359KAr0/p9kRRVVGdkWd4w/8J+KbifKH RYXgDC6kpTrA36OAqlkZHeNJN4g/NUsZkWSLLOHIwzGgtW1fdmppVlSZiXcJpITHyF1h vOWj0eNLugQFeFP1jqPEQPWq7VmDEFoojGwyiCWhvEfm1nTYOgdC+Qllom2ZSjVexloh vVog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769470718; x=1770075518; 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=oRwVTJFKb2ZAcM7A7atqNIePTZvwsmBE4N9u/5GAQ66SlYs4D5FLDDk444xXr6TZuu C+KlfgCFMhBH0afz7/VHOT6kvBC4Edls1vFIChyzAs12n6QmfY87TwGNsZxzhg7lMmIX 3mH4bYF4s2j845VC9ffMad69p6kjc3dUn9L75FIDLz8LgDyt1oAmQQXCW9ox/Ib1CfPy qvNEFshbDpaNh2bRX1I0nMO1iiaVYJnEh13SUv0V7rr+DmMSHMki6d12M1sKNj4AluNk ThGQ8uGzy7EOMCJxHVv1ZlTFFDMYBAgGTVZRxSSyzM2Xk/ZCfOcmu2cvMGuizre1phE+ gDCA== X-Forwarded-Encrypted: i=1; AJvYcCVf/vgrzRHLi/OPPrRbCyaQD39oWqR2P28AEyug9uyx65kVE827rOyD+Jky7A4U3G5dKEDIolmFw4ocSrM=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/YuKuyvzaaN3koloXTDx/CZ+QPENks2yi83/Iq30tL2nuWpLr FnMGFxxtMA7criYjJuL3VRdVtXnrxe8r/Cr+ubZGfLqNnxmtcb4DeGnn5L3IM24Uj+2MVkHPgpg iRJgxGgxKI6j+9nL2EAnnEJIBjwYQfP4e9BxYUWWgyeml6hHibOHwb7EMmNyJFCpvTP4= X-Gm-Gg: AZuq6aL287I1SUr4+7Mjvxi/+m2uRePhFTbe1L1KI4OAJnNLEnIBHl3xGJ4Z4uGasEa cdihFkAi+K+6bgOqoHI7AU3da75S6eroVFx+Ex2K1L15gBu0JDn1Yu/ujBwBxJEGnARQDjYhJWm fymsUU/YP8Yk3DKyZuzf+/5li8vx5LJpx6lFDJbDfRQpYOf2azgul7BOvMMxwStXMwO0mRHcRvS OXD6nSG6JSmsivZvLWgRNtE4xbwkLbVC0hyVfaxd0LmK/XsrekHqIsrtWNYqpA84jHm1pRFcyGi 3JV68Wbwnv6rGJitPgA+NkhGbpbzMLNfGWpFQ5YG47cHVVlcaOvW68GPG8tBqn3qjsO/fyNfJtO 30IO0xxAd0iNLB1qc64EGk0pXSEF2aW61e2JzYexVjlSsQjWfbXlmlhEtSj4rMuI= X-Received: by 2002:a05:7022:438c:b0:11a:51a8:ec9 with SMTP id a92af1059eb24-1248ec41322mr3202372c88.29.1769470717629; Mon, 26 Jan 2026 15:38:37 -0800 (PST) X-Received: by 2002:a05:7022:438c:b0:11a:51a8:ec9 with SMTP id a92af1059eb24-1248ec41322mr3202352c88.29.1769470717090; Mon, 26 Jan 2026 15:38:37 -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-1247d90ce0dsm19948967c88.4.2026.01.26.15.38.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jan 2026 15:38:36 -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 v2 6/9] usb: misc: qcom_eud: add host mode coordination Date: Mon, 26 Jan 2026 15:38:27 -0800 Message-Id: <20260126233830.2193816-7-elson.serrao@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260126233830.2193816-1-elson.serrao@oss.qualcomm.com> References: <20260126233830.2193816-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-GUID: RU8x4RxDrHYpmG8JhSEg241Ir6M-faHL X-Authority-Analysis: v=2.4 cv=YpcChoYX c=1 sm=1 tr=0 ts=6977fafe cx=c_pps a=bS7HVuBVfinNPG3f6cIo3Q==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=vUbySO9Y5rIA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=EUspDBNiAAAA:8 a=0DRR6HtdnbDkULtDn-kA:9 a=vBUdepa8ALXHeOFLBtFW:22 X-Proofpoint-ORIG-GUID: RU8x4RxDrHYpmG8JhSEg241Ir6M-faHL X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMTI2MDIwMiBTYWx0ZWRfXz62S0PMqgS3/ l7YFZYJTpYklnKb3yF+DXncplDjmSoCSXGGlXyY8r1kAvzQS14lXy0Y8pGPCanYZjlZlUtB2dSx YigrTBOskK6NmNohzR3JHgN772/KLACPS0zYVYtueWv9/h5dzDgCDrNGWaFx8biHTRyerkfE9i9 SG9b1KHVkr6ofWwaId5+uvdnlwl3BWlJo5azesWIgalj8zX8zxpRdZ02DcZP2YESVCjbUNJ/4xc y8zWGFXZzaDDnV9SmLtCXyE0HiZ48yZFN4KszHv8VV+iEAzIvSVINDyEhhj+YeLB7Kobaz5IVK3 VCxu77X7/eH7vwzXpe7ZHYV65o+fYlSz8S0GJY5v/tFSsyUG0P68ZkmyeSvtZ0KumlUjXmkubHj dnVmVnpjVRDwa3A5OgO/g6zlmX80T8TolB0wZZ1fc2XSSnXze/5rv9lgpG7k4VV2yHoNgNJV+VB a0KYdY2XWTg7ONhjWXQ== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.20,FMLib:17.12.100.49 definitions=2026-01-26_04,2026-01-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 clxscore=1015 phishscore=0 impostorscore=0 suspectscore=0 spamscore=0 malwarescore=0 bulkscore=0 adultscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2601260202 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