Skip to content

Commit

Permalink
bcm2835-cpufreq: Only report a single frequency when max and min freq…
Browse files Browse the repository at this point in the history
…uencies are the same

4.8 kernel gives EINV error when max and min frequencies are the same (e.g. from using force_turbo=1)
  • Loading branch information
popcornmix committed Oct 5, 2016
1 parent d3d0a59 commit 2fb843e
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions drivers/cpufreq/bcm2835-cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,8 @@

/* ---------- GLOBALS ---------- */
static struct cpufreq_driver bcm2835_cpufreq_driver; /* the cpufreq driver global */

static struct cpufreq_frequency_table bcm2835_freq_table[] = {
{0, 0, 0},
{0, 0, 0},
{0, 0, CPUFREQ_TABLE_END},
};
static unsigned int min_frequency, max_frequency;
static struct cpufreq_frequency_table bcm2835_freq_table[3];

/*
===============================================
Expand Down Expand Up @@ -155,10 +151,19 @@ static int bcm2835_cpufreq_driver_init(struct cpufreq_policy *policy)
}

/* now find out what the maximum and minimum frequencies are */
bcm2835_freq_table[0].frequency = bcm2835_cpufreq_get_clock(RPI_FIRMWARE_GET_MIN_CLOCK_RATE);
bcm2835_freq_table[1].frequency = bcm2835_cpufreq_get_clock(RPI_FIRMWARE_GET_MAX_CLOCK_RATE);
min_frequency = bcm2835_cpufreq_get_clock(RPI_FIRMWARE_GET_MIN_CLOCK_RATE);
max_frequency = bcm2835_cpufreq_get_clock(RPI_FIRMWARE_GET_MAX_CLOCK_RATE);

if (min_frequency == max_frequency) {
bcm2835_freq_table[0].frequency = min_frequency;
bcm2835_freq_table[1].frequency = CPUFREQ_TABLE_END;
} else {
bcm2835_freq_table[0].frequency = min_frequency;
bcm2835_freq_table[1].frequency = max_frequency;
bcm2835_freq_table[2].frequency = CPUFREQ_TABLE_END;
}

print_info("min=%d max=%d\n", bcm2835_freq_table[0].frequency, bcm2835_freq_table[1].frequency);
print_info("min=%d max=%d\n", min_frequency, max_frequency);
return cpufreq_generic_init(policy, bcm2835_freq_table, transition_latency);
}

Expand All @@ -170,7 +175,7 @@ static int bcm2835_cpufreq_driver_init(struct cpufreq_policy *policy)

static int bcm2835_cpufreq_driver_target_index(struct cpufreq_policy *policy, unsigned int state)
{
unsigned int target_freq = bcm2835_freq_table[state].frequency;
unsigned int target_freq = state == 0 ? min_frequency : max_frequency;
unsigned int cur = bcm2835_cpufreq_set_clock(policy->cur, target_freq);

if (!cur)
Expand All @@ -192,7 +197,7 @@ static unsigned int bcm2835_cpufreq_driver_get(unsigned int cpu)
{
unsigned int actual_rate = bcm2835_cpufreq_get_clock(RPI_FIRMWARE_GET_CLOCK_RATE);
print_debug("cpu%d: freq=%d\n", cpu, actual_rate);
return actual_rate <= bcm2835_freq_table[0].frequency ? bcm2835_freq_table[0].frequency : bcm2835_freq_table[1].frequency;
return actual_rate <= min_frequency ? min_frequency : max_frequency;
}

/* the CPUFreq driver */
Expand Down

0 comments on commit 2fb843e

Please sign in to comment.