* [PATCH 0/2] platform/chrome: cros_ec_typec: Link PD object to partner
@ 2022-11-21 20:13 Prashant Malani
2022-11-21 20:13 ` [PATCH 1/2] usb: typec: Add helper to get partner device struct Prashant Malani
2022-11-21 20:13 ` [PATCH 2/2] platform/chrome: cros_ec_typec: Set parent of partner PD object Prashant Malani
0 siblings, 2 replies; 6+ messages in thread
From: Prashant Malani @ 2022-11-21 20:13 UTC (permalink / raw)
To: linux-kernel, linux-usb, chrome-platform
Cc: Prashant Malani, Benson Leung, Greg Kroah-Hartman, Guenter Roeck,
Heikki Krogerus
This is a short series to link a registered USB PD object to its associated
partner device. This is helpful for userspace services (the ChromeOS Type-C
daemon, for example), to identify which Type-C peripheral a PD object belongs to,
when a uevent for the PD object arrives.
The first patch adds a helper to the Type-C class code to access the device struct
for a partner. The second patch uses that helper to set the parent for the USB PD object
in the port driver code.
There was an earlier patch[1] to solve this issue, but it's been jettisoned (on advice from
GregKH) in favor of the current approach.
[1] https://lore.kernel.org/linux-usb/Y3vNZEuNI3CWzZ0L@chromium.org/T/#m7521020f64d878313d7dd79903ec0e9421aa8737
Series submission suggestions (if the approach is OK):
- Patch 1 goes throug the USB tree and Patch 2 goes in the next release cycle
through the chrome-platform tree.
- Patch 1 and 2 both go through the USB tree.
Prashant Malani (2):
usb: typec: Add helper to get partner device struct
platform/chrome: cros_ec_typec: Set parent of partner PD object
drivers/platform/chrome/cros_ec_typec.c | 2 +-
drivers/usb/typec/class.c | 13 +++++++++++++
include/linux/usb/typec.h | 2 ++
3 files changed, 16 insertions(+), 1 deletion(-)
--
2.38.1.584.g0f3c55d4c2-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] usb: typec: Add helper to get partner device struct
2022-11-21 20:13 [PATCH 0/2] platform/chrome: cros_ec_typec: Link PD object to partner Prashant Malani
@ 2022-11-21 20:13 ` Prashant Malani
2022-11-22 9:58 ` Heikki Krogerus
2022-11-21 20:13 ` [PATCH 2/2] platform/chrome: cros_ec_typec: Set parent of partner PD object Prashant Malani
1 sibling, 1 reply; 6+ messages in thread
From: Prashant Malani @ 2022-11-21 20:13 UTC (permalink / raw)
To: linux-kernel, linux-usb, chrome-platform
Cc: Prashant Malani, Benson Leung, Heikki Krogerus,
Greg Kroah-Hartman, Guenter Roeck
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 helper which returns a pointer
to the Type-C partner's device struct, so that it can be supplied as the
parent to the PD object.
Cc: Benson Leung <bleung@chromium.org>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
---
drivers/usb/typec/class.c | 13 +++++++++++++
include/linux/usb/typec.h | 2 ++
2 files changed, 15 insertions(+)
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index bd5e5dd70431..154c70630432 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -821,6 +821,19 @@ void typec_partner_set_svdm_version(struct typec_partner *partner,
}
EXPORT_SYMBOL_GPL(typec_partner_set_svdm_version);
+
+/**
+ * typec_partner_to_dev - Get the device struct of a USB Type-C partner.
+ * @partner: USB Type-C Partner
+ *
+ * Returns a pointer to the device struct or NULL.
+ */
+struct device *typec_partner_to_dev(struct typec_partner *partner)
+{
+ return partner ? &partner->dev : NULL;
+}
+EXPORT_SYMBOL_GPL(typec_partner_to_dev);
+
/**
* 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..085be3e94ff8 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -327,6 +327,8 @@ 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 device *typec_partner_to_dev(struct typec_partner *partner);
+
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);
--
2.38.1.584.g0f3c55d4c2-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] platform/chrome: cros_ec_typec: Set parent of partner PD object
2022-11-21 20:13 [PATCH 0/2] platform/chrome: cros_ec_typec: Link PD object to partner Prashant Malani
2022-11-21 20:13 ` [PATCH 1/2] usb: typec: Add helper to get partner device struct Prashant Malani
@ 2022-11-21 20:13 ` Prashant Malani
1 sibling, 0 replies; 6+ messages in thread
From: Prashant Malani @ 2022-11-21 20:13 UTC (permalink / raw)
To: linux-kernel, linux-usb, chrome-platform
Cc: Prashant Malani, Benson Leung, Heikki Krogerus,
Greg Kroah-Hartman, Guenter Roeck
In order to tell what Type-C device a PD object belongs to, its parent
needs to be set. Set the parent appropriately for PD objects which are
created for connected Type-C partners.
Cc: Benson Leung <bleung@chromium.org>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
---
drivers/platform/chrome/cros_ec_typec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 2a7ff14dc37e..a1cc23b86f3c 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -968,7 +968,7 @@ static void cros_typec_register_partner_pdos(struct cros_typec_data *typec,
if (!resp->source_cap_count && !resp->sink_cap_count)
return;
- port->partner_pd = usb_power_delivery_register(NULL, &desc);
+ port->partner_pd = usb_power_delivery_register(typec_partner_to_dev(port->partner), &desc);
if (IS_ERR(port->partner_pd)) {
dev_warn(typec->dev, "Failed to register partner PD device, port: %d\n", port_num);
return;
--
2.38.1.584.g0f3c55d4c2-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] usb: typec: Add helper to get partner device struct
2022-11-21 20:13 ` [PATCH 1/2] usb: typec: Add helper to get partner device struct Prashant Malani
@ 2022-11-22 9:58 ` Heikki Krogerus
2022-11-22 19:05 ` Prashant Malani
0 siblings, 1 reply; 6+ messages in thread
From: Heikki Krogerus @ 2022-11-22 9:58 UTC (permalink / raw)
To: Prashant Malani
Cc: linux-kernel, linux-usb, chrome-platform, Benson Leung,
Greg Kroah-Hartman, Guenter Roeck
Hi Prashant,
On Mon, Nov 21, 2022 at 08:13:35PM +0000, Prashant Malani wrote:
> +/**
> + * typec_partner_to_dev - Get the device struct of a USB Type-C partner.
> + * @partner: USB Type-C Partner
> + *
> + * Returns a pointer to the device struct or NULL.
> + */
> +struct device *typec_partner_to_dev(struct typec_partner *partner)
> +{
> + return partner ? &partner->dev : NULL;
> +}
> +EXPORT_SYMBOL_GPL(typec_partner_to_dev);
Let's not loose the protection around these devices unless there is no
other way, and in this case there is.
Please just create a wrapper for usb_power_delivery_register() instead:
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);
thanks,
--
heikki
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] usb: typec: Add helper to get partner device struct
2022-11-22 9:58 ` Heikki Krogerus
@ 2022-11-22 19:05 ` Prashant Malani
2022-11-23 8:49 ` Heikki Krogerus
0 siblings, 1 reply; 6+ messages in thread
From: Prashant Malani @ 2022-11-22 19:05 UTC (permalink / raw)
To: Heikki Krogerus
Cc: linux-kernel, linux-usb, chrome-platform, Benson Leung,
Greg Kroah-Hartman, Guenter Roeck
Hi Heikki,
Thanks for reviewing the patch.
On Tue, Nov 22, 2022 at 1:58 AM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>
> Let's not loose the protection around these devices unless there is no
> other way, and in this case there is.
>
> Please just create a wrapper for usb_power_delivery_register() instead:
>
> 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);
Sounds good. I'll send a v2 with the above change as patch 1 (instead
of the current patch 1).
I will list you as the "Suggested-by" tag (but please let me know if
you'd like attribution stated differently).
Thanks again!
-Prashant
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] usb: typec: Add helper to get partner device struct
2022-11-22 19:05 ` Prashant Malani
@ 2022-11-23 8:49 ` Heikki Krogerus
0 siblings, 0 replies; 6+ messages in thread
From: Heikki Krogerus @ 2022-11-23 8:49 UTC (permalink / raw)
To: Prashant Malani
Cc: linux-kernel, linux-usb, chrome-platform, Benson Leung,
Greg Kroah-Hartman, Guenter Roeck
On Tue, Nov 22, 2022 at 11:05:04AM -0800, Prashant Malani wrote:
> Hi Heikki,
>
> Thanks for reviewing the patch.
>
> On Tue, Nov 22, 2022 at 1:58 AM Heikki Krogerus
> <heikki.krogerus@linux.intel.com> wrote:
> >
> > Let's not loose the protection around these devices unless there is no
> > other way, and in this case there is.
> >
> > Please just create a wrapper for usb_power_delivery_register() instead:
> >
> > 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);
>
> Sounds good. I'll send a v2 with the above change as patch 1 (instead
> of the current patch 1).
>
> I will list you as the "Suggested-by" tag (but please let me know if
> you'd like attribution stated differently).
Thanks. Suggested-by is the correct tag IMO.
cheers,
--
heikki
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-11-23 8:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-21 20:13 [PATCH 0/2] platform/chrome: cros_ec_typec: Link PD object to partner Prashant Malani
2022-11-21 20:13 ` [PATCH 1/2] usb: typec: Add helper to get partner device struct Prashant Malani
2022-11-22 9:58 ` Heikki Krogerus
2022-11-22 19:05 ` Prashant Malani
2022-11-23 8:49 ` Heikki Krogerus
2022-11-21 20:13 ` [PATCH 2/2] platform/chrome: cros_ec_typec: Set parent of partner PD object Prashant Malani
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox