* [PATCH] phy: omap-usb2: add explicit PHY comparator API
@ 2026-07-22 5:36 Ivaylo Dimitrov
2026-08-27 6:13 ` Ivaylo Dimitrov
2026-08-27 15:51 ` Vinod Koul
0 siblings, 2 replies; 3+ messages in thread
From: Ivaylo Dimitrov @ 2026-07-22 5:36 UTC (permalink / raw)
To: Vinod Koul, Neil Armstrong, Johan Hovold
Cc: linux-phy, linux-kernel, Ivaylo Dimitrov
The existing omap_usb2_set_comparator() API locates the OMAP USB2 PHY
instance by calling usb_get_phy(USB_PHY_TYPE_USB2), assuming there is a
single USB2 PHY registered in the system.
This assumption no longer holds on systems with multiple USB2 PHY
providers. In such cases, the global lookup may return a different USB2
PHY instance, causing the OMAP driver to perform an invalid container_of()
conversion when accessing its private data.
Introduce omap_usb2_set_phy_comparator(), allowing callers to explicitly
specify the OMAP USB2 PHY instance to associate with a phy_companion.
The new helper validates that the supplied USB PHY is an OMAP USB2 PHY
before accessing its private data.
The existing omap_usb2_set_comparator() API is kept unchanged for
existing users.
Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
---
drivers/phy/ti/phy-omap-usb2.c | 32 ++++++++++++++++++++++++++++++++
include/linux/phy/omap_usb.h | 7 +++++++
2 files changed, 39 insertions(+)
diff --git a/drivers/phy/ti/phy-omap-usb2.c b/drivers/phy/ti/phy-omap-usb2.c
index 1eb252604441..ac31b693fce7 100644
--- a/drivers/phy/ti/phy-omap-usb2.c
+++ b/drivers/phy/ti/phy-omap-usb2.c
@@ -70,6 +70,8 @@ struct omap_usb {
#define phy_to_omapusb(x) container_of((x), struct omap_usb, phy)
+static int omap_usb_set_host(struct usb_otg *otg, struct usb_bus *host);
+
struct usb_phy_data {
const char *label;
u8 flags;
@@ -113,6 +115,36 @@ int omap_usb2_set_comparator(struct phy_companion *comparator)
}
EXPORT_SYMBOL_GPL(omap_usb2_set_comparator);
+/**
+ * omap_usb2_set_phy_comparator() - associate a comparator with an OMAP USB2 PHY
+ *
+ * @omap_phy: OMAP USB2 PHY instance
+ * @comparator: companion PHY providing comparator operations
+ *
+ * The phy companion driver should call this API with the companion PHY
+ * implementation containing the callbacks required by @omap_phy.
+ *
+ * For use by phy companion drivers.
+ */
+int omap_usb2_set_phy_comparator(struct usb_phy *omap_phy,
+ struct phy_companion *comparator)
+{
+ struct omap_usb *phy;
+
+ if (!omap_phy)
+ return -EINVAL;
+
+ if (WARN_ON(!omap_phy->otg ||
+ omap_phy->otg->set_host != omap_usb_set_host))
+ return -EINVAL;
+
+ phy = phy_to_omapusb(omap_phy);
+ phy->comparator = comparator;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(omap_usb2_set_phy_comparator);
+
static int omap_usb_set_vbus(struct usb_otg *otg, bool enabled)
{
struct omap_usb *phy = phy_to_omapusb(otg->usb_phy);
diff --git a/include/linux/phy/omap_usb.h b/include/linux/phy/omap_usb.h
index e23b52df93ec..96f9792c6ce6 100644
--- a/include/linux/phy/omap_usb.h
+++ b/include/linux/phy/omap_usb.h
@@ -15,11 +15,18 @@
#if defined(CONFIG_OMAP_USB2) || defined(CONFIG_OMAP_USB2_MODULE)
extern int omap_usb2_set_comparator(struct phy_companion *comparator);
+extern int omap_usb2_set_phy_comparator(struct usb_phy *omap_phy,
+ struct phy_companion *comparator);
#else
static inline int omap_usb2_set_comparator(struct phy_companion *comparator)
{
return -ENODEV;
}
+static inline int omap_usb2_set_phy_comparator(struct usb_phy *omap_phy,
+ struct phy_companion *comparator)
+{
+ return -ENODEV;
+}
#endif
#endif /* __DRIVERS_OMAP_USB_H */
--
2.39.5
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] phy: omap-usb2: add explicit PHY comparator API
2026-07-22 5:36 [PATCH] phy: omap-usb2: add explicit PHY comparator API Ivaylo Dimitrov
@ 2026-08-27 6:13 ` Ivaylo Dimitrov
2026-08-27 15:51 ` Vinod Koul
1 sibling, 0 replies; 3+ messages in thread
From: Ivaylo Dimitrov @ 2026-08-27 6:13 UTC (permalink / raw)
To: Vinod Koul, Neil Armstrong, Johan Hovold; +Cc: linux-phy, linux-kernel
Gentle ping on this patch. It's been about five weeks since v1, and I
haven't seen any feedback yet.
The patch is still applicable to current linux-next. Please let me know
if the approach looks reasonable, or if there are any concerns I should
address.
Thanks,
Ivo
On 22.07.26 г. 8:36 ч., Ivaylo Dimitrov wrote:
> The existing omap_usb2_set_comparator() API locates the OMAP USB2 PHY
> instance by calling usb_get_phy(USB_PHY_TYPE_USB2), assuming there is a
> single USB2 PHY registered in the system.
>
> This assumption no longer holds on systems with multiple USB2 PHY
> providers. In such cases, the global lookup may return a different USB2
> PHY instance, causing the OMAP driver to perform an invalid container_of()
> conversion when accessing its private data.
>
> Introduce omap_usb2_set_phy_comparator(), allowing callers to explicitly
> specify the OMAP USB2 PHY instance to associate with a phy_companion.
> The new helper validates that the supplied USB PHY is an OMAP USB2 PHY
> before accessing its private data.
>
> The existing omap_usb2_set_comparator() API is kept unchanged for
> existing users.
>
>
> Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
> ---
> drivers/phy/ti/phy-omap-usb2.c | 32 ++++++++++++++++++++++++++++++++
> include/linux/phy/omap_usb.h | 7 +++++++
> 2 files changed, 39 insertions(+)
>
> diff --git a/drivers/phy/ti/phy-omap-usb2.c b/drivers/phy/ti/phy-omap-usb2.c
> index 1eb252604441..ac31b693fce7 100644
> --- a/drivers/phy/ti/phy-omap-usb2.c
> +++ b/drivers/phy/ti/phy-omap-usb2.c
> @@ -70,6 +70,8 @@ struct omap_usb {
>
> #define phy_to_omapusb(x) container_of((x), struct omap_usb, phy)
>
> +static int omap_usb_set_host(struct usb_otg *otg, struct usb_bus *host);
> +
> struct usb_phy_data {
> const char *label;
> u8 flags;
> @@ -113,6 +115,36 @@ int omap_usb2_set_comparator(struct phy_companion *comparator)
> }
> EXPORT_SYMBOL_GPL(omap_usb2_set_comparator);
>
> +/**
> + * omap_usb2_set_phy_comparator() - associate a comparator with an OMAP USB2 PHY
> + *
> + * @omap_phy: OMAP USB2 PHY instance
> + * @comparator: companion PHY providing comparator operations
> + *
> + * The phy companion driver should call this API with the companion PHY
> + * implementation containing the callbacks required by @omap_phy.
> + *
> + * For use by phy companion drivers.
> + */
> +int omap_usb2_set_phy_comparator(struct usb_phy *omap_phy,
> + struct phy_companion *comparator)
> +{
> + struct omap_usb *phy;
> +
> + if (!omap_phy)
> + return -EINVAL;
> +
> + if (WARN_ON(!omap_phy->otg ||
> + omap_phy->otg->set_host != omap_usb_set_host))
> + return -EINVAL;
> +
> + phy = phy_to_omapusb(omap_phy);
> + phy->comparator = comparator;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(omap_usb2_set_phy_comparator);
> +
> static int omap_usb_set_vbus(struct usb_otg *otg, bool enabled)
> {
> struct omap_usb *phy = phy_to_omapusb(otg->usb_phy);
> diff --git a/include/linux/phy/omap_usb.h b/include/linux/phy/omap_usb.h
> index e23b52df93ec..96f9792c6ce6 100644
> --- a/include/linux/phy/omap_usb.h
> +++ b/include/linux/phy/omap_usb.h
> @@ -15,11 +15,18 @@
>
> #if defined(CONFIG_OMAP_USB2) || defined(CONFIG_OMAP_USB2_MODULE)
> extern int omap_usb2_set_comparator(struct phy_companion *comparator);
> +extern int omap_usb2_set_phy_comparator(struct usb_phy *omap_phy,
> + struct phy_companion *comparator);
> #else
> static inline int omap_usb2_set_comparator(struct phy_companion *comparator)
> {
> return -ENODEV;
> }
> +static inline int omap_usb2_set_phy_comparator(struct usb_phy *omap_phy,
> + struct phy_companion *comparator)
> +{
> + return -ENODEV;
> +}
> #endif
>
> #endif /* __DRIVERS_OMAP_USB_H */
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] phy: omap-usb2: add explicit PHY comparator API
2026-07-22 5:36 [PATCH] phy: omap-usb2: add explicit PHY comparator API Ivaylo Dimitrov
2026-08-27 6:13 ` Ivaylo Dimitrov
@ 2026-08-27 15:51 ` Vinod Koul
1 sibling, 0 replies; 3+ messages in thread
From: Vinod Koul @ 2026-08-27 15:51 UTC (permalink / raw)
To: Ivaylo Dimitrov; +Cc: Neil Armstrong, Johan Hovold, linux-phy, linux-kernel
On 22-07-26, 08:36, Ivaylo Dimitrov wrote:
> The existing omap_usb2_set_comparator() API locates the OMAP USB2 PHY
> instance by calling usb_get_phy(USB_PHY_TYPE_USB2), assuming there is a
> single USB2 PHY registered in the system.
>
> This assumption no longer holds on systems with multiple USB2 PHY
> providers. In such cases, the global lookup may return a different USB2
> PHY instance, causing the OMAP driver to perform an invalid container_of()
> conversion when accessing its private data.
>
> Introduce omap_usb2_set_phy_comparator(), allowing callers to explicitly
> specify the OMAP USB2 PHY instance to associate with a phy_companion.
> The new helper validates that the supplied USB PHY is an OMAP USB2 PHY
> before accessing its private data.
Well the name can cause ambiguity with old API. Second I would like to
see users of this API as well
>
> The existing omap_usb2_set_comparator() API is kept unchanged for
> existing users.
>
>
> Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
> ---
> drivers/phy/ti/phy-omap-usb2.c | 32 ++++++++++++++++++++++++++++++++
> include/linux/phy/omap_usb.h | 7 +++++++
> 2 files changed, 39 insertions(+)
>
> diff --git a/drivers/phy/ti/phy-omap-usb2.c b/drivers/phy/ti/phy-omap-usb2.c
> index 1eb252604441..ac31b693fce7 100644
> --- a/drivers/phy/ti/phy-omap-usb2.c
> +++ b/drivers/phy/ti/phy-omap-usb2.c
> @@ -70,6 +70,8 @@ struct omap_usb {
>
> #define phy_to_omapusb(x) container_of((x), struct omap_usb, phy)
>
> +static int omap_usb_set_host(struct usb_otg *otg, struct usb_bus *host);
> +
> struct usb_phy_data {
> const char *label;
> u8 flags;
> @@ -113,6 +115,36 @@ int omap_usb2_set_comparator(struct phy_companion *comparator)
> }
> EXPORT_SYMBOL_GPL(omap_usb2_set_comparator);
>
> +/**
> + * omap_usb2_set_phy_comparator() - associate a comparator with an OMAP USB2 PHY
> + *
> + * @omap_phy: OMAP USB2 PHY instance
> + * @comparator: companion PHY providing comparator operations
> + *
> + * The phy companion driver should call this API with the companion PHY
> + * implementation containing the callbacks required by @omap_phy.
> + *
> + * For use by phy companion drivers.
> + */
> +int omap_usb2_set_phy_comparator(struct usb_phy *omap_phy,
> + struct phy_companion *comparator)
> +{
> + struct omap_usb *phy;
> +
> + if (!omap_phy)
> + return -EINVAL;
> +
> + if (WARN_ON(!omap_phy->otg ||
> + omap_phy->otg->set_host != omap_usb_set_host))
> + return -EINVAL;
> +
> + phy = phy_to_omapusb(omap_phy);
> + phy->comparator = comparator;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(omap_usb2_set_phy_comparator);
> +
> static int omap_usb_set_vbus(struct usb_otg *otg, bool enabled)
> {
> struct omap_usb *phy = phy_to_omapusb(otg->usb_phy);
> diff --git a/include/linux/phy/omap_usb.h b/include/linux/phy/omap_usb.h
> index e23b52df93ec..96f9792c6ce6 100644
> --- a/include/linux/phy/omap_usb.h
> +++ b/include/linux/phy/omap_usb.h
> @@ -15,11 +15,18 @@
>
> #if defined(CONFIG_OMAP_USB2) || defined(CONFIG_OMAP_USB2_MODULE)
> extern int omap_usb2_set_comparator(struct phy_companion *comparator);
> +extern int omap_usb2_set_phy_comparator(struct usb_phy *omap_phy,
> + struct phy_companion *comparator);
> #else
> static inline int omap_usb2_set_comparator(struct phy_companion *comparator)
> {
> return -ENODEV;
> }
> +static inline int omap_usb2_set_phy_comparator(struct usb_phy *omap_phy,
> + struct phy_companion *comparator)
> +{
> + return -ENODEV;
> +}
> #endif
>
> #endif /* __DRIVERS_OMAP_USB_H */
> --
> 2.39.5
--
~Vinod
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-27 15:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-22 5:36 [PATCH] phy: omap-usb2: add explicit PHY comparator API Ivaylo Dimitrov
2026-08-27 6:13 ` Ivaylo Dimitrov
2026-08-27 15:51 ` Vinod Koul
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®