ipq806x: rework L2 cache patch

Rework l2 scaling patch to fix some compile warning
and to imporve the caling timings by removing call to unnecessary
function.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
master
Ansuel Smith 4 years ago committed by Petr Štetiar
parent 583111c124
commit c692d896eb

@ -1,13 +1,25 @@
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -48,16 +48,71 @@ static int set_target(struct cpufreq_pol
@@ -39,20 +39,85 @@ static struct freq_attr *cpufreq_dt_attr
NULL,
};
+struct shared_data {
+ unsigned long *curr_freq_table;
+ unsigned long curr_l2_freq;
+ unsigned long curr_l2_volt;
+};
+
+static struct shared_data *cpus_shared_data;
+
static int set_target(struct cpufreq_policy *policy, unsigned int index)
{
struct private_data *priv = policy->driver_data;
unsigned long freq = policy->freq_table[index].frequency;
+ struct clk *l2_clk = policy->l2_clk;
+ struct regulator *l2_regulator = policy->l2_regulator;
+ unsigned long l2_freq, target_l2_freq;
+ unsigned long l2_vol, target_l2_vol;
+ unsigned long l2_vol, target_l2_volt;
+ unsigned long target_freq;
int ret;
@ -16,20 +28,19 @@
if (!ret) {
+ if (policy->l2_rate_set) {
+ static unsigned long krait_l2[CONFIG_NR_CPUS] = { };
+ int cpu, l2_index, tol = 0;
+
+ target_freq = freq * 1000;
+
+ krait_l2[policy->cpu] = target_freq;
+ cpus_shared_data->curr_freq_table[policy->cpu] = target_freq;
+ for_each_present_cpu(cpu)
+ target_freq = max(target_freq, krait_l2[cpu]);
+ if (cpu != policy->cpu)
+ target_freq = max(target_freq, cpus_shared_data->curr_freq_table[cpu]);
+
+ for (l2_index = 2; l2_index >= 0; l2_index--)
+ for (l2_index = 2; l2_index > 0; l2_index--)
+ if (target_freq >= policy->l2_cpufreq[l2_index])
+ break;
+
+ l2_freq = clk_get_rate(l2_clk);
+ l2_freq = cpus_shared_data->curr_l2_freq;
+ target_l2_freq = policy->l2_rate[l2_index];
+
+ if (l2_freq != target_l2_freq) {
@ -44,21 +55,24 @@
+ if (ret)
+ goto exit;
+ }
+
+ /* scale l2 with the core */
+ ret = clk_set_rate(l2_clk, target_l2_freq);
+ if (ret)
+ goto exit;
+ cpus_shared_data->curr_l2_freq = target_l2_freq;
+
+ if (policy->l2_volt_set) {
+
+ l2_vol = regulator_get_voltage(l2_regulator);
+ target_l2_vol = policy->l2_volt[l2_index];
+ l2_vol = cpus_shared_data->curr_l2_volt;
+ target_l2_volt = policy->l2_volt[l2_index];
+
+ if (l2_vol != target_l2_vol) {
+ tol = target_l2_vol * policy->l2_volt_tol / 100;
+ ret = regulator_set_voltage_tol(l2_regulator,target_l2_vol,tol);
+ if (l2_vol != target_l2_volt) {
+ tol = target_l2_volt * policy->l2_volt_tol / 100;
+ ret = regulator_set_voltage_tol(l2_regulator,target_l2_volt,tol);
+ if (ret)
+ goto exit;
+ cpus_shared_data->curr_l2_volt = target_l2_volt;
+ }
+ }
+ }
@ -72,7 +86,7 @@
mutex_unlock(&priv->lock);
return ret;
@@ -200,6 +255,9 @@ static int cpufreq_init(struct cpufreq_p
@@ -195,6 +260,9 @@ static int cpufreq_init(struct cpufreq_p
bool fallback = false;
const char *name;
int ret;
@ -82,7 +96,7 @@
cpu_dev = get_cpu_device(policy->cpu);
if (!cpu_dev) {
@@ -307,6 +365,57 @@ static int cpufreq_init(struct cpufreq_p
@@ -302,6 +370,57 @@ static int cpufreq_init(struct cpufreq_p
policy->suspend_freq = dev_pm_opp_get_suspend_opp_freq(cpu_dev) / 1000;
@ -140,9 +154,33 @@
/* Support turbo/boost mode */
if (policy_has_boost_freq(policy)) {
/* This gets disabled by core on driver unregister */
@@ -401,6 +520,14 @@ static int dt_cpufreq_probe(struct platf
if (ret)
return ret;
+ cpus_shared_data = kzalloc(sizeof(struct shared_data), GFP_KERNEL);
+ if (!cpus_shared_data)
+ return -ENOMEM;
+
+ cpus_shared_data->curr_freq_table = kzalloc(sizeof(int) * CONFIG_NR_CPUS, GFP_KERNEL);
+ if (!cpus_shared_data->curr_freq_table)
+ return -ENOMEM;
+
if (data) {
if (data->have_governor_per_policy)
dt_cpufreq_driver.flags |= CPUFREQ_HAVE_GOVERNOR_PER_POLICY;
@@ -419,6 +546,8 @@ static int dt_cpufreq_probe(struct platf
static int dt_cpufreq_remove(struct platform_device *pdev)
{
+ kfree(cpus_shared_data->curr_freq_table);
+ kfree(cpus_shared_data);
cpufreq_unregister_driver(&dt_cpufreq_driver);
return 0;
}
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -72,7 +72,15 @@ struct cpufreq_policy {
@@ -58,7 +58,15 @@ struct cpufreq_policy {
should set cpufreq */
unsigned int cpu; /* cpu managing this policy, must be online */

Loading…
Cancel
Save