usb: typec: ucsi: Only enable supported notifications

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>
This commit is contained in:
Diogo Ivo 2024-03-27 12:11:42 +00:00 committed by Greg Kroah-Hartman
parent a2723e29c7
commit 27ffe4ff0b

View 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)