From patchwork Fri Jan 17 10:49:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13943217 Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (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 ED6FF1FC7EC for ; Fri, 17 Jan 2025 10:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110991; cv=none; b=XrmZBn1Nf93SjLPhxqJV8MxhjjkqsYuTJ4ErN1DoQrL8dJekAHtlUYxlkwhoKw8EA36SqV9fRbRgpi/OvmZCSu3PhxU14zHpDCfhZTZJCVsqE9XhfmviptTxteRejN87n5rOqY7UfxzZoDywfBDxAX+t4I/7KQlGxDqhao4Dt30= 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.170 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-f170.google.com with SMTP id 38308e7fff4ca-3072f8dc069so4145161fa.3 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=T71TW4LSdV98TTuXG05x52OrEpe1gIYjdoJX1LksUTb+dPEg0lXWCSusYajiJkSW8R t1tgFo0gs4mz1MiGs0FRqyqiY4HsAYBMfRTphn88JE05T7CETZZrMwZyL1Du4qBV2ITN k7smeIfxaqd0Bk/PS29PR4qeXl+d4MFhiSLW6XvupCT84nG0D1QGfnSMM6pjaHY8MvKd xooJwv3K3MeOgVM9yg1Kf4aiaXn9Xnhv6/nG4z9aFI9v9chAHj490ImWEeFV+svJAiji JxOGl5RVsWItKMSdohy4WRJh9KWqq/Ifikdg3EXAgkiwgX6zIodsPRHmQ9vevvcAGK2w UWBg== X-Gm-Message-State: AOJu0YzpyIIPmoroVfnfpkRVW2ePUZ8ULZmeWwWX8GduQ9j7MrtOJ4jd xZL86w9ONy8IS5NH5CvfsBu2eP19WDmV8b+nTFayd9HTQoCmHnTLpN5mnvt8FWx90UTYkSTi9Ba rFbE= X-Gm-Gg: ASbGnctmsn9+AR5MRNfctbl76Go2gwlSL7b0NvzU89JQ2WXsxx1qJScqAcVsIAZzswj oT3hV8905J3iRmGpNUOHRurrYR3RMc4k86PqTYnwirz6G8tidKv1Ep8QPW+N7QbyYPliMRihzq+ 0m/N81ndxryybmL9lfxIhGkctP1FC9f/yra9/UvgTaTMfipP8qHIQtrEv9pZ8N0ncEy6y6IK1Uj W31o6ixTy1wxSwknS+h+fy1RSjjUr5u1ocZkXegB0hz7i4Z4mLkq9TFcDmpOpv7 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-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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..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 Fri Jan 17 10:49:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13943218 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 5E0AE1FDE1B for ; Fri, 17 Jan 2025 10:49:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110993; cv=none; b=ZHLtXnOHGaOeGuXZerlma0S/PrQg5nL/wNtRj0Eh/8K42rPTOI54/py1VtZoFpcEb3cd9IEt2S+l/9rKjhDaFPQq9A4O+RNO7f5UFP0VoIK8Q004sH3D1kGEezCJyXtEzgjBc65giNnv4h5eMCxxPw9eQKGZFHy6gdUXxOdf/v4= 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.178 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-f178.google.com with SMTP id 38308e7fff4ca-3003d7ca01cso20164111fa.0 for ; Fri, 17 Jan 2025 02:49:50 -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=b5VBdHivQ5/IB5ZthxIxH45XKjp23h5QzVQeE5IAdMKP8waSYpwFCV7X61bZKAX121 8Z0The0L0BeqTHZEtDTIYw3ONt8CJUGOaukaX4gzEkQF/fpvi4fTQeKjNNRvwR+EI9+s dd5Ht5PyxjI0LuXZVeS0OlR15Yj9ks5CMUyM0aY9JI/qpnYocnsiloafhCmGIxtAy9lo h9uWPdCoaXZtrAJtlOur3PjRdXuR1MmhbW101In9cfIDLPLaotdEmqepHiE4EIzDfYc+ DY3I8WH43ocE66HK7M1+T9wnGGXBx5hO0JXVVQdTcCYNmH22TFTV98l1/MMEUe4RCazw FzgA== X-Gm-Message-State: AOJu0Yx1MbMcu2o//pqyOXhEvlgtgxIP9/YvpUt9blB0E6nCDmck4kPg SvR3b5C1IlR4g9uqQ13TE8UzL5GMaoux8/joyu0sy6Z/hQgivkLnlgbkQcfiWpY= X-Gm-Gg: ASbGncsqeXHRM5+g5A2SsS7Lx1ObskHjtkrzhrt/d11R/2iRrrI/ftAqD0/ClmWi66I 4YKmokP/h57duaa1274/OoK7ITtR0kFDDdxm7nUTtkndrphgfjKfSBSa8JD8LeBduYYxEPtzPZf k8aJL1PZNP7d15AburBDGwhbzR/QCcV0+1yxIlLdI+t915LYIfAXPLXxuTJ+JUYpyFGZbL6Vh3C mRI/wtm50PsgcXoU6PHIzITYdtUr4yx+mFM8Rk9HT+lzDpQjwyYxmD0vD1HwKy0 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-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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 Fri Jan 17 10:49: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: 13943219 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 7D7721FE456 for ; Fri, 17 Jan 2025 10:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110995; cv=none; b=aXFBYinJvOZWDVwbZ6JXvY3luKVaetKKp2vjcTEgRsMY15jav7jHBHPX6XyEdjebiinqU8fD8XpuCpmDywsxW5i3RCKuX7pWIRj5NfxIsygU34iuH2alxAoHAlQOe9l4feb1CiH82xVXB56cmssLIR1Q0+ELvnNgCn7vbnGuwpE= 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.43 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-f43.google.com with SMTP id 2adb3069b0e04-54026562221so2000006e87.1 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=tFtNQuSsoEZcpvMnxWLydz1Epx148KJaAdsEatddvRZ4mvVwMEHtnxO31/HbRIo1Le Dco2hKCQVyf8QNSJWBgmH0fevykliXNNDS/rOnR5BdtFfHxBxHnqpsvTYyXve2K6Ybk0 BAAglNqeS4HjsO/lUTZt7h3F2YY4bqav2MaaMWcK9LKoy5m+IXv4fIzZzvl6S2x94iul BW/9q2AWF6emfolT7bPTgqyXEAlAogFXvyrs1GeKQrqsFdnS8AER+TLwe07AkLiOULaZ ccrAMfdnX1nVJPdMMeguyp9x1J7WVYR+BwcWZPz1/gz2bSTiMxDPXGZs1RT7PHmAlw1B oZnQ== X-Gm-Message-State: AOJu0YzR5jXjumi/OigXecogn0S4LHKzPVx9YF1PJ8hPggo/65+2s32O FIWfp9upD8gGnBRACszJr8Mz9OuqPlV5geDNLJAtaRMB73BaXprP03i20W8POGg= X-Gm-Gg: ASbGncvV38K9ZQg1k1ojtKMYgP8FbKpKAwU/Qz70vCIHqF9XLxGEgg5qiKjQnwgdptd UzVcQXhJ84nAygwE190R1TUIwQ4n+W0qOmR4LAz7s6FZW8duxwfa3ROf7KnxgeiA+G+u7mYpbhw T61xV+6S6MXOKvPiP/7JFDln3D0IqdmEzGUFgKRN9Xgg7PdLAiJZ6YM3Nu+3YM6G34QKOkn/4LB evzFwknxG5Q1JDlaDbqzddLoEduiQePn3KZ7cBzm4Kc1o7tRPKDtkaeioHXMMgJ 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-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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 };