From patchwork Thu Apr 10 13:24:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Gautam X-Patchwork-Id: 3962951 Return-Path: X-Original-To: patchwork-linux-samsung-soc@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 D4B78BFF02 for ; Thu, 10 Apr 2014 13:26:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CE07E20618 for ; Thu, 10 Apr 2014 13:26:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE526204F6 for ; Thu, 10 Apr 2014 13:26:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030948AbaDJNZw (ORCPT ); Thu, 10 Apr 2014 09:25:52 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:58539 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030907AbaDJNZN (ORCPT ); Thu, 10 Apr 2014 09:25:13 -0400 Received: by mail-pa0-f44.google.com with SMTP id bj1so3993203pad.3 for ; Thu, 10 Apr 2014 06:25:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=xEC1fO0rwL29ShMddd8x69CEZwGuMU8bGby7U+Xd8Zs=; b=a8Z5Lu+fXyNjEOBnMzS+XPXtpeoYcKmC2SccSXwsKz7V2t6ZWLF8QJy5+bYhLrWWMQ G+cIPJmTJMYdU7fFbdO//xyw7CnWpViA5Xr3UZcdZLm+3fe3a+Fgem5DvRvJdm3lJ0xE v+4L5ebIyeFfaKzRtV0FY70QyxBtX17h7lSv7Mejd+R4LYetUnDTSXXAiOJBg3ZmZwc5 89Ax9e1MQ0ggHSAH0U+L6GlShnWod0QPoIYBsY10yceVznp0q4Vm82sDG6ZAAegP2I13 WZy8j79wSKX5F85qLdXasT3uiKTHdUflqBwYE/yJrrF6MGKXuOL+GOY5OLdWuQkPiAEW IIkQ== X-Received: by 10.66.158.132 with SMTP id wu4mr19871497pab.66.1397136312232; Thu, 10 Apr 2014 06:25:12 -0700 (PDT) Received: from vivek-linuxpc.sisodomain.com ([115.113.119.130]) by mx.google.com with ESMTPSA id qx11sm20623374pab.35.2014.04.10.06.25.08 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 10 Apr 2014 06:25:11 -0700 (PDT) From: Vivek Gautam To: linux-usb@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-doc@vger.kernel.org, devicetree@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kgene.kim@samsung.com, robh+dt@kernel.org, Jingoo Han , Alan Stern Subject: [PATCH] usb: ohci-exynos: Add facility to use phy provided by the generic phy framework Date: Thu, 10 Apr 2014 18:54:21 +0530 Message-Id: <1397136261-16408-1-git-send-email-gautam.vivek@samsung.com> X-Mailer: git-send-email 1.7.10.4 Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable 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 Add support to consume phy provided by Generic phy framework. Keeping the support for older usb-phy intact right now, in order to prevent any functionality break in absence of relevant device tree side change for ohci-exynos. Once we move to new phy in the device nodes for ohci, we can remove the support for older phys. Signed-off-by: Vivek Gautam Cc: Jingoo Han Cc: Alan Stern --- Based on 'usb-next' branch of Greg's usb tree. Tested with local dt patches, similar to ehci dt changes posted by Kamil[1]. Tested on Exynos5250 smdk. [1] [PATCH v6 4/8] dts: Add usb2phy to Exynos 5250 https://lkml.org/lkml/2014/1/29/302 .../devicetree/bindings/usb/exynos-usb.txt | 14 ++++ drivers/usb/host/ohci-exynos.c | 79 ++++++++++++++++++-- 2 files changed, 85 insertions(+), 8 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/exynos-usb.txt b/Documentation/devicetree/bindings/usb/exynos-usb.txt index d967ba1..ef0bc09 100644 --- a/Documentation/devicetree/bindings/usb/exynos-usb.txt +++ b/Documentation/devicetree/bindings/usb/exynos-usb.txt @@ -38,6 +38,10 @@ Required properties: - interrupts: interrupt number to the cpu. - clocks: from common clock binding: handle to usb clock. - clock-names: from common clock binding: Shall be "usbhost". + - port: if in the SoC there are OHCI phys, they should be listed here. +One phy per port. Each port should have its reg entry with a consecutive +number. Also it should contain phys and phy-names entries specifying the +phy used by the port. Example: usb@12120000 { @@ -47,6 +51,16 @@ Example: clocks = <&clock 285>; clock-names = "usbhost"; + + #address-cells = <1>; + #size-cells = <0>; + port@0 { + reg = <0>; + phys = <&usb2phy 1>; + phy-names = "host"; + status = "disabled"; + }; + }; DWC3 diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c index 68588d8..52eb821 100644 --- a/drivers/usb/host/ohci-exynos.c +++ b/drivers/usb/host/ohci-exynos.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,7 @@ struct exynos_ohci_hcd { struct clk *clk; struct usb_phy *phy; struct usb_otg *otg; + struct phy *phy_g; }; static void exynos_ohci_phy_enable(struct platform_device *pdev) @@ -57,12 +59,26 @@ static void exynos_ohci_phy_disable(struct platform_device *pdev) usb_phy_shutdown(exynos_ohci->phy); } +static int exynos_ohci_phyg_on(struct phy *phy, bool on) +{ + int ret = 0; + + if (phy) { + if (on) + ret = phy_power_on(phy); + else + ret = phy_power_off(phy); + } + + return ret; +} + static int exynos_ohci_probe(struct platform_device *pdev) { struct exynos_ohci_hcd *exynos_ohci; struct usb_hcd *hcd; struct resource *res; - struct usb_phy *phy; + struct device_node *child; int irq; int err; @@ -88,16 +104,49 @@ static int exynos_ohci_probe(struct platform_device *pdev) "samsung,exynos5440-ohci")) goto skip_phy; - phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); - if (IS_ERR(phy)) { - usb_put_hcd(hcd); - dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); - return -EPROBE_DEFER; + exynos_ohci->phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); + if (IS_ERR(exynos_ohci->phy)) { + err = PTR_ERR(exynos_ohci->phy); + if (err == -ENXIO || err == -ENODEV) { + exynos_ohci->phy = NULL; + } else if (err == -EPROBE_DEFER) { + usb_put_hcd(hcd); + return err; + } else { + dev_err(&pdev->dev, "no usb2 phy configured\n"); + usb_put_hcd(hcd); + return err; + } } else { - exynos_ohci->phy = phy; - exynos_ohci->otg = phy->otg; + exynos_ohci->otg = exynos_ohci->phy->otg; } + /* Getting generic phy: + * We are keeping both types of phys as a part of transiting OHCI + * to generic phy framework, so that in absence of supporting dts + * changes the functionality doesn't break. + * Once we move the ohci dt nodes to use new generic phys, + * we can remove support for older PHY in this driver. + */ + child = of_get_next_child(pdev->dev.of_node, NULL); + exynos_ohci->phy_g = devm_of_phy_get(&pdev->dev, child, 0); + of_node_put(child); + if (IS_ERR(exynos_ohci->phy_g)) { + err = PTR_ERR(exynos_ohci->phy_g); + if (err == -ENOSYS || err == -ENODEV) { + exynos_ohci->phy_g = NULL; + } else if (err == -EPROBE_DEFER) { + usb_put_hcd(hcd); + return err; + } else { + dev_err(&pdev->dev, "no usb2 phy configured\n"); + usb_put_hcd(hcd); + return err; + } + } + + if (!exynos_ohci->phy && !exynos_ohci->phy_g) + dev_dbg(&pdev->dev, "Failed to get usb2 phy\n"); skip_phy: exynos_ohci->clk = devm_clk_get(&pdev->dev, "usbhost"); @@ -140,6 +189,11 @@ skip_phy: platform_set_drvdata(pdev, hcd); exynos_ohci_phy_enable(pdev); + err = exynos_ohci_phyg_on(exynos_ohci->phy_g, true); + if (err) { + dev_err(&pdev->dev, "Failed to enable phy\n"); + goto fail_io; + } err = usb_add_hcd(hcd, irq, IRQF_SHARED); if (err) { @@ -151,6 +205,7 @@ skip_phy: fail_add_hcd: exynos_ohci_phy_disable(pdev); + exynos_ohci_phyg_on(exynos_ohci->phy_g, false); fail_io: clk_disable_unprepare(exynos_ohci->clk); fail_clk: @@ -169,6 +224,7 @@ static int exynos_ohci_remove(struct platform_device *pdev) exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); exynos_ohci_phy_disable(pdev); + exynos_ohci_phyg_on(exynos_ohci->phy_g, false); clk_disable_unprepare(exynos_ohci->clk); @@ -205,6 +261,7 @@ static int exynos_ohci_suspend(struct device *dev) exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); exynos_ohci_phy_disable(pdev); + exynos_ohci_phyg_on(exynos_ohci->phy_g, false); clk_disable_unprepare(exynos_ohci->clk); @@ -218,6 +275,7 @@ static int exynos_ohci_resume(struct device *dev) struct usb_hcd *hcd = dev_get_drvdata(dev); struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); struct platform_device *pdev = to_platform_device(dev); + int ret; clk_prepare_enable(exynos_ohci->clk); @@ -225,6 +283,11 @@ static int exynos_ohci_resume(struct device *dev) exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); exynos_ohci_phy_enable(pdev); + ret = exynos_ohci_phyg_on(exynos_ohci->phy_g, true); + if (ret) { + dev_err(dev, "Failed to enable phy\n"); + return ret; + } ohci_resume(hcd, false);