* [PATCH] usb: typec: Add typec_enter_usb() helper function
@ 2020-11-09 12:05 Heikki Krogerus
2020-11-09 12:21 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Heikki Krogerus @ 2020-11-09 12:05 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb
This function configures the muxes according to the
requested USB mode in the Enter_USB Message that was
communicated with the partner.
In practice the function just fills struct typec_mux_state
for the caller by extracting the connector mode (so USB
mode) from the EUDO (Enter_USB Data Object), and then passes
that structure to typec_mux_set().
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
drivers/usb/typec/class.c | 32 ++++++++++++++++++++++++++++++++
include/linux/usb/typec.h | 1 +
2 files changed, 33 insertions(+)
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 35eec707cb512..22f82e924d585 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -11,6 +11,7 @@
#include <linux/mutex.h>
#include <linux/property.h>
#include <linux/slab.h>
+#include <linux/usb/pd.h>
#include "bus.h"
@@ -1579,6 +1580,37 @@ int typec_set_mode(struct typec_port *port, int mode)
}
EXPORT_SYMBOL_GPL(typec_set_mode);
+/**
+ * typec_enter_usb - Set USB Mode for USB Type-C connector
+ * @port: USB Type-C connector
+ * @data: Enter_USB Message details.
+ *
+ * This function is called when Enter_USB Message is used. It configures @port
+ * muxes for the USB mode (USB 2.0, USB 3.2 or USB4).
+ */
+int typec_enter_usb(struct typec_port *port, struct enter_usb_data *data)
+{
+ struct typec_mux_state mux_state;
+
+ switch ((data->eudo & EUDO_USB_MODE_MASK) >> EUDO_USB_MODE_SHIFT) {
+ case EUDO_USB_MODE_USB4:
+ mux_state.mode = TYPEC_MODE_USB4;
+ break;
+ case EUDO_USB_MODE_USB3:
+ mux_state.mode = TYPEC_MODE_USB3;
+ break;
+ default:
+ mux_state.mode = TYPEC_MODE_USB2;
+ break;
+ }
+
+ mux_state.alt = NULL; /* Not an alt mode */
+ mux_state.data = data;
+
+ return typec_mux_set(port->mux, &mux_state);
+}
+EXPORT_SYMBOL_GPL(typec_enter_usb);
+
/* --------------------------------------- */
/**
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index 6be5580459428..ee8db91737330 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -265,6 +265,7 @@ int typec_set_orientation(struct typec_port *port,
enum typec_orientation orientation);
enum typec_orientation typec_get_orientation(struct typec_port *port);
int typec_set_mode(struct typec_port *port, int mode);
+int typec_enter_usb(struct typec_port *port, struct enter_usb_data *data);
void *typec_get_drvdata(struct typec_port *port);
--
2.28.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: typec: Add typec_enter_usb() helper function
2020-11-09 12:05 [PATCH] usb: typec: Add typec_enter_usb() helper function Heikki Krogerus
@ 2020-11-09 12:21 ` Greg Kroah-Hartman
2020-11-09 12:34 ` Heikki Krogerus
0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2020-11-09 12:21 UTC (permalink / raw)
To: Heikki Krogerus; +Cc: linux-usb
On Mon, Nov 09, 2020 at 03:05:24PM +0300, Heikki Krogerus wrote:
> This function configures the muxes according to the
> requested USB mode in the Enter_USB Message that was
> communicated with the partner.
>
> In practice the function just fills struct typec_mux_state
> for the caller by extracting the connector mode (so USB
> mode) from the EUDO (Enter_USB Data Object), and then passes
> that structure to typec_mux_set().
>
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> drivers/usb/typec/class.c | 32 ++++++++++++++++++++++++++++++++
> include/linux/usb/typec.h | 1 +
> 2 files changed, 33 insertions(+)
>
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 35eec707cb512..22f82e924d585 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -11,6 +11,7 @@
> #include <linux/mutex.h>
> #include <linux/property.h>
> #include <linux/slab.h>
> +#include <linux/usb/pd.h>
>
> #include "bus.h"
>
> @@ -1579,6 +1580,37 @@ int typec_set_mode(struct typec_port *port, int mode)
> }
> EXPORT_SYMBOL_GPL(typec_set_mode);
>
> +/**
> + * typec_enter_usb - Set USB Mode for USB Type-C connector
> + * @port: USB Type-C connector
> + * @data: Enter_USB Message details.
> + *
> + * This function is called when Enter_USB Message is used. It configures @port
> + * muxes for the USB mode (USB 2.0, USB 3.2 or USB4).
> + */
> +int typec_enter_usb(struct typec_port *port, struct enter_usb_data *data)
> +{
> + struct typec_mux_state mux_state;
> +
> + switch ((data->eudo & EUDO_USB_MODE_MASK) >> EUDO_USB_MODE_SHIFT) {
> + case EUDO_USB_MODE_USB4:
> + mux_state.mode = TYPEC_MODE_USB4;
> + break;
> + case EUDO_USB_MODE_USB3:
> + mux_state.mode = TYPEC_MODE_USB3;
> + break;
> + default:
> + mux_state.mode = TYPEC_MODE_USB2;
> + break;
> + }
> +
> + mux_state.alt = NULL; /* Not an alt mode */
> + mux_state.data = data;
> +
> + return typec_mux_set(port->mux, &mux_state);
> +}
> +EXPORT_SYMBOL_GPL(typec_enter_usb);
We can't add symbols/functions for no in-kernel users, so perhaps submit
this as part of a series that actually uses it?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: typec: Add typec_enter_usb() helper function
2020-11-09 12:21 ` Greg Kroah-Hartman
@ 2020-11-09 12:34 ` Heikki Krogerus
0 siblings, 0 replies; 3+ messages in thread
From: Heikki Krogerus @ 2020-11-09 12:34 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb
On Mon, Nov 09, 2020 at 01:21:20PM +0100, Greg Kroah-Hartman wrote:
> We can't add symbols/functions for no in-kernel users, so perhaps submit
> this as part of a series that actually uses it?
Sorry Greg. I didn't mean to send the patch out yet.
thanks,
--
heikki
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-09 12:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-09 12:05 [PATCH] usb: typec: Add typec_enter_usb() helper function Heikki Krogerus
2020-11-09 12:21 ` Greg Kroah-Hartman
2020-11-09 12:34 ` Heikki Krogerus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox