Re: [PATCH 08/28] usb: musb: pass fifo_mode from hw glue driver

Previous thread: Re: FTDI-SIO hang on ftdi_close() by Alan Stern on Saturday, December 11, 2010 - 1:20 pm. (2 messages)

Next thread: Re: [PATCH 21/28] usb: musb: print dma type in runtime way by David Brownell on Sunday, December 12, 2010 - 12:53 pm. (2 messages)
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

This patches remove dependency on the following option in
musb driver:

	CONFIG_USB_MUSB_OMAP2PLUS
	CONFIG_USB_MUSB_TUSB6010
	CONFIG_USB_MUSB_AM35X
	USB_MUSB_DAVINCI
	USB_MUSB_DA8XX	

also remove the dma controller related options below from
musb source code, and only keep very few of them in header file:
	CONFIG_USB_INVENTRA_DMA
	CONFIG_USB_TUSB_OMAP_DMA
	CONFIG_USB_TI_CPPI_DMA

so musb driver source code is more clean than before, :-).

The patch set makes full use of the hw glue layer implemented
by Felipe.

Since all the specific hardwares related option are removed now,
we can build one single musb driver(binary) to make it working
on multiple machines of same ARCH.

Also the patches support the features below:
	- each glue driver can be compiled as one standalone module
	- each dma controler driver can be compiler as one standalone module

The patch set has been tested on beagle xM, g_ether/g_zero are OK
even both OMAP2PLUS, TUSB6010 and AM35X are enabled and the three
modules are built in one image at the same time.


--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

This patch introduces get_hw_revision callback in glue_ops,
and implement it in tusb glue driver, so tusb dma code can
get tusb revision via .get_hw_revision callback and we can
make glue drivers built as module easyly in later patches.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.h     |    3 +++
 drivers/usb/musb/tusb6010.c      |    2 ++
 drivers/usb/musb/tusb6010_omap.c |    3 ++-
 3 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index b9ea563..5843810 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -259,6 +259,7 @@ enum musb_g_ep0_state {
  * @exit:	undoes @init
  * @set_mode:	forcefully changes operating mode
  * @try_ilde:	tries to idle the IP
+ * @get_hw_revision: get hardware revision
  * @vbus_status: returns vbus status if possible
  * @set_vbus:	forces vbus status
  */
@@ -272,6 +273,8 @@ struct musb_platform_ops {
 	int	(*set_mode)(struct musb *musb, u8 mode);
 	void	(*try_idle)(struct musb *musb, unsigned long timeout);
 
+	u8  (*get_hw_revision)(struct musb *musb);
+
 	int	(*vbus_status)(struct musb *musb);
 	void	(*set_vbus)(struct musb *musb, int on);
 };
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index c891843..b29ecd8 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -1173,6 +1173,8 @@ static const struct musb_platform_ops tusb_ops = {
 	.set_mode	= tusb_musb_set_mode,
 	.try_idle	= tusb_musb_try_idle,
 
+	.get_hw_revision	= tusb_get_revision,
+
 	.vbus_status	= tusb_musb_vbus_status,
 	.set_vbus	= tusb_musb_set_vbus,
 };
diff --git a/drivers/usb/musb/tusb6010_omap.c b/drivers/usb/musb/tusb6010_omap.c
index c061a88..7403bfd 100644
--- a/drivers/usb/musb/tusb6010_omap.c
+++ b/drivers/usb/musb/tusb6010_omap.c
@@ -696,7 +696,8 @@ dma_controller_create(struct musb *musb, void __iomem *base)
 ...
From: Felipe Balbi
Date: Monday, December 13, 2010 - 1:10 am

put a static inline on the header, don't access the point directly.
Also, musb can have a generic get_hw_revision().

-- 
balbi
--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

This patch introduces get_hw_revision callback in glue_ops,
and implement it in tusb glue driver, so tusb dma code can
get tusb revision via .get_hw_revision callback and we can
make glue drivers built as module easyly in later patches.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.h     |    3 +++
 drivers/usb/musb/tusb6010.c      |    2 ++
 drivers/usb/musb/tusb6010_omap.c |    3 ++-
 3 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index b9ea563..5843810 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -259,6 +259,7 @@ enum musb_g_ep0_state {
  * @exit:	undoes @init
  * @set_mode:	forcefully changes operating mode
  * @try_ilde:	tries to idle the IP
+ * @get_hw_revision: get hardware revision
  * @vbus_status: returns vbus status if possible
  * @set_vbus:	forces vbus status
  */
@@ -272,6 +273,8 @@ struct musb_platform_ops {
 	int	(*set_mode)(struct musb *musb, u8 mode);
 	void	(*try_idle)(struct musb *musb, unsigned long timeout);
 
+	u8  (*get_hw_revision)(struct musb *musb);
+
 	int	(*vbus_status)(struct musb *musb);
 	void	(*set_vbus)(struct musb *musb, int on);
 };
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index c891843..b29ecd8 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -1173,6 +1173,8 @@ static const struct musb_platform_ops tusb_ops = {
 	.set_mode	= tusb_musb_set_mode,
 	.try_idle	= tusb_musb_try_idle,
 
+	.get_hw_revision	= tusb_get_revision,
+
 	.vbus_status	= tusb_musb_vbus_status,
 	.set_vbus	= tusb_musb_set_vbus,
 };
diff --git a/drivers/usb/musb/tusb6010_omap.c b/drivers/usb/musb/tusb6010_omap.c
index c061a88..7403bfd 100644
--- a/drivers/usb/musb/tusb6010_omap.c
+++ b/drivers/usb/musb/tusb6010_omap.c
@@ -696,7 +696,8 @@ dma_controller_create(struct musb *musb, void __iomem *base)
 ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

Export this functions so that glue drivers can see them if glue drivers
are built as modules.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 2bbf911..070725f 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -116,6 +116,7 @@
 
 
 unsigned musb_debug;
+EXPORT_SYMBOL(musb_debug);
 module_param_named(debug, musb_debug, uint, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(debug, "Debug message level. Default = 0");
 
@@ -271,6 +272,7 @@ void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
 		writesb(fifo, src, len);
 	}
 }
+EXPORT_SYMBOL(musb_write_fifo);
 
 #if !defined(CONFIG_USB_MUSB_AM35X)
 /*
@@ -310,6 +312,7 @@ void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
 		readsb(fifo, dst, len);
 	}
 }
+EXPORT_SYMBOL(musb_read_fifo);
 #endif
 
 #endif	/* normal PIO */
@@ -368,6 +371,7 @@ const char *otg_state_string(struct musb *musb)
 	default:			return "UNDEFINED";
 	}
 }
+EXPORT_SYMBOL(otg_state_string);
 
 #ifdef	CONFIG_USB_MUSB_OTG
 
@@ -1654,7 +1658,7 @@ irqreturn_t musb_interrupt(struct musb *musb)
 
 	return retval;
 }
-
+EXPORT_SYMBOL(musb_interrupt);
 
 #ifndef CONFIG_MUSB_PIO_ONLY
 static int __initdata use_dma = 1;
@@ -1701,6 +1705,7 @@ void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
 		}
 	}
 }
+EXPORT_SYMBOL(musb_dma_completion);
 
 #else
 #define use_dma			0
-- 
1.7.3

--

From: Felipe Balbi
Date: Monday, December 13, 2010 - 1:10 am

change all these to EXPORT_SYMBOL_GPL() is glue layer isn't GPL we don't
want it.

-- 
balbi
--

From: Felipe Balbi
Date: Monday, December 13, 2010 - 2:02 am

BTW, changing all DBG() to dev_dbg() on hw glue layer already kills most
of the complaints. I think it's better to say musb-omap2430 than
musb-hdrc on debug messages comming for omap2430.c as it's a better hint
of where the problem is.

otg_state_string() will be generalized soon with a patchset that's been
sent already, so most of the problems are killed.

I'm also not sure we want to build glue layer as module, it's just a
glue layer anyway, and instead of users just modprobe musb_hdrc they'll
have to modprobe musb-omap2430 && modprobe musb_hdrc, on that order
otherwise it doesn't work. So keep glue layer as bool, and the same
"behavior" is kept. That means a simple change to drivers/Makefile would
be enough. Something like:

diff --git a/drivers/Makefile b/drivers/Makefile
index 14cf907..9c66677 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -65,7 +65,7 @@ obj-$(CONFIG_TC)              += tc/
  obj-$(CONFIG_UWB)              += uwb/
  obj-$(CONFIG_USB_OTG_UTILS)    += usb/otg/
  obj-$(CONFIG_USB)              += usb/
-obj-$(CONFIG_USB_MUSB_HDRC)    += usb/musb/
+obj-$(CONFIG_USB_MUSB)         += usb/musb/
  obj-$(CONFIG_PCI)              += usb/
  obj-$(CONFIG_USB_GADGET)       += usb/gadget/
  obj-$(CONFIG_SERIO)            += input/serio/
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 4cbb7e4..98c0dc9 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -6,6 +6,9 @@
  comment "Enable Host or Gadget support to see Inventra options"
         depends on !USB && USB_GADGET=n
  
+config USB_MUSB
+       bool
+
  # (M)HDRC = (Multipoint) Highspeed Dual-Role Controller
  config USB_MUSB_HDRC
         depends on (USB || USB_GADGET)
@@ -14,6 +17,7 @@ config USB_MUSB_HDRC
         select TWL4030_USB if MACH_OMAP_3430SDP
         select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA
         select USB_OTG_UTILS
+       select USB_MUSB
         tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...
From: Felipe Balbi
Date: Monday, December 13, 2010 - 2:53 am

not so trivial wrt IRQ, but maybe something like below will work for all
cases?

diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index d5a3da3..e69c233 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -219,19 +219,15 @@ static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout)
  	mod_timer(&otg_workaround, timeout);
  }
  
-static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
+static int am35x_musb_interrupt(struct musb *musb)
  {
-	struct musb  *musb = hci;
  	void __iomem *reg_base = musb->ctrl_base;
  	struct device *dev = musb->controller;
  	struct musb_hdrc_platform_data *plat = dev->platform_data;
  	struct omap_musb_board_data *data = plat->board_data;
-	unsigned long flags;
  	irqreturn_t ret = IRQ_NONE;
  	u32 epintr, usbintr;
  
-	spin_lock_irqsave(&musb->lock, flags);
-
  	/* Get endpoint interrupts */
  	epintr = musb_readl(reg_base, EP_INTR_SRC_MASKED_REG);
  
@@ -255,6 +251,7 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
  		musb->int_usb =
  			(usbintr & AM35X_INTR_USB_MASK) >> AM35X_INTR_USB_SHIFT;
  	}
+
  	/*
  	 * DRVVBUS IRQs are the only proxy we have (a very poor one!) for
  	 * AM35x's missing ID change IRQ.  We need an ID change IRQ to
@@ -310,9 +307,6 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
  		ret = IRQ_HANDLED;
  	}
  
-	if (musb->int_tx || musb->int_rx || musb->int_usb)
-		ret |= musb_interrupt(musb);
-
  eoi:
  	/* EOI needs to be written for the IRQ to be re-asserted. */
  	if (ret == IRQ_HANDLED || epintr || usbintr) {
@@ -327,8 +321,6 @@ eoi:
  	if (is_otg_enabled(musb) && musb->xceiv->state == OTG_STATE_B_IDLE)
  		mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
  
-	spin_unlock_irqrestore(&musb->lock, flags);
-
  	return ret;
  }
  
@@ -383,8 +375,6 @@ static int am35x_musb_init(struct musb *musb)
  
  	msleep(5);
  
-	musb->isr = am35x_musb_interrupt;
-
  	/* clear level interrupt */
  	if ...
From: Ming Lei
Date: Monday, December 13, 2010 - 4:46 am

No, only modprobe musb-omap2430 is enough, which has been OK now in
my beagle with this patch set.

If we want to run one single binary to support multiple machines and
if glue driver can't be built as module, we have to load all glue driver into
ram, which is sure very ugly.

If glue driver can depend on musb_hdrc,  we can make musb_hdrc
more generic to export this kind of generic functions, which may be



-- 
Lei Ming
--

From: Felipe Balbi
Date: Monday, December 13, 2010 - 5:00 am

Hi,


glue layer's probe() won't be called as musb-XXXX won't be available. So
no resources will be used, right ?

-- 
balbi
--

From: Ming Lei
Date: Monday, December 13, 2010 - 5:17 am

Yes, seems it should be, :-)

musb-XXXX is created by arch/xx/mach-yy, so if there is no musb-XXXX,
glue layer's probe() won't be called, then musb_hdrc's probe() can't be called
too.

Above should be reasonable and correct, right?

-- 
Lei Ming
--

From: Ming Lei
Date: Monday, December 13, 2010 - 5:31 am

It is right, but the glue code without device may consume some memory and
does nothing since it have to be loaded always.

If we can build glue layer driver as module, it will be loaded until there has
the musb-XXXX device. So I think we should support to build glue driver
as module to reduce memory footprint.

see size of glue modules built with this patch set in my beagle-xm:

-rw-rw-r--    1 500      500        132068 Dec 13  2010 am35x.ko
-rw-rw-r--    1 500      500        135279 Dec 13  2010 omap2430.ko
-rw-rw-r--    1 500      500        152696 Dec 13  2010 tusb6010.ko

-- 
Lei Ming
--

From: Felipe Balbi
Date: Monday, December 13, 2010 - 6:05 am

that's all on .init.text section, no ?!? then it'll be freed after we're
out of initcalls.

-- 
balbi
--

From: Ming Lei
Date: Monday, December 13, 2010 - 6:15 am

No, only very few function/variables of glue driver is declared
as __init, and is in .init section. Others will still stay in ram for ever.

-- 
Lei Ming
--

From: Felipe Balbi
Date: Monday, December 13, 2010 - 6:19 am

Hi,


But what's the problem ? We want a single binary for several glue layers
of same ARCH anyway. When building products, device makers will
optimize what they think needs to be optimized, counting removing unused
drivers from kernel configuration.

On a distro-like kernel we will have all of that configured to work.
Which is the same in both approaches (glue built-in or as module), the
difference is that there's not behavior change for users which have been
issuing 'modprobe musb_hdrc' since it has been added to mainline. OTOH,
if we change glue layers to modules, users will have to remember that
now they're running omap2plus boards and they have to type modprobe
musb-omap2430, instead of modprobe musb_hdrc.

See the problem ? We have a false abstraction as user has to know which
glue layer to load.

Users will never issue 'modprobe ehci-omap' they run 'modprobe
ehci-hcd'.

-- 
balbi
--

From: Ming Lei
Date: Monday, December 13, 2010 - 6:26 am

In fact, user doesn't need to issue all modprobe things in theroy, :-)

-- 
Lei Ming
--

From: Felipe Balbi
Date: Monday, December 13, 2010 - 6:36 am

there are systems which don't use udev :-)

-- 
balbi
--

From: Greg KH
Date: Monday, December 13, 2010 - 9:42 am

And do they also expect to automatically load the proper drivers for any
device that is randomly plugged in?

No, they don't, so relying on udev to handle module loading is fine,
that's what the rest of the kernel does today.

thanks,

greg k-h
--

From: Ming Lei
Date: Sunday, December 19, 2010 - 7:35 am

Hi,



Seems many DBG in irq path, and simply changing all DBG in glue driver
to dev_dbg may cause debug messages flood if debug is enabled, so could
we not do it at least now?

thanks,
-- 
Lei Ming
--

From: Felipe Balbi
Date: Monday, December 20, 2010 - 12:30 am

Don't change to dev_dbg() on IRQ path, only on glue layer. Then we will
have to export musb_debug for the IRQ path. Although I think
musb_interrupt() should not be exported. It should only rely on glue
code to setup musb->int_usb/int_rx/int_tx field correctly. Then, if
needed, also clear IRQ, like it's needed with am35x.

-- 
balbi
--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

Obviously hw glue layer driver should be compiled as module,
which can help to build one single image to support multiple machines.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/Kconfig  |   62 ++++++++++++++++++++++++++++++++-------------
 drivers/usb/musb/Makefile |   12 ++++----
 2 files changed, 50 insertions(+), 24 deletions(-)

diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 2250b91..5e0a5e8 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -36,31 +36,57 @@ choice
 	prompt "Platform Glue Layer"
 	depends on USB_MUSB_HDRC
 
-config USB_MUSB_DAVINCI
-	bool "DaVinci"
-	depends on ARCH_DAVINCI_DMx
+config USB_MUSB_DAVINCI_GLUE
+	select USB_MUSB_DAVINCI
+	tristate "DaVinci"
+	depends on ARCH_DAVINCI_DMx && USB_MUSB_HDRC
+
+config USB_MUSB_DA8XX_GLUE
+	select USB_MUSB_DA8XX
+	tristate "DA8xx/OMAP-L1x"
+	depends on ARCH_DAVINCI_DA8XX && USB_MUSB_HDRC
+
+config USB_MUSB_TUSB6010_GLUE
+	select USB_MUSB_TUSB6010
+	tristate "TUSB6010"
+	depends on ARCH_OMAP && USB_MUSB_HDRC
+
+config USB_MUSB_OMAP2PLUS_GLUE
+	select USB_MUSB_OMAP2PLUS
+	tristate "OMAP2430 and onwards"
+	depends on ARCH_OMAP2PLUS && USB_MUSB_HDRC
+
+config USB_MUSB_AM35X_GLUE
+	select USB_MUSB_AM35X
+	tristate "AM35x"
+	depends on ARCH_OMAP && USB_MUSB_HDRC
+
+config USB_MUSB_BLACKFIN_GLUE
+	select USB_MUSB_BLACKFIN
+	tristate "Blackfin"
+	depends on (BF54x && !BF544) || (BF52x && ! BF522 && !BF523)
 
-config USB_MUSB_DA8XX
-	bool "DA8xx/OMAP-L1x"
-	depends on ARCH_DAVINCI_DA8XX
+endchoice
 
+config USB_MUSB_DAVINCI
+	bool
+	default n
+config USB_MUSB_DA8XX
+	bool
+	default n
 config USB_MUSB_TUSB6010
-	bool "TUSB6010"
-	depends on ARCH_OMAP
-
+	bool
+	default n
 config USB_MUSB_OMAP2PLUS
-	bool "OMAP2430 and onwards"
-	depends on ARCH_OMAP2PLUS
-
+	bool
+	default n
 config USB_MUSB_AM35X
-	bool "AM35x"
-	depends on ARCH_OMAP
-
+	bool
+	default n
 config ...
From: Felipe Balbi
Date: Monday, December 13, 2010 - 1:11 am

just change the original to tristate.

-- 
balbi
--

From: Ming Lei
Date: Monday, December 13, 2010 - 3:28 am

Many files in arch/arm/mach-* depend them, so I keep this option
as 'bool' to avoid arch tree involved in the patches since 'tristate'
may add "_MODULE" to the option name.

-- 
Lei Ming
--

From: Felipe Balbi
Date: Monday, December 13, 2010 - 3:44 am

true, good point. We can use what you suggest then.

-- 
balbi
--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

Export this functions so that glue drivers can see them if glue drivers
are built as modules.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 2bbf911..070725f 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -116,6 +116,7 @@
 
 
 unsigned musb_debug;
+EXPORT_SYMBOL(musb_debug);
 module_param_named(debug, musb_debug, uint, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(debug, "Debug message level. Default = 0");
 
@@ -271,6 +272,7 @@ void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
 		writesb(fifo, src, len);
 	}
 }
+EXPORT_SYMBOL(musb_write_fifo);
 
 #if !defined(CONFIG_USB_MUSB_AM35X)
 /*
@@ -310,6 +312,7 @@ void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
 		readsb(fifo, dst, len);
 	}
 }
+EXPORT_SYMBOL(musb_read_fifo);
 #endif
 
 #endif	/* normal PIO */
@@ -368,6 +371,7 @@ const char *otg_state_string(struct musb *musb)
 	default:			return "UNDEFINED";
 	}
 }
+EXPORT_SYMBOL(otg_state_string);
 
 #ifdef	CONFIG_USB_MUSB_OTG
 
@@ -1654,7 +1658,7 @@ irqreturn_t musb_interrupt(struct musb *musb)
 
 	return retval;
 }
-
+EXPORT_SYMBOL(musb_interrupt);
 
 #ifndef CONFIG_MUSB_PIO_ONLY
 static int __initdata use_dma = 1;
@@ -1701,6 +1705,7 @@ void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
 		}
 	}
 }
+EXPORT_SYMBOL(musb_dma_completion);
 
 #else
 #define use_dma			0
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

This patch introduces read_fifo/write_fifo callback in glue ops,
so that we can make musb in one single images working on multiple
boards.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 5843810..bfbd72e 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -262,6 +262,8 @@ enum musb_g_ep0_state {
  * @get_hw_revision: get hardware revision
  * @vbus_status: returns vbus status if possible
  * @set_vbus:	forces vbus status
+ * @read_fifo: read data from musb fifo in PIO
+ * @write_fifo: write data into musb fifo in PIO
  */
 struct musb_platform_ops {
 	int	(*init)(struct musb *musb);
@@ -277,6 +279,8 @@ struct musb_platform_ops {
 
 	int	(*vbus_status)(struct musb *musb);
 	void	(*set_vbus)(struct musb *musb, int on);
+	void (*read_fifo)(struct musb_hw_ep *hw_ep, u16 len, u8 *buf);
+	void (*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf);
 };
 
 /*
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

Obviously hw glue layer driver should be compiled as module,
which can help to build one single image to support multiple machines.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/Kconfig  |   62 ++++++++++++++++++++++++++++++++-------------
 drivers/usb/musb/Makefile |   12 ++++----
 2 files changed, 50 insertions(+), 24 deletions(-)

diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 2250b91..5e0a5e8 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -36,31 +36,57 @@ choice
 	prompt "Platform Glue Layer"
 	depends on USB_MUSB_HDRC
 
-config USB_MUSB_DAVINCI
-	bool "DaVinci"
-	depends on ARCH_DAVINCI_DMx
+config USB_MUSB_DAVINCI_GLUE
+	select USB_MUSB_DAVINCI
+	tristate "DaVinci"
+	depends on ARCH_DAVINCI_DMx && USB_MUSB_HDRC
+
+config USB_MUSB_DA8XX_GLUE
+	select USB_MUSB_DA8XX
+	tristate "DA8xx/OMAP-L1x"
+	depends on ARCH_DAVINCI_DA8XX && USB_MUSB_HDRC
+
+config USB_MUSB_TUSB6010_GLUE
+	select USB_MUSB_TUSB6010
+	tristate "TUSB6010"
+	depends on ARCH_OMAP && USB_MUSB_HDRC
+
+config USB_MUSB_OMAP2PLUS_GLUE
+	select USB_MUSB_OMAP2PLUS
+	tristate "OMAP2430 and onwards"
+	depends on ARCH_OMAP2PLUS && USB_MUSB_HDRC
+
+config USB_MUSB_AM35X_GLUE
+	select USB_MUSB_AM35X
+	tristate "AM35x"
+	depends on ARCH_OMAP && USB_MUSB_HDRC
+
+config USB_MUSB_BLACKFIN_GLUE
+	select USB_MUSB_BLACKFIN
+	tristate "Blackfin"
+	depends on (BF54x && !BF544) || (BF52x && ! BF522 && !BF523)
 
-config USB_MUSB_DA8XX
-	bool "DA8xx/OMAP-L1x"
-	depends on ARCH_DAVINCI_DA8XX
+endchoice
 
+config USB_MUSB_DAVINCI
+	bool
+	default n
+config USB_MUSB_DA8XX
+	bool
+	default n
 config USB_MUSB_TUSB6010
-	bool "TUSB6010"
-	depends on ARCH_OMAP
-
+	bool
+	default n
 config USB_MUSB_OMAP2PLUS
-	bool "OMAP2430 and onwards"
-	depends on ARCH_OMAP2PLUS
-
+	bool
+	default n
 config USB_MUSB_AM35X
-	bool "AM35x"
-	depends on ARCH_OMAP
-
+	bool
+	default n
 config ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

This patch uses native read_fifo/write_fifo for each hw glue driver.
Musb core can always use musb->ops->*_fifo to do PIO, also removes
some ugly ifdef for musb_read_fifo/musb_write_fifo.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/am35x.c           |    5 ++++-
 drivers/usb/musb/blackfin.c        |    7 +++++--
 drivers/usb/musb/da8xx.c           |    3 +++
 drivers/usb/musb/davinci.c         |    3 +++
 drivers/usb/musb/musb_core.c       |   11 +----------
 drivers/usb/musb/musb_gadget.c     |    4 ++--
 drivers/usb/musb/musb_gadget_ep0.c |    8 ++++----
 drivers/usb/musb/musb_host.c       |   10 +++++-----
 drivers/usb/musb/omap2430.c        |    3 +++
 drivers/usb/musb/tusb6010.c        |    6 ++++--
 drivers/usb/musb/tusb6010_omap.c   |    4 ++--
 11 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index d5a3da3..6ab6ed2 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -412,7 +412,7 @@ static int am35x_musb_exit(struct musb *musb)
 }
 
 /* AM35x supports only 32bit read operation */
-void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
+static void am35x_musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
 {
 	void __iomem *fifo = hw_ep->fifo;
 	u32		val;
@@ -452,6 +452,9 @@ static const struct musb_platform_ops am35x_ops = {
 	.try_idle	= am35x_musb_try_idle,
 
 	.set_vbus	= am35x_musb_set_vbus,
+
+	.read_fifo  = am35x_musb_read_fifo,
+	.write_fifo = musb_write_fifo,
 };
 
 static u64 am35x_dmamask = DMA_BIT_MASK(32);
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index c6d3818..6d61349 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -32,7 +32,7 @@ struct bfin_glue {
 /*
  * Load an endpoint's FIFO
  */
-void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
+static void bfin_musb_write_fifo(struct musb_hw_ep ...
From: Felipe Balbi
Date: Monday, December 13, 2010 - 1:13 am

Hi,


no direct access, put the static inline on the header file. There's a
generic read/write fifo too.

-- 
balbi
--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

This patch introduces read_fifo/write_fifo callback in glue ops,
so that we can make musb in one single images working on multiple
boards.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 5843810..bfbd72e 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -262,6 +262,8 @@ enum musb_g_ep0_state {
  * @get_hw_revision: get hardware revision
  * @vbus_status: returns vbus status if possible
  * @set_vbus:	forces vbus status
+ * @read_fifo: read data from musb fifo in PIO
+ * @write_fifo: write data into musb fifo in PIO
  */
 struct musb_platform_ops {
 	int	(*init)(struct musb *musb);
@@ -277,6 +279,8 @@ struct musb_platform_ops {
 
 	int	(*vbus_status)(struct musb *musb);
 	void	(*set_vbus)(struct musb *musb, int on);
+	void (*read_fifo)(struct musb_hw_ep *hw_ep, u16 len, u8 *buf);
+	void (*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf);
 };
 
 /*
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

This patch introduces flags field into musb_platform_ops,
so we can handle hw glue difference in musb core driver
from the information of .flags, then we can remove the
ugly macros of hw glue related to help to make one image
working for multiple machines in later patches.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 6667fa2..38d6a6e 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -256,6 +256,7 @@ enum musb_g_ep0_state {
 /**
  * struct musb_platform_ops - Operations passed to musb_core by HW glue layer
  * @fifo_mode: which fifo_mode is taken by me
+ * @flags	 : each hw glue difference information will be here
  * @init:	turns on clocks, sets up platform-specific registers, etc
  * @exit:	undoes @init
  * @set_mode:	forcefully changes operating mode
@@ -268,6 +269,7 @@ enum musb_g_ep0_state {
  */
 struct musb_platform_ops {
 	short	fifo_mode;
+	unsigned short	flags;
 	int	(*init)(struct musb *musb);
 	int	(*exit)(struct musb *musb);
 
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

This patch introduces flags field into musb_platform_ops,
so we can handle hw glue difference in musb core driver
from the information of .flags, then we can remove the
ugly macros of hw glue related to help to make one image
working for multiple machines in later patches.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 6667fa2..38d6a6e 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -256,6 +256,7 @@ enum musb_g_ep0_state {
 /**
  * struct musb_platform_ops - Operations passed to musb_core by HW glue layer
  * @fifo_mode: which fifo_mode is taken by me
+ * @flags	 : each hw glue difference information will be here
  * @init:	turns on clocks, sets up platform-specific registers, etc
  * @exit:	undoes @init
  * @set_mode:	forcefully changes operating mode
@@ -268,6 +269,7 @@ enum musb_g_ep0_state {
  */
 struct musb_platform_ops {
 	short	fifo_mode;
+	unsigned short	flags;
 	int	(*init)(struct musb *musb);
 	int	(*exit)(struct musb *musb);
 
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

This patch allows all hw glue drivers to be built into one single
image, so that we can support one single image to be run in multiple
machines.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/Kconfig |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 5e0a5e8..8b73d98 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -32,8 +32,7 @@ config USB_MUSB_HDRC
 	  To compile this driver as a module, choose M here; the
 	  module will be called "musb-hdrc".
 
-choice
-	prompt "Platform Glue Layer"
+comment "Platform Glue Layer"
 	depends on USB_MUSB_HDRC
 
 config USB_MUSB_DAVINCI_GLUE
@@ -66,8 +65,6 @@ config USB_MUSB_BLACKFIN_GLUE
 	tristate "Blackfin"
 	depends on (BF54x && !BF544) || (BF52x && ! BF522 && !BF523)
 
-endchoice
-
 config USB_MUSB_DAVINCI
 	bool
 	default n
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

Since hw glue drivers may depend on musb_hdrc and musb_init will return
failure if no glue device is registered, this patch fixes the issue
by registering musb_hdrc driver first.

Also this patch replaces most of __init with __devinit to support
platform_driver_register.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/cppi_dma.c      |    6 +++---
 drivers/usb/musb/musb_core.c     |   37 +++++++++++++++++++------------------
 drivers/usb/musb/musb_debugfs.c  |    4 ++--
 drivers/usb/musb/musb_dma.h      |    2 +-
 drivers/usb/musb/musb_gadget.c   |    6 +++---
 drivers/usb/musb/musbhsdma.c     |    2 +-
 drivers/usb/musb/tusb6010_omap.c |    2 +-
 7 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/drivers/usb/musb/cppi_dma.c b/drivers/usb/musb/cppi_dma.c
index de55a3c..8dbeee5 100644
--- a/drivers/usb/musb/cppi_dma.c
+++ b/drivers/usb/musb/cppi_dma.c
@@ -104,7 +104,7 @@ static void cppi_reset_tx(struct cppi_tx_stateram __iomem *tx, u32 ptr)
 	musb_writel(&tx->tx_complete, 0, ptr);
 }
 
-static void __init cppi_pool_init(struct cppi *cppi, struct cppi_channel *c)
+static void __devinit cppi_pool_init(struct cppi *cppi, struct cppi_channel *c)
 {
 	int	j;
 
@@ -149,7 +149,7 @@ static void cppi_pool_free(struct cppi_channel *c)
 	c->last_processed = NULL;
 }
 
-static int __init cppi_controller_start(struct dma_controller *c)
+static int __devinit cppi_controller_start(struct dma_controller *c)
 {
 	struct cppi	*controller;
 	void __iomem	*tibase;
@@ -1302,7 +1302,7 @@ irqreturn_t cppi_interrupt(int irq, void *dev_id)
 }
 
 /* Instantiate a software object representing a DMA controller. */
-struct dma_controller *__init
+struct dma_controller *__devinit
 dma_controller_create(struct musb *musb, void __iomem *mregs)
 {
 	struct cppi		*controller;
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index fc3ba1e..cf8895a 100644
--- ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

This patch introduces MUSB_GLUE_TUSB_STYLE flag, which
can be used to handle tusb dependent things by runtime
method instead of previous static method.

This patch handles tusb fifo style according to the flag
of MUSB_GLUE_TUSB_STYLE passed from hw glue drivers.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.c |   26 ++++++++++++++------------
 drivers/usb/musb/musb_core.h |   15 ++++++++-------
 drivers/usb/musb/musb_regs.h |    7 +------
 drivers/usb/musb/tusb6010.c  |    1 +
 4 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 2f73002..dba20f8 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1481,18 +1481,20 @@ static int __devinit musb_core_init(u16 musb_type, struct musb *musb)
 	for (i = 0; i < musb->nr_endpoints; i++) {
 		struct musb_hw_ep	*hw_ep = musb->endpoints + i;
 
-		hw_ep->fifo = MUSB_FIFO_OFFSET(i) + mbase;
-#ifdef CONFIG_USB_MUSB_TUSB6010
-		hw_ep->fifo_async = musb->async + 0x400 + MUSB_FIFO_OFFSET(i);
-		hw_ep->fifo_sync = musb->sync + 0x400 + MUSB_FIFO_OFFSET(i);
-		hw_ep->fifo_sync_va =
-			musb->sync_va + 0x400 + MUSB_FIFO_OFFSET(i);
-
-		if (i == 0)
-			hw_ep->conf = mbase - 0x400 + TUSB_EP0_CONF;
-		else
-			hw_ep->conf = mbase + 0x400 + (((i - 1) & 0xf) << 2);
-#endif
+		if (musb->ops->flags & MUSB_GLUE_TUSB_STYLE) {
+			hw_ep->fifo = MUSB_TUSB_FIFO_OFFSET(i) + mbase;
+			hw_ep->fifo_async = musb->async + 0x400 + MUSB_TUSB_FIFO_OFFSET(i);
+			hw_ep->fifo_sync = musb->sync + 0x400 + MUSB_TUSB_FIFO_OFFSET(i);
+			hw_ep->fifo_sync_va =
+				musb->sync_va + 0x400 + MUSB_TUSB_FIFO_OFFSET(i);
+
+			if (i == 0)
+				hw_ep->conf = mbase - 0x400 + TUSB_EP0_CONF;
+			else
+				hw_ep->conf = mbase + 0x400 + (((i - 1) & 0xf) << 2);
+		} else {
+			hw_ep->fifo = MUSB_FIFO_OFFSET(i) + mbase;
+		}
 
 		hw_ep->regs = MUSB_EP_OFFSET(i, 0) + mbase;
 #ifdef ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

This patch introduces musb_readb/musb_writeb function pointer,
so that we can use same musb_readb/musb_writeb in one single
binary image to help to support multiple machines.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.c |   55 ++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/musb/musb_core.h |    3 ++
 drivers/usb/musb/musb_io.h   |   49 -------------------------------------
 3 files changed, 58 insertions(+), 49 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index dba20f8..ca3ae8b 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -135,6 +135,10 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("platform:" MUSB_DRIVER_NAME);
 
+u8 (*musb_readb)(const void __iomem *addr, unsigned offset);
+EXPORT_SYMBOL(musb_readb);
+void (*musb_writeb)(void __iomem *addr, unsigned offset, u8 data);
+EXPORT_SYMBOL(musb_writeb);
 
 /*-------------------------------------------------------------------------*/
 
@@ -151,6 +155,43 @@ static inline struct musb *dev_to_musb(struct device *dev)
 /*-------------------------------------------------------------------------*/
 
 #ifndef CONFIG_BLACKFIN
+
+/*
+ * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum.
+ */
+static inline u8 __tusb_musb_readb(const void __iomem *addr, unsigned offset)
+{
+	u16 tmp;
+	u8 val;
+
+	tmp = __raw_readw(addr + (offset & ~1));
+	if (offset & 1)
+		val = (tmp >> 8);
+	else
+		val = tmp & 0xff;
+
+	return val;
+}
+
+static inline void __tusb_musb_writeb(void __iomem *addr, unsigned offset, u8 data)
+{
+	u16 tmp;
+
+	tmp = __raw_readw(addr + (offset & ~1));
+	if (offset & 1)
+		tmp = (data << 8) | (tmp & 0xff);
+	else
+		tmp = (tmp & 0xff00) | data;
+
+	__raw_writew(tmp, addr + (offset & ~1));
+}
+
+static inline u8 __musb_readb(const void __iomem *addr, unsigned offset)
+	{ return __raw_readb(addr + ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

Since hw glue drivers may depend on musb_hdrc and musb_init will return
failure if no glue device is registered, this patch fixes the issue
by registering musb_hdrc driver first.

Also this patch replaces most of __init with __devinit to support
platform_driver_register.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/cppi_dma.c      |    6 +++---
 drivers/usb/musb/musb_core.c     |   37 +++++++++++++++++++------------------
 drivers/usb/musb/musb_debugfs.c  |    4 ++--
 drivers/usb/musb/musb_dma.h      |    2 +-
 drivers/usb/musb/musb_gadget.c   |    6 +++---
 drivers/usb/musb/musbhsdma.c     |    2 +-
 drivers/usb/musb/tusb6010_omap.c |    2 +-
 7 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/drivers/usb/musb/cppi_dma.c b/drivers/usb/musb/cppi_dma.c
index de55a3c..8dbeee5 100644
--- a/drivers/usb/musb/cppi_dma.c
+++ b/drivers/usb/musb/cppi_dma.c
@@ -104,7 +104,7 @@ static void cppi_reset_tx(struct cppi_tx_stateram __iomem *tx, u32 ptr)
 	musb_writel(&tx->tx_complete, 0, ptr);
 }
 
-static void __init cppi_pool_init(struct cppi *cppi, struct cppi_channel *c)
+static void __devinit cppi_pool_init(struct cppi *cppi, struct cppi_channel *c)
 {
 	int	j;
 
@@ -149,7 +149,7 @@ static void cppi_pool_free(struct cppi_channel *c)
 	c->last_processed = NULL;
 }
 
-static int __init cppi_controller_start(struct dma_controller *c)
+static int __devinit cppi_controller_start(struct dma_controller *c)
 {
 	struct cppi	*controller;
 	void __iomem	*tibase;
@@ -1302,7 +1302,7 @@ irqreturn_t cppi_interrupt(int irq, void *dev_id)
 }
 
 /* Instantiate a software object representing a DMA controller. */
-struct dma_controller *__init
+struct dma_controller *__devinit
 dma_controller_create(struct musb *musb, void __iomem *mregs)
 {
 	struct cppi		*controller;
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index fc3ba1e..cf8895a 100644
--- ...
From: Felipe Balbi
Date: Monday, December 13, 2010 - 1:14 am

don't do that. We want the glue layer to be registered first as it will
setup the platform_device for musb and setup the platform_data, enable
clocks, etc.

NAK

-- 
balbi
--

From: Ming Lei
Date: Monday, December 13, 2010 - 4:21 am

If we want to compile glue layer as module, we must load musb_hdrc
first since glue layers depend on musb_hdrc. (It is a very reasonable
model, that specific/concrete device modules depend on musb core driver,
which is more generic)

I change platform_driver_probe to platform_driver_register,  which not
cause .probe of musb_hdrc called until 'musb_hdrc' device is created.

So the patch doesn't change the running order between .probe of glue and
.probe of musb_hdrc, and first is .probe of glue always, musb_hdrc .probe
is second.

So I think the patch is correct, and does make sense.

-- 
Lei Ming
--

From: Felipe Balbi
Date: Monday, December 13, 2010 - 4:25 am

could be, but ideally, glue layer would not depend on symbols exported
by musb, it would be the other way around. Glue layer sets things up for
musb to use. So any exported symbols from musb used in glue layer should
be studied and converted into a more generic thing. All DBG() calls on
glue layer can be converted into dev_dbg(), for musb_interrupt() we can
add a 'irq' field on musb_platform_ops, similarly for read/write fifo
and the read[bsl]/write[bsl] calls, although those I think should go to
some musb_platform_io structure.

-- 
balbi
--

From: Ming Lei
Date: Monday, December 13, 2010 - 5:11 am

In fact,  we can think glue device as specific device and musb device
(musb_hdrc) as more generic device, so glue driver should focus on specific
hardware details and musb hdrc should be more generic to handle all
standard things.

It is very reasonable that specific drivers depends on more generic drivers,

EXPORT is simpler and reasonable, also no obvious side effect, right?

For example,

musb_read_fifo/musb_write_fifo in musb_core.c  should be enough for
most of glue devices, except for AM35x(read), bfin and tusb. So we have
to put the generic musb_read_fifo/musb_write_fifo into one place, no doubt
the ideal place is musb_hdrc.  But how do other glue drivers see the symbols?
export_symbol is OK.


As said before, for read[bsl]/write[bsl], we should avoid to access this via
function pointer as far as possible for performance reason. It is best to
access this helpers by inline function or macro always.

thanks,
-- 
Lei Ming
--

From: Felipe Balbi
Date: Monday, December 13, 2010 - 6:11 am

Hi,


exactly, and that's why we pass function pointers of our hardware



I rather use something like:

static int musb_read_fifo(...)
{
	if (musb->ops->read_fifo)
		return musb->ops->read_fifo(...);

	/* otherwise fallback to generic implementation. */

	[...]

Without some numbers I can't see the real performance impact. I doubt a
pointer dereference is that expensive, is it ?!?

-- 
balbi
--

From: Ming Lei
Date: Monday, December 13, 2010 - 6:21 am

Seems it is a low cost action, :-) Also not very much symbols are to be

But where are .read_fifo from?  we must set a symbol to it, and

Since read[bsl]/write[bsl] are called with very high frequency, it is better to
inline it. At least all read[bsl]/write[bsl] are inline or defined as
MACRO in other
arch or platform.

-- 
Lei Ming
--

From: Felipe Balbi
Date: Monday, December 13, 2010 - 6:37 am

it's a static function in the glue layer. Just add it to struct

without numbers, we can't be sure it's really a big overhead.

-- 
balbi
--

From: Ming Lei
Date: Monday, December 13, 2010 - 6:43 am

In fact many glue driver used the same default read_fifo/write_fifo, do



-- 
Lei Ming
--

From: Felipe Balbi
Date: Monday, December 13, 2010 - 6:47 am

hi,


no, look at the code I put:

/* the below code would be on musb_core.c */

static void musb_read_fifo(...)
	void __iomem *fifo = hw_ep->fifo;

	DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
			'R', hw_ep->epnum, fifo, len, dst);

	if (musb->ops->read_fifo) {
		musb->ops->read_fifo();
		return;
	}

	/* else */

	/* we can't assume unaligned writes work */
	if (likely((0x01 & (unsigned long) dst) == 0)) {
		u16	index = 0;

		/* best case is 32bit-aligned destination address */
		if ((0x02 & (unsigned long) dst) == 0) {
			if (len >= 4) {
				readsl(fifo, dst, len >> 2);
				index = len & ~0x03;
			}
			if (len & 0x02) {
				*(u16 *)&dst[index] = musb_readw(fifo, 0);
				index += 2;
			}
		} else {
			if (len >= 2) {
				readsw(fifo, dst, len >> 1);
				index = len & ~0x01;
			}
		}
		if (len & 0x01)
			dst[index] = musb_readb(fifo, 0);
	} else  {
		/* byte aligned */
		readsb(fifo, dst, len);
	}
}

-- 
balbi
--

From: Ming Lei
Date: Monday, December 13, 2010 - 9:49 pm

Hi Felipe,


Yes, as said from the comments, musb_read_fifo and musb_write_fifo
are defined in musb_hdrc driver(musb_core.c) now.

Now some of glue drivers need to access the two symbols to use the default
implementation, and other glue drivers have their own .read_fifo/.write_fifo
implementations. If the two sybmols are not permitted to be exported from
musb_hdrc,  the glue drivers which need to access them will have to duplicate
this two functions into their own drivers, right?

So I think we should allow to export some symbols from musb_hdrc.

thanks,

-- 
Lei Ming
--

From: Felipe Balbi
Date: Tuesday, December 14, 2010 - 4:04 am

You didn't read the code I put on previous mail, did you ?
musb_read_fifo() would not be exported and still allow for glue layers
to implement their own versions.

-- 
balbi
--

From: Ming Lei
Date: Wednesday, December 15, 2010 - 4:39 am

Hi Felipe,


Sorry, it is really a very tricky method, but we still have the problems
on the functions below:

        musb_interrupt/musb_dma_completion/musb_debug/...

so export symbol has fewer changes than your method and
no obvious side effect, isn't it?

-- 
Lei Ming
--

From: Felipe Balbi
Date: Wednesday, December 15, 2010 - 5:32 am

I don't like that, but let's see the final patches. Although about
musb_debug, I think we should convert DBG() into dev_dbg() on glue
layers then, intead of printing musb-hdrc they'll print musb-omap2430
and etc, which makes it easier to figure out the problem might be on
glue layer, not on musb :-)

-- 
balbi
--

From: Ming Lei
Date: Wednesday, December 15, 2010 - 6:45 am

thanks,
-- 
Lei Ming
--

From: Ming Lei
Date: Monday, December 13, 2010 - 9:57 pm

Hi Felipe,


IMHO, ehci-omap is very different with your glue hw driver:

        - ehci-omap.c is included into ehci-hcd.c directly, and is
part of ehci-hcd.ko

        - ehci-omap.c is part of ehci-hcd, and not a standalone driver, but
          musb glue driver is standalone driver(has its own platform_driver
          instance implemented)

        - if ehci-omap want to be a standalone driver, ehci-hcd has to export
          many symbols to ehci-omap, such as,
                      ehci_urb_enqueue/ehci_urb_dequeue/...


thanks,
-- 
Lei Ming
--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

In fact, for tusb, musb_ep_select and MUSB_EP_OFFSET are same with
that for indexed mapping, so merge the two cases to simplify
definition of the two helpers.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.h |    8 +-------
 drivers/usb/musb/musb_regs.h |    3 ---
 2 files changed, 1 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 042b7fc..2e558d4 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -224,14 +224,8 @@ enum musb_g_ep0_state {
 #define	MUSB_FLAT_REG
 #endif
 
-/* TUSB mapping: "flat" plus ep0 special cases */
-#if	defined(CONFIG_USB_MUSB_TUSB6010)
-#define musb_ep_select(_mbase, _epnum) \
-	musb_writeb((_mbase), MUSB_INDEX, (_epnum))
-#define	MUSB_EP_OFFSET			MUSB_TUSB_OFFSET
-
 /* "flat" mapping: each endpoint has its own i/o address */
-#elif	defined(MUSB_FLAT_REG)
+#ifdef	MUSB_FLAT_REG
 #define musb_ep_select(_mbase, _epnum)	(((void)(_mbase)), ((void)(_epnum)))
 #define	MUSB_EP_OFFSET			MUSB_FLAT_OFFSET
 
diff --git a/drivers/usb/musb/musb_regs.h b/drivers/usb/musb/musb_regs.h
index edc0cca..3321bae 100644
--- a/drivers/usb/musb/musb_regs.h
+++ b/drivers/usb/musb/musb_regs.h
@@ -292,9 +292,6 @@
 #define MUSB_FLAT_OFFSET(_epnum, _offset)	\
 	(0x100 + (0x10*(_epnum)) + (_offset))
 
-/* TUSB6010 EP0 configuration register is special */
-#define MUSB_TUSB_OFFSET(_epnum, _offset)	\
-	(0x10 + _offset)
 #include "tusb6010.h"		/* Needed "only" for TUSB_EP0_CONF */
 
 #define MUSB_TXCSR_MODE			0x2000
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

Each hw controller may have different fifo configuraion,
so passing fifo_mode from hw glue is very reasonable.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/am35x.c     |    1 +
 drivers/usb/musb/blackfin.c  |    1 +
 drivers/usb/musb/da8xx.c     |    1 +
 drivers/usb/musb/davinci.c   |    1 +
 drivers/usb/musb/musb_core.c |   11 ++++-------
 drivers/usb/musb/musb_core.h |    2 ++
 drivers/usb/musb/omap2430.c  |    1 +
 drivers/usb/musb/tusb6010.c  |    1 +
 8 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 6ab6ed2..20231f3 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -442,6 +442,7 @@ static void am35x_musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
 }
 
 static const struct musb_platform_ops am35x_ops = {
+	.fifo_mode	= 4,
 	.init		= am35x_musb_init,
 	.exit		= am35x_musb_exit,
 
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index 6d61349..f6127ef8 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -416,6 +416,7 @@ static int bfin_musb_exit(struct musb *musb)
 }
 
 static const struct musb_platform_ops bfin_ops = {
+	.fifo_mode	= 2,
 	.init		= bfin_musb_init,
 	.exit		= bfin_musb_exit,
 
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 616da28..5cc7881 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -470,6 +470,7 @@ static int da8xx_musb_exit(struct musb *musb)
 }
 
 static const struct musb_platform_ops da8xx_ops = {
+	.fifo_mode	= 2,
 	.init		= da8xx_musb_init,
 	.exit		= da8xx_musb_exit,
 
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index 6987899..3c7f39a 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -505,6 +505,7 @@ static int davinci_musb_exit(struct musb *musb)
 }
 
 static const struct musb_platform_ops davinci_ops = ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

This patch introduces musb_readb/musb_writeb function pointer,
so that we can use same musb_readb/musb_writeb in one single
binary image to help to support multiple machines.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.c |   55 ++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/musb/musb_core.h |    3 ++
 drivers/usb/musb/musb_io.h   |   49 -------------------------------------
 3 files changed, 58 insertions(+), 49 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index dba20f8..ca3ae8b 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -135,6 +135,10 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("platform:" MUSB_DRIVER_NAME);
 
+u8 (*musb_readb)(const void __iomem *addr, unsigned offset);
+EXPORT_SYMBOL(musb_readb);
+void (*musb_writeb)(void __iomem *addr, unsigned offset, u8 data);
+EXPORT_SYMBOL(musb_writeb);
 
 /*-------------------------------------------------------------------------*/
 
@@ -151,6 +155,43 @@ static inline struct musb *dev_to_musb(struct device *dev)
 /*-------------------------------------------------------------------------*/
 
 #ifndef CONFIG_BLACKFIN
+
+/*
+ * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum.
+ */
+static inline u8 __tusb_musb_readb(const void __iomem *addr, unsigned offset)
+{
+	u16 tmp;
+	u8 val;
+
+	tmp = __raw_readw(addr + (offset & ~1));
+	if (offset & 1)
+		val = (tmp >> 8);
+	else
+		val = tmp & 0xff;
+
+	return val;
+}
+
+static inline void __tusb_musb_writeb(void __iomem *addr, unsigned offset, u8 data)
+{
+	u16 tmp;
+
+	tmp = __raw_readw(addr + (offset & ~1));
+	if (offset & 1)
+		tmp = (data << 8) | (tmp & 0xff);
+	else
+		tmp = (tmp & 0xff00) | data;
+
+	__raw_writew(tmp, addr + (offset & ~1));
+}
+
+static inline u8 __musb_readb(const void __iomem *addr, unsigned offset)
+	{ return __raw_readb(addr + ...
From: Felipe Balbi
Date: Monday, December 13, 2010 - 1:27 am

Hi,


my idea for this was to have struct musb_io_ops. something like:

struct musb_io_ops {
	u8	(*readb)(const void __iomem *addr, unsigned offset);
	void	(*writeb)(const void __iomem *addr, unsigned offset, u8 data);

	u16	(*readw)(....);
	void	(*writew)(;...);

	u32	(*readl)();
	void	(writel)();
}

then you have a pointer for that inside the struct musb_platform_ops, or
maybe somewhere else. And you initialize the same way platform_ops, and
if you don't have a field, you fallback to default implementation.

-- 
balbi
--

From: Ming Lei
Date: Monday, December 13, 2010 - 4:26 am

In fact, I think inline helper has a good performance, so it is better.

But no way to reach this if config option is not used, so I suggest using
inline helpers as far as possible.

-- 
Lei Ming
--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

Remove musb_in_tusb since no one may use it.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/tusb6010.h |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/musb/tusb6010.h b/drivers/usb/musb/tusb6010.h
index 35c933a..1864e24 100644
--- a/drivers/usb/musb/tusb6010.h
+++ b/drivers/usb/musb/tusb6010.h
@@ -14,12 +14,6 @@
 
 extern u8 tusb_get_revision(struct musb *musb);
 
-#ifdef CONFIG_USB_TUSB6010
-#define musb_in_tusb()			1
-#else
-#define musb_in_tusb()			0
-#endif
-
 #ifdef CONFIG_USB_TUSB_OMAP_DMA
 #define tusb_dma_omap()			1
 #else
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

The patch uses the information about hw endpoint register address
mapping from hw glue driver to implement MUSB_OFFSET/musb_ep_select
for different cases.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/am35x.c     |    1 +
 drivers/usb/musb/blackfin.c  |    1 +
 drivers/usb/musb/da8xx.c     |    1 +
 drivers/usb/musb/davinci.c   |    1 +
 drivers/usb/musb/musb_core.h |   12 +++++++++++-
 drivers/usb/musb/musb_regs.h |    7 +++++++
 drivers/usb/musb/omap2430.c  |    1 +
 drivers/usb/musb/tusb6010.c  |    2 +-
 8 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 20231f3..f14198d 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -443,6 +443,7 @@ static void am35x_musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
 
 static const struct musb_platform_ops am35x_ops = {
 	.fifo_mode	= 4,
+	.flags		= MUSB_GLUE_EP_ADDR_FLAT_MAPPING,
 	.init		= am35x_musb_init,
 	.exit		= am35x_musb_exit,
 
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index f6127ef8..6f5b6e6 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -417,6 +417,7 @@ static int bfin_musb_exit(struct musb *musb)
 
 static const struct musb_platform_ops bfin_ops = {
 	.fifo_mode	= 2,
+	.flags		= MUSB_GLUE_EP_ADDR_FLAT_MAPPING,
 	.init		= bfin_musb_init,
 	.exit		= bfin_musb_exit,
 
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 5cc7881..7b1a2ae 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -471,6 +471,7 @@ static int da8xx_musb_exit(struct musb *musb)
 
 static const struct musb_platform_ops da8xx_ops = {
 	.fifo_mode	= 2,
+	.flags		= MUSB_GLUE_EP_ADDR_FLAT_MAPPING,
 	.init		= da8xx_musb_init,
 	.exit		= da8xx_musb_exit,
 
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index 3c7f39a..8ce8c97 100644
--- ...
From: Felipe Balbi
Date: Monday, December 13, 2010 - 1:28 am

forgot to delete ?

-- 
balbi
--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

This patch uses native read_fifo/write_fifo for each hw glue driver.
Musb core can always use musb->ops->*_fifo to do PIO, also removes
some ugly ifdef for musb_read_fifo/musb_write_fifo.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/am35x.c           |    5 ++++-
 drivers/usb/musb/blackfin.c        |    7 +++++--
 drivers/usb/musb/da8xx.c           |    3 +++
 drivers/usb/musb/davinci.c         |    3 +++
 drivers/usb/musb/musb_core.c       |   11 +----------
 drivers/usb/musb/musb_gadget.c     |    4 ++--
 drivers/usb/musb/musb_gadget_ep0.c |    8 ++++----
 drivers/usb/musb/musb_host.c       |   10 +++++-----
 drivers/usb/musb/omap2430.c        |    3 +++
 drivers/usb/musb/tusb6010.c        |    6 ++++--
 drivers/usb/musb/tusb6010_omap.c   |    4 ++--
 11 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index d5a3da3..6ab6ed2 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -412,7 +412,7 @@ static int am35x_musb_exit(struct musb *musb)
 }
 
 /* AM35x supports only 32bit read operation */
-void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
+static void am35x_musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
 {
 	void __iomem *fifo = hw_ep->fifo;
 	u32		val;
@@ -452,6 +452,9 @@ static const struct musb_platform_ops am35x_ops = {
 	.try_idle	= am35x_musb_try_idle,
 
 	.set_vbus	= am35x_musb_set_vbus,
+
+	.read_fifo  = am35x_musb_read_fifo,
+	.write_fifo = musb_write_fifo,
 };
 
 static u64 am35x_dmamask = DMA_BIT_MASK(32);
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index c6d3818..6d61349 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -32,7 +32,7 @@ struct bfin_glue {
 /*
  * Load an endpoint's FIFO
  */
-void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
+static void bfin_musb_write_fifo(struct musb_hw_ep ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

In fact, for tusb, musb_ep_select and MUSB_EP_OFFSET are same with
that for indexed mapping, so merge the two cases to simplify
definition of the two helpers.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.h |    8 +-------
 drivers/usb/musb/musb_regs.h |    3 ---
 2 files changed, 1 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 042b7fc..2e558d4 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -224,14 +224,8 @@ enum musb_g_ep0_state {
 #define	MUSB_FLAT_REG
 #endif
 
-/* TUSB mapping: "flat" plus ep0 special cases */
-#if	defined(CONFIG_USB_MUSB_TUSB6010)
-#define musb_ep_select(_mbase, _epnum) \
-	musb_writeb((_mbase), MUSB_INDEX, (_epnum))
-#define	MUSB_EP_OFFSET			MUSB_TUSB_OFFSET
-
 /* "flat" mapping: each endpoint has its own i/o address */
-#elif	defined(MUSB_FLAT_REG)
+#ifdef	MUSB_FLAT_REG
 #define musb_ep_select(_mbase, _epnum)	(((void)(_mbase)), ((void)(_epnum)))
 #define	MUSB_EP_OFFSET			MUSB_FLAT_OFFSET
 
diff --git a/drivers/usb/musb/musb_regs.h b/drivers/usb/musb/musb_regs.h
index edc0cca..3321bae 100644
--- a/drivers/usb/musb/musb_regs.h
+++ b/drivers/usb/musb/musb_regs.h
@@ -292,9 +292,6 @@
 #define MUSB_FLAT_OFFSET(_epnum, _offset)	\
 	(0x100 + (0x10*(_epnum)) + (_offset))
 
-/* TUSB6010 EP0 configuration register is special */
-#define MUSB_TUSB_OFFSET(_epnum, _offset)	\
-	(0x10 + _offset)
 #include "tusb6010.h"		/* Needed "only" for TUSB_EP0_CONF */
 
 #define MUSB_TXCSR_MODE			0x2000
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

Each hw controller may have different fifo configuraion,
so passing fifo_mode from hw glue is very reasonable.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/am35x.c     |    1 +
 drivers/usb/musb/blackfin.c  |    1 +
 drivers/usb/musb/da8xx.c     |    1 +
 drivers/usb/musb/davinci.c   |    1 +
 drivers/usb/musb/musb_core.c |   11 ++++-------
 drivers/usb/musb/musb_core.h |    2 ++
 drivers/usb/musb/omap2430.c  |    1 +
 drivers/usb/musb/tusb6010.c  |    1 +
 8 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 6ab6ed2..20231f3 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -442,6 +442,7 @@ static void am35x_musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
 }
 
 static const struct musb_platform_ops am35x_ops = {
+	.fifo_mode	= 4,
 	.init		= am35x_musb_init,
 	.exit		= am35x_musb_exit,
 
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index 6d61349..f6127ef8 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -416,6 +416,7 @@ static int bfin_musb_exit(struct musb *musb)
 }
 
 static const struct musb_platform_ops bfin_ops = {
+	.fifo_mode	= 2,
 	.init		= bfin_musb_init,
 	.exit		= bfin_musb_exit,
 
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 616da28..5cc7881 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -470,6 +470,7 @@ static int da8xx_musb_exit(struct musb *musb)
 }
 
 static const struct musb_platform_ops da8xx_ops = {
+	.fifo_mode	= 2,
 	.init		= da8xx_musb_init,
 	.exit		= da8xx_musb_exit,
 
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index 6987899..3c7f39a 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -505,6 +505,7 @@ static int davinci_musb_exit(struct musb *musb)
 }
 
 static const struct musb_platform_ops davinci_ops = ...
From: Felipe Balbi
Date: Monday, December 13, 2010 - 1:15 am

Hi,


there's already a way for boards to pass in fifo_mode via platform_data.
NAK

-- 
balbi
--

From: Ming Lei
Date: Wednesday, December 15, 2010 - 11:14 pm

Hi,


You mean musb_hdrc_platform_data?  Seems it doesn't have fifo mode
information, also musb core only uses the fifo mode from static variable
of 'fifo_mode' currently.

IMHO, introducing fifo_mode in glue layer is more doable than in board data,
since all boards shipped with same hw musb controller(omap2430/davinci/tusb/...)
should use the same default fifo mode.

Any suggestions?

-- 
Lei Ming
--

From: Felipe Balbi
Date: Thursday, December 16, 2010 - 1:48 am

Look at this patch:

$ git show e6c213b2968cbee4cfb8f89f2d685b9ad07eefbd

commit e6c213b2968cbee4cfb8f89f2d685b9ad07eefbd
Author: Felipe Balbi <felipe.balbi@nokia.com>
Date:   Fri Mar 12 10:29:06 2010 +0200

     usb: musb: allow board to pass down fifo mode
     
     boards might want to optimize their fifo configuration
     to the particular needs of that specific board. Allow
     that by moving all related data structures to
     <linux/usb/musb.h>
     
     Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
     Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index ced6d9e..3f4c158 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -995,24 +995,13 @@ static ushort __initdata fifo_mode = 2;
  module_param(fifo_mode, ushort, 0);
  MODULE_PARM_DESC(fifo_mode, "initial endpoint configuration");
  
-
-enum fifo_style { FIFO_RXTX, FIFO_TX, FIFO_RX } __attribute__ ((packed));
-enum buf_mode { BUF_SINGLE, BUF_DOUBLE } __attribute__ ((packed));
-
-struct fifo_cfg {
-	u8		hw_ep_num;
-	enum fifo_style	style;
-	enum buf_mode	mode;
-	u16		maxpacket;
-};
-
  /*
   * tables defining fifo_mode values.  define more if you like.
   * for host side, make sure both halves of ep1 are set up.
   */
  
  /* mode 0 - fits in 2KB */
-static struct fifo_cfg __initdata mode_0_cfg[] = {
+static struct musb_fifo_cfg __initdata mode_0_cfg[] = {
  { .hw_ep_num = 1, .style = FIFO_TX,   .maxpacket = 512, },
  { .hw_ep_num = 1, .style = FIFO_RX,   .maxpacket = 512, },
  { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, },
@@ -1021,7 +1010,7 @@ static struct fifo_cfg __initdata mode_0_cfg[] = {
  };
  
  /* mode 1 - fits in 4KB */
-static struct fifo_cfg __initdata mode_1_cfg[] = {
+static struct musb_fifo_cfg __initdata mode_1_cfg[] = {
  { .hw_ep_num = 1, .style = FIFO_TX,   .maxpacket = 512, .mode = BUF_DOUBLE, },
  { .hw_ep_num = 1, .style = FIFO_RX,   .maxpacket ...
From: Ming Lei
Date: Thursday, December 16, 2010 - 3:06 am

Hi Felipe,


But seems the commit can't meet my requirement, I just want to remove
the config options below to support one set of musb binary drivers for
multiple musb hw controller:

/*musb_core.c*/
#if defined(CONFIG_USB_MUSB_TUSB6010) || defined(CONFIG_USB_MUSB_OMAP2PLUS) \
    || defined(CONFIG_USB_MUSB_AM35X)
static ushort __initdata fifo_mode = 4;
#else
static ushort __initdata fifo_mode = 2;
#endif

Any suggestions?

thanks,
-- 
Lei Ming
--

From: Felipe Balbi
Date: Thursday, December 16, 2010 - 5:12 am

Hi,


hmmm, I see. Ideally we wouldn't have that, those are only sane defaults

none whatsoever :-( But we need to drop those, for sure. Although I
think the way you proposed is kinda duplication, I think it's fine. At
least drops the ifdeferry.

-- 
balbi
--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

The patch uses the information about hw endpoint register address
mapping from hw glue driver to implement MUSB_OFFSET/musb_ep_select
for different cases.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/am35x.c     |    1 +
 drivers/usb/musb/blackfin.c  |    1 +
 drivers/usb/musb/da8xx.c     |    1 +
 drivers/usb/musb/davinci.c   |    1 +
 drivers/usb/musb/musb_core.h |   12 +++++++++++-
 drivers/usb/musb/musb_regs.h |    7 +++++++
 drivers/usb/musb/omap2430.c  |    1 +
 drivers/usb/musb/tusb6010.c  |    2 +-
 8 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 20231f3..f14198d 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -443,6 +443,7 @@ static void am35x_musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
 
 static const struct musb_platform_ops am35x_ops = {
 	.fifo_mode	= 4,
+	.flags		= MUSB_GLUE_EP_ADDR_FLAT_MAPPING,
 	.init		= am35x_musb_init,
 	.exit		= am35x_musb_exit,
 
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index f6127ef8..6f5b6e6 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -417,6 +417,7 @@ static int bfin_musb_exit(struct musb *musb)
 
 static const struct musb_platform_ops bfin_ops = {
 	.fifo_mode	= 2,
+	.flags		= MUSB_GLUE_EP_ADDR_FLAT_MAPPING,
 	.init		= bfin_musb_init,
 	.exit		= bfin_musb_exit,
 
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 5cc7881..7b1a2ae 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -471,6 +471,7 @@ static int da8xx_musb_exit(struct musb *musb)
 
 static const struct musb_platform_ops da8xx_ops = {
 	.fifo_mode	= 2,
+	.flags		= MUSB_GLUE_EP_ADDR_FLAT_MAPPING,
 	.init		= da8xx_musb_init,
 	.exit		= da8xx_musb_exit,
 
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index 3c7f39a..8ce8c97 100644
--- ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

Each musb hw controller may use different DMA controller, so we
introduce dma controller related flags and callbacks in glue ops.
HW glue driver can provide its dma controller information to
musb core with this flags and callbacks, so we can make musb core
more generic and avoid to depend on the ugly macro below as far as
possible:

	CONFIG_USB_INVENTRA_DMA
	CONFIG_USB_TUSB_OMAP_DMA
	CONFIG_USB_TI_CPPI_DMA

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index ae92e3c..89d8de2 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -261,6 +261,10 @@ enum musb_g_ep0_state {
 #define     MUSB_GLUE_TUSB_STYLE   0x0001
 #define     MUSB_GLUE_EP_ADDR_FLAT_MAPPING	0x0002
 #define     MUSB_GLUE_EP_ADDR_INDEXED_MAPPING	0x0004
+#define		MUSB_GLUE_DMA_INVENTRA				0x0008
+#define		MUSB_GLUE_DMA_CPPI					0x0010
+#define		MUSB_GLUE_DMA_TUSB					0x0020
+
 
 /**
  * struct musb_platform_ops - Operations passed to musb_core by HW glue layer
@@ -275,6 +279,8 @@ enum musb_g_ep0_state {
  * @set_vbus:	forces vbus status
  * @read_fifo: read data from musb fifo in PIO
  * @write_fifo: write data into musb fifo in PIO
+ * @dma_controller_create: create dma controller for me
+ * @dma_controller_destroy: destroy dma controller
  */
 struct musb_platform_ops {
 	short	fifo_mode;
@@ -294,6 +300,9 @@ struct musb_platform_ops {
 	void	(*set_vbus)(struct musb *musb, int on);
 	void (*read_fifo)(struct musb_hw_ep *hw_ep, u16 len, u8 *buf);
 	void (*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf);
+	struct dma_controller* (*dma_controller_create)(struct musb *,
+		void __iomem *);
+	void (*dma_controller_destroy)(struct dma_controller *);
 };
 
 /*
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

This patch allows all hw glue drivers to be built into one single
image, so that we can support one single image to be run in multiple
machines.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/Kconfig |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 5e0a5e8..8b73d98 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -32,8 +32,7 @@ config USB_MUSB_HDRC
 	  To compile this driver as a module, choose M here; the
 	  module will be called "musb-hdrc".
 
-choice
-	prompt "Platform Glue Layer"
+comment "Platform Glue Layer"
 	depends on USB_MUSB_HDRC
 
 config USB_MUSB_DAVINCI_GLUE
@@ -66,8 +65,6 @@ config USB_MUSB_BLACKFIN_GLUE
 	tristate "Blackfin"
 	depends on (BF54x && !BF544) || (BF52x && ! BF522 && !BF523)
 
-endchoice
-
 config USB_MUSB_DAVINCI
 	bool
 	default n
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This patche adds the paramer of musb pointer to musb_ep_select
and MUSB_EP_OFFSET, then we can pass musb into this two helpers
and can give corresponding implementation for flat mappings and
indexed mappings of hw endpoint register address using the information
from hw glue driver.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/cppi_dma.c        |   10 ++++++----
 drivers/usb/musb/musb_core.c       |   10 +++++-----
 drivers/usb/musb/musb_core.h       |    6 +++---
 drivers/usb/musb/musb_gadget.c     |   20 ++++++++++----------
 drivers/usb/musb/musb_gadget_ep0.c |   24 ++++++++++++------------
 drivers/usb/musb/musb_host.c       |   26 +++++++++++++-------------
 drivers/usb/musb/musb_regs.h       |    8 ++++----
 drivers/usb/musb/musbhsdma.c       |   10 +++++-----
 drivers/usb/musb/tusb6010_omap.c   |    6 +++---
 9 files changed, 61 insertions(+), 59 deletions(-)

diff --git a/drivers/usb/musb/cppi_dma.c b/drivers/usb/musb/cppi_dma.c
index 8dbeee5..519e641 100644
--- a/drivers/usb/musb/cppi_dma.c
+++ b/drivers/usb/musb/cppi_dma.c
@@ -354,8 +354,9 @@ cppi_dump_rx(int level, struct cppi_channel *c, const char *tag)
 {
 	void __iomem			*base = c->controller->mregs;
 	struct cppi_rx_stateram __iomem	*rx = c->state_ram;
+	struct musb		*musb = c->controller->musb;
 
-	musb_ep_select(base, c->index + 1);
+	musb_ep_select(musb, base, c->index + 1);
 
 	DBG(level, "RX DMA%d%s: %d left, csr %04x, "
 			"%08x H%08x S%08x C%08x, "
@@ -384,8 +385,9 @@ cppi_dump_tx(int level, struct cppi_channel *c, const char *tag)
 {
 	void __iomem			*base = c->controller->mregs;
 	struct cppi_tx_stateram __iomem	*tx = c->state_ram;
+	struct musb		*musb = c->controller->musb;
 
-	musb_ep_select(base, c->index + 1);
+	musb_ep_select(musb, base, c->index + 1);
 
 	DBG(level, "TX DMA%d%s: csr %04x, "
 			"H%08x S%08x C%08x %08x, "
@@ -1108,7 +1110,7 @@ static bool cppi_rx_scan(struct cppi *cppi, unsigned ch)
 			 */
 ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

tusb_dma_omap is defined in musb_dma.h already and same with
it in tusb6010.h, so remove the definition in tusb6010.h.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/tusb6010.h |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/musb/tusb6010.h b/drivers/usb/musb/tusb6010.h
index 1864e24..e1e434a 100644
--- a/drivers/usb/musb/tusb6010.h
+++ b/drivers/usb/musb/tusb6010.h
@@ -14,12 +14,6 @@
 
 extern u8 tusb_get_revision(struct musb *musb);
 
-#ifdef CONFIG_USB_TUSB_OMAP_DMA
-#define tusb_dma_omap()			1
-#else
-#define tusb_dma_omap()			0
-#endif
-
 /* VLYNQ control register. 32-bit at offset 0x000 */
 #define TUSB_VLYNQ_CTRL			0x004
 
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This comments has said clearly that they are for Mentor(INVENTRA) DMA
controller, so remove this unnecessary ifdef to make code more clean.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_gadget.c |    8 --------
 drivers/usb/musb/musb_host.c   |    8 --------
 2 files changed, 0 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 8ea1e2e..014632d 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -253,8 +253,6 @@ static inline int max_ep_writesize(struct musb *musb, struct musb_ep *ep)
 }
 
 
-#ifdef CONFIG_USB_INVENTRA_DMA
-
 /* Peripheral tx (IN) using Mentor DMA works as follows:
 	Only mode 0 is used for transfers <= wPktSize,
 	mode 1 is used for larger transfers,
@@ -285,8 +283,6 @@ static inline int max_ep_writesize(struct musb *musb, struct musb_ep *ep)
  * upleveling from irq-per-packet to irq-per-buffer.
  */
 
-#endif
-
 /*
  * An endpoint is transmitting data. This can be called either from
  * the IRQ routine or from ep.queue() to kickstart a request on an
@@ -563,8 +559,6 @@ void musb_g_tx(struct musb *musb, u8 epnum)
 
 /* ------------------------------------------------------------ */
 
-#ifdef CONFIG_USB_INVENTRA_DMA
-
 /* Peripheral rx (OUT) using Mentor DMA works as follows:
 	- Only mode 0 is used.
 
@@ -592,8 +586,6 @@ void musb_g_tx(struct musb *musb, u8 epnum)
  * Non-Mentor DMA engines can of course work differently.
  */
 
-#endif
-
 /*
  * Context: controller locked, IRQs blocked, endpoint selected
  */
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index a2c6bdb..8aa77ea 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -1089,8 +1089,6 @@ done:
 }
 
 
-#ifdef CONFIG_USB_INVENTRA_DMA
-
 /* Host side TX (OUT) using Mentor DMA works as follows:
 	submit_urb ->
 		- if queue was empty, Program Endpoint
@@ ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This comments has said clearly that they are for Mentor(INVENTRA) DMA
controller, so remove this unnecessary ifdef to make code more clean.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_gadget.c |    8 --------
 drivers/usb/musb/musb_host.c   |    8 --------
 2 files changed, 0 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 8ea1e2e..014632d 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -253,8 +253,6 @@ static inline int max_ep_writesize(struct musb *musb, struct musb_ep *ep)
 }
 
 
-#ifdef CONFIG_USB_INVENTRA_DMA
-
 /* Peripheral tx (IN) using Mentor DMA works as follows:
 	Only mode 0 is used for transfers <= wPktSize,
 	mode 1 is used for larger transfers,
@@ -285,8 +283,6 @@ static inline int max_ep_writesize(struct musb *musb, struct musb_ep *ep)
  * upleveling from irq-per-packet to irq-per-buffer.
  */
 
-#endif
-
 /*
  * An endpoint is transmitting data. This can be called either from
  * the IRQ routine or from ep.queue() to kickstart a request on an
@@ -563,8 +559,6 @@ void musb_g_tx(struct musb *musb, u8 epnum)
 
 /* ------------------------------------------------------------ */
 
-#ifdef CONFIG_USB_INVENTRA_DMA
-
 /* Peripheral rx (OUT) using Mentor DMA works as follows:
 	- Only mode 0 is used.
 
@@ -592,8 +586,6 @@ void musb_g_tx(struct musb *musb, u8 epnum)
  * Non-Mentor DMA engines can of course work differently.
  */
 
-#endif
-
 /*
  * Context: controller locked, IRQs blocked, endpoint selected
  */
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index a2c6bdb..8aa77ea 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -1089,8 +1089,6 @@ done:
 }
 
 
-#ifdef CONFIG_USB_INVENTRA_DMA
-
 /* Host side TX (OUT) using Mentor DMA works as follows:
 	submit_urb ->
 		- if queue was empty, Program Endpoint
@@ ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

Remove musb_in_tusb since no one may use it.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/tusb6010.h |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/musb/tusb6010.h b/drivers/usb/musb/tusb6010.h
index 35c933a..1864e24 100644
--- a/drivers/usb/musb/tusb6010.h
+++ b/drivers/usb/musb/tusb6010.h
@@ -14,12 +14,6 @@
 
 extern u8 tusb_get_revision(struct musb *musb);
 
-#ifdef CONFIG_USB_TUSB6010
-#define musb_in_tusb()			1
-#else
-#define musb_in_tusb()			0
-#endif
-
 #ifdef CONFIG_USB_TUSB_OMAP_DMA
 #define tusb_dma_omap()			1
 #else
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

Remove one 'ifdef' and one 'exit' symbol to make code more cleaner.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_gadget.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 655b094..8ea1e2e 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -885,8 +885,9 @@ void musb_g_rx(struct musb *musb, u8 epnum)
  			 **/
 			csr = musb_readw(epio, MUSB_RXCSR);
 			if ((csr & MUSB_RXCSR_RXPKTRDY) &&
-				hw_ep->rx_double_buffered)
-				goto exit;
+				hw_ep->rx_double_buffered) {
+				rxstate(musb, to_musb_request(request));
+			}
 			return;
 		}
 #endif
@@ -896,9 +897,6 @@ void musb_g_rx(struct musb *musb, u8 epnum)
 		if (!request)
 			return;
 	}
-#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_TUSB_OMAP_DMA)
-exit:
-#endif
 	/* Analyze request */
 	rxstate(musb, to_musb_request(request));
 }
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

tusb_dma_omap is defined in musb_dma.h already and same with
it in tusb6010.h, so remove the definition in tusb6010.h.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/tusb6010.h |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/musb/tusb6010.h b/drivers/usb/musb/tusb6010.h
index 1864e24..e1e434a 100644
--- a/drivers/usb/musb/tusb6010.h
+++ b/drivers/usb/musb/tusb6010.h
@@ -14,12 +14,6 @@
 
 extern u8 tusb_get_revision(struct musb *musb);
 
-#ifdef CONFIG_USB_TUSB_OMAP_DMA
-#define tusb_dma_omap()			1
-#else
-#define tusb_dma_omap()			0
-#endif
-
 /* VLYNQ control register. 32-bit at offset 0x000 */
 #define TUSB_VLYNQ_CTRL			0x004
 
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:01 am

From: Ming Lei <tom.leiming@gmail.com>

This patch introduces MUSB_GLUE_TUSB_STYLE flag, which
can be used to handle tusb dependent things by runtime
method instead of previous static method.

This patch handles tusb fifo style according to the flag
of MUSB_GLUE_TUSB_STYLE passed from hw glue drivers.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.c |   26 ++++++++++++++------------
 drivers/usb/musb/musb_core.h |   15 ++++++++-------
 drivers/usb/musb/musb_regs.h |    7 +------
 drivers/usb/musb/tusb6010.c  |    1 +
 4 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 2f73002..dba20f8 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1481,18 +1481,20 @@ static int __devinit musb_core_init(u16 musb_type, struct musb *musb)
 	for (i = 0; i < musb->nr_endpoints; i++) {
 		struct musb_hw_ep	*hw_ep = musb->endpoints + i;
 
-		hw_ep->fifo = MUSB_FIFO_OFFSET(i) + mbase;
-#ifdef CONFIG_USB_MUSB_TUSB6010
-		hw_ep->fifo_async = musb->async + 0x400 + MUSB_FIFO_OFFSET(i);
-		hw_ep->fifo_sync = musb->sync + 0x400 + MUSB_FIFO_OFFSET(i);
-		hw_ep->fifo_sync_va =
-			musb->sync_va + 0x400 + MUSB_FIFO_OFFSET(i);
-
-		if (i == 0)
-			hw_ep->conf = mbase - 0x400 + TUSB_EP0_CONF;
-		else
-			hw_ep->conf = mbase + 0x400 + (((i - 1) & 0xf) << 2);
-#endif
+		if (musb->ops->flags & MUSB_GLUE_TUSB_STYLE) {
+			hw_ep->fifo = MUSB_TUSB_FIFO_OFFSET(i) + mbase;
+			hw_ep->fifo_async = musb->async + 0x400 + MUSB_TUSB_FIFO_OFFSET(i);
+			hw_ep->fifo_sync = musb->sync + 0x400 + MUSB_TUSB_FIFO_OFFSET(i);
+			hw_ep->fifo_sync_va =
+				musb->sync_va + 0x400 + MUSB_TUSB_FIFO_OFFSET(i);
+
+			if (i == 0)
+				hw_ep->conf = mbase - 0x400 + TUSB_EP0_CONF;
+			else
+				hw_ep->conf = mbase + 0x400 + (((i - 1) & 0xf) << 2);
+		} else {
+			hw_ep->fifo = MUSB_FIFO_OFFSET(i) + mbase;
+		}
 
 		hw_ep->regs = MUSB_EP_OFFSET(i, 0) + mbase;
 #ifdef ...
From: Felipe Balbi
Date: Monday, December 13, 2010 - 1:21 am

Hi,


I'm not sure I like this approach. I didn't want musb to have to know

fields which are used only by tusb should be moved to struct tusb_glue
instead. That'll be a bit more work.

-- 
balbi
--

From: Ming Lei
Date: Sunday, December 19, 2010 - 7:58 am

We need to remove CONFIG_USB_MUSB_TUSB6010 first, so I think
the method taken by the patch is doable for the purpose.

Once we have better one, we can convert to it, but I find no better


Could we do it in another patch set?

thanks,
-- 
Lei Ming
--

From: Felipe Balbi
Date: Monday, December 20, 2010 - 12:27 am

I think we can, instead, move all of those  "the following field is only
used by tusb" to tusb glue layer. Put those on struct tusb_glue and
access them only from there.

I didn't check the code thoroughly but looks like it's possible.

-- 
balbi
--

From: Ming Lei
Date: Monday, December 20, 2010 - 12:41 am

Hi,


If so, we need to access tusb specific type from musb core or musb dma,
seems not good since musb core or musb dma have to know if the current
glue driver is tusb, right?

thanks,
-- 
Lei Ming
--

From: Felipe Balbi
Date: Monday, December 20, 2010 - 1:29 am

Not necessarily, we can ask glue layer to write correct registers with
function pointers, for instance. But, like I said, I quickly looked at
that code, could be that it'd be a lot of work.

-- 
balbi
--

From: Ming Lei
Date: Monday, December 20, 2010 - 2:22 am

Hi,


Yes, it should be a lot of work, so I suggest removing dependency on
CONFIG_USB_MUSB_TUSB6010 and other config options first in the
patch set.

Obviously, we can't do all cleanup in one single patch set, :-)

Could you agree on taking the method of the patch now?

thanks,
-- 
Lei Ming
--

From: Felipe Balbi
Date: Monday, December 20, 2010 - 2:35 am

Sure, we can split things more later.

-- 
balbi
--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This patch provides support for building each dma controller driver
as standalone module, and this modules can be built into one same
image and can be used by each hw glue driver.

HW glue driver has the knowledge of which type of dma controller will
be used, and can pass the knowledge into musb core driver via glue ops,
so we can take runtime method to support all hw controller and its dma
controller in one binary musb driver.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/Kconfig         |   28 ++++++++++++++++----
 drivers/usb/musb/Makefile        |   19 ++------------
 drivers/usb/musb/blackfin.c      |    5 +++-
 drivers/usb/musb/cppi_dma.c      |   21 +++++++++++++--
 drivers/usb/musb/davinci.c       |    5 +++-
 drivers/usb/musb/musb_core.c     |    9 +++++-
 drivers/usb/musb/musb_dma.h      |   50 ++++++++++++++++++++++++++++++++++++-
 drivers/usb/musb/musbhsdma.c     |   23 +++++++++++++++--
 drivers/usb/musb/omap2430.c      |    5 +++-
 drivers/usb/musb/tusb6010.c      |    6 ++++-
 drivers/usb/musb/tusb6010_omap.c |   23 +++++++++++++++--
 11 files changed, 155 insertions(+), 39 deletions(-)

diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 8b73d98..9139ba1 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -171,22 +171,25 @@ config MUSB_PIO_ONLY
 	  you can still disable it at run time using the "use_dma=n" module
 	  parameter.
 
-config USB_INVENTRA_DMA
-	bool
+config USB_INVENTRA_DMA_HW
+	select USB_INVENTRA_DMA
+	tristate
 	depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY
 	default USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN
 	help
 	  Enable DMA transfers using Mentor's engine.
 
-config USB_TI_CPPI_DMA
-	bool
+config USB_TI_CPPI_DMA_HW
+	select USB_TI_CPPI_DMA
+	tristate
 	depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY
 	default USB_MUSB_DAVINCI_DMx
 	help
 	  Enable DMA transfers when TI CPPI DMA is available.
 
-config ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

We will support multiple dma controller type in one single
musb core driver(binary), so print dma type by the
information from hw glue driver.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.c |   14 ++------------
 drivers/usb/musb/musb_core.h |   16 ++++++++++++++++
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 245bdc2..0a1ac52 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -2045,6 +2045,8 @@ bad_config:
 		musb_writeb = __musb_writeb;
 	}
 
+	dev_info(dev, "dma type: %s\n", get_dma_name(musb));
+
 	/* The musb_platform_init() call:
 	 *   - adjusts musb->mregs and musb->isr if needed,
 	 *   - may initialize an integrated tranceiver
@@ -2503,18 +2505,6 @@ static int __init musb_init(void)
 #endif
 
 	pr_info("%s: version " MUSB_VERSION ", "
-#ifdef CONFIG_MUSB_PIO_ONLY
-		"pio"
-#elif defined(CONFIG_USB_TI_CPPI_DMA)
-		"cppi-dma"
-#elif defined(CONFIG_USB_INVENTRA_DMA)
-		"musb-dma"
-#elif defined(CONFIG_USB_TUSB_OMAP_DMA)
-		"tusb-omap-dma"
-#else
-		"?dma?"
-#endif
-		", "
 #ifdef CONFIG_USB_MUSB_OTG
 		"otg (peripheral+host)"
 #elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 89d8de2..e42b20d 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -678,4 +678,20 @@ static inline int musb_platform_exit(struct musb *musb)
 	return musb->ops->exit(musb);
 }
 
+static inline const char *get_dma_name(struct musb *musb)
+{
+#ifdef CONFIG_MUSB_PIO_ONLY
+	return "pio";
+#else
+	if (musb->ops->flags & MUSB_GLUE_DMA_INVENTRA)
+		return "musb->dma";
+	else if (musb->ops->flags & MUSB_GLUE_DMA_CPPI)
+		return "cppi-dma";
+	else if (musb->ops->flags & MUSB_GLUE_DMA_TUSB)
+		return "tusb-omap-dma";
+	else
+		return "?dma?";
+#endif
+}
+
 #endif	/* __MUSB_CORE_H__ ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This patche adds the paramer of musb pointer to musb_ep_select
and MUSB_EP_OFFSET, then we can pass musb into this two helpers
and can give corresponding implementation for flat mappings and
indexed mappings of hw endpoint register address using the information
from hw glue driver.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/cppi_dma.c        |   10 ++++++----
 drivers/usb/musb/musb_core.c       |   10 +++++-----
 drivers/usb/musb/musb_core.h       |    6 +++---
 drivers/usb/musb/musb_gadget.c     |   20 ++++++++++----------
 drivers/usb/musb/musb_gadget_ep0.c |   24 ++++++++++++------------
 drivers/usb/musb/musb_host.c       |   26 +++++++++++++-------------
 drivers/usb/musb/musb_regs.h       |    8 ++++----
 drivers/usb/musb/musbhsdma.c       |   10 +++++-----
 drivers/usb/musb/tusb6010_omap.c   |    6 +++---
 9 files changed, 61 insertions(+), 59 deletions(-)

diff --git a/drivers/usb/musb/cppi_dma.c b/drivers/usb/musb/cppi_dma.c
index 8dbeee5..519e641 100644
--- a/drivers/usb/musb/cppi_dma.c
+++ b/drivers/usb/musb/cppi_dma.c
@@ -354,8 +354,9 @@ cppi_dump_rx(int level, struct cppi_channel *c, const char *tag)
 {
 	void __iomem			*base = c->controller->mregs;
 	struct cppi_rx_stateram __iomem	*rx = c->state_ram;
+	struct musb		*musb = c->controller->musb;
 
-	musb_ep_select(base, c->index + 1);
+	musb_ep_select(musb, base, c->index + 1);
 
 	DBG(level, "RX DMA%d%s: %d left, csr %04x, "
 			"%08x H%08x S%08x C%08x, "
@@ -384,8 +385,9 @@ cppi_dump_tx(int level, struct cppi_channel *c, const char *tag)
 {
 	void __iomem			*base = c->controller->mregs;
 	struct cppi_tx_stateram __iomem	*tx = c->state_ram;
+	struct musb		*musb = c->controller->musb;
 
-	musb_ep_select(base, c->index + 1);
+	musb_ep_select(musb, base, c->index + 1);
 
 	DBG(level, "TX DMA%d%s: csr %04x, "
 			"H%08x S%08x C%08x %08x, "
@@ -1108,7 +1110,7 @@ static bool cppi_rx_scan(struct cppi *cppi, unsigned ch)
 			 */
 ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This patch provides support for building each dma controller driver
as standalone module, and this modules can be built into one same
image and can be used by each hw glue driver.

HW glue driver has the knowledge of which type of dma controller will
be used, and can pass the knowledge into musb core driver via glue ops,
so we can take runtime method to support all hw controller and its dma
controller in one binary musb driver.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/Kconfig         |   28 ++++++++++++++++----
 drivers/usb/musb/Makefile        |   19 ++------------
 drivers/usb/musb/blackfin.c      |    5 +++-
 drivers/usb/musb/cppi_dma.c      |   21 +++++++++++++--
 drivers/usb/musb/davinci.c       |    5 +++-
 drivers/usb/musb/musb_core.c     |    9 +++++-
 drivers/usb/musb/musb_dma.h      |   50 ++++++++++++++++++++++++++++++++++++-
 drivers/usb/musb/musbhsdma.c     |   23 +++++++++++++++--
 drivers/usb/musb/omap2430.c      |    5 +++-
 drivers/usb/musb/tusb6010.c      |    6 ++++-
 drivers/usb/musb/tusb6010_omap.c |   23 +++++++++++++++--
 11 files changed, 155 insertions(+), 39 deletions(-)

diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 8b73d98..9139ba1 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -171,22 +171,25 @@ config MUSB_PIO_ONLY
 	  you can still disable it at run time using the "use_dma=n" module
 	  parameter.
 
-config USB_INVENTRA_DMA
-	bool
+config USB_INVENTRA_DMA_HW
+	select USB_INVENTRA_DMA
+	tristate
 	depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY
 	default USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN
 	help
 	  Enable DMA transfers using Mentor's engine.
 
-config USB_TI_CPPI_DMA
-	bool
+config USB_TI_CPPI_DMA_HW
+	select USB_TI_CPPI_DMA
+	tristate
 	depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY
 	default USB_MUSB_DAVINCI_DMx
 	help
 	  Enable DMA transfers when TI CPPI DMA is available.
 
-config ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

Each musb hw controller may use different DMA controller, so we
introduce dma controller related flags and callbacks in glue ops.
HW glue driver can provide its dma controller information to
musb core with this flags and callbacks, so we can make musb core
more generic and avoid to depend on the ugly macro below as far as
possible:

	CONFIG_USB_INVENTRA_DMA
	CONFIG_USB_TUSB_OMAP_DMA
	CONFIG_USB_TI_CPPI_DMA

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index ae92e3c..89d8de2 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -261,6 +261,10 @@ enum musb_g_ep0_state {
 #define     MUSB_GLUE_TUSB_STYLE   0x0001
 #define     MUSB_GLUE_EP_ADDR_FLAT_MAPPING	0x0002
 #define     MUSB_GLUE_EP_ADDR_INDEXED_MAPPING	0x0004
+#define		MUSB_GLUE_DMA_INVENTRA				0x0008
+#define		MUSB_GLUE_DMA_CPPI					0x0010
+#define		MUSB_GLUE_DMA_TUSB					0x0020
+
 
 /**
  * struct musb_platform_ops - Operations passed to musb_core by HW glue layer
@@ -275,6 +279,8 @@ enum musb_g_ep0_state {
  * @set_vbus:	forces vbus status
  * @read_fifo: read data from musb fifo in PIO
  * @write_fifo: write data into musb fifo in PIO
+ * @dma_controller_create: create dma controller for me
+ * @dma_controller_destroy: destroy dma controller
  */
 struct musb_platform_ops {
 	short	fifo_mode;
@@ -294,6 +300,9 @@ struct musb_platform_ops {
 	void	(*set_vbus)(struct musb *musb, int on);
 	void (*read_fifo)(struct musb_hw_ep *hw_ep, u16 len, u8 *buf);
 	void (*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf);
+	struct dma_controller* (*dma_controller_create)(struct musb *,
+		void __iomem *);
+	void (*dma_controller_destroy)(struct dma_controller *);
 };
 
 /*
-- 
1.7.3

--

From: Felipe Balbi
Date: Monday, December 13, 2010 - 1:30 am

DMA controller should be splitted to its own platform_driver also, then
you instanciate the correct platform_device on the glue layer. And
that might not be enough either, you could have an omap3/4 device using
sDMA (but you don't have sync lines, so that's not really usable).

-- 
balbi
--

From: Ming Lei
Date: Monday, December 13, 2010 - 4:30 am

Yes, I agree, but we have to remove the dependency on this config option
in musb_core.c/musb_gadget.c/musb_host.c first, seems this options are

Before reaching the final goal, we have to remove this options first in
source code.

-- 
Lei Ming
--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

Remove one 'ifdef' and one 'exit' symbol to make code more cleaner.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_gadget.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 655b094..8ea1e2e 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -885,8 +885,9 @@ void musb_g_rx(struct musb *musb, u8 epnum)
  			 **/
 			csr = musb_readw(epio, MUSB_RXCSR);
 			if ((csr & MUSB_RXCSR_RXPKTRDY) &&
-				hw_ep->rx_double_buffered)
-				goto exit;
+				hw_ep->rx_double_buffered) {
+				rxstate(musb, to_musb_request(request));
+			}
 			return;
 		}
 #endif
@@ -896,9 +897,6 @@ void musb_g_rx(struct musb *musb, u8 epnum)
 		if (!request)
 			return;
 	}
-#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_TUSB_OMAP_DMA)
-exit:
-#endif
 	/* Analyze request */
 	rxstate(musb, to_musb_request(request));
 }
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This patch passes musb pointer to tusb_dma_omap to
prepare for support of runtime tusb_dma_omap.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.c   |    2 +-
 drivers/usb/musb/musb_dma.h    |    4 ++--
 drivers/usb/musb/musb_gadget.c |    6 +++---
 drivers/usb/musb/musb_host.c   |    8 ++++----
 drivers/usb/musb/tusb6010.c    |    2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 4544609..43718df 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1709,7 +1709,7 @@ void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
 	/* called with controller lock already held */
 
 	if (!epnum) {
-		if (!tusb_dma_omap() && !is_cppi_enabled()) {
+		if (!tusb_dma_omap(musb) && !is_cppi_enabled()) {
 			/* endpoint 0 */
 			if (devctl & MUSB_DEVCTL_HM)
 				musb_h_ep0_irq(musb);
diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index 7a7fb27..aa1ee04 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -81,9 +81,9 @@ struct musb_hw_ep;
 #endif
 
 #ifdef CONFIG_USB_TUSB_OMAP_DMA
-#define tusb_dma_omap()			1
+#define tusb_dma_omap(musb)			1
 #else
-#define tusb_dma_omap()			0
+#define tusb_dma_omap(musb)			0
 #endif
 
 /* Anomaly 05000456 - USB Receive Interrupt Is Not Generated in DMA Mode 1
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 79e7ed6..5ee6fcb 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -414,7 +414,7 @@ static void txstate(struct musb *musb, struct musb_request *req)
 				musb_writew(epio, MUSB_TXCSR, csr);
 				/* invariant: prequest->buf is non-null */
 			}
-		} else if (tusb_dma_omap()) {
+		} else if (tusb_dma_omap(musb)) {
 			use_dma = use_dma && c->channel_program(
 					musb_ep->dma, musb_ep->packet_sz,
 					request->zero,
@@ ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This patch uses the three helpers below:
	is_inventra_dma/is_cppi_enabled/tusb_dma_omap
to replace the options of CONFIG_USB_*_DMA.

The method was applied in musb_host.c before(using
is_cppi_enabled & tusb_dma_omap to replace using
'ifdef CONFIG_USB_*_DMA',  and don't introduce any
performance loss since compiler is smart enough to
handle this cases.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.c   |    4 +-
 drivers/usb/musb/musb_gadget.c |  137 +++++++++++++++++++---------------------
 drivers/usb/musb/musb_host.c   |  128 ++++++++++++++++++-------------------
 3 files changed, 128 insertions(+), 141 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 0a1ac52..4544609 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1709,15 +1709,13 @@ void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
 	/* called with controller lock already held */
 
 	if (!epnum) {
-#ifndef CONFIG_USB_TUSB_OMAP_DMA
-		if (!is_cppi_enabled()) {
+		if (!tusb_dma_omap() && !is_cppi_enabled()) {
 			/* endpoint 0 */
 			if (devctl & MUSB_DEVCTL_HM)
 				musb_h_ep0_irq(musb);
 			else
 				musb_g_ep0_irq(musb);
 		}
-#endif
 	} else {
 		/* endpoints 1..15 */
 		if (transmit) {
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 014632d..4449230 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -343,8 +343,7 @@ static void txstate(struct musb *musb, struct musb_request *req)
 
 		/* MUSB_TXCSR_P_ISO is still set correctly */
 
-#ifdef CONFIG_USB_INVENTRA_DMA
-		{
+		if (is_inventra_dma()) {
 			if (request_size < musb_ep->packet_sz)
 				musb_ep->dma->desired_mode = 0;
 			else
@@ -381,49 +380,47 @@ static void txstate(struct musb *musb, struct musb_request *req)
 
 				musb_writew(epio, MUSB_TXCSR, csr);
 			}
-		}
-
-#elif ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This patch introduces is_inventra_dma helper, so that
we can remove dependency on CONFIG_USB_INVENTRA_DMA
in source file of musb core driver in later patches.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_dma.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index 70a64a2..b4271b8 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -68,6 +68,12 @@ struct musb_hw_ep;
 #define	is_dma_capable()	(0)
 #endif
 
+#ifdef CONFIG_USB_INVENTRA_DMA
+#define	is_inventra_dma()	1
+#else
+#define	is_inventra_dma()	0
+#endif
+
 #ifdef CONFIG_USB_TI_CPPI_DMA
 #define	is_cppi_enabled()	1
 #else
-- 
1.7.3

--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

We will support multiple dma controller type in one single
musb core driver(binary), so print dma type by the
information from hw glue driver.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.c |   14 ++------------
 drivers/usb/musb/musb_core.h |   16 ++++++++++++++++
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 245bdc2..0a1ac52 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -2045,6 +2045,8 @@ bad_config:
 		musb_writeb = __musb_writeb;
 	}
 
+	dev_info(dev, "dma type: %s\n", get_dma_name(musb));
+
 	/* The musb_platform_init() call:
 	 *   - adjusts musb->mregs and musb->isr if needed,
 	 *   - may initialize an integrated tranceiver
@@ -2503,18 +2505,6 @@ static int __init musb_init(void)
 #endif
 
 	pr_info("%s: version " MUSB_VERSION ", "
-#ifdef CONFIG_MUSB_PIO_ONLY
-		"pio"
-#elif defined(CONFIG_USB_TI_CPPI_DMA)
-		"cppi-dma"
-#elif defined(CONFIG_USB_INVENTRA_DMA)
-		"musb-dma"
-#elif defined(CONFIG_USB_TUSB_OMAP_DMA)
-		"tusb-omap-dma"
-#else
-		"?dma?"
-#endif
-		", "
 #ifdef CONFIG_USB_MUSB_OTG
 		"otg (peripheral+host)"
 #elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 89d8de2..e42b20d 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -678,4 +678,20 @@ static inline int musb_platform_exit(struct musb *musb)
 	return musb->ops->exit(musb);
 }
 
+static inline const char *get_dma_name(struct musb *musb)
+{
+#ifdef CONFIG_MUSB_PIO_ONLY
+	return "pio";
+#else
+	if (musb->ops->flags & MUSB_GLUE_DMA_INVENTRA)
+		return "musb->dma";
+	else if (musb->ops->flags & MUSB_GLUE_DMA_CPPI)
+		return "cppi-dma";
+	else if (musb->ops->flags & MUSB_GLUE_DMA_TUSB)
+		return "tusb-omap-dma";
+	else
+		return "?dma?";
+#endif
+}
+
 #endif	/* __MUSB_CORE_H__ ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This patch introduces is_inventra_dma helper, so that
we can remove dependency on CONFIG_USB_INVENTRA_DMA
in source file of musb core driver in later patches.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_dma.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index 70a64a2..b4271b8 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -68,6 +68,12 @@ struct musb_hw_ep;
 #define	is_dma_capable()	(0)
 #endif
 
+#ifdef CONFIG_USB_INVENTRA_DMA
+#define	is_inventra_dma()	1
+#else
+#define	is_inventra_dma()	0
+#endif
+
 #ifdef CONFIG_USB_TI_CPPI_DMA
 #define	is_cppi_enabled()	1
 #else
-- 
1.7.3

--

From: Felipe Balbi
Date: Monday, December 13, 2010 - 1:32 am

we actually want to get rid of that, all DMA-specific crap should move
to dma layer, MUSB should not care about which DMA it's using.

-- 
balbi
--

From: Ming Lei
Date: Monday, December 13, 2010 - 4:37 am

Yes, the helpers above will be removed finally. I think it will be close to
the final goal to convert 'ifdef CONFIG_USB_*_DMA' into is_*_dma first.

Once the conversion is finished, it will be very easier to remove
this helpers and move all dma specific code into its dma controller driver,
then musb core(musb_hdrc) will be much more generic than now.

thanks,
-- 
Lei Ming
--

From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This patch passes musb pointer to is_inventra_dma to
prepare for support runtime is_inventra_dma.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_dma.h    |    4 ++--
 drivers/usb/musb/musb_gadget.c |    8 ++++----
 drivers/usb/musb/musb_host.c   |    8 ++++----
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index b4271b8..7a7fb27 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -69,9 +69,9 @@ struct musb_hw_ep;
 #endif
 
 #ifdef CONFIG_USB_INVENTRA_DMA
-#define	is_inventra_dma()	1
+#define	is_inventra_dma(musb)	1
 #else
-#define	is_inventra_dma()	0
+#define	is_inventra_dma(musb)	0
 #endif
 
 #ifdef CONFIG_USB_TI_CPPI_DMA
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 4449230..79e7ed6 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -343,7 +343,7 @@ static void txstate(struct musb *musb, struct musb_request *req)
 
 		/* MUSB_TXCSR_P_ISO is still set correctly */
 
-		if (is_inventra_dma()) {
+		if (is_inventra_dma(musb)) {
 			if (request_size < musb_ep->packet_sz)
 				musb_ep->dma->desired_mode = 0;
 			else
@@ -521,7 +521,7 @@ void musb_g_tx(struct musb *musb, u8 epnum)
 		if ((request->zero && request->length
 			&& (request->length % musb_ep->packet_sz == 0)
 			&& (request->actual == request->length))
-			|| (is_inventra_dma() && is_dma && (!dma->desired_mode ||
+			|| (is_inventra_dma(musb) && is_dma && (!dma->desired_mode ||
 				(request->actual &
 					(musb_ep->packet_sz - 1))))
 		) {
@@ -645,7 +645,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
 		len = musb_readw(epio, MUSB_RXCOUNT);
 		if (request->actual < request->length) {
 			if (is_dma_capable() &&
-				is_inventra_dma() && musb_ep->dma) {
+				is_inventra_dma(musb) && musb_ep->dma) {
 				struct dma_controller	*c;
 ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This patch uses the three helpers below:
	is_inventra_dma/is_cppi_enabled/tusb_dma_omap
to replace the options of CONFIG_USB_*_DMA.

The method was applied in musb_host.c before(using
is_cppi_enabled & tusb_dma_omap to replace using
'ifdef CONFIG_USB_*_DMA',  and don't introduce any
performance loss since compiler is smart enough to
handle this cases.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.c   |    4 +-
 drivers/usb/musb/musb_gadget.c |  137 +++++++++++++++++++---------------------
 drivers/usb/musb/musb_host.c   |  128 ++++++++++++++++++-------------------
 3 files changed, 128 insertions(+), 141 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 0a1ac52..4544609 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1709,15 +1709,13 @@ void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
 	/* called with controller lock already held */
 
 	if (!epnum) {
-#ifndef CONFIG_USB_TUSB_OMAP_DMA
-		if (!is_cppi_enabled()) {
+		if (!tusb_dma_omap() && !is_cppi_enabled()) {
 			/* endpoint 0 */
 			if (devctl & MUSB_DEVCTL_HM)
 				musb_h_ep0_irq(musb);
 			else
 				musb_g_ep0_irq(musb);
 		}
-#endif
 	} else {
 		/* endpoints 1..15 */
 		if (transmit) {
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 014632d..4449230 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -343,8 +343,7 @@ static void txstate(struct musb *musb, struct musb_request *req)
 
 		/* MUSB_TXCSR_P_ISO is still set correctly */
 
-#ifdef CONFIG_USB_INVENTRA_DMA
-		{
+		if (is_inventra_dma()) {
 			if (request_size < musb_ep->packet_sz)
 				musb_ep->dma->desired_mode = 0;
 			else
@@ -381,49 +380,47 @@ static void txstate(struct musb *musb, struct musb_request *req)
 
 				musb_writew(epio, MUSB_TXCSR, csr);
 			}
-		}
-
-#elif ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This patch passes musb pointer to is_cppi_enabled to
prepare for support of runtime is_cppi_enabled.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/davinci.c     |    2 +-
 drivers/usb/musb/musb_core.c   |    2 +-
 drivers/usb/musb/musb_dma.h    |    4 ++--
 drivers/usb/musb/musb_gadget.c |    4 ++--
 drivers/usb/musb/musb_host.c   |   10 +++++-----
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index b0f5101..7f339cf 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -291,7 +291,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
 	 * mask, state, "vector", and EOI registers.
 	 */
 	cppi = container_of(musb->dma_controller, struct cppi, controller);
-	if (is_cppi_enabled() && musb->dma_controller && !cppi->irq)
+	if (is_cppi_enabled(musb) && musb->dma_controller && !cppi->irq)
 		retval = cppi_interrupt(irq, __hci);
 
 	/* ack and handle non-CPPI interrupts */
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 43718df..39bebfd 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1709,7 +1709,7 @@ void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
 	/* called with controller lock already held */
 
 	if (!epnum) {
-		if (!tusb_dma_omap(musb) && !is_cppi_enabled()) {
+		if (!tusb_dma_omap(musb) && !is_cppi_enabled(musb)) {
 			/* endpoint 0 */
 			if (devctl & MUSB_DEVCTL_HM)
 				musb_h_ep0_irq(musb);
diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index aa1ee04..dbc6d3d 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -75,9 +75,9 @@ struct musb_hw_ep;
 #endif
 
 #ifdef CONFIG_USB_TI_CPPI_DMA
-#define	is_cppi_enabled()	1
+#define	is_cppi_enabled(musb)	1
 #else
-#define	is_cppi_enabled()	0
+#define	is_cppi_enabled(musb)	0
 #endif
 
 #ifdef ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This patch passes musb pointer to is_inventra_dma to
prepare for support runtime is_inventra_dma.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_dma.h    |    4 ++--
 drivers/usb/musb/musb_gadget.c |    8 ++++----
 drivers/usb/musb/musb_host.c   |    8 ++++----
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index b4271b8..7a7fb27 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -69,9 +69,9 @@ struct musb_hw_ep;
 #endif
 
 #ifdef CONFIG_USB_INVENTRA_DMA
-#define	is_inventra_dma()	1
+#define	is_inventra_dma(musb)	1
 #else
-#define	is_inventra_dma()	0
+#define	is_inventra_dma(musb)	0
 #endif
 
 #ifdef CONFIG_USB_TI_CPPI_DMA
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 4449230..79e7ed6 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -343,7 +343,7 @@ static void txstate(struct musb *musb, struct musb_request *req)
 
 		/* MUSB_TXCSR_P_ISO is still set correctly */
 
-		if (is_inventra_dma()) {
+		if (is_inventra_dma(musb)) {
 			if (request_size < musb_ep->packet_sz)
 				musb_ep->dma->desired_mode = 0;
 			else
@@ -521,7 +521,7 @@ void musb_g_tx(struct musb *musb, u8 epnum)
 		if ((request->zero && request->length
 			&& (request->length % musb_ep->packet_sz == 0)
 			&& (request->actual == request->length))
-			|| (is_inventra_dma() && is_dma && (!dma->desired_mode ||
+			|| (is_inventra_dma(musb) && is_dma && (!dma->desired_mode ||
 				(request->actual &
 					(musb_ep->packet_sz - 1))))
 		) {
@@ -645,7 +645,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
 		len = musb_readw(epio, MUSB_RXCOUNT);
 		if (request->actual < request->length) {
 			if (is_dma_capable() &&
-				is_inventra_dma() && musb_ep->dma) {
+				is_inventra_dma(musb) && musb_ep->dma) {
 				struct dma_controller	*c;
 ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This patch passes musb pointer to tusb_dma_omap to
prepare for support of runtime tusb_dma_omap.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.c   |    2 +-
 drivers/usb/musb/musb_dma.h    |    4 ++--
 drivers/usb/musb/musb_gadget.c |    6 +++---
 drivers/usb/musb/musb_host.c   |    8 ++++----
 drivers/usb/musb/tusb6010.c    |    2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 4544609..43718df 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1709,7 +1709,7 @@ void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
 	/* called with controller lock already held */
 
 	if (!epnum) {
-		if (!tusb_dma_omap() && !is_cppi_enabled()) {
+		if (!tusb_dma_omap(musb) && !is_cppi_enabled()) {
 			/* endpoint 0 */
 			if (devctl & MUSB_DEVCTL_HM)
 				musb_h_ep0_irq(musb);
diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index 7a7fb27..aa1ee04 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -81,9 +81,9 @@ struct musb_hw_ep;
 #endif
 
 #ifdef CONFIG_USB_TUSB_OMAP_DMA
-#define tusb_dma_omap()			1
+#define tusb_dma_omap(musb)			1
 #else
-#define tusb_dma_omap()			0
+#define tusb_dma_omap(musb)			0
 #endif
 
 /* Anomaly 05000456 - USB Receive Interrupt Is Not Generated in DMA Mode 1
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 79e7ed6..5ee6fcb 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -414,7 +414,7 @@ static void txstate(struct musb *musb, struct musb_request *req)
 				musb_writew(epio, MUSB_TXCSR, csr);
 				/* invariant: prequest->buf is non-null */
 			}
-		} else if (tusb_dma_omap()) {
+		} else if (tusb_dma_omap(musb)) {
 			use_dma = use_dma && c->channel_program(
 					musb_ep->dma, musb_ep->packet_sz,
 					request->zero,
@@ ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

This patch passes musb pointer to is_cppi_enabled to
prepare for support of runtime is_cppi_enabled.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/davinci.c     |    2 +-
 drivers/usb/musb/musb_core.c   |    2 +-
 drivers/usb/musb/musb_dma.h    |    4 ++--
 drivers/usb/musb/musb_gadget.c |    4 ++--
 drivers/usb/musb/musb_host.c   |   10 +++++-----
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index b0f5101..7f339cf 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -291,7 +291,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
 	 * mask, state, "vector", and EOI registers.
 	 */
 	cppi = container_of(musb->dma_controller, struct cppi, controller);
-	if (is_cppi_enabled() && musb->dma_controller && !cppi->irq)
+	if (is_cppi_enabled(musb) && musb->dma_controller && !cppi->irq)
 		retval = cppi_interrupt(irq, __hci);
 
 	/* ack and handle non-CPPI interrupts */
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 43718df..39bebfd 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1709,7 +1709,7 @@ void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
 	/* called with controller lock already held */
 
 	if (!epnum) {
-		if (!tusb_dma_omap(musb) && !is_cppi_enabled()) {
+		if (!tusb_dma_omap(musb) && !is_cppi_enabled(musb)) {
 			/* endpoint 0 */
 			if (devctl & MUSB_DEVCTL_HM)
 				musb_h_ep0_irq(musb);
diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index aa1ee04..dbc6d3d 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -75,9 +75,9 @@ struct musb_hw_ep;
 #endif
 
 #ifdef CONFIG_USB_TI_CPPI_DMA
-#define	is_cppi_enabled()	1
+#define	is_cppi_enabled(musb)	1
 #else
-#define	is_cppi_enabled()	0
+#define	is_cppi_enabled(musb)	0
 #endif
 
 #ifdef ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

Now we can implement the three helpers below in runtime method:

	is_inventra_dma/is_cppi_enabled/tusb_dma_omap

so we can build all hw glue drivers, dma drivers and musb_hdrc into
one single binary image to support musb on mulitple machines.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.h |   19 +++++++++++++++++++
 drivers/usb/musb/musb_dma.h  |   18 ------------------
 2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index e42b20d..97b9760 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -694,4 +694,23 @@ static inline const char *get_dma_name(struct musb *musb)
 #endif
 }
 
+#ifdef CONFIG_USB_INVENTRA_DMA
+#define	is_inventra_dma(musb)	(musb->ops->flags & MUSB_GLUE_DMA_INVENTRA)
+#else
+#define	is_inventra_dma(musb)	0
+#endif
+
+#ifdef CONFIG_USB_TI_CPPI_DMA
+#define	is_cppi_enabled(musb)	(musb->ops->flags & MUSB_GLUE_DMA_CPPI)
+
+#else
+#define	is_cppi_enabled(musb)	0
+#endif
+
+#ifdef CONFIG_USB_TUSB_OMAP_DMA
+#define tusb_dma_omap(musb)			(musb->ops->flags & MUSB_GLUE_DMA_TUSB)
+#else
+#define tusb_dma_omap(musb)			0
+#endif
+
 #endif	/* __MUSB_CORE_H__ */
diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index dbc6d3d..df5a735 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -68,24 +68,6 @@ struct musb_hw_ep;
 #define	is_dma_capable()	(0)
 #endif
 
-#ifdef CONFIG_USB_INVENTRA_DMA
-#define	is_inventra_dma(musb)	1
-#else
-#define	is_inventra_dma(musb)	0
-#endif
-
-#ifdef CONFIG_USB_TI_CPPI_DMA
-#define	is_cppi_enabled(musb)	1
-#else
-#define	is_cppi_enabled(musb)	0
-#endif
-
-#ifdef CONFIG_USB_TUSB_OMAP_DMA
-#define tusb_dma_omap(musb)			1
-#else
-#define tusb_dma_omap(musb)			0
-#endif
-
 /* Anomaly 05000456 - USB Receive Interrupt Is Not Generated in DMA Mode 1
  *	Only allow DMA mode 1 to be used when ...
From: tom.leiming
Date: Sunday, December 12, 2010 - 10:02 am

From: Ming Lei <tom.leiming@gmail.com>

If only one DMA type for musb is defined, we always use
this DMA type.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/usb/musb/musb_core.h |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 97b9760..e233678 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -695,20 +695,31 @@ static inline const char *get_dma_name(struct musb *musb)
 }
 
 #ifdef CONFIG_USB_INVENTRA_DMA
+#if !defined(CONFIG_USB_TI_CPPI_DMA) && !defined(CONFIG_USB_TUSB_OMAP_DMA)
+#define	is_inventra_dma(musb)	1
+#else
 #define	is_inventra_dma(musb)	(musb->ops->flags & MUSB_GLUE_DMA_INVENTRA)
+#endif
 #else
 #define	is_inventra_dma(musb)	0
 #endif
 
 #ifdef CONFIG_USB_TI_CPPI_DMA
+#if !defined(CONFIG_USB_INVENTRA_DMA) && !defined(CONFIG_USB_TUSB_OMAP_DMA)
+#define	is_cppi_enabled(musb)	1
+#else
 #define	is_cppi_enabled(musb)	(musb->ops->flags & MUSB_GLUE_DMA_CPPI)
-
+#endif
 #else
 #define	is_cppi_enabled(musb)	0
 #endif
 
 #ifdef CONFIG_USB_TUSB_OMAP_DMA
+#if !defined(CONFIG_USB_INVENTRA_DMA) && !defined(CONFIG_USB_TI_CPPI_DMA)
+#define tusb_dma_omap(musb)			1
+#else
 #define tusb_dma_omap(musb)			(musb->ops->flags & MUSB_GLUE_DMA_TUSB)
+#endif
 #else
 #define tusb_dma_omap(musb)			0
 #endif
-- 
1.7.3

--

From: Sergei Shtylyov
Date: Monday, December 13, 2010 - 5:37 am

Hello.


    This doesn't really scale.

WBR, Sergei
--

From: Ming Lei
Date: Monday, December 13, 2010 - 5:48 am

Sorry, could you explain it in more detail so that I can grasp your idea?

thanks,
-- 
Lei Ming
--

From: Sergei Shtylyov
Date: Monday, December 13, 2010 - 6:00 am

Hello.


    The #if's will have to grow each time the new DMA engine is added. In 

WBR, Sergei
--

From: Felipe Balbi
Date: Monday, December 13, 2010 - 6:12 am

Hi,


I agree with you here Sergei. It's better to just split the thing to its
own platform driver and remove all ifdeferry on DMA usage.

-- 
balbi
--

From: Ming Lei
Date: Monday, December 13, 2010 - 6:40 am

As I said to Felipe in another mail, the final goal is to remove this helpers
and move all dma specific things into dma controller driver, make musb_hdrc
independent on specific dma controller.

But seems there are a not short-road to reach the goal, musb code
(musb_core.c/musb_host.c/musb_gadget.c) are very closely coupled with
specific DMA controller by the config options below and the
helpers(is_cppi_enabled/tusb_dma_omap):

              CONFIG_USB_INVENTRA_DMA
              CONFIG_USB_TI_CPPI_DMA
              CONFIG_USB_TUSB_OMAP_DMA

This patch set removes all dependency on the three config options in source
code and convert them into the three helpers.  We have gone ahead towards
the final goal since removing the helpers and converting dma-specific code
into dma controller will be more easily than before after all config options
have been killed.

-- 
Lei Ming
--

From: Gupta, Ajay Kumar
Date: Monday, December 13, 2010 - 12:55 am

Ming,

Have you tested by making modules also (.ko) ?

--

From: Ming Lei
Date: Monday, December 13, 2010 - 3:18 am

Yes, of course.

root@beagleboard:~# lsmod
Module                  Size  Used by
omap2430                4255  0
musbhsdma               4295  1 omap2430



-- 
Lei Ming
--

From: Ming Lei
Date: Monday, December 13, 2010 - 3:17 am

Yes, usb mass storage and hub is tested OK with the patches when musb



-- 
Lei Ming
--

Previous thread: Re: FTDI-SIO hang on ftdi_close() by Alan Stern on Saturday, December 11, 2010 - 1:20 pm. (2 messages)

Next thread: Re: [PATCH 21/28] usb: musb: print dma type in runtime way by David Brownell on Sunday, December 12, 2010 - 12:53 pm. (2 messages)