From nobody Mon Feb 9 12:11:43 2026 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 27DD71FCCFE for ; Fri, 17 Jan 2025 10:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110991; cv=none; b=K+EvUz5v9J5zydj8FNpzzHcMy5XlSnar4W9TUngt5noETy1u8TNYoLmWcA2ASzjBiwIbN0j5UL/tori1rvbqUJJHY3Bh0VkIFcOvkeYmKpdAjS33zV0Ur/BGcaiTvASrNwrYKxfZHf65MRxTOP80N6d11X84H39BCmzvDBL5JLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110991; c=relaxed/simple; bh=TgGTst054AUF5BLRcEqWxsTahGtW5ErSDs4mFY9yptU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KlF9lB1/Hpul8SrUt8LKw6L8T4O4uw5QrHiSxJDFNufo8MaQ9RPm7ZfydeAzisvuRSXzOTPRVyYifTeamR/+8vrV1gdrx3SyoICJYWeCAsH9Zk1rn1NsWy43/+v2/Ud/WWqwUmbc1S98U9oagCOryx43COeNgWTfaCfP4bsg6m8= 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=RY5NEWlS; arc=none smtp.client-ip=209.85.208.182 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="RY5NEWlS" Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-304d760f0dfso16758651fa.2 for ; Fri, 17 Jan 2025 02:49:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1737110987; x=1737715787; darn=vger.kernel.org; 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=kIsJjgqcD3CKuAw91D8+xLiCuc1mT42VX6rCIWe3wr0=; b=RY5NEWlSS7sPRcN8bcNJAfEeYq3p7+PoNkxqOkCwdJv3OUTPJrsJ0lrwHNYjxMqTt3 DD5vEkpBLsHtQ7+Q48OB8GOMHbqysUZZWUpxa0NgZaV5swW4tklv6xu42ERtZ7ZkCoZ0 uGx2EhCk8l46jcM5zLYOZs5VMu+0dZhIYJqk4RAzbrbomJwM8MD6v1EOHnrv1cvCpd50 pdoIqir17mkbCjy5EZ4VafECz/NZbFWSkKj4TtmXChRvF2courwK+5Prv00oGdchj1qC 5Xr0rYXEPltFQiqx4rwQpX6DR7I57KXgtLhq4k1DEFUTTXufbvwQJ++VFanv7yslFvlk O2pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737110987; x=1737715787; 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=kIsJjgqcD3CKuAw91D8+xLiCuc1mT42VX6rCIWe3wr0=; b=DwwgEiGpbn1d/uaKpo8P6gRBFF/MoDcCYVVddWvYejpPrp3jP94LviBidint7Xb+Wf Cw1O4EmQ4eOZdk7O+twn90PJEYQG1d+E6z7DilAWjsSDQSwns212i6lhBCD02+VPl9er 6hO9bZw1SEvCDCySstbJpaz0PEDKhJ3dBHm7h7SVmBSYcV9hsYxk5OkNpYXH6NGGocQn vVaHOJAyQ+Ocn+taAh8Rjq5kCfQreLjfQGX0WNMtLIAvtKJ6cEeXUjvMGZZSWMdTI6Xa xU/YLSzEahBqKVN7gKgaOoGNB8n4KWX7VDdqQUo1OERzqEBZO+ORFaRL0dAzrfWSARm/ 97FQ== X-Forwarded-Encrypted: i=1; AJvYcCX5hq7UUcyAAGG2Oac7pvVrTxTLz/9Yzr/rItBuhzS/onfBsc5JC+O/IxNyxia3BnnrAi1omhkwjuGsKcI=@vger.kernel.org X-Gm-Message-State: AOJu0YzKxq0Nldkg0C6T2agDuR+FJYVNrfkAzAx4Zx/DvDtuYXi1PrgU 5egBQv3wD3naBtStdAtd5foxBco1HyEese+S834DVmeVDc4VSWCJL+r6Bi2zSIZjvdJkaYwQy/4 rQDo= X-Gm-Gg: ASbGnctJKFFtpS+KbCfLvipr+4bkd1quxabsTKfG1z9QK8076O17ePswPvlHENWE6Vm 9IWMFaAJrZBXbDv1//oRK9iyDxPYjjlQLI1xupokSNBnwP1CwmDNIgi0tBi86Am06k/1ngOwalq iQnKqr/J1McRZ863THChNXXkgdaf6maLtyyWfWWu9biurF9/TWPL5w4exxVv/XXltl/05DDCXgg b5ivST9bMzJ1/sQiR6OBB8o3jRPF20rgHus0rul/mZBGBqIASzOqcY/TM9mrVJj X-Google-Smtp-Source: AGHT+IG7JzmugXSREVxuRHqTKN33noZpMABdtBvn0teNbwq88+AybiOF55u0wVoH3J2QQ01RCzY8DA== X-Received: by 2002:a2e:8e27:0:b0:302:2598:dec2 with SMTP id 38308e7fff4ca-3072ca75098mr6134391fa.14.1737110987070; Fri, 17 Jan 2025 02:49:47 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3072a3446c8sm3803321fa.27.2025.01.17.02.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 02:49:45 -0800 (PST) From: Dmitry Baryshkov Date: Fri, 17 Jan 2025 12:49:41 +0200 Subject: [PATCH 1/3] usb: typec: ucsi: return CCI and message from sync_control callback Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250117-ucsi-merge-commands-v1-1-e20c19934d59@linaro.org> References: <20250117-ucsi-merge-commands-v1-0-e20c19934d59@linaro.org> In-Reply-To: <20250117-ucsi-merge-commands-v1-0-e20c19934d59@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5724; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=TgGTst054AUF5BLRcEqWxsTahGtW5ErSDs4mFY9yptU=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnijXFQSDpFhCcDmKnHLcipMMYLKILoKTxMV5DL McXFISagRaJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ4o1xQAKCRCLPIo+Aiko 1TuCB/0SkqhhxSoA/uUxGd073w+q0JADO3Fr1lLWVld5rXTG6fkEPCpms5A84xFzqCIILVNthoG 9bsxf1BDSqcy5wcpYzviMvgwkmwhmh8CR5+RtahtEpjvMLHkodZJOWXG4AUSBlRGw07TDnlF0an nzNNZ4k0c3hgbPqniEc9IZ7zEiE+y27cM5jsoGI2GsSW0CqzeRr8G2Ung5KsTtiFqu+hhd8o/+3 dwjYekW0aLmNmKHnIernbTE7W/mT0v8N7jfxu63+sEuoW19GUOUmqHrirxCLfg61T+yYQSwd5vh itCUzCi4witBE6KypugDxqGnXm4JygNfls9Vu2+7rx11E1on 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 Reviewed-by: Heikki Krogerus --- 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 +++-- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index fcf499cc9458c0d12015a7e36e5f1ac448c3a431..559390a07a4e427c9b520dffaac= 905277d071638 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); =20 -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 =3D UCSI_COMMAND(command) =3D=3D UCSI_ACK_CC_CI; int ret; @@ -80,6 +81,13 @@ int ucsi_sync_control_common(struct ucsi *ucsi, u64 comm= and) else clear_bit(COMMAND_PENDING, &ucsi->flags); =20 + if (!ret && cci) + ret =3D ucsi->ops->read_cci(ucsi, cci); + + if (!ret && data && + (*cci & UCSI_CCI_COMMAND_COMPLETE)) + ret =3D 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 |=3D UCSI_ACK_CONNECTOR_CHANGE; } =20 - return ucsi->ops->sync_control(ucsi, ctrl); + return ucsi->ops->sync_control(ucsi, ctrl, NULL, NULL, 0); } =20 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 comm= and, u32 *cci, if (size > UCSI_MAX_DATA_LENGTH(ucsi)) return -EINVAL; =20 - ret =3D ucsi->ops->sync_control(ucsi, command); - if (ucsi->ops->read_cci(ucsi, cci)) - return -EIO; + ret =3D ucsi->ops->sync_control(ucsi, command, cci, data, size); =20 if (*cci & UCSI_CCI_BUSY) return ucsi_run_command(ucsi, UCSI_CANCEL, cci, NULL, 0, false) ?: -EBUS= Y; @@ -127,9 +133,6 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 comm= and, u32 *cci, else err =3D 0; =20 - if (!err && data && UCSI_CCI_LENGTH(*cci)) - err =3D 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..9ffc8debd7d77d118db042f2749= cf429a848f8df 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); =20 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); =20 #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/uc= si_acpi.c index 5c55155519634d95b6e544632f869c2867093617..8b02082201ec5b85031472563b8= b8d1eea6134de 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 *ucs= i, void *val, size_t val_le return ret; } =20 -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 =3D ucsi_get_drvdata(ucsi); int ret; =20 - ret =3D ucsi_sync_control_common(ucsi, command); + ret =3D ucsi_sync_control_common(ucsi, command, cci, data, size); if (ret < 0) return ret; =20 diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucs= i_ccg.c index 740171f24ef9fae9abdb52d7995abe692e0a7623..02ac04a52239327475a3590734b= 77f3ac74bb589 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, u6= 4 command) return ccg_write(uc, reg, (u8 *)&command, sizeof(command)); } =20 -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 =3D 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); } =20 - ret =3D ucsi_sync_control_common(ucsi, command); + ret =3D ucsi_sync_control_common(ucsi, command, cci, data, size); =20 err_put: pm_runtime_put_sync(uc->dev); --=20 2.39.5 From nobody Mon Feb 9 12:11:43 2026 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 76B921FDE23 for ; Fri, 17 Jan 2025 10:49:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110993; cv=none; b=jLWKvPq9e46REf4PTJ5SCQsqGAlrSM4cDBDJ/GB7K+AfVzgb8NYXVsOWrG7u23ik4oeAuKvGRumkSNOAmIFEvxaVJeCmFGohROojpWbTABEcpJjPnjScpICcwmBcx5TbVMYInwUZeYmOckRBHpsFGi82iSQT4HWCon5sm9+Ygc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110993; 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=drwrfKT1Py7ZPnTNyIuzaCDMGjaBoXd2fqgEkWthQR4CP96u0cqLaKtRf0E+AXn0XOzat3alDa4JzHL/X8KjPm4U6spjCuIJe7lYXp5z4vCl2cg41r1H9h/JXT1XPdcgQNjpPnpZVGSETfZ4XgJNkAh3AWYpR7CoAg9u+nYiHmo= 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=q57TZJLF; arc=none smtp.client-ip=209.85.208.177 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="q57TZJLF" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-30227c56b11so19601231fa.3 for ; Fri, 17 Jan 2025 02:49:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1737110989; x=1737715789; darn=vger.kernel.org; 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=q57TZJLFdPioDkOtgp7RPUAFjD/bDqHVGiygD6YjqXQ5btWBR3l5qerwCysE0ASGwx Q+IOu/UDydTcgNXnVh34XtZdnNw07TzCQxcS0I/Sum4H3EsnrfubG8M/dZwQHbJD6ax1 VLURzlxcFYWcROUUKx+w2WtmqcZ96CriHCtUv4JFC34SjWvPD4nBu89VEgAfLxGy4Ci5 Xhb7JONFAW2gkx+GD77L+BKVvDII5DcFZUde5LJPEduQmv3jbe8D3AXSk7gr6tjEESy6 FhtSWEL9XSDC7vpP/2+sgXxUkTtKSkuxM44Xvk350IW14v7aT3THauOM6L8vLqOF7kGy k2qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737110989; x=1737715789; 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=OYk0UhnIkw4yjw/7HDOU+KBUJS31f0AjT903fVPdDLfMf5eR9YO7n7pneOX+Y9o7Qd irTtyRt3zjQIndiJsxHFCFYsKWPcbJiXu4N4ItCTXWJLds19PDd59VOUJ5PKVvf54gNi YBZJ8TbKrDfT4waOVf5nnSBKKOzG1bCWVV1FE/OFpu+IOPt9sX7sqSpXIgMPmDeoZ58T WbCkpk4sC+r8mlzCzhkKuH/XiLaXSgYSuPg8S9Qi4iIAyUaEAQ51U4e3YDGKgGApfSHp DWn8cr/RLtq6ewdCkWv0TIiRE78LkiyiQVWPj/rqp1+AZLyQ2zC/PXmC6cY+S+CN6Ypa 3tuw== X-Forwarded-Encrypted: i=1; AJvYcCWeLB5bivOlFTxQjRsxCBGi4i2UNqzZEtYSJ8BNVZZsK/JoJGitNQ2bDIsatQ10MWdh2gfsX7I/0hDzV/A=@vger.kernel.org X-Gm-Message-State: AOJu0Yyz3AZ6xnqCCmPHXA4WzHghl2AW5zYMCLMVfP8CXphS0Kby50r+ FgX5gMg0zTwUdjXa59vmdGao0tkobOMgAP7Bk18evCT5x8/UhkbECLdaed+qWhkOBL2OfBSz0pu ex6I= X-Gm-Gg: ASbGncsqTx1uLs2qQ40srhgSgeywMejTwM98o9K0S3+gTH36nGPHKgkIgtBYELbOfo7 lyVIXUdRJRzLTDQL5OTQ445VjkEajJuZzkvG+SNmQAl+0MJr+ximxgNSr9KjzRg67+Tt1fmNP97 2Q1xWM7HuEdrf930kos5e6olo7740OeUrYIOx62B2BgDqLfksbwx5hpQCY5Vb1IuZG6vH3dOy7r 37j8uvKX0YFJiYL5UZ8trBNr+JhKdbjW4+7NV0ZO9oC4DJHgaVDLn0LOUvYFSwf X-Google-Smtp-Source: AGHT+IEiYTZQWrWOUKWjqhOVqBylp4MRFwJV7aM47B9T1N1DKb2eq5WqGCcUbHP2ESgQN4USFGOnVg== X-Received: by 2002:a2e:bc27:0:b0:302:40ec:a1b3 with SMTP id 38308e7fff4ca-3072caa166amr7459741fa.21.1737110989365; Fri, 17 Jan 2025 02:49:49 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3072a3446c8sm3803321fa.27.2025.01.17.02.49.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 02:49:48 -0800 (PST) From: Dmitry Baryshkov Date: Fri, 17 Jan 2025 12:49:42 +0200 Subject: [PATCH 2/3] usb: typec: ucsi: ccg: move command quirks to ucsi_ccg_sync_control() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250117-ucsi-merge-commands-v1-2-e20c19934d59@linaro.org> References: <20250117-ucsi-merge-commands-v1-0-e20c19934d59@linaro.org> In-Reply-To: <20250117-ucsi-merge-commands-v1-0-e20c19934d59@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org 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/pANAwAKAYs8ij4CKSjVAcsmYgBnijXGr/9bjVSYjTyTv0PnZm4zPbHPTKkO89qzs +zEEfSMzpWJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ4o1xgAKCRCLPIo+Aiko 1d0bB/4uri+jTSEL0p4zZ/3Tk6Q8cRfI5JIyJGiP8j+Q5NQ1GoP0JNWbXoOSTNmCwzfadWZC82K tVcZymG9oGop3auC8If9QBCPOEsb72b654eTK6IpjNlqRwgNfNLUWPYdjjKbs971jRu1Zw3aW1I IdB5TgFvlVWko2d1PuNTNY6j57lBSwK/DQs653p23xLg09MRtLS1wgpbYTGQxCZfkXYVNFEATZp HrQxUKGdAePtlggrshEFEybo20Pn2araqjL9L4fOtU/6etXTQqFUSJNa+jpQBfd993fbSMP5AG6 6/613qcaKmB4ZZrFA2nyfVV6fTp9RhPSJP2hz0fuY7hoeviO 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 Reviewed-by: Heikki Krogerus --- 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/ucs= i_ccg.c index 02ac04a52239327475a3590734b77f3ac74bb589..47498ee6cca89a9cc3fee872703= b8d27487ea7ae 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; =20 - 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 ucs= i_ccg *uc, * first and then vdo=3D0x3 */ 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 =3D=3D USB_TYPEC_NVIDIA_VLINK_DBG_VDO) alt[0].mid =3D 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 v= al_len) { struct ucsi_ccg *uc =3D ucsi_get_drvdata(ucsi); - struct ucsi_capability *cap; - struct ucsi_altmode *alt; =20 spin_lock(&uc->op_lock); memcpy(val, uc->op_data.message_in, val_len); spin_unlock(&uc->op_lock); =20 - 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) =3D=3D - UCSI_RECIPIENT_SOP) { - alt =3D val; - if (alt[0].svid =3D=3D USB_TYPEC_NVIDIA_VLINK_SID) - ucsi_ccg_nvidia_altmode(uc, alt); - } - break; - case UCSI_GET_CAPABILITY: - if (uc->fw_build =3D=3D CCG_FW_BUILD_NVIDIA_TEGRA) { - cap =3D val; - cap->features &=3D ~UCSI_CAP_ALT_MODE_DETAILS; - } - break; - default: - break; - } - uc->last_cmd_sent =3D 0; - return 0; } =20 @@ -639,11 +613,9 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u6= 4 command, u32 *cci, mutex_lock(&uc->lock); pm_runtime_get_sync(uc->dev); =20 - uc->last_cmd_sent =3D command; - - if (UCSI_COMMAND(uc->last_cmd_sent) =3D=3D UCSI_SET_NEW_CAM && + if (UCSI_COMMAND(command) =3D=3D UCSI_SET_NEW_CAM && uc->has_multiple_dp) { - con_index =3D (uc->last_cmd_sent >> 16) & + con_index =3D (command >> 16) & UCSI_CMD_CONNECTOR_MASK; if (con_index =3D=3D 0) { ret =3D -EINVAL; @@ -655,6 +627,30 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u6= 4 command, u32 *cci, =20 ret =3D ucsi_sync_control_common(ucsi, command, cci, data, size); =20 + 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) =3D=3D UCSI_RECIPIENT_SOP) { + struct ucsi_altmode *alt =3D data; + + if (alt[0].svid =3D=3D USB_TYPEC_NVIDIA_VLINK_SID) + ucsi_ccg_nvidia_altmode(uc, alt, command); + } + break; + case UCSI_GET_CAPABILITY: + if (uc->fw_build =3D=3D CCG_FW_BUILD_NVIDIA_TEGRA) { + struct ucsi_capability *cap =3D data; + + cap->features &=3D ~UCSI_CAP_ALT_MODE_DETAILS; + } + break; + default: + break; + } + err_put: pm_runtime_put_sync(uc->dev); mutex_unlock(&uc->lock); --=20 2.39.5 From nobody Mon Feb 9 12:11:43 2026 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.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 B16E01FE45F for ; Fri, 17 Jan 2025 10:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110995; cv=none; b=ZtpG6+cNO1NVfEVAFrEQgTMnjnPN+yZ/vVqhndfdQYu5/n1wllJaQbmfbR26sAfX5XVG3igEMripyI4EgONL0bpGBuZkT/P9ZWoj3gDQrWMgZSIs3YZI8hSPWneH1yLbny3YeVp7Y/45WjqxbW5luqbWAlScTYu6aGy+m1GfFS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110995; c=relaxed/simple; bh=HA9jbb7sf9FEcEGIypHqxSqTIh49BbritadiThhm0/8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OaOYoQgEKE8sbXaJMbsqg0vJx4VaTNJOiSHsBRhI84UUZkzyB0Vt+rm1fb7JsWJAABpzrzVqijTHX4WI9z3xQM/AnlbYq+vnDIograz11KiYV0kfJa3K31X8DE/TSw7fq8e8zdWYkzDx83wILOYJ/3lGcbI3N24yAqJNNie3fQU= 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=eMKZEA25; arc=none smtp.client-ip=209.85.167.51 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="eMKZEA25" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-5401bd6ccadso2038065e87.2 for ; Fri, 17 Jan 2025 02:49:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1737110992; x=1737715792; darn=vger.kernel.org; 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=eMKZEA25eA4t8NMLmmJdwmzrfNmFS8zz1LL3kE7Q2+Uwy1dtjIFK6aBIW5USJinYbQ wfk8IyTXWf2eycnDygf1A4TaIVGD8ipPWRE5cdcdLPkdarVG0YHhyActci1UgWGuifZW JB3H488VxdtaEhUQqumfdVewwwzaSfHCqEzC67hIcZ7vYmA+SFfoUA8B38aNWxEEaBBq UvAk5eSexGu76HkkxVrn3+piQx/GMpuCFXMy0J8E9cghL2513fQbwdQ26U0s+33JlpMH KdhQ4zH4FbCRuuQxt8h58kCTAI6FYFcgoOGyOg7HcFOw328IbnI+UaR7RXTyazyOdEqe uD+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737110992; x=1737715792; 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=QnL8LabWdH3OFtHfx7ywoctSgkKJyzlcVHJ0az2CVIyLrgxo4gqeNvoThyKiibjcrl P5HH2NtVh4doV+IOyHQfwu3gYm6GTArhMjgl8rh9DZ+HfUZPOsHhRQC+wZuXuLygeiu1 D2vwLraZ31wXlC8it6wiVlbOmatE2uU7rlwCLXP2IlkpVNrs3lx6bJEeFibwyc+VFCMv MUGzDpRkO2V4KUiobZ2OPNNs/9sX/LaXgRpvkKu89jeTAQF/rF/08jJ9/wMCTYrsVqzw SBLLwfsfCjvOT2kCOD8ZvLmNuhVG++bKiPEjqNiBWWCbRetTmt+LAzHFjkeHsFIZJDYy zPpw== X-Forwarded-Encrypted: i=1; AJvYcCXpbA7V7TK+WBrz77VmfuUA7BaALK1GD5sECsc7860r/i60d6QChNoqkrcqfExMjCDS0mxOt1NKigPVwS8=@vger.kernel.org X-Gm-Message-State: AOJu0YyF55zMd7OAOx2y1EAN7vWndYHZTgcw/uXhLK2Y6NQYeQMOYitk 19PHK75tJWrZWhQL2+3PTpTG0//B5gB4zKFGwEjJMEgo30BPG+Gpch/ihJJnmNzF4HonRLvXAAP +FRw= X-Gm-Gg: ASbGncvFHSlctxuLcVdgqwlbuDvuSzvhj3vlgLVR1Dy7YUEntE8b5WEkLh8VrrILmsk /zlabXGKeSVvMIBB0EqvI5pGZkTrZwIhzpaUpd4wWsG5Qr3oE/SYTPe6bzGHtXoV5TO2Ul3rknO UO218KYaHaO9g1Hkeg6QHXC/DEVxo2PUMcPb+9qPSmo2OjC5e5BxdTNchTDp2Az9W1BHA/b25uz X+8hRM6QANjtg9A8uxRmil4KyBnooR3E+H5VCQYgHK7t3M49pSd1RwsvinRJEEf X-Google-Smtp-Source: AGHT+IHIsU/u3tBigo6IljY3ksqOtejhOflhJneknqBt3azQrF7a0rP854priPpfPUa+G4NTHofa2w== X-Received: by 2002:a05:6512:3409:b0:542:250d:eefb with SMTP id 2adb3069b0e04-5439c281f66mr667438e87.41.1737110991596; Fri, 17 Jan 2025 02:49:51 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3072a3446c8sm3803321fa.27.2025.01.17.02.49.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 02:49:50 -0800 (PST) From: Dmitry Baryshkov Date: Fri, 17 Jan 2025 12:49:43 +0200 Subject: [PATCH 3/3] usb: typec: ucsi: acpi: move LG Gram quirk to ucsi_gram_sync_control() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250117-ucsi-merge-commands-v1-3-e20c19934d59@linaro.org> References: <20250117-ucsi-merge-commands-v1-0-e20c19934d59@linaro.org> In-Reply-To: <20250117-ucsi-merge-commands-v1-0-e20c19934d59@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org 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=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnijXG3uwtzwYp9Y+1h0WsxIqT/JBER6AauTSMD QvMcplbOs6JATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ4o1xgAKCRCLPIo+Aiko 1fWNB/9y4/CwN+TiuuFIuuGLLi6OOecOc8IM4nhdln3ahSo/r0f/iRuiv2BgDa3N0uqjsE+XKJb BNvkoJlft3sGt9QZQN2cJxkcahLO9v+SGcuhTHOLTzDhluZbXer0RMJtHjW7T0h/mwR2+qGpk3O 9iB5Dyeo+0CzJHRhwvYaM3clcKaYKWys8Dg8noovie/U4f1zQs4OMU6/gH1oQZkRrl/fNWcMYQq itzb4UVAdEbfU7pj/lobqj3YpOKX4s4WmfrbJo42VspQ3vKOXu3hb1dXodv5tclk5lV9x2oi6Vf wgHXOAm8arAa5ovC+PV42GwLiaizfaDshig54otthqWkEFJ/ 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 Reviewed-by: Heikki Krogerus --- 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/uc= si_acpi.c index 8b02082201ec5b85031472563b8b8d1eea6134de..ada5d0d21ee6fb1f406b6a8b846= 6bc71ffdb5b46 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 =3D { .async_control =3D ucsi_acpi_async_control }; =20 -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 =3D UCSI_CONSTAT_POWER_LEVEL_CHANGE | UCSI_CONSTAT_PDOS_CHANGE; struct ucsi_acpi *ua =3D ucsi_get_drvdata(ucsi); int ret; =20 - ret =3D ucsi_acpi_read_message_in(ucsi, val, val_len); + ret =3D ucsi_sync_control_common(ucsi, command, cci, val, len); if (ret < 0) return ret; =20 + if (UCSI_COMMAND(ua->cmd) =3D=3D UCSI_GET_PDOS && + ua->cmd & UCSI_GET_PDOS_PARTNER_PDO(1) && + ua->cmd & UCSI_GET_PDOS_SRC_PDOS) + ua->check_bogus_event =3D true; + if (UCSI_COMMAND(ua->cmd) =3D=3D 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 *ucs= i, void *val, size_t val_le return ret; } =20 -static int ucsi_gram_sync_control(struct ucsi *ucsi, u64 command, u32 *cci, - void *data, size_t size) -{ - struct ucsi_acpi *ua =3D ucsi_get_drvdata(ucsi); - int ret; - - ret =3D ucsi_sync_control_common(ucsi, command, cci, data, size); - if (ret < 0) - return ret; - - if (UCSI_COMMAND(ua->cmd) =3D=3D UCSI_GET_PDOS && - ua->cmd & UCSI_GET_PDOS_PARTNER_PDO(1) && - ua->cmd & UCSI_GET_PDOS_SRC_PDOS) - ua->check_bogus_event =3D true; - - return ret; -} - static const struct ucsi_operations ucsi_gram_ops =3D { .read_version =3D ucsi_acpi_read_version, .read_cci =3D ucsi_acpi_read_cci, - .read_message_in =3D ucsi_gram_read_message_in, + .read_message_in =3D ucsi_acpi_read_message_in, .sync_control =3D ucsi_gram_sync_control, .async_control =3D ucsi_acpi_async_control }; --=20 2.39.5