Received: by 2002:a05:7412:8d1c:b0:fa:4c10:6cad with SMTP id bj28csp53206rdb; Tue, 16 Jan 2024 14:51:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IEg+iOOKICn5buJ1wXcY6Err7AiaSEANhGRTZFwrSdGwycuizXYGwFVic101R6toaIkZNQu X-Received: by 2002:a17:907:d502:b0:a2d:9a0d:5c7e with SMTP id wb2-20020a170907d50200b00a2d9a0d5c7emr4819149ejc.74.1705445479343; Tue, 16 Jan 2024 14:51:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705445479; cv=pass; d=google.com; s=arc-20160816; b=CSOxJ+61JQlYEXKgXQ/ScC2cxc6JXrg5cpCsTGcbNVPoFn2UXr0VIxDsB0QNHsh5Jw TacM78u0E1g+5K9DHMj+TEJ2BPRq5HlgEEPxgOU2e4Ok9FM1HKk6CiyIYtykhdtI8ekV wnY4p8VXdiy9cOm0cFGL4sPXLLkTNRyGrzvMYVk2w2yNXQCIMqdNJcfI+IR4A3vFxrth nsQ62QWL3phBqMNWor+otndsUUYOrNBitAjS5A1vbec1JwRpcqgH1kEVCxAwZdA/eqzY h97QlyN/kA3C/XEob51S9cYgMFu6CoN8q5KNxWm146U2fxpzJZTQXo4YmOC1ZdB53yAF 2Vzg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=GpDYGfBOeX5SkCH6gmevMRNqwjiNLzmCUKvwy3y5VLw=; fh=PBT+T+L/Wk7fQyAuF/ivTwxWqTQzcP6BniPDJctp9Xs=; b=vNv0EsGfj+zgt4Pa9UjuFZjEa3PtuK8JZIEpOCrdPDGKd9xtCRK5xCWh+7CVeVX5Hv 5qqBptl+hkdv8I9cd+5xgMrbckueiwMXynkdezruVXQ1H0Nv5si6r7kp8iIXYyxy3I1B UgWpIQvxl87RP63ZIrE1h7IicVLINXyv1kslBpoKNGuFardSuNiOSR2jnHDkvOcxaX0+ Hid6L7T+dnlHX6wDFgOza9vS38fyRCwRrEejGGZVzouaLaZlbAKtk0cXGsTVPfAmJ1Gl rEadBiayKSDClyC6WPjzCwUs2SUxXx/7o15lsOXaqrNMaa6BobBqW2/I6EqZqeYVSHSR KdiQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=c--e.de); spf=pass (google.com: domain of linux-kernel+bounces-28361-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28361-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f4-20020a17090624c400b00a28dcc30c58si5072775ejb.504.2024.01.16.14.51.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 14:51:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28361-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; arc=pass (i=1 spf=pass spfdomain=c--e.de); spf=pass (google.com: domain of linux-kernel+bounces-28361-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28361-linux.lists.archive=gmail.com@vger.kernel.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 ADBD91F2BA00 for ; Tue, 16 Jan 2024 22:46:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D12F1E885; Tue, 16 Jan 2024 22:41:16 +0000 (UTC) Received: from cae.in-ulm.de (cae.in-ulm.de [217.10.14.231]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DAAB51D546; Tue, 16 Jan 2024 22:41:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.10.14.231 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705444876; cv=none; b=jzeq8wJvjicJGNbzlra4AljFBhL6w/U1QZkJaIipkN8yMU9MV4RiNAd7N8bBPbEwZvqDMo8HSsRMnPgqrH4KF8UMtQnS/F7KVjEym57bEhgrIvTwQVMa7pWxmxjI3gjhajg3qfRxfxljQpnOrg8gBGkxPeO9Jja0LmirJBwanpA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705444876; c=relaxed/simple; bh=Us1B128cnUSRTVsPfStgm8OL/356CO5Ra0cSmwYpTsg=; h=Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=Qc5AImkPAcvyGjrJo3tKmai4J6oPaB1Gxexsb1BQ1hVhj7wCkzNK4L9ck0yf1kRnoZEdLB302xAfKi2a7nYvd9JKqqSf2tsXv7hDxR3NnAcJsYLDbqRYuLClUnbOFYcssSaKFrleSVT/PWKhWZBotJPFl9uMOxevNEuYOy0IVeE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=c--e.de; spf=pass smtp.mailfrom=c--e.de; arc=none smtp.client-ip=217.10.14.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=c--e.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=c--e.de Received: by cae.in-ulm.de (Postfix, from userid 1000) id E216214042E; Tue, 16 Jan 2024 23:41:11 +0100 (CET) From: "Christian A. Ehrhardt" To: Heikki Krogerus , linux-usb@vger.kernel.org Cc: "Christian A. Ehrhardt" , Dell.Client.Kernel@dell.com, Greg Kroah-Hartman , Neil Armstrong , Hans de Goede , Jack Pham , Fabrice Gasnier , =?UTF-8?q?Samuel=20=C4=8Cavoj?= , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] usb: ucsi_acpi: Quirk to ack a connector change ack cmd Date: Tue, 16 Jan 2024 23:40:41 +0100 Message-Id: <20240116224041.220740-4-lk@c--e.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240116224041.220740-1-lk@c--e.de> References: <20240116224041.220740-1-lk@c--e.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The PPM on some Dell laptops seems to expect that the ACK_CC_CI command to clear the connector change notification is in turn followed by another ACK_CC_CI to acknowledge the ACK_CC_CI command itself. This is in violation of the UCSI spec that states: "The only notification that is not acknowledged by the OPM is the command completion notification for the ACK_CC_CI or the PPM_RESET command." Add a quirk to send this ack anyway. Apply the quirk to all Dell systems. On the first command that acks a connector change send a dummy command to determine if it runs into a timeout. Only activate the quirk if it does. This ensure that we do not break Dell systems that do not need the quirk. Signed-off-by: Christian A. Ehrhardt --- drivers/usb/typec/ucsi/ucsi_acpi.c | 69 ++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c index 33dac67154d2..a0b08b10c4a9 100644 --- a/drivers/usb/typec/ucsi/ucsi_acpi.c +++ b/drivers/usb/typec/ucsi/ucsi_acpi.c @@ -25,6 +25,8 @@ struct ucsi_acpi { unsigned long flags; guid_t guid; u64 cmd; + bool dell_quirk_probed; + bool dell_quirk_active; }; static int ucsi_acpi_dsm(struct ucsi_acpi *ua, int func) @@ -126,12 +128,71 @@ static const struct ucsi_operations ucsi_zenbook_ops = { .async_write = ucsi_acpi_async_write }; -static const struct dmi_system_id zenbook_dmi_id[] = { +/** + * Some Dell laptops expect that an ACK command with the + * UCSI_ACK_CONNECTOR_CHANGE bit set is followed by a (separate) + * ACK command that only has the UCSI_ACK_COMMAND_COMPLETE bit set. + * If this is not done events are not delivered to OSPM and + * subsequent commands will timeout. + */ +static int +ucsi_dell_sync_write(struct ucsi *ucsi, unsigned int offset, + const void *val, size_t val_len) +{ + struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); + u64 cmd = *(u64*)val, ack = 0; + int ret; + + if (UCSI_COMMAND(cmd) == UCSI_ACK_CC_CI && + cmd & UCSI_ACK_CONNECTOR_CHANGE) + ack = UCSI_ACK_CC_CI | UCSI_ACK_COMMAND_COMPLETE; + + ret = ucsi_acpi_sync_write(ucsi, offset, val, val_len); + if (ret != 0) + return ret; + if (ack == 0) + return ret; + + if (!ua->dell_quirk_probed) { + ua->dell_quirk_probed = true; + + cmd = UCSI_GET_CAPABILITY; + ret = ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, &cmd, + sizeof(cmd)); + if (ret == 0) + return ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, + &ack, sizeof(ack)); + if (ret != -ETIMEDOUT) + return ret; + + ua->dell_quirk_active = true; + } + + if (!ua->dell_quirk_active) + return ret; + + return ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, &ack, sizeof(ack)); +} + +static const struct ucsi_operations ucsi_dell_ops = { + .read = ucsi_acpi_read, + .sync_write = ucsi_dell_sync_write, + .async_write = ucsi_acpi_async_write +}; + +static const struct dmi_system_id ucsi_acpi_quirks[] = { { .matches = { DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), DMI_MATCH(DMI_PRODUCT_NAME, "ZenBook UX325UA_UM325UA"), }, + .driver_data = (void *)&ucsi_zenbook_ops, + }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + }, + .driver_data = (void *)&ucsi_dell_ops, }, { } }; @@ -160,6 +221,7 @@ static int ucsi_acpi_probe(struct platform_device *pdev) { struct acpi_device *adev = ACPI_COMPANION(&pdev->dev); const struct ucsi_operations *ops = &ucsi_acpi_ops; + const struct dmi_system_id *id; struct ucsi_acpi *ua; struct resource *res; acpi_status status; @@ -189,8 +251,9 @@ static int ucsi_acpi_probe(struct platform_device *pdev) init_completion(&ua->complete); ua->dev = &pdev->dev; - if (dmi_check_system(zenbook_dmi_id)) - ops = &ucsi_zenbook_ops; + id = dmi_first_match(ucsi_acpi_quirks); + if (id) + ops = id->driver_data; ua->ucsi = ucsi_create(&pdev->dev, ops); if (IS_ERR(ua->ucsi)) -- 2.40.1