mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 20:07:46 +09:00
cpufreq: rockchip_big_little: add rockchip_bl_ prefix and indent
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
This commit is contained in:
@@ -11,7 +11,9 @@
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
#define pr_fmt(fmt) "cpufreq: " fmt
|
||||
|
||||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/cpufreq.h>
|
||||
#include <linux/err.h>
|
||||
@@ -44,7 +46,6 @@
|
||||
|
||||
#define RK3368_GRF_CPU_CON(n) (0x500 + 4*n)
|
||||
|
||||
|
||||
#define VERSION "1.0"
|
||||
#define RK_MAX_CLUSTERS 2
|
||||
|
||||
@@ -68,6 +69,7 @@ static struct cpufreq_frequency_table default_freq_table[] = {
|
||||
{.frequency = 1608 * 1000, .index = 1350 * 1000},
|
||||
{.frequency = CPUFREQ_TABLE_END},
|
||||
};
|
||||
|
||||
static struct cpufreq_frequency_table *freq_table[RK_MAX_CLUSTERS + 1];
|
||||
/*********************************************************/
|
||||
/* additional symantics for "relation" in cpufreq with pm */
|
||||
@@ -76,11 +78,11 @@ static struct cpufreq_frequency_table *freq_table[RK_MAX_CLUSTERS + 1];
|
||||
#define MASK_FURTHER_CPUFREQ 0x30
|
||||
/* With 0x00(NOCHANGE), it depends on the previous "further" status */
|
||||
#define CPUFREQ_PRIVATE 0x100
|
||||
static unsigned int no_cpufreq_access[RK_MAX_CLUSTERS] = {0};
|
||||
static unsigned int suspend_freq[RK_MAX_CLUSTERS] = {816 * 1000, 816 * 1000};
|
||||
static unsigned int no_cpufreq_access[RK_MAX_CLUSTERS] = { 0 };
|
||||
static unsigned int suspend_freq[RK_MAX_CLUSTERS] = { 816 * 1000, 816 * 1000 };
|
||||
static unsigned int suspend_volt = 1100000;
|
||||
static unsigned int low_battery_freq[RK_MAX_CLUSTERS] = {600 * 1000,
|
||||
600 * 1000};
|
||||
static unsigned int low_battery_freq[RK_MAX_CLUSTERS] = { 600 * 1000,
|
||||
600 * 1000 };
|
||||
static unsigned int low_battery_capacity = 5;
|
||||
static bool is_booting = true;
|
||||
static DEFINE_MUTEX(cpufreq_mutex);
|
||||
@@ -91,12 +93,12 @@ static u32 cluster_policy_cpu[RK_MAX_CLUSTERS];
|
||||
static unsigned int big_little = 1;
|
||||
|
||||
/*******************************************************/
|
||||
static int cpu_to_cluster(int cpu)
|
||||
static inline int cpu_to_cluster(int cpu)
|
||||
{
|
||||
return topology_physical_package_id(cpu);
|
||||
}
|
||||
|
||||
static unsigned int cpufreq_bl_get_rate(unsigned int cpu)
|
||||
static unsigned int rockchip_bl_cpufreq_get_rate(unsigned int cpu)
|
||||
{
|
||||
u32 cur_cluster = cpu_to_cluster(cpu);
|
||||
|
||||
@@ -121,8 +123,8 @@ static unsigned int get_freq_from_table(unsigned int max_freq,
|
||||
unsigned int i;
|
||||
unsigned int target_freq = 0;
|
||||
|
||||
for (i = 0; freq_table[cluster][i].frequency !=
|
||||
CPUFREQ_TABLE_END; i++) {
|
||||
for (i = 0; freq_table[cluster][i].frequency != CPUFREQ_TABLE_END;
|
||||
i++) {
|
||||
unsigned int freq = freq_table[cluster][i].frequency;
|
||||
|
||||
if (freq <= max_freq && target_freq < freq)
|
||||
@@ -133,8 +135,9 @@ static unsigned int get_freq_from_table(unsigned int max_freq,
|
||||
return target_freq;
|
||||
}
|
||||
|
||||
static int cpufreq_notifier_policy(struct notifier_block *nb, unsigned long val,
|
||||
void *data)
|
||||
static int rockchip_bl_cpufreq_notifier_policy(struct notifier_block *nb,
|
||||
unsigned long val,
|
||||
void *data)
|
||||
{
|
||||
static unsigned int min_rate = 0, max_rate = -1;
|
||||
struct cpufreq_policy *policy = data;
|
||||
@@ -157,10 +160,10 @@ static int cpufreq_notifier_policy(struct notifier_block *nb, unsigned long val,
|
||||
}
|
||||
|
||||
static struct notifier_block notifier_policy_block = {
|
||||
.notifier_call = cpufreq_notifier_policy
|
||||
.notifier_call = rockchip_bl_cpufreq_notifier_policy
|
||||
};
|
||||
|
||||
static int cpufreq_bl_verify(struct cpufreq_policy *policy)
|
||||
static int rockchip_bl_cpufreq_verify(struct cpufreq_policy *policy)
|
||||
{
|
||||
u32 cur_cluster = cpu_to_cluster(policy->cpu);
|
||||
|
||||
@@ -180,7 +183,8 @@ static int clk_node_get_cluster_id(struct clk *clk)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpufreq_bl_scale_rate_for_dvfs(struct clk *clk, unsigned long rate)
|
||||
static int rockchip_bl_cpufreq_scale_rate_for_dvfs(struct clk *clk,
|
||||
unsigned long rate)
|
||||
{
|
||||
int ret;
|
||||
struct cpufreq_freqs freqs;
|
||||
@@ -216,8 +220,9 @@ static int cluster_cpus_freq_dvfs_init(u32 cluster_id, char *dvfs_name)
|
||||
__func__, cluster_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
dvfs_clk_register_set_rate_callback(clk_cpu_dvfs_node[cluster_id],
|
||||
cpufreq_bl_scale_rate_for_dvfs);
|
||||
dvfs_clk_register_set_rate_callback(
|
||||
clk_cpu_dvfs_node[cluster_id],
|
||||
rockchip_bl_cpufreq_scale_rate_for_dvfs);
|
||||
freq_table[cluster_id] =
|
||||
dvfs_get_freq_volt_table(clk_cpu_dvfs_node[cluster_id]);
|
||||
if (freq_table[cluster_id] == NULL) {
|
||||
@@ -227,22 +232,22 @@ static int cluster_cpus_freq_dvfs_init(u32 cluster_id, char *dvfs_name)
|
||||
int i;
|
||||
|
||||
for (i = 0; freq_table[cluster_id][i].frequency !=
|
||||
CPUFREQ_TABLE_END; i++) {
|
||||
CPUFREQ_TABLE_END; i++) {
|
||||
if (freq_table[cluster_id][i].index >= suspend_volt &&
|
||||
v > freq_table[cluster_id][i].index) {
|
||||
suspend_freq[cluster_id] =
|
||||
freq_table[cluster_id][i].frequency;
|
||||
v = freq_table[cluster_id][i].index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
low_battery_freq[cluster_id] =
|
||||
get_freq_from_table(low_battery_freq[cluster_id], cluster_id);
|
||||
clk_enable_dvfs(clk_cpu_dvfs_node[cluster_id]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpufreq_bl_init_cpu0(struct cpufreq_policy *policy)
|
||||
static int rockchip_bl_cpufreq_init_cpu0(struct cpufreq_policy *policy)
|
||||
{
|
||||
clk_gpu_dvfs_node = clk_get_dvfs_node("clk_gpu");
|
||||
if (clk_gpu_dvfs_node)
|
||||
@@ -258,18 +263,18 @@ static int cpufreq_bl_init_cpu0(struct cpufreq_policy *policy)
|
||||
cpufreq_register_notifier(¬ifier_policy_block,
|
||||
CPUFREQ_POLICY_NOTIFIER);
|
||||
|
||||
pr_info("cpufreq version " VERSION ", suspend freq %d %d MHz\n",
|
||||
pr_info("version " VERSION ", suspend freq %d %d MHz\n",
|
||||
suspend_freq[0] / 1000, suspend_freq[1] / 1000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpufreq_bl_init(struct cpufreq_policy *policy)
|
||||
static int rockchip_bl_cpufreq_init(struct cpufreq_policy *policy)
|
||||
{
|
||||
static int cpu0_err;
|
||||
u32 cur_cluster = cpu_to_cluster(policy->cpu);
|
||||
|
||||
if (policy->cpu == 0)
|
||||
cpu0_err = cpufreq_bl_init_cpu0(policy);
|
||||
cpu0_err = rockchip_bl_cpufreq_init_cpu0(policy);
|
||||
if (cpu0_err)
|
||||
return cpu0_err;
|
||||
|
||||
@@ -280,14 +285,8 @@ static int cpufreq_bl_init(struct cpufreq_policy *policy)
|
||||
/* sys nod */
|
||||
cpufreq_frequency_table_get_attr(freq_table[cur_cluster], policy->cpu);
|
||||
|
||||
if (cur_cluster < RK_MAX_CLUSTERS) {
|
||||
/* int cpu; */
|
||||
if (cur_cluster < RK_MAX_CLUSTERS)
|
||||
cpumask_copy(policy->cpus, topology_core_cpumask(policy->cpu));
|
||||
/* for_each_cpu(cpu, policy->cpus) {
|
||||
pr_info("%s:policy->cpu=%d,cpu=%d,%02x\n",
|
||||
__func__, policy->cpu, cpu, policy->cpus[0]);
|
||||
} */
|
||||
}
|
||||
|
||||
policy->cur = clk_get_rate(clk_cpu_dvfs_node[cur_cluster]->clk) / 1000;
|
||||
|
||||
@@ -297,7 +296,7 @@ static int cpufreq_bl_init(struct cpufreq_policy *policy)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpufreq_bl_exit(struct cpufreq_policy *policy)
|
||||
static int rockchip_bl_cpufreq_exit(struct cpufreq_policy *policy)
|
||||
{
|
||||
u32 cur_cluster = cpu_to_cluster(policy->cpu);
|
||||
|
||||
@@ -311,7 +310,7 @@ static int cpufreq_bl_exit(struct cpufreq_policy *policy)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct freq_attr *cpufreq_attr[] = {
|
||||
static struct freq_attr *rockchip_bl_cpufreq_attr[] = {
|
||||
&cpufreq_freq_attr_scaling_available_freqs,
|
||||
NULL,
|
||||
};
|
||||
@@ -319,12 +318,15 @@ static struct freq_attr *cpufreq_attr[] = {
|
||||
#ifdef CONFIG_CHARGER_DISPLAY
|
||||
extern int rk_get_system_battery_capacity(void);
|
||||
#else
|
||||
static int rk_get_system_battery_capacity(void) { return 100; }
|
||||
static int rk_get_system_battery_capacity(void)
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
#endif
|
||||
|
||||
static unsigned int cpufreq_bl_scale_limit(unsigned int target_freq,
|
||||
struct cpufreq_policy *policy,
|
||||
bool is_private)
|
||||
static unsigned int
|
||||
rockchip_bl_cpufreq_scale_limit(unsigned int target_freq,
|
||||
struct cpufreq_policy *policy, bool is_private)
|
||||
{
|
||||
bool is_ondemand = cpufreq_is_ondemand(policy);
|
||||
u32 cur_cluster = cpu_to_cluster(policy->cpu);
|
||||
@@ -347,8 +349,9 @@ static unsigned int cpufreq_bl_scale_limit(unsigned int target_freq,
|
||||
return target_freq;
|
||||
}
|
||||
|
||||
static int cpufreq_bl_target(struct cpufreq_policy *policy,
|
||||
unsigned int target_freq, unsigned int relation)
|
||||
static int rockchip_bl_cpufreq_target(struct cpufreq_policy *policy,
|
||||
unsigned int target_freq,
|
||||
unsigned int relation)
|
||||
{
|
||||
unsigned int i, new_freq = target_freq, new_rate, cur_rate;
|
||||
int ret = 0;
|
||||
@@ -386,7 +389,9 @@ static int cpufreq_bl_target(struct cpufreq_policy *policy,
|
||||
}
|
||||
new_freq = freq_table[cur_cluster][i].frequency;
|
||||
if (!no_cpufreq_access[cur_cluster])
|
||||
new_freq = cpufreq_bl_scale_limit(new_freq, policy, is_private);
|
||||
new_freq =
|
||||
rockchip_bl_cpufreq_scale_limit(new_freq, policy,
|
||||
is_private);
|
||||
|
||||
new_rate = new_freq * 1000;
|
||||
cur_rate = dvfs_clk_get_rate(clk_cpu_dvfs_node[cur_cluster]);
|
||||
@@ -402,8 +407,8 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int cpufreq_pm_notifier_event(struct notifier_block *this,
|
||||
unsigned long event, void *ptr)
|
||||
static int rockchip_bl_cpufreq_pm_notifier_event(struct notifier_block *this,
|
||||
unsigned long event, void *ptr)
|
||||
{
|
||||
int ret = NOTIFY_DONE;
|
||||
int i;
|
||||
@@ -433,10 +438,10 @@ static int cpufreq_pm_notifier_event(struct notifier_block *this,
|
||||
case PM_POST_RESTORE:
|
||||
case PM_POST_SUSPEND:
|
||||
/* if (target_freq == policy->cur) then
|
||||
cpufreq_driver_target will return, and
|
||||
our target will not be called, it casue
|
||||
ENABLE_FURTHER_CPUFREQ flag invalid,
|
||||
avoid that. */
|
||||
cpufreq_driver_target will return, and
|
||||
our target will not be called, it casue
|
||||
ENABLE_FURTHER_CPUFREQ flag invalid,
|
||||
avoid that. */
|
||||
policy->cur++;
|
||||
cpufreq_driver_target(policy, suspend_freq[i],
|
||||
ENABLE_FURTHER_CPUFREQ |
|
||||
@@ -450,8 +455,8 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct notifier_block cpufreq_pm_notifier = {
|
||||
.notifier_call = cpufreq_pm_notifier_event,
|
||||
static struct notifier_block rockchip_bl_cpufreq_pm_notifier = {
|
||||
.notifier_call = rockchip_bl_cpufreq_pm_notifier_event,
|
||||
};
|
||||
|
||||
static int rockchip_bl_cpufreq_reboot_limit_freq(void)
|
||||
@@ -465,25 +470,26 @@ static int rockchip_bl_cpufreq_reboot_limit_freq(void)
|
||||
|
||||
for (i = 0; i < RK_MAX_CLUSTERS; i++) {
|
||||
dvfs_clk_enable_limit(clk_cpu_dvfs_node[i],
|
||||
1000*suspend_freq[i],
|
||||
1000*suspend_freq[i]);
|
||||
rate = dvfs_clk_get_rate(clk_cpu_dvfs_node[i]);
|
||||
1000 * suspend_freq[i],
|
||||
1000 * suspend_freq[i]);
|
||||
rate = dvfs_clk_get_rate(clk_cpu_dvfs_node[i]);
|
||||
}
|
||||
|
||||
regulator = dvfs_get_regulator("vdd_arm");
|
||||
if (regulator)
|
||||
volt = regulator_get_voltage(regulator);
|
||||
else
|
||||
pr_info("cpufreq: get arm regulator failed\n");
|
||||
pr_info("cpufreq: reboot set cluster0 rate=%lu, cluster1 rate=%lu, volt=%d\n",
|
||||
pr_info("get arm regulator failed\n");
|
||||
pr_info("reboot set cluster0 rate=%lu, cluster1 rate=%lu, volt=%d\n",
|
||||
dvfs_clk_get_rate(clk_cpu_dvfs_node[0]),
|
||||
dvfs_clk_get_rate(clk_cpu_dvfs_node[1]), volt);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpufreq_reboot_notifier_event(struct notifier_block *this,
|
||||
unsigned long event, void *ptr)
|
||||
static int rockchip_bl_cpufreq_reboot_notifier_event(struct notifier_block
|
||||
*this, unsigned long event,
|
||||
void *ptr)
|
||||
{
|
||||
rockchip_set_system_status(SYS_STATUS_REBOOT);
|
||||
rockchip_bl_cpufreq_reboot_limit_freq();
|
||||
@@ -491,38 +497,38 @@ static int cpufreq_reboot_notifier_event(struct notifier_block *this,
|
||||
return NOTIFY_OK;
|
||||
};
|
||||
|
||||
static struct notifier_block cpufreq_reboot_notifier = {
|
||||
.notifier_call = cpufreq_reboot_notifier_event,
|
||||
static struct notifier_block rockchip_bl_cpufreq_reboot_notifier = {
|
||||
.notifier_call = rockchip_bl_cpufreq_reboot_notifier_event,
|
||||
};
|
||||
|
||||
static struct cpufreq_driver cpufreq_driver = {
|
||||
static struct cpufreq_driver rockchip_bl_cpufreq_driver = {
|
||||
.flags = CPUFREQ_CONST_LOOPS,
|
||||
.verify = cpufreq_bl_verify,
|
||||
.target = cpufreq_bl_target,
|
||||
.get = cpufreq_bl_get_rate,
|
||||
.init = cpufreq_bl_init,
|
||||
.exit = cpufreq_bl_exit,
|
||||
.verify = rockchip_bl_cpufreq_verify,
|
||||
.target = rockchip_bl_cpufreq_target,
|
||||
.get = rockchip_bl_cpufreq_get_rate,
|
||||
.init = rockchip_bl_cpufreq_init,
|
||||
.exit = rockchip_bl_cpufreq_exit,
|
||||
.name = "rockchip-bl",
|
||||
.have_governor_per_policy = true,
|
||||
.attr = cpufreq_attr,
|
||||
.attr = rockchip_bl_cpufreq_attr,
|
||||
};
|
||||
|
||||
static const struct of_device_id cpufreq_match[] = {
|
||||
static const struct of_device_id rockchip_bl_cpufreq_match[] = {
|
||||
{
|
||||
.compatible = "rockchip,rk3368-cpufreq",
|
||||
},
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, cpufreq_match);
|
||||
MODULE_DEVICE_TABLE(of, rockchip_bl_cpufreq_match);
|
||||
|
||||
static int cpufreq_probe(struct platform_device *pdev)
|
||||
static int rockchip_bl_cpufreq_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device_node *np;
|
||||
struct regmap *grf_regmap;
|
||||
unsigned int big_bits, litt_bits;
|
||||
int ret;
|
||||
|
||||
np = pdev->dev.of_node;
|
||||
np = pdev->dev.of_node;
|
||||
if (!np)
|
||||
return -ENODEV;
|
||||
|
||||
@@ -536,8 +542,7 @@ static int cpufreq_probe(struct platform_device *pdev)
|
||||
FREQ_ERR("Cpufreq couldn't read to GRF\n");
|
||||
return -1;
|
||||
}
|
||||
ret = regmap_read(grf_regmap, RK3368_GRF_CPU_CON(1),
|
||||
&litt_bits);
|
||||
ret = regmap_read(grf_regmap, RK3368_GRF_CPU_CON(1), &litt_bits);
|
||||
if (ret != 0) {
|
||||
FREQ_ERR("Cpufreq couldn't read to GRF\n");
|
||||
return -1;
|
||||
@@ -550,30 +555,31 @@ static int cpufreq_probe(struct platform_device *pdev)
|
||||
big_little = 1;
|
||||
else if (big_bits == 0x0 && litt_bits == 0x01)
|
||||
big_little = 0;
|
||||
pr_info("cpufreq: boot from %d\n", big_little);
|
||||
pr_info("boot from %d\n", big_little);
|
||||
|
||||
register_reboot_notifier(&cpufreq_reboot_notifier);
|
||||
register_pm_notifier(&cpufreq_pm_notifier);
|
||||
register_reboot_notifier(&rockchip_bl_cpufreq_reboot_notifier);
|
||||
register_pm_notifier(&rockchip_bl_cpufreq_pm_notifier);
|
||||
|
||||
return cpufreq_register_driver(&cpufreq_driver);
|
||||
return cpufreq_register_driver(&rockchip_bl_cpufreq_driver);
|
||||
}
|
||||
|
||||
static int cpufreq_remove(struct platform_device *pdev)
|
||||
static int rockchip_bl_cpufreq_remove(struct platform_device *pdev)
|
||||
{
|
||||
cpufreq_unregister_driver(&cpufreq_driver);
|
||||
cpufreq_unregister_driver(&rockchip_bl_cpufreq_driver);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver cpufreq_platdrv = {
|
||||
static struct platform_driver rockchip_bl_cpufreq_platdrv = {
|
||||
.driver = {
|
||||
.name = "rockchip-bl-cpufreq",
|
||||
.owner = THIS_MODULE,
|
||||
.of_match_table = cpufreq_match,
|
||||
.of_match_table = rockchip_bl_cpufreq_match,
|
||||
},
|
||||
.probe = cpufreq_probe,
|
||||
.remove = cpufreq_remove,
|
||||
.probe = rockchip_bl_cpufreq_probe,
|
||||
.remove = rockchip_bl_cpufreq_remove,
|
||||
};
|
||||
module_platform_driver(cpufreq_platdrv);
|
||||
|
||||
module_platform_driver(rockchip_bl_cpufreq_platdrv);
|
||||
|
||||
MODULE_AUTHOR("Xiao Feng <xf@rock-chips.com>");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
Reference in New Issue
Block a user