[PATCH 08/13] pci: dwc: pcie-kirin: place common init code altogether

From: Mauro Carvalho Chehab
Date: Tue Feb 02 2021 - 08:33:37 EST


Both Kirin 960 and Kirin 970 need to do ioremap for apb, phy
and dbi.

So, use a shared code for those.

It should be noticed that the dbi remap is now done by dwc core,
so it can simply be removed from kirin970_pcie_get_resource().

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@xxxxxxxxxx>
---
drivers/pci/controller/dwc/pcie-kirin.c | 45 +++++++++++--------------
1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c
index e1ebe0747978..2bce6e3750d4 100644
--- a/drivers/pci/controller/dwc/pcie-kirin.c
+++ b/drivers/pci/controller/dwc/pcie-kirin.c
@@ -292,21 +292,27 @@ static void kirin970_pcie_set_eyeparam(struct kirin_pcie *kirin_pcie)
kirin_apb_natural_phy_writel(kirin_pcie, val, LANEN_DIG_ASIC_TX_OVRD_IN_1);
}

+static long kirin_common_pcie_get_resource(struct kirin_pcie *kirin_pcie,
+ struct platform_device *pdev)
+{
+ kirin_pcie->apb_base = devm_platform_ioremap_resource_byname(pdev,
+ "apb");
+ if (IS_ERR(kirin_pcie->apb_base))
+ return PTR_ERR(kirin_pcie->apb_base);
+
+ kirin_pcie->phy_base = devm_platform_ioremap_resource_byname(pdev,
+ "phy");
+ if (IS_ERR(kirin_pcie->phy_base))
+ return PTR_ERR(kirin_pcie->phy_base);
+
+ return 0;
+}
+
static long kirin960_pcie_get_resource(struct kirin_pcie *kirin_pcie,
struct platform_device *pdev)
{
struct device *dev = &pdev->dev;

- kirin_pcie->apb_base = devm_platform_ioremap_resource_byname(pdev,
- "apb");
- if (IS_ERR(kirin_pcie->apb_base))
- return PTR_ERR(kirin_pcie->apb_base);
-
- kirin_pcie->phy_base = devm_platform_ioremap_resource_byname(pdev,
- "phy");
- if (IS_ERR(kirin_pcie->phy_base))
- return PTR_ERR(kirin_pcie->phy_base);
-
kirin_pcie->crgctrl =
syscon_regmap_lookup_by_compatible("hisilicon,hi3660-crgctrl");
if (IS_ERR(kirin_pcie->crgctrl))
@@ -331,21 +337,6 @@ static long kirin970_pcie_get_resource(struct kirin_pcie *kirin_pcie,
struct device *dev = &pdev->dev;
int ret;

- kirin_pcie->apb_base = devm_platform_ioremap_resource_byname(pdev,
- "apb");
- if (IS_ERR(kirin_pcie->apb_base))
- return PTR_ERR(kirin_pcie->apb_base);
-
- kirin_pcie->phy_base = devm_platform_ioremap_resource_byname(pdev,
- "phy");
- if (IS_ERR(kirin_pcie->phy_base))
- return PTR_ERR(kirin_pcie->phy_base);
-
- kirin_pcie->pci->dbi_base = devm_platform_ioremap_resource_byname(pdev,
- "dbi");
- if (IS_ERR(kirin_pcie->pci->dbi_base))
- return PTR_ERR(kirin_pcie->pci->dbi_base);
-
kirin970_pcie_get_eyeparam(kirin_pcie);

kirin_pcie->gpio_id_reset[0] = of_get_named_gpio(dev->of_node,
@@ -1141,6 +1132,10 @@ static int kirin_pcie_probe(struct platform_device *pdev)
if (ret)
return ret;

+ ret = kirin_common_pcie_get_resource(kirin_pcie, pdev);
+ if (ret)
+ return ret;
+
ret = ops->get_resource(kirin_pcie, pdev);
if (ret)
return ret;
--
2.29.2