Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4485100ybe; Mon, 9 Sep 2019 09:56:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTCei0q7wzwPrnWkZP0d9i7CNt4Zek9hKP5yNfNkaRWQWL3becmCTBB6OAyZqTk3KFAMH3 X-Received: by 2002:a17:907:2102:: with SMTP id qn2mr20705503ejb.266.1568048163231; Mon, 09 Sep 2019 09:56:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568048163; cv=none; d=google.com; s=arc-20160816; b=gSJi+KesO4/13Y2yEA9yt120joE016Z+oP2RfJDt5j1vpvbs/UL2wyu+Yowy1E4DqK eDRo1YQwC9mTSEiPUXCpFIdgIe7TX0kozoG3YiihMnmNQnTLMDyFcOIx/BmwhE0GPmC7 CPzJjte4i2X1jXqqPz9tRTADjSrIDVuHMzigPyEdQu8i1xwuNhBTT6F9eRSJ0b/4dBCy hcBus74Cy61/OdPxoEjIQ2NHJOuy6K897/pFhR2dH5kPbaqWu+9XASPHLfWbPwAnN022 zLlu6BTg+RwcOWoBmq5f1UOvRjtuE+EMR2sjR7hJfWbaOkeeYnyO6KbkQxODvfOkJ2oI m9aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=GfU3+s0+ry1VaN8+GjjuqfUgRel0oGwdsijTY+FcD+E=; b=WAWyV5d8VZwlqN4zNfQzUXH6e8cSNfFZ7YLi+Io8XIVYoQs2aahw57JTHouyEwYZaP H9zRVZ4fA2lkVM7g8VtwlPGfdYVinUailCXlAjHZmv4zESUP1GcKqmaLddWGBadaUoVG /Rcln74mCFBxsAi6/eS4g8xIMSRk7hEDs4IECJ+iCjDhAZ3POlLtEv0FcCHHb5nt1mTG mOuaFNl5ENazUueHIHDKKGMDZH44T7Hm0nHj09JQir/wEpOE91y2kFk9TkBhTeRKGzKH V4y+DgMWiVYP+6W/T8bJKZ5d6RzJucQZeHiageEykRzUHgIX1M/JpXU6hd1VUkQtF5lr gFtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=nG6KyFZy; 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 z11si4302202ejm.28.2019.09.09.09.55.38; Mon, 09 Sep 2019 09:56:03 -0700 (PDT) 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; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=nG6KyFZy; 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 S1728567AbfIHNn2 (ORCPT + 99 others); Sun, 8 Sep 2019 09:43:28 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:33922 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728335AbfIHNnL (ORCPT ); Sun, 8 Sep 2019 09:43:11 -0400 Received: by mail-wm1-f68.google.com with SMTP id y135so10877386wmc.1 for ; Sun, 08 Sep 2019 06:43:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GfU3+s0+ry1VaN8+GjjuqfUgRel0oGwdsijTY+FcD+E=; b=nG6KyFZyzSd3lTnGM5OP0RP5rl1BXxFirerAxOlFlCgvkh9kgICw0TRsZNyrZG29rv U50N5G0BoU62C/44fOS/2xXU9rtB9fYAQWqPxvprWVYUVpRN+qqdcnldv4sOj4FHRts+ Trz0KUu8QEiAdo9QNqxJ3X40hDGBW2E0pDWmNj3oZvQpwghUZA2SZAb4vrJ8T5S4nCdD wcgN+MLFNgeSK24EQk6mrM+2bGQaVn3uSJR1uZeJxFShK/X4MKZdBJMs8moCLhj7PXuH eLPQP1KEVSX+WZj+66OObsiGqJLAO3IPYgBqccEde9zB7MuyRFIXWb5JS5/ozFowccea kW3A== 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:in-reply-to :references; bh=GfU3+s0+ry1VaN8+GjjuqfUgRel0oGwdsijTY+FcD+E=; b=IJRmzjgebjZ8/Y/5FiK6afPHWCvopSpwK6FdIkTf1M9uHDOF84ubYQfMWbGm9c5/SO +tIqy8e/FbAJJOW+5nM0e3/WrXQ3/suJ+m4rlzH05JL1i0VoSHqlS6YI0KNCF02Xe7cf V2w0A6fNRRGopLcp6z/sQQZaNv39wZOkonh6JyECSFta6JVMnRG11h0t3xm9+Kp1CSon mZwT8VJoX/PS7qL4RCufvO2WKgUOIsMMTcmHBFslq73vidspL3Vr9yWKgl5gRs31RlCP jiTM0QjIZgSAOvYlIPx8gBQnyUXW4vW8FqPUEa5rYRvKRmj0H/SPp3afXDl6JhB/czcM u2Qg== X-Gm-Message-State: APjAAAV3ZBbupsqDxzlEoQyIgvuaqT43HORAzQ6i+eBfqOynQ+L5CXO9 EMF3/ObH1cDaUpKdkd9DIIEhqQ== X-Received: by 2002:a1c:4082:: with SMTP id n124mr15773002wma.154.1567950188213; Sun, 08 Sep 2019 06:43:08 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.gmail.com with ESMTPSA id t203sm14313902wmf.42.2019.09.08.06.43.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Sep 2019 06:43:07 -0700 (PDT) From: Neil Armstrong To: khilman@baylibre.com, bhelgaas@google.com, lorenzo.pieralisi@arm.com, yue.wang@Amlogic.com, kishon@ti.com Cc: repk@triplefau.lt, Neil Armstrong , maz@kernel.org, linux-amlogic@lists.infradead.org, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/6] PCI: amlogic: meson: Add support for G12A Date: Sun, 8 Sep 2019 13:42:55 +0000 Message-Id: <1567950178-4466-4-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1567950178-4466-1-git-send-email-narmstrong@baylibre.com> References: <1567950178-4466-1-git-send-email-narmstrong@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for the Amlogic G12A SoC using a separate shared PHY. This adds support for fetching a PHY phandle and call the PHY init, reset and power on/off calls instead of writing in the PHY register or toggling the PHY reset line. The MIPI clock is also made optional since it is used for setting up the PHY reference clock chared with the DSI controller on AXG. Signed-off-by: Neil Armstrong --- drivers/pci/controller/dwc/pci-meson.c | 101 ++++++++++++++++++++----- 1 file changed, 84 insertions(+), 17 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-meson.c b/drivers/pci/controller/dwc/pci-meson.c index ab79990798f8..3fadad381762 100644 --- a/drivers/pci/controller/dwc/pci-meson.c +++ b/drivers/pci/controller/dwc/pci-meson.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "pcie-designware.h" @@ -96,12 +97,18 @@ struct meson_pcie_rc_reset { struct reset_control *apb; }; +struct meson_pcie_param { + bool has_shared_phy; +}; + struct meson_pcie { struct dw_pcie pci; struct meson_pcie_mem_res mem_res; struct meson_pcie_clk_res clk_res; struct meson_pcie_rc_reset mrst; struct gpio_desc *reset_gpio; + struct phy *phy; + const struct meson_pcie_param *param; }; static struct reset_control *meson_pcie_get_reset(struct meson_pcie *mp, @@ -123,10 +130,12 @@ static int meson_pcie_get_resets(struct meson_pcie *mp) { struct meson_pcie_rc_reset *mrst = &mp->mrst; - mrst->phy = meson_pcie_get_reset(mp, "phy", PCIE_SHARED_RESET); - if (IS_ERR(mrst->phy)) - return PTR_ERR(mrst->phy); - reset_control_deassert(mrst->phy); + if (!mp->param->has_shared_phy) { + mrst->phy = meson_pcie_get_reset(mp, "phy", PCIE_SHARED_RESET); + if (IS_ERR(mrst->phy)) + return PTR_ERR(mrst->phy); + reset_control_deassert(mrst->phy); + } mrst->port = meson_pcie_get_reset(mp, "port", PCIE_NORMAL_RESET); if (IS_ERR(mrst->port)) @@ -180,6 +189,9 @@ static int meson_pcie_get_mems(struct platform_device *pdev, if (IS_ERR(mp->mem_res.cfg_base)) return PTR_ERR(mp->mem_res.cfg_base); + if (mp->param->has_shared_phy) + return 0; + /* Meson SoC has two PCI controllers use same phy register*/ mp->mem_res.phy_base = meson_pcie_get_mem_shared(pdev, mp, "phy"); if (IS_ERR(mp->mem_res.phy_base)) @@ -188,19 +200,33 @@ static int meson_pcie_get_mems(struct platform_device *pdev, return 0; } -static void meson_pcie_power_on(struct meson_pcie *mp) +static int meson_pcie_power_on(struct meson_pcie *mp) { - writel(MESON_PCIE_PHY_POWERUP, mp->mem_res.phy_base); + int ret = 0; + + if (mp->param->has_shared_phy) + ret = phy_power_on(mp->phy); + else + writel(MESON_PCIE_PHY_POWERUP, mp->mem_res.phy_base); + + return ret; } -static void meson_pcie_reset(struct meson_pcie *mp) +static int meson_pcie_reset(struct meson_pcie *mp) { struct meson_pcie_rc_reset *mrst = &mp->mrst; - - reset_control_assert(mrst->phy); - udelay(PCIE_RESET_DELAY); - reset_control_deassert(mrst->phy); - udelay(PCIE_RESET_DELAY); + int ret = 0; + + if (mp->param->has_shared_phy) { + ret = phy_reset(mp->phy); + if (ret) + return ret; + } else { + reset_control_assert(mrst->phy); + udelay(PCIE_RESET_DELAY); + reset_control_deassert(mrst->phy); + udelay(PCIE_RESET_DELAY); + } reset_control_assert(mrst->port); reset_control_assert(mrst->apb); @@ -208,6 +234,8 @@ static void meson_pcie_reset(struct meson_pcie *mp) reset_control_deassert(mrst->port); reset_control_deassert(mrst->apb); udelay(PCIE_RESET_DELAY); + + return 0; } static inline struct clk *meson_pcie_probe_clock(struct device *dev, @@ -250,9 +278,11 @@ static int meson_pcie_probe_clocks(struct meson_pcie *mp) if (IS_ERR(res->port_clk)) return PTR_ERR(res->port_clk); - res->mipi_gate = meson_pcie_probe_clock(dev, "mipi", 0); - if (IS_ERR(res->mipi_gate)) - return PTR_ERR(res->mipi_gate); + if (!mp->param->has_shared_phy) { + res->mipi_gate = meson_pcie_probe_clock(dev, "mipi", 0); + if (IS_ERR(res->mipi_gate)) + return PTR_ERR(res->mipi_gate); + } res->general_clk = meson_pcie_probe_clock(dev, "general", 0); if (IS_ERR(res->general_clk)) @@ -524,6 +554,7 @@ static const struct dw_pcie_ops dw_pcie_ops = { static int meson_pcie_probe(struct platform_device *pdev) { + const struct meson_pcie_param *match_data; struct device *dev = &pdev->dev; struct dw_pcie *pci; struct meson_pcie *mp; @@ -537,6 +568,20 @@ static int meson_pcie_probe(struct platform_device *pdev) pci->dev = dev; pci->ops = &dw_pcie_ops; + match_data = of_device_get_match_data(dev); + if (!match_data) { + dev_err(dev, "failed to get match data\n"); + return -ENODEV; + } + mp->param = match_data; + + if (mp->param->has_shared_phy) { + mp->phy = devm_phy_get(dev, "pcie"); + if (IS_ERR(mp->phy)) { + return PTR_ERR(mp->phy); + } + } + mp->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); if (IS_ERR(mp->reset_gpio)) { dev_err(dev, "get reset gpio failed\n"); @@ -555,8 +600,17 @@ static int meson_pcie_probe(struct platform_device *pdev) return ret; } - meson_pcie_power_on(mp); - meson_pcie_reset(mp); + ret = meson_pcie_power_on(mp); + if (ret) { + dev_err(dev, "phy power on failed, %d\n", ret); + return ret; + } + + ret = meson_pcie_reset(mp); + if (ret) { + dev_err(dev, "reset failed, %d\n", ret); + return ret; + } ret = meson_pcie_probe_clocks(mp); if (ret) { @@ -575,9 +629,22 @@ static int meson_pcie_probe(struct platform_device *pdev) return 0; } +static struct meson_pcie_param meson_pcie_axg_param = { + .has_shared_phy = false, +}; + +static struct meson_pcie_param meson_pcie_g12a_param = { + .has_shared_phy = true, +}; + static const struct of_device_id meson_pcie_of_match[] = { { .compatible = "amlogic,axg-pcie", + .data = &meson_pcie_axg_param, + }, + { + .compatible = "amlogic,g12a-pcie", + .data = &meson_pcie_g12a_param, }, {}, }; -- 2.17.1