114 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3=============================================================4General description of the CPUFreq core and CPUFreq notifiers5=============================================================6 7Authors: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>12 13.. Contents:14 15 1. CPUFreq core and interfaces16 2. CPUFreq notifiers17 3. CPUFreq Table Generation with Operating Performance Point (OPP)18 191. General Information20======================21 22The CPUFreq core code is located in drivers/cpufreq/cpufreq.c. This23cpufreq code offers a standardized interface for the CPUFreq24architecture drivers (those pieces of code that do actual25frequency transitions), as well as to "notifiers". These are device26drivers or other part of the kernel that need to be informed of27policy changes (ex. thermal modules like ACPI) or of all28frequency changes (ex. timing code) or even need to force certain29speed limits (like LCD drivers on ARM architecture). Additionally, the30kernel "constant" loops_per_jiffy is updated on frequency changes31here.32 33Reference counting of the cpufreq policies is done by cpufreq_cpu_get34and cpufreq_cpu_put, which make sure that the cpufreq driver is35correctly registered with the core, and will not be unloaded until36cpufreq_put_cpu is called. That also ensures that the respective cpufreq37policy doesn't get freed while being used.38 392. CPUFreq notifiers40====================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 and46transition notifiers.47 48 492.1 CPUFreq policy notifiers50----------------------------51 52These are notified when a new policy is created or removed.53 54The phase is specified in the second argument to the notifier. The phase is55CPUFREQ_CREATE_POLICY when the policy is first created and it is56CPUFREQ_REMOVE_POLICY when the policy is removed.57 58The third argument, a ``void *pointer``, points to a struct cpufreq_policy59consisting of several values, including min, max (the lower and upper60frequencies (in kHz) of the new policy).61 62 632.2 CPUFreq transition notifiers64--------------------------------65 66These are notified twice for each online CPU in the policy, when the67CPUfreq driver switches the CPU core frequency and this change has no68any external implications.69 70The second argument specifies the phase - CPUFREQ_PRECHANGE or71CPUFREQ_POSTCHANGE.72 73The third argument is a struct cpufreq_freqs with the following74values:75 76====== ======================================77policy a pointer to the struct cpufreq_policy78old old frequency79new new frequency80flags flags of the cpufreq driver81====== ======================================82 833. CPUFreq Table Generation with Operating Performance Point (OPP)84==================================================================85For details about OPP, see Documentation/power/opp.rst86 87dev_pm_opp_init_cpufreq_table -88 This function provides a ready to use conversion routine to translate89 the OPP layer's internal information about the available frequencies90 into a format readily providable to cpufreq.91 92 .. Warning::93 94 Do not use this function in interrupt context.95 96 Example::97 98 soc_pm_init()99 {100 /* Do things */101 r = dev_pm_opp_init_cpufreq_table(dev, &freq_table);102 if (!r)103 policy->freq_table = freq_table;104 /* Do other things */105 }106 107 .. note::108 109 This function is available only if CONFIG_CPU_FREQ is enabled in110 addition to CONFIG_PM_OPP.111 112dev_pm_opp_free_cpufreq_table113 Free up the table allocated by dev_pm_opp_init_cpufreq_table114