All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: "Samuel Čavoj" <samuel@cavoj.net>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: typec: ucsi: introduce read_explicit operation
Date: Thu, 16 Mar 2023 15:08:03 +0200	[thread overview]
Message-ID: <ZBMUsweZjfqxZJdc@kuha.fi.intel.com> (raw)
In-Reply-To: <ZAi1KO+WUs+9nNOn@kuha.fi.intel.com>

[-- Attachment #1: Type: text/plain, Size: 929 bytes --]

On Wed, Mar 08, 2023 at 06:17:47PM +0200, Heikki Krogerus wrote:
> Hi Samuel,
> 
> > I asked that Samuel to share this here, but perhaps we should consider
> > it still as an RFC. I have tested this with some of my platforms, but
> > I want to test more.
> 
> Sorry about the slow progress, but this is causing commands to fail on
> some platforms. I've been trying to figure out how to fix those, but
> nothing has worked so far.
> 
> I think we have to handle this with a DMI quick in ucsi_acpi.c. I
> don't have any other ideas. I'll try a few more things, and then
> prepare a patch for that.

Unfortunately nothing seems to work... I'm attaching the DMI quirk
patch here. Can you test it?

I'm not sure if the DMI_PRODUCT_NAME is just "ZenBook" so you may
need to fix that in the patch!!

You can get the correct value by running dmidecode. This should work:

        % dmidecode -s system-product-name

thanks,

-- 
heikki

[-- Attachment #2: 0001-usb-typec-ucsi-acpi-Quirk-for-ZenBook.patch --]
[-- Type: text/plain, Size: 2913 bytes --]

From 6111911b5cd9da86679b0942f5df01b7c1516cae Mon Sep 17 00:00:00 2001
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Date: Thu, 16 Mar 2023 14:59:30 +0200
Subject: [PATCH] usb: typec: ucsi: acpi: Quirk for ZenBook

Interim. Still WIP.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/usb/typec/ucsi/ucsi_acpi.c | 43 +++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c
index 62206a6b8ea75..873e64f48b477 100644
--- a/drivers/usb/typec/ucsi/ucsi_acpi.c
+++ b/drivers/usb/typec/ucsi/ucsi_acpi.c
@@ -9,6 +9,7 @@
 #include <linux/platform_device.h>
 #include <linux/module.h>
 #include <linux/acpi.h>
+#include <linux/dmi.h>
 
 #include "ucsi.h"
 
@@ -23,6 +24,7 @@ struct ucsi_acpi {
 	struct completion complete;
 	unsigned long flags;
 	guid_t guid;
+	u64 cmd;
 };
 
 static int ucsi_acpi_dsm(struct ucsi_acpi *ua, int func)
@@ -62,6 +64,7 @@ static int ucsi_acpi_async_write(struct ucsi *ucsi, unsigned int offset,
 	struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi);
 
 	memcpy(ua->base + offset, val, val_len);
+	ua->cmd = *(u64*)val;
 
 	return ucsi_acpi_dsm(ua, UCSI_DSM_FUNC_WRITE);
 }
@@ -93,6 +96,40 @@ static const struct ucsi_operations ucsi_acpi_ops = {
 	.async_write = ucsi_acpi_async_write
 };
 
+static int
+ucsi_zenbook_read(struct ucsi *ucsi, unsigned int offset, void *val, size_t val_len)
+{
+	struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi);
+	int ret;
+
+	if (ua->cmd & (UCSI_VERSION | UCSI_PPM_RESET)) {
+		ret = ucsi_acpi_dsm(ua, UCSI_DSM_FUNC_READ);
+		if (ret)
+			return ret;
+	}
+
+	memcpy(val, ua->base + offset, val_len);
+	ua->cmd = 0;
+
+	return 0;
+}
+
+static const struct ucsi_operations ucsi_zenbook_ops = {
+	.read = ucsi_zenbook_read,
+	.sync_write = ucsi_acpi_sync_write,
+	.async_write = ucsi_acpi_async_write
+};
+
+static const struct dmi_system_id zenbook_dmi_id[] = {
+	{
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "ZenBook"),
+		},
+	},
+	{ }
+};
+
 static void ucsi_acpi_notify(acpi_handle handle, u32 event, void *data)
 {
 	struct ucsi_acpi *ua = data;
@@ -114,6 +151,7 @@ static void ucsi_acpi_notify(acpi_handle handle, u32 event, void *data)
 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;
 	struct ucsi_acpi *ua;
 	struct resource *res;
 	acpi_status status;
@@ -143,7 +181,10 @@ static int ucsi_acpi_probe(struct platform_device *pdev)
 	init_completion(&ua->complete);
 	ua->dev = &pdev->dev;
 
-	ua->ucsi = ucsi_create(&pdev->dev, &ucsi_acpi_ops);
+	if (dmi_check_system(zenbook_dmi_id))
+		ops = &ucsi_zenbook_ops;
+
+	ua->ucsi = ucsi_create(&pdev->dev, ops);
 	if (IS_ERR(ua->ucsi))
 		return PTR_ERR(ua->ucsi);
 
-- 
2.39.2


  reply	other threads:[~2023-03-16 13:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-20 23:39 [PATCH] usb: typec: ucsi: introduce read_explicit operation Samuel Čavoj
2023-01-21  7:17 ` Greg KH
2023-01-24 11:21   ` Heikki Krogerus
2023-03-08 16:17     ` Heikki Krogerus
2023-03-16 13:08       ` Heikki Krogerus [this message]
2023-03-18  2:04         ` Samuel Čavoj
2023-03-29 23:48           ` Samuel Čavoj
2023-03-30 14:06             ` Heikki Krogerus
2023-04-01 18:06               ` Samuel Čavoj
2023-04-04 13:02                 ` Heikki Krogerus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZBMUsweZjfqxZJdc@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=samuel@cavoj.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.