1 From ca61215561a0947476576f8ee06c0dca69b25884 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Wed, 20 Mar 2024 08:39:23 +0100
4 Subject: usb: typec: ucsi: Check for notifications after init
6 From: Christian A. Ehrhardt <lk@c--e.de>
8 [ Upstream commit 808a8b9e0b87bbc72bcc1f7ddfe5d04746e7ce56 ]
10 The completion notification for the final SET_NOTIFICATION_ENABLE
11 command during initialization can include a connector change
12 notification. However, at the time this completion notification is
13 processed, the ucsi struct is not ready to handle this notification.
14 As a result the notification is ignored and the controller
15 never sends an interrupt again.
17 Re-check CCI for a pending connector state change after
18 initialization is complete. Adjust the corresponding debug
21 Fixes: 71a1fa0df2a3 ("usb: typec: ucsi: Store the notification mask")
22 Cc: stable@vger.kernel.org
23 Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
24 Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
25 Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8550-QRD
26 Link: https://lore.kernel.org/r/20240320073927.1641788-3-lk@c--e.de
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 Signed-off-by: Sasha Levin <sashal@kernel.org>
30 drivers/usb/typec/ucsi/ucsi.c | 10 +++++++++-
31 1 file changed, 9 insertions(+), 1 deletion(-)
33 diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
34 index 98f335cbbcdea..1fd4aaf348047 100644
35 --- a/drivers/usb/typec/ucsi/ucsi.c
36 +++ b/drivers/usb/typec/ucsi/ucsi.c
37 @@ -855,7 +855,7 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num)
38 struct ucsi_connector *con = &ucsi->connector[num - 1];
40 if (!(ucsi->ntfy & UCSI_ENABLE_NTFY_CONNECTOR_CHANGE)) {
41 - dev_dbg(ucsi->dev, "Bogus connector change event\n");
42 + dev_dbg(ucsi->dev, "Early connector change event\n");
46 @@ -1248,6 +1248,7 @@ static int ucsi_init(struct ucsi *ucsi)
48 struct ucsi_connector *con, *connector;
54 @@ -1300,6 +1301,13 @@ static int ucsi_init(struct ucsi *ucsi)
56 ucsi->connector = connector;
59 + ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci));
62 + if (UCSI_CCI_CONNECTOR(READ_ONCE(cci)))
63 + ucsi_connector_change(ucsi, cci);