blob: 70933eadc308db500fb25e0c12e7d5ca3c17fe21 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001 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 F r e q C o r e
7
8
9 Dominik Brodowski <linux@brodo.de>
10 David Kimdon <dwhedon@debian.org>
11
12
13
14 Clock scaling allows you to change the clock speed of the CPUs on the
15 fly. This is a nice method to save battery power, because the lower
16 the clock speed, the less power the CPU consumes.
17
18
19Contents:
20---------
211. CPUFreq core and interfaces
222. CPUFreq notifiers
Nishanth Menona0dd7b72014-05-05 08:33:50 -0500233. CPUFreq Table Generation with Operating Performance Point (OPP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
251. General Information
26=======================
27
Dominik Brodowskieff0df62006-10-02 19:26:47 -040028The CPUFreq core code is located in drivers/cpufreq/cpufreq.c. This
Linus Torvalds1da177e2005-04-16 15:20:36 -070029cpufreq code offers a standardized interface for the CPUFreq
30architecture drivers (those pieces of code that do actual
31frequency transitions), as well as to "notifiers". These are device
32drivers or other part of the kernel that need to be informed of
33policy changes (ex. thermal modules like ACPI) or of all
34frequency changes (ex. timing code) or even need to force certain
35speed limits (like LCD drivers on ARM architecture). Additionally, the
36kernel "constant" loops_per_jiffy is updated on frequency changes
37here.
38
39Reference counting is done by cpufreq_get_cpu and cpufreq_put_cpu,
40which make sure that the cpufreq processor driver is correctly
41registered with the core, and will not be unloaded until
42cpufreq_put_cpu is called.
43
442. CPUFreq notifiers
45====================
46
47CPUFreq notifiers conform to the standard kernel notifier interface.
48See linux/include/linux/notifier.h for details on notifiers.
49
50There are two different CPUFreq notifiers - policy notifiers and
51transition notifiers.
52
53
542.1 CPUFreq policy notifiers
55----------------------------
56
57These are notified when a new policy is intended to be set. Each
58CPUFreq policy notifier is called three times for a policy transition:
59
601.) During CPUFREQ_ADJUST all CPUFreq notifiers may change the limit if
61 they see a need for this - may it be thermal considerations or
62 hardware limitations.
63
642.) During CPUFREQ_INCOMPATIBLE only changes may be done in order to avoid
65 hardware failure.
66
673.) And during CPUFREQ_NOTIFY all notifiers are informed of the new policy
68 - if two hardware drivers failed to agree on a new policy before this
69 stage, the incompatible hardware shall be shut down, and the user
70 informed of this.
71
72The phase is specified in the second argument to the notifier.
73
74The third argument, a void *pointer, points to a struct cpufreq_policy
75consisting of five values: cpu, min, max, policy and max_cpu_freq. min
76and max are the lower and upper frequencies (in kHz) of the new
77policy, policy the new policy, cpu the number of the affected CPU; and
78max_cpu_freq the maximum supported CPU frequency. This value is given
79for informational purposes only.
80
81
822.2 CPUFreq transition notifiers
83--------------------------------
84
85These are notified twice when the CPUfreq driver switches the CPU core
86frequency and this change has any external implications.
87
88The second argument specifies the phase - CPUFREQ_PRECHANGE or
89CPUFREQ_POSTCHANGE.
90
91The third argument is a struct cpufreq_freqs with the following
92values:
93cpu - number of the affected CPU
94old - old frequency
95new - new frequency
Nishanth Menona0dd7b72014-05-05 08:33:50 -050096
973. CPUFreq Table Generation with Operating Performance Point (OPP)
98==================================================================
99For details about OPP, see Documentation/power/opp.txt
100
101dev_pm_opp_init_cpufreq_table - cpufreq framework typically is initialized with
102 cpufreq_frequency_table_cpuinfo which is provided with the list of
103 frequencies that are available for operation. This function provides
104 a ready to use conversion routine to translate the OPP layer's internal
105 information about the available frequencies into a format readily
106 providable to cpufreq.
107
108 WARNING: Do not use this function in interrupt context.
109
110 Example:
111 soc_pm_init()
112 {
113 /* Do things */
114 r = dev_pm_opp_init_cpufreq_table(dev, &freq_table);
115 if (!r)
116 cpufreq_frequency_table_cpuinfo(policy, freq_table);
117 /* Do other things */
118 }
119
120 NOTE: This function is available only if CONFIG_CPU_FREQ is enabled in
121 addition to CONFIG_PM_OPP.
122
123dev_pm_opp_free_cpufreq_table - Free up the table allocated by dev_pm_opp_init_cpufreq_table