From patchwork Wed Apr 30 05:19:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Gautam X-Patchwork-Id: 4091451 Return-Path: X-Original-To: patchwork-linux-samsung-soc@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 8D95B9F39D for ; Wed, 30 Apr 2014 05:20:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 815DE201FB for ; Wed, 30 Apr 2014 05:20:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 61539201F9 for ; Wed, 30 Apr 2014 05:20:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757579AbaD3FUU (ORCPT ); Wed, 30 Apr 2014 01:20:20 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:60047 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757507AbaD3FUQ (ORCPT ); Wed, 30 Apr 2014 01:20:16 -0400 Received: by mail-pa0-f51.google.com with SMTP id fb1so1342176pad.24 for ; Tue, 29 Apr 2014 22:20:15 -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:in-reply-to:references; bh=knBHwygoQxhX1szQxE5nVCdXwdPmKLRS5hbU2GCDFBM=; b=ZOchF7PW82Gpvz+O93r1S1ppT0DqOmCPskxXZ1zoEfq832z5+/PhpDIi1u/he7wOD0 cQC1h+BhXvifXmZg9pCIfXXrBS2MKsNgYH7q4g5AT5ToZyk679Glh9wBQTV6mrnbdggC Aaa01Fg4F0tRKonnzpychJD6jVfos65y9sKPkx+k37CzAGbHsMudOFx0nx8EEEpeE+p1 AltuIS/3x3CraRPJdna59PYsfmH/d1m0Hgi3qMG7YktUI2uhhCWN/iVtid4XCo7lrNrU D8cvbSccHjfnXtrnbm+PKw3UZAaBJ5srvaB55YY8eqLLGjlmYeKA29N33VNmUjbJPtck DCCQ== X-Received: by 10.66.221.4 with SMTP id qa4mr4552035pac.138.1398835215315; Tue, 29 Apr 2014 22:20:15 -0700 (PDT) Received: from vivek-linuxpc.sisodomain.com ([115.113.119.130]) by mx.google.com with ESMTPSA id au16sm126932405pac.27.2014.04.29.22.20.10 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Apr 2014 22:20:14 -0700 (PDT) From: Vivek Gautam To: linux-usb@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, gregkh@linuxfoundation.org, balbi@ti.com, kgene.kim@samsung.com, k.debski@samsung.com, jg1.han@samsung.com, Vivek Gautam , Alan Stern Subject: [PATCH v4 3/4] usb: ohci-exynos: Add facility to use phy provided by the generic phy framework Date: Wed, 30 Apr 2014 10:49:51 +0530 Message-Id: <1398835192-21634-3-git-send-email-gautam.vivek@samsung.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1398835192-21634-1-git-send-email-gautam.vivek@samsung.com> References: <1398835192-21634-1-git-send-email-gautam.vivek@samsung.com> 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=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 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 --- Changes from v3: - Calling usb_phy_shutdown() when exynos_ohci_phy_enable() is failing. - Made exynos_ohci_phy_disable() return void, since its return value did not serve any purpose. - Calling clk_disable_unprepare() in exynos_ohci_resume() when exynos_ohci_phy_enable() is failed. .../devicetree/bindings/usb/exynos-usb.txt | 19 +++ drivers/usb/host/ohci-exynos.c | 128 +++++++++++++++++--- 2 files changed, 132 insertions(+), 15 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/exynos-usb.txt b/Documentation/devicetree/bindings/usb/exynos-usb.txt index d967ba1..a90c973 100644 --- a/Documentation/devicetree/bindings/usb/exynos-usb.txt +++ b/Documentation/devicetree/bindings/usb/exynos-usb.txt @@ -38,6 +38,15 @@ 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 following entries: + - reg: port number on OHCI controller, e.g + On Exynos5250, port 0 is USB2.0 otg phy + port 1 is HSIC phy0 + port 2 is HSIC phy1 + - phys: from the *Generic PHY* bindings, specifying phy used by port. + - phy-names: from the *Generic PHY* bindings, specifying name of phy + used by the port. Example: usb@12120000 { @@ -47,6 +56,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 05f00e3..f90bf9a 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 @@ -33,28 +34,122 @@ static struct hc_driver __read_mostly exynos_ohci_hc_driver; #define to_exynos_ohci(hcd) (struct exynos_ohci_hcd *)(hcd_to_ohci(hcd)->priv) +#define PHY_NUMBER 3 struct exynos_ohci_hcd { struct clk *clk; struct usb_phy *phy; struct usb_otg *otg; + struct phy *phy_g[PHY_NUMBER]; }; -static void exynos_ohci_phy_enable(struct device *dev) +static int exynos_ohci_get_phy(struct device *dev, + struct exynos_ohci_hcd *exynos_ohci) +{ + struct device_node *child; + struct phy *phy; + int phy_number; + int ret = 0; + + exynos_ohci->phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); + if (IS_ERR(exynos_ohci->phy)) { + ret = PTR_ERR(exynos_ohci->phy); + /* This is the case when PHY config is disabled */ + if (ret == -ENXIO || ret == -ENODEV) { + dev_dbg(dev, "Failed to get usb2 phy\n"); + exynos_ohci->phy = NULL; + ret = 0; + } else if (ret == -EPROBE_DEFER) { + goto fail_phy; + } else { + dev_err(dev, "no usb2 phy configured\n"); + goto fail_phy; + } + } else { + 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. + */ + for_each_available_child_of_node(dev->of_node, child) { + ret = of_property_read_u32(child, "reg", &phy_number); + if (ret) { + dev_err(dev, "Failed to parse device tree\n"); + of_node_put(child); + goto fail_phy; + } + if (phy_number >= PHY_NUMBER) { + dev_err(dev, "Invalid number of PHYs\n"); + of_node_put(child); + ret = -EINVAL; + goto fail_phy; + } + phy = devm_of_phy_get(dev, child, 0); + of_node_put(child); + if (IS_ERR(phy)) { + ret = PTR_ERR(phy); + /* This is the case when PHY config is disabled */ + if (ret == -ENOSYS || ret == -ENODEV) { + dev_dbg(dev, "Failed to get usb2 phy\n"); + phy = NULL; + ret = 0; + } else if (ret == -EPROBE_DEFER) { + goto fail_phy; + } else { + dev_err(dev, "no usb2 phy configured\n"); + goto fail_phy; + } + } + exynos_ohci->phy_g[phy_number] = phy; + } + +fail_phy: + return ret; +} + +static int exynos_ohci_phy_enable(struct device *dev) { struct usb_hcd *hcd = dev_get_drvdata(dev); struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); + int i; + int ret = 0; - if (exynos_ohci->phy) - usb_phy_init(exynos_ohci->phy); + if (exynos_ohci->phy) { + ret = usb_phy_init(exynos_ohci->phy); + if (ret) + return ret; + } + + for (i = 0; ret == 0 && i < PHY_NUMBER; i++) + if (exynos_ohci->phy_g[i]) + ret = phy_power_on(exynos_ohci->phy_g[i]); + if (ret) { + for (i--; i >= 0; i--) + if (exynos_ohci->phy_g[i]) + phy_power_off(exynos_ohci->phy_g[i]); + if (exynos_ohci->phy) + usb_phy_shutdown(exynos_ohci->phy); + } + + return ret; } static void exynos_ohci_phy_disable(struct device *dev) { struct usb_hcd *hcd = dev_get_drvdata(dev); struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); + int i; if (exynos_ohci->phy) usb_phy_shutdown(exynos_ohci->phy); + + for (i = 0; i < PHY_NUMBER; i++) + if (exynos_ohci->phy_g[i]) + phy_power_off(exynos_ohci->phy_g[i]); } static int exynos_ohci_probe(struct platform_device *pdev) @@ -62,7 +157,6 @@ 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; int irq; int err; @@ -88,15 +182,9 @@ 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; - } else { - exynos_ohci->phy = phy; - exynos_ohci->otg = phy->otg; - } + err = exynos_ohci_get_phy(&pdev->dev, exynos_ohci); + if (err) + goto fail_clk; skip_phy: exynos_ohci->clk = devm_clk_get(&pdev->dev, "usbhost"); @@ -139,7 +227,11 @@ skip_phy: platform_set_drvdata(pdev, hcd); - exynos_ohci_phy_enable(&pdev->dev); + err = exynos_ohci_phy_enable(&pdev->dev); + if (err) { + dev_err(&pdev->dev, "Failed to enable USB phy\n"); + goto fail_io; + } err = usb_add_hcd(hcd, irq, IRQF_SHARED); if (err) { @@ -210,13 +302,19 @@ 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); + int ret; clk_prepare_enable(exynos_ohci->clk); if (exynos_ohci->otg) exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); - exynos_ohci_phy_enable(dev); + ret = exynos_ohci_phy_enable(dev); + if (ret) { + dev_err(dev, "Failed to enable USB phy\n"); + clk_disable_unprepare(exynos_ohci->clk); + return ret; + } ohci_resume(hcd, false);