From nobody Mon Dec 1 22:03:20 2025 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CC0230BF77 for ; Mon, 1 Dec 2025 12:26:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764591980; cv=none; b=doG/e/1F9Wbgli7/IJM71OcGBBRq0+OzO+uLL0eNWUWneVdHTEKVGRWrnZrf/4dGgOD3v6CFTl2WYWF8/XvOeuLOJnVXV4ET9UK3beym9ECaF8FeWCVGlETmjq4IpEGTD+AeoJ5JdHJjK1yEPC30jb+oNpmchbCBBg0RN63MbIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764591980; c=relaxed/simple; bh=6VDUNhFKjIyxAfmAoMmcN/eMripBuE0sbN890k7u5Co=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uGiesR439jDBrphwH7CeVCr010fX3Ls/ArlMN8wMyuvlbjBzGdAL7tke4rz6SrWEjKP6JWSXT1ScNJzVBC24ZVvCf+1Irv9lWUyl4SuyJFKfZTn6wgbocex/XEEisK0OhKpQGDWV+YKyQlI2DUEt5vZ5PXjeWNT/tTubkfkuTBI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=UpPT4Zoe; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="UpPT4Zoe" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-64162c04f90so7795783a12.0 for ; Mon, 01 Dec 2025 04:26:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1764591977; x=1765196777; 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=OjAcK5jQuv2kklMSEXof63giOR/XCPNAsoShF6a7bVw=; b=UpPT4ZoeVHXHl59Vz3mg1aWK8Bg+Y2G78tqyTR+u93i9qxlrYWsDH/CSft5fSF2J/K aPMZV3to8k/rCzJZLA/3/gTzjQ6MwCYhhBIH54nZDqJ4+lmqmtCKJDSgM14msRdzIjQ6 /zX75RCprvagV65UZ5zbLqh6Zz3AvIZESa25A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764591977; x=1765196777; 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=OjAcK5jQuv2kklMSEXof63giOR/XCPNAsoShF6a7bVw=; b=figHgpaBzYA1zPnsnoGQtrS+xkuH0ZTkOYEQEq4+Vu1CuN2Ff95FLQ9V8l5eXikXYa qVF4lH+U2zu+8iRXJISG1Ib//YpIgy4VF8sJE3chimVopagJYM5SxBSZFBtrUKMmem37 HlzTYD89/6IWoQxO+iatbDj99selW5K4TsE+E49e1oHb8HAqcUKd46CRjRACSSBur3qu Zr581OK8SNeFh81FvrHUoDT13VTfdRlTUnKjgeMl7aAgdgcWy7YOeB610uAZo3ike1pA ace+dzr9OOMa0AmGxy6qZFD46OlnEQmkLW/W+ynTYVV39S5FI/NxNHpYMVeR8iy/Y+/8 xQ5Q== X-Forwarded-Encrypted: i=1; AJvYcCVytlpSLKbwCCI29goTJhxsXSFsrZEjIdSxHQuOnplqb4SuMSVWtUsGWbJkNIa9YG7sk0ZdmoJXQTbCEaQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyXOGInRBgMtCB+FMfdUQBZZU0FO0gB8SvFXLnJA5mST5JJlnFg 07scvA1Cg+9zAfj0kSvH3gx45mc7IiX2iIdBAcroegXd83rdyde+noI9POcNDssa0g== X-Gm-Gg: ASbGncv8Z/t0YfCqDnVIlbuMCAPK8aVgxtRwG3Lb7MqzwAGYg/rXGT1hl/neqbtGOkC VUIUmaR4ChTwtx4dyyPDSm41lWqxY2TOQa8elR5Db0FLybLEVKyz3l0ZaMJT2kmDoMpK9Wd0vSK ofmikF9CbvsrwAnIkiDSMJhwLoI5kBudxaHmvkWaTysSh9Q42Blw0gxfwF2tWPlup+X5x4TeVQP KN4y42Om9pSHAHXGngiYcPJpI1o8hkw9sqrM+Ajx0B1B6GtsnZjXPZUGW0bUKcB1FmGL64DhD1u dtp7Fa+bh6q9ZK7K8FAY2/qfKAC3wdGe+q0yFvixfWFFN6c6XP0nHNjLJUrK/clFrnQwfFOAz2O 4cwh4iBqAxH+NaMCVmX4qZHHmwtrCgOUmDgjIUdjYKa85AGMCAApONT7LcYjPOfuATnPjfNAu/r mF9Z/kp3s3eaLCdlYfq8VB3cN1e2tVTTM10mnJJFmgOPGLUZSe4/u9RFBnBFxzdSVxDXLcwE7+0 SJ4c+CxnBs= X-Google-Smtp-Source: AGHT+IG3kfMAbGwiNdUyy1C0roJ6R6b1shoAdCyb+csyZ1jwsKMGfN9QjFVoFo8tRijm4LmBgMo8uQ== X-Received: by 2002:a17:907:6eaa:b0:b71:854:4e49 with SMTP id a640c23a62f3a-b767189cf54mr4375094666b.56.1764591976789; Mon, 01 Dec 2025 04:26:16 -0800 (PST) Received: from akuchynski.c.googlers.com.com (218.127.147.34.bc.googleusercontent.com. [34.147.127.218]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b76f519e331sm1229049266b.24.2025.12.01.04.26.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 04:26:16 -0800 (PST) From: Andrei Kuchynski To: Heikki Krogerus , Abhishek Pandit-Subedi , Benson Leung , Jameson Thies , Tzung-Bi Shih , linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: Guenter Roeck , Greg Kroah-Hartman , Dmitry Baryshkov , "Christian A. Ehrhardt" , Abel Vesa , Pooja Katiyar , Pavan Holla , Madhu M , Venkat Jayaraman , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH RFC 2/8] usb: typec: Integrate USB4 into the mode selection process Date: Mon, 1 Dec 2025 12:25:58 +0000 Message-ID: <20251201122604.1268071-3-akuchynski@chromium.org> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog In-Reply-To: <20251201122604.1268071-1-akuchynski@chromium.org> References: <20251201122604.1268071-1-akuchynski@chromium.org> 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 Content-Type: text/plain; charset="utf-8" USB4 is defined as the most preferred mode and is placed at the top of the mode priority list. This ensures that if the port and partner support USB4, activation is attempted first. Activation is handled via the `enter_usb_mode` function. System control (enabling/disabling) over the mode is exposed through the `usb_capability` sysfs port attribute. Signed-off-by: Andrei Kuchynski --- drivers/usb/typec/mode_selection.c | 27 +++++++++++++++++++++++++-- include/linux/usb/typec_altmode.h | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/mode_selection.c b/drivers/usb/typec/mode_se= lection.c index 1cf8a4dcd742..957e09813831 100644 --- a/drivers/usb/typec/mode_selection.c +++ b/drivers/usb/typec/mode_selection.c @@ -74,6 +74,7 @@ static int mode_selection_activate(struct mode_selection = *sel, =20 __must_hold(&sel->lock) { + struct typec_port *port =3D to_typec_port(sel->partner->dev.parent); struct mode_order order =3D {.svid =3D svid, .enter =3D enter, .result = =3D -ENODEV}; =20 /* @@ -85,7 +86,14 @@ static int mode_selection_activate(struct mode_selection= *sel, * interval. */ mutex_unlock(&sel->lock); - device_for_each_child(&sel->partner->dev, &order, activate_altmode); + if (svid =3D=3D USB_TYPEC_USB4_SID) { + if (port->ops && port->ops->enter_usb_mode) + order.result =3D port->ops->enter_usb_mode(port, + enter ? USB_MODE_USB4 : USB_MODE_USB3); + else + order.result =3D -EOPNOTSUPP; + } else + device_for_each_child(&sel->partner->dev, &order, activate_altmode); mutex_lock(&sel->lock); =20 return order.result; @@ -236,7 +244,9 @@ static int altmode_add_to_list(struct device *dev, void= *data) int typec_mode_selection_start(struct typec_partner *partner, const unsigned int delay, const unsigned int timeout) { + struct typec_port *port =3D to_typec_port(partner->dev.parent); struct mode_selection *sel; + struct mode_state *ms; int ret; =20 if (partner->sel) @@ -251,13 +261,26 @@ int typec_mode_selection_start(struct typec_partner *= partner, ret =3D device_for_each_child( &partner->dev, &sel->mode_list, altmode_add_to_list); =20 + if (!ret) { + list_sort(NULL, &sel->mode_list, compare_priorities); + + if (port->usb_mode =3D=3D USB_MODE_USB4 && + partner->usb_capability & USB_CAPABILITY_USB4 && + port->ops && port->ops->enter_usb_mode) { + ms =3D create_mode_entry(USB_TYPEC_USB4_SID, 0); + if (!ms) + ret =3D -ENOMEM; + else + list_add(&ms->list, &sel->mode_list); + } + } + if (ret || list_empty(&sel->mode_list)) { mode_list_clean(sel); kfree(sel); return ret; } =20 - list_sort(NULL, &sel->mode_list, compare_priorities); sel->partner =3D partner; sel->delay =3D delay; sel->timeout =3D timeout; diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_al= tmode.h index a240d8264b92..faf72e4d6ceb 100644 --- a/include/linux/usb/typec_altmode.h +++ b/include/linux/usb/typec_altmode.h @@ -9,6 +9,8 @@ =20 #define MODE_DISCOVERY_MAX 6 =20 +#define USB_TYPEC_USB4_SID 0xFF00 + struct typec_altmode_ops; =20 /** --=20 2.52.0.158.g65b55ccf14-goog