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 7/7] platform/chrome: cros_ec_typec: Register partner altmodes
Date: Fri, 30 Oct 2020 15:32:08 +0200	[thread overview]
Message-ID: <20201030133208.GF2333887@kuha.fi.intel.com> (raw)
In-Reply-To: <20201029222738.482366-8-pmalani@chromium.org>

On Thu, Oct 29, 2020 at 03:27:42PM -0700, Prashant Malani wrote:
> Use the discovery data from the Chrome EC to register parter altmodes
> with the Type C Connector Class framework. Also introduce a node
> struct to keep track of the list of registered alt modes.
> 
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Signed-off-by: Prashant Malani <pmalani@chromium.org>

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

> ---
> 
> Changes in v2:
> - Changed list traversal during alt mode unregistering to use
>   list_for_each_entry_safe() base on review comment.
> 
>  drivers/platform/chrome/cros_ec_typec.c | 77 +++++++++++++++++++++++++
>  1 file changed, 77 insertions(+)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index f14550dac614..ce031a10eb1b 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -7,6 +7,7 @@
>   */
>  
>  #include <linux/acpi.h>
> +#include <linux/list.h>
>  #include <linux/module.h>
>  #include <linux/of.h>
>  #include <linux/platform_data/cros_ec_commands.h>
> @@ -31,6 +32,12 @@ enum {
>  	CROS_EC_ALTMODE_MAX,
>  };
>  
> +/* Container for altmode pointer nodes. */
> +struct cros_typec_altmode_node {
> +	struct typec_altmode *amode;
> +	struct list_head list;
> +};
> +
>  /* Per port data. */
>  struct cros_typec_port {
>  	struct typec_port *port;
> @@ -53,6 +60,7 @@ struct cros_typec_port {
>  	/* Flag indicating that PD discovery data parsing is completed. */
>  	bool disc_done;
>  	struct ec_response_typec_discovery *sop_disc;
> +	struct list_head partner_mode_list;
>  };
>  
>  /* Platform-specific data for the Chrome OS EC Type C controller. */
> @@ -172,11 +180,25 @@ static int cros_typec_add_partner(struct cros_typec_data *typec, int port_num,
>  	return ret;
>  }
>  
> +static void cros_typec_unregister_altmodes(struct cros_typec_data *typec, int port_num)
> +{
> +	struct cros_typec_port *port = typec->ports[port_num];
> +	struct cros_typec_altmode_node *node, *tmp;
> +
> +	list_for_each_entry_safe(node, tmp, &port->partner_mode_list, list) {
> +		list_del(&node->list);
> +		typec_unregister_altmode(node->amode);
> +		devm_kfree(typec->dev, node);
> +	}
> +}
> +
>  static void cros_typec_remove_partner(struct cros_typec_data *typec,
>  				     int port_num)
>  {
>  	struct cros_typec_port *port = typec->ports[port_num];
>  
> +	cros_typec_unregister_altmodes(typec, port_num);
> +
>  	port->state.alt = NULL;
>  	port->state.mode = TYPEC_STATE_USB;
>  	port->state.data = NULL;
> @@ -306,6 +328,8 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
>  			ret = -ENOMEM;
>  			goto unregister_ports;
>  		}
> +
> +		INIT_LIST_HEAD(&cros_port->partner_mode_list);
>  	}
>  
>  	return 0;
> @@ -590,6 +614,49 @@ static int cros_typec_get_mux_info(struct cros_typec_data *typec, int port_num,
>  				     sizeof(req), resp, sizeof(*resp));
>  }
>  
> +static int cros_typec_register_altmodes(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 cros_typec_altmode_node *node;
> +	struct typec_altmode_desc desc;
> +	struct typec_altmode *amode;
> +	int ret = 0;
> +	int i, j;
> +
> +	for (i = 0; i < sop_disc->svid_count; i++) {
> +		for (j = 0; j < sop_disc->svids[i].mode_count; j++) {
> +			memset(&desc, 0, sizeof(desc));
> +			desc.svid = sop_disc->svids[i].svid;
> +			desc.mode = j;
> +			desc.vdo = sop_disc->svids[i].mode_vdo[j];
> +
> +			amode = typec_partner_register_altmode(port->partner, &desc);
> +			if (IS_ERR(amode)) {
> +				ret = PTR_ERR(amode);
> +				goto err_cleanup;
> +			}
> +
> +			/* If no memory is available we should unregister and exit. */
> +			node = devm_kzalloc(typec->dev, sizeof(*node), GFP_KERNEL);
> +			if (!node) {
> +				ret = -ENOMEM;
> +				typec_unregister_altmode(amode);
> +				goto err_cleanup;
> +			}
> +
> +			node->amode = amode;
> +			list_add_tail(&node->list, &port->partner_mode_list);
> +		}
> +	}
> +
> +	return 0;
> +
> +err_cleanup:
> +	cros_typec_unregister_altmodes(typec, port_num);
> +	return ret;
> +}
> +
>  static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num)
>  {
>  	struct cros_typec_port *port = typec->ports[port_num];
> @@ -630,6 +697,16 @@ static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_nu
>  		port->p_identity.vdo[i - 3] = sop_disc->discovery_vdo[i];
>  
>  	ret = typec_partner_set_identity(port->partner);
> +	if (ret < 0) {
> +		dev_err(typec->dev, "Failed to update partner PD identity, port: %d\n", port_num);
> +		goto disc_exit;
> +	}
> +
> +	ret = cros_typec_register_altmodes(typec, port_num);
> +	if (ret < 0) {
> +		dev_err(typec->dev, "Failed to register partner altmodes, port: %d\n", port_num);
> +		goto disc_exit;
> +	}
>  
>  disc_exit:
>  	return ret;
> -- 
> 2.29.1.341.ge80a0c044ae-goog

thanks,

-- 
heikki

  reply	other threads:[~2020-10-30 13:32 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
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 [this message]
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=20201030133208.GF2333887@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®