From patchwork Fri Jan 17 18:21:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentine Barshak X-Patchwork-Id: 3506731 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A663FC02DC for ; Fri, 17 Jan 2014 18:21:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 93A332015D for ; Fri, 17 Jan 2014 18:21:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8EE62200E9 for ; Fri, 17 Jan 2014 18:21:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753116AbaAQSVm (ORCPT ); Fri, 17 Jan 2014 13:21:42 -0500 Received: from mail-lb0-f171.google.com ([209.85.217.171]:54973 "EHLO mail-lb0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753075AbaAQSVl (ORCPT ); Fri, 17 Jan 2014 13:21:41 -0500 Received: by mail-lb0-f171.google.com with SMTP id c11so3217425lbj.2 for ; Fri, 17 Jan 2014 10:21:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hHf+XORQyiZP+CbCwzOyyPKU7YS+6qDwdEbaypSG0Fs=; b=DxVgBEeUXRar0PFcJczW9KP7+QSzW03TTS+vVhvkZ7htqTiyrHxPntx2ZoZWM9AKF3 Y4rtKL09FU9QnGhPcwByWS9jMDN7yiqMcsd2kJ46+/afvVyccBOEv4zTwjF/buGVfXIq ZP6tOgX2zb7Uz5D1wYXCmyg1TiKZXQ34qJdAfbBtXerrFjMtn+mZv4Lnbj/KOh9m7lhr 5363bT9f0k59sH5p0szwSKRD3LUZO+rGrID+glAIwvfz3MlX4w28DE3G8xphDyL7yl4a T+WNDbAFolSFw0OT2A/HiDRVHWhGomWdAf91Lk9Gsp1esX1DzWLsBMdsgv0RUJsSSIlN xYBA== X-Gm-Message-State: ALoCoQmQAIjS91gvypy3/hokqCdWisK8XAp8gpxBgLxSHB/bJSqtaB6EeZKLGxMfr2lGZTGfpfJm X-Received: by 10.152.4.74 with SMTP id i10mr17178lai.58.1389982900501; Fri, 17 Jan 2014 10:21:40 -0800 (PST) Received: from black.localnet ([93.100.122.208]) by mx.google.com with ESMTPSA id qx1sm7250746lbb.15.2014.01.17.10.21.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jan 2014 10:21:39 -0800 (PST) From: Valentine Barshak To: linux-sh@vger.kernel.org Cc: Simon Horman , Magnus Damm , Kuninori Morimoto , Laurent Pinchart Subject: [PATCH V2 2/4] ARM: shmobile: koelsch: Add USBHS support Date: Fri, 17 Jan 2014 22:21:33 +0400 Message-Id: <1389982895-20726-3-git-send-email-valentine.barshak@cogentembedded.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1389982895-20726-1-git-send-email-valentine.barshak@cogentembedded.com> References: <1389982895-20726-1-git-send-email-valentine.barshak@cogentembedded.com> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adds USBHS PHY and registers USBHS device if the driver is enabled. Signed-off-by: Valentine Barshak --- arch/arm/mach-shmobile/board-koelsch.c | 138 +++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) Changes in V2: * capitalized ARM in the subject; * rebased on top the latest devel tag; * added pipe_type array to the usbhs platform info since it differs from the default. diff --git a/arch/arm/mach-shmobile/board-koelsch.c b/arch/arm/mach-shmobile/board-koelsch.c index 2ab5c75..9ec1564 100644 --- a/arch/arm/mach-shmobile/board-koelsch.c +++ b/arch/arm/mach-shmobile/board-koelsch.c @@ -29,8 +29,11 @@ #include #include #include +#include #include #include +#include +#include #include #include #include @@ -163,6 +166,131 @@ static const struct platform_device_info sata0_info __initconst = { .dma_mask = DMA_BIT_MASK(32), }; +/* USBHS */ +#if IS_ENABLED(CONFIG_USB_RENESAS_USBHS_UDC) +static const struct resource usbhs_resources[] __initconst = { + DEFINE_RES_MEM(0xe6590000, 0x100), + DEFINE_RES_IRQ(gic_spi(107)), +}; + +struct usbhs_private { + struct renesas_usbhs_platform_info info; + struct usb_phy *phy; +}; + +#define usbhs_get_priv(pdev) \ + container_of(renesas_usbhs_get_info(pdev), struct usbhs_private, info) + +static int usbhs_power_ctrl(struct platform_device *pdev, + void __iomem *base, int enable) +{ + struct usbhs_private *priv = usbhs_get_priv(pdev); + + if (!priv->phy) + return -ENODEV; + + if (enable) { + int retval = usb_phy_init(priv->phy); + + if (!retval) + retval = usb_phy_set_suspend(priv->phy, 0); + return retval; + } + + usb_phy_set_suspend(priv->phy, 1); + usb_phy_shutdown(priv->phy); + return 0; +} + +static int usbhs_hardware_init(struct platform_device *pdev) +{ + struct usbhs_private *priv = usbhs_get_priv(pdev); + struct usb_phy *phy; + + phy = usb_get_phy_dev(&pdev->dev, 0); + if (IS_ERR(phy)) + return PTR_ERR(phy); + + priv->phy = phy; + return 0; +} + +static int usbhs_hardware_exit(struct platform_device *pdev) +{ + struct usbhs_private *priv = usbhs_get_priv(pdev); + + if (!priv->phy) + return 0; + + usb_put_phy(priv->phy); + priv->phy = NULL; + return 0; +} + +static int usbhs_get_id(struct platform_device *pdev) +{ + return USBHS_GADGET; +} + +static u32 koelsch_usbhs_pipe_type[] = { + USB_ENDPOINT_XFER_CONTROL, + USB_ENDPOINT_XFER_ISOC, + USB_ENDPOINT_XFER_ISOC, + USB_ENDPOINT_XFER_BULK, + USB_ENDPOINT_XFER_BULK, + USB_ENDPOINT_XFER_BULK, + USB_ENDPOINT_XFER_INT, + USB_ENDPOINT_XFER_INT, + USB_ENDPOINT_XFER_INT, + USB_ENDPOINT_XFER_BULK, + USB_ENDPOINT_XFER_BULK, + USB_ENDPOINT_XFER_BULK, + USB_ENDPOINT_XFER_BULK, + USB_ENDPOINT_XFER_BULK, + USB_ENDPOINT_XFER_BULK, + USB_ENDPOINT_XFER_BULK, +}; + +static struct usbhs_private usbhs_priv __initdata = { + .info = { + .platform_callback = { + .power_ctrl = usbhs_power_ctrl, + .hardware_init = usbhs_hardware_init, + .hardware_exit = usbhs_hardware_exit, + .get_id = usbhs_get_id, + }, + .driver_param = { + .buswait_bwait = 4, + .pipe_type = koelsch_usbhs_pipe_type, + .pipe_size = ARRAY_SIZE(koelsch_usbhs_pipe_type), + }, + } +}; + +static void __init koelsch_register_usbhs(void) +{ + usb_bind_phy("renesas_usbhs", 0, "usb_phy_rcar_gen2"); + platform_device_register_resndata(&platform_bus, + "renesas_usbhs", -1, + usbhs_resources, + ARRAY_SIZE(usbhs_resources), + &usbhs_priv.info, + sizeof(usbhs_priv.info)); +} +#else /* CONFIG_USB_RENESAS_USBHS_UDC */ +static inline void koelsch_register_usbhs(void) { } +#endif /* CONFIG_USB_RENESAS_USBHS_UDC */ + +/* USBHS PHY */ +static const struct rcar_gen2_phy_platform_data usbhs_phy_pdata __initconst = { + .chan0_pci = 0, /* Channel 0 is USBHS */ + .chan2_pci = 1, /* Channel 2 is PCI USB */ +}; + +static const struct resource usbhs_phy_resources[] __initconst = { + DEFINE_RES_MEM(0xe6590100, 0x100), +}; + static const struct pinctrl_map koelsch_pinctrl_map[] = { /* DU */ PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791", @@ -186,6 +314,9 @@ static const struct pinctrl_map koelsch_pinctrl_map[] = { /* SCIF1 (CN20: DEBUG SERIAL1) */ PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7791", "scif1_data_d", "scif1"), + /* USB0 */ + PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs", "pfc-r8a7791", + "usb0", "usb0"), }; static void __init koelsch_add_standard_devices(void) @@ -209,6 +340,13 @@ static void __init koelsch_add_standard_devices(void) koelsch_add_du_device(); platform_device_register_full(&sata0_info); + + platform_device_register_resndata(&platform_bus, "usb_phy_rcar_gen2", + -1, usbhs_phy_resources, + ARRAY_SIZE(usbhs_phy_resources), + &usbhs_phy_pdata, + sizeof(usbhs_phy_pdata)); + koelsch_register_usbhs(); } /*