0055-cpufreq-dt-Add-L2-frequency-scaling-support.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. From 0759cdff49f1cf361bf503c13f7bcb33da43ab95 Mon Sep 17 00:00:00 2001
  2. From: Georgi Djakov <[email protected]>
  3. Date: Tue, 8 Sep 2015 11:24:41 +0300
  4. Subject: [PATCH 55/69] cpufreq-dt: Add L2 frequency scaling support
  5. Signed-off-by: Georgi Djakov <[email protected]>
  6. ---
  7. drivers/cpufreq/cpufreq-dt.c | 41 ++++++++++++++++++++++++++++++++++++++++-
  8. include/linux/cpufreq.h | 2 ++
  9. 2 files changed, 42 insertions(+), 1 deletion(-)
  10. --- a/drivers/cpufreq/cpufreq-dt.c
  11. +++ b/drivers/cpufreq/cpufreq-dt.c
  12. @@ -49,11 +49,41 @@ static int set_target(struct cpufreq_pol
  13. struct private_data *priv = policy->driver_data;
  14. int ret;
  15. unsigned long target_freq = policy->freq_table[index].frequency * 1000;
  16. + struct clk *l2_clk = policy->l2_clk;
  17. + unsigned int l2_freq;
  18. + unsigned long new_l2_freq = 0;
  19. mutex_lock(&priv->lock);
  20. ret = dev_pm_opp_set_rate(priv->cpu_dev, target_freq);
  21. - if (!ret)
  22. +
  23. + if (!ret) {
  24. + if (!IS_ERR(l2_clk) && policy->l2_rate[0] && policy->l2_rate[1] &&
  25. + policy->l2_rate[2]) {
  26. + static unsigned long krait_l2[CONFIG_NR_CPUS] = { };
  27. + int cpu, ret = 0;
  28. +
  29. + if (target_freq >= policy->l2_rate[2])
  30. + new_l2_freq = policy->l2_rate[2];
  31. + else if (target_freq >= policy->l2_rate[1])
  32. + new_l2_freq = policy->l2_rate[1];
  33. + else
  34. + new_l2_freq = policy->l2_rate[0];
  35. +
  36. + krait_l2[policy->cpu] = new_l2_freq;
  37. + for_each_present_cpu(cpu)
  38. + new_l2_freq = max(new_l2_freq, krait_l2[cpu]);
  39. +
  40. + l2_freq = clk_get_rate(l2_clk);
  41. +
  42. + if (l2_freq != new_l2_freq) {
  43. + /* scale l2 with the core */
  44. + ret = clk_set_rate(l2_clk, new_l2_freq);
  45. + }
  46. + }
  47. +
  48. priv->opp_freq = target_freq;
  49. + }
  50. +
  51. mutex_unlock(&priv->lock);
  52. return ret;
  53. @@ -197,6 +227,8 @@ static int cpufreq_init(struct cpufreq_p
  54. const char *name;
  55. int ret;
  56. struct srcu_notifier_head *opp_srcu_head;
  57. + struct device_node *l2_np;
  58. + struct clk *l2_clk = NULL;
  59. cpu_dev = get_cpu_device(policy->cpu);
  60. if (!cpu_dev) {
  61. @@ -305,6 +337,13 @@ static int cpufreq_init(struct cpufreq_p
  62. policy->suspend_freq = dev_pm_opp_get_suspend_opp_freq(cpu_dev) / 1000;
  63. + l2_clk = clk_get(cpu_dev, "l2");
  64. + if (!IS_ERR(l2_clk))
  65. + policy->l2_clk = l2_clk;
  66. + l2_np = of_find_node_by_name(NULL, "qcom,l2");
  67. + if (l2_np)
  68. + of_property_read_u32_array(l2_np, "qcom,l2-rates", policy->l2_rate, 3);
  69. +
  70. ret = cpufreq_table_validate_and_show(policy, freq_table);
  71. if (ret) {
  72. dev_err(cpu_dev, "%s: invalid frequency table: %d\n", __func__,
  73. --- a/include/linux/cpufreq.h
  74. +++ b/include/linux/cpufreq.h
  75. @@ -73,6 +73,8 @@ struct cpufreq_policy {
  76. unsigned int cpu; /* cpu managing this policy, must be online */
  77. struct clk *clk;
  78. + struct clk *l2_clk; /* L2 clock */
  79. + unsigned int l2_rate[3]; /* L2 bus clock rate thresholds */
  80. struct cpufreq_cpuinfo cpuinfo;/* see above */
  81. unsigned int min; /* in kHz */