All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Marek Vasut <marek.vasut+renesas@gmail.com>,
	Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: "Liang He" <windhl@126.com>,
	"Geert Uytterhoeven" <geert+renesas@glider.be>,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	linux-pci@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Geert Uytterhoeven" <geert@linux-m68k.org>
Subject: [PATCH 1/2] PCI: rcar: Add dev struct for of_device_get_match_data()
Date: Tue, 21 Jun 2022 21:57:31 -0500	[thread overview]
Message-ID: <20220622025732.1359389-2-helgaas@kernel.org> (raw)
In-Reply-To: <20220622025732.1359389-1-helgaas@kernel.org>

From: Bjorn Helgaas <bhelgaas@google.com>

Add a struct rcar_variant to hold details about differences between the
different R-Car variants we support.  No functional change intended.

The benefit is that we can find all this information with the existing
single of_device_get_match_data() call.  A subsequent commit will remove
an of_find_matching_node() call by extending this structure.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Liang He <windhl@126.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drivers/pci/controller/pcie-rcar-host.c | 53 +++++++++++++++----------
 1 file changed, 33 insertions(+), 20 deletions(-)

diff --git a/drivers/pci/controller/pcie-rcar-host.c b/drivers/pci/controller/pcie-rcar-host.c
index 997c4df6a1e7..ccf13aafa1e5 100644
--- a/drivers/pci/controller/pcie-rcar-host.c
+++ b/drivers/pci/controller/pcie-rcar-host.c
@@ -56,13 +56,19 @@ static void __iomem *pcie_base;
 static struct device *pcie_dev;
 #endif
 
+struct rcar_pcie_host;
+
+struct rcar_variant {
+	int	(*phy_init_fn)(struct rcar_pcie_host *host);
+};
+
 /* Structure representing the PCIe interface */
 struct rcar_pcie_host {
-	struct rcar_pcie	pcie;
-	struct phy		*phy;
-	struct clk		*bus_clk;
-	struct			rcar_msi msi;
-	int			(*phy_init_fn)(struct rcar_pcie_host *host);
+	struct rcar_pcie	  pcie;
+	struct phy		  *phy;
+	struct clk		  *bus_clk;
+	struct rcar_msi		  msi;
+	const struct rcar_variant *variant;
 };
 
 static DEFINE_SPINLOCK(pmsr_lock);
@@ -958,19 +964,26 @@ static int rcar_pcie_parse_map_dma_ranges(struct rcar_pcie_host *host)
 	return err;
 }
 
+static const struct rcar_variant rcar_h1_data = {
+	.phy_init_fn = rcar_pcie_phy_init_h1,
+};
+
+static const struct rcar_variant rcar_gen2_data = {
+	.phy_init_fn = rcar_pcie_phy_init_gen2,
+};
+
+static const struct rcar_variant rcar_gen3_data = {
+	.phy_init_fn = rcar_pcie_phy_init_gen3,
+};
+
 static const struct of_device_id rcar_pcie_of_match[] = {
-	{ .compatible = "renesas,pcie-r8a7779",
-	  .data = rcar_pcie_phy_init_h1 },
-	{ .compatible = "renesas,pcie-r8a7790",
-	  .data = rcar_pcie_phy_init_gen2 },
-	{ .compatible = "renesas,pcie-r8a7791",
-	  .data = rcar_pcie_phy_init_gen2 },
-	{ .compatible = "renesas,pcie-rcar-gen2",
-	  .data = rcar_pcie_phy_init_gen2 },
-	{ .compatible = "renesas,pcie-r8a7795",
-	  .data = rcar_pcie_phy_init_gen3 },
-	{ .compatible = "renesas,pcie-rcar-gen3",
-	  .data = rcar_pcie_phy_init_gen3 },
+	{ .compatible = "renesas,pcie-r8a7779",   .data = &rcar_h1_data },
+	{ .compatible = "renesas,pcie-r8a7790",   .data = &rcar_gen2_data },
+	{ .compatible = "renesas,pcie-r8a7791",   .data = &rcar_gen2_data },
+	{ .compatible = "renesas,pcie-rcar-gen2", .data = &rcar_gen2_data },
+
+	{ .compatible = "renesas,pcie-r8a7795",   .data = &rcar_gen3_data },
+	{ .compatible = "renesas,pcie-rcar-gen3", .data = &rcar_gen3_data },
 	{},
 };
 
@@ -1015,8 +1028,8 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 	if (err)
 		goto err_clk_disable;
 
-	host->phy_init_fn = of_device_get_match_data(dev);
-	err = host->phy_init_fn(host);
+	host->variant = of_device_get_match_data(dev);
+	err = host->variant->phy_init_fn(host);
 	if (err) {
 		dev_err(dev, "failed to init PCIe PHY\n");
 		goto err_clk_disable;
@@ -1084,7 +1097,7 @@ static int __maybe_unused rcar_pcie_resume(struct device *dev)
 		return 0;
 
 	/* Failure to get a link might just be that no cards are inserted */
-	err = host->phy_init_fn(host);
+	err = host->variant->phy_init_fn(host);
 	if (err) {
 		dev_info(dev, "PCIe link down\n");
 		return 0;
-- 
2.25.1


  reply	other threads:[~2022-06-22  2:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-22  2:57 [PATCH 0/2] PCI: rcar: Fix of_find_matching_node() reference leak Bjorn Helgaas
2022-06-22  2:57 ` Bjorn Helgaas [this message]
2022-06-22  2:57 ` [PATCH 2/2] PCI: rcar: Resolve " Bjorn Helgaas
2022-06-22  7:45   ` Geert Uytterhoeven
2022-06-22 11:05     ` Bjorn Helgaas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220622025732.1359389-2-helgaas@kernel.org \
    --to=helgaas@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=geert+renesas@glider.be \
    --cc=geert@linux-m68k.org \
    --cc=kw@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=marek.vasut+renesas@gmail.com \
    --cc=robh@kernel.org \
    --cc=windhl@126.com \
    --cc=yoshihiro.shimoda.uh@renesas.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.