diff mbox

[1/2] USB: OHCI: prepare to make ohci-hcd a library module

Message ID 1365746856-7772-2-git-send-email-manjunath.goudar@linaro.org
State New
Headers show

Commit Message

manjunath.goudar@linaro.org April 12, 2013, 6:07 a.m. UTC
This patch prepares ohci-hcd for being split up into a core
library and separate platform driver modules.  A generic
ohci_hc_driver structure is created, containing all the "standard"
values, and a new mechanism is added whereby a driver module can
specify a set of overrides to those values.  In addition the
ohci_init(),ohci_restart(),ohci_hcd_init(),ohci_run() ohci_stop(),
ohci_suspend() and ohci_resume() routines need to be EXPORTed
for use by the drivers.

Signed-off-by: Manjunath Goudar <manjunath.goudar@linaro.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg KH <greg@kroah.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: linux-usb@vger.kernel.org
---
 drivers/usb/host/ohci-hcd.c |   90 +++++++++++++++++++++++++++++++++++--------
 drivers/usb/host/ohci-mem.c |    2 +-
 drivers/usb/host/ohci.h     |   24 ++++++++++++
 3 files changed, 98 insertions(+), 18 deletions(-)

Comments

Arnd Bergmann April 12, 2013, 11:11 a.m. UTC | #1
On Friday 12 April 2013, Manjunath Goudar wrote:
> This patch prepares ohci-hcd for being split up into a core
> library and separate platform driver modules.  A generic
> ohci_hc_driver structure is created, containing all the "standard"
> values, and a new mechanism is added whereby a driver module can
> specify a set of overrides to those values.  In addition the
> ohci_init(),ohci_restart(),ohci_hcd_init(),ohci_run() ohci_stop(),
> ohci_suspend() and ohci_resume() routines need to be EXPORTed
> for use by the drivers.
> 
> Signed-off-by: Manjunath Goudar <manjunath.goudar@linaro.org>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Greg KH <greg@kroah.com>
> Cc: Alan Stern <stern@rowland.harvard.edu>
> Cc: linux-usb@vger.kernel.org

Looks pretty good as far as I can tell. A few comments:

>  static void sb800_prefetch(struct ohci_hcd *ohci, int on);
> @@ -520,7 +514,7 @@ done:
>  
>  /* init memory, and kick BIOS/SMM off */
>  
> -static int ohci_init (struct ohci_hcd *ohci)
> +int ohci_init(struct ohci_hcd *ohci)
>  {
>  	int ret;
>  	struct usb_hcd *hcd = ohci_to_hcd(ohci);

Doesn't this need to be exported?

> @@ -597,7 +591,7 @@ static int ohci_init (struct ohci_hcd *ohci)
>   * resets USB and controller
>   * enable interrupts
>   */
> -static int ohci_run (struct ohci_hcd *ohci)
> +int ohci_run(struct ohci_hcd *ohci)
>  {
>  	u32			mask, val;
>  	int			first = ohci->fminterval == 0;
> @@ -767,7 +761,7 @@ retry:
>  
>  	return 0;
>  }
> -
> +EXPORT_SYMBOL_GPL(ohci_run);
>  /*-------------------------------------------------------------------------*/
>  
>  /* an interrupt happens */

Please leave a  blank line before the /*---------
when you add an export here and in the other cases.
> diff --git a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c
> index 2f20d3d..d44867b 100644
> --- a/drivers/usb/host/ohci-mem.c
> +++ b/drivers/usb/host/ohci-mem.c
> @@ -23,7 +23,7 @@
>  
>  /*-------------------------------------------------------------------------*/
>  
> -static void ohci_hcd_init (struct ohci_hcd *ohci)
> +void ohci_hcd_init (struct ohci_hcd *ohci)
>  {
>  	ohci->next_statechange = jiffies;
>  	spin_lock_init (&ohci->lock);

Export?

> +extern void	ohci_init_driver(struct hc_driver *drv,
> +				const struct ohci_driver_overrides *over);
> +extern int ohci_init (struct ohci_hcd *ohci);
> +extern void ohci_stop (struct usb_hcd *hcd);
> +extern void ohci_hcd_init (struct ohci_hcd *ohci);
> +extern int ohci_run (struct ohci_hcd *ohci);
> +#if defined(CONFIG_PM) || defined(CONFIG_PCI)
> +extern int ohci_restart (struct ohci_hcd *ohci);
> +#endif
> +
> +#ifdef CONFIG_PM
> +extern int	ohci_suspend(struct usb_hcd *hcd, bool do_wakeup);
> +extern int	ohci_resume(struct usb_hcd *hcd, bool hibernated);
> +#endif	/* CONFIG_PM */

I would generally not enclose declarations in #ifdef, unless you
have to provide an inline alternative in the #else path.

	Arnd
manjunath.goudar@linaro.org April 15, 2013, 11:48 a.m. UTC | #2
On 12 April 2013 16:41, Arnd Bergmann <arnd@linaro.org> wrote:

> On Friday 12 April 2013, Manjunath Goudar wrote:
> > This patch prepares ohci-hcd for being split up into a core
> > library and separate platform driver modules.  A generic
> > ohci_hc_driver structure is created, containing all the "standard"
> > values, and a new mechanism is added whereby a driver module can
> > specify a set of overrides to those values.  In addition the
> > ohci_init(),ohci_restart(),ohci_hcd_init(),ohci_run() ohci_stop(),
> > ohci_suspend() and ohci_resume() routines need to be EXPORTed
> > for use by the drivers.
> >
> > Signed-off-by: Manjunath Goudar <manjunath.goudar@linaro.org>
> > Cc: Arnd Bergmann <arnd@arndb.de>
> > Cc: Greg KH <greg@kroah.com>
> > Cc: Alan Stern <stern@rowland.harvard.edu>
> > Cc: linux-usb@vger.kernel.org
>
> Looks pretty good as far as I can tell. A few comments:
>
> >  static void sb800_prefetch(struct ohci_hcd *ohci, int on);
> > @@ -520,7 +514,7 @@ done:
> >
> >  /* init memory, and kick BIOS/SMM off */
> >
> > -static int ohci_init (struct ohci_hcd *ohci)
> > +int ohci_init(struct ohci_hcd *ohci)
> >  {
> >       int ret;
> >       struct usb_hcd *hcd = ohci_to_hcd(ohci);
>
> Doesn't this need to be exported?
>
> > @@ -597,7 +591,7 @@ static int ohci_init (struct ohci_hcd *ohci)
> >   * resets USB and controller
> >   * enable interrupts
> >   */
> > -static int ohci_run (struct ohci_hcd *ohci)
> > +int ohci_run(struct ohci_hcd *ohci)
> >  {
> >       u32                     mask, val;
> >       int                     first = ohci->fminterval == 0;
> > @@ -767,7 +761,7 @@ retry:
> >
> >       return 0;
> >  }
> > -
> > +EXPORT_SYMBOL_GPL(ohci_run);
> >
>  /*-------------------------------------------------------------------------*/
> >
> >  /* an interrupt happens */
>
> Please leave a  blank line before the /*---------
> when you add an export here and in the other cases.
> > diff --git a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c
> > index 2f20d3d..d44867b 100644
> > --- a/drivers/usb/host/ohci-mem.c
> > +++ b/drivers/usb/host/ohci-mem.c
> > @@ -23,7 +23,7 @@
> >
> >
>  /*-------------------------------------------------------------------------*/
> >
> > -static void ohci_hcd_init (struct ohci_hcd *ohci)
> > +void ohci_hcd_init (struct ohci_hcd *ohci)
> >  {
> >       ohci->next_statechange = jiffies;
> >       spin_lock_init (&ohci->lock);
>
> Export?
>
> > +extern void  ohci_init_driver(struct hc_driver *drv,
> > +                             const struct ohci_driver_overrides *over);
> > +extern int ohci_init (struct ohci_hcd *ohci);
> > +extern void ohci_stop (struct usb_hcd *hcd);
> > +extern void ohci_hcd_init (struct ohci_hcd *ohci);
> > +extern int ohci_run (struct ohci_hcd *ohci);
> > +#if defined(CONFIG_PM) || defined(CONFIG_PCI)
> > +extern int ohci_restart (struct ohci_hcd *ohci);
> > +#endif
> > +
> > +#ifdef CONFIG_PM
> > +extern int   ohci_suspend(struct usb_hcd *hcd, bool do_wakeup);
> > +extern int   ohci_resume(struct usb_hcd *hcd, bool hibernated);
> > +#endif       /* CONFIG_PM */
>
> I would generally not enclose declarations in #ifdef, unless you
> have to provide an inline alternative in the #else path.
>
>
Then what is your suggestion ?


>         Arnd
>
Arnd Bergmann April 15, 2013, 12:29 p.m. UTC | #3
On Monday 15 April 2013, Manjunath Goudar wrote:
> > > +
> > > +#ifdef CONFIG_PM
> > > +extern int   ohci_suspend(struct usb_hcd *hcd, bool do_wakeup);
> > > +extern int   ohci_resume(struct usb_hcd *hcd, bool hibernated);
> > > +#endif       /* CONFIG_PM */
> >
> > I would generally not enclose declarations in #ifdef, unless you
> > have to provide an inline alternative in the #else path.
> >
> >
> Then what is your suggestion ?
> 

Remove the #ifdef.

	Arnd
manjunath.goudar@linaro.org April 30, 2013, 12:47 p.m. UTC | #4
This series of patches begins the process of splitting ohci-hcd up into 
a core library module and multiple independent platform-specific driver 
modules.  The purpose of this change is to allow people and 
distributions to build systems that support more than one platform 
driver for OHCI (not counting PCI and a handful of others).

Patch 1/3 prepares the way by exporting a few functions from ohci-hcd
and adding a new mechanism for platform-specific drivers to initialize
their hc_driver structures.  This deserves to be done in the core
because almost all of the entries in these structures are pure
boilerplate -- practically none of the drivers need to override more
than three of the standard core values.

Patch 2/3  separate out ohci-pci into independent driver modules. 


Manjunath Goudar (2):
  USB: OHCI: prepare to make ohci-hcd a library module
  USB: OHCI: make ohci-pci a separate driver

 drivers/usb/host/Kconfig         |    7 +-
 drivers/usb/host/Makefile        |    3 +
 drivers/usb/host/ohci-hcd.c      |  130 ++++++++++++++++++++++++++++----------
 drivers/usb/host/ohci-pci.c      |  130 ++++++++++++--------------------------
 drivers/usb/host/ohci-platform.c |    2 +-
 drivers/usb/host/ohci-q.c        |   13 ++++
 drivers/usb/host/ohci.h          |   31 ++++++++-
 7 files changed, 185 insertions(+), 131 deletions(-)
manjunath.goudar@linaro.org May 10, 2013, 5:26 a.m. UTC | #5
This series of patches begins the process of splitting ohci-hcd up into
a core library module and independent pci driver modules.

Patch 1/2 prepares the way by exporting a few functions from ohci-hcd
and adding a new mechanism for platform-specific drivers to initialize
their hc_driver structures.  This deserves to be done in the core
because almost all of the entries in these structures are pure
boilerplate -- practically none of the drivers need to override more
than three of the standard core values.

Patch 2/2  separate out ohci-pci into independent driver modules.
 


Manjunath Goudar (2):
  USB: OHCI: prepare to make ohci-hcd a library module
  USB: OHCI: make ohci-pci a separate driver

 drivers/usb/host/Kconfig    |    9 ++-
 drivers/usb/host/Makefile   |    3 +
 drivers/usb/host/ohci-hcd.c |  122 ++++++++++++++++++++++++++++++--------
 drivers/usb/host/ohci-hub.c |    1 -
 drivers/usb/host/ohci-pci.c |  136 ++++++++++++-------------------------------
 drivers/usb/host/ohci-q.c   |   13 +++++
 drivers/usb/host/ohci.h     |   16 +++++
 7 files changed, 173 insertions(+), 127 deletions(-)
manjunath.goudar@linaro.org May 15, 2013, 5:18 a.m. UTC | #6
This series of patches begins the process of splitting ohci-hcd up into
a core library module and independent pci driver modules.

Patch 1/2 prepares the way by exporting a few functions from ohci-hcd
and adding a new mechanism for platform-specific drivers to initialize
their hc_driver structures.  This deserves to be done in the core
because almost all of the entries in these structures are pure
boilerplate -- practically none of the drivers need to override more
than three of the standard core values.

Patch 2/2  separate out ohci-pci into independent driver modules.
 


Manjunath Goudar (2):
  USB: OHCI: prepare to make ohci-hcd a library module
  USB: OHCI: make ohci-pci a separate driver

 drivers/usb/host/Kconfig    |    4 +-
 drivers/usb/host/Makefile   |    3 +
 drivers/usb/host/ohci-hcd.c |  119 +++++++++++++++++++++++++++------------
 drivers/usb/host/ohci-pci.c |  130 +++++++++++++------------------------------
 drivers/usb/host/ohci-q.c   |   19 +++++++
 drivers/usb/host/ohci.h     |   17 ++++++
 6 files changed, 163 insertions(+), 129 deletions(-)
manjunath.goudar@linaro.org May 20, 2013, 12:14 p.m. UTC | #7
This series of patches begins the process of splitting ohci-hcd up into
a core library module and independent pci driver modules.

Patch 1/2 prepares the way by exporting a few functions from ohci-hcd
and adding a new mechanism for platform-specific drivers to initialize
their hc_driver structures.  This deserves to be done in the core
because almost all of the entries in these structures are pure
boilerplate -- practically none of the drivers need to override more
than three of the standard core values.

Patch 2/2  separate out ohci-pci into independent driver modules.

Manjunath Goudar (2):
  USB: OHCI: prepare to make ohci-hcd a library module
  USB: OHCI: make ohci-pci a separate driver

 drivers/usb/host/Kconfig      |    4 +-
 drivers/usb/host/Makefile     |    3 +
 drivers/usb/host/ohci-hcd.c   |  130 +++++++++++++++++++++++++++-----------
 drivers/usb/host/ohci-hub.c   |    1 -
 drivers/usb/host/ohci-pci.c   |  140 +++++++++++++----------------------------
 drivers/usb/host/ohci-q.c     |    2 +
 drivers/usb/host/ohci.h       |   21 +++++++
 drivers/usb/host/pci-quirks.c |   18 +++++-
 drivers/usb/host/pci-quirks.h |    3 +
 9 files changed, 187 insertions(+), 135 deletions(-)
manjunath.goudar@linaro.org May 20, 2013, 12:19 p.m. UTC | #8
This series of patches begins the process of splitting ohci-hcd up into
a core library module and independent pci driver modules.

Patch 1/2 prepares the way by exporting a few functions from ohci-hcd
and adding a new mechanism for platform-specific drivers to initialize
their hc_driver structures.  This deserves to be done in the core
because almost all of the entries in these structures are pure
boilerplate -- practically none of the drivers need to override more
than three of the standard core values.

Patch 2/2  separate out ohci-pci into independent driver modules.

Manjunath Goudar (2):
  USB: OHCI: prepare to make ohci-hcd a library module
  USB: OHCI: make ohci-pci a separate driver

 drivers/usb/host/Kconfig      |    4 +-
 drivers/usb/host/Makefile     |    3 +
 drivers/usb/host/ohci-hcd.c   |  130 +++++++++++++++++++++++++++-----------
 drivers/usb/host/ohci-hub.c   |    1 -
 drivers/usb/host/ohci-pci.c   |  140 +++++++++++++----------------------------
 drivers/usb/host/ohci-q.c     |    2 +
 drivers/usb/host/ohci.h       |   21 +++++++
 drivers/usb/host/pci-quirks.c |   18 +++++-
 drivers/usb/host/pci-quirks.h |    3 +
 9 files changed, 187 insertions(+), 135 deletions(-)
diff mbox

Patch

diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 9e6de95..0c1646b 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -79,12 +79,6 @@  static const char	hcd_name [] = "ohci_hcd";
 #include "pci-quirks.h"
 
 static void ohci_dump (struct ohci_hcd *ohci, int verbose);
-static int ohci_init (struct ohci_hcd *ohci);
-static void ohci_stop (struct usb_hcd *hcd);
-
-#if defined(CONFIG_PM) || defined(CONFIG_PCI)
-static int ohci_restart (struct ohci_hcd *ohci);
-#endif
 
 #ifdef CONFIG_PCI
 static void sb800_prefetch(struct ohci_hcd *ohci, int on);
@@ -520,7 +514,7 @@  done:
 
 /* init memory, and kick BIOS/SMM off */
 
-static int ohci_init (struct ohci_hcd *ohci)
+int ohci_init(struct ohci_hcd *ohci)
 {
 	int ret;
 	struct usb_hcd *hcd = ohci_to_hcd(ohci);
@@ -597,7 +591,7 @@  static int ohci_init (struct ohci_hcd *ohci)
  * resets USB and controller
  * enable interrupts
  */
-static int ohci_run (struct ohci_hcd *ohci)
+int ohci_run(struct ohci_hcd *ohci)
 {
 	u32			mask, val;
 	int			first = ohci->fminterval == 0;
@@ -767,7 +761,7 @@  retry:
 
 	return 0;
 }
-
+EXPORT_SYMBOL_GPL(ohci_run);
 /*-------------------------------------------------------------------------*/
 
 /* an interrupt happens */
@@ -914,7 +908,7 @@  static irqreturn_t ohci_irq (struct usb_hcd *hcd)
 
 /*-------------------------------------------------------------------------*/
 
-static void ohci_stop (struct usb_hcd *hcd)
+void ohci_stop(struct usb_hcd *hcd)
 {
 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
 
@@ -943,13 +937,13 @@  static void ohci_stop (struct usb_hcd *hcd)
 		ohci->hcca_dma = 0;
 	}
 }
-
+EXPORT_SYMBOL_GPL(ohci_stop);
 /*-------------------------------------------------------------------------*/
 
 #if defined(CONFIG_PM) || defined(CONFIG_PCI)
 
 /* must not be called from interrupt context */
-static int ohci_restart (struct ohci_hcd *ohci)
+int ohci_restart(struct ohci_hcd *ohci)
 {
 	int temp;
 	int i;
@@ -1008,12 +1002,12 @@  static int ohci_restart (struct ohci_hcd *ohci)
 	ohci_dbg(ohci, "restart complete\n");
 	return 0;
 }
-
+EXPORT_SYMBOL_GPL(ohci_restart);
 #endif
 
 #ifdef CONFIG_PM
 
-static int __maybe_unused ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
+int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
 {
 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd);
 	unsigned long	flags;
@@ -1031,9 +1025,9 @@  static int __maybe_unused ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(ohci_suspend);
 
-
-static int __maybe_unused ohci_resume(struct usb_hcd *hcd, bool hibernated)
+int ohci_resume(struct usb_hcd *hcd, bool hibernated)
 {
 	struct ohci_hcd		*ohci = hcd_to_ohci(hcd);
 	int			port;
@@ -1081,11 +1075,73 @@  static int __maybe_unused ohci_resume(struct usb_hcd *hcd, bool hibernated)
 
 	return 0;
 }
-
+EXPORT_SYMBOL_GPL(ohci_resume);
 #endif
 
 /*-------------------------------------------------------------------------*/
 
+/*
+ * Generic structure: This gets copied for platform drivers so that
+ * individual entries can be overridden as needed.
+ */
+
+static const struct hc_driver ohci_hc_driver = {
+	.description =          hcd_name,
+	.product_desc =         "OHCI Host Controller",
+	.hcd_priv_size =        sizeof(struct ohci_hcd),
+
+	/*
+	 * generic hardware linkage
+	*/
+	.irq =                  ohci_irq,
+	.flags =                HCD_MEMORY | HCD_USB11,
+
+	/*
+	* basic lifecycle operations
+	*/
+	.start =                ohci_run,
+	.stop =                 ohci_stop,
+	.shutdown =             ohci_shutdown,
+
+	/*
+	 * managing i/o requests and associated device resources
+	*/
+	.urb_enqueue =          ohci_urb_enqueue,
+	.urb_dequeue =          ohci_urb_dequeue,
+	.endpoint_disable =     ohci_endpoint_disable,
+
+	/*
+	* scheduling support
+	*/
+	.get_frame_number =     ohci_get_frame,
+
+	/*
+	* root hub support
+	*/
+	.hub_status_data =      ohci_hub_status_data,
+	.hub_control =          ohci_hub_control,
+	.bus_suspend =          ohci_bus_suspend,
+	.bus_resume =           ohci_bus_resume,
+	.start_port_reset =	ohci_start_port_reset,
+};
+
+void ohci_init_driver(struct hc_driver *drv,
+		const struct ohci_driver_overrides *over)
+{
+	/* Copy the generic table to drv and then apply the overrides */
+	*drv = ohci_hc_driver;
+
+	drv->product_desc = over->product_desc;
+	drv->hcd_priv_size += over->extra_priv_size;
+	if (over->reset)
+		drv->reset = over->reset;
+	if (over->start)
+		drv->start = over->start;
+}
+EXPORT_SYMBOL_GPL(ohci_init_driver);
+
+/*-------------------------------------------------------------------------*/
+
 MODULE_AUTHOR (DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE ("GPL");
diff --git a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c
index 2f20d3d..d44867b 100644
--- a/drivers/usb/host/ohci-mem.c
+++ b/drivers/usb/host/ohci-mem.c
@@ -23,7 +23,7 @@ 
 
 /*-------------------------------------------------------------------------*/
 
-static void ohci_hcd_init (struct ohci_hcd *ohci)
+void ohci_hcd_init (struct ohci_hcd *ohci)
 {
 	ohci->next_statechange = jiffies;
 	spin_lock_init (&ohci->lock);
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index d329914..d62ba8c 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -718,3 +718,27 @@  static inline u32 roothub_status (struct ohci_hcd *hc)
 	{ return ohci_readl (hc, &hc->regs->roothub.status); }
 static inline u32 roothub_portstatus (struct ohci_hcd *hc, int i)
 	{ return read_roothub (hc, portstatus [i], 0xffe0fce0); }
+
+/* Declarations of things exported for use by ohci platform drivers */
+
+struct ohci_driver_overrides {
+	const char	*product_desc;
+	size_t		extra_priv_size;
+	int		(*reset)(struct usb_hcd *hcd);
+	int		(*start)(struct usb_hcd *hcd);
+};
+
+extern void	ohci_init_driver(struct hc_driver *drv,
+				const struct ohci_driver_overrides *over);
+extern int ohci_init (struct ohci_hcd *ohci);
+extern void ohci_stop (struct usb_hcd *hcd);
+extern void ohci_hcd_init (struct ohci_hcd *ohci);
+extern int ohci_run (struct ohci_hcd *ohci);
+#if defined(CONFIG_PM) || defined(CONFIG_PCI)
+extern int ohci_restart (struct ohci_hcd *ohci);
+#endif
+
+#ifdef CONFIG_PM
+extern int	ohci_suspend(struct usb_hcd *hcd, bool do_wakeup);
+extern int	ohci_resume(struct usb_hcd *hcd, bool hibernated);
+#endif	/* CONFIG_PM */