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: 3963441 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 46BFB9F375 for ; Thu, 10 Apr 2014 16:24:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 47B3320835 for ; Thu, 10 Apr 2014 16:24:25 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9D06520646 for ; Thu, 10 Apr 2014 16:24:23 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WYHlQ-0004dN-2H; Thu, 10 Apr 2014 16:23:44 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WYHlC-0005iG-6a; Thu, 10 Apr 2014 16:23:31 +0000 Received: from bombadil.infradead.org ([2001:1868:205::9]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WYHjj-0005aO-OK for linux-arm-kernel@merlin.infradead.org; Thu, 10 Apr 2014 16:22:00 +0000 Received: from mail-pb0-x22c.google.com ([2607:f8b0:400e:c01::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WYHi2-0001Pc-Lf for linux-arm-kernel@lists.infradead.org; Thu, 10 Apr 2014 16:20:15 +0000 Received: by mail-pb0-f44.google.com with SMTP id rp16so4184943pbb.3 for ; Thu, 10 Apr 2014 09:19:52 -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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140410_092014_747357_4A424B48 X-CRM114-Status: GOOD ( 18.55 ) X-Spam-Score: 0.2 (/) Cc: kgene.kim@samsung.com, gregkh@linuxfoundation.org, Jingoo Han , linux-kernel@vger.kernel.org, robh+dt@kernel.org, Alan Stern , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,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);