[v2,1/2] usb: typec: Add partner PD object wrapper

Message ID 20221122220538.2991775-2-pmalani@chromium.org
State New
Headers
Series platform/chrome: cros_ec_typec: Link PD object to partner |

Commit Message

Prashant Malani Nov. 22, 2022, 10:05 p.m. UTC
  Some port drivers may want to set a Type-C partner as a parent for a
USB Power Delivery object, but the Type-C partner struct isn't exposed
outside of the Type-C class driver. Add a wrapper to
usb_power_delivery_register() which sets the provided Type-C partner
as a parent to the USB PD object. This helps to avoid exposing the
Type-C partner's device struct unnecessarily.

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

Changes since v1:
- Patch first introduced in v2.

 drivers/usb/typec/class.c | 19 +++++++++++++++++++
 include/linux/usb/typec.h |  4 ++++
 2 files changed, 23 insertions(+)
  

Comments

Heikki Krogerus Nov. 23, 2022, 8:53 a.m. UTC | #1
On Tue, Nov 22, 2022 at 10:05:36PM +0000, Prashant Malani wrote:
> Some port drivers may want to set a Type-C partner as a parent for a
> USB Power Delivery object, but the Type-C partner struct isn't exposed
> outside of the Type-C class driver. Add a wrapper to
> usb_power_delivery_register() which sets the provided Type-C partner
> as a parent to the USB PD object. This helps to avoid exposing the
> Type-C partner's device struct unnecessarily.
> 
> Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Benson Leung <bleung@chromium.org>
> Signed-off-by: Prashant Malani <pmalani@chromium.org>

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

> ---
> 
> Changes since v1:
> - Patch first introduced in v2.
> 
>  drivers/usb/typec/class.c | 19 +++++++++++++++++++
>  include/linux/usb/typec.h |  4 ++++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index bd5e5dd70431..5897905cb4f0 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -821,6 +821,25 @@ void typec_partner_set_svdm_version(struct typec_partner *partner,
>  }
>  EXPORT_SYMBOL_GPL(typec_partner_set_svdm_version);
>  
> +/**
> + * typec_partner_usb_power_delivery_register - Register Type-C partner USB Power Delivery Support
> + * @partner: Type-C partner device.
> + * @desc: Description of the USB PD contract.
> + *
> + * This routine is a wrapper around usb_power_delivery_register(). It registers
> + * USB Power Delivery Capabilities for a Type-C partner device. Specifically,
> + * it sets the Type-C partner device as a parent for the resulting USB Power Delivery object.
> + *
> + * Returns handle to struct usb_power_delivery or ERR_PTR.
> + */
> +struct usb_power_delivery *
> +typec_partner_usb_power_delivery_register(struct typec_partner *partner,
> +					  struct usb_power_delivery_desc *desc)
> +{
> +	return usb_power_delivery_register(&partner->dev, desc);
> +}
> +EXPORT_SYMBOL_GPL(typec_partner_usb_power_delivery_register);
> +
>  /**
>   * typec_register_partner - Register a USB Type-C Partner
>   * @port: The USB Type-C Port the partner is connected to
> diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> index 7751bedcae5d..8fa781207970 100644
> --- a/include/linux/usb/typec.h
> +++ b/include/linux/usb/typec.h
> @@ -23,6 +23,7 @@ struct fwnode_handle;
>  struct device;
>  
>  struct usb_power_delivery;
> +struct usb_power_delivery_desc;
>  
>  enum typec_port_type {
>  	TYPEC_PORT_SRC,
> @@ -327,6 +328,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);
>  
> +struct usb_power_delivery *typec_partner_usb_power_delivery_register(struct typec_partner *partner,
> +							struct usb_power_delivery_desc *desc);
> +
>  int typec_port_set_usb_power_delivery(struct typec_port *port, struct usb_power_delivery *pd);
>  int typec_partner_set_usb_power_delivery(struct typec_partner *partner,
>  					 struct usb_power_delivery *pd);

thanks,
  

Patch

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index bd5e5dd70431..5897905cb4f0 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -821,6 +821,25 @@  void typec_partner_set_svdm_version(struct typec_partner *partner,
 }
 EXPORT_SYMBOL_GPL(typec_partner_set_svdm_version);
 
+/**
+ * typec_partner_usb_power_delivery_register - Register Type-C partner USB Power Delivery Support
+ * @partner: Type-C partner device.
+ * @desc: Description of the USB PD contract.
+ *
+ * This routine is a wrapper around usb_power_delivery_register(). It registers
+ * USB Power Delivery Capabilities for a Type-C partner device. Specifically,
+ * it sets the Type-C partner device as a parent for the resulting USB Power Delivery object.
+ *
+ * Returns handle to struct usb_power_delivery or ERR_PTR.
+ */
+struct usb_power_delivery *
+typec_partner_usb_power_delivery_register(struct typec_partner *partner,
+					  struct usb_power_delivery_desc *desc)
+{
+	return usb_power_delivery_register(&partner->dev, desc);
+}
+EXPORT_SYMBOL_GPL(typec_partner_usb_power_delivery_register);
+
 /**
  * typec_register_partner - Register a USB Type-C Partner
  * @port: The USB Type-C Port the partner is connected to
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index 7751bedcae5d..8fa781207970 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -23,6 +23,7 @@  struct fwnode_handle;
 struct device;
 
 struct usb_power_delivery;
+struct usb_power_delivery_desc;
 
 enum typec_port_type {
 	TYPEC_PORT_SRC,
@@ -327,6 +328,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);
 
+struct usb_power_delivery *typec_partner_usb_power_delivery_register(struct typec_partner *partner,
+							struct usb_power_delivery_desc *desc);
+
 int typec_port_set_usb_power_delivery(struct typec_port *port, struct usb_power_delivery *pd);
 int typec_partner_set_usb_power_delivery(struct typec_partner *partner,
 					 struct usb_power_delivery *pd);