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

Commit 3de4f99

Browse files
Christian A. Ehrhardtgregkh
authored andcommitted
usb: typec: ucsi: Clear UCSI_CCI_RESET_COMPLETE before reset
Check the UCSI_CCI_RESET_COMPLETE complete flag before starting another reset. Use a UCSI_SET_NOTIFICATION_ENABLE command to clear the flag if it is set. Signed-off-by: Christian A. Ehrhardt <lk@c--e.de> Cc: stable <stable@kernel.org> 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-6-lk@c--e.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6aaceb7 commit 3de4f99

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

drivers/usb/typec/ucsi/ucsi.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,13 +1264,47 @@ static int ucsi_reset_connector(struct ucsi_connector *con, bool hard)
12641264

12651265
static int ucsi_reset_ppm(struct ucsi *ucsi)
12661266
{
1267-
u64 command = UCSI_PPM_RESET;
1267+
u64 command;
12681268
unsigned long tmo;
12691269
u32 cci;
12701270
int ret;
12711271

12721272
mutex_lock(&ucsi->ppm_lock);
12731273

1274+
ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci));
1275+
if (ret < 0)
1276+
goto out;
1277+
1278+
/*
1279+
* If UCSI_CCI_RESET_COMPLETE is already set we must clear
1280+
* the flag before we start another reset. Send a
1281+
* UCSI_SET_NOTIFICATION_ENABLE command to achieve this.
1282+
* Ignore a timeout and try the reset anyway if this fails.
1283+
*/
1284+
if (cci & UCSI_CCI_RESET_COMPLETE) {
1285+
command = UCSI_SET_NOTIFICATION_ENABLE;
1286+
ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command,
1287+
sizeof(command));
1288+
if (ret < 0)
1289+
goto out;
1290+
1291+
tmo = jiffies + msecs_to_jiffies(UCSI_TIMEOUT_MS);
1292+
do {
1293+
ret = ucsi->ops->read(ucsi, UCSI_CCI,
1294+
&cci, sizeof(cci));
1295+
if (ret < 0)
1296+
goto out;
1297+
if (cci & UCSI_CCI_COMMAND_COMPLETE)
1298+
break;
1299+
if (time_is_before_jiffies(tmo))
1300+
break;
1301+
msleep(20);
1302+
} while (1);
1303+
1304+
WARN_ON(cci & UCSI_CCI_RESET_COMPLETE);
1305+
}
1306+
1307+
command = UCSI_PPM_RESET;
12741308
ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command,
12751309
sizeof(command));
12761310
if (ret < 0)

0 commit comments

Comments
 (0)