From patchwork Tue Apr 9 22:52:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 2418241 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 0F33F3FC71 for ; Tue, 9 Apr 2013 22:53:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751808Ab3DIWxt (ORCPT ); Tue, 9 Apr 2013 18:53:49 -0400 Received: from mail-la0-f42.google.com ([209.85.215.42]:60557 "EHLO mail-la0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751100Ab3DIWxs (ORCPT ); Tue, 9 Apr 2013 18:53:48 -0400 Received: by mail-la0-f42.google.com with SMTP id fe20so6973086lab.1 for ; Tue, 09 Apr 2013 15:53:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:organization:to:subject:date:user-agent:cc :references:in-reply-to:mime-version:content-type :content-transfer-encoding:message-id:x-gm-message-state; bh=lUzDQfbpmOSkJRjBuBgwfYd8drFszy2uM4fRmTmCOrk=; b=SSqkuESFTAxqlmTR9zMlYgnS4aslJucifqfxf5VSeM3GphzII88iuWnR+gIrbLz3Zo yp1evM9DyRZJLSDZoFOlTVuYO+H9JrPaAX8wONlorkVDTeZd3k4lw9MSI3yTnft+iIaC i91G7kJyvC2r4OGHkVF/wbOZMsMfwN1eLF0AeMGB0Uvaq5LIXOYbOBwlQxobgvpPcxHs FPEedxmCphhiKhjydL8KFOoycKGAXZnA4lCodDQzlrpNC6hyQynw1w1shT3890nTos8c e6xykin/SKGEqyw6hu5C5MJQJrubx1Bpu/9ghk4Na/Wu4SucLCqtjKGGdjYVgboF7/wU XS3w== X-Received: by 10.152.134.164 with SMTP id pl4mr15110732lab.54.1365548026730; Tue, 09 Apr 2013 15:53:46 -0700 (PDT) Received: from wasted.dev.rtsoft.ru (ppp91-79-87-206.pppoe.mtu-net.ru. [91.79.87.206]) by mx.google.com with ESMTPS id op1sm1636986lbb.2.2013.04.09.15.53.44 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 09 Apr 2013 15:53:45 -0700 (PDT) From: Sergei Shtylyov Organization: Cogent Embedded To: horms@verge.net.au, magnus.damm@gmail.com, linux@arm.linux.org.uk, linux-sh@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/4] ARM: shmobile: R8A7778: add USB support Date: Wed, 10 Apr 2013 02:52:45 +0400 User-Agent: KMail/1.13.5 (Linux/2.6.32.26-175.fc12.i686.PAE; KDE/4.4.5; i686; ; ) Cc: linux-usb@vger.kernel.org References: <201304100247.22615.sergei.shtylyov@cogentembedded.com> In-Reply-To: <201304100247.22615.sergei.shtylyov@cogentembedded.com> MIME-Version: 1.0 Message-Id: <201304100252.46139.sergei.shtylyov@cogentembedded.com> X-Gm-Message-State: ALoCoQllGal0gsD8wPRg4c2lZN/wr9uPQ5CLZGf4+4pwDLWQwC07mjV/yMP9Q0GWNcGe+GC77FfK Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Add USB clock and EHCI, OHCI, and USB PHY platform devices for R8A7778 SoC; add a function to register PHY device with board-specific platform data and register EHCI and OHCI platfrom devices from the init_late() board method. Also, don't forget to enable CONFIG_ARCH_HAS_[EO]HCI options for R8A7778 SoC in Kconfig... The patch has been tested on the BOCK-W board. Signed-off-by: Sergei Shtylyov --- arch/arm/mach-shmobile/Kconfig | 2 arch/arm/mach-shmobile/clock-r8a7778.c | 4 arch/arm/mach-shmobile/include/mach/r8a7778.h | 3 arch/arm/mach-shmobile/setup-r8a7778.c | 108 ++++++++++++++++++++++++++ 4 files changed, 117 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: renesas/arch/arm/mach-shmobile/Kconfig =================================================================== --- renesas.orig/arch/arm/mach-shmobile/Kconfig +++ renesas/arch/arm/mach-shmobile/Kconfig @@ -40,6 +40,8 @@ config ARCH_R8A7778 select CPU_V7 select SH_CLK_CPG select ARM_GIC + select USB_ARCH_HAS_EHCI + select USB_ARCH_HAS_OHCI config ARCH_R8A7779 bool "R-Car H1 (R8A77790)" Index: renesas/arch/arm/mach-shmobile/clock-r8a7778.c =================================================================== --- renesas.orig/arch/arm/mach-shmobile/clock-r8a7778.c +++ renesas/arch/arm/mach-shmobile/clock-r8a7778.c @@ -59,12 +59,14 @@ static struct clk *main_clks[] = { enum { MSTP114, + MSTP100, MSTP026, MSTP025, MSTP024, MSTP023, MSTP022, MSTP021, MSTP016, MSTP015, MSTP_NR }; static struct clk mstp_clks[MSTP_NR] = { [MSTP114] = SH_CLK_MSTP32(&clkp, MSTPCR1, 14, 0), /* Ether */ + [MSTP100] = SH_CLK_MSTP32(&clkp, MSTPCR1, 0, 0), /* USB0/1 */ [MSTP026] = SH_CLK_MSTP32(&clkp, MSTPCR0, 26, 0), /* SCIF0 */ [MSTP025] = SH_CLK_MSTP32(&clkp, MSTPCR0, 25, 0), /* SCIF1 */ [MSTP024] = SH_CLK_MSTP32(&clkp, MSTPCR0, 24, 0), /* SCIF2 */ @@ -78,6 +80,8 @@ static struct clk mstp_clks[MSTP_NR] = { static struct clk_lookup lookups[] = { /* MSTP32 clocks */ CLKDEV_DEV_ID("sh-eth", &mstp_clks[MSTP114]), /* Ether */ + CLKDEV_DEV_ID("ehci-platform", &mstp_clks[MSTP100]), /* USB EHCI port0/1 */ + CLKDEV_DEV_ID("ohci-platform", &mstp_clks[MSTP100]), /* USB OHCI port0/1 */ CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[MSTP026]), /* SCIF0 */ CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[MSTP025]), /* SCIF1 */ CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[MSTP024]), /* SCIF2 */ Index: renesas/arch/arm/mach-shmobile/include/mach/r8a7778.h =================================================================== --- renesas.orig/arch/arm/mach-shmobile/include/mach/r8a7778.h +++ renesas/arch/arm/mach-shmobile/include/mach/r8a7778.h @@ -19,10 +19,13 @@ #define __ASM_R8A7778_H__ #include +#include extern void r8a7778_add_standard_devices(void); extern void r8a7778_add_standard_devices_dt(void); extern void r8a7778_add_ether_device(struct sh_eth_plat_data *pdata); +extern void r8a7778_add_usb_phy_device(struct rcar_phy_platform_data *pdata); +extern void r8a7778_init_late(void); extern void r8a7778_init_delay(void); extern void r8a7778_init_irq(void); extern void r8a7778_init_irq_dt(void); Index: renesas/arch/arm/mach-shmobile/setup-r8a7778.c =================================================================== --- renesas.orig/arch/arm/mach-shmobile/setup-r8a7778.c +++ renesas/arch/arm/mach-shmobile/setup-r8a7778.c @@ -29,6 +29,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -88,6 +94,99 @@ static struct sh_timer_config sh_tmu1_pl &sh_tmu##idx##_platform_data, \ sizeof(sh_tmu##idx##_platform_data)) +/* USB PHY */ +static struct resource usb_phy_resources[] = { + DEFINE_RES_MEM(0xffe70800, 0x100), + DEFINE_RES_MEM(0xffe76000, 0x100), +}; + +void __init r8a7778_add_usb_phy_device(struct rcar_phy_platform_data *pdata) +{ + platform_device_register_resndata(&platform_bus, "rcar_usb_phy", -1, + usb_phy_resources, + ARRAY_SIZE(usb_phy_resources), + pdata, sizeof(*pdata)); +} + +/* USB */ +static struct usb_phy *phy; + +static int usb_power_on(struct platform_device *pdev) +{ + if (!phy) + return -EIO; + + pm_runtime_enable(&pdev->dev); + pm_runtime_get_sync(&pdev->dev); + + usb_phy_init(phy); + + return 0; +} + +static void usb_power_off(struct platform_device *pdev) +{ + if (!phy) + return; + + usb_phy_shutdown(phy); + + pm_runtime_put_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); +} + +static int ehci_init_internal_buffer(struct usb_hcd *hcd) +{ + /* + * Below are recommended values from the datasheet; + * see [USB :: Setting of EHCI Internal Buffer]. + */ + /* EHCI IP internal buffer setting */ + iowrite32(0x00ff0040, hcd->regs + 0x0094); + /* EHCI IP internal buffer enable */ + iowrite32(0x00000001, hcd->regs + 0x009C); + + return 0; +} + +static struct usb_ehci_pdata ehci_pdata = { + .power_on = usb_power_on, + .power_off = usb_power_off, + .power_suspend = usb_power_off, + .pre_setup = ehci_init_internal_buffer, +}; + +static struct resource ehci_resources[] = { + DEFINE_RES_MEM(0xffe70000, 0x400), + DEFINE_RES_IRQ(gic_iid(0x4c)), +}; + +static struct usb_ohci_pdata ohci_pdata = { + .power_on = usb_power_on, + .power_off = usb_power_off, + .power_suspend = usb_power_off, +}; + +static struct resource ohci_resources[] = { + DEFINE_RES_MEM(0xffe70400, 0x400), + DEFINE_RES_IRQ(gic_iid(0x4c)), +}; + +#define USB_PLATFORM_INFO(hci) \ +static struct platform_device_info hci##_info = { \ + .parent = &platform_bus, \ + .name = #hci "-platform", \ + .id = -1, \ + .res = hci##_resources, \ + .num_res = ARRAY_SIZE(hci##_resources), \ + .data = &hci##_pdata, \ + .size_data = sizeof(hci##_pdata), \ + .dma_mask = DMA_BIT_MASK(32), \ +} + +USB_PLATFORM_INFO(ehci); +USB_PLATFORM_INFO(ohci); + /* Ether */ static struct resource ether_resources[] = { DEFINE_RES_MEM(0xfde00000, 0x400), @@ -126,6 +225,14 @@ void __init r8a7778_add_standard_devices r8a7778_register_tmu(1); } +void __init r8a7778_init_late(void) +{ + phy = usb_get_phy(USB_PHY_TYPE_USB2); + + platform_device_register_full(&ehci_info); + platform_device_register_full(&ohci_info); +} + static struct renesas_intc_irqpin_config irqpin_platform_data = { .irq_base = irq_pin(0), /* IRQ0 -> IRQ3 */ .sense_bitfield_width = 2, @@ -239,6 +346,7 @@ DT_MACHINE_START(R8A7778_DT, "Generic R8 .init_machine = r8a7778_add_standard_devices_dt, .init_time = shmobile_timer_init, .dt_compat = r8a7778_compat_dt, + .init_late = r8a7778_init_late, MACHINE_END #endif /* CONFIG_USE_OF */