Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp656767lqj; Sun, 2 Jun 2024 16:26:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVFoKGFAubMxzed0UcTjZLhdusAZSnkXhjU5Q5ft+ZmksfOdYuL0jjsdzlVDONrJfi7fsn8Hg2dxlPcFhv6OaW0eTfuKW6Etr3NkN01aQ== X-Google-Smtp-Source: AGHT+IG2SF37AolSrnWGuriTHrqY0D8gIxPhZEkFK+DYTsaknYiOI6Byl/vbGG1TtVx2/bSERuKw X-Received: by 2002:a17:907:86a6:b0:a68:be21:8dca with SMTP id a640c23a62f3a-a68be218e99mr403015466b.10.1717370785930; Sun, 02 Jun 2024 16:26:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717370785; cv=pass; d=google.com; s=arc-20160816; b=Nqdlhzbet+wJ2PEXbc+P8NyzGXNqUuroPN6V/DeCX/vPPT1I+q5GLjq+yXkQ9edeYI XVkd0MifPtPKjhPJJrn5v4DDLuQoqkO0lBUO2frUlEjPWZ2zp6+Zp51br67SVLaB69QW JAdpuOijK0tTpnWc+fIHZ20wrdisCpKPZZDokH8paw9QRUq//hPNV3DeUyJvtNauwSWN VCgCIhSukj/fBLXwHV0zRZVGRugzvH5co7gpkgKfckDxM8wFAlb13Syl1mcLbFAKC8g5 aBqGfdUGO2l9dxYDf33P+f7Ju2GSkghs7ozVxarxvdRKiqEBMLsCGGoiDR7/G/+6UTRj 3HqA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=fLTVeDBunzWZL7NXj62dRVbdmskQ6vEkyJgavqsHljg=; fh=nemh0uy15k16qUoVoGPtKAQd8d5Jz9d6Grk1Z7H2x8A=; b=sBjJdW7kDbHvot5AWU7W6g6ultJB+C7ShzYH0mG3uaG5qim028g1Z0zaNdNTwV5ioU 6jLVsHcAATtECOZFOG+2YikdnlzYn0SJ85UVmIcarSetCzmnwKTQP99ZlTXzC9iOys3k ZeCQnhOdianwY+V3aC9C1IQvQ3gox4W5YzehTqh6zvSkJrCX9MDma8FhYdz////qILnR 7kOxA43FQnhUPLCmdaGvGRhrbN0xn+zUHW+B9Z6WFBvSyP9N3lMMNEjwFrSFVOHiYTR4 o8FW7JLWCzBFbYuB24xtsM1MzB056wKn4u/JXJ3QhpAbq+HZJv7eBiVAajX8E+doB/3+ McPw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uPxRVO+l; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-198480-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198480-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a68fe449292si82150166b.434.2024.06.02.16.26.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jun 2024 16:26:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198480-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uPxRVO+l; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-198480-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198480-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7F9E91F21734 for ; Sun, 2 Jun 2024 23:26:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 30FA783CC8; Sun, 2 Jun 2024 23:25:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="uPxRVO+l" Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03E5D7FBC4 for ; Sun, 2 Jun 2024 23:25:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717370705; cv=none; b=rXK4e45g6o6ecxneVkzNW0qJvk6FebsyiB2OTTTJySaSINsR0UE/dc70ugySkvISQC+gsXJgcocytU7O5iza45zMMMPXZ4n4w/9QbgfeIGnpqIveGEeuS36SxwjM33R9DLYFQf/U4KndXYjkGw2X75jEiLhMgl6MB93eR82w9o4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717370705; c=relaxed/simple; bh=xsVlzflUb/Qp1trYi1IqtQRk3wSvC2VlMHb1s/cNflQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ivnKUFAG/WWqsmxrn4v6L59g3ddWdmqVLsXjkDdzkP3TVY5fHAGwiaVZrWtjVgcKsnkT9tvA04ymq/6UUEj3C92YephH4i0ZELT5IUZ/jRYwwrOuyRd+7j9HWUSxJl7sVHdJP+N0HS4eKFx0nLlfOTbDh5dOZxmZdDgqIcEJxHU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=uPxRVO+l; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-52b88335dd7so3231773e87.1 for ; Sun, 02 Jun 2024 16:25:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717370701; x=1717975501; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=fLTVeDBunzWZL7NXj62dRVbdmskQ6vEkyJgavqsHljg=; b=uPxRVO+lniez5ZVbPpE/X6n+QNn05/FaRWhTv5Ff+leZ21Eu62D+hi4Vr2ICldGEu7 UevGXut9+nuWQWmq07gvD71Pr9NfvgPPIiGGFVLUORlZ/zUm9eKuG8KKPF+U1r0hmTk+ Xao7kaGzxcTRkUHNwz3N0KT1078iGmlqRYFdis+nlsYYsilucmtY2bQao1Rias7XnMeb Mu2XI1kR8U9eXoSQWO9UHZmn5qJfAu55snDTtz9B9Es+8augVHWR4VZVulwNtWws1v0T mzERSW+C1TNYc0AFuuaJgtoJyQxFcJ+d7YYGyku6sGOrqXfHw5SGEfEFf5gzwYKhDAxt FTPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717370701; x=1717975501; 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=fLTVeDBunzWZL7NXj62dRVbdmskQ6vEkyJgavqsHljg=; b=wL8NCb2R366vtpNX/Et4rL9ITmsb6/Why4tK+sBNNxsPFO0QSJtVci1Dqjy1m/MY0G JSRLViHi8Rk0RJb51+lrIueA31Vop8HhML4LCQ2z/K+cyAjCB/yUUHFpIjtWST9JmekT nEkaz2WYIgPqoa5+FWL0OUULhD7yl7apuZfFMrSWD4a1VtnsmhvwSPRDKyoe3ySl7cIF v7xPxcviuuJXYrSoO31ES8dIsQkg+YfEdcPJpK5FFcrb9eBDPyWpm5+ZaHnpP96ZDXYD wP9PhFTs4cOXsQHcaSXkfpovhsta4tmWGzg5Az6nj/KlcuGdVxCYe2p+vH2pNTHhSOmb Tk7w== X-Forwarded-Encrypted: i=1; AJvYcCUn88g/8C9jr2DHgGzg4pAa7cA9Xyfl/ityFIRUsV5tJUFwwHwZRNKY1zi6W+7XFrG7m8jA43YFNEzWY5g5DbUCkKlsP0x5Xyb39YYh X-Gm-Message-State: AOJu0YzdWihrxrAnxHTcfnWw0F10RVe9VkjMEVTnmBMMRu4E5VvTzJHd SdGgZEw2DMZnPFbLphGnXG5waQOcVXIGFdQCRXIO/uJ3bZ0ughD8W8NpBsPQi5M5+Q04v/6UFg3 / X-Received: by 2002:a05:6512:1152:b0:52b:9c8a:735a with SMTP id 2adb3069b0e04-52b9c8a74fcmr205388e87.40.1717370700848; Sun, 02 Jun 2024 16:25:00 -0700 (PDT) Received: from umbar.lan ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52b959008aasm392369e87.269.2024.06.02.16.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jun 2024 16:25:00 -0700 (PDT) From: Dmitry Baryshkov Date: Mon, 03 Jun 2024 02:24:59 +0300 Subject: [PATCH RFC 6/7] usb: typec: ucsi: extract common code for command handling Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240603-ucsi-rework-interface-v1-6-99a6d544cec8@linaro.org> References: <20240603-ucsi-rework-interface-v1-0-99a6d544cec8@linaro.org> In-Reply-To: <20240603-ucsi-rework-interface-v1-0-99a6d544cec8@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=14654; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=xsVlzflUb/Qp1trYi1IqtQRk3wSvC2VlMHb1s/cNflQ=; b=owGbwMvMwMXYbdNlx6SpcZXxtFoSQ1rMf3fZKVbMvl/MvA4YZCjfVVleW3U9nju+f0XV2tjJe 17ZW27rZDRmYWDkYpAVU2TxKWiZGrMpOezDjqn1MINYmUCmMHBxCsBEFHdxMMyLKbipKsrvU3b1 XdwubZecG8LTp9RNfLIn4AHP2+7vP63uPZD5J8+cyiOrxngkznOJWV1RumBn6NeZf1ezipzkfb1 HnHftHiWnLc4PdVXFVwhs1P0t92qflabtpI37/VimvE80fLrGfHuDn72PfbJNb4e/6h/v566PGf 23Bh3fossgZrVWLD80J39fr0Ju6u34vy31dU9sD8dzZ0gt3HPDqsFb606YXsSX7bZ+Dd8dG76Jz TcyXSRgzWBk3F56Y01K8fR16ayKhmKl+afNzVdctzqm8W2L+6P/1xp+7T7Oocx7+5X/e50i///7 vk07cmS/f1uWe9mxh1qqEXph7wp3sYRmds50cnz1zkoTAA== X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A 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 | 46 +++------------------------------- drivers/usb/typec/ucsi/ucsi_ccg.c | 21 +++------------- drivers/usb/typec/ucsi/ucsi_glink.c | 47 ++--------------------------------- drivers/usb/typec/ucsi/ucsi_stm32g0.c | 44 ++------------------------------ 6 files changed, 60 insertions(+), 148 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index ac4bd86b3fae..4d36a04dc63b 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; @@ -1858,6 +1900,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 f770e1070424..b08393417fa9 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 @@ -409,6 +410,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 */ @@ -473,6 +477,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 61dd28dae3a4..e8402fac70c8 100644 --- a/drivers/usb/typec/ucsi/ucsi_acpi.c +++ b/drivers/usb/typec/ucsi/ucsi_acpi.c @@ -21,10 +21,6 @@ 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 guid_t guid; u64 cmd; }; @@ -97,38 +93,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 }; @@ -164,7 +133,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 }; @@ -189,15 +158,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) @@ -231,7 +192,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 7f6a48624ee5..8b74da38d283 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 e3cfcb258e43..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); -- 2.39.2