From patchwork Mon Jan 20 09:16:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13944891 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.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 68FC2190470 for ; Mon, 20 Jan 2025 09:16:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737364612; cv=none; b=KVKX/6S4Dss5IsUkcPcG5/8dDabbppnEwrLK7EBalssc/LNnn6Qqk3esTugN/z3YnFrXgKr7TrpXwz5CrP/Qt1D5o1YF+cQlABnKBlvpGx5BHlcBcCllwg7cG7u2hwfaJykfImyKGxIuli/aMtrIrbcGBbFD9VTX3Xu1an51ECA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737364612; c=relaxed/simple; bh=sYOPK5n0Y8mPKJ42apx1GpzU8l3v2hgaZerBeQUeFAQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HKZV4jooYYGV0hK5Nsw32XC7KGe3/oheVyR0bspYAExsvxHF/vtZj5n93veM0AMF+OZy8YzvZbR0b4Y5r6IOEKfnqfoz0+pEm9ST1Wrj1I6es/Teg4QeGUAPB/Dve1tq3eo7NyQZIlnIqnA/b8DcSLgd/IrFxK914HyGurNHvuE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=TsTfapK8; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="TsTfapK8" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5401bd6ccadso4216205e87.2 for ; Mon, 20 Jan 2025 01:16:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1737364607; x=1737969407; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=0mGuVToP5GgJ7674F4ibSkeejzkyIQRftxnK/ZUBoic=; b=TsTfapK8qhrIfPTU2lNfXT/xGYxUsJh9WxXlhJSGxIQrZFk+zD5OOJbAvq4uaSSZwK naSLsz/JUeYYdwu8qjdLsV9PwFs8wcQKWJ6quM9p+TTBn4B3ta7fDfNVh75seKLgl9mF EddXldnr8U7hPUswUdF8pHTsdXwg5D6WtXfgz1vW9FWGoQtTJeyf7e8gAA6HfBJMO5Ht 2AlHPUh3QbI28JIWTjggnufgN0rGV9UUAdvUmwX+KZQO3ml9Zyep50kg5tWyI2DA2hoi aFl6IGmFCacEzG441lHqCX6h9UWr+leqR24P3wMX5SbJ2uXPQzQnRs3gm4iTg39xWzXd Opvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737364607; x=1737969407; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0mGuVToP5GgJ7674F4ibSkeejzkyIQRftxnK/ZUBoic=; b=N8VDZAr/qEwOVNiNhGXRpkzNBYs+kEH8NwFgrQpuUT0/bgM7+loFxhJaphuhgeBAUs o20VgVc/wiNxFJU624g0v9p+PubAZaMQViqnHsmn3jW/u7bHqdVJZKGsekFc293rv13n T/70L+eOm2U2L5D3lvm0P8Jpm1FX7D8qcJAzJM+9Ug3c6Ib6an06k1RwczV1Sh2YXR1N tduLbvN3QqigERmrDhq5uAD8M1Kb4hUvN8ItyUDXEiZS41UFg1pXciN1xZv9YVzVWVLY bmH4v9cmOaPeOFgL8Yb2QjJrhBDX4GMOiB7MQBK7wbVGq87s1Xaf5P/NH28Nmc48H94H 8u2A== X-Forwarded-Encrypted: i=1; AJvYcCUxgvYissmOCRA++ovmDl0k+UrDnUeCVoxuh39WHO6BVLi2ZPU33d+/l8HuNJouB+PLzGBYdMMwjvpOa1mqsFE=@lists.linux.dev X-Gm-Message-State: AOJu0Ywe9/foqnRYUZVy68MLltgHd2r0BcwEtWlljSZFtmr+invQRDvq rFgjWkHfBqiHVj1a4vTo0czZlfIW5O4HnTLOEnz9p0y5wvxeJqLIud/eAM1165A= X-Gm-Gg: ASbGncs8JICOM6ZYftt84Lqzb21QzTBVHYh5PjqBmvpF5xEViKw6pW/srX9nNx4KAuU Q+u2o1gNMh/XtuRuMwRZBAAZmmLmT2GyXl8jgnswTRLxc93f3JQeCyzka8rPcLwdLaI+PXoB2gq TjXOtQl3LjKRkUcNPV+yDy/mDCw4mor7DfTK+RKPgs/l6foe4kxQXPBDd7CdF+lMnPr937vkjvU zYtNQW73tRSwPSF3jXSEttTJcpA4DHHTlN95Gia33Kg8qPavtD0EBSDMsWmWsHsbAwqxd9Liivu Yg== X-Google-Smtp-Source: AGHT+IEPqjTMZr9kF5L4Q9EICOFU0VTJqKLJSHILO6JoUiQm8KOXLZzkt7cXnID/70dql3+8kTYIxg== X-Received: by 2002:ac2:528a:0:b0:53f:6c6a:f99f with SMTP id 2adb3069b0e04-5439c21f277mr3124071e87.8.1737364607280; Mon, 20 Jan 2025 01:16:47 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5439af729ccsm1223639e87.188.2025.01.20.01.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 01:16:45 -0800 (PST) From: Dmitry Baryshkov Date: Mon, 20 Jan 2025 11:16:43 +0200 Subject: [PATCH v2 1/3] usb: typec: ucsi: return CCI and message from sync_control callback Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250120-ucsi-merge-commands-v2-1-462a1ec22ecc@linaro.org> References: <20250120-ucsi-merge-commands-v2-0-462a1ec22ecc@linaro.org> In-Reply-To: <20250120-ucsi-merge-commands-v2-0-462a1ec22ecc@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman , Abhishek Pandit-Subedi , =?utf-8?q?=C5=81ukas?= =?utf-8?q?z_Bartosik?= , Benson Leung , Guenter Roeck Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6611; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=sYOPK5n0Y8mPKJ42apx1GpzU8l3v2hgaZerBeQUeFAQ=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnjhR7CHqMGxYwPKr+Wqe3YuDg6fGoumP4Bin+y 2+vSRsDLUOJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ44UewAKCRCLPIo+Aiko 1dLVB/9C1mWAa1lMJAfYX8Ho/+mXiOg1gDWhkpLtqojW6w8lHhDkzh6ABJe1hRpTeGaeYzLB432 Y7+EGG8zcIMz/mWatzH2Bu+l/TLgeqtEFhRQKcqTuam6ItOTCerZmHp23e86bzmNOzKyDhxSKxo WCU8pQmFoKWkGUQYCRrJ0PS0skrel3rYBW6ZlCRuhlWkfNKnURacAnceFA6xFjglc146yWnoUhp cSjYCpayEnMBb8TKMyNteFhzPaGF3l0lTi65TxqxikvrYjyz2W5yWdyz3Gz+kx+GpLTWyU2khJO tG1pG9pgJnSiUPh/Ye2+kscyCofC77sSobyc2Sn5dfMiymyY X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A Some of the drivers emulate or handle some of the commands in the platform-specific way. The code ends up being split between several callbacks, which complicates emulation. In preparation to reworking such drivers, move read_cci() and read_message_in() calls into ucsi_sync_control_common(). Signed-off-by: Dmitry Baryshkov --- drivers/usb/typec/ucsi/cros_ec_ucsi.c | 5 +++-- drivers/usb/typec/ucsi/ucsi.c | 19 +++++++++++-------- drivers/usb/typec/ucsi/ucsi.h | 6 ++++-- drivers/usb/typec/ucsi/ucsi_acpi.c | 5 +++-- drivers/usb/typec/ucsi/ucsi_ccg.c | 5 +++-- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi.c b/drivers/usb/typec/ucsi/cros_ec_ucsi.c index c605c8616726874434d5812731420fbc6f12790e..744f0709a40eddeed17f23e986f60e9f985381fd 100644 --- a/drivers/usb/typec/ucsi/cros_ec_ucsi.c +++ b/drivers/usb/typec/ucsi/cros_ec_ucsi.c @@ -105,12 +105,13 @@ static int cros_ucsi_async_control(struct ucsi *ucsi, u64 cmd) return 0; } -static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd) +static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd, u32 *cci, + void *data, size_t size) { struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi); int ret; - ret = ucsi_sync_control_common(ucsi, cmd); + ret = ucsi_sync_control_common(ucsi, cmd, cci, data, size); switch (ret) { case -EBUSY: /* EC may return -EBUSY if CCI.busy is set. diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index fcf499cc9458c0d12015a7e36e5f1ac448c3a431..559390a07a4e427c9b520dffaac905277d071638 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -55,7 +55,8 @@ void ucsi_notify_common(struct ucsi *ucsi, u32 cci) } EXPORT_SYMBOL_GPL(ucsi_notify_common); -int ucsi_sync_control_common(struct ucsi *ucsi, u64 command) +int ucsi_sync_control_common(struct ucsi *ucsi, u64 command, u32 *cci, + void *data, size_t size) { bool ack = UCSI_COMMAND(command) == UCSI_ACK_CC_CI; int ret; @@ -80,6 +81,13 @@ int ucsi_sync_control_common(struct ucsi *ucsi, u64 command) else clear_bit(COMMAND_PENDING, &ucsi->flags); + if (!ret && cci) + ret = ucsi->ops->read_cci(ucsi, cci); + + if (!ret && data && + (*cci & UCSI_CCI_COMMAND_COMPLETE)) + ret = ucsi->ops->read_message_in(ucsi, data, size); + return ret; } EXPORT_SYMBOL_GPL(ucsi_sync_control_common); @@ -95,7 +103,7 @@ static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack) ctrl |= UCSI_ACK_CONNECTOR_CHANGE; } - return ucsi->ops->sync_control(ucsi, ctrl); + return ucsi->ops->sync_control(ucsi, ctrl, NULL, NULL, 0); } static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, @@ -108,9 +116,7 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, if (size > UCSI_MAX_DATA_LENGTH(ucsi)) return -EINVAL; - ret = ucsi->ops->sync_control(ucsi, command); - if (ucsi->ops->read_cci(ucsi, cci)) - return -EIO; + ret = ucsi->ops->sync_control(ucsi, command, cci, data, size); if (*cci & UCSI_CCI_BUSY) return ucsi_run_command(ucsi, UCSI_CANCEL, cci, NULL, 0, false) ?: -EBUSY; @@ -127,9 +133,6 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, else err = 0; - if (!err && data && UCSI_CCI_LENGTH(*cci)) - err = ucsi->ops->read_message_in(ucsi, data, size); - /* * Don't ACK connection change if there was an error. */ diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 5ff369c24a2fc445e8559201d563c31d83b2c876..9ffc8debd7d77d118db042f2749cf429a848f8df 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -76,7 +76,8 @@ struct ucsi_operations { int (*read_version)(struct ucsi *ucsi, u16 *version); int (*read_cci)(struct ucsi *ucsi, u32 *cci); int (*read_message_in)(struct ucsi *ucsi, void *val, size_t val_len); - int (*sync_control)(struct ucsi *ucsi, u64 command); + int (*sync_control)(struct ucsi *ucsi, u64 command, u32 *cci, + void *data, size_t size); int (*async_control)(struct ucsi *ucsi, u64 command); bool (*update_altmodes)(struct ucsi *ucsi, struct ucsi_altmode *orig, struct ucsi_altmode *updated); @@ -528,7 +529,8 @@ void ucsi_altmode_update_active(struct ucsi_connector *con); int ucsi_resume(struct ucsi *ucsi); void ucsi_notify_common(struct ucsi *ucsi, u32 cci); -int ucsi_sync_control_common(struct ucsi *ucsi, u64 command); +int ucsi_sync_control_common(struct ucsi *ucsi, u64 command, u32 *cci, + void *data, size_t size); #if IS_ENABLED(CONFIG_POWER_SUPPLY) int ucsi_register_port_psy(struct ucsi_connector *con); diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c index 5c55155519634d95b6e544632f869c2867093617..8b02082201ec5b85031472563b8b8d1eea6134de 100644 --- a/drivers/usb/typec/ucsi/ucsi_acpi.c +++ b/drivers/usb/typec/ucsi/ucsi_acpi.c @@ -122,12 +122,13 @@ static int ucsi_gram_read_message_in(struct ucsi *ucsi, void *val, size_t val_le return ret; } -static int ucsi_gram_sync_control(struct ucsi *ucsi, u64 command) +static int ucsi_gram_sync_control(struct ucsi *ucsi, u64 command, u32 *cci, + void *data, size_t size) { struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); int ret; - ret = ucsi_sync_control_common(ucsi, command); + ret = ucsi_sync_control_common(ucsi, command, cci, data, size); if (ret < 0) return ret; diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index 740171f24ef9fae9abdb52d7995abe692e0a7623..02ac04a52239327475a3590734b77f3ac74bb589 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -628,7 +628,8 @@ static int ucsi_ccg_async_control(struct ucsi *ucsi, u64 command) return ccg_write(uc, reg, (u8 *)&command, sizeof(command)); } -static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command) +static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command, u32 *cci, + void *data, size_t size) { struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); struct ucsi_connector *con; @@ -652,7 +653,7 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command) ucsi_ccg_update_set_new_cam_cmd(uc, con, &command); } - ret = ucsi_sync_control_common(ucsi, command); + ret = ucsi_sync_control_common(ucsi, command, cci, data, size); err_put: pm_runtime_put_sync(uc->dev); From patchwork Mon Jan 20 09:16:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13944892 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 C2E3E1A9B45 for ; Mon, 20 Jan 2025 09:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737364613; cv=none; b=agY3W/mLlTu+t8pPTANngKQkHJf3WYBq9NgwjmDg71oqkvCk28wZc0vuUs1V+DVTLWvYl1c+BUU0pinuOfXzwBjcySlX5zQ+zJKffoJ05qjPPuf4OX0rFYGXOm3rZOeBY08PEaXdkmt7lXAeDi+BJRHDU/CFNDWlwW1o8Tad8Oc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737364613; c=relaxed/simple; bh=heR3VU+nxs99VRFMxd5VRCD07Xmz+D63MnVIf+KUZ+4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=e9048nj9uFT7oQSVKsEmKN42YuYUs/m/t3nA2DA/OwMQ6RrAGySZkrfZsXDxpCCSNDnak+E8deCS/DKybAWvNmvOW92xSXQlofCtMqyx7nWo90VcLT/MaItVCXdnZAcX26RoOX2yn8si4rOiJUSIS2mJphPPjp6hDGyIxK5AoPY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Wk7utdqL; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Wk7utdqL" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-540201cfedbso3903880e87.3 for ; Mon, 20 Jan 2025 01:16:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1737364610; x=1737969410; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=hibVCX0t4Pp4PQDIRaZNNKRSG9poNjEEnaBSc7dWujQ=; b=Wk7utdqLwc4DDK/w7JZREx4TIerQuQSa0b38SCLFy3xixWlILRz/WmHmcEIrmgOQAQ IOhWcOqCn63oq80lDFn60/2qscW/1eLHSicEeFNlBjbU+DJRUpABqyL1EXj6vDIaJFbO sdbqbm+LlswmCfma1dWLXgUgbR1B3MPDFCuBOJHmkfyTkoCzqvRePo3VcuZxGlmHBibu 0FP5OiGzIYNd3XlKIfeYo08tQwm//hAb4RW2iyIik5S/ztzyPf2911gDF1C1DCmWyXNz nBpwxQsj77QfLsQdq/mWiFetK13FHuEt+Y6pxp2aQnhj92LYIT+8QmcslC+VrwGEYl7T H/KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737364610; x=1737969410; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hibVCX0t4Pp4PQDIRaZNNKRSG9poNjEEnaBSc7dWujQ=; b=fAssSvRCD+idQBwHxJzVhuCvCoiOAxhkot7vo80Tubjf7gcRKWZA+VrKuOOtvvlbsR inmKYxlRARTDbL6ljiF0/QWyXQR34CoUTUqu+H+AFqJEO0d+GU2otrc/+TOHtG4biCW+ VwZEWj3ZLGw+5LNrA0G8gRHxL7tIy58MVSklWPkRPde95DAeGLdHPrX/bVXFJAMFBjgJ KZr+GaHmimtA7asJlDfOhIjSdoXOCfGCDFnSmD/+Pv0/XdT32PPoEpgMj8ihZmUMIjqJ 2WMao/c8YWExhnap0o31PJtRXMrxhQGySsE+5QIy6EvAH5FK/gv+Ib0hLYoEbEl7cLXh xjDg== X-Forwarded-Encrypted: i=1; AJvYcCWy/IbXIi7ZiYoeFoCibHWMESkb/Rb197w/K2cXXtE0emQFcB3TgVygb7mzj6jkG3y7pEHZ3dQcppdjHn10ff8=@lists.linux.dev X-Gm-Message-State: AOJu0Yw9k9QRAoUraeUmE2fbbEnW0r91NXCTEzHW/WLOH7YKqjIFuhYw y0uANIgcJGi+4YfMxnuHlJaEzFIDcTs/Dthx/DxYrJmbuCHLTx+Nbq/KJ+kzsp0= X-Gm-Gg: ASbGnctGeFqNrM98syE2uh8XiVHsRR7DAC8Y4pKeJBc3WVAlotDM3tav7DPsjkT9axK X13sGVI/H1m3KlNDw7VjFTQ7+3PrtaayLGnn8jZG8B3P01TiEf3ewGSuG3XexpHca6IobKlvETn 9ZxXwmDhUYwUEgnsDRF5uZvUXXB82Gz0OuXV7Fkzy8lF7QIVTirCojUdjY1BScZg8VhsYcF34ho el1O2Po1Do7pU89auRJWwrxg5T4JwSWHQIshJKDBDucauj1OcuFDpBMvqORgcJwLKgh2bg2U7IE +Q== X-Google-Smtp-Source: AGHT+IEJUmsSIld/ACGqbgQQoq8POA12hEoDXxsjPg3XLaDfZFr4I7p6+h8L6N5YBGEnzScLdOUPyQ== X-Received: by 2002:ac2:59c8:0:b0:53e:3a22:7a2e with SMTP id 2adb3069b0e04-5439c285a6emr3566649e87.47.1737364609814; Mon, 20 Jan 2025 01:16:49 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5439af729ccsm1223639e87.188.2025.01.20.01.16.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 01:16:48 -0800 (PST) From: Dmitry Baryshkov Date: Mon, 20 Jan 2025 11:16:44 +0200 Subject: [PATCH v2 2/3] usb: typec: ucsi: ccg: move command quirks to ucsi_ccg_sync_control() Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250120-ucsi-merge-commands-v2-2-462a1ec22ecc@linaro.org> References: <20250120-ucsi-merge-commands-v2-0-462a1ec22ecc@linaro.org> In-Reply-To: <20250120-ucsi-merge-commands-v2-0-462a1ec22ecc@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman , Abhishek Pandit-Subedi , =?utf-8?q?=C5=81ukas?= =?utf-8?q?z_Bartosik?= , Benson Leung , Guenter Roeck Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3833; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=heR3VU+nxs99VRFMxd5VRCD07Xmz+D63MnVIf+KUZ+4=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnjhR76xiiWH5fNtdZA0XzJwToX4fsdFJYF8F7X 4xO2HRE8MyJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ44UewAKCRCLPIo+Aiko 1XXrB/96vBeczO4rBNcGXmEhdffkOgqz6VqVfGEmMO64kXzA0L5RJsDGQSNxfrSjfSZ+p65j8vN ynvaFEuZErkvBOJDOoFWcaY560YBpsBY1/ykmJP+b+u7mERJ1gNx2L4D2oUNNLMr8MqzOMBXxxn t+H1tdbEHGZl6Hm/88SZyCdEXfuB9eslwqntDat35+AofdfysuMtbyUv3k8K92weiZsP9CLQMfk T+i3cZPYKHRxdVwGvRCQlE4v04ikX1CEIpUM7LIv0YGHtEG0a8cyF1uNfvQRc5v8gx4b0RmBkWD pnux3+veyByAox7Ty0fKwYC4wmDF/tGU5kwIx+13VYM1K5p5 X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A It is easier to keep all command-specific quirks in a single place. Move them to ucsi_ccg_sync_control() as the code now allows us to return modified messages data. Signed-off-by: Dmitry Baryshkov --- drivers/usb/typec/ucsi/ucsi_ccg.c | 62 ++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index 02ac04a52239327475a3590734b77f3ac74bb589..47498ee6cca89a9cc3fee872703b8d27487ea7ae 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -222,7 +222,6 @@ struct ucsi_ccg { u16 fw_build; struct work_struct pm_work; - u64 last_cmd_sent; bool has_multiple_dp; struct ucsi_ccg_altmode orig[UCSI_MAX_ALTMODES]; struct ucsi_ccg_altmode updated[UCSI_MAX_ALTMODES]; @@ -538,9 +537,10 @@ static void ucsi_ccg_update_set_new_cam_cmd(struct ucsi_ccg *uc, * first and then vdo=0x3 */ static void ucsi_ccg_nvidia_altmode(struct ucsi_ccg *uc, - struct ucsi_altmode *alt) + struct ucsi_altmode *alt, + u64 command) { - switch (UCSI_ALTMODE_OFFSET(uc->last_cmd_sent)) { + switch (UCSI_ALTMODE_OFFSET(command)) { case NVIDIA_FTB_DP_OFFSET: if (alt[0].mid == USB_TYPEC_NVIDIA_VLINK_DBG_VDO) alt[0].mid = USB_TYPEC_NVIDIA_VLINK_DP_VDO | @@ -578,37 +578,11 @@ static int ucsi_ccg_read_cci(struct ucsi *ucsi, u32 *cci) static int ucsi_ccg_read_message_in(struct ucsi *ucsi, void *val, size_t val_len) { struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); - struct ucsi_capability *cap; - struct ucsi_altmode *alt; spin_lock(&uc->op_lock); memcpy(val, uc->op_data.message_in, val_len); spin_unlock(&uc->op_lock); - switch (UCSI_COMMAND(uc->last_cmd_sent)) { - case UCSI_GET_CURRENT_CAM: - if (uc->has_multiple_dp) - ucsi_ccg_update_get_current_cam_cmd(uc, (u8 *)val); - break; - case UCSI_GET_ALTERNATE_MODES: - if (UCSI_ALTMODE_RECIPIENT(uc->last_cmd_sent) == - UCSI_RECIPIENT_SOP) { - alt = val; - if (alt[0].svid == USB_TYPEC_NVIDIA_VLINK_SID) - ucsi_ccg_nvidia_altmode(uc, alt); - } - break; - case UCSI_GET_CAPABILITY: - if (uc->fw_build == CCG_FW_BUILD_NVIDIA_TEGRA) { - cap = val; - cap->features &= ~UCSI_CAP_ALT_MODE_DETAILS; - } - break; - default: - break; - } - uc->last_cmd_sent = 0; - return 0; } @@ -639,11 +613,9 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command, u32 *cci, mutex_lock(&uc->lock); pm_runtime_get_sync(uc->dev); - uc->last_cmd_sent = command; - - if (UCSI_COMMAND(uc->last_cmd_sent) == UCSI_SET_NEW_CAM && + if (UCSI_COMMAND(command) == UCSI_SET_NEW_CAM && uc->has_multiple_dp) { - con_index = (uc->last_cmd_sent >> 16) & + con_index = (command >> 16) & UCSI_CMD_CONNECTOR_MASK; if (con_index == 0) { ret = -EINVAL; @@ -655,6 +627,30 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command, u32 *cci, ret = ucsi_sync_control_common(ucsi, command, cci, data, size); + switch (UCSI_COMMAND(command)) { + case UCSI_GET_CURRENT_CAM: + if (uc->has_multiple_dp) + ucsi_ccg_update_get_current_cam_cmd(uc, (u8 *)data); + break; + case UCSI_GET_ALTERNATE_MODES: + if (UCSI_ALTMODE_RECIPIENT(command) == UCSI_RECIPIENT_SOP) { + struct ucsi_altmode *alt = data; + + if (alt[0].svid == USB_TYPEC_NVIDIA_VLINK_SID) + ucsi_ccg_nvidia_altmode(uc, alt, command); + } + break; + case UCSI_GET_CAPABILITY: + if (uc->fw_build == CCG_FW_BUILD_NVIDIA_TEGRA) { + struct ucsi_capability *cap = data; + + cap->features &= ~UCSI_CAP_ALT_MODE_DETAILS; + } + break; + default: + break; + } + err_put: pm_runtime_put_sync(uc->dev); mutex_unlock(&uc->lock); From patchwork Mon Jan 20 09:16:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13944893 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 4E9D11AE850 for ; Mon, 20 Jan 2025 09:16:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737364616; cv=none; b=lX1TXjr6iBTW59ucblNSdhHtf+4zp057EhjPMXC2zZ28sv7BKJU1X70pDYkoqNUEoiYfx1p/LB6ZbjXYGG3YW0IvlcdGcPkrMEvekOLbmLmBYlsiQ8Q+Yy87hNe0JbuMe/2LEEe7MyLbRIg+RNsJl0VZ0+KhXCSyBliZhnmHHRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737364616; c=relaxed/simple; bh=HA9jbb7sf9FEcEGIypHqxSqTIh49BbritadiThhm0/8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WYeAWV3cwGxeQPDQUH5VoGfPzDqnDXXtchler8Y1aPQoXeDpXiNJwbXbtcYRWAJrkdDdqSwvgSh0GYulvaFHCut10yaCm6pblUuzpVTmdhqpyQZWgb3vUbKKvrgLKE+oftAX55m2oJ08FtV3+CdhddHWfIk6PI4oGPTGi5SLS90= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=dYTZKfiD; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="dYTZKfiD" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-5401be44b58so4372801e87.0 for ; Mon, 20 Jan 2025 01:16:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1737364612; x=1737969412; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=5GKui2+m9IAjivOenJXop0/jshpzhAnhINNH8CjefO4=; b=dYTZKfiDg9XrXLyPsgXyoE1j8WbJOocFyXTSYZozy9kUDNOkuPMlZd0AdtyQdfiY7k fDezMeNsS7GZL7Y4dOBJaTbWbeuY8JbSrZOwAS3wC0zs6jnG2T0XX1huk+sFYU0D8cBD eSmxbOAwyoO+6lxksyh9zmtSWOVRyX4Vzb+UtEfnGaPnlqF3yGiTX0bVbm7J/hughvaE 17wPn4am2LgfLOsFKHHomZEM0FtES3XvQsCQPjtmVAh4hVhkgJIqC6BTtPwI7MegicJZ /8MK3JU9IsqdPGKGjoGggnb5Ix6LpwoXSOTGyZtsghvfpdMFbDU+c1KG0mJcRq9IhttS Da0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737364612; x=1737969412; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5GKui2+m9IAjivOenJXop0/jshpzhAnhINNH8CjefO4=; b=eXBtXUOPcmlGFu714Nasq7/hycBrJuG/4D/kVzB/BkczRBucUkYW4Ll/yoSEHwR4vj VR+QIAHWEidKTOTnp8gt3oXHwmx3TiMOpVhiVzCmEB1VjKzXilZnk5QVm9I/yD9JODi8 0+J732r+vdvZQ09hlh2uDxM+VGCoJH35kes+y/DLEgE/8fIzw7ysyQsrirYjK9ZjusCf JeyvNkUxbdUwhjKlDpUIRuRTZJQBZh38AqXrGRNxosZf0+4yhts/8OyaUi048XyzL7xc wrVCUtSteAbBiOgodJlPVWr2vPw/+mQzVlmGXew/wnKUaY+GLB/9hjF6uSCMxTEL77Dk iB5Q== X-Forwarded-Encrypted: i=1; AJvYcCUnw8udzXaKbeJhJWlLl1h4xmdN52lGZhSmg66v+Qv2zWLLBTxvwhrDiKJ/z5il7wHX+Kj50tG4dOfMpWyt2Q8=@lists.linux.dev X-Gm-Message-State: AOJu0YwifzOth+pyQhbVCLJ2siDBeWokDs4JoMVire66bOBvq1NEwgu7 Amvg7IVKVlkbcjbQeThIEZ5y0Yv2iExlL7Z7YTyD0v0KNns3yDZdlsMKAujc9Zc= X-Gm-Gg: ASbGncsyk4WERsmTbvJqAqzBvPzO6r7hD4Htvq512KxMtvlnrYscjdVrG5T0ViqY35H 8Eaew233L4CfX7FovusNX/w923OBPvKZ1+FlHB6nQqleB+9SAkWYAtBQ9szEe4LVkOFMxkMBUjC hGnQePWVdja/OB5ZExjjzmb2czx8u4aGZOYn5lDP1iRKkpIQM2vGFEaZxxPYz3NuXMK7AWuzW+b CWiIRo97DQxGNISC6Q7GdHr1Zyz1uNr71Reh2RMmSk85U2hIFDk+AVGrRwXvVViC+cNW/0eBcoV AA== X-Google-Smtp-Source: AGHT+IEa+n48Uv8t7RWPHQjoPF7/uY9Me0OAnRXFnlzYDS/J3Z3bAwwUyNmzVAbCCcuLCA7BppNsgw== X-Received: by 2002:a05:6512:1292:b0:540:353a:df90 with SMTP id 2adb3069b0e04-5439c27b46fmr6101201e87.43.1737364612359; Mon, 20 Jan 2025 01:16:52 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5439af729ccsm1223639e87.188.2025.01.20.01.16.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 01:16:51 -0800 (PST) From: Dmitry Baryshkov Date: Mon, 20 Jan 2025 11:16:45 +0200 Subject: [PATCH v2 3/3] usb: typec: ucsi: acpi: move LG Gram quirk to ucsi_gram_sync_control() Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250120-ucsi-merge-commands-v2-3-462a1ec22ecc@linaro.org> References: <20250120-ucsi-merge-commands-v2-0-462a1ec22ecc@linaro.org> In-Reply-To: <20250120-ucsi-merge-commands-v2-0-462a1ec22ecc@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman , Abhishek Pandit-Subedi , =?utf-8?q?=C5=81ukas?= =?utf-8?q?z_Bartosik?= , Benson Leung , Guenter Roeck Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2515; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=HA9jbb7sf9FEcEGIypHqxSqTIh49BbritadiThhm0/8=; b=owGbwMvMwMXYbdNlx6SpcZXxtFoSQ3qfSI2su+Gqz+s52fYmVh9LvO5UFPbs+pmW6LpnHW/vJ s8PX/qwk9GYhYGRi0FWTJHFp6Blasym5LAPO6bWwwxiZQKZwsDFKQATKa5l/5/Cs59voqLUp+fy fdev7andLbhGevMP7dbef+y1F2wOVnXoxrP5JRzg3vZSgen1K9XvWl82Nj5TWyJbHsEckzE7sy6 fNY+pY2JwwTzvpCVPqp2PHZlkv7cgIu+OTXy3g8FDrzrWp5PnVn8NqZo6yX1+1fuFd9nP6tTdSu 8M5006NyP8s3Rgz1+W1OmRnWl7l8RPuaCxztf62Z63LYV6V/1sY41l3Xnl5DQel1150NXf6fF/2 6sVDSscBGNnSUmtPmT1m7HiTGq8SMb39R/+tijxHHt+cat+fnr4kYj3cXue80cs2uGuIX8ijT3e tOJCUoDlwR2zQovrrbftcryhYv/ifoDdU25uK0a+k49jAA== X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A It is easier to keep all command-specific quirks in a single place. Move them to ucsi_gram_sync_control() as the code now allows us to return modified messages data. Signed-off-by: Dmitry Baryshkov --- drivers/usb/typec/ucsi/ucsi_acpi.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c index 8b02082201ec5b85031472563b8b8d1eea6134de..ada5d0d21ee6fb1f406b6a8b8466bc71ffdb5b46 100644 --- a/drivers/usb/typec/ucsi/ucsi_acpi.c +++ b/drivers/usb/typec/ucsi/ucsi_acpi.c @@ -99,17 +99,23 @@ static const struct ucsi_operations ucsi_acpi_ops = { .async_control = ucsi_acpi_async_control }; -static int ucsi_gram_read_message_in(struct ucsi *ucsi, void *val, size_t val_len) +static int ucsi_gram_sync_control(struct ucsi *ucsi, u64 command, u32 *cci, + void *val, size_t len) { u16 bogus_change = UCSI_CONSTAT_POWER_LEVEL_CHANGE | UCSI_CONSTAT_PDOS_CHANGE; struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); int ret; - ret = ucsi_acpi_read_message_in(ucsi, val, val_len); + ret = ucsi_sync_control_common(ucsi, command, cci, val, len); if (ret < 0) return ret; + if (UCSI_COMMAND(ua->cmd) == UCSI_GET_PDOS && + ua->cmd & UCSI_GET_PDOS_PARTNER_PDO(1) && + ua->cmd & UCSI_GET_PDOS_SRC_PDOS) + ua->check_bogus_event = true; + if (UCSI_COMMAND(ua->cmd) == UCSI_GET_CONNECTOR_STATUS && ua->check_bogus_event) { /* Clear the bogus change */ @@ -122,28 +128,10 @@ static int ucsi_gram_read_message_in(struct ucsi *ucsi, void *val, size_t val_le return ret; } -static int ucsi_gram_sync_control(struct ucsi *ucsi, u64 command, u32 *cci, - void *data, size_t size) -{ - struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); - int ret; - - ret = ucsi_sync_control_common(ucsi, command, cci, data, size); - if (ret < 0) - return ret; - - if (UCSI_COMMAND(ua->cmd) == UCSI_GET_PDOS && - ua->cmd & UCSI_GET_PDOS_PARTNER_PDO(1) && - ua->cmd & UCSI_GET_PDOS_SRC_PDOS) - ua->check_bogus_event = true; - - return ret; -} - static const struct ucsi_operations ucsi_gram_ops = { .read_version = ucsi_acpi_read_version, .read_cci = ucsi_acpi_read_cci, - .read_message_in = ucsi_gram_read_message_in, + .read_message_in = ucsi_acpi_read_message_in, .sync_control = ucsi_gram_sync_control, .async_control = ucsi_acpi_async_control };