Patchwork [U-Boot,06/17] usb: mv_udc: Make use of struct ehci_ctrl

login
register
mail settings
Submitter Marek Vasut
Date July 10, 2013, 1:16 a.m.
Message ID <1373419003-10919-7-git-send-email-marex@denx.de>
Download mbox | patch
Permalink /patch/257933/
State Awaiting Upstream
Delegated to: Marek Vasut
Headers show

Comments

Marek Vasut - July 10, 2013, 1:16 a.m.
The usb_lowlevel_init() call already fills and passes back struct
ehci_ctrl , which readily contains correctly determined address of
the port register block address computed from values from controller
configuration registers. Leverage this and make use of this value
as this makes the code mode universal, but also gets us rid of the
CONFIG_USB_REG_BASE configuration option.

Moreover, this patch cleans up the usb_gadget_register_driver() call
a little by correcting the error handling. Note the usb_lowlevel_init()
and mvudc_probe() are now called in reversed order, but this has no
impact on the code.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Lei Wen <leiwen@marvell.com>
Cc: Otavio Salvador <otavio@ossystems.com.br>
Cc: Stefano Babic <sbabic@denx.de>
---
 drivers/usb/gadget/mv_udc.c |   41 +++++++++++++++++++++++------------------
 include/usb/mv_udc.h        |    6 +++---
 2 files changed, 26 insertions(+), 21 deletions(-)

Patch

diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c
index 1164d74..fd3be77 100644
--- a/drivers/usb/gadget/mv_udc.c
+++ b/drivers/usb/gadget/mv_udc.c
@@ -134,7 +134,7 @@  static void mv_ep_free_request(struct usb_ep *ep, struct usb_request *_req)
 static void ep_enable(int num, int in)
 {
 	struct ept_queue_head *head;
-	struct mv_udc *udc = controller.udc;
+	struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor;
 	unsigned n;
 	head = epts + 2*num + in;
 
@@ -170,7 +170,7 @@  static int mv_ep_queue(struct usb_ep *ep,
 		struct usb_request *req, gfp_t gfp_flags)
 {
 	struct mv_ep *mv_ep = container_of(ep, struct mv_ep, ep);
-	struct mv_udc *udc = controller.udc;
+	struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor;
 	struct ept_queue_item *item;
 	struct ept_queue_head *head;
 	unsigned phys;
@@ -236,7 +236,7 @@  static void handle_ep_complete(struct mv_ep *ep)
 static void handle_setup(void)
 {
 	struct usb_request *req = &controller.ep[0].req;
-	struct mv_udc *udc = controller.udc;
+	struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor;
 	struct ept_queue_head *head;
 	struct usb_ctrlrequest r;
 	int status = 0;
@@ -309,7 +309,7 @@  static void stop_activity(void)
 {
 	int i, num, in;
 	struct ept_queue_head *head;
-	struct mv_udc *udc = controller.udc;
+	struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor;
 	writel(readl(&udc->epcomp), &udc->epcomp);
 	writel(readl(&udc->epstat), &udc->epstat);
 	writel(0xffffffff, &udc->epflush);
@@ -331,7 +331,7 @@  static void stop_activity(void)
 
 void udc_irq(void)
 {
-	struct mv_udc *udc = controller.udc;
+	struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor;
 	unsigned n = readl(&udc->usbsts);
 	writel(n, &udc->usbsts);
 	int bit, i, num, in;
@@ -389,7 +389,7 @@  void udc_irq(void)
 int usb_gadget_handle_interrupts(void)
 {
 	u32 value;
-	struct mv_udc *udc = controller.udc;
+	struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor;
 
 	value = readl(&udc->usbsts);
 	if (value)
@@ -400,7 +400,7 @@  int usb_gadget_handle_interrupts(void)
 
 static int mv_pullup(struct usb_gadget *gadget, int is_on)
 {
-	struct mv_udc *udc = controller.udc;
+	struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor;
 	if (is_on) {
 		/* RESET */
 		writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd);
@@ -428,7 +428,7 @@  static int mv_pullup(struct usb_gadget *gadget, int is_on)
 
 void udc_disconnect(void)
 {
-	struct mv_udc *udc = controller.udc;
+	struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor;
 	/* disable pullup */
 	stop_activity();
 	writel(USBCMD_FS2, &udc->usbcmd);
@@ -443,7 +443,6 @@  static int mvudc_probe(void)
 	int i;
 
 	controller.gadget.ops = &mv_udc_ops;
-	controller.udc = (struct mv_udc *)CONFIG_USB_REG_BASE;
 	epts = memalign(PAGE_SIZE, QH_MAXNUM * sizeof(struct ept_queue_head));
 	memset(epts, 0, QH_MAXNUM * sizeof(struct ept_queue_head));
 	for (i = 0; i < 2 * NUM_ENDPOINTS; i++) {
@@ -485,9 +484,8 @@  static int mvudc_probe(void)
 
 int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 {
-	struct mv_udc *udc = controller.udc;
-	int             retval;
-	void *ctrl;
+	struct mv_udc *udc;
+	int ret;
 
 	if (!driver
 			|| driver->speed < USB_SPEED_FULL
@@ -497,15 +495,22 @@  int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 		return -EINVAL;
 	}
 
-	if (!mvudc_probe()) {
-		usb_lowlevel_init(0, &ctrl);
+	ret = usb_lowlevel_init(0, (void **)&controller.ctrl);
+	if (ret)
+		return ret;
+
+	ret = mvudc_probe();
+	if (!ret) {
+		udc = (struct mv_udc *)controller.ctrl->hcor;
+
 		/* select ULPI phy */
 		writel(PTS(PTS_ENABLE) | PFSC, &udc->portsc);
 	}
-	retval = driver->bind(&controller.gadget);
-	if (retval) {
-		DBG("driver->bind() returned %d\n", retval);
-		return retval;
+
+	ret = driver->bind(&controller.gadget);
+	if (ret) {
+		DBG("driver->bind() returned %d\n", ret);
+		return ret;
 	}
 	controller.driver = driver;
 
diff --git a/include/usb/mv_udc.h b/include/usb/mv_udc.h
index 88100ce..9af9358 100644
--- a/include/usb/mv_udc.h
+++ b/include/usb/mv_udc.h
@@ -27,6 +27,8 @@ 
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 
+#include "../../drivers/usb/host/ehci.h"
+
 #define NUM_ENDPOINTS		6
 
 /* Endpoint parameters */
@@ -36,7 +38,6 @@ 
 #define EP0_MAX_PACKET_SIZE	64
 
 struct mv_udc {
-	u32 pad0[80];
 #define MICRO_8FRAME	0x8
 #define USBCMD_ITC(x)	((((x) > 0xff) ? 0xff : x) << 16)
 #define USBCMD_FS2	(1 << 15)
@@ -86,7 +87,7 @@  struct mv_ep {
 struct mv_drv {
 	struct usb_gadget		gadget;
 	struct usb_gadget_driver	*driver;
-	struct mv_udc			*udc;
+	struct ehci_ctrl		*ctrl;
 	struct mv_ep			ep[NUM_ENDPOINTS];
 };
 
@@ -134,5 +135,4 @@  struct ept_queue_item {
 #define INFO_BUFFER_ERROR	(1 << 5)
 #define INFO_TX_ERROR		(1 << 3)
 
-extern int usb_lowlevel_init(int index, void **controller);
 #endif /* __MV_UDC_H__ */