]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - Documentation/cpu-freq/cpu-drivers.txt
Merge branches 'pm-cpufreq' and 'pm-devfreq'
[mirror_ubuntu-zesty-kernel.git] / Documentation / cpu-freq / cpu-drivers.txt
CommitLineData
1da177e4
LT
1 CPU frequency and voltage scaling code in the Linux(TM) kernel
2
3
4 L i n u x C P U F r e q
5
6 C P U D r i v e r s
7
8 - information for developers -
9
10
11 Dominik Brodowski <linux@brodo.de>
12
13
14
15 Clock scaling allows you to change the clock speed of the CPUs on the
16 fly. This is a nice method to save battery power, because the lower
17 the clock speed, the less power the CPU consumes.
18
19
20Contents:
21---------
221. What To Do?
231.1 Initialization
241.2 Per-CPU Initialization
251.3 verify
9c0ebcf7
VK
261.4 target/target_index or setpolicy?
271.5 target/target_index
1da177e4
LT
281.6 setpolicy
292. Frequency Table Helpers
30
31
32
331. What To Do?
34==============
35
36So, you just got a brand-new CPU / chipset with datasheets and want to
37add cpufreq support for this CPU / chipset? Great. Here are some hints
38on what is necessary:
39
40
411.1 Initialization
42------------------
43
44First of all, in an __initcall level 7 (module_init()) or later
45function check whether this kernel runs on the right CPU and the right
46chipset. If so, register a struct cpufreq_driver with the CPUfreq core
47using cpufreq_register_driver()
48
49What shall this struct cpufreq_driver contain?
50
51cpufreq_driver.name - The name of this driver.
52
1da177e4
LT
53cpufreq_driver.init - A pointer to the per-CPU initialization
54 function.
55
56cpufreq_driver.verify - A pointer to a "verification" function.
57
58cpufreq_driver.setpolicy _or_
9c0ebcf7
VK
59cpufreq_driver.target/
60target_index - See below on the differences.
1da177e4
LT
61
62And optionally
63
64cpufreq_driver.exit - A pointer to a per-CPU cleanup function.
65
66cpufreq_driver.resume - A pointer to a per-CPU resume function
67 which is called with interrupts disabled
68 and _before_ the pre-suspend frequency
69 and/or policy is restored by a call to
9c0ebcf7 70 ->target/target_index or ->setpolicy.
1da177e4
LT
71
72cpufreq_driver.attr - A pointer to a NULL-terminated list of
73 "struct freq_attr" which allow to
74 export values to sysfs.
75
76
771.2 Per-CPU Initialization
78--------------------------
79
80Whenever a new CPU is registered with the device model, or after the
81cpufreq driver registers itself, the per-CPU initialization function
82cpufreq_driver.init is called. It takes a struct cpufreq_policy
83*policy as argument. What to do now?
84
85If necessary, activate the CPUfreq support on your CPU.
86
87Then, the driver must fill in the following values:
88
89policy->cpuinfo.min_freq _and_
90policy->cpuinfo.max_freq - the minimum and maximum frequency
91 (in kHz) which is supported by
92 this CPU
93policy->cpuinfo.transition_latency the time it takes on this CPU to
bbe237aa
MB
94 switch between two frequencies in
95 nanoseconds (if appropriate, else
96 specify CPUFREQ_ETERNAL)
1da177e4
LT
97
98policy->cur The current operating frequency of
99 this CPU (if appropriate)
100policy->min,
101policy->max,
102policy->policy and, if necessary,
103policy->governor must contain the "default policy" for
104 this CPU. A few moments later,
105 cpufreq_driver.verify and either
106 cpufreq_driver.setpolicy or
9c0ebcf7
VK
107 cpufreq_driver.target/target_index is called
108 with these values.
1da177e4 109
eb2f50ff
VK
110For setting some of these values (cpuinfo.min[max]_freq, policy->min[max]), the
111frequency table helpers might be helpful. See the section 2 for more information
112on them.
1da177e4 113
951fc5f4
VK
114SMP systems normally have same clock source for a group of cpus. For these the
115.init() would be called only once for the first online cpu. Here the .init()
116routine must initialize policy->cpus with mask of all possible cpus (Online +
117Offline) that share the clock. Then the core would copy this mask onto
118policy->related_cpus and will reset policy->cpus to carry only online cpus.
119
1da177e4
LT
120
1211.3 verify
122------------
123
124When the user decides a new policy (consisting of
125"policy,governor,min,max") shall be set, this policy must be validated
126so that incompatible values can be corrected. For verifying these
127values, a frequency table helper and/or the
128cpufreq_verify_within_limits(struct cpufreq_policy *policy, unsigned
129int min_freq, unsigned int max_freq) function might be helpful. See
130section 2 for details on frequency table helpers.
131
132You need to make sure that at least one valid frequency (or operating
133range) is within policy->min and policy->max. If necessary, increase
134policy->max first, and only if this is no solution, decrease policy->min.
135
136
9c0ebcf7 1371.4 target/target_index or setpolicy?
1da177e4
LT
138----------------------------
139
140Most cpufreq drivers or even most cpu frequency scaling algorithms
141only allow the CPU to be set to one frequency. For these, you use the
9c0ebcf7 142->target/target_index call.
1da177e4
LT
143
144Some cpufreq-capable processors switch the frequency between certain
145limits on their own. These shall use the ->setpolicy call
146
147
9c0ebcf7 1481.4. target/target_index
1da177e4
LT
149-------------
150
9c0ebcf7
VK
151The target_index call has two arguments: struct cpufreq_policy *policy,
152and unsigned int index (into the exposed frequency table).
153
154The CPUfreq driver must set the new frequency when called here. The
155actual frequency must be determined by freq_table[index].frequency.
156
157Deprecated:
158----------
1da177e4
LT
159The target call has three arguments: struct cpufreq_policy *policy,
160unsigned int target_frequency, unsigned int relation.
161
162The CPUfreq driver must set the new frequency when called here. The
163actual frequency must be determined using the following rules:
164
165- keep close to "target_freq"
166- policy->min <= new_freq <= policy->max (THIS MUST BE VALID!!!)
167- if relation==CPUFREQ_REL_L, try to select a new_freq higher than or equal
168 target_freq. ("L for lowest, but no lower than")
169- if relation==CPUFREQ_REL_H, try to select a new_freq lower than or equal
170 target_freq. ("H for highest, but no higher than")
171
51555c0e 172Here again the frequency table helper might assist you - see section 2
1da177e4
LT
173for details.
174
175
1761.5 setpolicy
177---------------
178
179The setpolicy call only takes a struct cpufreq_policy *policy as
180argument. You need to set the lower limit of the in-processor or
181in-chipset dynamic frequency switching to policy->min, the upper limit
182to policy->max, and -if supported- select a performance-oriented
183setting when policy->policy is CPUFREQ_POLICY_PERFORMANCE, and a
184powersaving-oriented setting when CPUFREQ_POLICY_POWERSAVE. Also check
25eb650a 185the reference implementation in drivers/cpufreq/longrun.c
1da177e4
LT
186
187
188
1892. Frequency Table Helpers
190==========================
191
192As most cpufreq processors only allow for being set to a few specific
193frequencies, a "frequency table" with some functions might assist in
194some work of the processor driver. Such a "frequency table" consists
3a7818e6 195of an array of struct cpufreq_frequency_table entries, with any value in
50701588 196"driver_data" you want to use, and the corresponding frequency in
1da177e4 197"frequency". At the end of the table, you need to add a
3a7818e6 198cpufreq_frequency_table entry with frequency set to CPUFREQ_TABLE_END. And
1da177e4
LT
199if you want to skip one entry in the table, set the frequency to
200CPUFREQ_ENTRY_INVALID. The entries don't need to be in ascending
201order.
202
203By calling cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
204 struct cpufreq_frequency_table *table);
205the cpuinfo.min_freq and cpuinfo.max_freq values are detected, and
206policy->min and policy->max are set to the same values. This is
207helpful for the per-CPU initialization stage.
208
209int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
210 struct cpufreq_frequency_table *table);
211assures that at least one valid frequency is within policy->min and
212policy->max, and all other criteria are met. This is helpful for the
213->verify call.
214
215int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
216 struct cpufreq_frequency_table *table,
217 unsigned int target_freq,
218 unsigned int relation,
219 unsigned int *index);
220
221is the corresponding frequency table helper for the ->target
222stage. Just pass the values to this function, and the unsigned int
223index returns the number of the frequency table entry which contains
50701588 224the frequency the CPU shall be set to.