clk: qcom: Migrate to clk_hw based registration and OF APIs
authorStephen Boyd <stephen.boyd@linaro.org>
Tue, 16 Aug 2016 22:38:27 +0000 (15:38 -0700)
committerStephen Boyd <sboyd@codeaurora.org>
Thu, 25 Aug 2016 00:37:06 +0000 (17:37 -0700)
Now that we have clk_hw based provider APIs to register clks, we
can get rid of struct clk pointers in this driver, allowing us to
move closer to a clear split of consumer and provider clk APIs.

Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
drivers/clk/qcom/clk-regmap.c
drivers/clk/qcom/clk-regmap.h
drivers/clk/qcom/common.c
drivers/clk/qcom/gcc-mdm9615.c
drivers/clk/qcom/gcc-msm8996.c
drivers/clk/qcom/mmcc-msm8996.c

index a58ba39a900ce78239119125ca8844683d170f02..1c856d330733f160041a695a4aa205430e05a840 100644 (file)
@@ -101,14 +101,13 @@ EXPORT_SYMBOL_GPL(clk_disable_regmap);
  * clk_regmap struct via this function so that the regmap is initialized
  * and so that the clock is registered with the common clock framework.
  */
-struct clk *devm_clk_register_regmap(struct device *dev,
-                                    struct clk_regmap *rclk)
+int devm_clk_register_regmap(struct device *dev, struct clk_regmap *rclk)
 {
        if (dev && dev_get_regmap(dev, NULL))
                rclk->regmap = dev_get_regmap(dev, NULL);
        else if (dev && dev->parent)
                rclk->regmap = dev_get_regmap(dev->parent, NULL);
 
-       return devm_clk_register(dev, &rclk->hw);
+       return devm_clk_hw_register(dev, &rclk->hw);
 }
 EXPORT_SYMBOL_GPL(devm_clk_register_regmap);
index 491a63d537df9ebef56fa19c2597ee598844d87f..90d95cd11ec6329048127d402a49911c31aa0c9b 100644 (file)
@@ -39,7 +39,6 @@ struct clk_regmap {
 int clk_is_enabled_regmap(struct clk_hw *hw);
 int clk_enable_regmap(struct clk_hw *hw);
 void clk_disable_regmap(struct clk_hw *hw);
-struct clk *
-devm_clk_register_regmap(struct device *dev, struct clk_regmap *rclk);
+int devm_clk_register_regmap(struct device *dev, struct clk_regmap *rclk);
 
 #endif
index f7c226ab4307dbc308191d9392bfdb1bbf500431..fffcbaf0fba74b3fad90ea48c25761aa7873ab43 100644 (file)
@@ -27,8 +27,8 @@
 
 struct qcom_cc {
        struct qcom_reset_controller reset;
-       struct clk_onecell_data data;
-       struct clk *clks[];
+       struct clk_regmap **rclks;
+       size_t num_rclks;
 };
 
 const
@@ -102,8 +102,8 @@ static int _qcom_cc_register_board_clk(struct device *dev, const char *path,
        struct device_node *clocks_node;
        struct clk_fixed_factor *factor;
        struct clk_fixed_rate *fixed;
-       struct clk *clk;
        struct clk_init_data init_data = { };
+       int ret;
 
        clocks_node = of_find_node_by_path("/clocks");
        if (clocks_node)
@@ -121,9 +121,9 @@ static int _qcom_cc_register_board_clk(struct device *dev, const char *path,
                init_data.name = path;
                init_data.ops = &clk_fixed_rate_ops;
 
-               clk = devm_clk_register(dev, &fixed->hw);
-               if (IS_ERR(clk))
-                       return PTR_ERR(clk);
+               ret = devm_clk_hw_register(dev, &fixed->hw);
+               if (ret)
+                       return ret;
        }
        of_node_put(node);
 
@@ -141,9 +141,9 @@ static int _qcom_cc_register_board_clk(struct device *dev, const char *path,
                init_data.flags = 0;
                init_data.ops = &clk_fixed_factor_ops;
 
-               clk = devm_clk_register(dev, &factor->hw);
-               if (IS_ERR(clk))
-                       return PTR_ERR(clk);
+               ret = devm_clk_hw_register(dev, &factor->hw);
+               if (ret)
+                       return ret;
        }
 
        return 0;
@@ -174,42 +174,48 @@ int qcom_cc_register_sleep_clk(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(qcom_cc_register_sleep_clk);
 
+static struct clk_hw *qcom_cc_clk_hw_get(struct of_phandle_args *clkspec,
+                                        void *data)
+{
+       struct qcom_cc *cc = data;
+       unsigned int idx = clkspec->args[0];
+
+       if (idx >= cc->num_rclks) {
+               pr_err("%s: invalid index %u\n", __func__, idx);
+               return ERR_PTR(-EINVAL);
+       }
+
+       return cc->rclks[idx] ? &cc->rclks[idx]->hw : ERR_PTR(-ENOENT);
+}
+
 int qcom_cc_really_probe(struct platform_device *pdev,
                         const struct qcom_cc_desc *desc, struct regmap *regmap)
 {
        int i, ret;
        struct device *dev = &pdev->dev;
-       struct clk *clk;
-       struct clk_onecell_data *data;
-       struct clk **clks;
        struct qcom_reset_controller *reset;
        struct qcom_cc *cc;
        struct gdsc_desc *scd;
        size_t num_clks = desc->num_clks;
        struct clk_regmap **rclks = desc->clks;
 
-       cc = devm_kzalloc(dev, sizeof(*cc) + sizeof(*clks) * num_clks,
-                         GFP_KERNEL);
+       cc = devm_kzalloc(dev, sizeof(*cc), GFP_KERNEL);
        if (!cc)
                return -ENOMEM;
 
-       clks = cc->clks;
-       data = &cc->data;
-       data->clks = clks;
-       data->clk_num = num_clks;
+       cc->rclks = rclks;
+       cc->num_rclks = num_clks;
 
        for (i = 0; i < num_clks; i++) {
-               if (!rclks[i]) {
-                       clks[i] = ERR_PTR(-ENOENT);
+               if (!rclks[i])
                        continue;
-               }
-               clk = devm_clk_register_regmap(dev, rclks[i]);
-               if (IS_ERR(clk))
-                       return PTR_ERR(clk);
-               clks[i] = clk;
+
+               ret = devm_clk_register_regmap(dev, rclks[i]);
+               if (ret)
+                       return ret;
        }
 
-       ret = of_clk_add_provider(dev->of_node, of_clk_src_onecell_get, data);
+       ret = of_clk_add_hw_provider(dev->of_node, qcom_cc_clk_hw_get, cc);
        if (ret)
                return ret;
 
index 0f648fcb2b65e8fa5ff0532f1ab59992d5541373..581a17f67379b5465fbf1c85a8cc12e490418791 100644 (file)
@@ -1686,7 +1686,7 @@ static int gcc_mdm9615_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
        struct regmap *regmap;
-       struct clk *clk;
+       int ret;
        int i;
 
        regmap = qcom_cc_map(pdev, &gcc_mdm9615_desc);
@@ -1694,9 +1694,9 @@ static int gcc_mdm9615_probe(struct platform_device *pdev)
                return PTR_ERR(regmap);
 
        for (i = 0; i < ARRAY_SIZE(gcc_mdm9615_hws); i++) {
-               clk = devm_clk_register(dev, gcc_mdm9615_hws[i]);
-               if (IS_ERR(clk))
-                       return PTR_ERR(clk);
+               ret = devm_clk_hw_register(dev, gcc_mdm9615_hws[i]);
+               if (ret)
+                       return ret;
        }
 
        return qcom_cc_really_probe(pdev, &gcc_mdm9615_desc, regmap);
index bbf732bbc3fdc37dd79fd6475461356e64b85538..3afe42c9d61172b11ea47bfe3424530e4e680c52 100644 (file)
@@ -3447,9 +3447,8 @@ MODULE_DEVICE_TABLE(of, gcc_msm8996_match_table);
 
 static int gcc_msm8996_probe(struct platform_device *pdev)
 {
-       struct clk *clk;
        struct device *dev = &pdev->dev;
-       int i;
+       int i, ret;
        struct regmap *regmap;
 
        regmap = qcom_cc_map(pdev, &gcc_msm8996_desc);
@@ -3463,9 +3462,9 @@ static int gcc_msm8996_probe(struct platform_device *pdev)
        regmap_update_bits(regmap, 0x52008, BIT(21), BIT(21));
 
        for (i = 0; i < ARRAY_SIZE(gcc_msm8996_hws); i++) {
-               clk = devm_clk_register(dev, gcc_msm8996_hws[i]);
-               if (IS_ERR(clk))
-                       return PTR_ERR(clk);
+               ret = devm_clk_hw_register(dev, gcc_msm8996_hws[i]);
+               if (ret)
+                       return ret;
        }
 
        return qcom_cc_really_probe(pdev, &gcc_msm8996_desc, regmap);
index 18220458ee6ce866a6c35d2052c00fb8b1a2f1cb..ca97e11517976cbe81e895f8586d540283441591 100644 (file)
@@ -3314,9 +3314,8 @@ MODULE_DEVICE_TABLE(of, mmcc_msm8996_match_table);
 
 static int mmcc_msm8996_probe(struct platform_device *pdev)
 {
-       struct clk *clk;
        struct device *dev = &pdev->dev;
-       int i;
+       int i, ret;
        struct regmap *regmap;
 
        regmap = qcom_cc_map(pdev, &mmcc_msm8996_desc);
@@ -3329,9 +3328,9 @@ static int mmcc_msm8996_probe(struct platform_device *pdev)
        regmap_update_bits(regmap, 0x5054, BIT(15), 0);
 
        for (i = 0; i < ARRAY_SIZE(mmcc_msm8996_hws); i++) {
-               clk = devm_clk_register(dev, mmcc_msm8996_hws[i]);
-               if (IS_ERR(clk))
-                       return PTR_ERR(clk);
+               ret = devm_clk_hw_register(dev, mmcc_msm8996_hws[i]);
+               if (ret)
+                       return ret;
        }
 
        return qcom_cc_really_probe(pdev, &mmcc_msm8996_desc, regmap);