From patchwork Thu Jun 13 17:24:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Warren X-Patchwork-Id: 251121 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id DE7FC2C0079 for ; Fri, 14 Jun 2013 03:24:33 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758569Ab3FMRYb (ORCPT ); Thu, 13 Jun 2013 13:24:31 -0400 Received: from avon.wwwdotorg.org ([70.85.31.133]:55765 "EHLO avon.wwwdotorg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758545Ab3FMRY3 (ORCPT ); Thu, 13 Jun 2013 13:24:29 -0400 Received: from severn.wwwdotorg.org (unknown [192.168.65.5]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by avon.wwwdotorg.org (Postfix) with ESMTPS id 2A47E63C3; Thu, 13 Jun 2013 11:33:04 -0600 (MDT) Received: from swarren-lx1.nvidia.com (localhost [127.0.0.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by severn.wwwdotorg.org (Postfix) with ESMTPSA id B09C0E4626; Thu, 13 Jun 2013 11:24:27 -0600 (MDT) From: Stephen Warren To: Greg Kroah-Hartman Cc: Felipe Balbi , Alan Stern , Manjunath Goudar , Arnd Bergmann , Venu Byravarasu , linux-usb@vger.kernel.org, linux-tegra@vger.kernel.org, Stephen Warren Subject: [PATCH V3 REPOST 6/7] USB: EHCI: make ehci-tegra a separate driver Date: Thu, 13 Jun 2013 11:24:12 -0600 Message-Id: <1371144253-21295-7-git-send-email-swarren@wwwdotorg.org> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1371144253-21295-1-git-send-email-swarren@wwwdotorg.org> References: <1371144253-21295-1-git-send-email-swarren@wwwdotorg.org> X-NVConfidentiality: public X-Virus-Scanned: clamav-milter 0.97.7 at avon.wwwdotorg.org X-Virus-Status: Clean Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Manjunath Goudar Separate the Tegra on-chip host controller driver from ehci-hcd host code so that it can be built as a separate driver module. This work is part of enabling multi-platform kernels on ARM. Signed-off-by: Manjunath Goudar [swarren, reworked Manjunath's patches to split them more logically, minor re-order of added lines to better match layout of other split-up HCD drivers and existing code, add MODULE_DEVICE_TABLE, fix MODULE_LICENSE, adapted to change in earlier patches which removed the ehci_driver_overrides addition, removed all PM code and solved circular dependencies.] Signed-off-by: Stephen Warren Acked-by: Arnd Bergmann Acked-by: Alan Stern --- v3: * Removed use of tegra_ehci_power_up() from egra_ehci_hcd_shutdown(). * Made tegra_overrides const/initconst not initdata. * Added comment re: need for overrides in ehci_tegra_init(). v2: * Set non-standard fields in tegra_ehci_hc_driver manually, rather than relying on an expanded struct ehci_driver_overrides. * Save orig_hub_control rather than relying on ehci_hub_control being exported. * Rebased on new versions of earlier patches. --- drivers/usb/host/Kconfig | 2 +- drivers/usb/host/Makefile | 1 + drivers/usb/host/ehci-hcd.c | 5 -- drivers/usb/host/ehci-tegra.c | 128 ++++++++++++++++++++++++------------------ 4 files changed, 76 insertions(+), 60 deletions(-) diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 881609e..7d0aa5f 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -198,7 +198,7 @@ config USB_EHCI_MSM has an external PHY. config USB_EHCI_TEGRA - boolean "NVIDIA Tegra HCD support" + tristate "NVIDIA Tegra HCD support" depends on ARCH_TEGRA select USB_EHCI_ROOT_HUB_TT select USB_PHY diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index b41fa5f..bea7112 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_USB_EHCI_HCD_SPEAR) += ehci-spear.o obj-$(CONFIG_USB_EHCI_S5P) += ehci-s5p.o obj-$(CONFIG_USB_EHCI_HCD_AT91) += ehci-atmel.o obj-$(CONFIG_USB_EHCI_MSM) += ehci-msm.o +obj-$(CONFIG_USB_EHCI_TEGRA) += ehci-tegra.o obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index e8a6f3d..7abf1ce 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -1269,11 +1269,6 @@ MODULE_LICENSE ("GPL"); #define PLATFORM_DRIVER ehci_hcd_msp_driver #endif -#ifdef CONFIG_USB_EHCI_TEGRA -#include "ehci-tegra.c" -#define PLATFORM_DRIVER tegra_ehci_driver -#endif - #ifdef CONFIG_SPARC_LEON #include "ehci-grlib.c" #define PLATFORM_DRIVER ehci_grlib_driver diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c index 8063429..338c8a5 100644 --- a/drivers/usb/host/ehci-tegra.c +++ b/drivers/usb/host/ehci-tegra.c @@ -17,25 +17,44 @@ */ #include +#include +#include #include -#include -#include -#include -#include #include +#include +#include +#include #include #include +#include +#include #include +#include #include #include -#include +#include +#include +#include + +#include "ehci.h" #define TEGRA_USB_BASE 0xC5000000 #define TEGRA_USB2_BASE 0xC5004000 #define TEGRA_USB3_BASE 0xC5008000 +#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) + #define TEGRA_USB_DMA_ALIGN 32 +#define DRIVER_DESC "Tegra EHCI driver" +#define DRV_NAME "tegra-ehci" + +static struct hc_driver __read_mostly tegra_ehci_hc_driver; + +static int (*orig_hub_control)(struct usb_hcd *hcd, + u16 typeReq, u16 wValue, u16 wIndex, + char *buf, u16 wLength); + struct tegra_ehci_hcd { struct ehci_hcd *ehci; struct tegra_usb_phy *phy; @@ -218,25 +237,13 @@ static int tegra_ehci_hub_control( spin_unlock_irqrestore(&ehci->lock, flags); /* Handle the hub control events here */ - return ehci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); + return orig_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); + done: spin_unlock_irqrestore(&ehci->lock, flags); return retval; } -static int tegra_ehci_setup(struct usb_hcd *hcd) -{ - struct ehci_hcd *ehci = hcd_to_ehci(hcd); - - /* EHCI registers start at offset 0x100 */ - ehci->caps = hcd->regs + 0x100; - - /* switch to host mode */ - hcd->has_tt = 1; - - return ehci_setup(hcd); -} - struct dma_aligned_buffer { void *kmalloc_ptr; void *old_xfer_buffer; @@ -316,38 +323,6 @@ static void tegra_ehci_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) free_dma_aligned_buffer(urb); } -static const struct hc_driver tegra_ehci_hc_driver = { - .description = hcd_name, - .product_desc = "Tegra EHCI Host Controller", - .hcd_priv_size = sizeof(struct ehci_hcd), - .flags = HCD_USB2 | HCD_MEMORY, - - /* standard ehci functions */ - .irq = ehci_irq, - .start = ehci_run, - .stop = ehci_stop, - .urb_enqueue = ehci_urb_enqueue, - .urb_dequeue = ehci_urb_dequeue, - .endpoint_disable = ehci_endpoint_disable, - .endpoint_reset = ehci_endpoint_reset, - .get_frame_number = ehci_get_frame, - .hub_status_data = ehci_hub_status_data, - .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, - .relinquish_port = ehci_relinquish_port, - .port_handed_over = ehci_port_handed_over, - - /* modified ehci functions for tegra */ - .reset = tegra_ehci_setup, - .shutdown = ehci_shutdown, - .map_urb_for_dma = tegra_ehci_map_urb_for_dma, - .unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma, - .hub_control = tegra_ehci_hub_control, -#ifdef CONFIG_PM - .bus_suspend = ehci_bus_suspend, - .bus_resume = ehci_bus_resume, -#endif -}; - static int setup_vbus_gpio(struct platform_device *pdev, struct tegra_ehci_platform_data *pdata) { @@ -444,6 +419,9 @@ static int tegra_ehci_probe(struct platform_device *pdev) err = -ENOMEM; goto cleanup_clk; } + tegra->ehci = hcd_to_ehci(hcd); + + hcd->has_tt = 1; hcd->phy = u_phy; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -460,6 +438,7 @@ static int tegra_ehci_probe(struct platform_device *pdev) err = -ENOMEM; goto cleanup_hcd_create; } + tegra->ehci->caps = hcd->regs + 0x100; err = usb_phy_init(hcd->phy); if (err) { @@ -482,8 +461,6 @@ static int tegra_ehci_probe(struct platform_device *pdev) goto cleanup_phy; } - tegra->ehci = hcd_to_ehci(hcd); - irq = platform_get_irq(pdev, 0); if (!irq) { dev_err(&pdev->dev, "Failed to get IRQ\n"); @@ -558,7 +535,50 @@ static struct platform_driver tegra_ehci_driver = { .remove = tegra_ehci_remove, .shutdown = tegra_ehci_hcd_shutdown, .driver = { - .name = "tegra-ehci", + .name = DRV_NAME, .of_match_table = tegra_ehci_of_match, } }; + +static const struct ehci_driver_overrides tegra_overrides __initconst = { + .extra_priv_size = sizeof(struct tegra_ehci_hcd), +}; + +static int __init ehci_tegra_init(void) +{ + if (usb_disabled()) + return -ENODEV; + + pr_info(DRV_NAME ": " DRIVER_DESC "\n"); + + ehci_init_driver(&tegra_ehci_hc_driver, &tegra_overrides); + + /* + * The Tegra HW has some unusual quirks, which require Tegra-specific + * workarounds. We override certain hc_driver functions here to + * achieve that. We explicitly do not enhance ehci_driver_overrides to + * allow this more easily, since this is an unusual case, and we don't + * want to encourage others to override these functions by making it + * too easy. + */ + + orig_hub_control = tegra_ehci_hc_driver.hub_control; + + tegra_ehci_hc_driver.map_urb_for_dma = tegra_ehci_map_urb_for_dma; + tegra_ehci_hc_driver.unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma; + tegra_ehci_hc_driver.hub_control = tegra_ehci_hub_control; + + return platform_driver_register(&tegra_ehci_driver); +} +module_init(ehci_tegra_init); + +static void __exit ehci_tegra_cleanup(void) +{ + platform_driver_unregister(&tegra_ehci_driver); +} +module_exit(ehci_tegra_cleanup); + +MODULE_DESCRIPTION(DRIVER_DESC); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:" DRV_NAME); +MODULE_DEVICE_TABLE(of, tegra_ehci_of_match);