linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: typec: ucsi: Only enable supported notifications
@ 2024-03-27 12:11 Diogo Ivo
  2024-04-02 10:10 ` Heikki Krogerus
  0 siblings, 1 reply; 2+ messages in thread
From: Diogo Ivo @ 2024-03-27 12:11 UTC (permalink / raw)
  To: heikki.krogerus, gregkh, pmalani, jthies, neil.armstrong,
	abhishekpandit, fabrice.gasnier, linux-usb
  Cc: diogo.ivo

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

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: typec: ucsi: Only enable supported notifications
  2024-03-27 12:11 [PATCH] usb: typec: ucsi: Only enable supported notifications Diogo Ivo
@ 2024-04-02 10:10 ` Heikki Krogerus
  0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2024-04-02 10:10 UTC (permalink / raw)
  To: Diogo Ivo
  Cc: gregkh, pmalani, jthies, neil.armstrong, abhishekpandit,
	fabrice.gasnier, linux-usb

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

-- 
heikki

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-02 10:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-27 12:11 [PATCH] usb: typec: ucsi: Only enable supported notifications Diogo Ivo
2024-04-02 10:10 ` Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).