Skip to contentSkip to conversation

usb: gadget: udc: atmel: assorted fixes

PATCH RESEND In review Michał Mirosław 3 participants 10 messages Jul 8, 2020 – Jul 16, 2020

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

cover usb: gadget: udc: atmel: assorted fixes

Two trivial fixes and .pullup implementation for Atmel UDC driver to make composite gadget happy when handling reconfiguration.

Michał Mirosław (3):
usb: gadget: udc: atmel: remove outdated comment in usba_ep_disable()
usb: gadget: udc: atmel: fix uninitialized read in debug printk
usb: gadget: udc: atmel: implement .pullup callback

 drivers/usb/gadget/udc/atmel_usba_udc.c | 30 ++++++++++++++++++-------
 1 file changed, 22 insertions(+), 8 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH RESEND 1/3 usb: gadget: udc: atmel: remove outdated comment in usba_ep_disable()

Fixed commit removed the offending behaviour from the driver, but missed the comment and associated test. Remove them now.

Fixes 38e58986e6fc ("usb: gadget: udc: atmel: don't disable enpdoints we don't own")
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/usb/gadget/udc/atmel_usba_udc.c +1 -7
index d69f61ff0181..9153e220848d 100644
@@ -676,13 +676,7 @@ static int usba_ep_disable(struct usb_ep *_ep)
 
 	if (!ep->ep.desc) {
 		spin_unlock_irqrestore(&udc->lock, flags);
-		/* REVISIT because this driver disables endpoints in
-		 * reset_all_endpoints() before calling disconnect(),
-		 * most gadget drivers would trigger this non-error ...
-		 */
-		if (udc->gadget.speed != USB_SPEED_UNKNOWN)
-			DBG(DBG_ERR, "ep_disable: %s not enabled\n",
-					ep->ep.name);
+		DBG(DBG_ERR, "ep_disable: %s not enabled\n", ep->ep.name);
 		return -EINVAL;
 	}
 	ep->ep.desc = NULL;
Signature · 1 line
2.20.1
maintainer Acked-by on v1 1/3
#2 lore raw

Re: [PATCH RESEND 1/3] usb: gadget: udc: atmel: remove outdated comment in usba_ep_disable()

Quoted 5 lines · Michał Mirosław

Fixed commit removed the offending behaviour from the driver, but missed the comment and associated test. Remove them now.

Fixes 38e58986e6fc ("usb: gadget: udc: atmel: don't disable enpdoints we don't own")
Quoted 26 lines
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/usb/gadget/udc/atmel_usba_udc.c +1 -7
index d69f61ff0181..9153e220848d 100644
@@ -676,13 +676,7 @@ static int usba_ep_disable(struct usb_ep *_ep)
 
 	if (!ep->ep.desc) {
 		spin_unlock_irqrestore(&udc->lock, flags);
-		/* REVISIT because this driver disables endpoints in
-		 * reset_all_endpoints() before calling disconnect(),
-		 * most gadget drivers would trigger this non-error ...
-		 */
-		if (udc->gadget.speed != USB_SPEED_UNKNOWN)
-			DBG(DBG_ERR, "ep_disable: %s not enabled\n",
-					ep->ep.name);
+		DBG(DBG_ERR, "ep_disable: %s not enabled\n", ep->ep.name);
 		return -EINVAL;
 	}
 	ep->ep.desc = NULL;
Signature · 1 line
2.20.1
Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
maintainer Acked-by
#3 lore raw

Re: [PATCH RESEND 1/3] usb: gadget: udc: atmel: remove outdated comment in usba_ep_disable()

Quoted 8 lines · Alexandre Belloni
Quoted 5 lines · Michał Mirosław

Fixed commit removed the offending behaviour from the driver, but missed the comment and associated test. Remove them now.

Fixes 38e58986e6fc ("usb: gadget: udc: atmel: don't disable enpdoints we don't own")
Quoted 33 lines
Quoted 25 lines
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/usb/gadget/udc/atmel_usba_udc.c +1 -8
index d69f61ff0181..9153e220848d 100644
@@ -676,13 +676,7 @@ static int usba_ep_disable(struct usb_ep *_ep)
 
      if (!ep->ep.desc) {
              spin_unlock_irqrestore(&udc->lock, flags);
-             /* REVISIT because this driver disables endpoints in
-              * reset_all_endpoints() before calling disconnect(),
-              * most gadget drivers would trigger this non-error ...
-              */
-             if (udc->gadget.speed != USB_SPEED_UNKNOWN)
-                     DBG(DBG_ERR, "ep_disable: %s not enabled\n",
-                                     ep->ep.name);
+             DBG(DBG_ERR, "ep_disable: %s not enabled\n", ep->ep.name);
              return -EINVAL;
      }
      ep->ep.desc = NULL;
--
Quoted 2 lines

2.20.1

--
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

#4 lore raw

PATCH RESEND 2/3 usb: gadget: udc: atmel: fix uninitialized read in debug printk

In reply to Michał Mirosław

Fixed commit moved the assignment of 'req', but did not update a reference in the DBG() call. Use the argument as it was renamed.

Fixes 5fb694f96e7c ("usb: gadget: udc: atmel: fix possible oops when unloading module")
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/udc/atmel_usba_udc.c +1 -1
index 9153e220848d..9342a3d24963 100644
@@ -865,7 +865,7 @@ static int usba_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 	u32 status;
 
 	DBG(DBG_GADGET | DBG_QUEUE, "ep_dequeue: %s, req %p\n",
-			ep->ep.name, req);
+			ep->ep.name, _req);
 
 	spin_lock_irqsave(&udc->lock, flags);
 
Signature · 1 line
2.20.1
maintainer Acked-by on v1 2/3
#5 lore raw

Re: [PATCH RESEND 2/3] usb: gadget: udc: atmel: fix uninitialized read in debug printk

Quoted 5 lines · Michał Mirosław

Fixed commit moved the assignment of 'req', but did not update a reference in the DBG() call. Use the argument as it was renamed.

Fixes 5fb694f96e7c ("usb: gadget: udc: atmel: fix possible oops when unloading module")
Quoted 20 lines
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/udc/atmel_usba_udc.c +1 -1
index 9153e220848d..9342a3d24963 100644
@@ -865,7 +865,7 @@ static int usba_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 	u32 status;
 
 	DBG(DBG_GADGET | DBG_QUEUE, "ep_dequeue: %s, req %p\n",
-			ep->ep.name, req);
+			ep->ep.name, _req);
 
 	spin_lock_irqsave(&udc->lock, flags);
 
Signature · 1 line
2.20.1
Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
maintainer Acked-by
#6 lore raw

Re: [PATCH RESEND 2/3] usb: gadget: udc: atmel: fix uninitialized read in debug printk

Quoted 9 lines · Alexandre Belloni

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 5 lines · Michał Mirosław

Fixed commit moved the assignment of 'req', but did not update a reference in the DBG() call. Use the argument as it was renamed.

Fixes 5fb694f96e7c ("usb: gadget: udc: atmel: fix possible oops when unloading module")
Quoted 27 lines
Quoted 19 lines
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/udc/atmel_usba_udc.c +1 -2
index 9153e220848d..9342a3d24963 100644
@@ -865,7 +865,7 @@ static int usba_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
      u32 status;
 
      DBG(DBG_GADGET | DBG_QUEUE, "ep_dequeue: %s, req %p\n",
-                     ep->ep.name, req);
+                     ep->ep.name, _req);
 
      spin_lock_irqsave(&udc->lock, flags);
 
--
Quoted 2 lines

2.20.1

--
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

#7 lore raw

PATCH RESEND 3/3 usb: gadget: udc: atmel: implement .pullup callback

In reply to Michał Mirosław

Implement udc->pullup callback, so that udc_connect/disconnect work. This is needed for composite gadget, as it assumes udc_disconnect() actually works and calls its ->disconnect callback.

---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/usb/gadget/udc/atmel_usba_udc.c +20 -0
index 9342a3d24963..c5128c229c52 100644
@@ -1028,6 +1028,7 @@ usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)
 	return 0;
 }
 
+static int atmel_usba_pullup(struct usb_gadget *gadget, int is_on);
 static int atmel_usba_start(struct usb_gadget *gadget,
 		struct usb_gadget_driver *driver);
 static int atmel_usba_stop(struct usb_gadget *gadget);
@@ -1101,6 +1102,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			= atmel_usba_pullup,
 	.udc_start		= atmel_usba_start,
 	.udc_stop		= atmel_usba_stop,
 	.match_ep		= atmel_usba_match_ep,
@@ -1957,6 +1959,24 @@ static irqreturn_t usba_vbus_irq_thread(int irq, void *devid)
 	return IRQ_HANDLED;
 }
 
+static int atmel_usba_pullup(struct usb_gadget *gadget, int is_on)
+{
+	struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget);
+	unsigned long flags;
+	u32 ctrl;
+
+	spin_lock_irqsave(&udc->lock, flags);
+	ctrl = usba_readl(udc, CTRL);
+	if (is_on)
+		ctrl &= ~USBA_DETACH;
+	else
+		ctrl |= USBA_DETACH;
+	usba_writel(udc, CTRL, ctrl);
+	spin_unlock_irqrestore(&udc->lock, flags);
+
+	return 0;
+}
+
 static int atmel_usba_start(struct usb_gadget *gadget,
 		struct usb_gadget_driver *driver)
 {
Signature · 1 line
2.20.1
maintainer Acked-by on v1 3/3
#8 lore raw

Re: [PATCH RESEND 3/3] usb: gadget: udc: atmel: implement .pullup callback

Quoted 5 lines · Michał Mirosław

Implement udc->pullup callback, so that udc_connect/disconnect work. This is needed for composite gadget, as it assumes udc_disconnect() actually works and calls its ->disconnect callback.

Quoted 52 lines
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/usb/gadget/udc/atmel_usba_udc.c +20 -0
index 9342a3d24963..c5128c229c52 100644
@@ -1028,6 +1028,7 @@ usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)
 	return 0;
 }
 
+static int atmel_usba_pullup(struct usb_gadget *gadget, int is_on);
 static int atmel_usba_start(struct usb_gadget *gadget,
 		struct usb_gadget_driver *driver);
 static int atmel_usba_stop(struct usb_gadget *gadget);
@@ -1101,6 +1102,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			= atmel_usba_pullup,
 	.udc_start		= atmel_usba_start,
 	.udc_stop		= atmel_usba_stop,
 	.match_ep		= atmel_usba_match_ep,
@@ -1957,6 +1959,24 @@ static irqreturn_t usba_vbus_irq_thread(int irq, void *devid)
 	return IRQ_HANDLED;
 }
 
+static int atmel_usba_pullup(struct usb_gadget *gadget, int is_on)
+{
+	struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget);
+	unsigned long flags;
+	u32 ctrl;
+
+	spin_lock_irqsave(&udc->lock, flags);
+	ctrl = usba_readl(udc, CTRL);
+	if (is_on)
+		ctrl &= ~USBA_DETACH;
+	else
+		ctrl |= USBA_DETACH;
+	usba_writel(udc, CTRL, ctrl);
+	spin_unlock_irqrestore(&udc->lock, flags);
+
+	return 0;
+}
+
 static int atmel_usba_start(struct usb_gadget *gadget,
 		struct usb_gadget_driver *driver)
 {
Signature · 1 line
2.20.1
Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
maintainer Acked-by
#9 lore raw

Re: [PATCH RESEND 3/3] usb: gadget: udc: atmel: implement .pullup callback

Quoted 8 lines · Alexandre Belloni
Quoted 5 lines · Michał Mirosław

Implement udc->pullup callback, so that udc_connect/disconnect work. This is needed for composite gadget, as it assumes udc_disconnect() actually works and calls its ->disconnect callback.

I checked the patch on sama5d2_xplained board and monitored the traffic with a sniffer. Everything looks good.

Quoted 59 lines
Quoted 51 lines
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/usb/gadget/udc/atmel_usba_udc.c +20 -1
index 9342a3d24963..c5128c229c52 100644
@@ -1028,6 +1028,7 @@ usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)
      return 0;
 }
 
+static int atmel_usba_pullup(struct usb_gadget *gadget, int is_on);
 static int atmel_usba_start(struct usb_gadget *gadget,
              struct usb_gadget_driver *driver);
 static int atmel_usba_stop(struct usb_gadget *gadget);
@@ -1101,6 +1102,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                 = atmel_usba_pullup,
      .udc_start              = atmel_usba_start,
      .udc_stop               = atmel_usba_stop,
      .match_ep               = atmel_usba_match_ep,
@@ -1957,6 +1959,24 @@ static irqreturn_t usba_vbus_irq_thread(int irq, void *devid)
      return IRQ_HANDLED;
 }
 
+static int atmel_usba_pullup(struct usb_gadget *gadget, int is_on)
+{
+     struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget);
+     unsigned long flags;
+     u32 ctrl;
+
+     spin_lock_irqsave(&udc->lock, flags);
+     ctrl = usba_readl(udc, CTRL);
+     if (is_on)
+             ctrl &= ~USBA_DETACH;
+     else
+             ctrl |= USBA_DETACH;
+     usba_writel(udc, CTRL, ctrl);
+     spin_unlock_irqrestore(&udc->lock, flags);
+
+     return 0;
+}
+
 static int atmel_usba_start(struct usb_gadget *gadget,
              struct usb_gadget_driver *driver)
 {
--
Quoted 2 lines

2.20.1

--
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com