blob: 4ceef8e7217c38fc3e07606ce24b05fbed57d71d [file] [log] [blame]
Mauro Carvalho Chehabc460f972020-03-03 14:52:04 +01001.. SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002
Mauro Carvalho Chehabc460f972020-03-03 14:52:04 +01003=============================================================
4General description of the CPUFreq core and CPUFreq notifiers
5=============================================================
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
Mauro Carvalho Chehabc460f972020-03-03 14:52:04 +01007Authors:
8 - Dominik Brodowski <linux@brodo.de>
9 - David Kimdon <dwhedon@debian.org>
10 - Rafael J. Wysocki <rafael.j.wysocki@intel.com>
11 - Viresh Kumar <viresh.kumar@linaro.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Mauro Carvalho Chehabc460f972020-03-03 14:52:04 +010013.. Contents:
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Mauro Carvalho Chehabc460f972020-03-03 14:52:04 +010015 1. CPUFreq core and interfaces
16 2. CPUFreq notifiers
17 3. CPUFreq Table Generation with Operating Performance Point (OPP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
191. General Information
Mauro Carvalho Chehabc460f972020-03-03 14:52:04 +010020======================
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Dominik Brodowskieff0df62006-10-02 19:26:47 -040022The CPUFreq core code is located in drivers/cpufreq/cpufreq.c. This
Linus Torvalds1da177e2005-04-16 15:20:36 -070023cpufreq code offers a standardized interface for the CPUFreq
24architecture drivers (those pieces of code that do actual
25frequency transitions), as well as to "notifiers". These are device
26drivers or other part of the kernel that need to be informed of
27policy changes (ex. thermal modules like ACPI) or of all
28frequency changes (ex. timing code) or even need to force certain
29speed limits (like LCD drivers on ARM architecture). Additionally, the
30kernel "constant" loops_per_jiffy is updated on frequency changes
31here.
32
Viresh Kumar7de962c2017-01-06 11:08:05 +053033Reference counting of the cpufreq policies is done by cpufreq_cpu_get
34and cpufreq_cpu_put, which make sure that the cpufreq driver is
35correctly registered with the core, and will not be unloaded until
36cpufreq_put_cpu is called. That also ensures that the respective cpufreq
37policy doesn't get freed while being used.
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
392. CPUFreq notifiers
40====================
41
42CPUFreq notifiers conform to the standard kernel notifier interface.
43See linux/include/linux/notifier.h for details on notifiers.
44
45There are two different CPUFreq notifiers - policy notifiers and
46transition notifiers.
47
48
492.1 CPUFreq policy notifiers
50----------------------------
51
Viresh Kumarc27c38a2019-07-23 11:44:10 +053052These are notified when a new policy is created or removed.
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Viresh Kumarc27c38a2019-07-23 11:44:10 +053054The phase is specified in the second argument to the notifier. The phase is
55CPUFREQ_CREATE_POLICY when the policy is first created and it is
56CPUFREQ_REMOVE_POLICY when the policy is removed.
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Mauro Carvalho Chehabc460f972020-03-03 14:52:04 +010058The third argument, a ``void *pointer``, points to a struct cpufreq_policy
Viresh Kumar7de962c2017-01-06 11:08:05 +053059consisting of several values, including min, max (the lower and upper
60frequencies (in kHz) of the new policy).
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62
632.2 CPUFreq transition notifiers
64--------------------------------
65
Viresh Kumar7de962c2017-01-06 11:08:05 +053066These are notified twice for each online CPU in the policy, when the
67CPUfreq driver switches the CPU core frequency and this change has no
68any external implications.
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70The second argument specifies the phase - CPUFREQ_PRECHANGE or
71CPUFREQ_POSTCHANGE.
72
73The third argument is a struct cpufreq_freqs with the following
74values:
Mauro Carvalho Chehabc460f972020-03-03 14:52:04 +010075
Tang Yizhoua15b8cd2021-12-01 15:40:21 +080076====== ======================================
77policy a pointer to the struct cpufreq_policy
Mauro Carvalho Chehabc460f972020-03-03 14:52:04 +010078old old frequency
79new new frequency
80flags flags of the cpufreq driver
Tang Yizhoua15b8cd2021-12-01 15:40:21 +080081====== ======================================
Nishanth Menona0dd7b72014-05-05 08:33:50 -050082
833. CPUFreq Table Generation with Operating Performance Point (OPP)
84==================================================================
Mauro Carvalho Chehab151f4e22019-06-13 07:10:36 -030085For details about OPP, see Documentation/power/opp.rst
Nishanth Menona0dd7b72014-05-05 08:33:50 -050086
Viresh Kumar2dd0df82018-04-03 15:37:39 +053087dev_pm_opp_init_cpufreq_table -
88 This function provides a ready to use conversion routine to translate
89 the OPP layer's internal information about the available frequencies
90 into a format readily providable to cpufreq.
Nishanth Menona0dd7b72014-05-05 08:33:50 -050091
Mauro Carvalho Chehabc460f972020-03-03 14:52:04 +010092 .. Warning::
Nishanth Menona0dd7b72014-05-05 08:33:50 -050093
Mauro Carvalho Chehabc460f972020-03-03 14:52:04 +010094 Do not use this function in interrupt context.
95
96 Example::
97
Nishanth Menona0dd7b72014-05-05 08:33:50 -050098 soc_pm_init()
99 {
100 /* Do things */
101 r = dev_pm_opp_init_cpufreq_table(dev, &freq_table);
102 if (!r)
Viresh Kumar2dd0df82018-04-03 15:37:39 +0530103 policy->freq_table = freq_table;
Nishanth Menona0dd7b72014-05-05 08:33:50 -0500104 /* Do other things */
105 }
106
Mauro Carvalho Chehabc460f972020-03-03 14:52:04 +0100107 .. note::
Nishanth Menona0dd7b72014-05-05 08:33:50 -0500108
Mauro Carvalho Chehabc460f972020-03-03 14:52:04 +0100109 This function is available only if CONFIG_CPU_FREQ is enabled in
110 addition to CONFIG_PM_OPP.
111
112dev_pm_opp_free_cpufreq_table
113 Free up the table allocated by dev_pm_opp_init_cpufreq_table