PCI: qcom-ep: Rely on the clocks supplied by devicetree
authorManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Wed, 14 Sep 2022 07:53:40 +0000 (13:23 +0530)
committerLorenzo Pieralisi <lpieralisi@kernel.org>
Mon, 3 Oct 2022 08:38:16 +0000 (10:38 +0200)
Generally, device drivers should just rely on the platform data like
devicetree to supply the clocks required for the functioning of the
peripheral. There is no need to hardcode the clk info in the driver.
So get rid of the static clk info and obtain the platform supplied
clks.

The total number of clocks supplied is obtained using the
devm_clk_bulk_get_all() API and used for the rest of the clk_bulk_ APIs.

Link: https://lore.kernel.org/r/20220914075350.7992-3-manivannan.sadhasivam@linaro.org
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
drivers/pci/controller/dwc/pcie-qcom-ep.c

index 98c64a85d01f81a5f0b9e2999aeac43f41dfabe6..e6ba781594a60a1e185df041544e7231d4583241 100644 (file)
@@ -130,16 +130,6 @@ enum qcom_pcie_ep_link_status {
        QCOM_PCIE_EP_LINK_DOWN,
 };
 
-static struct clk_bulk_data qcom_pcie_ep_clks[] = {
-       { .id = "cfg" },
-       { .id = "aux" },
-       { .id = "bus_master" },
-       { .id = "bus_slave" },
-       { .id = "ref" },
-       { .id = "sleep" },
-       { .id = "slave_q2a" },
-};
-
 /**
  * struct qcom_pcie_ep - Qualcomm PCIe Endpoint Controller
  * @pci: Designware PCIe controller struct
@@ -151,6 +141,8 @@ static struct clk_bulk_data qcom_pcie_ep_clks[] = {
  * @reset: PERST# GPIO
  * @wake: WAKE# GPIO
  * @phy: PHY controller block
+ * @clks: PCIe clocks
+ * @num_clks: PCIe clocks count
  * @perst_en: Flag for PERST enable
  * @perst_sep_en: Flag for PERST separation enable
  * @link_status: PCIe Link status
@@ -170,6 +162,9 @@ struct qcom_pcie_ep {
        struct gpio_desc *wake;
        struct phy *phy;
 
+       struct clk_bulk_data *clks;
+       int num_clks;
+
        u32 perst_en;
        u32 perst_sep_en;
 
@@ -244,8 +239,7 @@ static int qcom_pcie_enable_resources(struct qcom_pcie_ep *pcie_ep)
 {
        int ret;
 
-       ret = clk_bulk_prepare_enable(ARRAY_SIZE(qcom_pcie_ep_clks),
-                                     qcom_pcie_ep_clks);
+       ret = clk_bulk_prepare_enable(pcie_ep->num_clks, pcie_ep->clks);
        if (ret)
                return ret;
 
@@ -266,8 +260,7 @@ static int qcom_pcie_enable_resources(struct qcom_pcie_ep *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);
+       clk_bulk_disable_unprepare(pcie_ep->num_clks, pcie_ep->clks);
 
        return ret;
 }
@@ -276,8 +269,7 @@ 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);
+       clk_bulk_disable_unprepare(pcie_ep->num_clks, pcie_ep->clks);
 }
 
 static int qcom_pcie_perst_deassert(struct dw_pcie *pci)
@@ -495,10 +487,11 @@ static int qcom_pcie_ep_get_resources(struct platform_device *pdev,
                return ret;
        }
 
-       ret = devm_clk_bulk_get(dev, ARRAY_SIZE(qcom_pcie_ep_clks),
-                               qcom_pcie_ep_clks);
-       if (ret)
-               return ret;
+       pcie_ep->num_clks = devm_clk_bulk_get_all(dev, &pcie_ep->clks);
+       if (pcie_ep->num_clks < 0) {
+               dev_err(dev, "Failed to get clocks\n");
+               return pcie_ep->num_clks;
+       }
 
        pcie_ep->core_reset = devm_reset_control_get_exclusive(dev, "core");
        if (IS_ERR(pcie_ep->core_reset))