blob: 978463a7c81ea59ea24f2e967f9683321ef1188e [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>
Viresh Kumar7de962c2017-01-06 11:08:05 +053011 Rafael J. Wysocki <rafael.j.wysocki@intel.com>
12 Viresh Kumar <viresh.kumar@linaro.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14
15
16 Clock scaling allows you to change the clock speed of the CPUs on the
17 fly. This is a nice method to save battery power, because the lower
18 the clock speed, the less power the CPU consumes.
19
20
21Contents:
22---------
231. CPUFreq core and interfaces
242. CPUFreq notifiers
Nishanth Menona0dd7b72014-05-05 08:33:50 -0500253. CPUFreq Table Generation with Operating Performance Point (OPP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
271. General Information
28=======================
29
Dominik Brodowskieff0df62006-10-02 19:26:47 -040030The CPUFreq core code is located in drivers/cpufreq/cpufreq.c. This
Linus Torvalds1da177e2005-04-16 15:20:36 -070031cpufreq code offers a standardized interface for the CPUFreq
32architecture drivers (those pieces of code that do actual
33frequency transitions), as well as to "notifiers". These are device
34drivers or other part of the kernel that need to be informed of
35policy changes (ex. thermal modules like ACPI) or of all
36frequency changes (ex. timing code) or even need to force certain
37speed limits (like LCD drivers on ARM architecture). Additionally, the
38kernel "constant" loops_per_jiffy is updated on frequency changes
39here.
40
Viresh Kumar7de962c2017-01-06 11:08:05 +053041Reference counting of the cpufreq policies is done by cpufreq_cpu_get
42and cpufreq_cpu_put, which make sure that the cpufreq driver is
43correctly registered with the core, and will not be unloaded until
44cpufreq_put_cpu is called. That also ensures that the respective cpufreq
45policy doesn't get freed while being used.
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
472. CPUFreq notifiers
48====================
49
50CPUFreq notifiers conform to the standard kernel notifier interface.
51See linux/include/linux/notifier.h for details on notifiers.
52
53There are two different CPUFreq notifiers - policy notifiers and
54transition notifiers.
55
56
572.1 CPUFreq policy notifiers
58----------------------------
59
60These are notified when a new policy is intended to be set. Each
Viresh Kumar6bfb7c72015-08-03 08:36:14 +053061CPUFreq policy notifier is called twice for a policy transition:
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
631.) During CPUFREQ_ADJUST all CPUFreq notifiers may change the limit if
64 they see a need for this - may it be thermal considerations or
65 hardware limitations.
66
Viresh Kumar6bfb7c72015-08-03 08:36:14 +0530672.) And during CPUFREQ_NOTIFY all notifiers are informed of the new policy
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 - 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
Viresh Kumar7de962c2017-01-06 11:08:05 +053075consisting of several values, including min, max (the lower and upper
76frequencies (in kHz) of the new policy).
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78
792.2 CPUFreq transition notifiers
80--------------------------------
81
Viresh Kumar7de962c2017-01-06 11:08:05 +053082These are notified twice for each online CPU in the policy, when the
83CPUfreq driver switches the CPU core frequency and this change has no
84any external implications.
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86The second argument specifies the phase - CPUFREQ_PRECHANGE or
87CPUFREQ_POSTCHANGE.
88
89The third argument is a struct cpufreq_freqs with the following
90values:
91cpu - number of the affected CPU
92old - old frequency
93new - new frequency
Viresh Kumar7de962c2017-01-06 11:08:05 +053094flags - flags of the cpufreq driver
Nishanth Menona0dd7b72014-05-05 08:33:50 -050095
963. CPUFreq Table Generation with Operating Performance Point (OPP)
97==================================================================
98For details about OPP, see Documentation/power/opp.txt
99
100dev_pm_opp_init_cpufreq_table - cpufreq framework typically is initialized with
Viresh Kumar64bf55a2016-05-31 16:50:23 +0530101 cpufreq_table_validate_and_show() which is provided with the list of
Nishanth Menona0dd7b72014-05-05 08:33:50 -0500102 frequencies that are available for operation. This function provides
103 a ready to use conversion routine to translate the OPP layer's internal
104 information about the available frequencies into a format readily
105 providable to cpufreq.
106
107 WARNING: Do not use this function in interrupt context.
108
109 Example:
110 soc_pm_init()
111 {
112 /* Do things */
113 r = dev_pm_opp_init_cpufreq_table(dev, &freq_table);
114 if (!r)
Viresh Kumar64bf55a2016-05-31 16:50:23 +0530115 cpufreq_table_validate_and_show(policy, freq_table);
Nishanth Menona0dd7b72014-05-05 08:33:50 -0500116 /* Do other things */
117 }
118
119 NOTE: This function is available only if CONFIG_CPU_FREQ is enabled in
120 addition to CONFIG_PM_OPP.
121
122dev_pm_opp_free_cpufreq_table - Free up the table allocated by dev_pm_opp_init_cpufreq_table