Release 4.11 drivers/cpufreq/loongson2_cpufreq.c
/*
* Cpufreq driver for the loongson-2 processors
*
* The 2E revision of loongson processor not support this feature.
*
* Copyright (C) 2006 - 2008 Lemote Inc. & Institute of Computing Technology
* Author: Yanhua, yanh@lemote.com
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/cpufreq.h>
#include <linux/module.h>
#include <linux/err.h>
#include <linux/sched.h> /* set_cpus_allowed() */
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <asm/clock.h>
#include <asm/idle.h>
#include <asm/mach-loongson64/loongson.h>
static uint nowait;
static void (*saved_cpu_wait) (void);
static int loongson2_cpu_freq_notifier(struct notifier_block *nb,
unsigned long val, void *data);
static struct notifier_block loongson2_cpufreq_notifier_block = {
.notifier_call = loongson2_cpu_freq_notifier
};
static int loongson2_cpu_freq_notifier(struct notifier_block *nb,
unsigned long val, void *data)
{
if (val == CPUFREQ_POSTCHANGE)
current_cpu_data.udelay_val = loops_per_jiffy;
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Wu Zhangjin | 34 | 100.00% | 1 | 100.00% |
Total | 34 | 100.00% | 1 | 100.00% |
/*
* Here we notify other drivers of the proposed change and the final change.
*/
static int loongson2_cpufreq_target(struct cpufreq_policy *policy,
unsigned int index)
{
unsigned int cpu = policy->cpu;
cpumask_t cpus_allowed;
unsigned int freq;
cpus_allowed = current->cpus_allowed;
set_cpus_allowed_ptr(current, cpumask_of(cpu));
freq =
((cpu_clock_freq / 1000) *
loongson2_clockmod_table[index].driver_data) / 8;
set_cpus_allowed_ptr(current, &cpus_allowed);
/* setting the cpu frequency */
clk_set_rate(policy->clk, freq * 1000);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Wu Zhangjin | 76 | 86.36% | 1 | 16.67% |
Viresh Kumar | 6 | 6.82% | 3 | 50.00% |
Julia Lawall | 4 | 4.55% | 1 | 16.67% |
Aaro Koskinen | 2 | 2.27% | 1 | 16.67% |
Total | 88 | 100.00% | 6 | 100.00% |
static int loongson2_cpufreq_cpu_init(struct cpufreq_policy *policy)
{
struct clk *cpuclk;
int i;
unsigned long rate;
int ret;
cpuclk = clk_get(NULL, "cpu_clk");
if (IS_ERR(cpuclk)) {
pr_err("couldn't get CPU clk\n");
return PTR_ERR(cpuclk);
}
rate = cpu_clock_freq / 1000;
if (!rate) {
clk_put(cpuclk);
return -EINVAL;
}
/* clock table init */
for (i = 2;
(loongson2_clockmod_table[i].frequency != CPUFREQ_TABLE_END);
i++)
loongson2_clockmod_table[i].frequency = (rate * i) / 8;
ret = clk_set_rate(cpuclk, rate * 1000);
if (ret) {
clk_put(cpuclk);
return ret;
}
policy->clk = cpuclk;
return cpufreq_generic_init(policy, &loongson2_clockmod_table[0], 0);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Wu Zhangjin | 103 | 65.19% | 1 | 12.50% |
Aaro Koskinen | 25 | 15.82% | 2 | 25.00% |
Viresh Kumar | 14 | 8.86% | 2 | 25.00% |
Julia Lawall | 14 | 8.86% | 1 | 12.50% |
Joe Perches | 2 | 1.27% | 2 | 25.00% |
Total | 158 | 100.00% | 8 | 100.00% |
static int loongson2_cpufreq_exit(struct cpufreq_policy *policy)
{
clk_put(policy->clk);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Wu Zhangjin | 18 | 85.71% | 1 | 50.00% |
Viresh Kumar | 3 | 14.29% | 1 | 50.00% |
Total | 21 | 100.00% | 2 | 100.00% |
static struct cpufreq_driver loongson2_cpufreq_driver = {
.name = "loongson2",
.init = loongson2_cpufreq_cpu_init,
.verify = cpufreq_generic_frequency_table_verify,
.target_index = loongson2_cpufreq_target,
.get = cpufreq_generic_get,
.exit = loongson2_cpufreq_exit,
.attr = cpufreq_generic_attr,
};
static struct platform_device_id platform_device_ids[] = {
{
.name = "loongson2_cpufreq",
},
{}
};
MODULE_DEVICE_TABLE(platform, platform_device_ids);
static struct platform_driver platform_driver = {
.driver = {
.name = "loongson2_cpufreq",
},
.id_table = platform_device_ids,
};
/*
* This is the simple version of Loongson-2 wait, Maybe we need do this in
* interrupt disabled context.
*/
static DEFINE_SPINLOCK(loongson2_wait_lock);
static void loongson2_cpu_wait(void)
{
unsigned long flags;
u32 cpu_freq;
spin_lock_irqsave(&loongson2_wait_lock, flags);
cpu_freq = LOONGSON_CHIPCFG(0);
LOONGSON_CHIPCFG(0) &= ~0x7; /* Put CPU into wait mode */
LOONGSON_CHIPCFG(0) = cpu_freq; /* Restore CPU state */
spin_unlock_irqrestore(&loongson2_wait_lock, flags);
local_irq_enable();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Ralf Bächle | 46 | 79.31% | 2 | 66.67% |
Huacai Chen | 12 | 20.69% | 1 | 33.33% |
Total | 58 | 100.00% | 3 | 100.00% |
static int __init cpufreq_init(void)
{
int ret;
/* Register platform stuff */
ret = platform_driver_register(&platform_driver);
if (ret)
return ret;
pr_info("Loongson-2F CPU frequency driver\n");
cpufreq_register_notifier(&loongson2_cpufreq_notifier_block,
CPUFREQ_TRANSITION_NOTIFIER);
ret = cpufreq_register_driver(&loongson2_cpufreq_driver);
if (!ret && !nowait) {
saved_cpu_wait = cpu_wait;
cpu_wait = loongson2_cpu_wait;
}
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Wu Zhangjin | 69 | 98.57% | 1 | 50.00% |
Joe Perches | 1 | 1.43% | 1 | 50.00% |
Total | 70 | 100.00% | 2 | 100.00% |
static void __exit cpufreq_exit(void)
{
if (!nowait && saved_cpu_wait)
cpu_wait = saved_cpu_wait;
cpufreq_unregister_driver(&loongson2_cpufreq_driver);
cpufreq_unregister_notifier(&loongson2_cpufreq_notifier_block,
CPUFREQ_TRANSITION_NOTIFIER);
platform_driver_unregister(&platform_driver);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Wu Zhangjin | 40 | 100.00% | 1 | 100.00% |
Total | 40 | 100.00% | 1 | 100.00% |
module_init(cpufreq_init);
module_exit(cpufreq_exit);
module_param(nowait, uint, 0644);
MODULE_PARM_DESC(nowait, "Disable Loongson-2F specific wait");
MODULE_AUTHOR("Yanhua <yanh@lemote.com>");
MODULE_DESCRIPTION("cpufreq driver for Loongson2F");
MODULE_LICENSE("GPL");
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Wu Zhangjin | 534 | 77.84% | 1 | 5.56% |
Ralf Bächle | 58 | 8.45% | 5 | 27.78% |
Aaro Koskinen | 27 | 3.94% | 2 | 11.11% |
Viresh Kumar | 27 | 3.94% | 5 | 27.78% |
Julia Lawall | 18 | 2.62% | 2 | 11.11% |
Huacai Chen | 12 | 1.75% | 1 | 5.56% |
Joe Perches | 10 | 1.46% | 2 | 11.11% |
Total | 686 | 100.00% | 18 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.