diff mbox series

[4/4] usb: ucsi: Apply UCSI_ACK_CONNECTOR_CHANGE_ACK_CMD to Dell systems

Message ID 20240107001701.130535-5-lk@c--e.de (mailing list archive)
State New
Headers show
Series Make UCSI on Dell Latitude work | expand

Commit Message

Christian Ehrhardt Jan. 7, 2024, 12:17 a.m. UTC
Apply the UCSI_ACK_CONNECTOR_CHANGE_ACK_CMD to all Dell systems.

There are various reports that ucsi does not work on Dell systems
with "GET_CONNECTOR_STATUS failed". At least some of these are
most likely due to the need for this quirk.

If the logic is wrong users can still use the new quirk override
for the typec_ucsi module to disable the quirk.

Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
---
 drivers/usb/typec/ucsi/ucsi_acpi.c | 36 +++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)

Comments

Heikki Krogerus Jan. 15, 2024, 9:05 a.m. UTC | #1
Hi Christian,

On Sun, Jan 07, 2024 at 01:17:01AM +0100, Christian A. Ehrhardt wrote:
> Apply the UCSI_ACK_CONNECTOR_CHANGE_ACK_CMD to all Dell systems.
> 
> There are various reports that ucsi does not work on Dell systems
> with "GET_CONNECTOR_STATUS failed". At least some of these are
> most likely due to the need for this quirk.
> 
> If the logic is wrong users can still use the new quirk override
> for the typec_ucsi module to disable the quirk.
> 
> Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
> ---
>  drivers/usb/typec/ucsi/ucsi_acpi.c | 36 +++++++++++++++++++++++++-----
>  1 file changed, 31 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c
> index 78a0d13584ad..690d5e55bdc4 100644
> --- a/drivers/usb/typec/ucsi/ucsi_acpi.c
> +++ b/drivers/usb/typec/ucsi/ucsi_acpi.c
> @@ -27,6 +27,11 @@ struct ucsi_acpi {
>  	u64 cmd;
>  };
>  
> +struct ucsi_acpi_attach_data {
> +	const struct ucsi_operations *ops;
> +	unsigned int quirks;
> +};
> +
>  static int ucsi_acpi_dsm(struct ucsi_acpi *ua, int func)
>  {
>  	union acpi_object *obj;
> @@ -121,12 +126,30 @@ static const struct ucsi_operations ucsi_zenbook_ops = {
>  	.async_write = ucsi_acpi_async_write
>  };
>  
> -static const struct dmi_system_id zenbook_dmi_id[] = {
> +static const struct ucsi_acpi_attach_data ucsi_acpi_default_attach_data = {
> +	.ops = &ucsi_acpi_ops,
> +	.quirks = 0
> +};
> +
> +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 = &(struct ucsi_acpi_attach_data) {
> +			.ops = &ucsi_zenbook_ops,
> +			.quirks = 0
> +		},
> +	},
> +	{
> +		.matches = {
> +			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
> +		},
> +		.driver_data = &(struct ucsi_acpi_attach_data) {
> +			.ops = &ucsi_acpi_ops,
> +			.quirks = UCSI_ACK_CONNECTOR_CHANGE_ACK_CMD

Please don't add any more quirk flags like that for single user (you
may never have more than the one user for it). Let's just first handle
this with only Dell's like I proposed.

If there are other platforms that need the same quirk, then we can
start looking at how to share the quirk.

thanks,
Christian Ehrhardt Jan. 15, 2024, 11:57 a.m. UTC | #2
Hi Heikki,

On Mon, Jan 15, 2024 at 11:05:36AM +0200, Heikki Krogerus wrote:
> Hi Christian,
> 
> On Sun, Jan 07, 2024 at 01:17:01AM +0100, Christian A. Ehrhardt wrote:
> > Apply the UCSI_ACK_CONNECTOR_CHANGE_ACK_CMD to all Dell systems.
> > 
> > There are various reports that ucsi does not work on Dell systems
> > with "GET_CONNECTOR_STATUS failed". At least some of these are
> > most likely due to the need for this quirk.
> > 
> > If the logic is wrong users can still use the new quirk override
> > for the typec_ucsi module to disable the quirk.
> > 
> > Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
> > ---
> >  drivers/usb/typec/ucsi/ucsi_acpi.c | 36 +++++++++++++++++++++++++-----
> >  1 file changed, 31 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c
> > index 78a0d13584ad..690d5e55bdc4 100644
> > --- a/drivers/usb/typec/ucsi/ucsi_acpi.c
> > +++ b/drivers/usb/typec/ucsi/ucsi_acpi.c
> > @@ -27,6 +27,11 @@ struct ucsi_acpi {
> >  	u64 cmd;
> >  };
> >  
> > +struct ucsi_acpi_attach_data {
> > +	const struct ucsi_operations *ops;
> > +	unsigned int quirks;
> > +};
> > +
> >  static int ucsi_acpi_dsm(struct ucsi_acpi *ua, int func)
> >  {
> >  	union acpi_object *obj;
> > @@ -121,12 +126,30 @@ static const struct ucsi_operations ucsi_zenbook_ops = {
> >  	.async_write = ucsi_acpi_async_write
> >  };
> >  
> > -static const struct dmi_system_id zenbook_dmi_id[] = {
> > +static const struct ucsi_acpi_attach_data ucsi_acpi_default_attach_data = {
> > +	.ops = &ucsi_acpi_ops,
> > +	.quirks = 0
> > +};
> > +
> > +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 = &(struct ucsi_acpi_attach_data) {
> > +			.ops = &ucsi_zenbook_ops,
> > +			.quirks = 0
> > +		},
> > +	},
> > +	{
> > +		.matches = {
> > +			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
> > +		},
> > +		.driver_data = &(struct ucsi_acpi_attach_data) {
> > +			.ops = &ucsi_acpi_ops,
> > +			.quirks = UCSI_ACK_CONNECTOR_CHANGE_ACK_CMD
> 
> Please don't add any more quirk flags like that for single user (you
> may never have more than the one user for it). Let's just first handle
> this with only Dell's like I proposed.
> 
> If there are other platforms that need the same quirk, then we can
> start looking at how to share the quirk.

Ok, thanks for the feedback. Will do.

However, please note that it is not clear if it is all or only some
dells that need this. This is the prime reason why I was looking for
a way to enable/disable the quirk.

     regards   Christian
diff mbox series

Patch

diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c
index 78a0d13584ad..690d5e55bdc4 100644
--- a/drivers/usb/typec/ucsi/ucsi_acpi.c
+++ b/drivers/usb/typec/ucsi/ucsi_acpi.c
@@ -27,6 +27,11 @@  struct ucsi_acpi {
 	u64 cmd;
 };
 
+struct ucsi_acpi_attach_data {
+	const struct ucsi_operations *ops;
+	unsigned int quirks;
+};
+
 static int ucsi_acpi_dsm(struct ucsi_acpi *ua, int func)
 {
 	union acpi_object *obj;
@@ -121,12 +126,30 @@  static const struct ucsi_operations ucsi_zenbook_ops = {
 	.async_write = ucsi_acpi_async_write
 };
 
-static const struct dmi_system_id zenbook_dmi_id[] = {
+static const struct ucsi_acpi_attach_data ucsi_acpi_default_attach_data = {
+	.ops = &ucsi_acpi_ops,
+	.quirks = 0
+};
+
+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 = &(struct ucsi_acpi_attach_data) {
+			.ops = &ucsi_zenbook_ops,
+			.quirks = 0
+		},
+	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+		},
+		.driver_data = &(struct ucsi_acpi_attach_data) {
+			.ops = &ucsi_acpi_ops,
+			.quirks = UCSI_ACK_CONNECTOR_CHANGE_ACK_CMD
+		},
 	},
 	{ }
 };
@@ -152,7 +175,8 @@  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;
+	const struct dmi_system_id *id;
+	const struct ucsi_acpi_attach_data *attach;
 	struct ucsi_acpi *ua;
 	struct resource *res;
 	acpi_status status;
@@ -182,10 +206,12 @@  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;
+	attach = &ucsi_acpi_default_attach_data;
+	id = dmi_first_match(ucsi_acpi_quirks);
+	if (id)
+		attach = id->driver_data;
 
-	ua->ucsi = ucsi_create(&pdev->dev, ops, 0);
+	ua->ucsi = ucsi_create(&pdev->dev, attach->ops, attach->quirks);
 	if (IS_ERR(ua->ucsi))
 		return PTR_ERR(ua->ucsi);