diff mbox

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

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

Commit Message

manjunath.goudar@linaro.org May 15, 2013, 5:18 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_suspend() and ohci_resume() routines need
to be EXPORTed for use by the drivers.

Added ohci_start() routine for to start the generic controller rather
than each having its own idiosyncratic approach.This allow to clean
duplicated code in most of SOC driver

In V2:
 -ohci_hcd_init() ohci_run() and ohci_stop() are not made non-static.
 -Adds the ohci_setup() and ohci_start() routine.

In V3:
 -purpose of ohci_setup() and ohci_start() function description written in the patch
  description.
 -ohci_init() are not made non-static but now called beginning of the ohci_restart().
 -ohci_run() signature change reverted back.
 -unrelated changes removed.
 -duplicate comment line removed.
 -inline ohci_suspend() and ohci_resume() is not needed so removed from ohci.h file.

In V4:
 -ohci-init() EXPORTed because it is called by all bus glue modules.
 -ohci-setup() removed from 1/2 added into 2/2 patch.

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 |   93 ++++++++++++++++++++++++++++++++++++++-----
 drivers/usb/host/ohci.h     |   17 ++++++++
 2 files changed, 99 insertions(+), 11 deletions(-)

Comments

Alan Stern May 15, 2013, 3 p.m. UTC | #1
On Wed, 15 May 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_suspend() and ohci_resume() routines need
> to be EXPORTed for use by the drivers.
> 
> Added ohci_start() routine for to start the generic controller rather
> than each having its own idiosyncratic approach.This allow to clean
> duplicated code in most of SOC driver


> +/*
> + * 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_start,
> +	.stop =                 ohci_stop,
> +	.shutdown =             ohci_shutdown,

The .reset member isn't set.  That's why I think you need to create an
ohci_setup() function.  And once you have that, you probably don't need
to export ohci_init().

> +
> +	/*
> +	 * 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,

These two lines will cause a compiler error if CONFIG_PM isn't enabled.

Alan Stern
manjunath.goudar@linaro.org May 15, 2013, 4:27 p.m. UTC | #2
On 15 May 2013 20:30, Alan Stern <stern@rowland.harvard.edu> wrote:

> On Wed, 15 May 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_suspend() and ohci_resume() routines need
> > to be EXPORTed for use by the drivers.
> >
> > Added ohci_start() routine for to start the generic controller rather
> > than each having its own idiosyncratic approach.This allow to clean
> > duplicated code in most of SOC driver
>
>
>
>

> > +/*
> > + * 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_start,
> > +     .stop =                 ohci_stop,
> > +     .shutdown =             ohci_shutdown,
>
> The .reset member isn't set.  That's why I think you need to create an
> ohci_setup() function.  And once you have that, you probably don't need
> to export ohci_init().
>
>
right now ohci_init() is required to export because,it is called by all the
driver,once we separating all driver from ohci-hcd we can make static.If we
planed for ohci_init() function as static we can write below function.

/* ohci_setup routine for generic controller initialization */

static int ohci_setup(struct usb_hcd *hcd)
{
       struct ohci_hcd         *ohci = hcd_to_ohci(hcd);
       int retval;

       /* data structure init */
       retval = ohci_init(ohci);
       if (retval)
               return retval;
       return 0;
}

initially I written above function,after export ohci_init(),I feel
ohci_setup() is only calling ohci_init() nothing doing other than calling
ohci_init() function thats what ohci_init() directly calling each
individual reset() function in bus glue.

> +
> > +     /*
> > +      * 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,
>
> These two lines will cause a compiler error if CONFIG_PM isn't enabled.
>
>

This  region only I had been written

#else
static inline int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
{
       return 0;
}
static inline int ohci_resume(struct usb_hcd *hcd, bool hibernated)
{
       return 0;
}
#endif

 part in ohci.h file.

May be I am feeling else part approach is correct,what you say.

Alan Stern
>
>
Alan Stern May 15, 2013, 7:32 p.m. UTC | #3
On Wed, 15 May 2013, Manjunath Goudar wrote:

> > > +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_start,
> > > +     .stop =                 ohci_stop,
> > > +     .shutdown =             ohci_shutdown,
> >
> > The .reset member isn't set.  That's why I think you need to create an
> > ohci_setup() function.  And once you have that, you probably don't need
> > to export ohci_init().
> >
> >
> right now ohci_init() is required to export because,it is called by all the
> driver,once we separating all driver from ohci-hcd we can make static.

This sounds exactly backward.  ohci_init() is static now, and it works
because the drivers are all part of ohci-hcd.  When they are separated,
they won't be able to call ohci_init() unless it is exported.

> If we
> planed for ohci_init() function as static we can write below function.
> 
> /* ohci_setup routine for generic controller initialization */
> 
> static int ohci_setup(struct usb_hcd *hcd)
> {
>        struct ohci_hcd         *ohci = hcd_to_ohci(hcd);
>        int retval;
> 
>        /* data structure init */
>        retval = ohci_init(ohci);
>        if (retval)
>                return retval;
>        return 0;
> }

Yes, that's what we should do.  Except that (as I pointed out earlier) 
it should be written like this:

int ohci_setup(struct usb_hcd *hcd)
{
	struct ohci_hcd		*ohci = hcd_to_ohci(hcd);

	return ohci_init(ohci);
}
EXPORT_SYMBOL_GPL(ohci_setup);


> initially I written above function,after export ohci_init(),I feel
> ohci_setup() is only calling ohci_init() nothing doing other than calling
> ohci_init() function thats what ohci_init() directly calling each
> individual reset() function in bus glue.

I can't understand this.  It isn't proper English.

> > > +     /*
> > > +     * 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,
> >
> > These two lines will cause a compiler error if CONFIG_PM isn't enabled.
> >
> >
> 
> This  region only I had been written
> 
> #else
> static inline int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
> {
>        return 0;
> }
> static inline int ohci_resume(struct usb_hcd *hcd, bool hibernated)
> {
>        return 0;
> }
> #endif
> 
>  part in ohci.h file.
> 
> May be I am feeling else part approach is correct,what you say.

Don't add the static inline definitions to ohci.h.  Just do this:

#ifdef	CONFIG_PM
	.bus_suspend =		ohci_bus_suspend,
	.bus_resume =		ohci_bus_resume,
#endif

After all, that's what the glue drivers do now.

Alan Stern
diff mbox

Patch

diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 9e6de95..97faf89 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -79,13 +79,7 @@  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);
 #else
@@ -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);
@@ -590,6 +584,7 @@  static int ohci_init (struct ohci_hcd *ohci)
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(ohci_init);
 
 /*-------------------------------------------------------------------------*/
 
@@ -768,6 +763,20 @@  retry:
 	return 0;
 }
 
+/* ohci_start routine for generic controller start of all OHCI bus glue */
+static int ohci_start(struct usb_hcd *hcd)
+{
+	struct ohci_hcd		*ohci = hcd_to_ohci(hcd);
+	int	ret;
+
+	ret = ohci_run(ohci);
+	if (ret < 0) {
+		ohci_err(ohci, "can't start\n");
+		ohci_stop(hcd);
+	}
+	return ret;
+}
+
 /*-------------------------------------------------------------------------*/
 
 /* an interrupt happens */
@@ -949,7 +958,7 @@  static void ohci_stop (struct usb_hcd *hcd)
 #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 +1017,13 @@  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 +1041,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 +1091,72 @@  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_start,
+	.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;
+}
+EXPORT_SYMBOL_GPL(ohci_init_driver);
+
+/*-------------------------------------------------------------------------*/
+
 MODULE_AUTHOR (DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE ("GPL");
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index d329914..8bdcef0 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -718,3 +718,20 @@  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);
+};
+
+extern void	ohci_init_driver(struct hc_driver *drv,
+				const struct ohci_driver_overrides *over);
+extern int	ohci_restart(struct ohci_hcd *ohci);
+extern int	ohci_init(struct ohci_hcd *ohci);
+#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