Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 6aaceb7

Browse files
Christian A. Ehrhardtgregkh
authored andcommitted
usb: typec: ucsi_acpi: Refactor and fix DELL quirk
Some DELL systems don't like UCSI_ACK_CC_CI commands with the UCSI_ACK_CONNECTOR_CHANGE but not the UCSI_ACK_COMMAND_COMPLETE bit set. The current quirk still leaves room for races because it requires two consecutive ACK commands to be sent. Refactor and significantly simplify the quirk to fix this: Send a dummy command and bundle the connector change ack with the command completion ack in a single UCSI_ACK_CC_CI command. This removes the need to probe for the quirk. While there define flag bits for struct ucsi_acpi->flags in ucsi_acpi.c and don't re-use definitions from ucsi.h for struct ucsi->flags. Fixes: f3be347 ("usb: ucsi_acpi: Quirk to ack a connector change ack cmd") Cc: stable@vger.kernel.org Signed-off-by: Christian A. Ehrhardt <lk@c--e.de> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8550-QRD Link: https://lore.kernel.org/r/20240320073927.1641788-5-lk@c--e.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6b5c85d commit 6aaceb7

File tree

1 file changed

+33
-42
lines changed

1 file changed

+33
-42
lines changed

drivers/usb/typec/ucsi/ucsi_acpi.c

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ struct ucsi_acpi {
2323
void *base;
2424
struct completion complete;
2525
unsigned long flags;
26+
#define UCSI_ACPI_SUPPRESS_EVENT 0
27+
#define UCSI_ACPI_COMMAND_PENDING 1
28+
#define UCSI_ACPI_ACK_PENDING 2
2629
guid_t guid;
2730
u64 cmd;
28-
bool dell_quirk_probed;
29-
bool dell_quirk_active;
3031
};
3132

3233
static int ucsi_acpi_dsm(struct ucsi_acpi *ua, int func)
@@ -79,9 +80,9 @@ static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset,
7980
int ret;
8081

8182
if (ack)
82-
set_bit(ACK_PENDING, &ua->flags);
83+
set_bit(UCSI_ACPI_ACK_PENDING, &ua->flags);
8384
else
84-
set_bit(COMMAND_PENDING, &ua->flags);
85+
set_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags);
8586

8687
ret = ucsi_acpi_async_write(ucsi, offset, val, val_len);
8788
if (ret)
@@ -92,9 +93,9 @@ static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset,
9293

9394
out_clear_bit:
9495
if (ack)
95-
clear_bit(ACK_PENDING, &ua->flags);
96+
clear_bit(UCSI_ACPI_ACK_PENDING, &ua->flags);
9697
else
97-
clear_bit(COMMAND_PENDING, &ua->flags);
98+
clear_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags);
9899

99100
return ret;
100101
}
@@ -129,51 +130,40 @@ static const struct ucsi_operations ucsi_zenbook_ops = {
129130
};
130131

131132
/*
132-
* Some Dell laptops expect that an ACK command with the
133-
* UCSI_ACK_CONNECTOR_CHANGE bit set is followed by a (separate)
134-
* ACK command that only has the UCSI_ACK_COMMAND_COMPLETE bit set.
135-
* If this is not done events are not delivered to OSPM and
136-
* subsequent commands will timeout.
133+
* Some Dell laptops don't like ACK commands with the
134+
* UCSI_ACK_CONNECTOR_CHANGE but not the UCSI_ACK_COMMAND_COMPLETE
135+
* bit set. To work around this send a dummy command and bundle the
136+
* UCSI_ACK_CONNECTOR_CHANGE with the UCSI_ACK_COMMAND_COMPLETE
137+
* for the dummy command.
137138
*/
138139
static int
139140
ucsi_dell_sync_write(struct ucsi *ucsi, unsigned int offset,
140141
const void *val, size_t val_len)
141142
{
142143
struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi);
143-
u64 cmd = *(u64 *)val, ack = 0;
144+
u64 cmd = *(u64 *)val;
145+
u64 dummycmd = UCSI_GET_CAPABILITY;
144146
int ret;
145147

146-
if (UCSI_COMMAND(cmd) == UCSI_ACK_CC_CI &&
147-
cmd & UCSI_ACK_CONNECTOR_CHANGE)
148-
ack = UCSI_ACK_CC_CI | UCSI_ACK_COMMAND_COMPLETE;
149-
150-
ret = ucsi_acpi_sync_write(ucsi, offset, val, val_len);
151-
if (ret != 0)
152-
return ret;
153-
if (ack == 0)
154-
return ret;
155-
156-
if (!ua->dell_quirk_probed) {
157-
ua->dell_quirk_probed = true;
158-
159-
cmd = UCSI_GET_CAPABILITY;
160-
ret = ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, &cmd,
161-
sizeof(cmd));
162-
if (ret == 0)
163-
return ucsi_acpi_sync_write(ucsi, UCSI_CONTROL,
164-
&ack, sizeof(ack));
165-
if (ret != -ETIMEDOUT)
148+
if (cmd == (UCSI_ACK_CC_CI | UCSI_ACK_CONNECTOR_CHANGE)) {
149+
cmd |= UCSI_ACK_COMMAND_COMPLETE;
150+
151+
/*
152+
* The UCSI core thinks it is sending a connector change ack
153+
* and will accept new connector change events. We don't want
154+
* this to happen for the dummy command as its response will
155+
* still report the very event that the core is trying to clear.
156+
*/
157+
set_bit(UCSI_ACPI_SUPPRESS_EVENT, &ua->flags);
158+
ret = ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, &dummycmd,
159+
sizeof(dummycmd));
160+
clear_bit(UCSI_ACPI_SUPPRESS_EVENT, &ua->flags);
161+
162+
if (ret < 0)
166163
return ret;
167-
168-
ua->dell_quirk_active = true;
169-
dev_err(ua->dev, "Firmware bug: Additional ACK required after ACKing a connector change.\n");
170-
dev_err(ua->dev, "Firmware bug: Enabling workaround\n");
171164
}
172165

173-
if (!ua->dell_quirk_active)
174-
return ret;
175-
176-
return ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, &ack, sizeof(ack));
166+
return ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd));
177167
}
178168

179169
static const struct ucsi_operations ucsi_dell_ops = {
@@ -209,13 +199,14 @@ static void ucsi_acpi_notify(acpi_handle handle, u32 event, void *data)
209199
if (ret)
210200
return;
211201

212-
if (UCSI_CCI_CONNECTOR(cci))
202+
if (UCSI_CCI_CONNECTOR(cci) &&
203+
!test_bit(UCSI_ACPI_SUPPRESS_EVENT, &ua->flags))
213204
ucsi_connector_change(ua->ucsi, UCSI_CCI_CONNECTOR(cci));
214205

215206
if (cci & UCSI_CCI_ACK_COMPLETE && test_bit(ACK_PENDING, &ua->flags))
216207
complete(&ua->complete);
217208
if (cci & UCSI_CCI_COMMAND_COMPLETE &&
218-
test_bit(COMMAND_PENDING, &ua->flags))
209+
test_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags))
219210
complete(&ua->complete);
220211
}
221212

0 commit comments

Comments
 (0)