mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/8] usb: gadget: fsl_udc: Drop using global variable
Date: Fri, 26 Oct 2018 11:33:31 +0200	[thread overview]
Message-ID: <20181026093338.22751-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20181026093338.22751-1-s.hauer@pengutronix.de>

No need to use the global udc_controller variable when we are provided
an usb_gadget.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/gadget/fsl_udc.c | 39 ++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc.c b/drivers/usb/gadget/fsl_udc.c
index 9b59669773..7782d4bdd9 100644
--- a/drivers/usb/gadget/fsl_udc.c
+++ b/drivers/usb/gadget/fsl_udc.c
@@ -450,6 +450,11 @@ struct fsl_udc {
 	u8 device_address;	/* Device USB address */
 };
 
+static inline struct fsl_udc *to_fsl_udc(struct usb_gadget *gadget)
+{
+	return container_of(gadget, struct fsl_udc, gadget);
+}
+
 /*-------------------------------------------------------------------------*/
 
 #ifdef DEBUG
@@ -1943,12 +1948,9 @@ static void dtd_complete_irq(struct fsl_udc *udc)
  */
 static void fsl_udc_gadget_poll(struct usb_gadget *gadget)
 {
-	struct fsl_udc *udc = udc_controller;
+	struct fsl_udc *udc = to_fsl_udc(gadget);
 	u32 irq_src;
 
-	if (!udc)
-		return;
-
 	/* Disable ISR for OTG host mode */
 	if (udc->stopped)
 		return;
@@ -1981,7 +1983,7 @@ static void fsl_udc_gadget_poll(struct usb_gadget *gadget)
 
 	/* Sleep Enable (Suspend) */
 	if (irq_src & USB_STS_SUSPEND)
-		udc->driver->disconnect(&udc_controller->gadget);
+		udc->driver->disconnect(gadget);
 
 	if (irq_src & (USB_STS_ERR | USB_STS_SYS_ERR))
 		printf("Error IRQ %x\n", irq_src);
@@ -1993,6 +1995,8 @@ static void fsl_udc_gadget_poll(struct usb_gadget *gadget)
 *----------------------------------------------------------------*/
 static int fsl_udc_start(struct usb_gadget *gadget, struct usb_gadget_driver *driver)
 {
+	struct fsl_udc *udc = to_fsl_udc(gadget);
+
 	/*
 	 * We currently have PHY no driver which could call vbus_connect,
 	 * so when the USB gadget core calls usb_gadget_connect() the
@@ -2002,13 +2006,13 @@ static int fsl_udc_start(struct usb_gadget *gadget, struct usb_gadget_driver *dr
 	usb_gadget_vbus_connect(gadget);
 
 	/* hook up the driver */
-	udc_controller->driver = driver;
+	udc->driver = driver;
 
 	/* Enable DR IRQ reg and Set usbcmd reg  Run bit */
-	dr_controller_run(udc_controller);
-	udc_controller->usb_state = USB_STATE_ATTACHED;
-	udc_controller->ep0_state = WAIT_FOR_SETUP;
-	udc_controller->ep0_dir = 0;
+	dr_controller_run(udc);
+	udc->usb_state = USB_STATE_ATTACHED;
+	udc->ep0_state = WAIT_FOR_SETUP;
+	udc->ep0_dir = 0;
 
 	return 0;
 }
@@ -2016,20 +2020,21 @@ static int fsl_udc_start(struct usb_gadget *gadget, struct usb_gadget_driver *dr
 /* Disconnect from gadget driver */
 static int fsl_udc_stop(struct usb_gadget *gadget, struct usb_gadget_driver *driver)
 {
+	struct fsl_udc *udc = to_fsl_udc(gadget);
 	struct fsl_ep *loop_ep;
 
 	/* stop DR, disable intr */
-	dr_controller_stop(udc_controller);
+	dr_controller_stop(udc);
 
 	/* in fact, no needed */
-	udc_controller->usb_state = USB_STATE_ATTACHED;
-	udc_controller->ep0_state = WAIT_FOR_SETUP;
-	udc_controller->ep0_dir = 0;
+	udc->usb_state = USB_STATE_ATTACHED;
+	udc->ep0_state = WAIT_FOR_SETUP;
+	udc->ep0_dir = 0;
 
 	/* stand operation */
-	udc_controller->gadget.speed = USB_SPEED_UNKNOWN;
-	nuke(&udc_controller->eps[0], -ESHUTDOWN);
-	list_for_each_entry(loop_ep, &udc_controller->gadget.ep_list,
+	udc->gadget.speed = USB_SPEED_UNKNOWN;
+	nuke(&udc->eps[0], -ESHUTDOWN);
+	list_for_each_entry(loop_ep, &udc->gadget.ep_list,
 			ep.ep_list)
 		nuke(loop_ep, -ESHUTDOWN);
 
-- 
2.19.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2018-10-26  9:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-26  9:33 [PATCH 0/8] USB ehci/chipidea fixes Sascha Hauer
2018-10-26  9:33 ` Sascha Hauer [this message]
2018-10-26  9:33 ` [PATCH 2/8] usb: host: ehci: rename ehci_priv to ehci_host Sascha Hauer
2018-10-26  9:33 ` [PATCH 3/8] usb: Add usb_unregister_host() Sascha Hauer
2018-10-26  9:33 ` [PATCH 4/8] usb: host: ehci: add ehci_unregister() Sascha Hauer
2018-10-26  9:33 ` [PATCH 5/8] usb: host: ehci: do not use dev->priv Sascha Hauer
2018-10-26  9:33 ` [PATCH 6/8] usb: host: ehci-atmel: unregister host on device remove Sascha Hauer
2018-10-26  9:33 ` [PATCH 7/8] usb: imx: unregister ehci controller on device removal Sascha Hauer
2018-10-26  9:33 ` [PATCH 8/8] usb: gadget: fsl_udc: pass controller instance to unregister Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181026093338.22751-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox