diff mbox series

usb: typec: ucsi: Only enable supported notifications

Message ID yhz7nq622mbg3rqsyvqz632pc756niagpfbnzayfswhzo7esho@vrdtx5c3hjgx
State New
Headers show
Series usb: typec: ucsi: Only enable supported notifications | expand

Commit Message

Diogo Ivo March 27, 2024, 12:11 p.m. UTC
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>
---
 drivers/usb/typec/ucsi/ucsi.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

Comments

Heikki Krogerus April 2, 2024, 10:10 a.m. UTC | #1
On Wed, Mar 27, 2024 at 12:11:42PM +0000, Diogo Ivo wrote:
> 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>

> ---
>  drivers/usb/typec/ucsi/ucsi.c | 25 +++++++++++++++++++++++--
>  1 file changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index cf52cb34d285..0c8f3b3a99d6 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1626,6 +1626,27 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
>  	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
> @@ -1679,8 +1700,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)
> -- 
> 2.44.0
diff mbox series

Patch

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index cf52cb34d285..0c8f3b3a99d6 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1626,6 +1626,27 @@  static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
 	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
@@ -1679,8 +1700,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)