public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Prashant Malani <pmalani@chromium.org>
To: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: linux-kernel@vger.kernel.org,
	Azhar Shaikh <azhar.shaikh@intel.com>,
	Casey Bowman <casey.g.bowman@intel.com>,
	Benson Leung <bleung@chromium.org>,
	Enric Balletbo i Serra <enric.balletbo@collabora.com>,
	Guenter Roeck <groeck@chromium.org>,
	Lee Jones <lee.jones@linaro.org>, Mark Brown <broonie@kernel.org>,
	Tzung-Bi Shih <tzungbi@google.com>,
	Yicheng Li <yichengli@chromium.org>
Subject: Re: [PATCH 2/2] platform/chrome: cros_ec_typec: Add TBT compat support
Date: Wed, 24 Jun 2020 10:42:04 -0700	[thread overview]
Message-ID: <20200624174204.GB151731@google.com> (raw)
In-Reply-To: <20200624092040.GB1487@kuha.fi.intel.com>

Hi Heikki,

On Wed, Jun 24, 2020 at 12:20:40PM +0300, Heikki Krogerus wrote:
> On Wed, Jun 24, 2020 at 12:15:20PM +0300, Heikki Krogerus wrote:
> > On Wed, Jun 24, 2020 at 01:09:24AM -0700, Prashant Malani wrote:
> > > Add mux control support for Thunderbolt compatibility mode.
> > > 
> > > Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > > Co-developed-by: Azhar Shaikh <azhar.shaikh@intel.com>
> > > Co-developed-by: Casey Bowman <casey.g.bowman@intel.com>
> > > Signed-off-by: Prashant Malani <pmalani@chromium.org>
> > > ---
> > >  drivers/platform/chrome/cros_ec_typec.c | 70 ++++++++++++++++++++++++-
> > >  1 file changed, 69 insertions(+), 1 deletion(-)
> > 
> > Cool! Can you guys test also USB4 with the attached patch (still work
> > in progress)? It should apply on top of these.
> > 
> > The mux driver is still missing USB4 support, but I'll send the
> > patches needed for that right now...
> 
> Actually, I'll just attach that one here as well. Let me know if you
> guys can test these.

Thanks for the patches. Will try them out today and compare the PMC IPC
buffers against what extcon is doing.

Best regards,

-Prashant
> 
> thanks,
> 
> -- 
> heikki

> From 396bd399ac815165ec4992739d45d52ecf234acc Mon Sep 17 00:00:00 2001
> From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Date: Wed, 3 Jun 2020 17:00:14 +0300
> Subject: [PATCH] usb: typec: intel_pmc_mux: Add support for USB4
> 
> The PMC mux-agent can be used also when Enter_USB is used in
> order to enter USB4 mode. The mux-agent does not have USB4
> specific message, but instead needs to be put into TBT
> alternate mode also with USB4. That is OK as the controller
> is in any case the same with TBT3 and USB4.
> 
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
>  drivers/usb/typec/mux/intel_pmc_mux.c | 65 +++++++++++++++++++++++----
>  1 file changed, 56 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/intel_pmc_mux.c
> index 70ddc9d6d49e4..6d223bd360b8e 100644
> --- a/drivers/usb/typec/mux/intel_pmc_mux.c
> +++ b/drivers/usb/typec/mux/intel_pmc_mux.c
> @@ -10,6 +10,7 @@
>  #include <linux/module.h>
>  #include <linux/platform_device.h>
>  #include <linux/property.h>
> +#include <linux/usb/pd.h>
>  #include <linux/usb/role.h>
>  #include <linux/usb/typec_mux.h>
>  #include <linux/usb/typec_dp.h>
> @@ -227,6 +228,41 @@ pmc_usb_mux_tbt(struct pmc_usb_port *port, struct typec_mux_state *state)
>  	return pmc_usb_command(port, (void *)&req, sizeof(req));
>  }
>  
> +static int
> +pmc_usb_mux_usb4(struct pmc_usb_port *port, struct typec_mux_state *state)
> +{
> +	u32 eudo = *(u32 *)state->data;
> +	struct altmode_req req = { };
> +	u8 cable_speed;
> +
> +	req.usage = PMC_USB_ALT_MODE;
> +	req.usage |= port->usb3_port << PMC_USB_MSG_USB3_PORT_SHIFT;
> +	req.mode_type = PMC_USB_MODE_TYPE_TBT << PMC_USB_MODE_TYPE_SHIFT;
> +
> +	/* USB4 Mode */
> +	req.mode_data = PMC_USB_ALTMODE_FORCE_LSR;
> +	req.mode_data |= PMC_USB_ALTMODE_ACTIVE_LINK;
> +
> +	req.mode_data |= (port->orientation - 1) << PMC_USB_ALTMODE_ORI_SHIFT;
> +	req.mode_data |= (port->role - 1) << PMC_USB_ALTMODE_UFP_SHIFT;
> +
> +	switch ((eudo & EUDO_CABLE_TYPE_MASK) >> EUDO_CABLE_TYPE_SHIFT) {
> +	case EUDO_CABLE_TYPE_PASSIVE:
> +		break;
> +	case EUDO_CABLE_TYPE_OPTICAL:
> +		req.mode_data |= PMC_USB_ALTMODE_CABLE_TYPE;
> +		/* fall through */
> +	default:
> +		req.mode_data |= PMC_USB_ALTMODE_ACTIVE_CABLE;
> +		break;
> +	}
> +
> +	cable_speed = (eudo & EUDO_CABLE_SPEED_MASK) >> EUDO_CABLE_SPEED_SHIFT;
> +	req.mode_data |= PMC_USB_ALTMODE_CABLE_SPD(cable_speed);
> +
> +	return pmc_usb_command(port, (void *)&req, sizeof(req));
> +}
> +
>  static int pmc_usb_mux_safe_state(struct pmc_usb_port *port)
>  {
>  	u8 msg;
> @@ -268,17 +304,28 @@ pmc_usb_mux_set(struct typec_mux *mux, struct typec_mux_state *state)
>  {
>  	struct pmc_usb_port *port = typec_mux_get_drvdata(mux);
>  
> -	if (!state->alt)
> -		return 0;
> -
>  	if (state->mode == TYPEC_STATE_SAFE)
>  		return pmc_usb_mux_safe_state(port);
> -
> -	switch (state->alt->svid) {
> -	case USB_TYPEC_TBT_SID:
> -		return pmc_usb_mux_tbt(port, state);
> -	case USB_TYPEC_DP_SID:
> -		return pmc_usb_mux_dp(port, state);
> +	if (state->mode == TYPEC_STATE_USB)
> +		return pmc_usb_connect(port);
> +
> +	if (state->alt) {
> +		switch (state->alt->svid) {
> +		case USB_TYPEC_TBT_SID:
> +			return pmc_usb_mux_tbt(port, state);
> +		case USB_TYPEC_DP_SID:
> +			return pmc_usb_mux_dp(port, state);
> +		}
> +	} else {
> +		switch (state->mode) {
> +		case TYPEC_MODE_USB2:
> +			/* REVISIT: Try with usb3_port set to 0? */
> +			break;
> +		case TYPEC_MODE_USB3:
> +			return pmc_usb_connect(port);
> +		case TYPEC_MODE_USB4:
> +			return pmc_usb_mux_usb4(port, state);
> +		}
>  	}
>  
>  	return -EOPNOTSUPP;
> -- 
> 2.27.0
> 


  reply	other threads:[~2020-06-24 17:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-24  8:09 [PATCH 1/2] platform/chrome: cros_ec_typec: Add TBT pd_ctrl fields Prashant Malani
2020-06-24  8:09 ` [PATCH 2/2] platform/chrome: cros_ec_typec: Add TBT compat support Prashant Malani
2020-06-24  9:15   ` Heikki Krogerus
2020-06-24  9:20     ` Heikki Krogerus
2020-06-24 17:42       ` Prashant Malani [this message]
2020-06-25  7:45   ` Heikki Krogerus
2020-06-26  9:10 ` [PATCH 1/2] platform/chrome: cros_ec_typec: Add TBT pd_ctrl fields Enric Balletbo i Serra
2020-06-26 19:04   ` Prashant Malani

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=20200624174204.GB151731@google.com \
    --to=pmalani@chromium.org \
    --cc=azhar.shaikh@intel.com \
    --cc=bleung@chromium.org \
    --cc=broonie@kernel.org \
    --cc=casey.g.bowman@intel.com \
    --cc=enric.balletbo@collabora.com \
    --cc=groeck@chromium.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tzungbi@google.com \
    --cc=yichengli@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