From nobody Thu Oct 9 20:24:10 2025 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 1542E156237 for ; Mon, 16 Jun 2025 13:33:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080793; cv=none; b=eMPYJLIYAL9CX5rDhxqw8Yfkk/mcSx/CKKH/gaiDQDjoNwUvwAf/eYcZMWHzFbbuBBor7n/1IGty9Pgufo1jbnjohjUYzdrHTR5hE30KAjDbXj9zlVLiAyBgETX4xP6c5HW7CPSk2PyB0xFF7VEY7iKccajBYLPSNIGiNEuSVu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080793; c=relaxed/simple; bh=DfWtOSkx84l5KOCfEGNRyyvx2K3TB+JWEySzWnCGZMk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fsdra/FvgDbWD8B3SecmPsMGm62qijMLpHXLjWSfRZFwAbyzXD4Jgin5H1q6bI0se43bakkvpViFVnikeoHKESO8XS1ecnxRCdk8FOZsL0nN3R6xAc0KxjPLYBL5Pk3Hd8NWgBG5lGRbNDFc2iuOdLIowoqDseomi8Ye5XjlQP0= 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=Nq9sAS0t; arc=none smtp.client-ip=209.85.208.52 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="Nq9sAS0t" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-60727e46168so7726096a12.0 for ; Mon, 16 Jun 2025 06:33:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1750080790; x=1750685590; 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=CrvRU9dPA3iyQCatW33yYrWOV+Y1tKJvNMOa8l/wSkM=; b=Nq9sAS0tjhVHWqo34HkdDipyx7QRBX9Hh/Sb7V/3SBXdKJMbruVPEdw74m2LoGf8FR ubj2QJk8x29w4zmu3rmm57sI28gMt9Bj3avvsFW0saXxNnMpbd8+p5pOPRkNLMo5Pag/ tPAI+BHjBpx4GbZIIxxquu1TUTGRDk6nqehNc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750080790; x=1750685590; 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=CrvRU9dPA3iyQCatW33yYrWOV+Y1tKJvNMOa8l/wSkM=; b=qcC93ARMx7tWkXYUQq6eLZXJEOj9B+nedOJIJPrFzMzyG3gJFGOwf83gxkOAuUxJk2 eBKrFdWVHg7AGSTiYLe4r5p6/eZrV6gfBnqRwmsOvK2BMXxJlOB89iIJ78CAnso+Qd3B ggnST7TU//3+aA2me4m40xXzneQVVqKQlIwZ/LWo8FgVhFUWSWdDdaueX9hwzik7EzgZ 9hny3B/o/c01SFHMq5gQspqZEiF8ButcdVUCUVmesBlOu47+vaUdRvRAUAFlXh3gvmkx C7fnOkWufuPVx7bVgf3kDufvYX2+c//PVcTz0zzbxPLvqoSD1L6SUDfk6zbEHHkrr6WE oung== X-Forwarded-Encrypted: i=1; AJvYcCX0sQpuNYMaopnVKB6MF69tu2MKjXwIKpxwPf+8xtKUE9lqbY5dgbtZapvtqOpvGQJj9CzW5ISPJJU5TFk=@vger.kernel.org X-Gm-Message-State: AOJu0YzTKOI2DbNwnu1cFj7U81d6u11qHmoOH7juRq972wqcNMh7AIwL 1TO4OUy79/SoG0Bx9TMlTiEK7RdN7FQxfcSCF3zGhoY8y1IzmDM84cah8ayjgNUeYQ== X-Gm-Gg: ASbGnct1JQoXz4bsjVKjcVLk1DUVGQUGhFasNXhBXEq+YWoWcXOQzdXRWLmI5NczoHK OqsQs0WUmPfSZyXnkqp8BvA/Iw3MpRCM23HAngtFjBfMapLzpIeqvdTazcVUQjTzXbdBQeDRcAt dAR7Yl0Z7bJzoncYn5fpgZW8SEkm+aOExmJIdgxNsEUEF/graNlGpS2oSMwE5kRJem+h87UU5WQ wCCGVayNg+V8yqW+qRVCVtSV3jpFo/Jhs6CJa0vbkYn0VCZERQICbd2EiVB7ICE9ITilJae0ECU nZaCSmCQ1+naMLxZ+X0tW7mlexjKe6cwC1VVIhjZhs3/MiFDg341zuIwLIPBNh0xahlHP2MVHYJ 9QkOlMLnDxPURqFS1g/VH/88X8ws+mbCmcCF/TZHVDRvyh3sTqw8c0Dvi+w== X-Google-Smtp-Source: AGHT+IHbDTcXrvlPhvHImcuxrvjv5KF3hnVki+pNJuztPFo+tXtICwF+2GhVHRAJEkGScMRhGJ4DLw== X-Received: by 2002:a17:906:794a:b0:ad4:fd7f:a4 with SMTP id a640c23a62f3a-adfad4f42eemr816606366b.47.1750080790329; Mon, 16 Jun 2025 06:33:10 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (244.175.141.34.bc.googleusercontent.com. [34.141.175.244]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-608b4a94ce7sm6036664a12.58.2025.06.16.06.33.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jun 2025 06:33:09 -0700 (PDT) From: Andrei Kuchynski To: Heikki Krogerus , Dmitry Baryshkov , Abhishek Pandit-Subedi , Jameson Thies , Benson Leung , Tzung-Bi Shih Cc: Greg Kroah-Hartman , Guenter Roeck , Pooja Katiyar , Badhri Jagan Sridharan , RD Babiera , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, Andrei Kuchynski Subject: [PATCH 01/10] usb: typec: Add alt_mode_override field to port property Date: Mon, 16 Jun 2025 13:31:38 +0000 Message-ID: <20250616133147.1835939-2-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog In-Reply-To: <20250616133147.1835939-1-akuchynski@chromium.org> References: <20250616133147.1835939-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" This new field in the port properties dictates whether the Platform Policy Manager (PPM) allows the OS Policy Manager (OPM) to change the currently active, negotiated alternate mode. Signed-off-by: Andrei Kuchynski --- drivers/usb/typec/class.c | 14 +++++++++++--- drivers/usb/typec/class.h | 2 ++ include/linux/usb/typec.h | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 67a533e35150..a72325ff099a 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -459,9 +459,16 @@ static umode_t typec_altmode_attr_is_visible(struct ko= bject *kobj, struct typec_altmode *adev =3D to_typec_altmode(kobj_to_dev(kobj)); =20 if (attr =3D=3D &dev_attr_active.attr) - if (!is_typec_port(adev->dev.parent) && - (!adev->ops || !adev->ops->activate)) - return 0444; + if (!is_typec_port(adev->dev.parent)) { + struct typec_partner *partner =3D + to_typec_partner(adev->dev.parent); + struct typec_port *port =3D + to_typec_port(partner->dev.parent); + + if (!port->alt_mode_override || !adev->ops || + !adev->ops->activate) + return 0444; + } =20 return attr->mode; } @@ -2681,6 +2688,7 @@ struct typec_port *typec_register_port(struct device = *parent, } =20 port->pd =3D cap->pd; + port->alt_mode_override =3D cap->alt_mode_override; =20 ret =3D device_add(&port->dev); if (ret) { diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h index db2fe96c48ff..f05d9201c233 100644 --- a/drivers/usb/typec/class.h +++ b/drivers/usb/typec/class.h @@ -80,6 +80,8 @@ struct typec_port { */ struct device *usb2_dev; struct device *usb3_dev; + + bool alt_mode_override; }; =20 #define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev) diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index 252af3f77039..6e09e68788dd 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -304,6 +304,7 @@ struct typec_capability { enum typec_accessory accessory[TYPEC_MAX_ACCESSORY]; unsigned int orientation_aware:1; u8 usb_capability; + bool alt_mode_override; =20 struct fwnode_handle *fwnode; void *driver_data; --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Thu Oct 9 20:24:10 2025 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 97FAB2877DB for ; Mon, 16 Jun 2025 13:33:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080795; cv=none; b=b9OUETeMf0QzXRERoq/o4WOnvAFE6n6ysglSyQFn3Jap/lSdn306Wj/SsrbEotmUvAY5znCJKhSvZ+SJn2urDxr3uOPvB99K0mBZm2/iiRW5Iuq/f9RtcPhM6Ru294AstjZb++byNPZu7gWG3DMgNAOynq1eghChuNVzQuahyKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080795; c=relaxed/simple; bh=Zr0by00gzuLqU/8noVtlHXiuZTGL3C9qQp8UPrlTVhI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jTIODMMfOIPZhN62f/D580GIZrj3YqEfkfVOfmaLTOjuS9Z7pn3ji2VcdFJAOQfRfVpy6wBhUdUaElHUL5VlWyhd3rzdT+EdUwlBW5Suqe8DrKOspNdVIcFKiV5oYDlVNifOnofPHQMV676Qa6T1cq3NZ6Ufg55iWxYxmynkCp8= 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=VfoyGgc1; arc=none smtp.client-ip=209.85.208.42 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="VfoyGgc1" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-6097d144923so497253a12.1 for ; Mon, 16 Jun 2025 06:33:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1750080792; x=1750685592; 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=feDBvsCRg//C7YMonBlbgFAdDrxVjfxFzxxt26XS52w=; b=VfoyGgc1ag2hNEN0A+rWuPryMy2nRVOtm0KMNFSApU9jD38nzEfw+mSDyIkBIKsUjm Sz12FpO9L8M51ntJ//H3Te1TBps1xtc3U2pgKWcBcTM/Ci0wwsI8iEYbYqv8lQJYlJZz kZkB/vOThTJaK4BprrnKADL70eoVgYWqPThx0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750080792; x=1750685592; 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=feDBvsCRg//C7YMonBlbgFAdDrxVjfxFzxxt26XS52w=; b=jcQ9PS3JsRr71JRxNFExRhxQPuzUHlqaSATJ53jHM3aTSruu6CHp73ynWQTIe2NCod 5nRlxAF5NKEnwSdfSoV170TIUDJqEOiH1Mn3QzaCzu1kxZcY9N2bokGccx7GgJIhOaQ9 afhJkjPMcELDM6pqSTSPplxRBh1ssW9yddg3+GnSaDmFCxD/uzz1Dh6k6nukLarVIEP5 LCVuIXipUMZTgxSf4jGpgAG347qBdCVVd4dp9+VLh+nPN6QuTzkcvBSPoE0DwqGO9/gD lsY4nE5E6DHytI/OZnWOvtaXZtR8vftDdFuCaeOHlrSPL7RS02X58/XXm9ytuW94WiJV 8xLQ== X-Forwarded-Encrypted: i=1; AJvYcCU40SdAuYX5Y6Czx4QOYnFPfJQnTs+JpTuR6+mekJOEDOmeRDaqRY+GXXa6GbLaA0Yfjx68McGpdiKwsTs=@vger.kernel.org X-Gm-Message-State: AOJu0YzzOYt2yMrW2q9u20+iRx44uQht6uBAvGKP7TNyqp3UX3vYbuNS BO5FB8JdqAj4nCBRpKh6Kdoka+5kdfOyXhFY6tdqC7Kk0hxAiHIU8l3pZ5RomdWfMA== X-Gm-Gg: ASbGncul1taplFsxBkNCLa1gyyg2KB5V6bkDBA3JAyp/v0fMyP7K19TJfUuZW7Iv7lg HUrGM4wFVMuIBw8fjqCkTmhWsFP6RquxrZYNZ9pnkQRzL8VxPE3+69RB52pdube9iTetK6UKeew 5Gkr98eJL7ndsX8cdFW0BdETvlwnj9FLo9HsZA+7f0X0osLb5LGhC+h0naXYq3PyRTa3AOztElj M2yfusIsrUj8IAHZpTbOaT7SeC0oLSg76vPu5tZVVKdDCbBm13bKhgXe/XektYLoBDApTYMtVAo 03yOLjw/H26hsM+taA88eSd9zsoa6lzkGNp/QbHycE7vGSaLxtMLXI92utC3lLj4poY3G6v3OpX bzFMSfgD3U1IIsliU2PPudbHFWtz7+Rmf82O//fRPuHz+AKYPLjX4vSUomsuFkb73hoHV X-Google-Smtp-Source: AGHT+IHjZH5bwhZ1Xd6IbpKopcl9AXhlpygAbGOG0etGiJyiXrgesebapu3fw6k5UbnpFpkYC/Jj0w== X-Received: by 2002:a05:6402:5113:b0:607:ea4e:251c with SMTP id 4fb4d7f45d1cf-608ce4c0fccmr8482617a12.8.1750080791872; Mon, 16 Jun 2025 06:33:11 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (244.175.141.34.bc.googleusercontent.com. [34.141.175.244]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-608b4a94ce7sm6036664a12.58.2025.06.16.06.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jun 2025 06:33:11 -0700 (PDT) From: Andrei Kuchynski To: Heikki Krogerus , Dmitry Baryshkov , Abhishek Pandit-Subedi , Jameson Thies , Benson Leung , Tzung-Bi Shih Cc: Greg Kroah-Hartman , Guenter Roeck , Pooja Katiyar , Badhri Jagan Sridharan , RD Babiera , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, Andrei Kuchynski Subject: [PATCH 02/10] platform/chrome: cros_ec_typec: Set alt_mode_override flag Date: Mon, 16 Jun 2025 13:31:39 +0000 Message-ID: <20250616133147.1835939-3-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog In-Reply-To: <20250616133147.1835939-1-akuchynski@chromium.org> References: <20250616133147.1835939-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" This flag specifies that the Embedded Controller (EC) must receive explicit approval from the Application Processor (AP) before initiating Type-C alternate modes or USB4 mode. Signed-off-by: Andrei Kuchynski --- drivers/platform/chrome/cros_ec_typec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chr= ome/cros_ec_typec.c index 7678e3d05fd3..3aed429fde03 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -408,6 +408,7 @@ static int cros_typec_init_ports(struct cros_typec_data= *typec) =20 cap->driver_data =3D cros_port; cap->ops =3D &cros_typec_usb_mode_ops; + cap->alt_mode_override =3D typec->ap_driven_altmode; =20 cros_port->port =3D typec_register_port(dev, cap); if (IS_ERR(cros_port->port)) { --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Thu Oct 9 20:24:10 2025 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 DD4102877FF for ; Mon, 16 Jun 2025 13:33:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080797; cv=none; b=hGoy45L9xwUICsEjOI84Q/RK7iaBq0OUYgdaT0f6uujylK2LTpdKjL/Mps0v3TyzmkqYbWBnFxtjn6BLICcAKO9NDUS/bK9RQQBgqkRlEtWBdzGoHkNP4OONmTavapb92mHBMYPtlkd17EHxxvR0J81+0JQlj7usmuYCKwFL8AQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080797; c=relaxed/simple; bh=0xC0NBWhh+5FZ6EevG3lvJaPJC0xaC2CtQxodewDrnc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZUpOpjbO7jIprbqk4TdWjzaLCbdt2fd/qClHRKRWvh0CVDjl0tNnG9j8+gVuQeQv4nIlbcU4ZhwnFcQneCjTHv41OtPKKGLBIEqfywodwJF1qJ4jbzAlNEyK99eUnryqNoNifmSXyQMYoxDjWP1r0Sf+yOtPYd18cPM2zIqsiBY= 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=haZhNVVW; arc=none smtp.client-ip=209.85.208.41 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="haZhNVVW" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-60789b450ceso8807610a12.2 for ; Mon, 16 Jun 2025 06:33:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1750080793; x=1750685593; 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=DCYACXhfENDI28fFqwzO6WcqXr+cZJHgaCmuMhA1C2o=; b=haZhNVVWWvs2sRVX4sdjaQN8lQx96TpHZ7V715IZSr9SWp1cpVmPPKvOqsao9zLTJc ma4N01Caa4nG9jGh0QckyBkcJNPc/CN6Zq4n/1Qu0B7hwoNq4ApKdp1HL0GSfgsEWmzS 9vbxeE2nOJabxahiqbDOuV/ED1YARdXrhjoJs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750080793; x=1750685593; 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=DCYACXhfENDI28fFqwzO6WcqXr+cZJHgaCmuMhA1C2o=; b=KO0LEI1j9PluWEFybj1Bp5VyebnefVm7cXxQ4xK2JV/dec4uv96V9x0NkWGJ4TcDFU wI73KN5ctlb/8fs+TrpibuNHrXbotakWouXvKsDyYfSael6mVx62mh0tYbjgWz5QRTVW w2TxcsbIJ0UtcZdtkq5s/LyFEf2u20mVFCew9cCJ0Qe83dkZ3J9UXXkIc+I44FFO3Omh nNr5Yhyk9hxIZ3MKJ9Jk0ZIsx1jh+BBqMadm/JQuPAfXYi4mzpxRs7homACp7Pxv3xUk IdB4r96RS8Ro2TrTB7ea0gXxD05zR5BRVQDD4ETM2SeuESJ8uhAYQ5oYNOj1IqV7htTQ rTUg== X-Forwarded-Encrypted: i=1; AJvYcCXZZp1TGF144gqdeb7VRrFM2NuDHdprlEdtu4ewzdCpTG3Ffo0XZERgNh6og17RYdWw5aPdZwAL51rv6HQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywbs5oD53C8mAF7shDtUC1PnlWvAgI0CmeecJfvBmeLBOg7e9d7 DUzS1p/rnAYzf2J8xtUQmEfUPmmVrdls+2/+9VRE1aBOVkq6xPllZmh7CWhS81YHmQ== X-Gm-Gg: ASbGncveMLxvpyhRoZnusrkG3x54BASgFpUztgfMI347WxFf2RtCovIzQa6W9hmRO+Q qrAifNzAiYkuF0lKWbdV7d4rY20KVb4C6h+ixYRESEIjlgi3V8VDsOW7kDnGtztTa02ahJ9alyK RUuHbCXVv/XZgLqP0AnpKOQ89R3ziPkxYR3ZmKiiCmVH9r9X2Nxvk9qYlK0JkOf6W1aTV8nib1W siy6AKyBf4Jy8xYrItXJhDEv+yfAIpjvgkKJFJtXcJU6vC0b6mj/5Z5+fjpRQHqm0yDB9K183g9 TK1IoYZEvlZENdY/5sHrL4+ENS4MWvTjMp5E54/eDuGpkGmntNbNEPt2U2n3jM/fteDwHdj3B2/ tcJbMt/pJefkRbnzByAJ6MXPPDbdTpz2ujsY+l58sbU9L/dUIagr1UxiU7Q== X-Google-Smtp-Source: AGHT+IHEB1jBPDHClH0iincBHttzHTsFdApFe/gtRaP+clRmz4tP9oguLOHtjZhuypGZtB3dDT6wTQ== X-Received: by 2002:a05:6402:51d1:b0:608:50ab:7e38 with SMTP id 4fb4d7f45d1cf-608d08f7932mr8236948a12.14.1750080793177; Mon, 16 Jun 2025 06:33:13 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (244.175.141.34.bc.googleusercontent.com. [34.141.175.244]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-608b4a94ce7sm6036664a12.58.2025.06.16.06.33.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jun 2025 06:33:12 -0700 (PDT) From: Andrei Kuchynski To: Heikki Krogerus , Dmitry Baryshkov , Abhishek Pandit-Subedi , Jameson Thies , Benson Leung , Tzung-Bi Shih Cc: Greg Kroah-Hartman , Guenter Roeck , Pooja Katiyar , Badhri Jagan Sridharan , RD Babiera , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, Andrei Kuchynski Subject: [PATCH 03/10] usb: typec: ucsi: Set alt_mode_override flag Date: Mon, 16 Jun 2025 13:31:40 +0000 Message-ID: <20250616133147.1835939-4-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog In-Reply-To: <20250616133147.1835939-1-akuchynski@chromium.org> References: <20250616133147.1835939-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" This flag indicates that the PPM allows the OPM to change the currently negotiated alternate mode using the SET_NEW_CAM command. Signed-off-by: Andrei Kuchynski --- drivers/usb/typec/ucsi/ucsi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 01ce858a1a2b..1372becaec82 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -1616,6 +1616,8 @@ static int ucsi_register_port(struct ucsi *ucsi, stru= ct ucsi_connector *con) =20 cap->driver_data =3D con; cap->ops =3D &ucsi_ops; + cap->alt_mode_override =3D + !!(con->ucsi->cap.features & UCSI_CAP_ALT_MODE_OVERRIDE); =20 if (ucsi->ops->update_connector) ucsi->ops->update_connector(con); --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Thu Oct 9 20:24:10 2025 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 84B492DBF77 for ; Mon, 16 Jun 2025 13:33:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080799; cv=none; b=LpMSufjLOAx0bH33mNFgJPnvHjyNT5KWLQYnHwXTIB/fadv2Ie21W6Mlrlqjh6BwmVyJS2KptrUeZb5u146BX7TnMHs6yDSUTobF9YK/tpcI9HD/qhAWjA2aFgzBZR7mVcAv8P2zxFGYX9+p0g6p3kNAhbBTnz9ZrQ9D3JlpCqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080799; c=relaxed/simple; bh=CTkb+Zlmdex8XBt0jVOO6st2izRqSZRpU7vG9r6yMUM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X7myNO4YxYy1AI6NQ1ZCuvUsY8HxjvAMyj8twMMxxOeBJYAEzq3Dx138ROXFdVsJSHyaW8pqFg23rAlQ/ZoJ/SuKP62mqRkM6cPh+pZGdAerj4jf36vXx3wOKbEZPCngRWMuADkwPndRsGDcD3iGLc0kOz1FVvyS07t76Pwvt6A= 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=mq+BB86u; arc=none smtp.client-ip=209.85.208.42 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="mq+BB86u" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-606b6dbe316so9582451a12.3 for ; Mon, 16 Jun 2025 06:33:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1750080796; x=1750685596; 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=vDh9sojrOp84Y06qtG9e+QA6xkN553TiG7S+NM2mdjE=; b=mq+BB86uhOunM7FEk3Nd2SS8zUDhs8NK+WvgWTP4sdKnr6gr9wZ268lOtFRzKxbLTo Hojv+6qZ8RXz6KDo7q+Ze6tc9IpAtLEFS9lU4pGJwp4pFGJjyexg0igEAmG14vzNmkho Cipdz6cP2JkugCZUTO2E665g6Wbx0yUox+jLQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750080796; x=1750685596; 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=vDh9sojrOp84Y06qtG9e+QA6xkN553TiG7S+NM2mdjE=; b=Ei2ZvXiMt+kz842vrW/RIzZ33qidrJU6YWAXy7UTKLF5BGULPlKmPrQ/XTaFaC6hB7 94wiE9yhjWRWm3Ig5w1t5Ljf7xLsqgx/TPtVVLMWyRHYKTLbiy3ei7T+JzYvUvgjl0WZ gkMjkGQ9SDzO/21dPDSOjqvjEq7eVFVTGMHY3V14uigzkeNnndDQppU2pfyLX360dH30 vbbUjw5tbo06GHO+BVIp10iiVy66+E3fO8RIVm/nL6y25nnFIRWNgTOEOSXTNj6Gr/VC hxVu7Iw5ofjBwjWmhoLWLIdpJbzZAvQOz1tCQHkYF6a8rz5Z7SU6LqZZTi8W9hCFZEaF k8PQ== X-Forwarded-Encrypted: i=1; AJvYcCWnnEmx2sprlWI41r2oI9MdZR5BjjQbDg8OokGqa29BIAaC6hv1EeRzVaUB3svyfvqY3vODWipJUCXGJKw=@vger.kernel.org X-Gm-Message-State: AOJu0Yyf/VdORtzlfzZMnTuRAruAg6BqKmDFsZahahVzj8YCSVsYn8Rr qbAk6rrZezFVbNJ3STm6p5zOedl90X32OWdSo2hRTHhhFtAD2PYKEmRNEV3YWf+c1Q== X-Gm-Gg: ASbGnctSRkQUVoJhR8Ybz7+9vzN7q2NmvAMdn0mJe1jM0MlsCbU+G6kHlnrrHg2bkUv AnVxb53E93kzNTnJiiLeP6m3xIdwBiKwBaPJ+huhpYBxMiR7orcIL54hJ01lVhORT9iK5pG5pzw FtKL+376gyUp04n1n3mSQEaxqYvgE0h4JkXx28mVGp7qfWFjJQXffj2BuMFCpEpQHz0Fm6aqaQP fivOqbWM/7npT0CRUYg6oJUHhL4l/z+hz3YNkcmWWBwy1PK6ot9foZ5tfwPc82EnMTg+jSeuQuR FTm+cqRojTtVJtSL3/VRMYkesJgcqmALr0SrnyeH1DJc5xFPee9uchRmPlozDxbiCLexU0rUnw3 AQ0TW2V4qLeMygelEU9g0MxhysegYfU6EObZOcCt8QlO3D3bUxmsc9mWmDA== X-Google-Smtp-Source: AGHT+IGv/AOmT6GEhQ7oUlSng8rP/zfkQJfNKBJnimzO204DsmsQDo7srREO5LYOs54/Dw1yISBEwQ== X-Received: by 2002:a05:6402:909:b0:607:19a6:9f1d with SMTP id 4fb4d7f45d1cf-608d08aa3d4mr7890265a12.14.1750080795674; Mon, 16 Jun 2025 06:33:15 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (244.175.141.34.bc.googleusercontent.com. [34.141.175.244]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-608b4a94ce7sm6036664a12.58.2025.06.16.06.33.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jun 2025 06:33:15 -0700 (PDT) From: Andrei Kuchynski To: Heikki Krogerus , Dmitry Baryshkov , Abhishek Pandit-Subedi , Jameson Thies , Benson Leung , Tzung-Bi Shih Cc: Greg Kroah-Hartman , Guenter Roeck , Pooja Katiyar , Badhri Jagan Sridharan , RD Babiera , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, Andrei Kuchynski Subject: [PATCH 04/10] usb: typec: Expose alternate mode priorities via sysfs Date: Mon, 16 Jun 2025 13:31:41 +0000 Message-ID: <20250616133147.1835939-5-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog In-Reply-To: <20250616133147.1835939-1-akuchynski@chromium.org> References: <20250616133147.1835939-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" This sysfs attribute specifies the preferred order for enabling DisplayPort alt-mode, Thunderbolt alt-mode, and USB4 mode. Signed-off-by: Andrei Kuchynski --- Documentation/ABI/testing/sysfs-class-typec | 17 ++++ drivers/usb/typec/Makefile | 2 +- drivers/usb/typec/class.c | 26 ++++++ drivers/usb/typec/class.h | 2 + drivers/usb/typec/mode_selection.c | 93 +++++++++++++++++++++ drivers/usb/typec/mode_selection.h | 5 ++ include/linux/usb/typec_altmode.h | 7 ++ 7 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 drivers/usb/typec/mode_selection.c create mode 100644 drivers/usb/typec/mode_selection.h diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/AB= I/testing/sysfs-class-typec index 38e101c17a00..46eee82042ab 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -162,6 +162,23 @@ Description: Lists the supported USB Modes. The defaul= t USB mode that is used - usb3 (USB 3.2) - usb4 (USB4) =20 +What: /sys/class/typec//altmode_priorities +Date: June 2025 +Contact: Andrei Kuchynski +Description: Lists the alternate modes supported by the port and their + priorities. The priority setting determines the order in which + Displayport alt-mode, Thunderbolt alt-mode and USB4 mode will be + activated, indicating the preferred selection sequence. A value of -1 + disables automatic entry into a specific mode, while lower numbers + indicate higher priority. The default priorities can be modified by + assigning new values. Modes without explicitly set values default to -1, + effectively disabling them. + + Example values: + - "USB4=3D0 TBT=3D1 DP=3D2" + - "USB4=3D-1 TBT=3D0" + - "DP=3D-1 USB4=3D-1 TBT=3D-1" + USB Type-C partner devices (eg. /sys/class/typec/port0-partner/) =20 What: /sys/class/typec/-partner/accessory_mode diff --git a/drivers/usb/typec/Makefile b/drivers/usb/typec/Makefile index 7a368fea61bc..8a6a1c663eb6 100644 --- a/drivers/usb/typec/Makefile +++ b/drivers/usb/typec/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_TYPEC) +=3D typec.o -typec-y :=3D class.o mux.o bus.o pd.o retimer.o +typec-y :=3D class.o mux.o bus.o pd.o retimer.o mode_selection.o typec-$(CONFIG_ACPI) +=3D port-mapper.o obj-$(CONFIG_TYPEC) +=3D altmodes/ obj-$(CONFIG_TYPEC_TCPM) +=3D tcpm/ diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index a72325ff099a..726fc0411c44 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -19,6 +19,7 @@ #include "bus.h" #include "class.h" #include "pd.h" +#include "mode_selection.h" =20 static DEFINE_IDA(typec_index_ida); =20 @@ -1942,6 +1943,25 @@ static ssize_t orientation_show(struct device *dev, } static DEVICE_ATTR_RO(orientation); =20 +static ssize_t altmode_priorities_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + struct typec_port *port =3D to_typec_port(dev); + int ret =3D typec_mode_priorities_set(port, buf); + + return ret ? : size; +} + +static ssize_t altmode_priorities_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct typec_port *port =3D to_typec_port(dev); + + return typec_mode_priorities_get(port, buf); +} +static DEVICE_ATTR_RW(altmode_priorities); + static struct attribute *typec_attrs[] =3D { &dev_attr_data_role.attr, &dev_attr_power_operation_mode.attr, @@ -1954,6 +1974,7 @@ static struct attribute *typec_attrs[] =3D { &dev_attr_port_type.attr, &dev_attr_orientation.attr, &dev_attr_usb_capability.attr, + &dev_attr_altmode_priorities.attr, NULL, }; =20 @@ -1992,6 +2013,9 @@ static umode_t typec_attr_is_visible(struct kobject *= kobj, return 0; if (!port->ops || !port->ops->default_usb_mode_set) return 0444; + } else if (attr =3D=3D &dev_attr_altmode_priorities.attr) { + if (!port->alt_mode_override) + return 0; } =20 return attr->mode; @@ -2652,6 +2676,8 @@ struct typec_port *typec_register_port(struct device = *parent, else if (cap->usb_capability & USB_CAPABILITY_USB2) port->usb_mode =3D USB_MODE_USB2; =20 + typec_mode_priorities_set(port, NULL); + device_initialize(&port->dev); port->dev.class =3D &typec_class; port->dev.parent =3D parent; diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h index f05d9201c233..dffe5ef03bc6 100644 --- a/drivers/usb/typec/class.h +++ b/drivers/usb/typec/class.h @@ -5,6 +5,7 @@ =20 #include #include +#include =20 struct typec_mux; struct typec_switch; @@ -82,6 +83,7 @@ struct typec_port { struct device *usb3_dev; =20 bool alt_mode_override; + int altmode_priorities[TYPEC_ALTMODE_MAX]; }; =20 #define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev) diff --git a/drivers/usb/typec/mode_selection.c b/drivers/usb/typec/mode_se= lection.c new file mode 100644 index 000000000000..d984c79eef45 --- /dev/null +++ b/drivers/usb/typec/mode_selection.c @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2025 Google LLC. + */ + +#include +#include +#include "class.h" + +#define MODE_PRIORITY_DISABLED -1 + +static const char * const altmode_names[] =3D { + [TYPEC_ALTMODE_DP] =3D "DP", + [TYPEC_ALTMODE_TBT] =3D "TBT", + [TYPEC_ALTMODE_USB4] =3D "USB4", +}; +static const char * const default_priorities =3D "USB4=3D0 TBT=3D1 DP=3D2"; + +/* -----------------------------------------------------------------------= --- */ +/* port 'altmode_priorities' attribute */ + +int typec_mode_priorities_set(struct typec_port *port, + const char *user_priorities) +{ + int priorities[TYPEC_ALTMODE_MAX]; + const char *str_priority =3D user_priorities ? : default_priorities; + char *buf, *buf_free; + int ret =3D -EINVAL; + char *str_name; + int i; + + buf =3D vmalloc(strlen(str_priority) + 1); + if (!buf) + return -ENOMEM; + strscpy(buf, str_priority, strlen(str_priority) + 1); + buf_free =3D buf; + + for (i =3D 0; i < TYPEC_ALTMODE_MAX; i++) + priorities[i] =3D MODE_PRIORITY_DISABLED; + + while ((str_name =3D strsep(&buf, " "))) { + char *str_value =3D strchr(str_name, '=3D'); + int value; + int mode; + + ret =3D -EINVAL; + if (!str_value) + goto parse_exit; + *str_value++ =3D '\0'; + + if (kstrtoint(str_value, 10, &value) || + value < MODE_PRIORITY_DISABLED) + goto parse_exit; + + if (value > MODE_PRIORITY_DISABLED) { + for (i =3D 0; i < TYPEC_ALTMODE_MAX; i++) + if (value =3D=3D priorities[i]) + goto parse_exit; + } + + for (mode =3D 0; mode < TYPEC_ALTMODE_MAX && + strcmp(str_name, altmode_names[mode]);) + mode++; + if (mode =3D=3D TYPEC_ALTMODE_MAX || + priorities[mode] !=3D MODE_PRIORITY_DISABLED) + goto parse_exit; + + priorities[mode] =3D value; + ret =3D 0; + } + + for (i =3D 0; i < TYPEC_ALTMODE_MAX; i++) + port->altmode_priorities[i] =3D priorities[i]; + +parse_exit: + vfree(buf_free); + + return ret; +} + +int typec_mode_priorities_get(struct typec_port *port, char *buf) +{ + ssize_t count =3D 0; + int i; + + for (i =3D 0; i < TYPEC_ALTMODE_MAX; i++) { + if (i !=3D TYPEC_ALTMODE_USB4 || + port->cap->usb_capability & USB_CAPABILITY_USB4) + count +=3D sysfs_emit_at(buf, count, "%s=3D%d ", + altmode_names[i], port->altmode_priorities[i]); + } + return count + sysfs_emit_at(buf, count, "\n"); +} diff --git a/drivers/usb/typec/mode_selection.h b/drivers/usb/typec/mode_se= lection.h new file mode 100644 index 000000000000..643f04f48343 --- /dev/null +++ b/drivers/usb/typec/mode_selection.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +int typec_mode_priorities_set(struct typec_port *port, + const char *user_priorities); +int typec_mode_priorities_get(struct typec_port *port, char *buf); diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_al= tmode.h index b3c0866ea70f..7ca2040ee1e4 100644 --- a/include/linux/usb/typec_altmode.h +++ b/include/linux/usb/typec_altmode.h @@ -145,6 +145,13 @@ enum { =20 #define TYPEC_MODAL_STATE(_state_) ((_state_) + TYPEC_STATE_MODAL) =20 +enum { + TYPEC_ALTMODE_DP =3D 0, + TYPEC_ALTMODE_TBT, + TYPEC_ALTMODE_USB4, + TYPEC_ALTMODE_MAX, +}; + struct typec_altmode *typec_altmode_get_plug(struct typec_altmode *altmode, enum typec_plug_index index); void typec_altmode_put_plug(struct typec_altmode *plug); --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Thu Oct 9 20:24:10 2025 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 6A0462DBF71 for ; Mon, 16 Jun 2025 13:33:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080802; cv=none; b=nve/e/zQzJR2Zac6LEBEmk/OWQbDHo4G0rICGbVrLE+GzaLjGK1LXpDEuuT73Lh3yeCOmrPKp2SfrGmh4BflmWQFBevpxPSYyC8oCE02Ahb0dSPvSK98Z5wySww1iEerpn+WTytaTD/rkVfHNjNvrHcOnA6E+2NVK9evqUBYsSQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080802; c=relaxed/simple; bh=3/DRUHcMTi2y3mpOqN273fqCN7TXxAZm6Dg+1+doKTo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ESsYnOmZeXKUy9Q9abKIfHCWP+1UXB1Sw77BNb/xZasz8ZA8LU0ZHLvvkSWE74jRX7RECsj5xB0UZ1kRyL1NUxAfvoTV8/tX2p7UMjLi7fWwcsLvCmUtCFgz8qowcBc1ynLazI+52GqS//0D2nC1INFHq2Rgk71/j+o4LPSGtBs= 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=OhYGMn/9; arc=none smtp.client-ip=209.85.208.51 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="OhYGMn/9" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-6097d144923so497512a12.1 for ; Mon, 16 Jun 2025 06:33:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1750080798; x=1750685598; 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=LJ08ykcaUh86luL6nlhAeVkvWPVp9UYwGXyL0gTTMNk=; b=OhYGMn/9cK50w2ys0eROu1jfa6/WwjUJwvlZ08jjwsYjIhza8+D5UVVcx9XVfKYoUo GyLT6lGVONgDP6JLPjPtPH9qPcd2bOkVg4z7KaRwopR8iO+ixMEbuRp61jfRURaGFIeT rF3O4gzEaHNwmEvvxQb4y3I7ehinmyMwcbsSI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750080798; x=1750685598; 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=LJ08ykcaUh86luL6nlhAeVkvWPVp9UYwGXyL0gTTMNk=; b=poz0oH4bw3SYzfE8kbk0aXnVx8XGiSYHkQJNmEguVE589P1FAX3MYtjCrtyNp2Cfhg F7Nqu34GgQAPVSKHc6td4fBzizQrZMKeVMSnho7XJRC0iL6Wcn3DmYawICa4RR+HcBVU JWKbChoLWQiHJyhSY/HwHb1E3iFq3GRqWabPNhNCKL8Mixjwsg84XcOZNm/zm3wDe34C eLFj2SahVqKeWr0U/mVu+DRQuf9aAwwx0mk+7ugN5KnkjXya6qxJMTccVIp2LYKh1+1f PU+n0QLaUrH/QktoqCS43xS2w0D9j39OzZUViuABLzmbieBtaoXltjZMHjL9bBs8NhJL rorA== X-Forwarded-Encrypted: i=1; AJvYcCWdHf6k98haxX+hWJr8zm8BGBQN5/77zCFV5JPxqR42VWCC1iJIOO64wMFf+/b8UFtHD8wAkKN4fQJrYus=@vger.kernel.org X-Gm-Message-State: AOJu0YxZ9vpBSOdxpwi+ym1Ft8mNZ7mHW2E+zQCVhaL8y1WSuOa/Pv1n D3kLHooVBI+UICOKjblqTXd9pOOkM1zfn3B5OoKImNMAti2Kkgc1H0MM+Q8DtBaPmQ== X-Gm-Gg: ASbGncu57SfxAspbQ/G/IuyAJua/xwYuz7Iq3P9SjCtZFYd5uIPlrbmZJLicALt8Plz 3pwo+8lOZW+6gDJWxaLS/tISqFaVh1s6FkWKGkV4b3ZIlXypcQUEaiGEx57mfUtegj2djxRp3yF O/1q3/YosHsQdpcSjhjOT3BV44SHXHZ6d0V60/n5zsX4rIVXgK407CCQemhaT9nxecOaqV3DcAL 3RPLS2R58Y78qOFEOTpBWzBz8RyzSGzegUY+QXedJ+8CNDg+mkVO6APhdlHTSe9Fs8o9VznKt7t MoKejprH6UFxhNtjT/gr/dZ8Y0pC+XcVG8h1I3eWseUwdj77i18gnApD1t4bSgMrOpDvX3rbmo/ PVeO6JDEzjLBw9jjcIGHIwYEhryoiIkp2Iq/SO71ygmH5JFRHBRZ8XRIlCbN/6YEbjQhU X-Google-Smtp-Source: AGHT+IF6GKFag0i4Lv/O+v/7mDdJI4fryPv5+oukAaxB/RbyOwFkxmlwO5un2SAx2VKkhO7cXQoPzw== X-Received: by 2002:a05:6402:13d0:b0:601:9afe:8da9 with SMTP id 4fb4d7f45d1cf-608ce59a873mr7840208a12.11.1750080797505; Mon, 16 Jun 2025 06:33:17 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (244.175.141.34.bc.googleusercontent.com. [34.141.175.244]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-608b4a94ce7sm6036664a12.58.2025.06.16.06.33.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jun 2025 06:33:17 -0700 (PDT) From: Andrei Kuchynski To: Heikki Krogerus , Dmitry Baryshkov , Abhishek Pandit-Subedi , Jameson Thies , Benson Leung , Tzung-Bi Shih Cc: Greg Kroah-Hartman , Guenter Roeck , Pooja Katiyar , Badhri Jagan Sridharan , RD Babiera , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, Andrei Kuchynski Subject: [PATCH 05/10] usb: typec: Implement automated alternate mode selection Date: Mon, 16 Jun 2025 13:31:42 +0000 Message-ID: <20250616133147.1835939-6-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog In-Reply-To: <20250616133147.1835939-1-akuchynski@chromium.org> References: <20250616133147.1835939-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" This commit introduces mode_selection sysfs attribute to control automated alternate mode negotiation. Writing "yes" to this file activates the automated selection process for DisplayPort alt-mode, Thunderbolt alt-mode, and USB4 mode. Conversely, writing "no" will cancel any ongoing selection process and exit the currently active alternate mode. Signed-off-by: Andrei Kuchynski --- Documentation/ABI/testing/sysfs-class-typec | 17 + drivers/usb/typec/class.c | 55 ++- drivers/usb/typec/class.h | 12 + drivers/usb/typec/mode_selection.c | 412 ++++++++++++++++++++ drivers/usb/typec/mode_selection.h | 37 ++ include/linux/usb/pd_vdo.h | 2 + include/linux/usb/typec_altmode.h | 5 + 7 files changed, 537 insertions(+), 3 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/AB= I/testing/sysfs-class-typec index 46eee82042ab..ec205f49964e 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -264,6 +264,23 @@ Description: The USB Modes that the partner device sup= ports. The active mode - usb3 (USB 3.2) - usb4 (USB4) =20 +What: /sys/class/typec/-partner/mode_selection +Date: June 2025 +Contact: Andrei Kuchynski +Description: Lists the partner-supported alternate modes and mode entry + results with the currently entered mode bracketed. If a cable doesn't + support a mode, it's marked as 'nc'. An ellipsis indicates a mode + currently in progress. Automated mode selection is activated by writing + "yes" to the file. Conversely, writing "no" will cancel any ongoing + selection process and exit the currently active mode, if any. + + Example values: + - "DP TBT=3D... USB4=3Dnc": The cable does not support USB4 mode, + The driver is currently attempting to enter Thunderbolt alt-mode. + - "[DP] TBT=3D-EOPNOTSUPP USB4=3D-ETIME": USB4 mode entry failed due to + a timeout, Thunderbolt failed with the result -EOPNOTSUPP, + and DisplayPort is the active alt-mode. + USB Type-C cable devices (eg. /sys/class/typec/port0-cable/) =20 Note: Electronically Marked Cables will have a device also for one cable p= lug diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 726fc0411c44..e8432070b403 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -541,7 +541,7 @@ static void typec_altmode_release(struct device *dev) } =20 const struct device_type typec_altmode_dev_type =3D { - .name =3D "typec_alternate_mode", + .name =3D ALTERNATE_MODE_DEVICE_TYPE_NAME, .groups =3D typec_altmode_groups, .release =3D typec_altmode_release, }; @@ -741,6 +741,34 @@ static ssize_t number_of_alternate_modes_show(struct d= evice *dev, struct device_ } static DEVICE_ATTR_RO(number_of_alternate_modes); =20 +static ssize_t mode_selection_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct typec_partner *partner =3D to_typec_partner(dev); + + return typec_mode_selection_get(partner, buf); +} + +static ssize_t mode_selection_store(struct device *dev, struct device_attr= ibute *attr, + const char *buf, size_t size) +{ + struct typec_partner *partner =3D to_typec_partner(dev); + bool start; + int ret =3D kstrtobool(buf, &start); + + if (ret) + return ret; + + if (start) + ret =3D typec_mode_selection_start(partner); + else + ret =3D typec_mode_selection_reset(partner); + + return ret ? : size; +} +static DEVICE_ATTR_RW(mode_selection); + static struct attribute *typec_partner_attrs[] =3D { &dev_attr_accessory_mode.attr, &dev_attr_supports_usb_power_delivery.attr, @@ -748,6 +776,7 @@ static struct attribute *typec_partner_attrs[] =3D { &dev_attr_type.attr, &dev_attr_usb_mode.attr, &dev_attr_usb_power_delivery_revision.attr, + &dev_attr_mode_selection.attr, NULL }; =20 @@ -772,6 +801,10 @@ static umode_t typec_partner_attr_is_visible(struct ko= bject *kobj, struct attrib if (!get_pd_product_type(kobj_to_dev(kobj))) return 0; =20 + if (attr =3D=3D &dev_attr_mode_selection.attr) + if (!port->alt_mode_override) + return 0444; + return attr->mode; } =20 @@ -850,8 +883,10 @@ int typec_partner_set_identity(struct typec_partner *p= artner) usb_capability |=3D USB_CAPABILITY_USB2; if (devcap & DEV_USB3_CAPABLE) usb_capability |=3D USB_CAPABILITY_USB3; - if (devcap & DEV_USB4_CAPABLE) + if (devcap & DEV_USB4_CAPABLE) { usb_capability |=3D USB_CAPABILITY_USB4; + typec_mode_selection_add_mode(partner, TYPEC_ALTMODE_USB4); + } } else { usb_capability =3D PD_VDO_DFP_HOSTCAP(id->vdo[0]); } @@ -971,7 +1006,12 @@ struct typec_altmode * typec_partner_register_altmode(struct typec_partner *partner, const struct typec_altmode_desc *desc) { - return typec_register_altmode(&partner->dev, desc); + struct typec_altmode *alt =3D typec_register_altmode(&partner->dev, desc); + + if (alt) + typec_mode_selection_add_mode(partner, TYPEC_SVID_TO_ALTMODE(alt->svid)); + + return alt; } EXPORT_SYMBOL_GPL(typec_partner_register_altmode); =20 @@ -1075,6 +1115,8 @@ struct typec_partner *typec_register_partner(struct t= ypec_port *port, typec_partner_link_device(partner, port->usb3_dev); mutex_unlock(&port->partner_link_lock); =20 + typec_mode_selection_create(partner); + return partner; } EXPORT_SYMBOL_GPL(typec_register_partner); @@ -1092,6 +1134,7 @@ void typec_unregister_partner(struct typec_partner *p= artner) if (IS_ERR_OR_NULL(partner)) return; =20 + typec_mode_selection_destroy(partner); port =3D to_typec_port(partner->dev.parent); =20 mutex_lock(&port->partner_link_lock); @@ -1360,6 +1403,7 @@ int typec_cable_set_identity(struct typec_cable *cabl= e) } EXPORT_SYMBOL_GPL(typec_cable_set_identity); =20 +static struct typec_partner *typec_get_partner(struct typec_port *port); /** * typec_register_cable - Register a USB Type-C Cable * @port: The USB Type-C Port the cable is connected to @@ -1374,6 +1418,7 @@ struct typec_cable *typec_register_cable(struct typec= _port *port, struct typec_cable_desc *desc) { struct typec_cable *cable; + struct typec_partner *partner; int ret; =20 cable =3D kzalloc(sizeof(*cable), GFP_KERNEL); @@ -1405,6 +1450,10 @@ struct typec_cable *typec_register_cable(struct type= c_port *port, return ERR_PTR(ret); } =20 + partner =3D typec_get_partner(port); + typec_mode_selection_add_cable(partner, cable); + put_device(&partner->dev); + return cable; } EXPORT_SYMBOL_GPL(typec_register_cable); diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h index dffe5ef03bc6..30e66d283a10 100644 --- a/drivers/usb/typec/class.h +++ b/drivers/usb/typec/class.h @@ -6,6 +6,7 @@ #include #include #include +#include =20 struct typec_mux; struct typec_switch; @@ -27,6 +28,8 @@ struct typec_cable { enum usb_pd_svdm_ver svdm_version; }; =20 +struct mode_selection_state; + struct typec_partner { struct device dev; unsigned int usb_pd:1; @@ -41,6 +44,13 @@ struct typec_partner { =20 struct usb_power_delivery *pd; =20 + struct delayed_work mode_selection_work; + DECLARE_KFIFO(mode_sequence, struct mode_selection_state *, + roundup_pow_of_two(TYPEC_ALTMODE_MAX)); + struct mutex mode_sequence_lock; + struct mode_selection_state *mode_states; + struct mode_selection_state *active_mode; + void (*attach)(struct typec_partner *partner, struct device *dev); void (*deattach)(struct typec_partner *partner, struct device *dev); }; @@ -113,4 +123,6 @@ static inline int typec_link_ports(struct typec_port *c= onnector) { return 0; } static inline void typec_unlink_ports(struct typec_port *connector) { } #endif =20 +#define ALTERNATE_MODE_DEVICE_TYPE_NAME "typec_alternate_mode" + #endif /* __USB_TYPEC_CLASS__ */ diff --git a/drivers/usb/typec/mode_selection.c b/drivers/usb/typec/mode_se= lection.c index d984c79eef45..2bef50226af4 100644 --- a/drivers/usb/typec/mode_selection.c +++ b/drivers/usb/typec/mode_selection.c @@ -5,9 +5,22 @@ =20 #include #include +#include +#include +#include "mode_selection.h" #include "class.h" =20 #define MODE_PRIORITY_DISABLED -1 +#define MODE_SELECTION_NO_RESULT 1 + +static unsigned int mode_selection_timeout =3D 4000; +module_param(mode_selection_timeout, uint, 0644); +MODULE_PARM_DESC(mode_selection_timeout, "The timeout mode entry, ms"); + +static unsigned int mode_selection_delay =3D 1000; +module_param(mode_selection_delay, uint, 0644); +MODULE_PARM_DESC(mode_selection_delay, + "The delay between attempts to enter or exit a mode, ms"); =20 static const char * const altmode_names[] =3D { [TYPEC_ALTMODE_DP] =3D "DP", @@ -16,6 +29,14 @@ static const char * const altmode_names[] =3D { }; static const char * const default_priorities =3D "USB4=3D0 TBT=3D1 DP=3D2"; =20 +struct mode_selection_state { + int mode; + bool enable; + bool cable_capability; + bool enter; + int result; +}; + /* -----------------------------------------------------------------------= --- */ /* port 'altmode_priorities' attribute */ =20 @@ -91,3 +112,394 @@ int typec_mode_priorities_get(struct typec_port *port,= char *buf) } return count + sysfs_emit_at(buf, count, "\n"); } + +/* -----------------------------------------------------------------------= --- */ +/* partner 'mod_selection' attribute */ + +/** + * mode_selection_next() - Process mode selection results and schedule next + * action + * + * This function evaluates the outcome of the previous mode entry or exit + * attempt. Based on this result, it determines the next alternate mode to + * process and schedules `mode_selection_work()` if further actions are + * required. + * + * If the previous mode entry was successful, the mode selection sequence = is + * considered complete for the current cycle. + * + * If the previous mode entry failed, this function schedules + * `mode_selection_work()` to attempt exiting the currently active mode. + * + * If the previous operation was an exit (after a failed entry attempt), + * `mode_selection_next()` then advances the internal list of candidate + * modes to determine the next mode to enter. + */ +static void mode_selection_next( + struct typec_partner *partner, struct mode_selection_state *ms) +{ + if (!ms->result && ms->enter) { + dev_info(&partner->dev, "%s mode entered\n", altmode_names[ms->mode]); + + partner->active_mode =3D ms; + kfifo_reset(&partner->mode_sequence); + } else { + if (ms->result && ms->enter) + dev_err(&partner->dev, "%s mode entry failed: %pe\n", + altmode_names[ms->mode], ERR_PTR(ms->result)); + + if (ms->result !=3D -EBUSY) { + if (ms->enter) + ms->enter =3D false; + else + kfifo_skip(&partner->mode_sequence); + } + + if (!kfifo_is_empty(&partner->mode_sequence)) { + cancel_delayed_work(&partner->mode_selection_work); + schedule_delayed_work(&partner->mode_selection_work, + msecs_to_jiffies(mode_selection_delay)); + } + } +} + +static void mode_selection_complete(struct typec_partner *partner, + const int mode, const int result) +{ + struct mode_selection_state *ms; + + mutex_lock(&partner->mode_sequence_lock); + if (kfifo_peek(&partner->mode_sequence, &ms)) { + if (ms->mode =3D=3D mode) { + ms->result =3D result; + mode_selection_next(partner, ms); + } + } + mutex_unlock(&partner->mode_sequence_lock); +} + +void typec_mode_selection_altmode_complete(struct typec_altmode *alt, + const int result) +{ + mode_selection_complete(to_typec_partner(alt->dev.parent), + TYPEC_SVID_TO_ALTMODE(alt->svid), result); +} +EXPORT_SYMBOL_GPL(typec_mode_selection_altmode_complete); + +void typec_mode_selection_usb4_complete(struct typec_partner *partner, + const int result) +{ + mode_selection_complete(partner, TYPEC_ALTMODE_USB4, result); +} +EXPORT_SYMBOL_GPL(typec_mode_selection_usb4_complete); + +static int mode_selection_activate_altmode(struct device *dev, void *data) +{ + if (!strcmp(dev->type->name, ALTERNATE_MODE_DEVICE_TYPE_NAME)) { + struct typec_altmode *alt =3D to_typec_altmode(dev); + struct mode_selection_state *ms =3D (struct mode_selection_state *)data; + + if (ms->mode =3D=3D TYPEC_SVID_TO_ALTMODE(alt->svid)) { + int result =3D -EOPNOTSUPP; + + if (alt->ops && alt->ops->activate) + result =3D alt->ops->activate(alt, ms->enter ? 1 : 0); + if (ms->enter) + ms->result =3D result; + return 1; + } + } + + return 0; +} + +static void mode_selection_activate_mode(struct typec_partner *partner, + struct mode_selection_state *ms) +{ + dev_info(&partner->dev, "Attempt to %s %s mode\n", + ms->enter ? "enter" : "exit", altmode_names[ms->mode]); + + if (ms->mode =3D=3D TYPEC_ALTMODE_USB4) { + struct typec_port *port =3D to_typec_port(partner->dev.parent); + int result =3D -EOPNOTSUPP; + + if (port->ops && port->ops->enter_usb_mode) + result =3D port->ops->enter_usb_mode(port, + ms->enter ? USB_MODE_USB4 : USB_MODE_NONE); + + if (ms->enter) + ms->result =3D result; + } else { + const int ret =3D device_for_each_child(&partner->dev, ms, + mode_selection_activate_altmode); + if (!ret && ms->enter) + ms->result =3D -ENODEV; + } +} + +/** + * mode_selection_work() - Activate entry into the upcoming mode + * + * This function works in conjunction with `mode_selection_next()`. + * It attempts to activate the next alternate mode in the selection sequen= ce. + * + * If the mode activation (`mode_selection_activate_mode()`) fails, + * `mode_selection_next()` will be called to initiate a new selection cycl= e. + * + * Otherwise, the result is temporarily set to -ETIME, and + * `mode_selection_activate_mode()` is scheduled for a subsequent entry af= ter a + * timeout period. The alternate mode driver is expected to call back with= the + * actual mode entry result. Upon this callback, `mode_selection_next()` w= ill + * determine the subsequent mode and re-schedule mode_selection_work(). + */ +static void mode_selection_work(struct work_struct *work) +{ + struct typec_partner *partner =3D container_of(work, struct typec_partner, + mode_selection_work.work); + struct mode_selection_state *ms; + + mutex_lock(&partner->mode_sequence_lock); + if (kfifo_peek(&partner->mode_sequence, &ms)) { + if (ms->enter && ms->result =3D=3D -ETIME) { + mode_selection_next(partner, ms); + } else { + mode_selection_activate_mode(partner, ms); + + if (!ms->enter || ms->result) + mode_selection_next(partner, ms); + else { + ms->result =3D -ETIME; + schedule_delayed_work(&partner->mode_selection_work, + msecs_to_jiffies(mode_selection_timeout)); + } + } + } + mutex_unlock(&partner->mode_sequence_lock); +} + +static void mode_selection_init(struct typec_partner *partner) +{ + int i; + + for (i =3D 0; i < TYPEC_ALTMODE_MAX; i++) { + partner->mode_states[i].mode =3D i; + partner->mode_states[i].result =3D MODE_SELECTION_NO_RESULT; + } + + kfifo_reset(&partner->mode_sequence); + partner->active_mode =3D NULL; +} + +int typec_mode_selection_create(struct typec_partner *partner) +{ + partner->mode_states =3D vmalloc( + sizeof(struct mode_selection_state) * TYPEC_ALTMODE_MAX); + if (!partner->mode_states) + return -ENOMEM; + + INIT_KFIFO(partner->mode_sequence); + mutex_init(&partner->mode_sequence_lock); + mode_selection_init(partner); + INIT_DELAYED_WORK(&partner->mode_selection_work, mode_selection_work); + + return 0; +} + +void typec_mode_selection_add_mode(struct typec_partner *partner, + const int mode) +{ + struct typec_port *port =3D to_typec_port(partner->dev.parent); + + if (!partner->mode_states) + return; + + if (mode < TYPEC_ALTMODE_MAX) { + if (mode =3D=3D TYPEC_ALTMODE_USB4) { + if (!(port->cap->usb_capability & USB_CAPABILITY_USB4)) + return; + } + partner->mode_states[mode].enable =3D true; + } +} + +void typec_mode_selection_add_cable(struct typec_partner *partner, + struct typec_cable *cable) +{ + const u32 id_header =3D cable->identity->id_header; + const u32 vdo0 =3D cable->identity->vdo[0]; + const u32 vdo1 =3D cable->identity->vdo[1]; + const u32 type =3D PD_IDH_PTYPE(id_header); + const u32 speed =3D VDO_TYPEC_CABLE_SPEED(vdo0); + bool capable_dp =3D true; + bool capable_tbt =3D false; + bool capable_usb4 =3D false; + + if (!partner->mode_states) + return; + + if (type =3D=3D IDH_PTYPE_PCABLE) { + capable_dp =3D (speed > CABLE_USB2_ONLY); + capable_tbt =3D capable_dp; + capable_usb4 =3D capable_dp; + } else if (type =3D=3D IDH_PTYPE_ACABLE) { + const u32 version =3D VDO_TYPEC_CABLE_VERSION(vdo0); + const bool usb4_support =3D VDO_TYPEC_CABLE_USB4_SUPP(vdo1); + const bool modal_support =3D PD_IDH_MODAL_SUPP(id_header); + + capable_dp =3D modal_support; + capable_tbt =3D true; + capable_usb4 =3D (version =3D=3D 3) ? usb4_support : modal_support; + } + + if (capable_dp || capable_tbt || capable_usb4) + dev_info(&partner->dev, "cable capabilities: %s %s %s\n", + capable_dp ? altmode_names[TYPEC_ALTMODE_DP] : "", + capable_tbt ? altmode_names[TYPEC_ALTMODE_TBT] : "", + capable_usb4 ? altmode_names[TYPEC_ALTMODE_USB4] : ""); + partner->mode_states[TYPEC_ALTMODE_DP].cable_capability =3D capable_dp; + partner->mode_states[TYPEC_ALTMODE_TBT].cable_capability =3D capable_tbt; + partner->mode_states[TYPEC_ALTMODE_USB4].cable_capability =3D capable_usb= 4; +} + +static void mode_selection_cancel_work(struct typec_partner *partner) +{ + /* + * mode_sequence_lock provides exclusive access to `mode_sequence` FIFO + * If the FIFO is empty, no further mode selection activities are expected + */ + mutex_lock(&partner->mode_sequence_lock); + kfifo_reset(&partner->mode_sequence); + mutex_unlock(&partner->mode_sequence_lock); + + cancel_delayed_work_sync(&partner->mode_selection_work); +} + +void typec_mode_selection_destroy(struct typec_partner *partner) +{ + if (!partner->mode_states) + return; + + mode_selection_cancel_work(partner); + mutex_destroy(&partner->mode_sequence_lock); + vfree(partner->mode_states); + partner->mode_states =3D NULL; +} + +/** + * typec_mode_selection_start() - Starts the alternate mode selection proc= ess. + * + * This function populates a 'mode_sequence' FIFO with pointers to + * `struct mode_selection_state` instances. The sequence is generated base= d on + * partner/cable capabilities and prioritized according to the port's sett= ings. + */ +int typec_mode_selection_start(struct typec_partner *partner) +{ + struct typec_port *port =3D to_typec_port(partner->dev.parent); + int priorities[TYPEC_ALTMODE_MAX]; + bool pending_mode =3D true; + int i; + + if (!partner->mode_states) + return -ENOMEM; + + mutex_lock(&partner->mode_sequence_lock); + if (!kfifo_is_empty(&partner->mode_sequence)) { + mutex_unlock(&partner->mode_sequence_lock); + return -EINPROGRESS; + } + if (partner->active_mode) { + mutex_unlock(&partner->mode_sequence_lock); + return -EALREADY; + } + + mode_selection_init(partner); + + for (i =3D 0; i < TYPEC_ALTMODE_MAX; i++) { + if (partner->mode_states[i].enable && + partner->mode_states[i].cable_capability) + priorities[i] =3D port->altmode_priorities[i]; + else + priorities[i] =3D MODE_PRIORITY_DISABLED; + } + + while (pending_mode) { + int mode =3D TYPEC_ALTMODE_MAX; + int max_priority =3D INT_MAX; + + for (i =3D 0; i < TYPEC_ALTMODE_MAX; i++) { + if (priorities[i] !=3D MODE_PRIORITY_DISABLED && + priorities[i] < max_priority) { + max_priority =3D priorities[i]; + mode =3D i; + } + } + + if (mode =3D=3D TYPEC_ALTMODE_MAX) + pending_mode =3D false; + else { + partner->mode_states[mode].enter =3D true; + kfifo_put(&partner->mode_sequence, &partner->mode_states[mode]); + priorities[mode] =3D MODE_PRIORITY_DISABLED; + } + } + + if (!kfifo_is_empty(&partner->mode_sequence)) + schedule_delayed_work(&partner->mode_selection_work, 0); + mutex_unlock(&partner->mode_sequence_lock); + + return 0; +} + +int typec_mode_selection_reset(struct typec_partner *partner) +{ + if (!partner->mode_states) + return -ENOMEM; + + mode_selection_cancel_work(partner); + + if (partner->active_mode) { + partner->active_mode->enter =3D false; + mode_selection_activate_mode(partner, partner->active_mode); + } + mode_selection_init(partner); + + return 0; +} + +int typec_mode_selection_get(struct typec_partner *partner, char *buf) +{ + ssize_t count =3D 0; + int i; + struct mode_selection_state *running_ms; + + if (!partner->mode_states) + return -ENOMEM; + + mutex_lock(&partner->mode_sequence_lock); + if (!kfifo_peek(&partner->mode_sequence, &running_ms)) + running_ms =3D NULL; + + for (i =3D 0; i < TYPEC_ALTMODE_MAX; i++) { + struct mode_selection_state *ms =3D &partner->mode_states[i]; + + if (ms->enable) { + if (!ms->cable_capability) + count +=3D sysfs_emit_at(buf, count, "%s=3Dnc ", altmode_names[i]); + else if (ms =3D=3D running_ms) + count +=3D sysfs_emit_at(buf, count, "%s=3D... ", altmode_names[i]); + else if (ms->result =3D=3D MODE_SELECTION_NO_RESULT) + count +=3D sysfs_emit_at(buf, count, "%s ", altmode_names[i]); + else if (ms->result =3D=3D 0) + count +=3D sysfs_emit_at(buf, count, "[%s] ", altmode_names[i]); + else + count +=3D sysfs_emit_at(buf, count, "%s=3D%pe ", altmode_names[i], + ERR_PTR(ms->result)); + } + } + mutex_unlock(&partner->mode_sequence_lock); + + if (count) + count +=3D sysfs_emit_at(buf, count, "\n"); + + return count; +} diff --git a/drivers/usb/typec/mode_selection.h b/drivers/usb/typec/mode_se= lection.h index 643f04f48343..62e92aed76c7 100644 --- a/drivers/usb/typec/mode_selection.h +++ b/drivers/usb/typec/mode_selection.h @@ -1,5 +1,42 @@ /* SPDX-License-Identifier: GPL-2.0 */ =20 +#include +#include + +#define TYPEC_SVID_TO_ALTMODE(svid) \ + (((svid) =3D=3D USB_TYPEC_DP_SID) ? TYPEC_ALTMODE_DP : \ + ((svid) =3D=3D USB_TYPEC_TBT_SID) ? TYPEC_ALTMODE_TBT : TYPEC_ALTMODE_MA= X) + int typec_mode_priorities_set(struct typec_port *port, const char *user_priorities); int typec_mode_priorities_get(struct typec_port *port, char *buf); + +/** + * The mode selection process follows a lifecycle tied to the USB-C partner + * device. The API is designed to first build a set of desired modes and t= hen + * trigger the selection process. The expected sequence of calls is as fol= lows: + * + * Creation and Configuration: + * call typec_mode_selection_create() when the partner device is being set + * up. This allocates resources for the mode selection. + * After creation, call typec_mode_selection_add_mode() and + * typec_mode_selection_add_cable() to define the parameters for the + * selection process. + * + * Execution: + * Call typec_mode_selection_start() to trigger the mode selection. + * Call typec_mode_selection_reset() to prematurely stop the selection + * process and clear any stored results. + * + * Destruction: + * Before destroying a partner, call typec_mode_selection_destroy() + */ +int typec_mode_selection_create(struct typec_partner *partner); +void typec_mode_selection_destroy(struct typec_partner *partner); +int typec_mode_selection_start(struct typec_partner *partner); +int typec_mode_selection_reset(struct typec_partner *partner); +void typec_mode_selection_add_mode(struct typec_partner *partner, + const int mode); +void typec_mode_selection_add_cable(struct typec_partner *partner, + struct typec_cable *cable); +int typec_mode_selection_get(struct typec_partner *partner, char *buf); diff --git a/include/linux/usb/pd_vdo.h b/include/linux/usb/pd_vdo.h index 5c48e8a81403..20bcf37ad634 100644 --- a/include/linux/usb/pd_vdo.h +++ b/include/linux/usb/pd_vdo.h @@ -439,6 +439,8 @@ | (trans) << 11 | (phy) << 10 | (ele) << 9 | (u4) << 8 \ | ((hops) & 0x3) << 6 | (u2) << 5 | (u32) << 4 | (lane) << 3 \ | (iso) << 2 | (gen)) +#define VDO_TYPEC_CABLE_VERSION(vdo) (((vdo) >> 21) & 0x7) +#define VDO_TYPEC_CABLE_USB4_SUPP(vdo) (((vdo) & BIT(8)) =3D=3D ACAB2_USB4= _SUPP) =20 /* * AMA VDO (PD Rev2.0) diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_al= tmode.h index 7ca2040ee1e4..46b0ab2b8f5d 100644 --- a/include/linux/usb/typec_altmode.h +++ b/include/linux/usb/typec_altmode.h @@ -225,4 +225,9 @@ void typec_altmode_unregister_driver(struct typec_altmo= de_driver *drv); module_driver(__typec_altmode_driver, typec_altmode_register_driver, \ typec_altmode_unregister_driver) =20 +void typec_mode_selection_altmode_complete(struct typec_altmode *alt, + const int result); +void typec_mode_selection_usb4_complete(struct typec_partner *partner, + const int result); + #endif /* __USB_TYPEC_ALTMODE_H */ --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Thu Oct 9 20:24:10 2025 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (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 E20A42877FF for ; Mon, 16 Jun 2025 13:33:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080802; cv=none; b=Gzt5QPyFRRyAGUeW5te6uRMZ/giPB5qugcyEXG9bYR0jJ2xGhNOQDFILeDXp3/WzsPR0JVE7v0xvjaMXXqUSEjRV9x6aTitJCYNoELTAZD/uxWS2xxmsYU4QuznRt6W3RMfmWweUq/FMh4MwFzTx+H+4hpPpjM7n5CWJpNdiTfw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080802; c=relaxed/simple; bh=Qd939gkPb0H61tPk2RIMeLDSe6Zyt59w3Ryj4n49L+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bjqV/gB5/I93kLlaEJ5KKNPdcEqN3olCwFhWlOWBjGN7Go6sjRNS+iymtRblnAIKR8gaKSOFscGso/sd5dZn01XOWaopatmA31mgeMFnAN7Al3/LKsxwYpd0Xe7jRFwdycU3AIoZGNHhFDP0jBCFBKZ4jchalgeipp+R5mFf7NQ= 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=L0dMoETu; arc=none smtp.client-ip=209.85.208.46 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="L0dMoETu" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-60780d74bbaso8095100a12.0 for ; Mon, 16 Jun 2025 06:33:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1750080799; x=1750685599; 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=NxRvpi4mZMXdsuvOPAqvVcquISKrLNsOB6lTKg+yoXc=; b=L0dMoETu2GWqiOB/SPJgmEpJcEG4LNW3FoySfEglS19BC9dsJvWMBNmGu6SPWZmvOJ ATu3Rg+I9AzO2IgCyJ6KXzgIeWxx9GmEnbi+PpoUuEEARPeKsG3XzMN7IaQrEjyNhom5 iPtV5ai8jvM7FBY90sibLniYKItVLE3NPoStE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750080799; x=1750685599; 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=NxRvpi4mZMXdsuvOPAqvVcquISKrLNsOB6lTKg+yoXc=; b=vypdkAou3CZEhwpdpIlfbnpmmhtu23DE4oWRyLLX1N+LdfxUAvJfuRltMM1R1yfpW4 i0m7p4dh66ikx7hURt+ny+xffqfZ5TkHBxDW5vb+wgSZtmc98v+LUFsRekWRpS0DgB8a MvllmUKBKxpNPIuyKyeTlkfY8eiaF2qoqnYRzQ6xhj1NNvCMeMsIyzev6Nf2DVYDZ6n5 TF6PJFFXj9SwooQPahRYwA9DBJW9+XAvfrj7r3Ij/Um8CldLJLSCeXhh/KvlFpoS7FMK BhNNfMgXlFqL8pCb1T6T6UUQ48FtS+ZJGMA7J5OVluNliI3+RpMvgJRV/ImCvU/oXplS gyUQ== X-Forwarded-Encrypted: i=1; AJvYcCVVfvuoW/rb3sr9Y0xAv9leeeGzU45Bn8AGv5R/n/kV09lF+l640OxKoUA9ZNxR4Y5kC8IUdBDTwg8NftU=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1yMdFfBIZq/8uQhQNRWI6x+yC5Px9FsBUBdqNAhpKgstA7PuX 9Hp9gGg2KgWUVdIkVmdteR95MmI6SasxkTkjFEaSRP9d9bccK+LiOyFWdk+LMLzgyA== X-Gm-Gg: ASbGncty4VojRVMq8lrzpF6j+2o8HODH7EyG2kVTNErPOtKSyfYG4thE1CXJppJ9os8 fi6960ZD5jTNM9zD+nC8QoHSj/04s3xrvsKCkL/u7UKY4+RPusp77Zvg35/sCJMR97YIf61DziK RMs953Y7xJQgNOMT5C/0zZuErNQjpxC+q1sEeJg3+O/D9KmKoTMAzXl87QPsGIMq+WmcrsfpEpj mzSpzoh3E0WWCXTgkG59uTBDpJM1XXJCSX7DU919MmPXgwtEDgyYXlbymU0yIoSnUzn/+ZoQNaG zo4IvOEox+NPFZLJNEmGf4d9YRc5elAzmZwDRPYlYq9PiCAlET9SYnZrJ4MrwpliL5ZWjSyuOB8 Drqwq4raDcuUo6r/SIVStvIsL8QsPA3hJWoo7Tk2yruIUpB2SrhzVK9x6OljvduoG8ljK X-Google-Smtp-Source: AGHT+IHXHH/g4hQtpUyXbw2a55jyHtMmZWxsR2Yjrb1ebrbQezAfwXZaOWNhg4NlM54/48a7s2JliA== X-Received: by 2002:a05:6402:26d0:b0:605:2990:a9e6 with SMTP id 4fb4d7f45d1cf-608c6e16978mr9487904a12.5.1750080799174; Mon, 16 Jun 2025 06:33:19 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (244.175.141.34.bc.googleusercontent.com. [34.141.175.244]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-608b4a94ce7sm6036664a12.58.2025.06.16.06.33.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jun 2025 06:33:18 -0700 (PDT) From: Andrei Kuchynski To: Heikki Krogerus , Dmitry Baryshkov , Abhishek Pandit-Subedi , Jameson Thies , Benson Leung , Tzung-Bi Shih Cc: Greg Kroah-Hartman , Guenter Roeck , Pooja Katiyar , Badhri Jagan Sridharan , RD Babiera , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, Andrei Kuchynski Subject: [PATCH 06/10] Revert "usb: typec: displayport: Receive DP Status Update NAK request exit dp altmode" Date: Mon, 16 Jun 2025 13:31:43 +0000 Message-ID: <20250616133147.1835939-7-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog In-Reply-To: <20250616133147.1835939-1-akuchynski@chromium.org> References: <20250616133147.1835939-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" This reverts commit b4b38ffb38c91afd4dc387608db26f6fc34ed40b. The commit introduced a deadlock with the cros_ec_typec driver. The deadlock occurs due to a recursive lock acquisition of `cros_typec_altmode_work::mutex`. The call chain is as follows:=20 1. cros_typec_altmode_work() acquires the mutex 2. typec_altmode_vdm() -> dp_altmode_vdm() -> 3. typec_altmode_exit() -> cros_typec_altmode_exit() 4. cros_typec_altmode_exit() attempts to acquire the mutex again This revert is considered safe as no other known driver sends back DP_CMD_STATUS_UPDATE command with the NAK flag. Signed-off-by: Andrei Kuchynski --- drivers/usb/typec/altmodes/displayport.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/a= ltmodes/displayport.c index b09b58d7311d..ac84a6d64c2f 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -393,10 +393,6 @@ static int dp_altmode_vdm(struct typec_altmode *alt, break; case CMDT_RSP_NAK: switch (cmd) { - case DP_CMD_STATUS_UPDATE: - if (typec_altmode_exit(alt)) - dev_err(&dp->alt->dev, "Exit Mode Failed!\n"); - break; case DP_CMD_CONFIGURE: dp->data.conf =3D 0; ret =3D dp_altmode_configured(dp); --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Thu Oct 9 20:24:10 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 6A0EA2877C3 for ; Mon, 16 Jun 2025 13:33:22 +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=1750080804; cv=none; b=Fmi3/d2ao5StZ+a61guV+/BieY+fqivu0Oazi12CMucRVF+9Kh+v4kRe99QcJQ4q/Qkbsbq+Z1DcT7yF3M9MoBB0PXiRyz1AuliMG/+ZmSkumgInl/7Jn6r/vK7Tw6ui2Ian3DZS2HHYjTETNgXlhAke9K1kMydCk/w6MRKHuc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080804; c=relaxed/simple; bh=0PHI8c4cGupy6mr00/69MtbHFn0M40BQMFD2F7JuKUM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NKgLT4EFAp9vL8geiKeh4e5teYGneSxJgg1Bh6r9XtaJhZ368k57oXpztHHUjvqg1O9D+Ry613xNTAx76qgxulUqJa7YSdnE78xRMxHGfZmdc31Kynksso12Tw7ogZXJUk2QFJmJqjbr9ReHUNH+oL4upxj/24i33ialChZUyQw= 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=VGrkzcjH; 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="VGrkzcjH" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-6070293103cso7859647a12.0 for ; Mon, 16 Jun 2025 06:33:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1750080801; x=1750685601; 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=zhqvBCRWi83ljiiFIoIKKjzL3JwEFntoAes/MRvHbvg=; b=VGrkzcjHJcxoKsVJO/hC0a5HRDzdSXGHs+xUtbV+PUKcnazteRKOU0/azSgJN7RpfK pp6D8TdJ/tYgGBJibvmMEIYYnBUAlU9lI7b2llWcotjEk1LeUS40amFJBWGGZQWdCYQm CgziL5y2yVh33bW8QCckwfwZKuQMruphZJlsU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750080801; x=1750685601; 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=zhqvBCRWi83ljiiFIoIKKjzL3JwEFntoAes/MRvHbvg=; b=HXw4DiJ14B8FPoJDfgS+KXNy9BeL7ETJ2IyG8tMdRKBLnu6gk/b2uxbKnYkUO7oEX5 6IdM//vmT/OlZqQYyv+gGx7DN4uUPKq9hsf4ZijqADf3+ZtnXqJLDZgoF/Jd+/S23RoY Ks1VIVaNjkzG5dRJTlNVPBZgafc14Rs8hIOEk6+GRcoPQW0RJXzqsk7gOqzYSGOwyQ9N mZl5pKAUueuZekTx7hy+rsIpPx8Ncl4NOyrUJpABaNxlyrr2W2xF9HefjsX8GCxMtd9R Ld0G21w0aMpVIEVTDjhsGLR0+kfF/rwVV92fSOwBtfKe3iKQVo5NDBHj0hzBX/5k+zuf DBVA== X-Forwarded-Encrypted: i=1; AJvYcCVpLGRZLgmem8Hrwwf+2GqjqkWHI4//tEJXn1v3hqXbNRHKgzs4PwHiKdj4byP9/f8qWR08ZVcrVdpygDI=@vger.kernel.org X-Gm-Message-State: AOJu0YwoHsj/8KE9AG8yWXBPNUjAgIPfD/J98/8oqtx7m1PrlinJjPP6 tC1/NYkVxV+IBvNU1/fUr3xw7ThOnm17+858/lHH8uugHw6iDL4l7mAHukqmogcUsg== X-Gm-Gg: ASbGncvWZJ3HyczHpxdRPUE6omwM77j4OBx/PRJy2+qzF7cHrudjCes44uOFNt2GZuY A1q3bmFe4e5cXRgj1bY9tZJYITFpNPKqpgoTXMr4YZx/MA3bvOV1iqL74p/Y1ossUaBQotbJggD L+Wgaq9ENJarmT8ujFm+EYqQLTR3yMLHFLBvd5GnLYr/IOQ89j7fC8SvUtC5ha2sgCK3Emqy4We ShvC0HkGwnF/yQ5C0E9Lv825gstKk2f3WZ/Q+rrW23r0FqqZC0R8zUrKQr7SeD7BJjzue45EeUg uyffcR8/96/RE7ZfW3EitVsDj9cnsRpb9Hq+yVAMg1tD4L5ThIP2p+asYaZVUbXxSG6WkieJVJr JgoKeGVkrCmbyoE8zgfEU3mLUS/rqEtH866pJG08VtwaYyb34BJEl1xMQTsgglEC1km00 X-Google-Smtp-Source: AGHT+IHfbJubtALYX705aMPJAZLadxG+o3H7c51K1HROrB1vOE0jaYQjb3BtZP2Tk8Y8fXZXY/12hQ== X-Received: by 2002:a05:6402:13d4:b0:606:e754:62bb with SMTP id 4fb4d7f45d1cf-608d09e3938mr8395397a12.28.1750080800769; Mon, 16 Jun 2025 06:33:20 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (244.175.141.34.bc.googleusercontent.com. [34.141.175.244]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-608b4a94ce7sm6036664a12.58.2025.06.16.06.33.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jun 2025 06:33:20 -0700 (PDT) From: Andrei Kuchynski To: Heikki Krogerus , Dmitry Baryshkov , Abhishek Pandit-Subedi , Jameson Thies , Benson Leung , Tzung-Bi Shih Cc: Greg Kroah-Hartman , Guenter Roeck , Pooja Katiyar , Badhri Jagan Sridharan , RD Babiera , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, Andrei Kuchynski Subject: [PATCH 07/10] usb: typec: Report altmode entry status via callback Date: Mon, 16 Jun 2025 13:31:44 +0000 Message-ID: <20250616133147.1835939-8-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog In-Reply-To: <20250616133147.1835939-1-akuchynski@chromium.org> References: <20250616133147.1835939-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" The Type-C mode selection logic requires feedback on the result of an alternate mode entry attempt. Call the `typec_mode_selection_altmode_complete()` callback to provide this final success or failure status. Signed-off-by: Andrei Kuchynski --- drivers/usb/typec/altmodes/displayport.c | 13 +++++++++++-- drivers/usb/typec/altmodes/thunderbolt.c | 6 ++++++ include/linux/usb/typec_tbt.h | 3 +++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/a= ltmodes/displayport.c index ac84a6d64c2f..946f61b57fa0 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -274,16 +274,20 @@ static void dp_altmode_work(struct work_struct *work) header =3D DP_HEADER(dp, svdm_version, DP_CMD_STATUS_UPDATE); vdo =3D 1; ret =3D typec_altmode_vdm(dp->alt, header, &vdo, 2); - if (ret) + if (ret) { dev_err(&dp->alt->dev, "unable to send Status Update command (%d)\n", ret); + typec_mode_selection_altmode_complete(dp->alt, ret); + } break; case DP_STATE_CONFIGURE: ret =3D dp_altmode_configure_vdm(dp, dp->data.conf); - if (ret) + if (ret) { dev_err(&dp->alt->dev, "unable to send Configure command (%d)\n", ret); + typec_mode_selection_altmode_complete(dp->alt, ret); + } break; case DP_STATE_CONFIGURE_PRIME: ret =3D dp_altmode_configure_vdm_cable(dp, dp->data_prime.conf); @@ -397,6 +401,9 @@ static int dp_altmode_vdm(struct typec_altmode *alt, dp->data.conf =3D 0; ret =3D dp_altmode_configured(dp); break; + case DP_CMD_STATUS_UPDATE: + ret =3D *(int *)vdo; + break; default: break; } @@ -407,6 +414,8 @@ static int dp_altmode_vdm(struct typec_altmode *alt, =20 if (dp->state !=3D DP_STATE_IDLE) schedule_work(&dp->work); + else if (ret || cmd =3D=3D DP_CMD_CONFIGURE) + typec_mode_selection_altmode_complete(dp->alt, ret); =20 err_unlock: mutex_unlock(&dp->lock); diff --git a/drivers/usb/typec/altmodes/thunderbolt.c b/drivers/usb/typec/a= ltmodes/thunderbolt.c index 6eadf7835f8f..697ab6060652 100644 --- a/drivers/usb/typec/altmodes/thunderbolt.c +++ b/drivers/usb/typec/altmodes/thunderbolt.c @@ -242,6 +242,9 @@ static int tbt_altmode_vdm(struct typec_altmode *alt, else if (tbt->plug[TYPEC_PLUG_SOP_P]) tbt->state =3D TBT_STATE_SOP_P_EXIT; break; + case TBT_CMD_STATUS_UPDATE: + typec_mode_selection_altmode_complete(alt, 0); + break; } break; case CMDT_RSP_NAK: @@ -249,6 +252,9 @@ static int tbt_altmode_vdm(struct typec_altmode *alt, case CMD_ENTER_MODE: dev_warn(&alt->dev, "Enter Mode refused\n"); break; + case TBT_CMD_STATUS_UPDATE: + typec_mode_selection_altmode_complete(alt, *(int *)vdo); + break; default: break; } diff --git a/include/linux/usb/typec_tbt.h b/include/linux/usb/typec_tbt.h index 55dcea12082c..57cbda5292bb 100644 --- a/include/linux/usb/typec_tbt.h +++ b/include/linux/usb/typec_tbt.h @@ -24,6 +24,9 @@ struct typec_thunderbolt_data { u32 enter_vdo; }; =20 +/* TBT3 alt mode specific commands */ +#define TBT_CMD_STATUS_UPDATE VDO_CMD_VENDOR(0) + /* TBT3 Device Discover Mode VDO bits */ #define TBT_MODE BIT(0) #define TBT_ADAPTER(_vdo_) FIELD_GET(BIT(16), _vdo_) --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Thu Oct 9 20:24:10 2025 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 2C8DA2DBF77 for ; Mon, 16 Jun 2025 13:33:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080807; cv=none; b=lxPgfL/jhY/gxuca7uZXZZeBYB8qZcFZr2jPO/NoZ+8IfSGxMzyhFXOEJmehxYoyKAt9EdBEQzOSucL6jeLyAhEwO7P6AWIA0FyPlUPH/Das8J2B0muIr+cCezcEhyNrjFBKHIVNF/Liytpn9CZm7h387UrOeo37x0gOUgzfwhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080807; c=relaxed/simple; bh=p39s08lBsdKyWiPzDRau2EzpDZFXgqJHAiwGMuq/Nwk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mGI/qDqxmmJyemdqghuShnd2uIqaBI3d5RaxVXovARQikF0Y0qdJGT6KRcfZGEUNoiWFuDh65Vrb0HWL+MbYFRJVnbVtlgPXPrH06ew0Ml6R16QVhXLia2wb9ZUk6nI5KBgZZuU9nU+l3xDWjNUt1lVl3ZhqBJ2/Lq2lWRXcrM4= 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=L+s8sUSS; arc=none smtp.client-ip=209.85.208.51 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="L+s8sUSS" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-60780d74c8cso8229768a12.2 for ; Mon, 16 Jun 2025 06:33:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1750080804; x=1750685604; 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=iRxqEsXbtVo0LTo1eLfkdMCcKn/6qpCdwe4jbm1dkIM=; b=L+s8sUSSF/Udpc2RkSiAVy5YerjD1X0adZ3u36b69fv6wfyOYFbxbDVj/LGqq0gAst 78jPhM7PY4undtTcqLg7rXKt1/A523FOJct926umc43ZdjUQDwp/PjZjFlqAakRYVjtp IXeg5h/zOg+F0XF6/IPiPvXTp79mDzaJ3hTco= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750080804; x=1750685604; 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=iRxqEsXbtVo0LTo1eLfkdMCcKn/6qpCdwe4jbm1dkIM=; b=YsVEEIjWZPqcYKXImCZiI6PA7BieOGXNKMRdflrKYyZSfY1IlO7Hak8Iw4Y590I9fj 4lLb82cmKSjbrrtVJxIt/9tzriTdjwIBpYnpBF6jESZVIxBPtCSC94nKlJ03iww5Wof5 xip32XJdNJWUTyZDCAVq/wgmMmMZSA3Q83Z34t+kRZBZrsX+WzS3cEgJ+XlAAIvxb1Ro Dy52hosLkQ6UiZ0s1MOx1TXj+5cYmKFvlkBaX4O+x9iOn0U2zmw5pVPMe2EmX9MUpas9 klvFmgWoYYbVgWWnMiU9NBji0FyyeLcuk/ZYXDfnycZ3gUp4N+thX8wYMn9QsSlTZbGi 0sbA== X-Forwarded-Encrypted: i=1; AJvYcCUlbcLZgAczJKG0DcbXszSwpOAky1tCzelDBCrSZzXwapNe64R40qJ1mmJLpQg4RvTvWezhJMcgl9+HzOM=@vger.kernel.org X-Gm-Message-State: AOJu0YyH9g3HIL99HPk3PpomrQLQGW1HlmOnNuTr2BJgvbgO8dMfWfha RV6CIMV9G8GOoA0Y4EKMrytM2oGuR+zIb94FJu/aQvOXvV8mFFTpV4LCKJEOSxwxxg== X-Gm-Gg: ASbGncuO7sx7P8vV8doufvrTOL52OApVVcwH8lws10RxP/yz7/L9TQMe94z6wLS1dVd M+Mswu50Qlv2rNhqtwbz8xVndbS57u+PTRsJwf5vib/s2YHT5uhntnD1vQn5U+nnITtimcEsTpp TTLq1JCBPGELwcwqo96BvgbMFd19JW6GvaKEP412ouxvrsF81ebiEDMi6xcWca1IKifZBXYSRbC 2S6qIWfy+wgV/B8JQysKGUYD3klKDcTymQGomduN3kKsqXPVL3uLEk83l+kcJ3Z/RImSzwzY3t5 L6uM63lCmglQtkF1FFxiWCiG0Ei0YWCSh2RwlB8sANzPeaMRcVlqqXArM6W8NOSBBuC6YoFzfex eFjbshuYbpRC4V7Nwx816deLrYcaLVeeDzbrXSFxXqplePeK/iHvYH0KJMQ== X-Google-Smtp-Source: AGHT+IHW7N4V3Xmd80K442egDP5c14Z4Wwz41/QwxRTZ4VwR1xjfYPTBJjTabMbR2EIyF9mo+GlBTw== X-Received: by 2002:a05:6402:348f:b0:602:225e:1d46 with SMTP id 4fb4d7f45d1cf-608d0835bf5mr8908309a12.3.1750080802251; Mon, 16 Jun 2025 06:33:22 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (244.175.141.34.bc.googleusercontent.com. [34.141.175.244]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-608b4a94ce7sm6036664a12.58.2025.06.16.06.33.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jun 2025 06:33:21 -0700 (PDT) From: Andrei Kuchynski To: Heikki Krogerus , Dmitry Baryshkov , Abhishek Pandit-Subedi , Jameson Thies , Benson Leung , Tzung-Bi Shih Cc: Greg Kroah-Hartman , Guenter Roeck , Pooja Katiyar , Badhri Jagan Sridharan , RD Babiera , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, Andrei Kuchynski Subject: [PATCH 08/10] usb: typec: ucsi: displayport: Propagate DP altmode entry result Date: Mon, 16 Jun 2025 13:31:45 +0000 Message-ID: <20250616133147.1835939-9-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog In-Reply-To: <20250616133147.1835939-1-akuchynski@chromium.org> References: <20250616133147.1835939-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" The `DP_CMD_CONFIGURE` VDM is the final step in the DisplayPort alternate mode entry sequence. Reporting the error code from this command back to the Type-C mode selection logic allows the detailed result to be propagated to user space. Signed-off-by: Andrei Kuchynski --- drivers/usb/typec/ucsi/displayport.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/ucsi/displayport.c b/drivers/usb/typec/ucsi/= displayport.c index 8aae80b457d7..6f754e696d93 100644 --- a/drivers/usb/typec/ucsi/displayport.c +++ b/drivers/usb/typec/ucsi/displayport.c @@ -241,7 +241,9 @@ static int ucsi_displayport_vdm(struct typec_altmode *a= lt, break; case DP_CMD_CONFIGURE: dp->data.conf =3D *data; - if (ucsi_displayport_configure(dp)) { + dp->data.error =3D ucsi_displayport_configure(dp); + if (dp->data.error) { + dp->vdo_data =3D &dp->data.error; dp->header |=3D VDO_CMDT(CMDT_RSP_NAK); } else { dp->header |=3D VDO_CMDT(CMDT_RSP_ACK); --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Thu Oct 9 20:24:10 2025 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (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 6F0802E4252 for ; Mon, 16 Jun 2025 13:33:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080807; cv=none; b=U8VieY63KNtjOIILtmzPFkpkSkAirHTNTSwTRXQkhjIjkhndSAmePleguZspNfqae9JdW7Sf0iZcKBj+d9ZJPcBNLi6WSLJ/Z4IrYgQWK/7Mdav80R9Y2vVUuHzj/81HEJj9rPGLZGWsqZYo+/QZ7uTv8RdrbKGQ/6Dy3vzpKgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080807; c=relaxed/simple; bh=+scX2JYc7g6Ny57270FvHahCDuDgXd0MvSdrc6MN7nE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bHPE5RrCOAir0nv5B4O3zkvSXujvJtOEuV7eAIyb0YVV9LOYSibH1g97diDwoTMU5IDeEh9CussNGOMibCOe5HTxUWnPen6U8UxhBec7f4g2j6To5E9Dy1dL/F1d+LwvwlYwo25dqzmz+TVqGZVdN6zMAG/lRNLr04ZqzH2Yvog= 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=gbEXMURP; arc=none smtp.client-ip=209.85.208.46 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="gbEXMURP" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-601dfef6a8dso7536897a12.1 for ; Mon, 16 Jun 2025 06:33:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1750080804; x=1750685604; 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=rPdVq+ZgSkdda1i1UwSKR/3OTMARvQfHUqZ/Ok6pdjM=; b=gbEXMURPbLhmBb8SWn6CgAXg9/Dv1SZUZYgiZf5lIV9zgH6vHMydxFNfhSWxvXjXsj HkzlqQYgEQtOCt0WqkGzI0BzQNKx0CYhVOXQxSrOzbikiUpFtVL8+/V8Oekciqrvp2Rw PQV9FbjaWK+TU61C+LJQdq8jJaJ4v2srpkvtA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750080804; x=1750685604; 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=rPdVq+ZgSkdda1i1UwSKR/3OTMARvQfHUqZ/Ok6pdjM=; b=sOn3v+px8dchcgPqKxgCuwAouNMS/rkzXm8VmbL2xx0OrtMsQi1Kmw80TE44bJdFPH qSJG48Swlh+HlvY0/oW/2dxmzUSp/AYCStIRvf0pEp1d7wrbwwww67j/KaP7PAyWKQvM x1KYyR2HIEePVTxPkgQo8yYFwQDMoN19pUsoIVhi/LOaJK0Aj+w8uDoSD0IpYcdSCwBr cy1+nG9Mt/cAir16dNWBQvYR6kQYxACyJAV9uMQgfPJarqlnQEVBxZDVRd/S0LNMpWsl 03A9saFwo88ivRGw/AbiM3Au2lW4Cnmytg5en9oj16B+z63vlGGBgGQzb7V1gc435/v1 YpfA== X-Forwarded-Encrypted: i=1; AJvYcCW25olbQAhWqrdFOPfk/USZwZddCakt1N3Hum9UCytJKKdgTxn+726CLyFKEBbmVOVcSwbumZgVPMAjCAY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7bK79DuYVZo0zaFt88v3/Ixwq5PKMQ0Ys/eS0cUvP4Y6Kw4Lk 2+kgCk3j6jX98qXh88JqHhWrpkgRJqI5sbQVO/Dz6lN6Z756GgoRAcAZUuzZocon1Q== X-Gm-Gg: ASbGncvT9GSvqO+uuz+l4FIpxOIb5xrl4XCwXE5JgRpBhLKbsXRMDLNkm7ccOiL441A E9oB3quTgYqj+Cdn6fLBa6SfL1pYOIV8Eojmz8XNyTyRWA/UYJbxadaLrCVlKR8VKpuvxYnTiIo ubiW7vDIMFRZRLcgqzoFyw2NQ1D8Il7qSGyW/YKdPrjRCD8jzkfrKnEydAvpt8xgU5mg12Wxuk1 dDEdG3bZfmIq6AC/eSPq2o890DkAgeow2EdFPtg7qbSMA1cCAYrUPN8tudprXhUNFhQ4No2rWwY M2NcRvhwsjkbOTkyECMmV5te4IV+bAlmkHyXzpm3POitnPyl4hPcnewnwIxKzkFYhoTXdOnPsHw 204KTPmUnzCB7W8h20x9zMm1QoKmHTuKiCpmGvkzDDkTlHBHxV2znL//FBw== X-Google-Smtp-Source: AGHT+IEw1MMStshySFu2Mw5NkUcbiGEAYvldonklBIuuR3wJfDRbJH4QZvobhuQJzCFy5gntWE9cAA== X-Received: by 2002:a05:6402:34d3:b0:607:2d8a:9b3e with SMTP id 4fb4d7f45d1cf-608d0835d29mr7714154a12.2.1750080803788; Mon, 16 Jun 2025 06:33:23 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (244.175.141.34.bc.googleusercontent.com. [34.141.175.244]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-608b4a94ce7sm6036664a12.58.2025.06.16.06.33.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jun 2025 06:33:23 -0700 (PDT) From: Andrei Kuchynski To: Heikki Krogerus , Dmitry Baryshkov , Abhishek Pandit-Subedi , Jameson Thies , Benson Leung , Tzung-Bi Shih Cc: Greg Kroah-Hartman , Guenter Roeck , Pooja Katiyar , Badhri Jagan Sridharan , RD Babiera , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, Andrei Kuchynski Subject: [PATCH 09/10] platform/chrome: cros_ec_typec: Propagate altmode entry result Date: Mon, 16 Jun 2025 13:31:46 +0000 Message-ID: <20250616133147.1835939-10-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog In-Reply-To: <20250616133147.1835939-1-akuchynski@chromium.org> References: <20250616133147.1835939-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" In the `cros_typec_configure_mux` function, which concludes the DP/TBT alternate mode entry, the error code should be reported back to the Type-C mode selection logic. This ensures a detailed result is conveyed to user space. To inform partner drivers about the result, the VDM mechanism is used. For DP altmode, the DP_CMD_STATUS_UPDATE message is utilized, as it is the final one in the mode entry sequence. For TBT mode, the TBT_CMD_STATUS_UPDATE message is sent. Signed-off-by: Andrei Kuchynski --- drivers/platform/chrome/cros_ec_typec.c | 9 ++++++ drivers/platform/chrome/cros_typec_altmode.c | 32 ++++++++++++++++++-- drivers/platform/chrome/cros_typec_altmode.h | 6 ++++ include/linux/usb/typec_dp.h | 2 ++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chr= ome/cros_ec_typec.c index 3aed429fde03..a4f338771094 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -610,6 +610,7 @@ static int cros_typec_enable_dp(struct cros_typec_data = *typec, if (!ret) ret =3D typec_mux_set(port->mux, &port->state); =20 + dp_data.error =3D 0; if (!ret) ret =3D cros_typec_displayport_status_update(port->state.alt, port->state.data); @@ -699,8 +700,16 @@ static int cros_typec_configure_mux(struct cros_typec_= data *typec, int port_num, ret =3D cros_typec_enable_usb4(typec, port_num, pd_ctrl); } else if (port->mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) { ret =3D cros_typec_enable_tbt(typec, port_num, pd_ctrl); + cros_typec_tbt_status_update( + port->port_altmode[CROS_EC_ALTMODE_TBT], ret); } else if (port->mux_flags & USB_PD_MUX_DP_ENABLED) { ret =3D cros_typec_enable_dp(typec, port_num, pd_ctrl); + if (ret) { + struct typec_displayport_data dp_data =3D {.error =3D ret}; + + cros_typec_displayport_status_update( + port->port_altmode[CROS_EC_ALTMODE_DP], &dp_data); + } } else if (port->mux_flags & USB_PD_MUX_SAFE_MODE) { ret =3D cros_typec_usb_safe_state(port); } else if (port->mux_flags & USB_PD_MUX_USB_ENABLED) { diff --git a/drivers/platform/chrome/cros_typec_altmode.c b/drivers/platfor= m/chrome/cros_typec_altmode.c index 557340b53af0..7ee295cf0c02 100644 --- a/drivers/platform/chrome/cros_typec_altmode.c +++ b/drivers/platform/chrome/cros_typec_altmode.c @@ -28,6 +28,7 @@ struct cros_typec_altmode_data { =20 u16 sid; u8 mode; + int error; }; =20 struct cros_typec_dp_data { @@ -295,9 +296,16 @@ int cros_typec_displayport_status_update(struct typec_= altmode *altmode, =20 dp_data->data =3D *data; dp_data->pending_status_update =3D false; - adata->header |=3D VDO_CMDT(CMDT_RSP_ACK); - adata->vdo_data =3D &dp_data->data.status; - adata->vdo_size =3D 2; + if (data->error) { + adata->header |=3D VDO_CMDT(CMDT_RSP_NAK); + adata->error =3D dp_data->data.error; + adata->vdo_data =3D &adata->error; + adata->vdo_size =3D 1; + } else { + adata->header |=3D VDO_CMDT(CMDT_RSP_ACK); + adata->vdo_data =3D &dp_data->data.status; + adata->vdo_size =3D 2; + } schedule_work(&adata->work); =20 mutex_unlock(&adata->lock); @@ -370,4 +378,22 @@ cros_typec_register_thunderbolt(struct cros_typec_port= *port, =20 return alt; } + +int cros_typec_tbt_status_update(struct typec_altmode *alt, int error) +{ + struct cros_typec_altmode_data *adata =3D typec_altmode_get_drvdata(alt); + + mutex_lock(&adata->lock); + + adata->header =3D VDO(adata->sid, 1, SVDM_VER_2_0, TBT_CMD_STATUS_UPDATE); + adata->header |=3D VDO_CMDT(error ? CMDT_RSP_NAK : CMDT_RSP_ACK); + adata->error =3D error; + adata->vdo_data =3D &adata->error; + adata->vdo_size =3D 1; + schedule_work(&adata->work); + + mutex_unlock(&adata->lock); + + return 0; +} #endif diff --git a/drivers/platform/chrome/cros_typec_altmode.h b/drivers/platfor= m/chrome/cros_typec_altmode.h index 3f2aa95d065a..848a2b194b34 100644 --- a/drivers/platform/chrome/cros_typec_altmode.h +++ b/drivers/platform/chrome/cros_typec_altmode.h @@ -39,6 +39,7 @@ static inline int cros_typec_displayport_status_update(st= ruct typec_altmode *alt struct typec_altmode * cros_typec_register_thunderbolt(struct cros_typec_port *port, struct typec_altmode_desc *desc); +int cros_typec_tbt_status_update(struct typec_altmode *alt, int error); #else static inline struct typec_altmode * cros_typec_register_thunderbolt(struct cros_typec_port *port, @@ -46,6 +47,11 @@ cros_typec_register_thunderbolt(struct cros_typec_port *= port, { return typec_port_register_altmode(port->port, desc); } +static inline int cros_typec_tbt_status_update(struct typec_altmode *alt, + int error) +{ + return 0; +} #endif =20 #endif /* __CROS_TYPEC_ALTMODE_H__ */ diff --git a/include/linux/usb/typec_dp.h b/include/linux/usb/typec_dp.h index f2da264d9c14..1679f7bb0c75 100644 --- a/include/linux/usb/typec_dp.h +++ b/include/linux/usb/typec_dp.h @@ -44,10 +44,12 @@ enum { * commands: Status Update and Configure. * * @status will show for example the status of the HPD signal. + * @error will contain the error code, if applicable. */ struct typec_displayport_data { u32 status; u32 conf; + int error; }; =20 enum { --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Thu Oct 9 20:24:10 2025 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (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 BDB212EACF3 for ; Mon, 16 Jun 2025 13:33:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080808; cv=none; b=CeWmFMBft3oR022vYIGS143jUfJgeuaLU4RtOFfUftr2w+12teRvYYx1ftmtMzYaaiqXbr7rJ+oA+XnTAmjpGWy+XzJstQ5dItitkI5OOGAV6ienzR9uaY7b4yXja4tVMviraNCMH3Evznj9A5TeK6cjNKKVxmmjBLIZzASYqME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750080808; c=relaxed/simple; bh=cMKsJUotDdosJ5GgRT61ngKqLnwH/Sc2vQwUb/JvwaQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IgSMVOrXLbdEkfsiQND/f348gHi2DWU5WQ3gHhXueFxLynnyABajBVaRVZ+HjDhIEzWbp6rFrhg0QsDqPw2/kTyg1tzZjc4EjukEceTUiyNaSO4YKXhGF8FE5wgzwvM3tOgRgCQm46ieU61zZ+45A+YF+oTBRlyUZYEBXjHrju4= 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=P5ba32G5; arc=none smtp.client-ip=209.85.208.44 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="P5ba32G5" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-607434e1821so6437275a12.0 for ; Mon, 16 Jun 2025 06:33:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1750080805; x=1750685605; 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=Lc1xa9XGYazZdbig9CQp0aaqg5/Q33JTrH3v7YQaNmY=; b=P5ba32G54XHUkHVqSLXc8+9deIRH3Ms0dsz+RUhfkLPMi20QlqGv4YQl1SIgT8bAZM OwdoTo8TYSeerWtM8Tc67/+Kn9DTfmazu1tcQ6cVi5wwSuWcDZAP55wUqmMh1O1JejYF qbYsCUyTFyXQGYzoj6h5JQjsFnjwxi113I3DI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750080805; x=1750685605; 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=Lc1xa9XGYazZdbig9CQp0aaqg5/Q33JTrH3v7YQaNmY=; b=Or1Qhr3ncv9xegI/jV+S0QC2mi7niJ5VvWPpfNIvy9IXoIvhbG9v6BxbfloY/yyStT 3RHFESU41Q5kjadO7uIsEGD36oCt3LhcDWm+/OSVSjhe696CZTFN94QAXiekpDwgBo33 wmft69qcETIM5oIY38vNLgZw+wh2yl+6nRFCRlalrJhuNA/T1gPgDvQevOFhRmKsAGvt 1i5t55AHFMBi7o7H6lg1FdIOk08D6Ao92ZMd0mFfOxM76ZEXXANoV8NF1PkOZCaC2SlE W9xf6eX2rrAGBkN0kmH2VnscR7hRjOrvbwRwdCPlHwDa4urtSyDLO+zj15MXFm/4fXjm /jyw== X-Forwarded-Encrypted: i=1; AJvYcCWJXIp2R3iElJJ50/MxS7Re2+txkBgf4KRHeX+3lbHPeddInvjWFYaUORL3SDvnEOqEKYiUiKCvjiK3vEc=@vger.kernel.org X-Gm-Message-State: AOJu0YwLp/jEfhZNdLKHspJ9D+vHWzW9IjPR37ffl5hz29zRXaFn0EHY RepFzDq3jwP8w8pB5jI+/PuxnSm0l8BfDNyuDCtwbNnYutrjHPXd7JL3LIfZX79D6g== X-Gm-Gg: ASbGncsbVR4kV2QyDMto+HDs24jC473Z6Xa3BR0j0jdpJN+jOApMXctI6Iykuo07vxl BJzOZSRpwPs1NHXB6gKjt3T+T3Dsl58fuS1LEjCGr+5gHd1otbR1oGAojFhOzKR382D86uZxYno 72GkXO2SNcptcxYFNhLQfjjA5H0w6EXLj9DZprjhWC9m5+f/yfUxl2ZL734+2Sl0UyC6Cn0RLZ0 mPAxKmDK7n2nlI43D5AwIM8F4swbClVJl7vKb/ntEjKYlV7A3+NkhqaIgXVnCViD5/RbSWEr3A1 vRjwQG66amUIMks9wfupOEYLYR2+ruosXxDsy7fpd/BrtpBEMVua6niZ2Lp3fOtb5PShXJ47sUT m5xpO694RzgeVZA50/eNIFkjYdN6QQr0Nhn8V1cgnZFw9zDCm7FeZMrRN5Q== X-Google-Smtp-Source: AGHT+IHw6+ZqjUiGtijKP7659AHwRHhXUfja1QVHvIcjre79jMfTDQp7kopiYwQiEAC5sFmbVRn9HQ== X-Received: by 2002:a05:6402:268d:b0:607:2e6b:47b2 with SMTP id 4fb4d7f45d1cf-608d0979e84mr9154566a12.26.1750080805113; Mon, 16 Jun 2025 06:33:25 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (244.175.141.34.bc.googleusercontent.com. [34.141.175.244]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-608b4a94ce7sm6036664a12.58.2025.06.16.06.33.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jun 2025 06:33:24 -0700 (PDT) From: Andrei Kuchynski To: Heikki Krogerus , Dmitry Baryshkov , Abhishek Pandit-Subedi , Jameson Thies , Benson Leung , Tzung-Bi Shih Cc: Greg Kroah-Hartman , Guenter Roeck , Pooja Katiyar , Badhri Jagan Sridharan , RD Babiera , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, Andrei Kuchynski Subject: [PATCH 10/10] platform/chrome: cros_ec_typec: Report USB4 mode entry status via callback Date: Mon, 16 Jun 2025 13:31:47 +0000 Message-ID: <20250616133147.1835939-11-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog In-Reply-To: <20250616133147.1835939-1-akuchynski@chromium.org> References: <20250616133147.1835939-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" The Type-C mode selection logic requires feedback on the result of USB4 mode entry attempt. Call the `typec_mode_selection_usb4_complete()` callback to provide this final success or failure status. Signed-off-by: Andrei Kuchynski --- drivers/platform/chrome/cros_ec_typec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chr= ome/cros_ec_typec.c index a4f338771094..c5a7f42ffb5a 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -698,6 +698,7 @@ static int cros_typec_configure_mux(struct cros_typec_d= ata *typec, int port_num, =20 if (port->mux_flags & USB_PD_MUX_USB4_ENABLED) { ret =3D cros_typec_enable_usb4(typec, port_num, pd_ctrl); + typec_mode_selection_usb4_complete(port->partner, ret); } else if (port->mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) { ret =3D cros_typec_enable_tbt(typec, port_num, pd_ctrl); cros_typec_tbt_status_update( --=20 2.50.0.rc1.591.g9c95f17f64-goog