diff mbox series

[2/2] platform/chrome: cros_typec_vdm: Add Attention support

Message ID 20230126205620.3714994-2-pmalani@chromium.org (mailing list archive)
State Accepted
Commit f54c013e7eef2962e610c9223e13659e65dfb550
Headers show
Series [1/2] platform/chrome: cros_ec: Add VDM attention headers | expand

Commit Message

Prashant Malani Jan. 26, 2023, 8:55 p.m. UTC
Add support to retrieve VDM attention messages and forward them to the
appropriate alt mode driver.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
---
 drivers/platform/chrome/cros_ec_typec.c  |  8 +++++
 drivers/platform/chrome/cros_typec_vdm.c | 40 ++++++++++++++++++++++++
 drivers/platform/chrome/cros_typec_vdm.h |  1 +
 3 files changed, 49 insertions(+)

Comments

Benson Leung Jan. 26, 2023, 9:01 p.m. UTC | #1
On Thu, Jan 26, 2023 at 08:55:46PM +0000, Prashant Malani wrote:
> Add support to retrieve VDM attention messages and forward them to the
> appropriate alt mode driver.
> 
> Signed-off-by: Prashant Malani <pmalani@chromium.org>

Reviewed-by: Benson Leung <bleung@chromium.org>


> ---
>  drivers/platform/chrome/cros_ec_typec.c  |  8 +++++
>  drivers/platform/chrome/cros_typec_vdm.c | 40 ++++++++++++++++++++++++
>  drivers/platform/chrome/cros_typec_vdm.h |  1 +
>  3 files changed, 49 insertions(+)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 1abb471840d5..71f5d7d8e055 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -1015,6 +1015,14 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
>  		if (ret < 0)
>  			dev_warn(typec->dev, "Failed VDM Reply event clear, port: %d\n", port_num);
>  	}
> +
> +	if (resp.events & PD_STATUS_EVENT_VDM_ATTENTION) {
> +		cros_typec_handle_vdm_attention(typec, port_num);
> +		ret = cros_typec_send_clear_event(typec, port_num, PD_STATUS_EVENT_VDM_ATTENTION);
> +		if (ret < 0)
> +			dev_warn(typec->dev, "Failed VDM Attenetion event clear, port: %d\n",
> +				 port_num);
> +	}
>  }
>  
>  static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
> diff --git a/drivers/platform/chrome/cros_typec_vdm.c b/drivers/platform/chrome/cros_typec_vdm.c
> index 06f4a55999c5..20515ee0a20e 100644
> --- a/drivers/platform/chrome/cros_typec_vdm.c
> +++ b/drivers/platform/chrome/cros_typec_vdm.c
> @@ -13,6 +13,46 @@
>  #include "cros_ec_typec.h"
>  #include "cros_typec_vdm.h"
>  
> +/*
> + * Retrieves pending VDM attention messages from the EC and forwards them to the altmode driver
> + * based on SVID.
> + */
> +void cros_typec_handle_vdm_attention(struct cros_typec_data *typec, int port_num)
> +{
> +	struct ec_response_typec_vdm_response resp;
> +	struct ec_params_typec_vdm_response req = {
> +		.port = port_num,
> +	};
> +	struct typec_altmode *amode;
> +	u16 svid;
> +	u32 hdr;
> +	int ret;
> +
> +	do {
> +		ret = cros_ec_cmd(typec->ec, 0, EC_CMD_TYPEC_VDM_RESPONSE, &req,
> +				sizeof(req), &resp, sizeof(resp));
> +		if (ret < 0) {
> +			dev_warn(typec->dev, "Failed VDM response fetch, port: %d\n", port_num);
> +			return;
> +		}
> +
> +		hdr = resp.vdm_response[0];
> +		svid = PD_VDO_VID(hdr);
> +		dev_dbg(typec->dev, "Received VDM Attention header: %x, port: %d\n", hdr, port_num);
> +
> +		amode = typec_match_altmode(typec->ports[port_num]->port_altmode,
> +					    CROS_EC_ALTMODE_MAX, svid, PD_VDO_OPOS(hdr));
> +		if (!amode) {
> +			dev_err(typec->dev,
> +				"Received VDM for unregistered altmode (SVID:%x), port: %d\n",
> +				svid, port_num);
> +			return;
> +		}
> +
> +		typec_altmode_attention(amode, resp.vdm_attention[1]);
> +	} while (resp.vdm_attention_left);
> +}
> +
>  /*
>   * Retrieves a VDM response from the EC and forwards it to the altmode driver based on SVID.
>   */
> diff --git a/drivers/platform/chrome/cros_typec_vdm.h b/drivers/platform/chrome/cros_typec_vdm.h
> index 003587525554..95a6a75d32b6 100644
> --- a/drivers/platform/chrome/cros_typec_vdm.h
> +++ b/drivers/platform/chrome/cros_typec_vdm.h
> @@ -7,6 +7,7 @@
>  
>  extern struct typec_altmode_ops port_amode_ops;
>  
> +void cros_typec_handle_vdm_attention(struct cros_typec_data *typec, int port_num);
>  void cros_typec_handle_vdm_response(struct cros_typec_data *typec, int port_num);
>  
>  #endif /*  __CROS_TYPEC_VDM__ */
> -- 
> 2.39.1.456.gfc5497dd1b-goog
> 
>
Heikki Krogerus Jan. 27, 2023, 3:11 p.m. UTC | #2
On Thu, Jan 26, 2023 at 08:55:46PM +0000, Prashant Malani wrote:
> Add support to retrieve VDM attention messages and forward them to the
> appropriate alt mode driver.
> 
> Signed-off-by: Prashant Malani <pmalani@chromium.org>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/platform/chrome/cros_ec_typec.c  |  8 +++++
>  drivers/platform/chrome/cros_typec_vdm.c | 40 ++++++++++++++++++++++++
>  drivers/platform/chrome/cros_typec_vdm.h |  1 +
>  3 files changed, 49 insertions(+)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 1abb471840d5..71f5d7d8e055 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -1015,6 +1015,14 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
>  		if (ret < 0)
>  			dev_warn(typec->dev, "Failed VDM Reply event clear, port: %d\n", port_num);
>  	}
> +
> +	if (resp.events & PD_STATUS_EVENT_VDM_ATTENTION) {
> +		cros_typec_handle_vdm_attention(typec, port_num);
> +		ret = cros_typec_send_clear_event(typec, port_num, PD_STATUS_EVENT_VDM_ATTENTION);
> +		if (ret < 0)
> +			dev_warn(typec->dev, "Failed VDM Attenetion event clear, port: %d\n",
> +				 port_num);
> +	}
>  }
>  
>  static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
> diff --git a/drivers/platform/chrome/cros_typec_vdm.c b/drivers/platform/chrome/cros_typec_vdm.c
> index 06f4a55999c5..20515ee0a20e 100644
> --- a/drivers/platform/chrome/cros_typec_vdm.c
> +++ b/drivers/platform/chrome/cros_typec_vdm.c
> @@ -13,6 +13,46 @@
>  #include "cros_ec_typec.h"
>  #include "cros_typec_vdm.h"
>  
> +/*
> + * Retrieves pending VDM attention messages from the EC and forwards them to the altmode driver
> + * based on SVID.
> + */
> +void cros_typec_handle_vdm_attention(struct cros_typec_data *typec, int port_num)
> +{
> +	struct ec_response_typec_vdm_response resp;
> +	struct ec_params_typec_vdm_response req = {
> +		.port = port_num,
> +	};
> +	struct typec_altmode *amode;
> +	u16 svid;
> +	u32 hdr;
> +	int ret;
> +
> +	do {
> +		ret = cros_ec_cmd(typec->ec, 0, EC_CMD_TYPEC_VDM_RESPONSE, &req,
> +				sizeof(req), &resp, sizeof(resp));
> +		if (ret < 0) {
> +			dev_warn(typec->dev, "Failed VDM response fetch, port: %d\n", port_num);
> +			return;
> +		}
> +
> +		hdr = resp.vdm_response[0];
> +		svid = PD_VDO_VID(hdr);
> +		dev_dbg(typec->dev, "Received VDM Attention header: %x, port: %d\n", hdr, port_num);
> +
> +		amode = typec_match_altmode(typec->ports[port_num]->port_altmode,
> +					    CROS_EC_ALTMODE_MAX, svid, PD_VDO_OPOS(hdr));
> +		if (!amode) {
> +			dev_err(typec->dev,
> +				"Received VDM for unregistered altmode (SVID:%x), port: %d\n",
> +				svid, port_num);
> +			return;
> +		}
> +
> +		typec_altmode_attention(amode, resp.vdm_attention[1]);
> +	} while (resp.vdm_attention_left);
> +}
> +
>  /*
>   * Retrieves a VDM response from the EC and forwards it to the altmode driver based on SVID.
>   */
> diff --git a/drivers/platform/chrome/cros_typec_vdm.h b/drivers/platform/chrome/cros_typec_vdm.h
> index 003587525554..95a6a75d32b6 100644
> --- a/drivers/platform/chrome/cros_typec_vdm.h
> +++ b/drivers/platform/chrome/cros_typec_vdm.h
> @@ -7,6 +7,7 @@
>  
>  extern struct typec_altmode_ops port_amode_ops;
>  
> +void cros_typec_handle_vdm_attention(struct cros_typec_data *typec, int port_num);
>  void cros_typec_handle_vdm_response(struct cros_typec_data *typec, int port_num);
>  
>  #endif /*  __CROS_TYPEC_VDM__ */
> -- 
> 2.39.1.456.gfc5497dd1b-goog
diff mbox series

Patch

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 1abb471840d5..71f5d7d8e055 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -1015,6 +1015,14 @@  static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
 		if (ret < 0)
 			dev_warn(typec->dev, "Failed VDM Reply event clear, port: %d\n", port_num);
 	}
+
+	if (resp.events & PD_STATUS_EVENT_VDM_ATTENTION) {
+		cros_typec_handle_vdm_attention(typec, port_num);
+		ret = cros_typec_send_clear_event(typec, port_num, PD_STATUS_EVENT_VDM_ATTENTION);
+		if (ret < 0)
+			dev_warn(typec->dev, "Failed VDM Attenetion event clear, port: %d\n",
+				 port_num);
+	}
 }
 
 static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
diff --git a/drivers/platform/chrome/cros_typec_vdm.c b/drivers/platform/chrome/cros_typec_vdm.c
index 06f4a55999c5..20515ee0a20e 100644
--- a/drivers/platform/chrome/cros_typec_vdm.c
+++ b/drivers/platform/chrome/cros_typec_vdm.c
@@ -13,6 +13,46 @@ 
 #include "cros_ec_typec.h"
 #include "cros_typec_vdm.h"
 
+/*
+ * Retrieves pending VDM attention messages from the EC and forwards them to the altmode driver
+ * based on SVID.
+ */
+void cros_typec_handle_vdm_attention(struct cros_typec_data *typec, int port_num)
+{
+	struct ec_response_typec_vdm_response resp;
+	struct ec_params_typec_vdm_response req = {
+		.port = port_num,
+	};
+	struct typec_altmode *amode;
+	u16 svid;
+	u32 hdr;
+	int ret;
+
+	do {
+		ret = cros_ec_cmd(typec->ec, 0, EC_CMD_TYPEC_VDM_RESPONSE, &req,
+				sizeof(req), &resp, sizeof(resp));
+		if (ret < 0) {
+			dev_warn(typec->dev, "Failed VDM response fetch, port: %d\n", port_num);
+			return;
+		}
+
+		hdr = resp.vdm_response[0];
+		svid = PD_VDO_VID(hdr);
+		dev_dbg(typec->dev, "Received VDM Attention header: %x, port: %d\n", hdr, port_num);
+
+		amode = typec_match_altmode(typec->ports[port_num]->port_altmode,
+					    CROS_EC_ALTMODE_MAX, svid, PD_VDO_OPOS(hdr));
+		if (!amode) {
+			dev_err(typec->dev,
+				"Received VDM for unregistered altmode (SVID:%x), port: %d\n",
+				svid, port_num);
+			return;
+		}
+
+		typec_altmode_attention(amode, resp.vdm_attention[1]);
+	} while (resp.vdm_attention_left);
+}
+
 /*
  * Retrieves a VDM response from the EC and forwards it to the altmode driver based on SVID.
  */
diff --git a/drivers/platform/chrome/cros_typec_vdm.h b/drivers/platform/chrome/cros_typec_vdm.h
index 003587525554..95a6a75d32b6 100644
--- a/drivers/platform/chrome/cros_typec_vdm.h
+++ b/drivers/platform/chrome/cros_typec_vdm.h
@@ -7,6 +7,7 @@ 
 
 extern struct typec_altmode_ops port_amode_ops;
 
+void cros_typec_handle_vdm_attention(struct cros_typec_data *typec, int port_num);
 void cros_typec_handle_vdm_response(struct cros_typec_data *typec, int port_num);
 
 #endif /*  __CROS_TYPEC_VDM__ */