Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1682785imu; Wed, 12 Dec 2018 02:25:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/XZevSFY13Q9SZZmSE9ugtOjoPya744M/5IKxHS5ejtMnYnGaeTnfmRjsTTeHnkXKuoGrRH X-Received: by 2002:a62:8949:: with SMTP id v70mr19223489pfd.85.1544610346786; Wed, 12 Dec 2018 02:25:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544610346; cv=none; d=google.com; s=arc-20160816; b=KLfcxNGIrMcj0LSMWOyy+0ZqU1nx4Q/Qkk+BEre/YLosDsnghrvllDXJYmm/nkPPXL u4DqLNtAynZxaxVqTIPuWHzYt1zQPN84C+8Z9SGrrCfBHQYtQZEz/COP9slCVIZVDTAW AEmbs0SzMtBY80jHEEb3twtSh+Jww6TysJ2UQU+t1qs3gPM/0uLr9otcGOHfQ1TJjA8d d3MX0miPLvLmU5DnS5JX9Lh06WvyWWehm6faDsd+9aHPW4ORFg4WOzb3q4yDvyM+20X3 zM8Ml49Dxc4cHYahvuHu19AsQZ84DtD9AsRYHJbSguTICQZI59TXN9PN01FI0QrCEwQN jHvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=g6vGxRaWPMMzhlWEoqRqGyBOigeEyrJPtOMhVsCD0sc=; b=e45ud4yt0/k6y/9GQsIWojDvTMX9kWKbdmJX7IasHwqIixcdKOuGFbRVyRZESP9Hc5 1xqVOfu2pVKdS22b35OyLhA8dHnQro55eJ0yDl3Qc8i/Hop/VojCaweEfqEeSu0CKQa+ bP6ZS4RkdzMow5e3OnV3ndpnHF1Jz2itRb/o3hU3Jmx3XucEJYWzW+BJGi3idCYMu1fO 0hffM3faaBce2qVWpTSwlymG5eA1aNZZ7CEZThobnFQCxtsZsnWI8F7ELalmfgbOoa0P LE137Z2DCFk7liL5OznMsmS+lSiel6Byg6z+wu8OXyhJ5hm4S5lKF0clSM6byE+PG72v Kh2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u21si14239203pgg.463.2018.12.12.02.25.31; Wed, 12 Dec 2018 02:25:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727303AbeLLKXC (ORCPT + 99 others); Wed, 12 Dec 2018 05:23:02 -0500 Received: from mail.bootlin.com ([62.4.15.54]:57484 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726879AbeLLKWG (ORCPT ); Wed, 12 Dec 2018 05:22:06 -0500 Received: by mail.bootlin.com (Postfix, from userid 110) id B8C5820763; Wed, 12 Dec 2018 11:22:03 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.2 Received: from localhost.localdomain (aaubervilliers-681-1-89-7.w90-88.abo.wanadoo.fr [90.88.30.7]) by mail.bootlin.com (Postfix) with ESMTPSA id ED6B020763; Wed, 12 Dec 2018 11:21:44 +0100 (CET) From: Miquel Raynal To: Gregory Clement , Jason Cooper , Andrew Lunn , Sebastian Hesselbarth , Thomas Petazzoni , Bjorn Helgaas Cc: , Rob Herring , Mark Rutland , Lorenzo Pieralisi , linux-pci@vger.kernel.org, , , Antoine Tenart , Maxime Chevallier , Nadav Haklai , Miquel Raynal Subject: [PATCH v2 03/12] PCI: aardvark: Add PHY support Date: Wed, 12 Dec 2018 11:21:33 +0100 Message-Id: <20181212102142.16053-4-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181212102142.16053-1-miquel.raynal@bootlin.com> References: <20181212102142.16053-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The IP needs its PHY to be properly configured to work. While the PHY is usually already configured by the bootloader, we will need this feature when adding S2RAM support. Take care of registering and configuring the PHY from the driver itself. Suggested-by: Grzegorz Jaszczyk Signed-off-by: Miquel Raynal --- drivers/pci/controller/pci-aardvark.c | 62 +++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index 1d31d74ddab7..da695572a2ed 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -204,6 +205,7 @@ struct advk_pcie { int root_bus_nr; struct pci_bridge_emul bridge; struct gpio_desc *reset_gpio; + struct phy *phy; }; static inline void advk_writel(struct advk_pcie *pcie, u32 val, u64 reg) @@ -1025,6 +1027,62 @@ static int advk_pcie_setup_reset_gpio(struct advk_pcie *pcie) return 0; } +static void advk_pcie_disable_phy(struct advk_pcie *pcie) +{ + phy_power_off(pcie->phy); + phy_exit(pcie->phy); +} + +static int advk_pcie_enable_phy(struct advk_pcie *pcie) +{ + int ret; + + if (!pcie->phy) + return 0; + + ret = phy_init(pcie->phy); + if (ret) + return ret; + + ret = phy_set_mode(pcie->phy, PHY_MODE_PCIE); + if (ret) { + phy_exit(pcie->phy); + return ret; + } + + ret = phy_power_on(pcie->phy); + if (ret) { + phy_exit(pcie->phy); + return ret; + } + + return 0; +} + +static int advk_pcie_setup_phy(struct advk_pcie *pcie) +{ + struct device *dev = &pcie->pdev->dev; + struct device_node *node = dev->of_node; + int ret = 0; + + pcie->phy = devm_of_phy_get(dev, node, NULL); + if (IS_ERR(pcie->phy) && (PTR_ERR(pcie->phy) == -EPROBE_DEFER)) + return PTR_ERR(pcie->phy); + + /* Old bindings miss the PHY handle */ + if (IS_ERR(pcie->phy)) { + dev_warn(dev, "PHY unavailable (%ld)\n", PTR_ERR(pcie->phy)); + pcie->phy = NULL; + return 0; + } + + ret = advk_pcie_enable_phy(pcie); + if (ret) + dev_err(dev, "Failed to initialize PHY (%d)\n", ret); + + return ret; +} + static int advk_pcie_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1060,6 +1118,10 @@ static int advk_pcie_probe(struct platform_device *pdev) return ret; } + ret = advk_pcie_setup_phy(pcie); + if (ret) + return ret; + ret = advk_pcie_setup_reset_gpio(pcie); if (ret) return ret; -- 2.19.1