012-3-clk-qcom-clk-rpm-Fix-clk_hw-references.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. From c260524aba53b57f72b5446ed553080df30b4d09 Mon Sep 17 00:00:00 2001
  2. From: Georgi Djakov <georgi.djakov@linaro.org>
  3. Date: Wed, 23 Nov 2016 16:52:49 +0200
  4. Subject: clk: qcom: clk-rpm: Fix clk_hw references
  5. Fix the clk_hw references to the actual clocks and add a xlate function
  6. to return the hw pointers from the already existing static array.
  7. Reported-by: Michael Scott <michael.scott@linaro.org>
  8. Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
  9. Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
  10. ---
  11. drivers/clk/qcom/clk-rpm.c | 36 ++++++++++++++++++++++--------------
  12. 1 file changed, 22 insertions(+), 14 deletions(-)
  13. --- a/drivers/clk/qcom/clk-rpm.c
  14. +++ b/drivers/clk/qcom/clk-rpm.c
  15. @@ -127,8 +127,8 @@ struct clk_rpm {
  16. struct rpm_cc {
  17. struct qcom_rpm *rpm;
  18. - struct clk_hw_onecell_data data;
  19. - struct clk_hw *hws[];
  20. + struct clk_rpm **clks;
  21. + size_t num_clks;
  22. };
  23. struct rpm_clk_desc {
  24. @@ -391,11 +391,23 @@ static const struct of_device_id rpm_clk
  25. };
  26. MODULE_DEVICE_TABLE(of, rpm_clk_match_table);
  27. +static struct clk_hw *qcom_rpm_clk_hw_get(struct of_phandle_args *clkspec,
  28. + void *data)
  29. +{
  30. + struct rpm_cc *rcc = data;
  31. + unsigned int idx = clkspec->args[0];
  32. +
  33. + if (idx >= rcc->num_clks) {
  34. + pr_err("%s: invalid index %u\n", __func__, idx);
  35. + return ERR_PTR(-EINVAL);
  36. + }
  37. +
  38. + return rcc->clks[idx] ? &rcc->clks[idx]->hw : ERR_PTR(-ENOENT);
  39. +}
  40. +
  41. static int rpm_clk_probe(struct platform_device *pdev)
  42. {
  43. - struct clk_hw **hws;
  44. struct rpm_cc *rcc;
  45. - struct clk_hw_onecell_data *data;
  46. int ret;
  47. size_t num_clks, i;
  48. struct qcom_rpm *rpm;
  49. @@ -415,14 +427,12 @@ static int rpm_clk_probe(struct platform
  50. rpm_clks = desc->clks;
  51. num_clks = desc->num_clks;
  52. - rcc = devm_kzalloc(&pdev->dev, sizeof(*rcc) + sizeof(*hws) * num_clks,
  53. - GFP_KERNEL);
  54. + rcc = devm_kzalloc(&pdev->dev, sizeof(*rcc), GFP_KERNEL);
  55. if (!rcc)
  56. return -ENOMEM;
  57. - hws = rcc->hws;
  58. - data = &rcc->data;
  59. - data->num = num_clks;
  60. + rcc->clks = rpm_clks;
  61. + rcc->num_clks = num_clks;
  62. for (i = 0; i < num_clks; i++) {
  63. if (!rpm_clks[i])
  64. @@ -436,18 +446,16 @@ static int rpm_clk_probe(struct platform
  65. }
  66. for (i = 0; i < num_clks; i++) {
  67. - if (!rpm_clks[i]) {
  68. - data->hws[i] = ERR_PTR(-ENOENT);
  69. + if (!rpm_clks[i])
  70. continue;
  71. - }
  72. ret = devm_clk_hw_register(&pdev->dev, &rpm_clks[i]->hw);
  73. if (ret)
  74. goto err;
  75. }
  76. - ret = of_clk_add_hw_provider(pdev->dev.of_node, of_clk_hw_onecell_get,
  77. - data);
  78. + ret = of_clk_add_hw_provider(pdev->dev.of_node, qcom_rpm_clk_hw_get,
  79. + rcc);
  80. if (ret)
  81. goto err;