diff mbox series

[v2,02/12] usb: typec: altmodes: add svdm version info for typec cables

Message ID 20231214230850.379863-16-rdbabiera@google.com (mailing list archive)
State Superseded
Headers show
Series usb: typec: add SOP' support to the tcpm and alt mode drivers | expand

Commit Message

RD Babiera Dec. 14, 2023, 11:08 p.m. UTC
Add typec_cable_set_svdm_version and typec_get_cable_svdm version symbols.
Cables can operate under a lower PD revision than the port partner, and the
max SVDM version is tied to the PD revision. So, typec_cable maintains its
own svdm_version.

Add typec_altmode_get_cable_svdm_version to return the cable's negotiated
svdm_version for altmode drivers to use.

Signed-off-by: RD Babiera <rdbabiera@google.com>
---
 drivers/usb/typec/class.c         | 40 +++++++++++++++++++++++++++++++
 drivers/usb/typec/class.h         |  1 +
 include/linux/usb/typec.h         |  3 +++
 include/linux/usb/typec_altmode.h | 10 ++++++++
 4 files changed, 54 insertions(+)

Comments

Heikki Krogerus Dec. 19, 2023, 1:54 p.m. UTC | #1
On Thu, Dec 14, 2023 at 11:08:46PM +0000, RD Babiera wrote:
> Add typec_cable_set_svdm_version and typec_get_cable_svdm version symbols.
> Cables can operate under a lower PD revision than the port partner, and the
> max SVDM version is tied to the PD revision. So, typec_cable maintains its
> own svdm_version.
> 
> Add typec_altmode_get_cable_svdm_version to return the cable's negotiated
> svdm_version for altmode drivers to use.
> 
> Signed-off-by: RD Babiera <rdbabiera@google.com>

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

> ---
>  drivers/usb/typec/class.c         | 40 +++++++++++++++++++++++++++++++
>  drivers/usb/typec/class.h         |  1 +
>  include/linux/usb/typec.h         |  3 +++
>  include/linux/usb/typec_altmode.h | 10 ++++++++
>  4 files changed, 54 insertions(+)
> 
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 86b5a8414b89..038c6498e683 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -2129,6 +2129,46 @@ int typec_get_negotiated_svdm_version(struct typec_port *port)
>  }
>  EXPORT_SYMBOL_GPL(typec_get_negotiated_svdm_version);
>  
> +/**
> + * typec_get_cable_svdm_version - Get cable negotiated SVDM Version
> + * @port: USB Type-C Port.
> + *
> + * Get the negotiated SVDM Version for the cable. The Version is set to the port
> + * default value based on the PD Revision during cable registration, and updated
> + * after a successful Discover Identity if the negotiated value is less than the
> + * default.
> + *
> + * Returns usb_pd_svdm_ver if the cable has been registered otherwise -ENODEV.
> + */
> +int typec_get_cable_svdm_version(struct typec_port *port)
> +{
> +	enum usb_pd_svdm_ver svdm_version;
> +	struct device *cable_dev;
> +
> +	cable_dev = device_find_child(&port->dev, NULL, cable_match);
> +	if (!cable_dev)
> +		return -ENODEV;
> +
> +	svdm_version = to_typec_cable(cable_dev)->svdm_version;
> +	put_device(cable_dev);
> +
> +	return svdm_version;
> +}
> +EXPORT_SYMBOL_GPL(typec_get_cable_svdm_version);
> +
> +/**
> + * typec_cable_set_svdm_version - Set negotiated Structured VDM (SVDM) Version
> + * @cable: USB Type-C Active Cable that supports SVDM
> + * @svdm_version: Negotiated SVDM Version
> + *
> + * This routine is used to save the negotiated SVDM Version.
> + */
> +void typec_cable_set_svdm_version(struct typec_cable *cable, enum usb_pd_svdm_ver svdm_version)
> +{
> +	cable->svdm_version = svdm_version;
> +}
> +EXPORT_SYMBOL_GPL(typec_cable_set_svdm_version);
> +
>  /**
>   * typec_get_drvdata - Return private driver data pointer
>   * @port: USB Type-C port
> diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h
> index c36761ba3f59..759b98355eeb 100644
> --- a/drivers/usb/typec/class.h
> +++ b/drivers/usb/typec/class.h
> @@ -23,6 +23,7 @@ struct typec_cable {
>  	struct usb_pd_identity		*identity;
>  	unsigned int			active:1;
>  	u16				pd_revision; /* 0300H = "3.0" */
> +	enum usb_pd_svdm_ver		svdm_version;
>  };
>  
>  struct typec_partner {
> diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> index 38f93d72fd1b..b35b427561ab 100644
> --- a/include/linux/usb/typec.h
> +++ b/include/linux/usb/typec.h
> @@ -337,6 +337,9 @@ void typec_partner_set_svdm_version(struct typec_partner *partner,
>  				    enum usb_pd_svdm_ver svdm_version);
>  int typec_get_negotiated_svdm_version(struct typec_port *port);
>  
> +int typec_get_cable_svdm_version(struct typec_port *port);
> +void typec_cable_set_svdm_version(struct typec_cable *cable, enum usb_pd_svdm_ver svdm_version);
> +
>  struct usb_power_delivery *typec_partner_usb_power_delivery_register(struct typec_partner *partner,
>  							struct usb_power_delivery_desc *desc);
>  
> diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_altmode.h
> index 72ec8058543a..b3c0866ea70f 100644
> --- a/include/linux/usb/typec_altmode.h
> +++ b/include/linux/usb/typec_altmode.h
> @@ -95,6 +95,16 @@ int typec_cable_altmode_exit(struct typec_altmode *altmode, enum typec_plug_inde
>  int typec_cable_altmode_vdm(struct typec_altmode *altmode, enum typec_plug_index sop,
>  			    const u32 header, const u32 *vdo, int count);
>  
> +/**
> + * typec_altmode_get_cable_svdm_version - Get negotiated SVDM version for cable plug
> + * @altmode: Handle to the alternate mode
> + */
> +static inline int
> +typec_altmode_get_cable_svdm_version(struct typec_altmode *altmode)
> +{
> +	return typec_get_cable_svdm_version(typec_altmode2port(altmode));
> +}
> +
>  /*
>   * These are the connector states (USB, Safe and Alt Mode) defined in USB Type-C
>   * Specification. SVID specific connector states are expected to follow and
> -- 
> 2.43.0.472.g3155946c3a-goog
diff mbox series

Patch

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 86b5a8414b89..038c6498e683 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -2129,6 +2129,46 @@  int typec_get_negotiated_svdm_version(struct typec_port *port)
 }
 EXPORT_SYMBOL_GPL(typec_get_negotiated_svdm_version);
 
+/**
+ * typec_get_cable_svdm_version - Get cable negotiated SVDM Version
+ * @port: USB Type-C Port.
+ *
+ * Get the negotiated SVDM Version for the cable. The Version is set to the port
+ * default value based on the PD Revision during cable registration, and updated
+ * after a successful Discover Identity if the negotiated value is less than the
+ * default.
+ *
+ * Returns usb_pd_svdm_ver if the cable has been registered otherwise -ENODEV.
+ */
+int typec_get_cable_svdm_version(struct typec_port *port)
+{
+	enum usb_pd_svdm_ver svdm_version;
+	struct device *cable_dev;
+
+	cable_dev = device_find_child(&port->dev, NULL, cable_match);
+	if (!cable_dev)
+		return -ENODEV;
+
+	svdm_version = to_typec_cable(cable_dev)->svdm_version;
+	put_device(cable_dev);
+
+	return svdm_version;
+}
+EXPORT_SYMBOL_GPL(typec_get_cable_svdm_version);
+
+/**
+ * typec_cable_set_svdm_version - Set negotiated Structured VDM (SVDM) Version
+ * @cable: USB Type-C Active Cable that supports SVDM
+ * @svdm_version: Negotiated SVDM Version
+ *
+ * This routine is used to save the negotiated SVDM Version.
+ */
+void typec_cable_set_svdm_version(struct typec_cable *cable, enum usb_pd_svdm_ver svdm_version)
+{
+	cable->svdm_version = svdm_version;
+}
+EXPORT_SYMBOL_GPL(typec_cable_set_svdm_version);
+
 /**
  * typec_get_drvdata - Return private driver data pointer
  * @port: USB Type-C port
diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h
index c36761ba3f59..759b98355eeb 100644
--- a/drivers/usb/typec/class.h
+++ b/drivers/usb/typec/class.h
@@ -23,6 +23,7 @@  struct typec_cable {
 	struct usb_pd_identity		*identity;
 	unsigned int			active:1;
 	u16				pd_revision; /* 0300H = "3.0" */
+	enum usb_pd_svdm_ver		svdm_version;
 };
 
 struct typec_partner {
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index 38f93d72fd1b..b35b427561ab 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -337,6 +337,9 @@  void typec_partner_set_svdm_version(struct typec_partner *partner,
 				    enum usb_pd_svdm_ver svdm_version);
 int typec_get_negotiated_svdm_version(struct typec_port *port);
 
+int typec_get_cable_svdm_version(struct typec_port *port);
+void typec_cable_set_svdm_version(struct typec_cable *cable, enum usb_pd_svdm_ver svdm_version);
+
 struct usb_power_delivery *typec_partner_usb_power_delivery_register(struct typec_partner *partner,
 							struct usb_power_delivery_desc *desc);
 
diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_altmode.h
index 72ec8058543a..b3c0866ea70f 100644
--- a/include/linux/usb/typec_altmode.h
+++ b/include/linux/usb/typec_altmode.h
@@ -95,6 +95,16 @@  int typec_cable_altmode_exit(struct typec_altmode *altmode, enum typec_plug_inde
 int typec_cable_altmode_vdm(struct typec_altmode *altmode, enum typec_plug_index sop,
 			    const u32 header, const u32 *vdo, int count);
 
+/**
+ * typec_altmode_get_cable_svdm_version - Get negotiated SVDM version for cable plug
+ * @altmode: Handle to the alternate mode
+ */
+static inline int
+typec_altmode_get_cable_svdm_version(struct typec_altmode *altmode)
+{
+	return typec_get_cable_svdm_version(typec_altmode2port(altmode));
+}
+
 /*
  * These are the connector states (USB, Safe and Alt Mode) defined in USB Type-C
  * Specification. SVID specific connector states are expected to follow and