diff mbox series

[v2,3/4] usb: gadget: atmel: Add attach/detach support

Message ID 20240722202426.190986-4-zli@ogga.fr
State Superseded
Delegated to: Marek Vasut
Headers show
Series usb: gadget: atmel: Code refactor and DM_USB_GADGET support | expand

Commit Message

Zixun LI July 22, 2024, 8:23 p.m. UTC
Add controller attach/detach support by using
usb_gadget_ops.pullup() method.

Signed-off-by: Zixun LI <zli@ogga.fr>
---
 drivers/usb/gadget/atmel_usba_udc.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
diff mbox series

Patch

diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index 3e3c5cb403..46f7ae9a0c 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -1176,6 +1176,23 @@  static int usba_udc_disable(struct usba_udc *udc)
 	return 0;
 }
 
+static int usba_udc_pullup(struct usb_gadget *g, int is_on)
+{
+	struct usba_udc *udc = controller;
+	u32 ctrl;
+
+	ctrl = usba_readl(udc, CTRL);
+
+	if (is_on)
+		ctrl &= ~USBA_DETACH;
+	else
+		ctrl |= USBA_DETACH;
+
+	usba_writel(udc, CTRL, ctrl);
+
+	return 0;
+}
+
 int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 {
 	struct usba_udc *udc = controller;
@@ -1233,6 +1250,7 @@  static const struct usb_gadget_ops usba_udc_ops = {
 	.get_frame		= usba_udc_get_frame,
 	.wakeup			= usba_udc_wakeup,
 	.set_selfpowered	= usba_udc_set_selfpowered,
+	.pullup			= usba_udc_pullup,
 };
 
 static struct usba_udc udc_controller = {