linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] platform/chrome: cros_ec_typec: USB4 support
@ 2020-07-10 19:40 Prashant Malani
  2020-07-21 19:55 ` Prashant Malani
  2020-09-01  9:08 ` Enric Balletbo i Serra
  0 siblings, 2 replies; 5+ messages in thread
From: Prashant Malani @ 2020-07-10 19:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: rajmohan.mani, Heikki Krogerus, Prashant Malani, Benson Leung,
	Enric Balletbo i Serra, Guenter Roeck

From: Heikki Krogerus <heikki.krogerus@linux.intel.com>

With USB4 mode the mux driver needs the Enter_USB Data
Object (EUDO) that was used when the USB mode was entered.
Though the object is not available in the driver, it is
possible to construct it from the information we have.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
---

This patch depends on latest usb-next from Greg KH, this commit in
particular:
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git/commit/?h=usb-next&id=ad8db94d6813dc659bd4de0531a8a1150559eafb

Changes in v2:
- Removed EUDO bits for cable current and tunneling support.

 drivers/platform/chrome/cros_ec_typec.c | 33 ++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 0c041b79cbba..a9700275a851 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -13,6 +13,7 @@
 #include <linux/platform_data/cros_ec_proto.h>
 #include <linux/platform_data/cros_usbpd_notify.h>
 #include <linux/platform_device.h>
+#include <linux/usb/pd.h>
 #include <linux/usb/typec.h>
 #include <linux/usb/typec_altmode.h>
 #include <linux/usb/typec_dp.h>
@@ -494,6 +495,34 @@ static int cros_typec_enable_dp(struct cros_typec_data *typec,
 	return typec_mux_set(port->mux, &port->state);
 }
 
+static int cros_typec_enable_usb4(struct cros_typec_data *typec,
+				  int port_num,
+				  struct ec_response_usb_pd_control_v2 *pd_ctrl)
+{
+	struct cros_typec_port *port = typec->ports[port_num];
+	struct enter_usb_data data;
+
+	data.eudo = EUDO_USB_MODE_USB4 << EUDO_USB_MODE_SHIFT;
+
+	/* Cable Speed */
+	data.eudo |= pd_ctrl->cable_speed << EUDO_CABLE_SPEED_SHIFT;
+
+	/* Cable Type */
+	if (pd_ctrl->control_flags & USB_PD_CTRL_OPTICAL_CABLE)
+		data.eudo |= EUDO_CABLE_TYPE_OPTICAL << EUDO_CABLE_TYPE_SHIFT;
+	else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE)
+		data.eudo |= EUDO_CABLE_TYPE_RE_TIMER << EUDO_CABLE_TYPE_SHIFT;
+
+	data.active_link_training = !!(pd_ctrl->control_flags &
+				       USB_PD_CTRL_ACTIVE_LINK_UNIDIR);
+
+	port->state.alt = NULL;
+	port->state.data = &data;
+	port->state.mode = TYPEC_MODE_USB4;
+
+	return typec_mux_set(port->mux, &port->state);
+}
+
 static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
 				uint8_t mux_flags,
 				struct ec_response_usb_pd_control_v2 *pd_ctrl)
@@ -514,7 +543,9 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
 	if (ret)
 		return ret;
 
-	if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
+	if (mux_flags & USB_PD_MUX_USB4_ENABLED) {
+		ret = cros_typec_enable_usb4(typec, port_num, pd_ctrl);
+	} else if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
 		ret = cros_typec_enable_tbt(typec, port_num, pd_ctrl);
 	} else if (mux_flags & USB_PD_MUX_DP_ENABLED) {
 		ret = cros_typec_enable_dp(typec, port_num, pd_ctrl);
-- 
2.27.0.383.g050319c2ae-goog


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

* Re: [PATCH v2] platform/chrome: cros_ec_typec: USB4 support
  2020-07-10 19:40 [PATCH v2] platform/chrome: cros_ec_typec: USB4 support Prashant Malani
@ 2020-07-21 19:55 ` Prashant Malani
  2020-07-22 15:27   ` Enric Balletbo i Serra
  2020-09-01  9:08 ` Enric Balletbo i Serra
  1 sibling, 1 reply; 5+ messages in thread
From: Prashant Malani @ 2020-07-21 19:55 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: Rajmohan Mani, Heikki Krogerus, Benson Leung,
	Enric Balletbo i Serra, Guenter Roeck

Hey Enric, Benson,

Just wondering if you've had a chance to review this patch.

Best regards,

-Prashant

On Fri, Jul 10, 2020 at 12:40 PM Prashant Malani <pmalani@chromium.org> wrote:
>
> From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>
> With USB4 mode the mux driver needs the Enter_USB Data
> Object (EUDO) that was used when the USB mode was entered.
> Though the object is not available in the driver, it is
> possible to construct it from the information we have.
>
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Signed-off-by: Prashant Malani <pmalani@chromium.org>
> ---
>
> This patch depends on latest usb-next from Greg KH, this commit in
> particular:
> https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git/commit/?h=usb-next&id=ad8db94d6813dc659bd4de0531a8a1150559eafb
>
> Changes in v2:
> - Removed EUDO bits for cable current and tunneling support.
>
>  drivers/platform/chrome/cros_ec_typec.c | 33 ++++++++++++++++++++++++-
>  1 file changed, 32 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 0c041b79cbba..a9700275a851 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -13,6 +13,7 @@
>  #include <linux/platform_data/cros_ec_proto.h>
>  #include <linux/platform_data/cros_usbpd_notify.h>
>  #include <linux/platform_device.h>
> +#include <linux/usb/pd.h>
>  #include <linux/usb/typec.h>
>  #include <linux/usb/typec_altmode.h>
>  #include <linux/usb/typec_dp.h>
> @@ -494,6 +495,34 @@ static int cros_typec_enable_dp(struct cros_typec_data *typec,
>         return typec_mux_set(port->mux, &port->state);
>  }
>
> +static int cros_typec_enable_usb4(struct cros_typec_data *typec,
> +                                 int port_num,
> +                                 struct ec_response_usb_pd_control_v2 *pd_ctrl)
> +{
> +       struct cros_typec_port *port = typec->ports[port_num];
> +       struct enter_usb_data data;
> +
> +       data.eudo = EUDO_USB_MODE_USB4 << EUDO_USB_MODE_SHIFT;
> +
> +       /* Cable Speed */
> +       data.eudo |= pd_ctrl->cable_speed << EUDO_CABLE_SPEED_SHIFT;
> +
> +       /* Cable Type */
> +       if (pd_ctrl->control_flags & USB_PD_CTRL_OPTICAL_CABLE)
> +               data.eudo |= EUDO_CABLE_TYPE_OPTICAL << EUDO_CABLE_TYPE_SHIFT;
> +       else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE)
> +               data.eudo |= EUDO_CABLE_TYPE_RE_TIMER << EUDO_CABLE_TYPE_SHIFT;
> +
> +       data.active_link_training = !!(pd_ctrl->control_flags &
> +                                      USB_PD_CTRL_ACTIVE_LINK_UNIDIR);
> +
> +       port->state.alt = NULL;
> +       port->state.data = &data;
> +       port->state.mode = TYPEC_MODE_USB4;
> +
> +       return typec_mux_set(port->mux, &port->state);
> +}
> +
>  static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
>                                 uint8_t mux_flags,
>                                 struct ec_response_usb_pd_control_v2 *pd_ctrl)
> @@ -514,7 +543,9 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
>         if (ret)
>                 return ret;
>
> -       if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
> +       if (mux_flags & USB_PD_MUX_USB4_ENABLED) {
> +               ret = cros_typec_enable_usb4(typec, port_num, pd_ctrl);
> +       } else if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
>                 ret = cros_typec_enable_tbt(typec, port_num, pd_ctrl);
>         } else if (mux_flags & USB_PD_MUX_DP_ENABLED) {
>                 ret = cros_typec_enable_dp(typec, port_num, pd_ctrl);
> --
> 2.27.0.383.g050319c2ae-goog
>

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

* Re: [PATCH v2] platform/chrome: cros_ec_typec: USB4 support
  2020-07-21 19:55 ` Prashant Malani
@ 2020-07-22 15:27   ` Enric Balletbo i Serra
  2020-07-24  0:47     ` Prashant Malani
  0 siblings, 1 reply; 5+ messages in thread
From: Enric Balletbo i Serra @ 2020-07-22 15:27 UTC (permalink / raw)
  To: Prashant Malani, Linux Kernel Mailing List
  Cc: Rajmohan Mani, Heikki Krogerus, Benson Leung, Guenter Roeck

Hi Prashant,

On 21/7/20 21:55, Prashant Malani wrote:
> Hey Enric, Benson,
> 
> Just wondering if you've had a chance to review this patch.
> 

It's on my radar but I'm waiting for the dependencies to be merged.


> Best regards,
> 
> -Prashant
> 
> On Fri, Jul 10, 2020 at 12:40 PM Prashant Malani <pmalani@chromium.org> wrote:
>>
>> From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>>
>> With USB4 mode the mux driver needs the Enter_USB Data
>> Object (EUDO) that was used when the USB mode was entered.
>> Though the object is not available in the driver, it is
>> possible to construct it from the information we have.
>>
>> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>> Signed-off-by: Prashant Malani <pmalani@chromium.org>

For my own reference:

Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>

>> ---
>>
>> This patch depends on latest usb-next from Greg KH, this commit in
>> particular:
>> https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git/commit/?h=usb-next&id=ad8db94d6813dc659bd4de0531a8a1150559eafb
>>
>> Changes in v2:
>> - Removed EUDO bits for cable current and tunneling support.
>>
>>  drivers/platform/chrome/cros_ec_typec.c | 33 ++++++++++++++++++++++++-
>>  1 file changed, 32 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
>> index 0c041b79cbba..a9700275a851 100644
>> --- a/drivers/platform/chrome/cros_ec_typec.c
>> +++ b/drivers/platform/chrome/cros_ec_typec.c
>> @@ -13,6 +13,7 @@
>>  #include <linux/platform_data/cros_ec_proto.h>
>>  #include <linux/platform_data/cros_usbpd_notify.h>
>>  #include <linux/platform_device.h>
>> +#include <linux/usb/pd.h>
>>  #include <linux/usb/typec.h>
>>  #include <linux/usb/typec_altmode.h>
>>  #include <linux/usb/typec_dp.h>
>> @@ -494,6 +495,34 @@ static int cros_typec_enable_dp(struct cros_typec_data *typec,
>>         return typec_mux_set(port->mux, &port->state);
>>  }
>>
>> +static int cros_typec_enable_usb4(struct cros_typec_data *typec,
>> +                                 int port_num,
>> +                                 struct ec_response_usb_pd_control_v2 *pd_ctrl)
>> +{
>> +       struct cros_typec_port *port = typec->ports[port_num];
>> +       struct enter_usb_data data;
>> +
>> +       data.eudo = EUDO_USB_MODE_USB4 << EUDO_USB_MODE_SHIFT;
>> +
>> +       /* Cable Speed */
>> +       data.eudo |= pd_ctrl->cable_speed << EUDO_CABLE_SPEED_SHIFT;
>> +
>> +       /* Cable Type */
>> +       if (pd_ctrl->control_flags & USB_PD_CTRL_OPTICAL_CABLE)
>> +               data.eudo |= EUDO_CABLE_TYPE_OPTICAL << EUDO_CABLE_TYPE_SHIFT;
>> +       else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE)
>> +               data.eudo |= EUDO_CABLE_TYPE_RE_TIMER << EUDO_CABLE_TYPE_SHIFT;
>> +
>> +       data.active_link_training = !!(pd_ctrl->control_flags &
>> +                                      USB_PD_CTRL_ACTIVE_LINK_UNIDIR);
>> +
>> +       port->state.alt = NULL;
>> +       port->state.data = &data;
>> +       port->state.mode = TYPEC_MODE_USB4;
>> +
>> +       return typec_mux_set(port->mux, &port->state);
>> +}
>> +
>>  static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
>>                                 uint8_t mux_flags,
>>                                 struct ec_response_usb_pd_control_v2 *pd_ctrl)
>> @@ -514,7 +543,9 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
>>         if (ret)
>>                 return ret;
>>
>> -       if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
>> +       if (mux_flags & USB_PD_MUX_USB4_ENABLED) {
>> +               ret = cros_typec_enable_usb4(typec, port_num, pd_ctrl);
>> +       } else if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
>>                 ret = cros_typec_enable_tbt(typec, port_num, pd_ctrl);
>>         } else if (mux_flags & USB_PD_MUX_DP_ENABLED) {
>>                 ret = cros_typec_enable_dp(typec, port_num, pd_ctrl);
>> --
>> 2.27.0.383.g050319c2ae-goog
>>

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

* Re: [PATCH v2] platform/chrome: cros_ec_typec: USB4 support
  2020-07-22 15:27   ` Enric Balletbo i Serra
@ 2020-07-24  0:47     ` Prashant Malani
  0 siblings, 0 replies; 5+ messages in thread
From: Prashant Malani @ 2020-07-24  0:47 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Linux Kernel Mailing List, Rajmohan Mani, Heikki Krogerus,
	Benson Leung, Guenter Roeck

On Wed, Jul 22, 2020 at 8:27 AM Enric Balletbo i Serra
<enric.balletbo@collabora.com> wrote:
>
> Hi Prashant,
>
> On 21/7/20 21:55, Prashant Malani wrote:
> > Hey Enric, Benson,
> >
> > Just wondering if you've had a chance to review this patch.
> >
>
> It's on my radar but I'm waiting for the dependencies to be merged.
>
Understood. Thanks!

BR,

-Prashant

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

* Re: [PATCH v2] platform/chrome: cros_ec_typec: USB4 support
  2020-07-10 19:40 [PATCH v2] platform/chrome: cros_ec_typec: USB4 support Prashant Malani
  2020-07-21 19:55 ` Prashant Malani
@ 2020-09-01  9:08 ` Enric Balletbo i Serra
  1 sibling, 0 replies; 5+ messages in thread
From: Enric Balletbo i Serra @ 2020-09-01  9:08 UTC (permalink / raw)
  To: Prashant Malani, linux-kernel
  Cc: rajmohan.mani, Heikki Krogerus, Benson Leung, Guenter Roeck

Hi Prashant and Heikki,

On 10/7/20 21:40, Prashant Malani wrote:
> From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> 
> With USB4 mode the mux driver needs the Enter_USB Data
> Object (EUDO) that was used when the USB mode was entered.
> Though the object is not available in the driver, it is
> possible to construct it from the information we have.
> 
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Signed-off-by: Prashant Malani <pmalani@chromium.org>
> ---
> 

Applied for 5.10.

Thanks,
 Enric

> This patch depends on latest usb-next from Greg KH, this commit in
> particular:
> https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git/commit/?h=usb-next&id=ad8db94d6813dc659bd4de0531a8a1150559eafb
> 
> Changes in v2:
> - Removed EUDO bits for cable current and tunneling support.
> 
>  drivers/platform/chrome/cros_ec_typec.c | 33 ++++++++++++++++++++++++-
>  1 file changed, 32 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 0c041b79cbba..a9700275a851 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -13,6 +13,7 @@
>  #include <linux/platform_data/cros_ec_proto.h>
>  #include <linux/platform_data/cros_usbpd_notify.h>
>  #include <linux/platform_device.h>
> +#include <linux/usb/pd.h>
>  #include <linux/usb/typec.h>
>  #include <linux/usb/typec_altmode.h>
>  #include <linux/usb/typec_dp.h>
> @@ -494,6 +495,34 @@ static int cros_typec_enable_dp(struct cros_typec_data *typec,
>  	return typec_mux_set(port->mux, &port->state);
>  }
>  
> +static int cros_typec_enable_usb4(struct cros_typec_data *typec,
> +				  int port_num,
> +				  struct ec_response_usb_pd_control_v2 *pd_ctrl)
> +{
> +	struct cros_typec_port *port = typec->ports[port_num];
> +	struct enter_usb_data data;
> +
> +	data.eudo = EUDO_USB_MODE_USB4 << EUDO_USB_MODE_SHIFT;
> +
> +	/* Cable Speed */
> +	data.eudo |= pd_ctrl->cable_speed << EUDO_CABLE_SPEED_SHIFT;
> +
> +	/* Cable Type */
> +	if (pd_ctrl->control_flags & USB_PD_CTRL_OPTICAL_CABLE)
> +		data.eudo |= EUDO_CABLE_TYPE_OPTICAL << EUDO_CABLE_TYPE_SHIFT;
> +	else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE)
> +		data.eudo |= EUDO_CABLE_TYPE_RE_TIMER << EUDO_CABLE_TYPE_SHIFT;
> +
> +	data.active_link_training = !!(pd_ctrl->control_flags &
> +				       USB_PD_CTRL_ACTIVE_LINK_UNIDIR);
> +
> +	port->state.alt = NULL;
> +	port->state.data = &data;
> +	port->state.mode = TYPEC_MODE_USB4;
> +
> +	return typec_mux_set(port->mux, &port->state);
> +}
> +
>  static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
>  				uint8_t mux_flags,
>  				struct ec_response_usb_pd_control_v2 *pd_ctrl)
> @@ -514,7 +543,9 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
>  	if (ret)
>  		return ret;
>  
> -	if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
> +	if (mux_flags & USB_PD_MUX_USB4_ENABLED) {
> +		ret = cros_typec_enable_usb4(typec, port_num, pd_ctrl);
> +	} else if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
>  		ret = cros_typec_enable_tbt(typec, port_num, pd_ctrl);
>  	} else if (mux_flags & USB_PD_MUX_DP_ENABLED) {
>  		ret = cros_typec_enable_dp(typec, port_num, pd_ctrl);
> 

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

end of thread, other threads:[~2020-09-01  9:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-10 19:40 [PATCH v2] platform/chrome: cros_ec_typec: USB4 support Prashant Malani
2020-07-21 19:55 ` Prashant Malani
2020-07-22 15:27   ` Enric Balletbo i Serra
2020-07-24  0:47     ` Prashant Malani
2020-09-01  9:08 ` Enric Balletbo i Serra

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