From patchwork Wed Aug 8 12:34:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 955007 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Mg92GYUs"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41lrS522Pnz9s1c for ; Wed, 8 Aug 2018 22:34:40 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 41E85C22000; Wed, 8 Aug 2018 12:34:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D32E9C21FBD; Wed, 8 Aug 2018 12:34:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BC007C21FBD; Wed, 8 Aug 2018 12:34:33 +0000 (UTC) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by lists.denx.de (Postfix) with ESMTPS id 6DA30C21FB5 for ; Wed, 8 Aug 2018 12:34:33 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id t25-v6so2579601wmi.3 for ; Wed, 08 Aug 2018 05:34:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=KYBwa3VJyN8tlW7WqKe4CeXAqlngE+xHS5LBcGbj5kk=; b=Mg92GYUsV/Cg/oeHN9jAJYyzGOlyTXdAH3ASLIderJ2SUPHdqzurPo2LjPEm+/Cfp1 ncuTb/5oZJkxXFuIytEoY1gcCmK7OCgRiqt/KdkqQ8iaP8iQft3ekV8wtRSDcGooi3Vd VyW8uKbX43oqairyjI7b7CgD0a3Xyq8iwe0xlro1XmWTksrij2GC8tZ6tn6KcQYw4Kxv tWpvkEZwC0h74yrekTW+xsdko6OK9Th/1CHTTPqWbSeWAHNhv7uuNVKpI9uByKpXi/Ub 9GHsoKBOTwA1E5HdwxiiIyWnDwA1uh4+ms1eKmge22Q9s3cZMb0cfC7mMO2gUbvNhWHB Zz/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=KYBwa3VJyN8tlW7WqKe4CeXAqlngE+xHS5LBcGbj5kk=; b=s40yQHyfXqgNqQtCWrOoE2nktLAhg1h/sOOPQfqqRy+AuLmDTxiQjdmodOz0Q9p3gp knd00C1lWt90pTpD4dVY6BM+zSAJLY1b13/VcNvISeU1undZchXO3VyL9foQDAnYeUYr DXRF895kX8lnUwm0IYyg/AImSiynf/Wdt5w4EiqhqwzyWDVyU5/tk02+00Fvob9d5pF2 +sTB8wk6NlT7IKVcgddsz+wqcBqrHxYpbWLOpgXIe2HGdJXr5m61Em/g4383/kJpKAOp rVVHy4NisVqJ7pB3vXa2cryTtkLhTx114gkkiMy0vcGh6Hm7Y8gdSyYLeKFNCZTxRY3H 8EjA== X-Gm-Message-State: AOUpUlGC16Fa57KOi65qqRhYYP+Mr0GQ9lcsEr6a68mhZwHg1p96Badt myZ06Qn2+EqqwQeNsG2W4z4BpO7B X-Google-Smtp-Source: AA+uWPxdvj9l2/GixicSQ5/88J3UQWjKzhszJK/vywOPFQvPK7Vr2DtKBLfpy33Qedfu6O8gYR6RUw== X-Received: by 2002:a1c:cbc1:: with SMTP id b184-v6mr1822651wmg.149.1533731672670; Wed, 08 Aug 2018 05:34:32 -0700 (PDT) Received: from kurokawa.lan (ip-86-49-107-50.net.upcbroadband.cz. [86.49.107.50]) by smtp.gmail.com with ESMTPSA id h14-v6sm6152281wro.15.2018.08.08.05.34.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 05:34:31 -0700 (PDT) From: Marek Vasut X-Google-Original-From: Marek Vasut To: u-boot@lists.denx.de Date: Wed, 8 Aug 2018 14:34:29 +0200 Message-Id: <20180808123429.29546-1-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.16.2 Cc: Marek Vasut Subject: [U-Boot] [PATCH] usb: ehci: Make the PHY handling generic X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Pull out the EHCI PHY functions into the ehci-hcd.c to let other EHCI drivers use them. Signed-off-by: Marek Vasut --- drivers/usb/host/ehci-generic.c | 56 +++------------------------------------- drivers/usb/host/ehci-hcd.c | 57 +++++++++++++++++++++++++++++++++++++++++ drivers/usb/host/ehci.h | 4 +++ 3 files changed, 64 insertions(+), 53 deletions(-) diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c index 5a56f66cfa..cc2f33826a 100644 --- a/drivers/usb/host/ehci-generic.c +++ b/drivers/usb/host/ehci-generic.c @@ -26,56 +26,6 @@ struct generic_ehci { int reset_count; }; -static int ehci_setup_phy(struct udevice *dev, int index) -{ - struct generic_ehci *priv = dev_get_priv(dev); - int ret; - - ret = generic_phy_get_by_index(dev, index, &priv->phy); - if (ret) { - if (ret != -ENOENT) { - dev_err(dev, "failed to get usb phy\n"); - return ret; - } - } else { - ret = generic_phy_init(&priv->phy); - if (ret) { - dev_err(dev, "failed to init usb phy\n"); - return ret; - } - - ret = generic_phy_power_on(&priv->phy); - if (ret) { - dev_err(dev, "failed to power on usb phy\n"); - return generic_phy_exit(&priv->phy); - } - } - - return 0; -} - -static int ehci_shutdown_phy(struct udevice *dev) -{ - struct generic_ehci *priv = dev_get_priv(dev); - int ret = 0; - - if (generic_phy_valid(&priv->phy)) { - ret = generic_phy_power_off(&priv->phy); - if (ret) { - dev_err(dev, "failed to power off usb phy\n"); - return ret; - } - - ret = generic_phy_exit(&priv->phy); - if (ret) { - dev_err(dev, "failed to power off usb phy\n"); - return ret; - } - } - - return 0; -} - static int ehci_usb_probe(struct udevice *dev) { struct generic_ehci *priv = dev_get_priv(dev); @@ -145,7 +95,7 @@ static int ehci_usb_probe(struct udevice *dev) } } - err = ehci_setup_phy(dev, 0); + err = ehci_setup_phy(dev, &priv->phy, 0); if (err) goto reset_err; @@ -160,7 +110,7 @@ static int ehci_usb_probe(struct udevice *dev) return 0; phy_err: - ret = ehci_shutdown_phy(dev); + ret = ehci_shutdown_phy(dev, &priv->phy); if (ret) dev_err(dev, "failed to shutdown usb phy\n"); @@ -185,7 +135,7 @@ static int ehci_usb_remove(struct udevice *dev) if (ret) return ret; - ret = ehci_shutdown_phy(dev); + ret = ehci_shutdown_phy(dev, &priv->phy); if (ret) return ret; diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 663f748ffc..03758c2313 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1675,3 +1676,59 @@ struct dm_usb_ops ehci_usb_ops = { }; #endif + +#ifdef CONFIG_PHY +int ehci_setup_phy(struct udevice *dev, struct phy *phy, int index) +{ + int ret; + + if (!phy) + return 0; + + ret = generic_phy_get_by_index(dev, index, phy); + if (ret) { + if (ret != -ENOENT) { + dev_err(dev, "failed to get usb phy\n"); + return ret; + } + } else { + ret = generic_phy_init(phy); + if (ret) { + dev_err(dev, "failed to init usb phy\n"); + return ret; + } + + ret = generic_phy_power_on(phy); + if (ret) { + dev_err(dev, "failed to power on usb phy\n"); + return generic_phy_exit(phy); + } + } + + return 0; +} + +int ehci_shutdown_phy(struct udevice *dev, struct phy *phy) +{ + int ret = 0; + + if (!phy) + return 0; + + if (generic_phy_valid(phy)) { + ret = generic_phy_power_off(phy); + if (ret) { + dev_err(dev, "failed to power off usb phy\n"); + return ret; + } + + ret = generic_phy_exit(phy); + if (ret) { + dev_err(dev, "failed to power off usb phy\n"); + return ret; + } + } + + return 0; +} +#endif diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index 07de472f91..a03dbb0039 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h @@ -288,4 +288,8 @@ int ehci_register(struct udevice *dev, struct ehci_hccr *hccr, int ehci_deregister(struct udevice *dev); extern struct dm_usb_ops ehci_usb_ops; +/* EHCI PHY functions */ +int ehci_setup_phy(struct udevice *dev, struct phy *phy, int index); +int ehci_shutdown_phy(struct udevice *dev, struct phy *phy); + #endif /* USB_EHCI_H */