From patchwork Fri Apr 25 11:18:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Gautam X-Patchwork-Id: 4059141 Return-Path: X-Original-To: patchwork-linux-arm@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 B31E2BFF02 for ; Fri, 25 Apr 2014 11:21:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 94056203AC for ; Fri, 25 Apr 2014 11:21:00 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (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 9222020398 for ; Fri, 25 Apr 2014 11:20:59 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wde9b-0004pC-0G; Fri, 25 Apr 2014 11:18:51 +0000 Received: from mail-pd0-x232.google.com ([2607:f8b0:400e:c02::232]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wde9Q-0004gO-9s for linux-arm-kernel@lists.infradead.org; Fri, 25 Apr 2014 11:18:41 +0000 Received: by mail-pd0-f178.google.com with SMTP id fp1so877636pdb.37 for ; Fri, 25 Apr 2014 04:18:17 -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=+dgLszmLD8HakOemDQGnHzc9PLYzDV9t2BqYOjYVdSI=; b=q71sTK1VVu0s+16pASPnKrwBkajlruzlcxpHnPYPm7rC4Qcxn/t5E8uzdN6hINn5bP 5LOeWbINtGdkG8U5YjxAO2oYx/nVY6SkpTGcB/+XmV11OGhATernOQr0c8TVsAnL+KeD e5VKysY6q+mnp2lDLOSB8ioyi25BlPuj+vQUOdfYHDhMReiDtqPcwM59l+BNJwdsJOjm BYe4BCyII/dNr4a33GXfkGptwxmhFbK2bqul/C780b9ZE60fBUQfdiMbeTsOdYNcJtb3 AGI4bH5j32DCfLUhSBdrvKRpI9HCsOndeV5+hwaN2dT/TxlkiXxaVy0p7sY+0CPOsPYn Jvuw== X-Received: by 10.68.197.39 with SMTP id ir7mr4382072pbc.78.1398424697332; Fri, 25 Apr 2014 04:18:17 -0700 (PDT) Received: from vivek-linuxpc.sisodomain.com ([115.113.119.130]) by mx.google.com with ESMTPSA id kl1sm15217179pbd.73.2014.04.25.04.18.13 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 25 Apr 2014 04:18:16 -0700 (PDT) From: Vivek Gautam To: linux-usb@vger.kernel.org, linux-samsung-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v2 1/2] usb: ohci-exynos: Add facility to use phy provided by the generic phy framework Date: Fri, 25 Apr 2014 16:48:02 +0530 Message-Id: <1398424683-20168-2-git-send-email-gautam.vivek@samsung.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1398424683-20168-1-git-send-email-gautam.vivek@samsung.com> References: <1398424683-20168-1-git-send-email-gautam.vivek@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140425_041840_406121_5D9AA3B7 X-CRM114-Status: GOOD ( 20.61 ) X-Spam-Score: 0.2 (/) Cc: k.debski@samsung.com, kgene.kim@samsung.com, gregkh@linuxfoundation.org, jg1.han@samsung.com, linux-kernel@vger.kernel.org, balbi@ti.com, stern@rowland.harvard.edu, 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=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, 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 --- Changes from v1: - Made two separate routines for exynos_ohci_phyg_on() and exynos_ohci_phyg_off(). - Separated out the phy-get related code from probe() to separate function exynos_ehci_get_phy(). - Using proper error labels in the code. .../devicetree/bindings/usb/exynos-usb.txt | 19 +++ drivers/usb/host/ohci-exynos.c | 123 ++++++++++++++++++-- 2 files changed, 132 insertions(+), 10 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/exynos-usb.txt b/Documentation/devicetree/bindings/usb/exynos-usb.txt index d967ba1..03b7e43 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 its 'reg' entry. + - 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 68588d8..eac47cb 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,12 +34,111 @@ 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 int exynos_ohci_get_phy(struct platform_device *pdev, + 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(&pdev->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(&pdev->dev, "Failed to get usb2 phy\n"); + exynos_ohci->phy = NULL; + ret = 0; + } else if (ret == -EPROBE_DEFER) { + goto fail_phy; + } else { + dev_err(&pdev->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(pdev->dev.of_node, child) { + ret = of_property_read_u32(child, "reg", &phy_number); + if (ret) { + dev_err(&pdev->dev, "Failed to parse device tree\n"); + of_node_put(child); + goto fail_phy; + } + if (phy_number >= PHY_NUMBER) { + dev_err(&pdev->dev, "Invalid number of PHYs\n"); + of_node_put(child); + ret = -EINVAL; + goto fail_phy; + } + phy = devm_of_phy_get(&pdev->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(&pdev->dev, "Failed to get usb2 phy\n"); + phy = NULL; + ret = 0; + } else if (ret == -EPROBE_DEFER) { + goto fail_phy; + } else { + dev_err(&pdev->dev, "no usb2 phy configured\n"); + goto fail_phy; + } + } + exynos_ohci->phy_g[phy_number] = phy; + } + +fail_phy: + return ret; +} + +static int exynos_ohci_phyg_on(struct phy *phy[]) +{ + int i; + int ret = 0; + + for (i = 0; ret == 0 && i < PHY_NUMBER; i++) + if (phy[i]) + ret = phy_power_on(phy[i]); + if (ret) + for (i--; i >= 0; i--) + if (phy[i]) + phy_power_off(phy[i]); + + return ret; +} + +static int exynos_ohci_phyg_off(struct phy *phy[]) +{ + int i; + int ret = 0; + + for (i = 0; ret == 0 && i < PHY_NUMBER; i++) + if (phy[i]) + ret = phy_power_off(phy[i]); + + return ret; +} + static void exynos_ohci_phy_enable(struct platform_device *pdev) { struct usb_hcd *hcd = platform_get_drvdata(pdev); @@ -46,6 +146,11 @@ static void exynos_ohci_phy_enable(struct platform_device *pdev) if (exynos_ohci->phy) usb_phy_init(exynos_ohci->phy); + + if (exynos_ohci->phy_g) + if (exynos_ohci_phyg_on(exynos_ohci->phy_g)) + dev_warn(&pdev->dev, "Failed to enable phy\n"); + } static void exynos_ohci_phy_disable(struct platform_device *pdev) @@ -55,6 +160,10 @@ static void exynos_ohci_phy_disable(struct platform_device *pdev) if (exynos_ohci->phy) usb_phy_shutdown(exynos_ohci->phy); + + if (exynos_ohci->phy_g) + if (exynos_ohci_phyg_off(exynos_ohci->phy_g)) + dev_warn(&pdev->dev, "Failed to enable phy\n"); } static int exynos_ohci_probe(struct platform_device *pdev) @@ -62,7 +171,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 +196,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, exynos_ohci); + if (err) + goto fail_clk; skip_phy: exynos_ohci->clk = devm_clk_get(&pdev->dev, "usbhost"); @@ -151,6 +253,7 @@ skip_phy: fail_add_hcd: exynos_ohci_phy_disable(pdev); + exynos_ohci_phyg_off(exynos_ohci->phy_g); fail_io: clk_disable_unprepare(exynos_ohci->clk); fail_clk: