]> www.infradead.org Git - users/willy/xarray.git/commitdiff
usb: typec: ucsi: Only enable supported notifications
authorDiogo Ivo <diogo.ivo@tecnico.ulisboa.pt>
Wed, 27 Mar 2024 12:11:42 +0000 (12:11 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 4 Apr 2024 15:06:31 +0000 (17:06 +0200)
The UCSI specification defines some notifications to be optional for the
PPM to support. From these only enable the ones the PPM informs us are
actually supported.

Signed-off-by: Diogo Ivo <diogo.ivo@tecnico.ulisboa.pt>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/yhz7nq622mbg3rqsyvqz632pc756niagpfbnzayfswhzo7esho@vrdtx5c3hjgx
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/ucsi/ucsi.c

index 31d8a46ae5e7cb4c5fee6f7b663517a6c367d348..f7157215eed6bbec82b38da1979f5ac605d79d03 100644 (file)
@@ -1672,6 +1672,27 @@ out_unlock:
        return ret;
 }
 
+static u64 ucsi_get_supported_notifications(struct ucsi *ucsi)
+{
+       u8 features = ucsi->cap.features;
+       u64 ntfy = UCSI_ENABLE_NTFY_ALL;
+
+       if (!(features & UCSI_CAP_ALT_MODE_DETAILS))
+               ntfy &= ~UCSI_ENABLE_NTFY_CAM_CHANGE;
+
+       if (!(features & UCSI_CAP_PDO_DETAILS))
+               ntfy &= ~(UCSI_ENABLE_NTFY_PWR_LEVEL_CHANGE |
+                         UCSI_ENABLE_NTFY_CAP_CHANGE);
+
+       if (!(features & UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS))
+               ntfy &= ~UCSI_ENABLE_NTFY_EXT_PWR_SRC_CHANGE;
+
+       if (!(features & UCSI_CAP_PD_RESET))
+               ntfy &= ~UCSI_ENABLE_NTFY_PD_RESET_COMPLETE;
+
+       return ntfy;
+}
+
 /**
  * ucsi_init - Initialize UCSI interface
  * @ucsi: UCSI to be initialized
@@ -1726,8 +1747,8 @@ static int ucsi_init(struct ucsi *ucsi)
                        goto err_unregister;
        }
 
-       /* Enable all notifications */
-       ntfy = UCSI_ENABLE_NTFY_ALL;
+       /* Enable all supported notifications */
+       ntfy = ucsi_get_supported_notifications(ucsi);
        command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;
        ret = ucsi_send_command(ucsi, command, NULL, 0);
        if (ret < 0)