提交 bc49681c 编写于 作者: D Dmitry Baryshkov 提交者: Lorenzo Pieralisi

PCI: qcom-ep: Move enable/disable resources code to common functions

Remove code duplication by moving the code related to enabling/disabling
the resources (PHY, CLK, Reset) to common functions so that they can be
called from multiple places.

[mani: renamed the functions and reworded the commit message]
Link: https://lore.kernel.org/r/20220502104938.97033-1-manivannan.sadhasivam@linaro.orgSigned-off-by: NDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Signed-off-by: NManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
上级 571dda6c
...@@ -223,11 +223,8 @@ static void qcom_pcie_dw_stop_link(struct dw_pcie *pci) ...@@ -223,11 +223,8 @@ static void qcom_pcie_dw_stop_link(struct dw_pcie *pci)
disable_irq(pcie_ep->perst_irq); disable_irq(pcie_ep->perst_irq);
} }
static int qcom_pcie_perst_deassert(struct dw_pcie *pci) static int qcom_pcie_enable_resources(struct qcom_pcie_ep *pcie_ep)
{ {
struct qcom_pcie_ep *pcie_ep = to_pcie_ep(pci);
struct device *dev = pci->dev;
u32 val, offset;
int ret; int ret;
ret = clk_bulk_prepare_enable(ARRAY_SIZE(qcom_pcie_ep_clks), ret = clk_bulk_prepare_enable(ARRAY_SIZE(qcom_pcie_ep_clks),
...@@ -247,6 +244,38 @@ static int qcom_pcie_perst_deassert(struct dw_pcie *pci) ...@@ -247,6 +244,38 @@ static int qcom_pcie_perst_deassert(struct dw_pcie *pci)
if (ret) if (ret)
goto err_phy_exit; goto err_phy_exit;
return 0;
err_phy_exit:
phy_exit(pcie_ep->phy);
err_disable_clk:
clk_bulk_disable_unprepare(ARRAY_SIZE(qcom_pcie_ep_clks),
qcom_pcie_ep_clks);
return ret;
}
static void qcom_pcie_disable_resources(struct qcom_pcie_ep *pcie_ep)
{
phy_power_off(pcie_ep->phy);
phy_exit(pcie_ep->phy);
clk_bulk_disable_unprepare(ARRAY_SIZE(qcom_pcie_ep_clks),
qcom_pcie_ep_clks);
}
static int qcom_pcie_perst_deassert(struct dw_pcie *pci)
{
struct qcom_pcie_ep *pcie_ep = to_pcie_ep(pci);
struct device *dev = pci->dev;
u32 val, offset;
int ret;
ret = qcom_pcie_enable_resources(pcie_ep);
if (ret) {
dev_err(dev, "Failed to enable resources: %d\n", ret);
return ret;
}
/* Assert WAKE# to RC to indicate device is ready */ /* Assert WAKE# to RC to indicate device is ready */
gpiod_set_value_cansleep(pcie_ep->wake, 1); gpiod_set_value_cansleep(pcie_ep->wake, 1);
usleep_range(WAKE_DELAY_US, WAKE_DELAY_US + 500); usleep_range(WAKE_DELAY_US, WAKE_DELAY_US + 500);
...@@ -335,7 +364,7 @@ static int qcom_pcie_perst_deassert(struct dw_pcie *pci) ...@@ -335,7 +364,7 @@ static int qcom_pcie_perst_deassert(struct dw_pcie *pci)
ret = dw_pcie_ep_init_complete(&pcie_ep->pci.ep); ret = dw_pcie_ep_init_complete(&pcie_ep->pci.ep);
if (ret) { if (ret) {
dev_err(dev, "Failed to complete initialization: %d\n", ret); dev_err(dev, "Failed to complete initialization: %d\n", ret);
goto err_phy_power_off; goto err_disable_resources;
} }
/* /*
...@@ -355,13 +384,8 @@ static int qcom_pcie_perst_deassert(struct dw_pcie *pci) ...@@ -355,13 +384,8 @@ static int qcom_pcie_perst_deassert(struct dw_pcie *pci)
return 0; return 0;
err_phy_power_off: err_disable_resources:
phy_power_off(pcie_ep->phy); qcom_pcie_disable_resources(pcie_ep);
err_phy_exit:
phy_exit(pcie_ep->phy);
err_disable_clk:
clk_bulk_disable_unprepare(ARRAY_SIZE(qcom_pcie_ep_clks),
qcom_pcie_ep_clks);
return ret; return ret;
} }
...@@ -376,10 +400,7 @@ static void qcom_pcie_perst_assert(struct dw_pcie *pci) ...@@ -376,10 +400,7 @@ static void qcom_pcie_perst_assert(struct dw_pcie *pci)
return; return;
} }
phy_power_off(pcie_ep->phy); qcom_pcie_disable_resources(pcie_ep);
phy_exit(pcie_ep->phy);
clk_bulk_disable_unprepare(ARRAY_SIZE(qcom_pcie_ep_clks),
qcom_pcie_ep_clks);
pcie_ep->link_status = QCOM_PCIE_EP_LINK_DISABLED; pcie_ep->link_status = QCOM_PCIE_EP_LINK_DISABLED;
} }
...@@ -643,43 +664,26 @@ static int qcom_pcie_ep_probe(struct platform_device *pdev) ...@@ -643,43 +664,26 @@ static int qcom_pcie_ep_probe(struct platform_device *pdev)
if (ret) if (ret)
return ret; return ret;
ret = clk_bulk_prepare_enable(ARRAY_SIZE(qcom_pcie_ep_clks), ret = qcom_pcie_enable_resources(pcie_ep);
qcom_pcie_ep_clks); if (ret) {
if (ret) dev_err(dev, "Failed to enable resources: %d\n", ret);
return ret; return ret;
}
ret = qcom_pcie_ep_core_reset(pcie_ep);
if (ret)
goto err_disable_clk;
ret = phy_init(pcie_ep->phy);
if (ret)
goto err_disable_clk;
/* PHY needs to be powered on for dw_pcie_ep_init() */
ret = phy_power_on(pcie_ep->phy);
if (ret)
goto err_phy_exit;
ret = dw_pcie_ep_init(&pcie_ep->pci.ep); ret = dw_pcie_ep_init(&pcie_ep->pci.ep);
if (ret) { if (ret) {
dev_err(dev, "Failed to initialize endpoint: %d\n", ret); dev_err(dev, "Failed to initialize endpoint: %d\n", ret);
goto err_phy_power_off; goto err_disable_resources;
} }
ret = qcom_pcie_ep_enable_irq_resources(pdev, pcie_ep); ret = qcom_pcie_ep_enable_irq_resources(pdev, pcie_ep);
if (ret) if (ret)
goto err_phy_power_off; goto err_disable_resources;
return 0; return 0;
err_phy_power_off: err_disable_resources:
phy_power_off(pcie_ep->phy); qcom_pcie_disable_resources(pcie_ep);
err_phy_exit:
phy_exit(pcie_ep->phy);
err_disable_clk:
clk_bulk_disable_unprepare(ARRAY_SIZE(qcom_pcie_ep_clks),
qcom_pcie_ep_clks);
return ret; return ret;
} }
...@@ -691,10 +695,7 @@ static int qcom_pcie_ep_remove(struct platform_device *pdev) ...@@ -691,10 +695,7 @@ static int qcom_pcie_ep_remove(struct platform_device *pdev)
if (pcie_ep->link_status == QCOM_PCIE_EP_LINK_DISABLED) if (pcie_ep->link_status == QCOM_PCIE_EP_LINK_DISABLED)
return 0; return 0;
phy_power_off(pcie_ep->phy); qcom_pcie_disable_resources(pcie_ep);
phy_exit(pcie_ep->phy);
clk_bulk_disable_unprepare(ARRAY_SIZE(qcom_pcie_ep_clks),
qcom_pcie_ep_clks);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册