mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Prashant Malani <pmalani@chromium.org>
Cc: linux-kernel@vger.kernel.org, dzigterman@chromium.org,
	alevkoy@chromium.org, Benson Leung <bleung@chromium.org>,
	Enric Balletbo i Serra <enric.balletbo@collabora.com>,
	Guenter Roeck <groeck@chromium.org>
Subject: Re: [PATCH v2 6/7] platform/chrome: cros_ec_typec: Parse partner PD ID VDOs
Date: Fri, 30 Oct 2020 15:31:14 +0200	[thread overview]
Message-ID: <20201030133114.GE2333887@kuha.fi.intel.com> (raw)
In-Reply-To: <20201029222738.482366-7-pmalani@chromium.org>

On Thu, Oct 29, 2020 at 03:27:40PM -0700, Prashant Malani wrote:
> Use EC_CMD_TYPE_DISCOVERY to retrieve and store the discovery data for
> the port partner. With that data, update the PD Identity VDO values for
> the partner, which were earlier not initialized.
> 
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Signed-off-by: Prashant Malani <pmalani@chromium.org>

FWIW:

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

> ---
> 
> Changes in v2:
> - No changes
> 
>  drivers/platform/chrome/cros_ec_typec.c | 60 ++++++++++++++++++++++++-
>  1 file changed, 59 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index f578d0bfbe5a..f14550dac614 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -14,6 +14,7 @@
>  #include <linux/platform_data/cros_usbpd_notify.h>
>  #include <linux/platform_device.h>
>  #include <linux/usb/pd.h>
> +#include <linux/usb/pd_vdo.h>
>  #include <linux/usb/typec.h>
>  #include <linux/usb/typec_altmode.h>
>  #include <linux/usb/typec_dp.h>
> @@ -51,6 +52,7 @@ struct cros_typec_port {
>  
>  	/* Flag indicating that PD discovery data parsing is completed. */
>  	bool disc_done;
> +	struct ec_response_typec_discovery *sop_disc;
>  };
>  
>  /* Platform-specific data for the Chrome OS EC Type C controller. */
> @@ -298,6 +300,12 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
>  				port_num);
>  
>  		cros_typec_register_port_altmodes(typec, port_num);
> +
> +		cros_port->sop_disc = devm_kzalloc(dev, EC_PROTO2_MAX_RESPONSE_SIZE, GFP_KERNEL);
> +		if (!cros_port->sop_disc) {
> +			ret = -ENOMEM;
> +			goto unregister_ports;
> +		}
>  	}
>  
>  	return 0;
> @@ -582,6 +590,51 @@ static int cros_typec_get_mux_info(struct cros_typec_data *typec, int port_num,
>  				     sizeof(req), resp, sizeof(*resp));
>  }
>  
> +static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num)
> +{
> +	struct cros_typec_port *port = typec->ports[port_num];
> +	struct ec_response_typec_discovery *sop_disc = port->sop_disc;
> +	struct ec_params_typec_discovery req = {
> +		.port = port_num,
> +		.partner_type = TYPEC_PARTNER_SOP,
> +	};
> +	int ret = 0;
> +	int i;
> +
> +	if (!port->partner) {
> +		dev_err(typec->dev,
> +			"SOP Discovery received without partner registered, port: %d\n",
> +			port_num);
> +		ret = -EINVAL;
> +		goto disc_exit;
> +	}
> +
> +	memset(sop_disc, 0, EC_PROTO2_MAX_RESPONSE_SIZE);
> +	ret = cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req),
> +				    sop_disc, EC_PROTO2_MAX_RESPONSE_SIZE);
> +	if (ret < 0) {
> +		dev_err(typec->dev, "Failed to get SOP discovery data for port: %d\n", port_num);
> +		goto disc_exit;
> +	}
> +
> +	/* First, update the PD identity VDOs for the partner. */
> +	if (sop_disc->identity_count > 0)
> +		port->p_identity.id_header = sop_disc->discovery_vdo[0];
> +	if (sop_disc->identity_count > 1)
> +		port->p_identity.cert_stat = sop_disc->discovery_vdo[1];
> +	if (sop_disc->identity_count > 2)
> +		port->p_identity.product = sop_disc->discovery_vdo[2];
> +
> +	/* Copy the remaining identity VDOs till a maximum of 6. */
> +	for (i = 3; i < sop_disc->identity_count && i < VDO_MAX_OBJECTS; i++)
> +		port->p_identity.vdo[i - 3] = sop_disc->discovery_vdo[i];
> +
> +	ret = typec_partner_set_identity(port->partner);
> +
> +disc_exit:
> +	return ret;
> +}
> +
>  static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num)
>  {
>  	struct ec_response_typec_status resp;
> @@ -602,7 +655,12 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
>  
>  	/* Handle any events appropriately. */
>  	if (resp.events & PD_STATUS_EVENT_SOP_DISC_DONE) {
> -		dev_dbg(typec->dev, "SOP Discovery done for port: %d\n", port_num);
> +		ret = cros_typec_handle_sop_disc(typec, port_num);
> +		if (ret < 0) {
> +			dev_err(typec->dev, "Couldn't parse SOP Disc data, port: %d\n", port_num);
> +			return;
> +		}
> +
>  		typec->ports[port_num]->disc_done = true;
>  	}
>  }

thanks,

-- 
heikki

  reply	other threads:[~2020-10-30 13:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-29 22:27 [PATCH v2 0/7] platform/chrome: cros_ec_typec: Register partner PD information Prashant Malani
2020-10-29 22:27 ` [PATCH v2 1/7] platform/chrome: cros_ec_typec: Relocate set_port_params_v*() functions Prashant Malani
2020-10-29 22:27 ` [PATCH v2 2/7] platform/chrome: cros_ec_typec: Fix remove partner logic Prashant Malani
2020-10-29 22:27 ` [PATCH v2 3/7] platform/chrome: cros_ec_typec: Clear partner identity on device removal Prashant Malani
2020-10-29 22:27 ` [PATCH v2 4/7] platform/chrome: cros_ec: Import Type C host commands Prashant Malani
2020-10-29 22:27 ` [PATCH v2 5/7] platform/chrome: cros_ec_typec: Introduce TYPEC_STATUS Prashant Malani
2020-10-29 22:27 ` [PATCH v2 6/7] platform/chrome: cros_ec_typec: Parse partner PD ID VDOs Prashant Malani
2020-10-30 13:31   ` Heikki Krogerus [this message]
2020-10-29 22:27 ` [PATCH v2 7/7] platform/chrome: cros_ec_typec: Register partner altmodes Prashant Malani
2020-10-30 13:32   ` Heikki Krogerus
2020-11-13  8:58 ` [PATCH v2 0/7] platform/chrome: cros_ec_typec: Register partner PD information Enric Balletbo i Serra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201030133114.GE2333887@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=alevkoy@chromium.org \
    --cc=bleung@chromium.org \
    --cc=dzigterman@chromium.org \
    --cc=enric.balletbo@collabora.com \
    --cc=groeck@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmalani@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®