From patchwork Tue Jun 25 14:54:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13711298 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B8C82C2BBCA for ; Tue, 25 Jun 2024 14:54:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JAfmKGbaHSRN3BDyb2Ps0ChAgC9WErixxC6u5jSyHcs=; b=gbe8O0X1bD4RnCnn5V6SFrL0as 1azbSwSB+z9+ZfQi65FMbZoyBU9ycBFLvBSNLGJ4fgP/J24VFc3dGDzZ4D34JCUtLDe82AwQP/BMZ nSvPCJtxk4xomQm3iJgsGra5U2ONiXbaOV9ER7JY8fAi9u6LJX5Q/BX/G3Ed7QEow/DMtjCSYY5ME fxRHh7xmjdLlwkxl2GoxoXfx0p0Phaiuc4NpoRUnBynkDL884KSzcuZBnN7eCrSw0mcsy4TWFN6cx UKyINsE+z49xCvNGuMgj/BJc028ir9UCQAJ5JZRteRM0u+6u/dYEqutZtdfEgJR/q5AqseZpEh9HI qnzb173w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7ZA-00000003H0e-2kO4; Tue, 25 Jun 2024 14:54:40 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7Z2-00000003GvQ-2Ry2 for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 14:54:34 +0000 Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-52cd9f9505cso4608809e87.0 for ; Tue, 25 Jun 2024 07:54:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719327270; x=1719932070; darn=lists.infradead.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=JAfmKGbaHSRN3BDyb2Ps0ChAgC9WErixxC6u5jSyHcs=; b=u49abPHJDRgDyavZdVLfXJZsviRZSt53hHMoph5JCBQtsrWHWcZQxorj7nCu6YzVpT qetaAUdZMd5Lb3cE1pHi2QqUrKbyFvJEkgdqQi3fH5o34WTffKHCi8a1+dOG8vuvlKoO 0bkGGnAV3xUpREOoBwsTcg2Rz9VKqHtilzBE4O67kJnRhN7rAHbeyuk1ZtGOTFBbwiNS dL0m44jg7WSNa4fcPBs+9dn2oeouaqKZ5zM/mOmKawGkr9cyrMQaPdHrTrGT8RfU4vkK Kdr0e5+QXP4N5GV75Jz5BMuxLioZXnFqmEva7e56bHF09njILIAjWx19Y8K2Af+CafzR e62w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719327270; x=1719932070; 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=JAfmKGbaHSRN3BDyb2Ps0ChAgC9WErixxC6u5jSyHcs=; b=dtcz2WWozQIrpBqrZOR3W0LnqwjpbvkxyTD+nYYt9DgCktoWg/FmAsWa0yRj/oUH4x a6KRaHo5Gti+yPC9bsanMupVwIYBdOoKFwlsnVI6HmHJmFDJZsHPx57+HZjAQ7xkKQNE XPQmDTfyPqtNmT2o+pd5FruvIbDdL/aY1OYui0xplNZtG53cdmqzZv77UN6UgSMehj8I mYJvDRq/539KgeXlhfp1xnHhX0/PzxJZIgnTaj252dNrx/FX1tlZLKoKb9/+fcp13+Ur lkNpbvHoHWqneDLAkTpz9gaqbdhSpYD69yFi6y69XoobJsai3xU/9Ly1IndG0iYXRU1c ccRA== X-Forwarded-Encrypted: i=1; AJvYcCWntEO2ihDVd+BAXrqthqFezpCz/JWAod13OiK7vG0pOPmfxFsO5QlZUWtEGTNCKxTJdPXEI9q1tZ5lWh9kf7HXGfvZGQhDt6HI3ajdFYGzZKoFpWc= X-Gm-Message-State: AOJu0YxZeO8zkz1RyMFMDrPnszG7DNrvRgNicPv+XybZFYvklUmkIG9D esqAN8XAS2hyY1pCnuHUqGDHx4rQ1Ehv/IwtvbZTQOjaadY+VKwqMG5D/XrH36I= X-Google-Smtp-Source: AGHT+IGZFf/nSGa2e2d62pxL5I+qOFEUEnjG9EKzs41xvEO8rAlHlgWJuddbGqx0uxqUQDIYsbz3Rw== X-Received: by 2002:a05:6512:453:b0:52c:d943:300f with SMTP id 2adb3069b0e04-52cdf7f6705mr5392914e87.38.1719327270161; Tue, 25 Jun 2024 07:54:30 -0700 (PDT) Received: from umbar.lan ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd64328b7sm1251877e87.221.2024.06.25.07.54.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 07:54:29 -0700 (PDT) From: Dmitry Baryshkov Date: Tue, 25 Jun 2024 17:54:26 +0300 Subject: [PATCH v3 1/7] usb: typec: ucsi: move ucsi_acknowledge() from ucsi_read_error() MIME-Version: 1.0 Message-Id: <20240625-ucsi-rework-interface-v3-1-7a6c8e17be3a@linaro.org> References: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> In-Reply-To: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman , Maxime Coquelin , Alexandre Torgue Cc: Nikita Travkin , Neil Armstrong , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1294; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=E+vOJjv2UvdlrXvKnRgzVGWs8xl24PgUq84JxgbpN+M=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBmetojmtp4D7cmDhXFyPFb6rzvpO9SqHUmDn68o x84cE4DSNWJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZnraIwAKCRCLPIo+Aiko 1dsqB/wKU/73Da/F7fXX3mKihmmgqnEt8z5DsYc/2Ek86sZ2QOVH5pcoOyQjGE2tEHJM1A460DU fniZ9SvZ17LHTf335zpqrqK1baAzCc7as/KU5FPsnsANZRV0di+AWzepIIFaNaN3bkEDgvyhGv3 D9plJZY56ZqgzDBYL4OkX/69YyQk2ndc/DcQOa6sbOSLN+5tjeH9gnPwh9coPGY9Cf2n3auuqJz 1jSXserA6xSdR0TK2kuorPqnD+k9K6yufTUWdeB5SNheTQwuDx4uTO2SUb42q1522ZwVKmxA7Bp KSyWF53xjvQ5qHB3NY1c+iU9Gf62IqbUUg5WbVjtBFRAZ1HM X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_075432_702527_26DFCF46 X-CRM114-Status: GOOD ( 11.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org As a preparation for reworking UCSI command handling, move ucsi_acknowledge() for the failed command from ucsi_read_error() to ucsi_exec_command(). Signed-off-by: Dmitry Baryshkov --- drivers/usb/typec/ucsi/ucsi.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 76c48d873b2a..297d939e8da8 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -70,11 +70,6 @@ static int ucsi_read_error(struct ucsi *ucsi) u16 error; int ret; - /* Acknowledge the command that failed */ - ret = ucsi_acknowledge(ucsi, false); - if (ret) - return ret; - ret = ucsi_exec_command(ucsi, UCSI_GET_ERROR_STATUS); if (ret < 0) return ret; @@ -153,13 +148,14 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd) } if (cci & UCSI_CCI_ERROR) { - if (cmd == UCSI_GET_ERROR_STATUS) { - ret = ucsi_acknowledge(ucsi, false); - if (ret) - return ret; + /* Acknowledge the command that failed */ + ret = ucsi_acknowledge(ucsi, false); + if (ret) + return ret; + if (cmd == UCSI_GET_ERROR_STATUS) return -EIO; - } + return ucsi_read_error(ucsi); } From patchwork Tue Jun 25 14:54:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13711300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 38D16C3064D for ; Tue, 25 Jun 2024 14:54:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7LEiFtfgfs0Ngipd4ntmJnXIdkp4mmOLM3swdnA1V8U=; b=slz+4qNA2T7JSLClXM5acPyU6M noVnoGIdFq6PpUPoZwLYScRoY7dnE8bDVVFz6l00QBXtmjM1UKiQACxZ51yB3046ao+fu7ATxP1Qo 8OSTeL7whLHZh/ZPH0s8KtIk924XEp9RFOKaYpntCQ/XvbHRk9CfGpMRL3bHatGSEBMjlfRqgPzVc Wl+e0t+1w6u+ClzhPv7S6fnDJajQC9csYLAfkWjOZ0V7HjZ9dNfciLHqx187rcebCzMa1mDfuInS4 aoFNfb2FMK+gzlmbH3i3IkCIP6eKyHVO88xxZsUMj4UIiwAqg1ZIsKzDbxLlf7TtmFnMhc5ji6iVL CO4YEhbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7ZH-00000003H2S-0uEu; Tue, 25 Jun 2024 14:54:47 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7Z3-00000003GvU-0EYB for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 14:54:35 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-52cdf9f934fso3131828e87.1 for ; Tue, 25 Jun 2024 07:54:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719327271; x=1719932071; darn=lists.infradead.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=7LEiFtfgfs0Ngipd4ntmJnXIdkp4mmOLM3swdnA1V8U=; b=uAKoVddHzJaX4EZ/dzsRchVP6dIWLZqJhpkAa4D5/OdHdX1PQoBo6TD1r8U96WgtTG TDndMO6XLNeGopWnJRPFwe2yFxcDFGyUyhSV5IXlBHUdzWz0fcCtnPFGNoLO+1r8R3pQ mQAmTrZj8jNs5wkbkZPW3YGeGqz3mcFuAWr6XpFPnMVgWpPp8+8sTWaWdtb2rlKND9ko HDhg6fd8jqbkasOAczo0dikzXWZBvQNVJeO4upF7y8yeEuNPcHKAgxLRqR2CDUIYC4/r UEbEWy0MJvJF3yo91rTJqtJVzxf0kIgImG4iLs0JdhJ0jCeOhhU9ATxysuYOgG4E+KKv 9M+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719327271; x=1719932071; 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=7LEiFtfgfs0Ngipd4ntmJnXIdkp4mmOLM3swdnA1V8U=; b=u8+ID7sxOMZSl6iIit04ymOiufe0jlrFfEn8GVT5d8He5dhOIsEKvrXbyVAetLJr8g B/QxjttJmaoYL6nHK7Yt7KVm0gFjRY7lHazKQp4FFve+6u7whYozXWd2j47QWQKyV6dw ruUkAB2f529UIn/Wv6q9ATIv9oMx7DQlQNCWEge6xyW33WgayAngnGyWKaUYy7ROkgj0 DL0R5bEPM8XQt0Mxz6DCkZHlykEyqjBRsAelutw6+Bq2Pb+oL1MFcJM6qYs2Gdr6bckB HYs/IG5oxnamWhtzfeA/HE74meQ2foQSXI3qklUQ+P+LG0boSRi+fBALnly+eNnxbliL MLLg== X-Forwarded-Encrypted: i=1; AJvYcCXV6XpUPdLDwpIyLx0tKgHBajy3ZeugcvRTzp9QlLnhj9wMc9UKO773bmaU6btsF7lalmq9Y+OLhAVbxVBktLJw6GSze7kGIQMTD2sbWYrCNrl76YQ= X-Gm-Message-State: AOJu0YxRwWbHhGWBb1DBLADUs4p8HEetKVU62aN4NpdNF9d/0naKEteU slhWF3IO4sapZQp+rX2scAeOf4krp/UZD0iURMhyg2q1H4h0zzBRZq/9OxhPJ/Q= X-Google-Smtp-Source: AGHT+IFF6rSU92qoqZYqmPJ7GZVrJ4GdjaT3kYYiAox4XIiLATWxaA6Yqp82cc6AN1alytvjPcOf9w== X-Received: by 2002:a19:700d:0:b0:52c:df90:203b with SMTP id 2adb3069b0e04-52ce0680324mr4031473e87.56.1719327270943; Tue, 25 Jun 2024 07:54:30 -0700 (PDT) Received: from umbar.lan ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd64328b7sm1251877e87.221.2024.06.25.07.54.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 07:54:30 -0700 (PDT) From: Dmitry Baryshkov Date: Tue, 25 Jun 2024 17:54:27 +0300 Subject: [PATCH v3 2/7] usb: typec: ucsi: simplify command sending API MIME-Version: 1.0 Message-Id: <20240625-ucsi-rework-interface-v3-2-7a6c8e17be3a@linaro.org> References: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> In-Reply-To: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman , Maxime Coquelin , Alexandre Torgue Cc: Nikita Travkin , Neil Armstrong , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=17266; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=CEvbvB7gJ/H3MYji/elAM+3tUMhYqRgw3bCCMI7tq6c=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBmetojeYJ2SPPKAueLrxUGEqYqt29fy+1b8hmE9 AdjEIQc5zOJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZnraIwAKCRCLPIo+Aiko 1eolB/0RMUBUttUqaEx5AdUlrGhbzYzR91kJ7QFCP0NILdTtC52gZoHAeTDjXy8YEU7qDH3MdHZ 5+85mSqeIA89apvxJU0RQzYX4uQH913N+WuNHMj+KF4v+7ZF8CiD2mtMU1N0Y6ML8yq/TX1IstE JtSeuZFs6wEkUNCy57sPnm9dnOi9MQ7sBf4KvRSi6wt1oAOpw1GHn4tJmHj3hMmj+KoSIc3zAYe 2hk7+5DbYNHsT8OA3wsHcc4HdDwOopupWp6ZEMBCxENcwUEtki3rMXvBq+TA2z5aoofULPVPxUV Z7sokLiWNWi0jf3DyfPRuyhvC+2+R+IJpswDMqtItcftcZvi X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_075433_156040_2ABDEB94 X-CRM114-Status: GOOD ( 16.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The sync_write and async_write are used only for writing UCSI commands to the UCSI_CONTROL offsets. Rename sync_write and async_write operations to sync_control and async_control accordingly. Drop the offset and length fields and pass u64 command instead. Signed-off-by: Dmitry Baryshkov --- drivers/usb/typec/ucsi/ucsi.c | 18 +++++++---------- drivers/usb/typec/ucsi/ucsi.h | 10 ++++------ drivers/usb/typec/ucsi/ucsi_acpi.c | 31 ++++++++++++++---------------- drivers/usb/typec/ucsi/ucsi_ccg.c | 34 +++++++++++++++------------------ drivers/usb/typec/ucsi/ucsi_glink.c | 14 ++++++-------- drivers/usb/typec/ucsi/ucsi_stm32g0.c | 24 +++++++++++------------ drivers/usb/typec/ucsi/ucsi_yoga_c630.c | 20 +++++++------------ 7 files changed, 64 insertions(+), 87 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 297d939e8da8..52903eea7274 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -60,7 +60,7 @@ static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack) ctrl |= UCSI_ACK_CONNECTOR_CHANGE; } - return ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &ctrl, sizeof(ctrl)); + return ucsi->ops->sync_control(ucsi, ctrl); } static int ucsi_exec_command(struct ucsi *ucsi, u64 command); @@ -126,7 +126,7 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd) u32 cci; int ret; - ret = ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd)); + ret = ucsi->ops->sync_control(ucsi, cmd); if (ret) return ret; @@ -1321,8 +1321,7 @@ static int ucsi_reset_ppm(struct ucsi *ucsi) */ if (cci & UCSI_CCI_RESET_COMPLETE) { command = UCSI_SET_NOTIFICATION_ENABLE; - ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command, - sizeof(command)); + ret = ucsi->ops->async_control(ucsi, command); if (ret < 0) goto out; @@ -1343,8 +1342,7 @@ static int ucsi_reset_ppm(struct ucsi *ucsi) } command = UCSI_PPM_RESET; - ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command, - sizeof(command)); + ret = ucsi->ops->async_control(ucsi, command); if (ret < 0) goto out; @@ -1365,9 +1363,7 @@ static int ucsi_reset_ppm(struct ucsi *ucsi) /* If the PPM is still doing something else, reset it again. */ if (cci & ~UCSI_CCI_RESET_COMPLETE) { - ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, - &command, - sizeof(command)); + ret = ucsi->ops->async_control(ucsi, command); if (ret < 0) goto out; } @@ -1895,7 +1891,7 @@ struct ucsi *ucsi_create(struct device *dev, const struct ucsi_operations *ops) { struct ucsi *ucsi; - if (!ops || !ops->read || !ops->sync_write || !ops->async_write) + if (!ops || !ops->read || !ops->sync_control || !ops->async_control) return ERR_PTR(-EINVAL); ucsi = kzalloc(sizeof(*ucsi), GFP_KERNEL); @@ -1971,7 +1967,7 @@ void ucsi_unregister(struct ucsi *ucsi) cancel_work_sync(&ucsi->resume_work); /* Disable notifications */ - ucsi->ops->async_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd)); + ucsi->ops->async_control(ucsi, cmd); if (!ucsi->connector) return; diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 1280cac314fe..3ad64acffda1 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -57,8 +57,8 @@ struct dentry; /** * struct ucsi_operations - UCSI I/O operations * @read: Read operation - * @sync_write: Blocking write operation - * @async_write: Non-blocking write operation + * @sync_control: Blocking control operation + * @async_control: Non-blocking control operation * @update_altmodes: Squashes duplicate DP altmodes * @update_connector: Update connector capabilities before registering * @connector_status: Updates connector status, called holding connector lock @@ -70,10 +70,8 @@ struct dentry; struct ucsi_operations { int (*read)(struct ucsi *ucsi, unsigned int offset, void *val, size_t val_len); - int (*sync_write)(struct ucsi *ucsi, unsigned int offset, - const void *val, size_t val_len); - int (*async_write)(struct ucsi *ucsi, unsigned int offset, - const void *val, size_t val_len); + int (*sync_control)(struct ucsi *ucsi, u64 command); + int (*async_control)(struct ucsi *ucsi, u64 command); bool (*update_altmodes)(struct ucsi *ucsi, struct ucsi_altmode *orig, struct ucsi_altmode *updated); void (*update_connector)(struct ucsi_connector *con); diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c index adf32ca0f761..f54e4722d8f6 100644 --- a/drivers/usb/typec/ucsi/ucsi_acpi.c +++ b/drivers/usb/typec/ucsi/ucsi_acpi.c @@ -61,22 +61,20 @@ static int ucsi_acpi_read(struct ucsi *ucsi, unsigned int offset, return 0; } -static int ucsi_acpi_async_write(struct ucsi *ucsi, unsigned int offset, - const void *val, size_t val_len) +static int ucsi_acpi_async_control(struct ucsi *ucsi, u64 command) { struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); - memcpy(ua->base + offset, val, val_len); - ua->cmd = *(u64 *)val; + memcpy(ua->base + UCSI_CONTROL, &command, sizeof(command)); + ua->cmd = command; return ucsi_acpi_dsm(ua, UCSI_DSM_FUNC_WRITE); } -static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset, - const void *val, size_t val_len) +static int ucsi_acpi_sync_control(struct ucsi *ucsi, u64 command) { struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); - bool ack = UCSI_COMMAND(*(u64 *)val) == UCSI_ACK_CC_CI; + bool ack = UCSI_COMMAND(command) == UCSI_ACK_CC_CI; int ret; if (ack) @@ -84,7 +82,7 @@ static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset, else set_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags); - ret = ucsi_acpi_async_write(ucsi, offset, val, val_len); + ret = ucsi_acpi_async_control(ucsi, command); if (ret) goto out_clear_bit; @@ -102,8 +100,8 @@ static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset, static const struct ucsi_operations ucsi_acpi_ops = { .read = ucsi_acpi_read, - .sync_write = ucsi_acpi_sync_write, - .async_write = ucsi_acpi_async_write + .sync_control = ucsi_acpi_sync_control, + .async_control = ucsi_acpi_async_control }; static int @@ -125,8 +123,8 @@ ucsi_zenbook_read(struct ucsi *ucsi, unsigned int offset, void *val, size_t val_ static const struct ucsi_operations ucsi_zenbook_ops = { .read = ucsi_zenbook_read, - .sync_write = ucsi_acpi_sync_write, - .async_write = ucsi_acpi_async_write + .sync_control = ucsi_acpi_sync_control, + .async_control = ucsi_acpi_async_control }; static int ucsi_gram_read(struct ucsi *ucsi, unsigned int offset, @@ -157,13 +155,12 @@ static int ucsi_gram_read(struct ucsi *ucsi, unsigned int offset, return ret; } -static int ucsi_gram_sync_write(struct ucsi *ucsi, unsigned int offset, - const void *val, size_t val_len) +static int ucsi_gram_sync_control(struct ucsi *ucsi, u64 command) { struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); int ret; - ret = ucsi_acpi_sync_write(ucsi, offset, val, val_len); + ret = ucsi_acpi_sync_control(ucsi, command); if (ret < 0) return ret; @@ -177,8 +174,8 @@ static int ucsi_gram_sync_write(struct ucsi *ucsi, unsigned int offset, static const struct ucsi_operations ucsi_gram_ops = { .read = ucsi_gram_read, - .sync_write = ucsi_gram_sync_write, - .async_write = ucsi_acpi_async_write + .sync_control = ucsi_gram_sync_control, + .async_control = ucsi_acpi_async_control }; static const struct dmi_system_id ucsi_acpi_quirks[] = { diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index dda7c7c94e08..76b39bb9762d 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -610,25 +610,23 @@ static int ucsi_ccg_read(struct ucsi *ucsi, unsigned int offset, return ret; } -static int ucsi_ccg_async_write(struct ucsi *ucsi, unsigned int offset, - const void *val, size_t val_len) +static int ucsi_ccg_async_control(struct ucsi *ucsi, u64 command) { struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); - u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(offset); + u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(UCSI_CONTROL); /* - * UCSI may read CCI instantly after async_write, + * UCSI may read CCI instantly after async_control, * clear CCI to avoid caller getting wrong data before we get CCI from ISR */ spin_lock(&uc->op_lock); uc->op_data.cci = 0; spin_unlock(&uc->op_lock); - return ccg_write(uc, reg, val, val_len); + return ccg_write(uc, reg, (u8 *)&command, sizeof(command)); } -static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset, - const void *val, size_t val_len) +static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command) { struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); struct ucsi_connector *con; @@ -639,19 +637,17 @@ static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset, pm_runtime_get_sync(uc->dev); set_bit(DEV_CMD_PENDING, &uc->flags); - if (offset == UCSI_CONTROL && val_len == sizeof(uc->last_cmd_sent)) { - uc->last_cmd_sent = *(u64 *)val; + uc->last_cmd_sent = command; - if (UCSI_COMMAND(uc->last_cmd_sent) == UCSI_SET_NEW_CAM && - uc->has_multiple_dp) { - con_index = (uc->last_cmd_sent >> 16) & - UCSI_CMD_CONNECTOR_MASK; - con = &uc->ucsi->connector[con_index - 1]; - ucsi_ccg_update_set_new_cam_cmd(uc, con, (u64 *)val); - } + if (UCSI_COMMAND(uc->last_cmd_sent) == UCSI_SET_NEW_CAM && + uc->has_multiple_dp) { + con_index = (uc->last_cmd_sent >> 16) & + UCSI_CMD_CONNECTOR_MASK; + con = &uc->ucsi->connector[con_index - 1]; + ucsi_ccg_update_set_new_cam_cmd(uc, con, &command); } - ret = ucsi_ccg_async_write(ucsi, offset, val, val_len); + ret = ucsi_ccg_async_control(ucsi, command); if (ret) goto err_clear_bit; @@ -668,8 +664,8 @@ static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset, static const struct ucsi_operations ucsi_ccg_ops = { .read = ucsi_ccg_read, - .sync_write = ucsi_ccg_sync_write, - .async_write = ucsi_ccg_async_write, + .sync_control = ucsi_ccg_sync_control, + .async_control = ucsi_ccg_async_control, .update_altmodes = ucsi_ccg_update_altmodes }; diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c index 2fa973afe4e6..ebd76257c4fc 100644 --- a/drivers/usb/typec/ucsi/ucsi_glink.c +++ b/drivers/usb/typec/ucsi/ucsi_glink.c @@ -143,21 +143,19 @@ static int pmic_glink_ucsi_locked_write(struct pmic_glink_ucsi *ucsi, unsigned i return 0; } -static int pmic_glink_ucsi_async_write(struct ucsi *__ucsi, unsigned int offset, - const void *val, size_t val_len) +static int pmic_glink_ucsi_async_control(struct ucsi *__ucsi, u64 command) { struct pmic_glink_ucsi *ucsi = ucsi_get_drvdata(__ucsi); int ret; mutex_lock(&ucsi->lock); - ret = pmic_glink_ucsi_locked_write(ucsi, offset, val, val_len); + ret = pmic_glink_ucsi_locked_write(ucsi, UCSI_CONTROL, &command, sizeof(command)); mutex_unlock(&ucsi->lock); return ret; } -static int pmic_glink_ucsi_sync_write(struct ucsi *__ucsi, unsigned int offset, - const void *val, size_t val_len) +static int pmic_glink_ucsi_sync_control(struct ucsi *__ucsi, u64 command) { struct pmic_glink_ucsi *ucsi = ucsi_get_drvdata(__ucsi); unsigned long left; @@ -169,7 +167,7 @@ static int pmic_glink_ucsi_sync_write(struct ucsi *__ucsi, unsigned int offset, ucsi->sync_val = 0; reinit_completion(&ucsi->sync_ack); ucsi->sync_pending = true; - ret = pmic_glink_ucsi_locked_write(ucsi, offset, val, val_len); + ret = pmic_glink_ucsi_locked_write(ucsi, UCSI_CONTROL, &command, sizeof(command)); mutex_unlock(&ucsi->lock); left = wait_for_completion_timeout(&ucsi->sync_ack, 5 * HZ); @@ -217,8 +215,8 @@ static void pmic_glink_ucsi_connector_status(struct ucsi_connector *con) static const struct ucsi_operations pmic_glink_ucsi_ops = { .read = pmic_glink_ucsi_read, - .sync_write = pmic_glink_ucsi_sync_write, - .async_write = pmic_glink_ucsi_async_write, + .sync_control = pmic_glink_ucsi_sync_control, + .async_control = pmic_glink_ucsi_async_control, .update_connector = pmic_glink_ucsi_update_connector, .connector_status = pmic_glink_ucsi_connector_status, }; diff --git a/drivers/usb/typec/ucsi/ucsi_stm32g0.c b/drivers/usb/typec/ucsi/ucsi_stm32g0.c index ac69288e8bb0..396e2090e7c3 100644 --- a/drivers/usb/typec/ucsi/ucsi_stm32g0.c +++ b/drivers/usb/typec/ucsi/ucsi_stm32g0.c @@ -359,8 +359,7 @@ static int ucsi_stm32g0_read(struct ucsi *ucsi, unsigned int offset, void *val, return 0; } -static int ucsi_stm32g0_async_write(struct ucsi *ucsi, unsigned int offset, const void *val, - size_t len) +static int ucsi_stm32g0_async_control(struct ucsi *ucsi, u64 command) { struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); struct i2c_client *client = g0->client; @@ -373,19 +372,19 @@ static int ucsi_stm32g0_async_write(struct ucsi *ucsi, unsigned int offset, cons unsigned char *buf; int ret; - buf = kmalloc(len + 1, GFP_KERNEL); + buf = kmalloc(sizeof(command) + 1, GFP_KERNEL); if (!buf) return -ENOMEM; - buf[0] = offset; - memcpy(&buf[1], val, len); - msg[0].len = len + 1; + buf[0] = UCSI_CONTROL; + memcpy(&buf[1], &command, sizeof(command)); + msg[0].len = sizeof(command) + 1; msg[0].buf = buf; ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); kfree(buf); if (ret != ARRAY_SIZE(msg)) { - dev_err(g0->dev, "i2c write %02x, %02x error: %d\n", client->addr, offset, ret); + dev_err(g0->dev, "i2c write %02x, %02x error: %d\n", client->addr, UCSI_CONTROL, ret); return ret < 0 ? ret : -EIO; } @@ -393,11 +392,10 @@ static int ucsi_stm32g0_async_write(struct ucsi *ucsi, unsigned int offset, cons return 0; } -static int ucsi_stm32g0_sync_write(struct ucsi *ucsi, unsigned int offset, const void *val, - size_t len) +static int ucsi_stm32g0_sync_control(struct ucsi *ucsi, u64 command) { struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); - bool ack = UCSI_COMMAND(*(u64 *)val) == UCSI_ACK_CC_CI; + bool ack = UCSI_COMMAND(command) == UCSI_ACK_CC_CI; int ret; if (ack) @@ -405,7 +403,7 @@ static int ucsi_stm32g0_sync_write(struct ucsi *ucsi, unsigned int offset, const else set_bit(COMMAND_PENDING, &g0->flags); - ret = ucsi_stm32g0_async_write(ucsi, offset, val, len); + ret = ucsi_stm32g0_async_control(ucsi, command); if (ret) goto out_clear_bit; @@ -449,8 +447,8 @@ static irqreturn_t ucsi_stm32g0_irq_handler(int irq, void *data) static const struct ucsi_operations ucsi_stm32g0_ops = { .read = ucsi_stm32g0_read, - .sync_write = ucsi_stm32g0_sync_write, - .async_write = ucsi_stm32g0_async_write, + .sync_control = ucsi_stm32g0_sync_control, + .async_control = ucsi_stm32g0_async_control, }; static int ucsi_stm32g0_register(struct ucsi *ucsi) diff --git a/drivers/usb/typec/ucsi/ucsi_yoga_c630.c b/drivers/usb/typec/ucsi/ucsi_yoga_c630.c index 8bee0b469041..e5e8ba0c0eaa 100644 --- a/drivers/usb/typec/ucsi/ucsi_yoga_c630.c +++ b/drivers/usb/typec/ucsi/ucsi_yoga_c630.c @@ -56,23 +56,17 @@ static int yoga_c630_ucsi_read(struct ucsi *ucsi, unsigned int offset, } } -static int yoga_c630_ucsi_async_write(struct ucsi *ucsi, unsigned int offset, - const void *val, size_t val_len) +static int yoga_c630_ucsi_async_control(struct ucsi *ucsi, u64 command) { struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); - if (offset != UCSI_CONTROL || - val_len != YOGA_C630_UCSI_WRITE_SIZE) - return -EINVAL; - - return yoga_c630_ec_ucsi_write(uec->ec, val); + return yoga_c630_ec_ucsi_write(uec->ec, (u8*)&command); } -static int yoga_c630_ucsi_sync_write(struct ucsi *ucsi, unsigned int offset, - const void *val, size_t val_len) +static int yoga_c630_ucsi_sync_control(struct ucsi *ucsi, u64 command) { struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); - bool ack = UCSI_COMMAND(*(u64 *)val) == UCSI_ACK_CC_CI; + bool ack = UCSI_COMMAND(command) == UCSI_ACK_CC_CI; int ret; if (ack) @@ -82,7 +76,7 @@ static int yoga_c630_ucsi_sync_write(struct ucsi *ucsi, unsigned int offset, reinit_completion(&uec->complete); - ret = yoga_c630_ucsi_async_write(ucsi, offset, val, val_len); + ret = yoga_c630_ucsi_async_control(ucsi, command); if (ret) goto out_clear_bit; @@ -100,8 +94,8 @@ static int yoga_c630_ucsi_sync_write(struct ucsi *ucsi, unsigned int offset, const struct ucsi_operations yoga_c630_ucsi_ops = { .read = yoga_c630_ucsi_read, - .sync_write = yoga_c630_ucsi_sync_write, - .async_write = yoga_c630_ucsi_async_write, + .sync_control = yoga_c630_ucsi_sync_control, + .async_control = yoga_c630_ucsi_async_control, }; static void yoga_c630_ucsi_notify_ucsi(struct yoga_c630_ucsi *uec, u32 cci) From patchwork Tue Jun 25 14:54:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13711301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F3DAFC2BBCA for ; Tue, 25 Jun 2024 14:55:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JHzYKHNjBXf+9UzjvIdsaqBY3cbTBbTnQBUGbCvbkus=; b=lRDPNbQWLWMtQY1tBe1/majU4T bm0siWHuwrWb6xLrQUHCX71PEC2ftZ0BmfoxEhylKUS5uckFMkJx6ew1zPEL0/6PWM2MSg2o/yDHG s7j36CYvKqgrb3DU/jc02XnI2zBMwc4jbhIAwzYIMz2v41wrdv+Z2wx7SX1BMtipxvni35IlK8joG GJcWUF+4bh+BfMwN3VE6yMiBwZkJNP8S6q/6yaMGYYNQRUe1g5JuUuobJGlnVJ6bhoGxoyIpMo136 DrwGQOuUk1KMRkCi/6ws6Y/YDZTFKTvZgF5LkBNUhVvd89TTbaejBxLCsLyJn5RtePAWIF6L7lNMC 50VL273Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7ZL-00000003H54-24GH; Tue, 25 Jun 2024 14:54:51 +0000 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7Z5-00000003Gwx-1ADt for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 14:54:37 +0000 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-5295e488248so6429956e87.2 for ; Tue, 25 Jun 2024 07:54:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719327272; x=1719932072; darn=lists.infradead.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=JHzYKHNjBXf+9UzjvIdsaqBY3cbTBbTnQBUGbCvbkus=; b=fsDKegoic1cn2wyYLvmXjGfAlR2d9s5b/bou4UXDTKp3vfBdNTL4ODIq2t/Hz149WK Ol1ELJ8KaW7VzFNP80gIShUAxNdbvhYAgCf/sFDFJj96gB0/vhSZ0t4piRBQsOWkl8aM S7t1xRnZoRayiXit2ZSQRcSZTvZVJmPPjdsQCILaNrPHg9I+q/LaYy3+It0FmNIVQSv+ Ikuei6AJGXAEhr3kH3/lxQBXuyfLiinM3D1P9acaDHPhywmSo9uNrjBH0iBNMwJMtiLf lNEkrP+BgOGIanhJsv13vFu5S4FLiHiuTpSrQOv5sH4PHeAsq5DDed+e5YQNmENpSdIM Km8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719327272; x=1719932072; 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=JHzYKHNjBXf+9UzjvIdsaqBY3cbTBbTnQBUGbCvbkus=; b=LX5AVK8GR4bz5BB1WUHYkR7agHQDaro7B8Bq243O6dYrFbcsbnvs/JmwcBNpVwMJEH NPyc+OI8o7r3/bB5FSZEZ9+RzCt3alUqvJTRB0pqXBKd69+uContTAa7il4x2PuUUlqq bUvBWs+Vhn9UUTXO93nJXArENhBPJ4ZLOPnSqystVVfgiTf9qN0fdXyEGBxu3hjMfjss xJKjeHBG+y8xVg/rfnDronIB0qUIK/VadjZ/hTaIhFFiLeaPNWhdizTDgvSlEwH+sKuE uUfoaDq+a0r3tstmblVbafiA7y4fDctcQfmv4+2qv7yOd1OQIf3/gYBa0eQBYvJ54MhC ycNQ== X-Forwarded-Encrypted: i=1; AJvYcCVdFQmYjXnQhM2uwv22p8hig9mjJNKqDNa8O8+jKqKjdAISPZKqAfzwpe56UouMV8FARCXsPsnfeSCbpzFfk7JsZPDpGb/fFUT1FVCqGQnJdSj5hzs= X-Gm-Message-State: AOJu0Yzz3WLycTCBEyxQWVd0PZ9dawL10DKtlXbmJJEhagaeU+fDpq1E ocLWxcjt4zVKeHonvTiLFR/0PseKdyGczQrklRqG5EM8GRj6JjBM1MlcCe7FF7t9d6norZheMza hTKM= X-Google-Smtp-Source: AGHT+IGhqQ+VBKIxaQ2lp2Pfy14XvRHw9UB90ZVR4jtUgoXS1297PMq+RIWx0NHafF59+uQIKs23DQ== X-Received: by 2002:ac2:550d:0:b0:52c:e126:3d50 with SMTP id 2adb3069b0e04-52ce183bf44mr4231354e87.36.1719327271692; Tue, 25 Jun 2024 07:54:31 -0700 (PDT) Received: from umbar.lan ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd64328b7sm1251877e87.221.2024.06.25.07.54.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 07:54:31 -0700 (PDT) From: Dmitry Baryshkov Date: Tue, 25 Jun 2024 17:54:28 +0300 Subject: [PATCH v3 3/7] usb: typec: ucsi: split read operation MIME-Version: 1.0 Message-Id: <20240625-ucsi-rework-interface-v3-3-7a6c8e17be3a@linaro.org> References: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> In-Reply-To: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman , Maxime Coquelin , Alexandre Torgue Cc: Nikita Travkin , Neil Armstrong , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=16964; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=4wZHRHUTLDa+Ajur4pcLq9kjg9ZZkfOeNHnW5AjdB+U=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBmetojz5ODXJomc1rapxF2ktWVUz9a/WEel79T5 OixCXVC8qKJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZnraIwAKCRCLPIo+Aiko 1YChB/9blK+zkNFOWhPUzE/TGHcI/2rtvvJI4F2Rg9lNVf8REPX01zLsxS7WGfj3I0CoSHjDJBm KvwwE/ZRjiTrLYdW4RxTF97d6LJQF2O6lWpXemKOfr/teiJav76MobxTQia8x/EV2Zlgw2e0KHi 9z5a9a8P1IsN6lAYlX2k9C75bn249CnAHnvCvqwfoa5Ea42VBS0ytYxLq5AdJ8x1/fFSV/vDBKt JiXwyITWCxjt4AN96lIs+zUBXxZL7ty0pIT7AtSQHgtftxRsDc5+qQfO38CHTsQaSGoorM6fsqH zKb88YD2sw/SYq0opHpHiOeYUzEe1mykDNGcDbICfvbWdB03 X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_075435_521344_905F82B5 X-CRM114-Status: GOOD ( 20.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The read operation is only used to read fixed data at fixed offsets (UCSI_VERSION, UCSI_CCI, UCSI_MESSAGE_IN). In some cases drivers apply offset-specific overrides. Split the read() operation into three operations, read_version(), read_cci(), read_message_in(). Signed-off-by: Dmitry Baryshkov --- drivers/usb/typec/ucsi/ucsi.c | 20 ++++----- drivers/usb/typec/ucsi/ucsi.h | 9 +++-- drivers/usb/typec/ucsi/ucsi_acpi.c | 72 ++++++++++++++++++++++++++------- drivers/usb/typec/ucsi/ucsi_ccg.c | 50 ++++++++++++----------- drivers/usb/typec/ucsi/ucsi_glink.c | 19 ++++++++- drivers/usb/typec/ucsi/ucsi_stm32g0.c | 19 ++++++++- drivers/usb/typec/ucsi/ucsi_yoga_c630.c | 52 +++++++++++++++--------- 7 files changed, 169 insertions(+), 72 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 52903eea7274..db25f51ff71d 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -46,7 +46,7 @@ static int ucsi_read_message_in(struct ucsi *ucsi, void *buf, if (ucsi->version <= UCSI_VERSION_1_2) buf_size = clamp(buf_size, 0, 16); - return ucsi->ops->read(ucsi, UCSI_MESSAGE_IN, buf, buf_size); + return ucsi->ops->read_message_in(ucsi, buf, buf_size); } static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack) @@ -130,7 +130,7 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd) if (ret) return ret; - ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci)); + ret = ucsi->ops->read_cci(ucsi, &cci); if (ret) return ret; @@ -1309,7 +1309,7 @@ static int ucsi_reset_ppm(struct ucsi *ucsi) mutex_lock(&ucsi->ppm_lock); - ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci)); + ret = ucsi->ops->read_cci(ucsi, &cci); if (ret < 0) goto out; @@ -1327,8 +1327,7 @@ static int ucsi_reset_ppm(struct ucsi *ucsi) tmo = jiffies + msecs_to_jiffies(UCSI_TIMEOUT_MS); do { - ret = ucsi->ops->read(ucsi, UCSI_CCI, - &cci, sizeof(cci)); + ret = ucsi->ops->read_cci(ucsi, &cci); if (ret < 0) goto out; if (cci & UCSI_CCI_COMMAND_COMPLETE) @@ -1357,7 +1356,7 @@ static int ucsi_reset_ppm(struct ucsi *ucsi) /* Give the PPM time to process a reset before reading CCI */ msleep(20); - ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci)); + ret = ucsi->ops->read_cci(ucsi, &cci); if (ret) goto out; @@ -1777,7 +1776,7 @@ static int ucsi_init(struct ucsi *ucsi) ucsi->ntfy = ntfy; mutex_lock(&ucsi->ppm_lock); - ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci)); + ret = ucsi->ops->read_cci(ucsi, &cci); mutex_unlock(&ucsi->ppm_lock); if (ret) return ret; @@ -1891,7 +1890,9 @@ struct ucsi *ucsi_create(struct device *dev, const struct ucsi_operations *ops) { struct ucsi *ucsi; - if (!ops || !ops->read || !ops->sync_control || !ops->async_control) + if (!ops || + !ops->read_version || !ops->read_cci || !ops->read_message_in || + !ops->sync_control || !ops->async_control) return ERR_PTR(-EINVAL); ucsi = kzalloc(sizeof(*ucsi), GFP_KERNEL); @@ -1927,8 +1928,7 @@ int ucsi_register(struct ucsi *ucsi) { int ret; - ret = ucsi->ops->read(ucsi, UCSI_VERSION, &ucsi->version, - sizeof(ucsi->version)); + ret = ucsi->ops->read_version(ucsi, &ucsi->version); if (ret) return ret; diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 3ad64acffda1..5c5a8c63090d 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -56,7 +56,9 @@ struct dentry; /** * struct ucsi_operations - UCSI I/O operations - * @read: Read operation + * @read_version: Read implemented UCSI version + * @read_cci: Read CCI register + * @read_message_in: Read message data from UCSI * @sync_control: Blocking control operation * @async_control: Non-blocking control operation * @update_altmodes: Squashes duplicate DP altmodes @@ -68,8 +70,9 @@ struct dentry; * return immediately after sending the data to the PPM. */ struct ucsi_operations { - int (*read)(struct ucsi *ucsi, unsigned int offset, - void *val, size_t val_len); + 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 (*async_control)(struct ucsi *ucsi, u64 command); bool (*update_altmodes)(struct ucsi *ucsi, struct ucsi_altmode *orig, diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c index f54e4722d8f6..3660dc3e6d32 100644 --- a/drivers/usb/typec/ucsi/ucsi_acpi.c +++ b/drivers/usb/typec/ucsi/ucsi_acpi.c @@ -46,8 +46,7 @@ static int ucsi_acpi_dsm(struct ucsi_acpi *ua, int func) return 0; } -static int ucsi_acpi_read(struct ucsi *ucsi, unsigned int offset, - void *val, size_t val_len) +static int ucsi_acpi_read_version(struct ucsi *ucsi, u16 *version) { struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); int ret; @@ -56,7 +55,35 @@ static int ucsi_acpi_read(struct ucsi *ucsi, unsigned int offset, if (ret) return ret; - memcpy(val, ua->base + offset, val_len); + memcpy(version, ua->base + UCSI_VERSION, sizeof(*version)); + + return 0; +} + +static int ucsi_acpi_read_cci(struct ucsi *ucsi, u32 *cci) +{ + struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); + int ret; + + ret = ucsi_acpi_dsm(ua, UCSI_DSM_FUNC_READ); + if (ret) + return ret; + + memcpy(cci, ua->base + UCSI_CCI, sizeof(*cci)); + + return 0; +} + +static int ucsi_acpi_read_message_in(struct ucsi *ucsi, void *val, size_t val_len) +{ + struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); + int ret; + + ret = ucsi_acpi_dsm(ua, UCSI_DSM_FUNC_READ); + if (ret) + return ret; + + memcpy(val, ua->base + UCSI_MESSAGE_IN, val_len); return 0; } @@ -99,36 +126,50 @@ static int ucsi_acpi_sync_control(struct ucsi *ucsi, u64 command) } static const struct ucsi_operations ucsi_acpi_ops = { - .read = ucsi_acpi_read, + .read_version = ucsi_acpi_read_version, + .read_cci = ucsi_acpi_read_cci, + .read_message_in = ucsi_acpi_read_message_in, .sync_control = ucsi_acpi_sync_control, .async_control = ucsi_acpi_async_control }; static int -ucsi_zenbook_read(struct ucsi *ucsi, unsigned int offset, void *val, size_t val_len) +ucsi_zenbook_read_cci(struct ucsi *ucsi, u32 *cci) { struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); int ret; - if (offset == UCSI_VERSION || UCSI_COMMAND(ua->cmd) == UCSI_PPM_RESET) { + if (UCSI_COMMAND(ua->cmd) == UCSI_PPM_RESET) { ret = ucsi_acpi_dsm(ua, UCSI_DSM_FUNC_READ); if (ret) return ret; } - memcpy(val, ua->base + offset, val_len); + memcpy(cci, ua->base + UCSI_CCI, sizeof(*cci)); + + return 0; +} + +static int +ucsi_zenbook_read_message_in(struct ucsi *ucsi, void *val, size_t val_len) +{ + struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); + + /* UCSI_MESSAGE_IN is never read for PPM_RESET, return stored data */ + memcpy(val, ua->base + UCSI_MESSAGE_IN, val_len); return 0; } static const struct ucsi_operations ucsi_zenbook_ops = { - .read = ucsi_zenbook_read, + .read_version = ucsi_acpi_read_version, + .read_cci = ucsi_zenbook_read_cci, + .read_message_in = ucsi_zenbook_read_message_in, .sync_control = ucsi_acpi_sync_control, .async_control = ucsi_acpi_async_control }; -static int ucsi_gram_read(struct ucsi *ucsi, unsigned int offset, - void *val, size_t val_len) +static int ucsi_gram_read_message_in(struct ucsi *ucsi, void *val, size_t val_len) { u16 bogus_change = UCSI_CONSTAT_POWER_LEVEL_CHANGE | UCSI_CONSTAT_PDOS_CHANGE; @@ -136,13 +177,12 @@ static int ucsi_gram_read(struct ucsi *ucsi, unsigned int offset, struct ucsi_connector_status *status; int ret; - ret = ucsi_acpi_read(ucsi, offset, val, val_len); + ret = ucsi_acpi_read_message_in(ucsi, val, val_len); if (ret < 0) return ret; if (UCSI_COMMAND(ua->cmd) == UCSI_GET_CONNECTOR_STATUS && - test_bit(UCSI_ACPI_CHECK_BOGUS_EVENT, &ua->flags) && - offset == UCSI_MESSAGE_IN) { + test_bit(UCSI_ACPI_CHECK_BOGUS_EVENT, &ua->flags)) { status = (struct ucsi_connector_status *)val; /* Clear the bogus change */ @@ -173,7 +213,9 @@ static int ucsi_gram_sync_control(struct ucsi *ucsi, u64 command) } static const struct ucsi_operations ucsi_gram_ops = { - .read = ucsi_gram_read, + .read_version = ucsi_acpi_read_version, + .read_cci = ucsi_acpi_read_cci, + .read_message_in = ucsi_gram_read_message_in, .sync_control = ucsi_gram_sync_control, .async_control = ucsi_acpi_async_control }; @@ -203,7 +245,7 @@ static void ucsi_acpi_notify(acpi_handle handle, u32 event, void *data) u32 cci; int ret; - ret = ua->ucsi->ops->read(ua->ucsi, UCSI_CCI, &cci, sizeof(cci)); + ret = ua->ucsi->ops->read_cci(ua->ucsi, &cci); if (ret) return; diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index 76b39bb9762d..6ccc394f268e 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -556,32 +556,34 @@ static void ucsi_ccg_nvidia_altmode(struct ucsi_ccg *uc, } } -static int ucsi_ccg_read(struct ucsi *ucsi, unsigned int offset, - void *val, size_t val_len) +static int ucsi_ccg_read_version(struct ucsi *ucsi, u16 *version) { struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); - u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(offset); - struct ucsi_capability *cap; - struct ucsi_altmode *alt; - int ret = 0; + u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(UCSI_VERSION); - if (offset == UCSI_CCI) { - spin_lock(&uc->op_lock); - memcpy(val, &(uc->op_data).cci, val_len); - spin_unlock(&uc->op_lock); - } else if (offset == UCSI_MESSAGE_IN) { - spin_lock(&uc->op_lock); - memcpy(val, &(uc->op_data).message_in, val_len); - spin_unlock(&uc->op_lock); - } else { - ret = ccg_read(uc, reg, val, val_len); - } + return ccg_read(uc, reg, (u8 *)version, sizeof(*version)); +} - if (ret) - return ret; +static int ucsi_ccg_read_cci(struct ucsi *ucsi, u32 *cci) +{ + struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); - if (offset != UCSI_MESSAGE_IN) - return ret; + spin_lock(&uc->op_lock); + *cci = uc->op_data.cci; + spin_unlock(&uc->op_lock); + + return 0; +} + +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: @@ -607,7 +609,7 @@ static int ucsi_ccg_read(struct ucsi *ucsi, unsigned int offset, } uc->last_cmd_sent = 0; - return ret; + return 0; } static int ucsi_ccg_async_control(struct ucsi *ucsi, u64 command) @@ -663,7 +665,9 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command) } static const struct ucsi_operations ucsi_ccg_ops = { - .read = ucsi_ccg_read, + .read_version = ucsi_ccg_read_version, + .read_cci = ucsi_ccg_read_cci, + .read_message_in = ucsi_ccg_read_message_in, .sync_control = ucsi_ccg_sync_control, .async_control = ucsi_ccg_async_control, .update_altmodes = ucsi_ccg_update_altmodes diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c index ebd76257c4fc..56bad054e78f 100644 --- a/drivers/usb/typec/ucsi/ucsi_glink.c +++ b/drivers/usb/typec/ucsi/ucsi_glink.c @@ -114,6 +114,21 @@ static int pmic_glink_ucsi_read(struct ucsi *__ucsi, unsigned int offset, return ret; } +static int pmic_glink_ucsi_read_version(struct ucsi *ucsi, u16 *version) +{ + return pmic_glink_ucsi_read(ucsi, UCSI_VERSION, version, sizeof(*version)); +} + +static int pmic_glink_ucsi_read_cci(struct ucsi *ucsi, u32 *cci) +{ + return pmic_glink_ucsi_read(ucsi, UCSI_CCI, cci, sizeof(*cci)); +} + +static int pmic_glink_ucsi_read_message_in(struct ucsi *ucsi, void *val, size_t val_len) +{ + return pmic_glink_ucsi_read(ucsi, UCSI_MESSAGE_IN, val, val_len); +} + static int pmic_glink_ucsi_locked_write(struct pmic_glink_ucsi *ucsi, unsigned int offset, const void *val, size_t val_len) { @@ -214,7 +229,9 @@ static void pmic_glink_ucsi_connector_status(struct ucsi_connector *con) } static const struct ucsi_operations pmic_glink_ucsi_ops = { - .read = pmic_glink_ucsi_read, + .read_version = pmic_glink_ucsi_read_version, + .read_cci = pmic_glink_ucsi_read_cci, + .read_message_in = pmic_glink_ucsi_read_message_in, .sync_control = pmic_glink_ucsi_sync_control, .async_control = pmic_glink_ucsi_async_control, .update_connector = pmic_glink_ucsi_update_connector, diff --git a/drivers/usb/typec/ucsi/ucsi_stm32g0.c b/drivers/usb/typec/ucsi/ucsi_stm32g0.c index 396e2090e7c3..14737ca3724c 100644 --- a/drivers/usb/typec/ucsi/ucsi_stm32g0.c +++ b/drivers/usb/typec/ucsi/ucsi_stm32g0.c @@ -359,6 +359,21 @@ static int ucsi_stm32g0_read(struct ucsi *ucsi, unsigned int offset, void *val, return 0; } +static int ucsi_stm32g0_read_version(struct ucsi *ucsi, u16 *version) +{ + return ucsi_stm32g0_read(ucsi, UCSI_VERSION, version, sizeof(*version)); +} + +static int ucsi_stm32g0_read_cci(struct ucsi *ucsi, u32 *cci) +{ + return ucsi_stm32g0_read(ucsi, UCSI_CCI, cci, sizeof(*cci)); +} + +static int ucsi_stm32g0_read_message_in(struct ucsi *ucsi, void *val, size_t len) +{ + return ucsi_stm32g0_read(ucsi, UCSI_MESSAGE_IN, val, len); +} + static int ucsi_stm32g0_async_control(struct ucsi *ucsi, u64 command) { struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); @@ -446,7 +461,9 @@ static irqreturn_t ucsi_stm32g0_irq_handler(int irq, void *data) } static const struct ucsi_operations ucsi_stm32g0_ops = { - .read = ucsi_stm32g0_read, + .read_version = ucsi_stm32g0_read_version, + .read_cci = ucsi_stm32g0_read_cci, + .read_message_in = ucsi_stm32g0_read_message_in, .sync_control = ucsi_stm32g0_sync_control, .async_control = ucsi_stm32g0_async_control, }; diff --git a/drivers/usb/typec/ucsi/ucsi_yoga_c630.c b/drivers/usb/typec/ucsi/ucsi_yoga_c630.c index e5e8ba0c0eaa..95a333ad5496 100644 --- a/drivers/usb/typec/ucsi/ucsi_yoga_c630.c +++ b/drivers/usb/typec/ucsi/ucsi_yoga_c630.c @@ -27,8 +27,16 @@ struct yoga_c630_ucsi { u16 version; }; -static int yoga_c630_ucsi_read(struct ucsi *ucsi, unsigned int offset, - void *val, size_t val_len) +static int yoga_c630_ucsi_read_version(struct ucsi *ucsi, u16 *version) +{ + struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); + + *version = uec->version; + + return 0; +} + +static int yoga_c630_ucsi_read_cci(struct ucsi *ucsi, u32 *cci) { struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); u8 buf[YOGA_C630_UCSI_READ_SIZE]; @@ -38,22 +46,26 @@ static int yoga_c630_ucsi_read(struct ucsi *ucsi, unsigned int offset, if (ret) return ret; - if (offset == UCSI_VERSION) { - memcpy(val, &uec->version, min(val_len, sizeof(uec->version))); - return 0; - } + memcpy(cci, buf, sizeof(*cci)); - switch (offset) { - case UCSI_CCI: - memcpy(val, buf, min(val_len, YOGA_C630_UCSI_CCI_SIZE)); - return 0; - case UCSI_MESSAGE_IN: - memcpy(val, buf + YOGA_C630_UCSI_CCI_SIZE, - min(val_len, YOGA_C630_UCSI_DATA_SIZE)); - return 0; - default: - return -EINVAL; - } + return 0; +} + +static int yoga_c630_ucsi_read_message_in(struct ucsi *ucsi, + void *val, size_t val_len) +{ + struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); + u8 buf[YOGA_C630_UCSI_READ_SIZE]; + int ret; + + ret = yoga_c630_ec_ucsi_read(uec->ec, buf); + if (ret) + return ret; + + memcpy(val, buf + YOGA_C630_UCSI_CCI_SIZE, + min(val_len, YOGA_C630_UCSI_DATA_SIZE)); + + return 0; } static int yoga_c630_ucsi_async_control(struct ucsi *ucsi, u64 command) @@ -93,7 +105,9 @@ static int yoga_c630_ucsi_sync_control(struct ucsi *ucsi, u64 command) } const struct ucsi_operations yoga_c630_ucsi_ops = { - .read = yoga_c630_ucsi_read, + .read_version = yoga_c630_ucsi_read_version, + .read_cci = yoga_c630_ucsi_read_cci, + .read_message_in = yoga_c630_ucsi_read_message_in, .sync_control = yoga_c630_ucsi_sync_control, .async_control = yoga_c630_ucsi_async_control, }; @@ -126,7 +140,7 @@ static int yoga_c630_ucsi_notify(struct notifier_block *nb, return NOTIFY_OK; case LENOVO_EC_EVENT_UCSI: - ret = uec->ucsi->ops->read(uec->ucsi, UCSI_CCI, &cci, sizeof(cci)); + ret = uec->ucsi->ops->read_cci(uec->ucsi, &cci); if (ret) return NOTIFY_DONE; From patchwork Tue Jun 25 14:54:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13711302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4091FC30658 for ; Tue, 25 Jun 2024 14:55:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+KB8pq5NQAZ6n/rTI4y8OIrQXRuJ/BDLkN3YelnKCzI=; b=cu+8odCZqwEhBs+yn2bG68R7tn y88Qvzzzu68W1ofT/VoZIZUe/iTElTn2N6zwXHHP9OMwMhs3P4HHKHSbhtyDhIdP7Z6vmL6ME8a6i F+74qQRPwDoI5/x8njTi7ePj39PJdASPEFFTxeEVFnAhSzD4Ub6r62AeoxNpxccR+Hmunwurd5acs 2vpp3+RmxYvIH0R9GcJ/oEBsBMst5qwljFHejwZwmz51hvvSbnwr5pvql1J6/6K8Q5dIN3l+XAStg ga+oSyapFID0SFrIbGEdDmJq6F3l4GRuC6JBNNf0Boc3qGkSRRZISkz/tBqV02XHB86ixM23nkTwG rVBbF1Hg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7ZQ-00000003H8i-32RI; Tue, 25 Jun 2024 14:54:56 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7Z5-00000003GxH-3DK6 for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 14:54:38 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-52ce674da85so2379635e87.2 for ; Tue, 25 Jun 2024 07:54:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719327273; x=1719932073; darn=lists.infradead.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=+KB8pq5NQAZ6n/rTI4y8OIrQXRuJ/BDLkN3YelnKCzI=; b=q9vVm1k2NLyg07UEuEZlOlGcjukFIhB5xsEF5g2GFVz4qMFVbZJ7uabr1z9nFcQxRZ txBgnahVKPE/NveBLaaXyC/Jqn94y15TsQ4hstbLm/dil7d9h+rY/Pbf57hp3Tt53Viu VDHf5eF7Mi5J9wYz1oI/Uh/NS6xCQtLZ379dc9Fl5HqIuf1/U7+IOQeG2ALjJcGEmQm6 IjKkVS36w9YYiNjHeU47zVsW9vmItqlwdflYZ1d830UMyTK0Z0fsv5wjs36veH7Wc/nT AWt7KNmb6Zm3SvjD2i2h5njnTqNnS9wzGijKXm6l4+FrYbHmPgb1E0HFhg7zFZsfZzxP t5mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719327273; x=1719932073; 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=+KB8pq5NQAZ6n/rTI4y8OIrQXRuJ/BDLkN3YelnKCzI=; b=V/PeI8Uur+O4/THNiQwYigb1eDk7gTelJq9/z6/x7xUn1D4O1vjpZ3QcktbmArwJmL FqSyN6iTM+xcglPi7cs/kVZPtcNHVQJ8bAm9ciEOwDkLNhcFzZSJFHTN4IHolkF8a2nV PaqWCMGHYqu8DV9ULf4MtLnyyOPXIws1xax1TZpxSokxR08YjnpCMVX/vfxA2mSxgEvF P41pc/g9edFPC2YLWDoaqXmZuPfaBHmqGhF/vploQo9ZGHZRp8hfYRORsgTfrl2HW9at ANfUb3KX8WSNIJNOiOZv5voNFrGm9SnFkUHMMFeSWbnasi9rV2aFRV2k2FRiRGCbJHU9 mbsA== X-Forwarded-Encrypted: i=1; AJvYcCXrRc+Ywx9QonVcJoJCmukZ8BTR1vChkj4n3GvUywShzh6sIquf/cfzybcaCo3AXsMAvqYWJdB8FubnUsEUgru035T3gC52v/iY2jd8hF/HN3ESqc0= X-Gm-Message-State: AOJu0YwlR7kJZMCLxJ6AsSJz7H+IzL1tyCG1+HrEdAZjIh7tmL7H4wk2 piAcda73yf4N7bwbUx6pjZeT5Ju5XgR1fphn6VyPb/AcLmt7x5GcIrhWPgygmdQ= X-Google-Smtp-Source: AGHT+IGtQxo5jV6cMwfXqOOOPD8YZNEebt3pWP+GVzXLpNydBk0U1gGSF/EvGWsWZGvWy6VumzOMyA== X-Received: by 2002:ac2:58f4:0:b0:52c:dacf:e5ac with SMTP id 2adb3069b0e04-52ce185d218mr5415211e87.54.1719327273412; Tue, 25 Jun 2024 07:54:33 -0700 (PDT) Received: from umbar.lan ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd64328b7sm1251877e87.221.2024.06.25.07.54.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 07:54:32 -0700 (PDT) From: Dmitry Baryshkov Date: Tue, 25 Jun 2024 17:54:29 +0300 Subject: [PATCH v3 4/7] usb: typec: ucsi: rework command execution functions MIME-Version: 1.0 Message-Id: <20240625-ucsi-rework-interface-v3-4-7a6c8e17be3a@linaro.org> References: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> In-Reply-To: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman , Maxime Coquelin , Alexandre Torgue Cc: Nikita Travkin , Neil Armstrong , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4449; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=iGz/1CTodFFLxhp6bKYq0V9qXiKSF7JlfOGZtn0n3AI=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBmetojsGNpr741Om5LXvH7sB4VKPc9Jwl3kjr86 7L8QXP96iqJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZnraIwAKCRCLPIo+Aiko 1WCzCACcWhUjxOL5ffytSZW+F/ypklLcxsDF6YxBlJcdE7up+io2SCqomp/iKmX+5dY/ORLmd66 lJuECdbPx9ngWe/pTO+CJNJYrH/dMWh81YM5i2PFb8n73II9/yqhxJmdrhlsw2LgK7If03UgJ2+ k+iO+dPgvCxceKi4Y0cN36dzDSztbdn1k2lHng2/DUhrTuUPscI8g120u9GusllZQ+D8YZjhBuo rUBkA3HL1EDs5Z0URtChJIRQ7i6Vots9o3vGO35gdat2BHFsIzzFeHrLvwp8vV5bQ0mLZVCxQ95 jS/FEKz7Q4a/a0K7/6AjoUN9hZ3Uf0r86rV6mYKJDAiL2jh5 X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_075435_914756_9B888D07 X-CRM114-Status: GOOD ( 15.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Rework command execution code to remove recursive calls of ucsi_exec_command. This also streamlines the sync_control / read(CCI) read (MESSAGE_IN) sequence, allowing further rework of the command code. Signed-off-by: Dmitry Baryshkov --- drivers/usb/typec/ucsi/ucsi.c | 134 ++++++++++++++++++++---------------------- 1 file changed, 64 insertions(+), 70 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index db25f51ff71d..5f8e5ed9e0f9 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -63,25 +63,74 @@ static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack) return ucsi->ops->sync_control(ucsi, ctrl); } -static int ucsi_exec_command(struct ucsi *ucsi, u64 command); - -static int ucsi_read_error(struct ucsi *ucsi) +static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, + void *data, size_t size, bool conn_ack) { - u16 error; int ret; - ret = ucsi_exec_command(ucsi, UCSI_GET_ERROR_STATUS); - if (ret < 0) + *cci = 0; + + ret = ucsi->ops->sync_control(ucsi, command); + if (ret) return ret; - ret = ucsi_read_message_in(ucsi, &error, sizeof(error)); + ret = ucsi->ops->read_cci(ucsi, cci); if (ret) return ret; - ret = ucsi_acknowledge(ucsi, false); + if (*cci & UCSI_CCI_BUSY) + return -EBUSY; + + if (!(*cci & UCSI_CCI_COMMAND_COMPLETE)) + return -EIO; + + if (*cci & UCSI_CCI_NOT_SUPPORTED) { + if (ucsi_acknowledge(ucsi, false) < 0) + dev_err(ucsi->dev, + "ACK of unsupported command failed\n"); + return -EOPNOTSUPP; + } + + if (*cci & UCSI_CCI_ERROR) { + /* Acknowledge the command that failed */ + ret = ucsi_acknowledge(ucsi, false); + return ret ? ret : -EIO; + } + + if (data) { + ret = ucsi_read_message_in(ucsi, data, size); + if (ret) + return ret; + } + + ret = ucsi_acknowledge(ucsi, conn_ack); if (ret) return ret; + return 0; +} + +static int ucsi_read_error(struct ucsi *ucsi) +{ + u16 error; + u32 cci; + int ret; + + ret = ucsi_run_command(ucsi, UCSI_GET_ERROR_STATUS, &cci, + &error, sizeof(error), false); + + if (cci & UCSI_CCI_BUSY) { + ret = ucsi_run_command(ucsi, UCSI_CANCEL, &cci, NULL, 0, false); + + return ret ? ret : -EBUSY; + } + + if (ret < 0) + return ret; + + if (cci & UCSI_CCI_ERROR) + return -EIO; + switch (error) { case UCSI_ERROR_INCOMPATIBLE_PARTNER: return -EOPNOTSUPP; @@ -121,78 +170,23 @@ static int ucsi_read_error(struct ucsi *ucsi) return -EIO; } -static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd) -{ - u32 cci; - int ret; - - ret = ucsi->ops->sync_control(ucsi, cmd); - if (ret) - return ret; - - ret = ucsi->ops->read_cci(ucsi, &cci); - if (ret) - return ret; - - if (cmd != UCSI_CANCEL && cci & UCSI_CCI_BUSY) - return ucsi_exec_command(ucsi, UCSI_CANCEL); - - if (!(cci & UCSI_CCI_COMMAND_COMPLETE)) - return -EIO; - - if (cci & UCSI_CCI_NOT_SUPPORTED) { - if (ucsi_acknowledge(ucsi, false) < 0) - dev_err(ucsi->dev, - "ACK of unsupported command failed\n"); - return -EOPNOTSUPP; - } - - if (cci & UCSI_CCI_ERROR) { - /* Acknowledge the command that failed */ - ret = ucsi_acknowledge(ucsi, false); - if (ret) - return ret; - - if (cmd == UCSI_GET_ERROR_STATUS) - return -EIO; - - return ucsi_read_error(ucsi); - } - - if (cmd == UCSI_CANCEL && cci & UCSI_CCI_CANCEL_COMPLETE) { - ret = ucsi_acknowledge(ucsi, false); - return ret ? ret : -EBUSY; - } - - return UCSI_CCI_LENGTH(cci); -} - static int ucsi_send_command_common(struct ucsi *ucsi, u64 command, void *data, size_t size, bool conn_ack) { - u8 length; + u32 cci; int ret; mutex_lock(&ucsi->ppm_lock); - ret = ucsi_exec_command(ucsi, command); - if (ret < 0) - goto out; - - length = ret; - - if (data) { - ret = ucsi_read_message_in(ucsi, data, size); - if (ret) - goto out; + ret = ucsi_run_command(ucsi, command, &cci, data, size, conn_ack); + if (cci & UCSI_CCI_BUSY) { + ret = ucsi_run_command(ucsi, UCSI_CANCEL, &cci, NULL, 0, false); + return ret ? ret : -EBUSY; } - ret = ucsi_acknowledge(ucsi, conn_ack); - if (ret) - goto out; + if (cci & UCSI_CCI_ERROR) + return ucsi_read_error(ucsi); - ret = length; -out: mutex_unlock(&ucsi->ppm_lock); return ret; } From patchwork Tue Jun 25 14:54:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13711303 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9903CC2BBCA for ; Tue, 25 Jun 2024 14:55:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Cd2X10zVjMn+EpTL9h3lm0rs/LnmaQV9sjYCW3W4aNs=; b=0TECDB3jvHJdJr7NTErVgJIwKF RVo+BXY+S6FyQqL5PaVIU5Y7CFXK/Hk6EjXeB7cHgjg8WKEr0iWPwYeNQG4w5399lZPsUhA4u6CvP G+xm8Mr2oR0N0JybByCzdnHBoMbKVHTJjD6ZKhSiPbHptsbIfpDXvDISjhiCep+H541fEDHoKz0Yh EsA2EFV7wGf9WH1K7KQOVySLM2Vnq6G9eLvBeAjzkiP9L7nRx6hxFtngm/IG/nT72SCHSUui46/o5 PeJNv8Evx3JI0lZrga4uqCLrCACV8SALaCyvmBQtbn7s+rOqdwp0kpYMV+ceaXnuCJ7d3J8geZ/2m j4Aom2hQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7ZX-00000003HDW-1RK9; Tue, 25 Jun 2024 14:55:03 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7Z6-00000003GxS-1ubN for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 14:54:38 +0000 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-52cd628f21cso4817287e87.3 for ; Tue, 25 Jun 2024 07:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719327274; x=1719932074; darn=lists.infradead.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=Cd2X10zVjMn+EpTL9h3lm0rs/LnmaQV9sjYCW3W4aNs=; b=WOyPKZc+VITF8v4fujdzys4GzXudp9w2WWoynqNuYnIQrdrsPXkfC+8TvP8kmaZRUt TLzTJUImMaXDP6jUWkYGZRQQxJZs3sxhK2OWZXNOZiHosHhxvKBJ2zkVXt7aWNi48HGg Wt1vgUC5UEJiLqwUwAeyudd7GMtBdQDgFOlhkpiX0gl1ty269xHpSb+P1c74MUZxuO8b O47VA8ZpalrjOwOmKY1YqP2X+xhr3uA689s8+rCOvb26jufdqZ/TIl1UyZ5Bv6LwIjvo aOxIg5en76QJyYoSMjTBqd0t59NOX3coNlQeyO9/34wigqFIdWHpsItKUr85O8CTSG8L JT9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719327274; x=1719932074; 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=Cd2X10zVjMn+EpTL9h3lm0rs/LnmaQV9sjYCW3W4aNs=; b=n7z9YvyTgmYhZWjNOMZt08K4+mndRUcoxLVvjM1i/S3NvKgOevNOE4JWiR4mTGtbuJ FDVEiBPPPQ1wR+5CQY2AtaZvUzmk23HegNM2PE8O2HvYroHA/9SH/b54Ih2+Mja/uh+B pUEMsNUcUOcAXOrLxwWHrlq+DucWxOAyPk+tQsNqkJ2YfkNwm7Goc3KjhJe8EMLTfiDY EAXhDetXI/7EIml4QJ4SzZjPCOFeKADms1ARbsqXPJbOnyADrDKxelHktFLAqj1Rss9X 4zu88a8vfcPSXb5PgN0GykmUDNbddhF5AWkLoc+X/I02sKh6vuGLviJuQDYjR9xgsDx7 5wYQ== X-Forwarded-Encrypted: i=1; AJvYcCWk1SqMdupZN8gEY/xFowpClLe7C/kLsr4q+NdkQIlZfqgYPQumL7kH37DSByA0Aj45pS4wFri3XcnWznIJ3ztQwQAozBjozlnb8tCS2NFhvAy0JxY= X-Gm-Message-State: AOJu0YwQRqH2sIlmZIDeDwlVe4eQ2c8pOWYHEEW6I4ZrX9cAJ0DN/j7D ZdECCPn98JefhabGuckwj6oBf0NzhYgVp3Q4eaOJ9qGYrBBm+KyZYO87WwBtpuc= X-Google-Smtp-Source: AGHT+IFBU/FqlV1rlHFm7VcDP7TI1En+d6tYg9faOguYFxQeaenBL0P/drueNcNZbM5bdmNqJCDT6w== X-Received: by 2002:a05:6512:2394:b0:52c:d84c:1182 with SMTP id 2adb3069b0e04-52ce1862c12mr5311099e87.64.1719327274126; Tue, 25 Jun 2024 07:54:34 -0700 (PDT) Received: from umbar.lan ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd64328b7sm1251877e87.221.2024.06.25.07.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 07:54:33 -0700 (PDT) From: Dmitry Baryshkov Date: Tue, 25 Jun 2024 17:54:30 +0300 Subject: [PATCH v3 5/7] usb: typec: ucsi: inline ucsi_read_message_in MIME-Version: 1.0 Message-Id: <20240625-ucsi-rework-interface-v3-5-7a6c8e17be3a@linaro.org> References: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> In-Reply-To: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman , Maxime Coquelin , Alexandre Torgue Cc: Nikita Travkin , Neil Armstrong , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1606; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=mI5j32lGmh9mGgx/qR0lTHll3MYLBaGs+ozW531l430=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBmetojhmAknU4eETQ/0OVEnR93dwpzXwqv4zv11 DBDhLbs1XGJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZnraIwAKCRCLPIo+Aiko 1Zv3B/9UujGkolgkJQLF8DrUxTo7LuRVr+QOZJVWx5Y+Qqj2Vrktn20TdD10r17dEMR4lI7w1VC UMrX64IlrvWdR72wijPKPH6uafW5wUnCh3PNSBQgh+/03iBS8LwLJHaACH8JzISR8VnV8dh6Cya Xn2x+c9iwslIG6VPuSj+cxfyP1RPp+XY24Um3N7VOqS9MpeuJ54FtBQ9SwcEq/lf33MRf/+Vxv+ WwdlSitm/UoP2YJG99Fmg4nhaSNFDyyuKOvwrwC8TVZlSnhgehx4ekDRPW/4pQEtyC2R6/PNpN5 9FXIu8GWZ1DIn1Pb30kNSGbmuqxjMWkVwcYgoe6MFIjYwGMf X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_075436_539502_2C7BB442 X-CRM114-Status: GOOD ( 13.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There is no need to have a separate wrapper for reading MESSAGE_IN data, inline it to ucsi_run_command(). Signed-off-by: Dmitry Baryshkov --- drivers/usb/typec/ucsi/ucsi.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 5f8e5ed9e0f9..e14366e20cd5 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -36,19 +36,6 @@ */ #define UCSI_SWAP_TIMEOUT_MS 5000 -static int ucsi_read_message_in(struct ucsi *ucsi, void *buf, - size_t buf_size) -{ - /* - * Below UCSI 2.0, MESSAGE_IN was limited to 16 bytes. Truncate the - * reads here. - */ - if (ucsi->version <= UCSI_VERSION_1_2) - buf_size = clamp(buf_size, 0, 16); - - return ucsi->ops->read_message_in(ucsi, buf, buf_size); -} - static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack) { u64 ctrl; @@ -70,6 +57,13 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, *cci = 0; + /* + * Below UCSI 2.0, MESSAGE_IN was limited to 16 bytes. Truncate the + * reads here. + */ + if (ucsi->version <= UCSI_VERSION_1_2) + size = clamp(size, 0, 16); + ret = ucsi->ops->sync_control(ucsi, command); if (ret) return ret; @@ -98,7 +92,7 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, } if (data) { - ret = ucsi_read_message_in(ucsi, data, size); + ret = ucsi->ops->read_message_in(ucsi, data, size); if (ret) return ret; } From patchwork Tue Jun 25 14:54:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13711305 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 90225C2BBCA for ; Tue, 25 Jun 2024 14:55:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=S5qhm4+2XkcMwcHH9Y62ZxdXLR2b03l5U4e9I0TRazQ=; b=TkKAdJd4EgGoIt7dc+MWUNSEbE bQKtD3hIjGVN7rN/9iKOEQcGQ4HoTwiIwcQm6DqLeC5Lt7kCWsI42mPyjNff/c2udQWmvrkKXEzDp Nwh+8itR2mbo1iwDWnRV7bGy1RRGp1sL49b4GetFjUXq0HzQ8bEu345v0CAX2vPmpktJmOrXVTiTw 1j/ha9ou1Ou9t3twYE2Y4mq9u9G+9BWymbUSvqCfW1oRavZAYGot4vVhkode/ReyBqT2XgmiUDfFA g3ieqFaNZJYEOJXY9Lzpv+8kU/Cx3mEIVxrIDJEJFCyfbJu65IAIqbzG6Mh2prRDRb93EHgs2iEeN aF6fPtmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7Zi-00000003HLQ-3rXf; Tue, 25 Jun 2024 14:55:14 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7Z7-00000003Gy5-0lKY for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 14:54:39 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-52cd8897c73so4380268e87.2 for ; Tue, 25 Jun 2024 07:54:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719327275; x=1719932075; darn=lists.infradead.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=S5qhm4+2XkcMwcHH9Y62ZxdXLR2b03l5U4e9I0TRazQ=; b=OUjzTg6rwcbYlu8n40xRRh0ZuRFxI32Iv4P3uYwoduVcx7x+izdVGFdJp7TT5RCkcZ M7FtiEmu/O++HxYwEwhRn2M8G1kAKUOnZfZMmfMikrhFWenAMDxcTV5H4FMO+2OYJoGp /4nGnC9bG80tNBaOJyE/0J1kS4o91SsJ6x1EVxYVOnE4MXpFBAuMrsJjmwP8JhhRYOax 8cOiieVdiXIwDlLgepR43ZaysjeDuNVvJk9X7sarmdLjhQBdpcXWbwR4Z6pkjzKMVQ6Q 65aZp1PTw/8IaJ85kr/DKD2fnn4KWttaXJAgMGD92AWtf7IGlBz69eHbYIp3TwDC5kBG ajAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719327275; x=1719932075; 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=S5qhm4+2XkcMwcHH9Y62ZxdXLR2b03l5U4e9I0TRazQ=; b=SsQYSDfNYvdcW8oMA3mOVWJR0xP1BJ3/M9ZmJ87GepqqfvpahfgCotEiQ7RQv7hsTT UyGuWN0brZ+lsv1b83X1whRZfO3eXhhGO6i8ddPhrNj35xtQ9NyDWHUAIWx1Fvg6lWVB cIDDI0Ft7KcyXnUGEcp5whD0prIeD1hB5NBH3v+OxbPs1968lanik8qamYmseGD1kwMF irjXx/okeM3U+nL+I2NqOAhHoKdlVJCzmsiu2psYU7pF0IFgwLyGRNx6815YiEuo5dmj IZ9jwrDk6SuWR+v5nIoXtHVPWTeop9MClomu+6JwozmqmEYj/41sEd9u9jkU7Uf8Rr/6 QCMQ== X-Forwarded-Encrypted: i=1; AJvYcCXl0Txl0Np6EhR2ve+m8hwCb9ObXMris/SLc8tMtvKpTpC4Fg+LdfeIR+WYucPVxqOaiBt7TImR7U2OVi2IgWz/RZi4d/6SGtnSIN9fi1XwTz+XPYM= X-Gm-Message-State: AOJu0YwbXw7pl4a3L6a87Z5Dn42jgdCSrML9FdUDO/my0WdggEilD7Al RZWqbDc3r94oQgoMzErh5iifISkxQQDDjhceLFjHf/cundId/fjUkhEVmAR/iCU= X-Google-Smtp-Source: AGHT+IEN2LCltJtpjekLEgpKoh8HPCN8iGxEnXstAl9tdb7NmU7VHYkWiqLNDTtNBus6TlrGoWmBMg== X-Received: by 2002:ac2:546f:0:b0:52c:db53:5fe5 with SMTP id 2adb3069b0e04-52ce18351c2mr4404918e87.27.1719327274857; Tue, 25 Jun 2024 07:54:34 -0700 (PDT) Received: from umbar.lan ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd64328b7sm1251877e87.221.2024.06.25.07.54.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 07:54:34 -0700 (PDT) From: Dmitry Baryshkov Date: Tue, 25 Jun 2024 17:54:31 +0300 Subject: [PATCH v3 6/7] usb: typec: ucsi: extract common code for command handling MIME-Version: 1.0 Message-Id: <20240625-ucsi-rework-interface-v3-6-7a6c8e17be3a@linaro.org> References: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> In-Reply-To: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman , Maxime Coquelin , Alexandre Torgue Cc: Nikita Travkin , Neil Armstrong , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=18645; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=cnfB8S/RXo/ZEWQY0rQqmDwr4D3dCufkp0JaUwPvn/I=; b=owGbwMvMwMXYbdNlx6SpcZXxtFoSQ1rVLZVjThMXZViGzgjS3SfVsv4s99eGI/3/uav2BC1sL i036dPpZDRmYWDkYpAVU2TxKWiZGrMpOezDjqn1MINYmUCmMHBxCsBEIhLY/ylW58VedJZYs3TJ QX2blRYMPn+npZrf63Bk8RAIdt6Qe1uGKeOetOMrpsurZf/MdG6JiV4w6+9ff0bWy0qXFA/Jv05 59ydt6Y2f7+R/H768sL26bqbpv69agYHuGXMdN6ZrGOWVqbcsDFneFOqVEftSh0/ZcM0RZaHHba EXlj1sOyX8wHfnxNiAVINuxtdGyg4bLifG8kW66u7bLbN0sc4Xta5tS8rFP/EvcPrBNjHyiEVtJ IOPrK+UwcL07e+2fJjM3ac+o3fe+dWPXKbUHUwtv8gfefl0wvlgKYW8qGCdze5HIi/W1Z/XOiHf k8gQce2ZmYLLK4Pla//xOISFdfTMN1tzx1TQRUZ5gnY2AA== X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_075437_414932_BBE77BFE X-CRM114-Status: GOOD ( 21.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Extract common functions to handle command sending and to handle events from UCSI. This ensures that all UCSI glue drivers handle the ACKs in the same way. The CCG driver used DEV_CMD_PENDING both for internal firmware-related commands and for UCSI control handling. Leave the former use case intact. Signed-off-by: Dmitry Baryshkov --- drivers/usb/typec/ucsi/ucsi.c | 43 +++++++++++++++++++++++++ drivers/usb/typec/ucsi/ucsi.h | 7 +++++ drivers/usb/typec/ucsi/ucsi_acpi.c | 56 +++++---------------------------- drivers/usb/typec/ucsi/ucsi_ccg.c | 21 ++----------- drivers/usb/typec/ucsi/ucsi_glink.c | 47 ++------------------------- drivers/usb/typec/ucsi/ucsi_stm32g0.c | 44 ++------------------------ drivers/usb/typec/ucsi/ucsi_yoga_c630.c | 52 ++---------------------------- 7 files changed, 67 insertions(+), 203 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index e14366e20cd5..3fb5d3a52b80 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -36,6 +36,48 @@ */ #define UCSI_SWAP_TIMEOUT_MS 5000 +void ucsi_notify_common(struct ucsi *ucsi, u32 cci) +{ + if (UCSI_CCI_CONNECTOR(cci)) + ucsi_connector_change(ucsi, UCSI_CCI_CONNECTOR(cci)); + + if (cci & UCSI_CCI_ACK_COMPLETE && + test_bit(ACK_PENDING, &ucsi->flags)) + complete(&ucsi->complete); + + if (cci & UCSI_CCI_COMMAND_COMPLETE && + test_bit(COMMAND_PENDING, &ucsi->flags)) + complete(&ucsi->complete); +} +EXPORT_SYMBOL_GPL(ucsi_notify_common); + +int ucsi_sync_control_common(struct ucsi *ucsi, u64 command) +{ + bool ack = UCSI_COMMAND(command) == UCSI_ACK_CC_CI; + int ret; + + if (ack) + set_bit(ACK_PENDING, &ucsi->flags); + else + set_bit(COMMAND_PENDING, &ucsi->flags); + + ret = ucsi->ops->async_control(ucsi, command); + if (ret) + goto out_clear_bit; + + if (!wait_for_completion_timeout(&ucsi->complete, 5 * HZ)) + ret = -ETIMEDOUT; + +out_clear_bit: + if (ack) + clear_bit(ACK_PENDING, &ucsi->flags); + else + clear_bit(COMMAND_PENDING, &ucsi->flags); + + return ret; +} +EXPORT_SYMBOL_GPL(ucsi_sync_control_common); + static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack) { u64 ctrl; @@ -1890,6 +1932,7 @@ struct ucsi *ucsi_create(struct device *dev, const struct ucsi_operations *ops) INIT_WORK(&ucsi->resume_work, ucsi_resume_work); INIT_DELAYED_WORK(&ucsi->work, ucsi_init_work); mutex_init(&ucsi->ppm_lock); + init_completion(&ucsi->complete); ucsi->dev = dev; ucsi->ops = ops; diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 5c5a8c63090d..21ed0eb5be9f 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -4,6 +4,7 @@ #define __DRIVER_USB_TYPEC_UCSI_H #include +#include #include #include #include @@ -420,6 +421,9 @@ struct ucsi { /* PPM communication flags */ unsigned long flags; #define EVENT_PENDING 0 +#define COMMAND_PENDING 1 +#define ACK_PENDING 2 + struct completion complete; unsigned long quirks; #define UCSI_NO_PARTNER_PDOS BIT(0) /* Don't read partner's PDOs */ @@ -484,6 +488,9 @@ int ucsi_send_command(struct ucsi *ucsi, u64 command, 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); + #if IS_ENABLED(CONFIG_POWER_SUPPLY) int ucsi_register_port_psy(struct ucsi_connector *con); void ucsi_unregister_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 3660dc3e6d32..7a5dff8d9cc6 100644 --- a/drivers/usb/typec/ucsi/ucsi_acpi.c +++ b/drivers/usb/typec/ucsi/ucsi_acpi.c @@ -21,11 +21,7 @@ struct ucsi_acpi { struct device *dev; struct ucsi *ucsi; void *base; - struct completion complete; - unsigned long flags; -#define UCSI_ACPI_COMMAND_PENDING 1 -#define UCSI_ACPI_ACK_PENDING 2 -#define UCSI_ACPI_CHECK_BOGUS_EVENT 3 + bool check_bogus_event; guid_t guid; u64 cmd; }; @@ -98,38 +94,11 @@ static int ucsi_acpi_async_control(struct ucsi *ucsi, u64 command) return ucsi_acpi_dsm(ua, UCSI_DSM_FUNC_WRITE); } -static int ucsi_acpi_sync_control(struct ucsi *ucsi, u64 command) -{ - struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); - bool ack = UCSI_COMMAND(command) == UCSI_ACK_CC_CI; - int ret; - - if (ack) - set_bit(UCSI_ACPI_ACK_PENDING, &ua->flags); - else - set_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags); - - ret = ucsi_acpi_async_control(ucsi, command); - if (ret) - goto out_clear_bit; - - if (!wait_for_completion_timeout(&ua->complete, 5 * HZ)) - ret = -ETIMEDOUT; - -out_clear_bit: - if (ack) - clear_bit(UCSI_ACPI_ACK_PENDING, &ua->flags); - else - clear_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags); - - return ret; -} - static const struct ucsi_operations ucsi_acpi_ops = { .read_version = ucsi_acpi_read_version, .read_cci = ucsi_acpi_read_cci, .read_message_in = ucsi_acpi_read_message_in, - .sync_control = ucsi_acpi_sync_control, + .sync_control = ucsi_sync_control_common, .async_control = ucsi_acpi_async_control }; @@ -165,7 +134,7 @@ static const struct ucsi_operations ucsi_zenbook_ops = { .read_version = ucsi_acpi_read_version, .read_cci = ucsi_zenbook_read_cci, .read_message_in = ucsi_zenbook_read_message_in, - .sync_control = ucsi_acpi_sync_control, + .sync_control = ucsi_sync_control_common, .async_control = ucsi_acpi_async_control }; @@ -182,14 +151,14 @@ static int ucsi_gram_read_message_in(struct ucsi *ucsi, void *val, size_t val_le return ret; if (UCSI_COMMAND(ua->cmd) == UCSI_GET_CONNECTOR_STATUS && - test_bit(UCSI_ACPI_CHECK_BOGUS_EVENT, &ua->flags)) { + ua->check_bogus_event) { status = (struct ucsi_connector_status *)val; /* Clear the bogus change */ if (status->change == bogus_change) status->change = 0; - clear_bit(UCSI_ACPI_CHECK_BOGUS_EVENT, &ua->flags); + ua->check_bogus_event = false; } return ret; @@ -200,14 +169,14 @@ static int ucsi_gram_sync_control(struct ucsi *ucsi, u64 command) struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); int ret; - ret = ucsi_acpi_sync_control(ucsi, command); + ret = ucsi_sync_control_common(ucsi, command); 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) - set_bit(UCSI_ACPI_CHECK_BOGUS_EVENT, &ua->flags); + ua->check_bogus_event = true; return ret; } @@ -249,15 +218,7 @@ static void ucsi_acpi_notify(acpi_handle handle, u32 event, void *data) if (ret) return; - if (UCSI_CCI_CONNECTOR(cci)) - ucsi_connector_change(ua->ucsi, UCSI_CCI_CONNECTOR(cci)); - - if (cci & UCSI_CCI_ACK_COMPLETE && - test_bit(UCSI_ACPI_ACK_PENDING, &ua->flags)) - complete(&ua->complete); - if (cci & UCSI_CCI_COMMAND_COMPLETE && - test_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags)) - complete(&ua->complete); + ucsi_notify_common(ua->ucsi, cci); } static int ucsi_acpi_probe(struct platform_device *pdev) @@ -291,7 +252,6 @@ static int ucsi_acpi_probe(struct platform_device *pdev) if (ret) return ret; - init_completion(&ua->complete); ua->dev = &pdev->dev; id = dmi_first_match(ucsi_acpi_quirks); diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index 6ccc394f268e..ba4db2310a05 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -222,8 +222,6 @@ struct ucsi_ccg { u16 fw_build; struct work_struct pm_work; - struct completion complete; - u64 last_cmd_sent; bool has_multiple_dp; struct ucsi_ccg_altmode orig[UCSI_MAX_ALTMODES]; @@ -637,7 +635,6 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command) mutex_lock(&uc->lock); pm_runtime_get_sync(uc->dev); - set_bit(DEV_CMD_PENDING, &uc->flags); uc->last_cmd_sent = command; @@ -649,15 +646,8 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command) ucsi_ccg_update_set_new_cam_cmd(uc, con, &command); } - ret = ucsi_ccg_async_control(ucsi, command); - if (ret) - goto err_clear_bit; - - if (!wait_for_completion_timeout(&uc->complete, msecs_to_jiffies(5000))) - ret = -ETIMEDOUT; + ret = ucsi_sync_control_common(ucsi, command); -err_clear_bit: - clear_bit(DEV_CMD_PENDING, &uc->flags); pm_runtime_put_sync(uc->dev); mutex_unlock(&uc->lock); @@ -694,9 +684,6 @@ static irqreturn_t ccg_irq_handler(int irq, void *data) if (ret) goto err_clear_irq; - if (UCSI_CCI_CONNECTOR(cci)) - ucsi_connector_change(uc->ucsi, UCSI_CCI_CONNECTOR(cci)); - /* * As per CCGx UCSI interface guide, copy CCI and MESSAGE_IN * to the OpRegion before clear the UCSI interrupt @@ -708,9 +695,8 @@ static irqreturn_t ccg_irq_handler(int irq, void *data) err_clear_irq: ccg_write(uc, CCGX_RAB_INTR_REG, &intr_reg, sizeof(intr_reg)); - if (!ret && test_bit(DEV_CMD_PENDING, &uc->flags) && - cci & (UCSI_CCI_ACK_COMPLETE | UCSI_CCI_COMMAND_COMPLETE)) - complete(&uc->complete); + if (!ret) + ucsi_notify_common(uc->ucsi, cci); return IRQ_HANDLED; } @@ -1429,7 +1415,6 @@ static int ucsi_ccg_probe(struct i2c_client *client) uc->client = client; uc->irq = client->irq; mutex_init(&uc->lock); - init_completion(&uc->complete); INIT_WORK(&uc->work, ccg_update_firmware); INIT_WORK(&uc->pm_work, ccg_pm_workaround_work); diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c index 56bad054e78f..16c328497e0b 100644 --- a/drivers/usb/typec/ucsi/ucsi_glink.c +++ b/drivers/usb/typec/ucsi/ucsi_glink.c @@ -64,12 +64,8 @@ struct pmic_glink_ucsi { struct ucsi *ucsi; struct completion read_ack; struct completion write_ack; - struct completion sync_ack; - bool sync_pending; struct mutex lock; /* protects concurrent access to PMIC Glink interface */ - int sync_val; - struct work_struct notify_work; struct work_struct register_work; @@ -170,35 +166,6 @@ static int pmic_glink_ucsi_async_control(struct ucsi *__ucsi, u64 command) return ret; } -static int pmic_glink_ucsi_sync_control(struct ucsi *__ucsi, u64 command) -{ - struct pmic_glink_ucsi *ucsi = ucsi_get_drvdata(__ucsi); - unsigned long left; - int ret; - - /* TOFIX: Downstream forces recipient to CON when UCSI_GET_ALTERNATE_MODES command */ - - mutex_lock(&ucsi->lock); - ucsi->sync_val = 0; - reinit_completion(&ucsi->sync_ack); - ucsi->sync_pending = true; - ret = pmic_glink_ucsi_locked_write(ucsi, UCSI_CONTROL, &command, sizeof(command)); - mutex_unlock(&ucsi->lock); - - left = wait_for_completion_timeout(&ucsi->sync_ack, 5 * HZ); - if (!left) { - dev_err(ucsi->dev, "timeout waiting for UCSI sync write response\n"); - /* return 0 here and let core UCSI code handle the CCI_BUSY */ - ret = 0; - } else if (ucsi->sync_val) { - dev_err(ucsi->dev, "sync write returned: %d\n", ucsi->sync_val); - } - - ucsi->sync_pending = false; - - return ret; -} - static void pmic_glink_ucsi_update_connector(struct ucsi_connector *con) { struct pmic_glink_ucsi *ucsi = ucsi_get_drvdata(con->ucsi); @@ -232,7 +199,7 @@ static const struct ucsi_operations pmic_glink_ucsi_ops = { .read_version = pmic_glink_ucsi_read_version, .read_cci = pmic_glink_ucsi_read_cci, .read_message_in = pmic_glink_ucsi_read_message_in, - .sync_control = pmic_glink_ucsi_sync_control, + .sync_control = ucsi_sync_control_common, .async_control = pmic_glink_ucsi_async_control, .update_connector = pmic_glink_ucsi_update_connector, .connector_status = pmic_glink_ucsi_connector_status, @@ -256,14 +223,12 @@ static void pmic_glink_ucsi_write_ack(struct pmic_glink_ucsi *ucsi, const void * if (resp->ret_code) return; - ucsi->sync_val = resp->ret_code; complete(&ucsi->write_ack); } static void pmic_glink_ucsi_notify(struct work_struct *work) { struct pmic_glink_ucsi *ucsi = container_of(work, struct pmic_glink_ucsi, notify_work); - unsigned int con_num; u32 cci; int ret; @@ -273,14 +238,7 @@ static void pmic_glink_ucsi_notify(struct work_struct *work) return; } - con_num = UCSI_CCI_CONNECTOR(cci); - if (con_num) - ucsi_connector_change(ucsi->ucsi, con_num); - - if (ucsi->sync_pending && - (cci & (UCSI_CCI_ACK_COMPLETE | UCSI_CCI_COMMAND_COMPLETE))) { - complete(&ucsi->sync_ack); - } + ucsi_notify_common(ucsi->ucsi, cci); } static void pmic_glink_ucsi_register(struct work_struct *work) @@ -362,7 +320,6 @@ static int pmic_glink_ucsi_probe(struct auxiliary_device *adev, INIT_WORK(&ucsi->register_work, pmic_glink_ucsi_register); init_completion(&ucsi->read_ack); init_completion(&ucsi->write_ack); - init_completion(&ucsi->sync_ack); mutex_init(&ucsi->lock); ucsi->ucsi = ucsi_create(dev, &pmic_glink_ucsi_ops); diff --git a/drivers/usb/typec/ucsi/ucsi_stm32g0.c b/drivers/usb/typec/ucsi/ucsi_stm32g0.c index 14737ca3724c..d948c3f579e1 100644 --- a/drivers/usb/typec/ucsi/ucsi_stm32g0.c +++ b/drivers/usb/typec/ucsi/ucsi_stm32g0.c @@ -61,11 +61,7 @@ struct ucsi_stm32g0 { struct i2c_client *i2c_bl; bool in_bootloader; u8 bl_version; - struct completion complete; struct device *dev; - unsigned long flags; -#define COMMAND_PENDING 1 -#define ACK_PENDING 2 const char *fw_name; struct ucsi *ucsi; bool suspended; @@ -407,35 +403,6 @@ static int ucsi_stm32g0_async_control(struct ucsi *ucsi, u64 command) return 0; } -static int ucsi_stm32g0_sync_control(struct ucsi *ucsi, u64 command) -{ - struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); - bool ack = UCSI_COMMAND(command) == UCSI_ACK_CC_CI; - int ret; - - if (ack) - set_bit(ACK_PENDING, &g0->flags); - else - set_bit(COMMAND_PENDING, &g0->flags); - - ret = ucsi_stm32g0_async_control(ucsi, command); - if (ret) - goto out_clear_bit; - - if (!wait_for_completion_timeout(&g0->complete, msecs_to_jiffies(5000))) - ret = -ETIMEDOUT; - else - return 0; - -out_clear_bit: - if (ack) - clear_bit(ACK_PENDING, &g0->flags); - else - clear_bit(COMMAND_PENDING, &g0->flags); - - return ret; -} - static irqreturn_t ucsi_stm32g0_irq_handler(int irq, void *data) { struct ucsi_stm32g0 *g0 = data; @@ -449,13 +416,7 @@ static irqreturn_t ucsi_stm32g0_irq_handler(int irq, void *data) if (ret) return IRQ_NONE; - if (UCSI_CCI_CONNECTOR(cci)) - ucsi_connector_change(g0->ucsi, UCSI_CCI_CONNECTOR(cci)); - - if (cci & UCSI_CCI_ACK_COMPLETE && test_and_clear_bit(ACK_PENDING, &g0->flags)) - complete(&g0->complete); - if (cci & UCSI_CCI_COMMAND_COMPLETE && test_and_clear_bit(COMMAND_PENDING, &g0->flags)) - complete(&g0->complete); + ucsi_notify_common(g0->ucsi, cci); return IRQ_HANDLED; } @@ -464,7 +425,7 @@ static const struct ucsi_operations ucsi_stm32g0_ops = { .read_version = ucsi_stm32g0_read_version, .read_cci = ucsi_stm32g0_read_cci, .read_message_in = ucsi_stm32g0_read_message_in, - .sync_control = ucsi_stm32g0_sync_control, + .sync_control = ucsi_sync_control_common, .async_control = ucsi_stm32g0_async_control, }; @@ -665,7 +626,6 @@ static int ucsi_stm32g0_probe(struct i2c_client *client) g0->dev = dev; g0->client = client; - init_completion(&g0->complete); i2c_set_clientdata(client, g0); g0->ucsi = ucsi_create(dev, &ucsi_stm32g0_ops); diff --git a/drivers/usb/typec/ucsi/ucsi_yoga_c630.c b/drivers/usb/typec/ucsi/ucsi_yoga_c630.c index 95a333ad5496..f3a5e24ea84d 100644 --- a/drivers/usb/typec/ucsi/ucsi_yoga_c630.c +++ b/drivers/usb/typec/ucsi/ucsi_yoga_c630.c @@ -20,10 +20,6 @@ struct yoga_c630_ucsi { struct yoga_c630_ec *ec; struct ucsi *ucsi; struct notifier_block nb; - struct completion complete; - unsigned long flags; -#define UCSI_C630_COMMAND_PENDING 0 -#define UCSI_C630_ACK_PENDING 1 u16 version; }; @@ -75,57 +71,14 @@ static int yoga_c630_ucsi_async_control(struct ucsi *ucsi, u64 command) return yoga_c630_ec_ucsi_write(uec->ec, (u8*)&command); } -static int yoga_c630_ucsi_sync_control(struct ucsi *ucsi, u64 command) -{ - struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); - bool ack = UCSI_COMMAND(command) == UCSI_ACK_CC_CI; - int ret; - - if (ack) - set_bit(UCSI_C630_ACK_PENDING, &uec->flags); - else - set_bit(UCSI_C630_COMMAND_PENDING, &uec->flags); - - reinit_completion(&uec->complete); - - ret = yoga_c630_ucsi_async_control(ucsi, command); - if (ret) - goto out_clear_bit; - - if (!wait_for_completion_timeout(&uec->complete, 5 * HZ)) - ret = -ETIMEDOUT; - -out_clear_bit: - if (ack) - clear_bit(UCSI_C630_ACK_PENDING, &uec->flags); - else - clear_bit(UCSI_C630_COMMAND_PENDING, &uec->flags); - - return ret; -} - const struct ucsi_operations yoga_c630_ucsi_ops = { .read_version = yoga_c630_ucsi_read_version, .read_cci = yoga_c630_ucsi_read_cci, .read_message_in = yoga_c630_ucsi_read_message_in, - .sync_control = yoga_c630_ucsi_sync_control, + .sync_control = ucsi_sync_control_common, .async_control = yoga_c630_ucsi_async_control, }; -static void yoga_c630_ucsi_notify_ucsi(struct yoga_c630_ucsi *uec, u32 cci) -{ - if (UCSI_CCI_CONNECTOR(cci)) - ucsi_connector_change(uec->ucsi, UCSI_CCI_CONNECTOR(cci)); - - if (cci & UCSI_CCI_ACK_COMPLETE && - test_bit(UCSI_C630_ACK_PENDING, &uec->flags)) - complete(&uec->complete); - - if (cci & UCSI_CCI_COMMAND_COMPLETE && - test_bit(UCSI_C630_COMMAND_PENDING, &uec->flags)) - complete(&uec->complete); -} - static int yoga_c630_ucsi_notify(struct notifier_block *nb, unsigned long action, void *data) { @@ -144,7 +97,7 @@ static int yoga_c630_ucsi_notify(struct notifier_block *nb, if (ret) return NOTIFY_DONE; - yoga_c630_ucsi_notify_ucsi(uec, cci); + ucsi_notify_common(uec->ucsi, cci); return NOTIFY_OK; @@ -165,7 +118,6 @@ static int yoga_c630_ucsi_probe(struct auxiliary_device *adev, return -ENOMEM; uec->ec = ec; - init_completion(&uec->complete); uec->nb.notifier_call = yoga_c630_ucsi_notify; uec->ucsi = ucsi_create(&adev->dev, &yoga_c630_ucsi_ops); From patchwork Tue Jun 25 14:54:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13711304 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C12DCC3064D for ; Tue, 25 Jun 2024 14:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=g2gxtQIN+xKJeYZrrZg4eTx3pd8ql0F1T/zN9SBRQsY=; b=DZvMfPOuhBySHy65/0QVfx/AJS QIuiEJxKQ2KXx9pVf1dhATfXFOEkSYUskjsp9evuH7tHU7jOvsyBiN4Dz8RouOJ4NYv3BivohyWEn jCricRdYm9R/DW5TlsVJj2dgs+4eAqAmXpxN8o6TU6I48GApVYXQQSqSzsWgQvb9BdQyX5ISkCBUH k09JPR3XmL1MI2g0IBZvt30qlP/0Q6+IggBqhITqVLqJtGkYDqWRnnU2hC9allstqCW1Lv/jxpnf6 t4HiOHnyqEc8R0uL3FmEJSv9PJj5xc2/zjjbfjRmkkvQsQVvetyWDXhK9kupnvGCE7LdvPJrLWtW4 VNFeiSfw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7Ze-00000003HIA-0YZN; Tue, 25 Jun 2024 14:55:10 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7Z7-00000003Gye-0SYO for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 14:54:38 +0000 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-52cf4ca8904so428179e87.3 for ; Tue, 25 Jun 2024 07:54:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719327275; x=1719932075; darn=lists.infradead.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=g2gxtQIN+xKJeYZrrZg4eTx3pd8ql0F1T/zN9SBRQsY=; b=YAXSk1oL28hJWo6yPuw6tTjvmVhwKyB9jtTSWcnveB4GWTh78bDDhL95wdsfziMYjS q+CZHe/lsO+07hB01JeAB0k3ALU3g9F1e4RVfqU+2x2yezBnFsUoLYO13g1ou79dhi5z ak79sp+S7QvpnJ9JSz7sdI0aHzURlnPTPfXj7JL3f/upJXtSlHGyw1ZZSBg2+xoi4wlw I8WFgJ7np4ZNbjllPoF9m8TrYWrgeL6U6VrSitcsunymjT+vSqyGEP3byg6IyxotWsv3 xRnTtWMVdc63GCf13OwbVNZk6Wyk6OesKiMVu8Kxv/8Z+ac3JM4TJ1m6bZm7WZqy51Gq jYKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719327275; x=1719932075; 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=g2gxtQIN+xKJeYZrrZg4eTx3pd8ql0F1T/zN9SBRQsY=; b=fQR6ovHYYuiI9nIFoYB8BviLUZ/U+OS77DnVbSfSFEEjUqM2fpVFEiJrfXJ8MHtjqE sjoRidM/yfTpsFPZXUFSZcBP98P588ZHM3msETWrIhrclAIvHjGAd9y7dirdzme+mo3/ l6SlDpg20LBjA58uY1w6FrW9cH4MuH1ljITrAB8/Pp5vDOLc0oadIS92WfaOrxD2Sc+J WXCpDldms3mSAQqV/zK7VXxalZgxdooouUWAjLafsYQdOWQr1YBXBPLo4ResoHvDvZc2 BCrfwwwbibTmWq2cpTv1NClpcoyB2uPqxWQPjDihFJ3pH4CpwJZEmPNvZX8raHSv5exD VHJA== X-Forwarded-Encrypted: i=1; AJvYcCW7VqpN23Y9SE2l7RoVZhXf45g4kp/VrAbrXUXD2qBn+CF/FMEPVd33X1U+O6fWPjhdtPiwQxu1Nxt+j3Gs7uNqd5sl+94BBiOd4sAmZJXC+4jUROw= X-Gm-Message-State: AOJu0YzVB8hroi/7C9L5S7kUecJqn9PWA9bOGmktD9gz6YShT+4AT0J1 QGEAumbimuC5l+7NXUHa9GOgYBTHQR3hxHDkBfuAkfUhVMXDdel0cJVp8bDuabOzEMtdaKAQGns b5PI= X-Google-Smtp-Source: AGHT+IFgTfwsx7ElY5vsvTSzReP2HLuqQHHg6f+F1C3RO23ndtkGTJu8+wBSZAIAD6eWetNxoUG4Kg== X-Received: by 2002:a05:6512:46f:b0:52c:9f9e:d8e3 with SMTP id 2adb3069b0e04-52ce064e3d8mr4973783e87.31.1719327275739; Tue, 25 Jun 2024 07:54:35 -0700 (PDT) Received: from umbar.lan ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd64328b7sm1251877e87.221.2024.06.25.07.54.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 07:54:35 -0700 (PDT) From: Dmitry Baryshkov Date: Tue, 25 Jun 2024 17:54:32 +0300 Subject: [PATCH v3 7/7] usb: typec: ucsi: reorder operations in ucsi_run_command() MIME-Version: 1.0 Message-Id: <20240625-ucsi-rework-interface-v3-7-7a6c8e17be3a@linaro.org> References: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> In-Reply-To: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman , Maxime Coquelin , Alexandre Torgue Cc: Nikita Travkin , Neil Armstrong , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2070; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=c1mFXRw/1F7jX+PLOZli37YidJtYzYIZwD0eERkZXpg=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBmetokKTBUAvA860F4TZ7LaGT2vn3//h0eO5fRP eXnVpE4f++JATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZnraJAAKCRCLPIo+Aiko 1Y7VCACNYuSM7sEYoqQvGqND2MRdAoZLFky1iBiqT6oimIP7qis1KVCv3F+gBFz/bdKtij+cztp Z5awCnGfW7Httm4zKIIT7NjJpuUDn4ia7oZOW3FAe99Zdq92p1EKUvXKnXApxNz6eom/iOY7qGH ZuClKE5VA15dUN4sl0zW6TTatSGt7zTfkToJ2jq8u83k9ID/maCxlb5V8FISVxuKEqgOJwLGGoE OvAeeooTh9x2NFAt/eeMWZ2D8kgVxeDZw+j5aVfO6x8v8emzAdbZuHaM+qRTH+T7uUXJOiJNXkB 9HVHfVpFVz76fdbmU925vbf0ul+6bFBUI9SNsbusDr5OPJul X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_075437_295225_AF277A30 X-CRM114-Status: GOOD ( 15.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Streamline control stream of ucsi_run_command(). Reorder operations so that there is only one call to ucsi_acknowledge(), making sure that all complete commands are acknowledged. This also makes sure that the command is acknowledged even if reading MESSAGE_IN data returns an error. Signed-off-by: Dmitry Baryshkov --- drivers/usb/typec/ucsi/ucsi.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 3fb5d3a52b80..0d091f06abd3 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -95,7 +95,7 @@ static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack) static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, void *data, size_t size, bool conn_ack) { - int ret; + int ret, err; *cci = 0; @@ -120,30 +120,24 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, if (!(*cci & UCSI_CCI_COMMAND_COMPLETE)) return -EIO; - if (*cci & UCSI_CCI_NOT_SUPPORTED) { - if (ucsi_acknowledge(ucsi, false) < 0) - dev_err(ucsi->dev, - "ACK of unsupported command failed\n"); - return -EOPNOTSUPP; - } - - if (*cci & UCSI_CCI_ERROR) { - /* Acknowledge the command that failed */ - ret = ucsi_acknowledge(ucsi, false); - return ret ? ret : -EIO; - } + if (*cci & UCSI_CCI_NOT_SUPPORTED) + err = -EOPNOTSUPP; + else if (*cci & UCSI_CCI_ERROR) + err = -EIO; + else + err = 0; - if (data) { - ret = ucsi->ops->read_message_in(ucsi, data, size); - if (ret) - return ret; - } + if (!err && data && UCSI_CCI_LENGTH(*cci)) + err = ucsi->ops->read_message_in(ucsi, data, size); - ret = ucsi_acknowledge(ucsi, conn_ack); + /* + * Don't ACK connection change if there was an error. + */ + ret = ucsi_acknowledge(ucsi, err ? false : conn_ack); if (ret) return ret; - return 0; + return err; } static int ucsi_read_error(struct ucsi *ucsi)