Skip to contentSkip to conversation

musb-new: fix omap peripheral support

PATCH In review Andreas Kemnade 2 participants 5 messages Jan 9, 2023 – Jan 19, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover musb-new: fix omap peripheral support

DM_GADGET did not compile at all, probe was not called in non-gadget mode.

Tested on an omap4 board with ums and fastboot command.

Changes in V2:
- split up former 2/2 patch into two.
- do not break non-DM_USB_GADGET compile further

Andreas Kemnade (2):
musb-new: omap2430: no host data access in gadget mode
musb-new: omap2430: fix compiling in DM_USB_GADGET config

 drivers/usb/musb-new/omap2430.c | 53 ++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 18 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/2 musb-new: omap2430: no host data access in gadget mode

Avoid accessing structures (usb_bus_priv) only present when musb is in host mode.

---
 drivers/usb/musb-new/omap2430.c | 34 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 18 deletions(-)
drivers/usb/musb-new/omap2430.c +16 -18
index 7d15b94a6c..0d1fb03727 100644
@@ -214,37 +214,35 @@ static int omap2430_musb_of_to_plat(struct udevice *dev)
 
 static int omap2430_musb_probe(struct udevice *dev)
 {
-#ifdef CONFIG_USB_MUSB_HOST
-	struct musb_host_data *host = dev_get_priv(dev);
-#else
-	struct musb *musbp;
-#endif
 	struct omap2430_musb_plat *plat = dev_get_plat(dev);
-	struct usb_bus_priv *priv = dev_get_uclass_priv(dev);
 	struct omap_musb_board_data *otg_board_data;
 	int ret = 0;
 	void *base = dev_read_addr_ptr(dev);
-
-	priv->desc_before_addr = true;
+	struct musb *musbp;
 
 	otg_board_data = &plat->otg_board_data;
 
-#ifdef CONFIG_USB_MUSB_HOST
-	host->host = musb_init_controller(&plat->plat,
-					  (struct device *)otg_board_data,
-					  plat->base);
-	if (!host->host) {
-		return -EIO;
+	if (CONFIG_IS_ENABLED(USB_MUSB_HOST)) {
+		struct musb_host_data *host = dev_get_priv(dev);
+		struct usb_bus_priv *priv = dev_get_uclass_priv(dev);
+
+		priv->desc_before_addr = true;
+
+		host->host = musb_init_controller(&plat->plat,
+						  (struct device *)otg_board_data,
+						  plat->base);
+		if (!host->host)
+			return -EIO;
+
+		return musb_lowlevel_init(host);
 	}
 
-	ret = musb_lowlevel_init(host);
-#else
 	musbp = musb_register(&plat->plat, (struct device *)otg_board_data,
 			      plat->base);
 	if (IS_ERR_OR_NULL(musbp))
 		return -EINVAL;
-#endif
-	return ret;
+
+	return 0;
 }
 
 static int omap2430_musb_remove(struct udevice *dev)
Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH v2 1/2] musb-new: omap2430: no host data access in gadget mode

Quoted 4 lines · Andreas Kemnade

Avoid accessing structures (usb_bus_priv) only present when musb is in host mode.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#3 lore raw

PATCH v2 2/2 musb-new: omap2430: fix compiling in DM_USB_GADGET config

In reply to Andreas Kemnade

Add the separate IRQ handling function and change the registration.

---
 drivers/usb/musb-new/omap2430.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/usb/musb-new/omap2430.c +19 -0
index 0d1fb03727..42e7abddbc 100644
@@ -46,6 +46,15 @@ static inline void omap2430_low_level_init(struct musb *musb)
 	musb_writel(musb->mregs, OTG_FORCESTDBY, l);
 }
 
+#ifdef CONFIG_DM_USB_GADGET
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
+{
+	struct musb_host_data *host = dev_get_priv(dev);
+
+	host->host->isr(0, host->host);
+	return 0;
+}
+#endif
 
 static int omap2430_musb_init(struct musb *musb)
 {
@@ -235,6 +244,16 @@ static int omap2430_musb_probe(struct udevice *dev)
 			return -EIO;
 
 		return musb_lowlevel_init(host);
+	} else if (CONFIG_IS_ENABLED(DM_USB_GADGET)) {
+		struct musb_host_data *host = dev_get_priv(dev);
+
+		host->host = musb_init_controller(&plat->plat,
+						  (struct device *)otg_board_data,
+						  plat->base);
+		if (!host->host)
+			return -EIO;
+
+		return usb_add_gadget_udc((struct device *)otg_board_data, &host->host->g);
 	}
 
 	musbp = musb_register(&plat->plat, (struct device *)otg_board_data,
Signature · 1 line
2.30.2
#4 lore raw

Re: [PATCH v2 2/2] musb-new: omap2430: fix compiling in DM_USB_GADGET config

Quoted 3 lines · Andreas Kemnade

Add the separate IRQ handling function and change the registration.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom