Blame view
drivers/cpufreq/sh-cpufreq.c
4.48 KB
1da177e4c Linux-2.6.12-rc2 |
1 |
/* |
1da177e4c Linux-2.6.12-rc2 |
2 3 |
* cpufreq driver for the SuperH processors. * |
3bccf4677 sh: cpufreq: perc... |
4 |
* Copyright (C) 2002 - 2012 Paul Mundt |
1da177e4c Linux-2.6.12-rc2 |
5 6 |
* Copyright (C) 2002 M. R. Brown * |
cb5ec75b8 sh: cpufreq: cloc... |
7 8 9 10 11 12 13 |
* Clock framework bits from arch/avr32/mach-at32ap/cpufreq.c * * Copyright (C) 2004-2007 Atmel Corporation * * 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. |
1da177e4c Linux-2.6.12-rc2 |
14 |
*/ |
ecbef17ad sh: cpufreq: stru... |
15 |
#define pr_fmt(fmt) "cpufreq: " fmt |
1da177e4c Linux-2.6.12-rc2 |
16 17 18 19 |
#include <linux/types.h> #include <linux/cpufreq.h> #include <linux/kernel.h> #include <linux/module.h> |
1da177e4c Linux-2.6.12-rc2 |
20 |
#include <linux/init.h> |
cb5ec75b8 sh: cpufreq: cloc... |
21 |
#include <linux/err.h> |
1da177e4c Linux-2.6.12-rc2 |
22 |
#include <linux/cpumask.h> |
ecbef17ad sh: cpufreq: stru... |
23 |
#include <linux/cpu.h> |
1da177e4c Linux-2.6.12-rc2 |
24 |
#include <linux/smp.h> |
4e57b6817 [PATCH] fix missi... |
25 |
#include <linux/sched.h> /* set_cpus_allowed() */ |
cb5ec75b8 sh: cpufreq: cloc... |
26 |
#include <linux/clk.h> |
3bccf4677 sh: cpufreq: perc... |
27 28 |
#include <linux/percpu.h> #include <linux/sh_clk.h> |
1da177e4c Linux-2.6.12-rc2 |
29 |
|
3bccf4677 sh: cpufreq: perc... |
30 |
static DEFINE_PER_CPU(struct clk, sh_cpuclk); |
1da177e4c Linux-2.6.12-rc2 |
31 |
|
cb5ec75b8 sh: cpufreq: cloc... |
32 |
static unsigned int sh_cpufreq_get(unsigned int cpu) |
1da177e4c Linux-2.6.12-rc2 |
33 |
{ |
3bccf4677 sh: cpufreq: perc... |
34 |
return (clk_get_rate(&per_cpu(sh_cpuclk, cpu)) + 500) / 1000; |
1da177e4c Linux-2.6.12-rc2 |
35 |
} |
1da177e4c Linux-2.6.12-rc2 |
36 37 38 |
/* * Here we notify other drivers of the proposed change and the final change. */ |
cb5ec75b8 sh: cpufreq: cloc... |
39 40 41 |
static int sh_cpufreq_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation) |
1da177e4c Linux-2.6.12-rc2 |
42 |
{ |
cb5ec75b8 sh: cpufreq: cloc... |
43 |
unsigned int cpu = policy->cpu; |
3bccf4677 sh: cpufreq: perc... |
44 |
struct clk *cpuclk = &per_cpu(sh_cpuclk, cpu); |
1da177e4c Linux-2.6.12-rc2 |
45 46 |
cpumask_t cpus_allowed; struct cpufreq_freqs freqs; |
ecbef17ad sh: cpufreq: stru... |
47 |
struct device *dev; |
cb5ec75b8 sh: cpufreq: cloc... |
48 |
long freq; |
1da177e4c Linux-2.6.12-rc2 |
49 |
|
1da177e4c Linux-2.6.12-rc2 |
50 |
cpus_allowed = current->cpus_allowed; |
59a2f7d9f arch/sh/kernel: U... |
51 |
set_cpus_allowed_ptr(current, cpumask_of(cpu)); |
1da177e4c Linux-2.6.12-rc2 |
52 53 |
BUG_ON(smp_processor_id() != cpu); |
ecbef17ad sh: cpufreq: stru... |
54 |
dev = get_cpu_device(cpu); |
cb5ec75b8 sh: cpufreq: cloc... |
55 56 |
/* Convert target_freq from kHz to Hz */ freq = clk_round_rate(cpuclk, target_freq * 1000); |
1da177e4c Linux-2.6.12-rc2 |
57 |
|
cb5ec75b8 sh: cpufreq: cloc... |
58 59 |
if (freq < (policy->min * 1000) || freq > (policy->max * 1000)) return -EINVAL; |
ecbef17ad sh: cpufreq: stru... |
60 61 |
dev_dbg(dev, "requested frequency %u Hz ", target_freq * 1000); |
1da177e4c Linux-2.6.12-rc2 |
62 |
|
cb5ec75b8 sh: cpufreq: cloc... |
63 64 65 |
freqs.old = sh_cpufreq_get(cpu); freqs.new = (freq + 500) / 1000; freqs.flags = 0; |
8fec051ee cpufreq: Convert ... |
66 |
cpufreq_freq_transition_begin(policy, &freqs); |
59a2f7d9f arch/sh/kernel: U... |
67 |
set_cpus_allowed_ptr(current, &cpus_allowed); |
cb5ec75b8 sh: cpufreq: cloc... |
68 |
clk_set_rate(cpuclk, freq); |
8fec051ee cpufreq: Convert ... |
69 |
cpufreq_freq_transition_end(policy, &freqs, 0); |
1da177e4c Linux-2.6.12-rc2 |
70 |
|
ecbef17ad sh: cpufreq: stru... |
71 72 |
dev_dbg(dev, "set frequency %lu Hz ", freq); |
cb5ec75b8 sh: cpufreq: cloc... |
73 |
|
1da177e4c Linux-2.6.12-rc2 |
74 75 |
return 0; } |
1bcfc723c sh: cpufreq: Supp... |
76 77 78 79 80 81 82 83 |
static int sh_cpufreq_verify(struct cpufreq_policy *policy) { struct clk *cpuclk = &per_cpu(sh_cpuclk, policy->cpu); struct cpufreq_frequency_table *freq_table; freq_table = cpuclk->nr_freqs ? cpuclk->freq_table : NULL; if (freq_table) return cpufreq_frequency_table_verify(policy, freq_table); |
be49e3465 cpufreq: add new ... |
84 |
cpufreq_verify_within_cpu_limits(policy); |
1bcfc723c sh: cpufreq: Supp... |
85 86 87 |
policy->min = (clk_round_rate(cpuclk, 1) + 500) / 1000; policy->max = (clk_round_rate(cpuclk, ~0UL) + 500) / 1000; |
be49e3465 cpufreq: add new ... |
88 |
cpufreq_verify_within_cpu_limits(policy); |
1bcfc723c sh: cpufreq: Supp... |
89 90 |
return 0; } |
1da177e4c Linux-2.6.12-rc2 |
91 92 |
static int sh_cpufreq_cpu_init(struct cpufreq_policy *policy) { |
3bccf4677 sh: cpufreq: perc... |
93 94 |
unsigned int cpu = policy->cpu; struct clk *cpuclk = &per_cpu(sh_cpuclk, cpu); |
1bcfc723c sh: cpufreq: Supp... |
95 |
struct cpufreq_frequency_table *freq_table; |
ecbef17ad sh: cpufreq: stru... |
96 |
struct device *dev; |
3bccf4677 sh: cpufreq: perc... |
97 |
|
ecbef17ad sh: cpufreq: stru... |
98 99 100 |
dev = get_cpu_device(cpu); cpuclk = clk_get(dev, "cpu_clk"); |
cb5ec75b8 sh: cpufreq: cloc... |
101 |
if (IS_ERR(cpuclk)) { |
ecbef17ad sh: cpufreq: stru... |
102 103 |
dev_err(dev, "couldn't get CPU clk "); |
cb5ec75b8 sh: cpufreq: cloc... |
104 105 |
return PTR_ERR(cpuclk); } |
1da177e4c Linux-2.6.12-rc2 |
106 |
|
1bcfc723c sh: cpufreq: Supp... |
107 108 |
freq_table = cpuclk->nr_freqs ? cpuclk->freq_table : NULL; if (freq_table) { |
1a565cf07 sh: cpufreq: noti... |
109 |
int result; |
1bcfc723c sh: cpufreq: Supp... |
110 |
|
c25d01b3e cpufreq: sh: use ... |
111 112 113 |
result = cpufreq_table_validate_and_show(policy, freq_table); if (result) return result; |
1bcfc723c sh: cpufreq: Supp... |
114 |
} else { |
1a565cf07 sh: cpufreq: noti... |
115 116 117 |
dev_notice(dev, "no frequency table found, falling back " "to rate rounding. "); |
eb2f50ff9 cpufreq: drivers:... |
118 |
policy->min = policy->cpuinfo.min_freq = |
1a565cf07 sh: cpufreq: noti... |
119 |
(clk_round_rate(cpuclk, 1) + 500) / 1000; |
eb2f50ff9 cpufreq: drivers:... |
120 |
policy->max = policy->cpuinfo.max_freq = |
1a565cf07 sh: cpufreq: noti... |
121 |
(clk_round_rate(cpuclk, ~0UL) + 500) / 1000; |
cb5ec75b8 sh: cpufreq: cloc... |
122 |
} |
1da177e4c Linux-2.6.12-rc2 |
123 |
|
1bcfc723c sh: cpufreq: Supp... |
124 |
policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; |
ecbef17ad sh: cpufreq: stru... |
125 |
dev_info(dev, "CPU Frequencies - Minimum %u.%03u MHz, " |
cb5ec75b8 sh: cpufreq: cloc... |
126 127 |
"Maximum %u.%03u MHz. ", |
ecbef17ad sh: cpufreq: stru... |
128 |
policy->min / 1000, policy->min % 1000, |
cb5ec75b8 sh: cpufreq: cloc... |
129 |
policy->max / 1000, policy->max % 1000); |
1da177e4c Linux-2.6.12-rc2 |
130 |
|
cb5ec75b8 sh: cpufreq: cloc... |
131 132 |
return 0; } |
1da177e4c Linux-2.6.12-rc2 |
133 |
|
1bcfc723c sh: cpufreq: Supp... |
134 |
static int sh_cpufreq_cpu_exit(struct cpufreq_policy *policy) |
cb5ec75b8 sh: cpufreq: cloc... |
135 |
{ |
1bcfc723c sh: cpufreq: Supp... |
136 137 |
unsigned int cpu = policy->cpu; struct clk *cpuclk = &per_cpu(sh_cpuclk, cpu); |
cb5ec75b8 sh: cpufreq: cloc... |
138 |
|
cb5ec75b8 sh: cpufreq: cloc... |
139 |
clk_put(cpuclk); |
1bcfc723c sh: cpufreq: Supp... |
140 |
|
1da177e4c Linux-2.6.12-rc2 |
141 142 143 144 |
return 0; } static struct cpufreq_driver sh_cpufreq_driver = { |
cb5ec75b8 sh: cpufreq: cloc... |
145 |
.name = "sh", |
cb5ec75b8 sh: cpufreq: cloc... |
146 |
.get = sh_cpufreq_get, |
1bcfc723c sh: cpufreq: Supp... |
147 148 149 150 |
.target = sh_cpufreq_target, .verify = sh_cpufreq_verify, .init = sh_cpufreq_cpu_init, .exit = sh_cpufreq_cpu_exit, |
a8f64decf cpufreq: sh: Use ... |
151 |
.attr = cpufreq_generic_attr, |
1da177e4c Linux-2.6.12-rc2 |
152 |
}; |
cb5ec75b8 sh: cpufreq: cloc... |
153 |
static int __init sh_cpufreq_module_init(void) |
1da177e4c Linux-2.6.12-rc2 |
154 |
{ |
ecbef17ad sh: cpufreq: stru... |
155 156 |
pr_notice("SuperH CPU frequency driver. "); |
cb5ec75b8 sh: cpufreq: cloc... |
157 |
return cpufreq_register_driver(&sh_cpufreq_driver); |
1da177e4c Linux-2.6.12-rc2 |
158 |
} |
cb5ec75b8 sh: cpufreq: cloc... |
159 |
static void __exit sh_cpufreq_module_exit(void) |
1da177e4c Linux-2.6.12-rc2 |
160 161 162 |
{ cpufreq_unregister_driver(&sh_cpufreq_driver); } |
cb5ec75b8 sh: cpufreq: cloc... |
163 164 |
module_init(sh_cpufreq_module_init); module_exit(sh_cpufreq_module_exit); |
1da177e4c Linux-2.6.12-rc2 |
165 166 167 168 |
MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>"); MODULE_DESCRIPTION("cpufreq driver for SuperH"); MODULE_LICENSE("GPL"); |