Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp2220592rdb; Sun, 21 Jan 2024 12:42:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUQBRtCqV874AJ/yMIZFN7C3S0xB7WiHF+tT5Xgfts6Vdcm1/YDKtWxyfb5WclcX0DtA56 X-Received: by 2002:a05:6358:d59b:b0:176:56f8:77d5 with SMTP id ms27-20020a056358d59b00b0017656f877d5mr759212rwb.1.1705869766551; Sun, 21 Jan 2024 12:42:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705869766; cv=pass; d=google.com; s=arc-20160816; b=vU0pdg/Cbf5KoUzxCpQETlmRMq15V+c1Q5koEoTouMq89S8YwyIVpG1ntLrYoOhwWI kIGaEeoJfTQ2N0NEFuhWrwnPFggVLpxKn/racCr2rDyhA4EWexysED4y4tXIR1Ms1kb7 DoUkpyHOjoPnZUDUJh02aEF1cow3Q4K5nm5OLiMIscPvjLTu0j/sxFtQE5gEDuDxUWya 3qUcqIrgJvQX6gafMsWF+fxTZ4wI1yFw2f9AznD+Wf+JUk6So4ELDWOaCy5OHDrMRHHa R0X8tRYWDx990CkD1p7JwYbJuX9URWViUk7CCzdTeFvVQTczCa4X4fllsi+CDTA383Uu 57kg== 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=GFgaoQ7gp19AqARfkCfjQTztpvgU/robMmtGnCIFimI=; fh=PBT+T+L/Wk7fQyAuF/ivTwxWqTQzcP6BniPDJctp9Xs=; b=FOo7cIY3wOOEzZvpb2a1WQ1BFWHP/pI8o2sOdAE4mxrhu2RqHFbAxWj0kxPA2u3mjP /05iizes/6N7gjNPGAJ1ItpLGvkJBogM+H45n9LA//QWdwB+Q6h6ZD7a6fmcboAPxnK+ sJ2wc5baEXR/HFpTraOeSOmLOAxeSQcSxmCmvax9k1Pbzvmo18VGdlzuTFF4PP53s+nM mZgI6vwcdUmPldZ5TJi0o5ME4UUWSTrANGeJYxzwnWjlLHH+WTavs50PgOV1rFACxhLX qkjvXkR/QmpC9MzlCOvcHtnm0ufuRNqYQj8n86Is/sNXLrh0AsawDvISZAWgaWED2Qm0 zTwg== 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-32187-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32187-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id cm10-20020a17090afa0a00b0028d158b5885si7056805pjb.33.2024.01.21.12.42.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 12:42:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32187-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=c--e.de); spf=pass (google.com: domain of linux-kernel+bounces-32187-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32187-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2CCB8280FBC for ; Sun, 21 Jan 2024 20:42:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 57FCC3985B; Sun, 21 Jan 2024 20:41:50 +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 218B438FA3; Sun, 21 Jan 2024 20:41:46 +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=1705869709; cv=none; b=Ie+OwxdCkjOWLIScxvvCltFl/2ffm5DJpMJSPlhKruFl3npVfMOLVhYhoYc9CnFJ59Spn+YBWYL+v25YFOeLxnSF2hYLwBjF/aYsWeczkmWeol6qV7xpKEUDX7J+KYnF9H/FUc3i6p9zsNAQk+kHLtHuQmJQMKIrt3YMDdt3v2I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705869709; c=relaxed/simple; bh=525/nQ/RCbmWlPgDj+Mt2E13AsRmF5QqZ/hM3AZ3pkE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=k6ilXTQ2clGQhErg+yKDoodBjh5v47Ov7OH9+0ZcRM6UQAs42aigclOOO2mYRpP85gahg4bkMGR439HH3Wwmk2//QTLgyRIWCz98yq3uIE0Q2HNS6lGDsVtFW7Ci1ufbrz4PZaHOsZgmqbGD8DoiuUMuR3oh7ctisVRgtJjdaQI= 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 D281E1402E4; Sun, 21 Jan 2024 21:41:45 +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 v3 3/3] usb: ucsi_acpi: Quirk to ack a connector change ack cmd Date: Sun, 21 Jan 2024 21:41:23 +0100 Message-Id: <20240121204123.275441-4-lk@c--e.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240121204123.275441-1-lk@c--e.de> References: <20240121204123.275441-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 | 71 ++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c index fa222080887d..928eacbeb21a 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,73 @@ 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; + dev_err(ua->dev, "Firmware bug: Additional ACK required after ACKing a connector change.\n"); + dev_err(ua->dev, "Firmware bug: Enabling workaround\n"); + } + + 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 +223,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 +253,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