173-cpufreq-dt-Add-L2-frequency-scaling-support.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. From b4629f9e30e865402c643de6d4668be790fc0539 Mon Sep 17 00:00:00 2001
  2. From: Georgi Djakov <georgi.djakov@linaro.org>
  3. Date: Tue, 8 Sep 2015 11:24:41 +0300
  4. Subject: cpufreq-dt: Add L2 frequency scaling support
  5. Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
  6. Conflicts:
  7. drivers/cpufreq/cpufreq-dt.c
  8. ---
  9. drivers/cpufreq/cpufreq-dt.c | 54 ++++++++++++++++++++++++++++++++++++++------
  10. include/linux/cpufreq.h | 2 ++
  11. 2 files changed, 49 insertions(+), 7 deletions(-)
  12. --- a/drivers/cpufreq/cpufreq-dt.c
  13. +++ b/drivers/cpufreq/cpufreq-dt.c
  14. @@ -86,11 +86,13 @@ static int set_target(struct cpufreq_pol
  15. struct dev_pm_opp *opp;
  16. struct cpufreq_frequency_table *freq_table = policy->freq_table;
  17. struct clk *cpu_clk = policy->clk;
  18. + struct clk *l2_clk = policy->l2_clk;
  19. struct private_data *priv = policy->driver_data;
  20. struct device *cpu_dev = priv->cpu_dev;
  21. struct regulator *cpu_reg = priv->cpu_reg;
  22. unsigned long volt = 0, volt_old = 0, tol = 0;
  23. - unsigned int old_freq, new_freq;
  24. + unsigned int old_freq, new_freq, l2_freq;
  25. + unsigned long new_l2_freq = 0;
  26. long freq_Hz, freq_exact;
  27. unsigned long opp_freq = 0;
  28. int ret;
  29. @@ -146,6 +148,30 @@ static int set_target(struct cpufreq_pol
  30. goto out;
  31. }
  32. + if (!IS_ERR(l2_clk) && policy->l2_rate[0] && policy->l2_rate[1] &&
  33. + policy->l2_rate[2]) {
  34. + static unsigned long krait_l2[CONFIG_NR_CPUS] = { };
  35. + int cpu, ret = 0;
  36. +
  37. + if (freq_exact >= policy->l2_rate[2])
  38. + new_l2_freq = policy->l2_rate[2];
  39. + else if (freq_exact >= policy->l2_rate[1])
  40. + new_l2_freq = policy->l2_rate[1];
  41. + else
  42. + new_l2_freq = policy->l2_rate[0];
  43. +
  44. + krait_l2[policy->cpu] = new_l2_freq;
  45. + for_each_present_cpu(cpu)
  46. + new_l2_freq = max(new_l2_freq, krait_l2[cpu]);
  47. +
  48. + l2_freq = clk_get_rate(l2_clk);
  49. +
  50. + if (l2_freq != new_l2_freq) {
  51. + /* scale l2 with the core */
  52. + ret = clk_set_rate(l2_clk, new_l2_freq);
  53. + }
  54. + }
  55. +
  56. /* scaling down? scale voltage after frequency */
  57. if (!IS_ERR(cpu_reg) && new_freq < old_freq) {
  58. ret = regulator_set_voltage_tol(cpu_reg, volt, tol);
  59. @@ -156,18 +182,21 @@ static int set_target(struct cpufreq_pol
  60. goto out;
  61. }
  62. }
  63. +
  64. priv->opp_freq = opp_freq;
  65. +
  66. out:
  67. mutex_unlock(&priv->lock);
  68. return ret;
  69. }
  70. static int allocate_resources(int cpu, struct device **cdev,
  71. - struct regulator **creg, struct clk **cclk)
  72. + struct regulator **creg, struct clk **cclk,
  73. + struct clk **l2)
  74. {
  75. struct device *cpu_dev;
  76. struct regulator *cpu_reg;
  77. - struct clk *cpu_clk;
  78. + struct clk *cpu_clk, *l2_clk = NULL;
  79. int ret = 0;
  80. char *reg_cpu0 = "cpu0", *reg_cpu = "cpu", *reg;
  81. @@ -227,6 +256,10 @@ try_again:
  82. *cdev = cpu_dev;
  83. *creg = cpu_reg;
  84. *cclk = cpu_clk;
  85. +
  86. + l2_clk = clk_get(cpu_dev, "l2");
  87. + if (!IS_ERR(l2_clk))
  88. + *l2 = l2_clk;
  89. }
  90. return ret;
  91. @@ -236,18 +269,20 @@ static int cpufreq_init(struct cpufreq_p
  92. {
  93. struct cpufreq_frequency_table *freq_table;
  94. struct device_node *np;
  95. + struct device_node *l2_np;
  96. struct private_data *priv;
  97. struct device *cpu_dev;
  98. struct regulator *cpu_reg;
  99. - struct clk *cpu_clk;
  100. struct dev_pm_opp *suspend_opp;
  101. + struct clk *cpu_clk, *l2_clk;
  102. unsigned long min_uV = ~0, max_uV = 0;
  103. unsigned int transition_latency;
  104. bool need_update = false;
  105. int ret;
  106. struct srcu_notifier_head *opp_srcu_head;
  107. - ret = allocate_resources(policy->cpu, &cpu_dev, &cpu_reg, &cpu_clk);
  108. + ret = allocate_resources(policy->cpu, &cpu_dev, &cpu_reg, &cpu_clk,
  109. + &l2_clk);
  110. if (ret) {
  111. pr_err("%s: Failed to allocate resources: %d\n", __func__, ret);
  112. return ret;
  113. @@ -398,6 +433,11 @@ static int cpufreq_init(struct cpufreq_p
  114. if (suspend_opp)
  115. policy->suspend_freq = dev_pm_opp_get_freq(suspend_opp) / 1000;
  116. rcu_read_unlock();
  117. + policy->l2_clk = l2_clk;
  118. +
  119. + l2_np = of_find_node_by_name(NULL, "qcom,l2");
  120. + if (l2_np)
  121. + of_property_read_u32_array(l2_np, "qcom,l2-rates", policy->l2_rate, 3);
  122. ret = cpufreq_table_validate_and_show(policy, freq_table);
  123. if (ret) {
  124. @@ -498,7 +538,7 @@ static int dt_cpufreq_probe(struct platf
  125. {
  126. struct device *cpu_dev;
  127. struct regulator *cpu_reg;
  128. - struct clk *cpu_clk;
  129. + struct clk *cpu_clk, *l2_clk;
  130. int ret;
  131. /*
  132. @@ -508,7 +548,7 @@ static int dt_cpufreq_probe(struct platf
  133. *
  134. * FIXME: Is checking this only for CPU0 sufficient ?
  135. */
  136. - ret = allocate_resources(0, &cpu_dev, &cpu_reg, &cpu_clk);
  137. + ret = allocate_resources(0, &cpu_dev, &cpu_reg, &cpu_clk, &l2_clk);
  138. if (ret)
  139. return ret;
  140. --- a/include/linux/cpufreq.h
  141. +++ b/include/linux/cpufreq.h
  142. @@ -67,6 +67,8 @@ struct cpufreq_policy {
  143. unsigned int cpu; /* cpu managing this policy, must be online */
  144. struct clk *clk;
  145. + struct clk *l2_clk; /* L2 clock */
  146. + unsigned int l2_rate[3]; /* L2 bus clock rate thresholds */
  147. struct cpufreq_cpuinfo cpuinfo;/* see above */
  148. unsigned int min; /* in kHz */