From patchwork Tue May 7 09:50:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: manjunath.goudar@linaro.org X-Patchwork-Id: 16727 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f197.google.com (mail-ve0-f197.google.com [209.85.128.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 81E4F238FD for ; Tue, 7 May 2013 09:51:42 +0000 (UTC) Received: by mail-ve0-f197.google.com with SMTP id jz10sf542302veb.8 for ; Tue, 07 May 2013 02:51:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=1xPof5mp65gfP1sgAuXTnJlJ+RngwMgdiVEm4aEMr8E=; b=OaBcZwqCRoNsq/NlzhKOjvQEaoYboiesgFgAJQeT5/P8DlYT7tlm+GR8TIrgXoybtY NYbARC+P/8ZI9P62BQkR+bnSdc2hDxd61QLHorXDJZHQ+y6e3zEJQv/I6y2HynADOEFu E5wnjzP6IVHYUyu+ZKUZ2LGacrc8RZlx4vDX97n5wtoQExv6+6OwZ54e19Q9bKVe+pCI LTcbOp4F5AE4xhNA9V+OwddThXjgHEJFYHwUj19HDKTGQXFLpimL0LOlXSB49QYW5pPJ uJ2IJPZZgd5Ah2BPOZ/3dwtVX2JK8JdFIoZoNyNjmG9sVrWiUvVA+ez6uqIt/QaW/nWB 3smA== X-Received: by 10.236.140.99 with SMTP id d63mr894758yhj.6.1367920283822; Tue, 07 May 2013 02:51:23 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.34.211 with SMTP id b19ls199441qej.88.gmail; Tue, 07 May 2013 02:51:23 -0700 (PDT) X-Received: by 10.220.237.193 with SMTP id kp1mr633023vcb.68.1367920283529; Tue, 07 May 2013 02:51:23 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id iz8si11892477vdb.71.2013.05.07.02.51.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 May 2013 02:51:23 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id gd11so295609vcb.28 for ; Tue, 07 May 2013 02:51:23 -0700 (PDT) X-Received: by 10.52.69.109 with SMTP id d13mr555457vdu.75.1367920283178; Tue, 07 May 2013 02:51:23 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp90977veb; Tue, 7 May 2013 02:51:22 -0700 (PDT) X-Received: by 10.67.10.4 with SMTP id dw4mr1938852pad.177.1367920281960; Tue, 07 May 2013 02:51:21 -0700 (PDT) Received: from mail-pd0-f171.google.com (mail-pd0-f171.google.com [209.85.192.171]) by mx.google.com with ESMTPS id pt5si13667642pac.243.2013.05.07.02.51.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 May 2013 02:51:21 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.171 is neither permitted nor denied by best guess record for domain of manjunath.goudar@linaro.org) client-ip=209.85.192.171; Received: by mail-pd0-f171.google.com with SMTP id r11so291264pdi.16 for ; Tue, 07 May 2013 02:51:21 -0700 (PDT) X-Received: by 10.68.25.233 with SMTP id f9mr1491220pbg.118.1367920281550; Tue, 07 May 2013 02:51:21 -0700 (PDT) Received: from manjunath-Latitude-E6420.LGE.NET ([203.247.149.152]) by mx.google.com with ESMTPSA id to7sm29745373pab.0.2013.05.07.02.51.15 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 May 2013 02:51:20 -0700 (PDT) From: Manjunath Goudar To: linux-usb@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, patches@linaro.org, stern@rowland.harvard.edu, arnd@linaro.org, gregkh@linuxfoundation.org, Manjunath Goudar , Arnd Bergmann , Greg KH Subject: [RFC PATCH 1/2] USB: OHCI: prepare to make ohci-hcd a library module Date: Tue, 7 May 2013 15:20:52 +0530 Message-Id: <1367920253-15207-2-git-send-email-manjunath.goudar@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1367920253-15207-1-git-send-email-manjunath.goudar@linaro.org> References: <1365746856-7772-2-git-send-email-manjunath.goudar@linaro.org> <1367920253-15207-1-git-send-email-manjunath.goudar@linaro.org> X-Gm-Message-State: ALoCoQksyPQ/k7cGOZYEGjTd+PKd3LFnUnDmwyKfETVCrkd6XeTuc5Re5Vv3B5XSktfrN/uzYnPF X-Original-Sender: manjunath.goudar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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_restart(),ohci_suspend() and ohci_resume() routines need to be EXPORTed for use by the drivers. In V2: -ohci_hcd_init(), ohci_run() and ohci_stop revert back to static routine. -ohci_setup() and ohci_start() functions written to generic OHCI initialization for all ohci bus glue. Signed-off-by: Manjunath Goudar Cc: Arnd Bergmann Cc: Greg KH Cc: Alan Stern Cc: linux-usb@vger.kernel.org --- drivers/usb/host/Makefile | 2 + drivers/usb/host/ohci-hcd.c | 123 +++++++++++++++++++++++++++++++++----- drivers/usb/host/ohci-pci.c | 2 +- drivers/usb/host/ohci-platform.c | 2 +- drivers/usb/host/ohci.h | 30 +++++++++- 5 files changed, 138 insertions(+), 21 deletions(-) diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 58c14c1..a38d76b 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile @@ -40,7 +40,9 @@ obj-$(CONFIG_USB_EHCI_TEGRA) +=ehci-tegra.o obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o obj-$(CONFIG_USB_ISP1362_HCD) += isp1362-hcd.o + obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o + obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o obj-$(CONFIG_USB_FHCI_HCD) += fhci.o obj-$(CONFIG_USB_XHCI_HCD) += xhci-hcd.o diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index 9e6de95..7922c61 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 - +static void ohci_stop(struct usb_hcd *hcd); #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); /*-------------------------------------------------------------------------*/ @@ -597,11 +592,11 @@ static int ohci_init (struct ohci_hcd *ohci) * resets USB and controller * enable interrupts */ -static int ohci_run (struct ohci_hcd *ohci) +static int ohci_run(struct usb_hcd *hcd) { + struct ohci_hcd *ohci = hcd_to_ohci(hcd); u32 mask, val; int first = ohci->fminterval == 0; - struct usb_hcd *hcd = ohci_to_hcd(ohci); ohci->rh_state = OHCI_RH_HALTED; @@ -767,7 +762,37 @@ retry: return 0; } +/*------------------------------------------------------------------------*/ + +/* ohci generic function for all OHCI bus glue */ + +static int ohci_setup(struct usb_hcd *hcd) +{ + struct ohci_hcd *ohci = hcd_to_ohci(hcd); + int retval; + + ohci->sbrn = HCD_USB11; + + /* data structure init */ + retval = ohci_init(ohci); + if (retval) + return retval; + ohci_usb_reset(ohci); + return 0; +} +static int ohci_start(struct usb_hcd *hcd) +{ + struct ohci_hcd *ohci = hcd_to_ohci(hcd); + int ret; + ret = ohci_run(hcd); + if (ret < 0) { + ohci_err(ohci, "can't start\n"); + ohci_stop(hcd); + } + return ret; +} +/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/ /* an interrupt happens */ @@ -949,11 +974,12 @@ 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; struct urb_priv *priv; + struct usb_hcd *hcd; spin_lock_irq(&ohci->lock); ohci->rh_state = OHCI_RH_HALTED; @@ -1001,19 +1027,22 @@ static int ohci_restart (struct ohci_hcd *ohci) ohci->ed_controltail = NULL; ohci->ed_bulktail = NULL; - if ((temp = ohci_run (ohci)) < 0) { - ohci_err (ohci, "can't restart, %d\n", temp); + hcd = ohci_to_hcd(ohci); + temp = ohci_run(hcd); + if (temp < 0) { + ohci_err(ohci, "can't restart, %d\n", temp); return temp; } 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 +1060,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 +1110,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 + */ + .reset = ohci_setup, + .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-pci.c b/drivers/usb/host/ohci-pci.c index 951514e..0b34b59 100644 --- a/drivers/usb/host/ohci-pci.c +++ b/drivers/usb/host/ohci-pci.c @@ -288,7 +288,7 @@ static int ohci_pci_start (struct usb_hcd *hcd) } #endif /* CONFIG_PM */ - ret = ohci_run (ohci); + ret = ohci_run(hcd); if (ret < 0) { ohci_err (ohci, "can't start\n"); ohci_stop (hcd); diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c index c3e7287..545c657 100644 --- a/drivers/usb/host/ohci-platform.c +++ b/drivers/usb/host/ohci-platform.c @@ -46,7 +46,7 @@ static int ohci_platform_start(struct usb_hcd *hcd) struct ohci_hcd *ohci = hcd_to_ohci(hcd); int err; - err = ohci_run(ohci); + err = ohci_run(hcd); if (err < 0) { ohci_err(ohci, "can't start\n"); ohci_stop(hcd); diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h index d329914..455e9b1 100644 --- a/drivers/usb/host/ohci.h +++ b/drivers/usb/host/ohci.h @@ -357,7 +357,6 @@ struct ohci_hcd { * I/O memory used to communicate with the HC (dma-consistent) */ struct ohci_regs __iomem *regs; - /* * main memory used to communicate with the HC (dma-consistent). * hcd adds to schedule for a live hc any time, but removals finish @@ -373,7 +372,6 @@ struct ohci_hcd { struct ed *periodic [NUM_INTS]; /* shadow int_table */ void (*start_hnp)(struct ohci_hcd *ohci); - /* * memory management for queue data structures */ @@ -392,7 +390,7 @@ struct ohci_hcd { unsigned long next_statechange; /* suspend/resume */ u32 fminterval; /* saved register */ unsigned autostop:1; /* rh auto stopping/stopped */ - + u8 sbrn; unsigned long flags; /* for HC bugs */ #define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */ #define OHCI_QUIRK_SUPERIO 0x02 /* natsemi */ @@ -718,3 +716,29 @@ 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_init(struct ohci_hcd *ohci); +extern int ohci_restart(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); +#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