sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget(/translations/zh_CN/cpu-freq/cpu-driversmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/zh_TW/cpu-freq/cpu-driversmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/it_IT/cpu-freq/cpu-driversmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/ja_JP/cpu-freq/cpu-driversmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/ko_KR/cpu-freq/cpu-driversmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/sp_SP/cpu-freq/cpu-driversmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhhB/var/lib/git/docbuild/linux/Documentation/cpu-freq/cpu-drivers.rsthKubhsection)}(hhh](htitle)}(h/How to Implement a new CPUFreq Processor Driverh]h/How to Implement a new CPUFreq Processor Driver}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hAuthors:h]hAuthors:}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh block_quote)}(h- Dominik Brodowski - Rafael J. Wysocki - Viresh Kumar h]h bullet_list)}(hhh](h list_item)}(h#Dominik Brodowski h]h)}(hhh](hDominik Brodowski <}(hhhhhNhNubh reference)}(hlinux@brodo.deh]hlinux@brodo.de}(hhhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:linux@brodo.deuh1hhhubh>}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hhubah}(h]h ]h"]h$]h&]uh1hhhubh)}(h.Rafael J. Wysocki h]h)}(hjh](hRafael J. Wysocki <}(hjhhhNhNubh)}(hrafael.j.wysocki@intel.comh]hrafael.j.wysocki@intel.com}(hjhhhNhNubah}(h]h ]h"]h$]h&]refuri!mailto:rafael.j.wysocki@intel.comuh1hhjubh>}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hjubah}(h]h ]h"]h$]h&]uh1hhhubh)}(h'Viresh Kumar h]h)}(h&Viresh Kumar h](hViresh Kumar <}(hjBhhhNhNubh)}(hviresh.kumar@linaro.orgh]hviresh.kumar@linaro.org}(hjJhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:viresh.kumar@linaro.orguh1hhjBubh>}(hjBhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hj>ubah}(h]h ]h"]h$]h&]uh1hhhubeh}(h]h ]h"]h$]h&]bullet-uh1hhhhK hhubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(hContents 1. What To Do? 1.1 Initialization 1.2 Per-CPU Initialization 1.3 verify 1.4 target/target_index or setpolicy? 1.5 target/target_index 1.6 setpolicy 1.7 get_intermediate and target_intermediate 2. Frequency Table Helpersh]hContents 1. What To Do? 1.1 Initialization 1.2 Per-CPU Initialization 1.3 verify 1.4 target/target_index or setpolicy? 1.5 target/target_index 1.6 setpolicy 1.7 get_intermediate and target_intermediate 2. Frequency Table Helpers}hjxsbah}(h]h ]h"]h$]h&]hhuh1hhhhhhhhKubh)}(hhh](h)}(h1. What To Do?h]h1. What To Do?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hSo, you just got a brand-new CPU / chipset with datasheets and want to add cpufreq support for this CPU / chipset? Great. Here are some hints on what is necessary:h]hSo, you just got a brand-new CPU / chipset with datasheets and want to add cpufreq support for this CPU / chipset? Great. Here are some hints on what is necessary:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hhh](h)}(h1.1 Initializationh]h1.1 Initialization}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK%ubh)}(hFirst of all, in an __initcall level 7 (module_init()) or later function check whether this kernel runs on the right CPU and the right chipset. If so, register a struct cpufreq_driver with the CPUfreq core using cpufreq_register_driver()h]hFirst of all, in an __initcall level 7 (module_init()) or later function check whether this kernel runs on the right CPU and the right chipset. If so, register a struct cpufreq_driver with the CPUfreq core using cpufreq_register_driver()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK'hjhhubh)}(h.What shall this struct cpufreq_driver contain?h]h.What shall this struct cpufreq_driver contain?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK,hjhhubh)}(h.name - The name of this driver. .init - A pointer to the per-policy initialization function. .verify - A pointer to a "verification" function. .setpolicy _or_ .fast_switch _or_ .target _or_ .target_index - See below on the differences. h](h)}(h .name - The name of this driver.h]h .name - The name of this driver.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK.hjubh)}(h<.init - A pointer to the per-policy initialization function.h]h<.init - A pointer to the per-policy initialization function.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK0hjubh)}(h1.verify - A pointer to a "verification" function.h]h5.verify - A pointer to a “verification” function.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK2hjubh)}(h\.setpolicy _or_ .fast_switch _or_ .target _or_ .target_index - See below on the differences.h]h\.setpolicy _or_ .fast_switch _or_ .target _or_ .target_index - See below on the differences.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK4hjubeh}(h]h ]h"]h$]h&]uh1hhhhK.hjhhubh)}(hAnd optionallyh]hAnd optionally}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK7hjhhubh)}(hX%.flags - Hints for the cpufreq core. .driver_data - cpufreq driver specific data. .get_intermediate and target_intermediate - Used to switch to stable frequency while changing CPU frequency. .get - Returns current frequency of the CPU. .bios_limit - Returns HW/BIOS max frequency limitations for the CPU. .exit - A pointer to a per-policy cleanup function called during CPU_POST_DEAD phase of cpu hotplug process. .suspend - A pointer to a per-policy suspend function which is called with interrupts disabled and _after_ the governor is stopped for the policy. .resume - A pointer to a per-policy resume function which is called with interrupts disabled and _before_ the governor is started again. .ready - A pointer to a per-policy ready function which is called after the policy is fully initialized. .attr - A pointer to a NULL-terminated list of "struct freq_attr" which allow to export values to sysfs. .boost_enabled - If set, boost frequencies are enabled. .set_boost - A pointer to a per-policy function to enable/disable boost frequencies. h](h)}(h$.flags - Hints for the cpufreq core.h]h$.flags - Hints for the cpufreq core.}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK9hj"ubh)}(h,.driver_data - cpufreq driver specific data.h]h,.driver_data - cpufreq driver specific data.}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK;hj"ubh)}(hl.get_intermediate and target_intermediate - Used to switch to stable frequency while changing CPU frequency.h]hl.get_intermediate and target_intermediate - Used to switch to stable frequency while changing CPU frequency.}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK=hj"ubh)}(h,.get - Returns current frequency of the CPU.h]h,.get - Returns current frequency of the CPU.}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK@hj"ubh)}(hD.bios_limit - Returns HW/BIOS max frequency limitations for the CPU.h]hD.bios_limit - Returns HW/BIOS max frequency limitations for the CPU.}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKBhj"ubh)}(hl.exit - A pointer to a per-policy cleanup function called during CPU_POST_DEAD phase of cpu hotplug process.h]hl.exit - A pointer to a per-policy cleanup function called during CPU_POST_DEAD phase of cpu hotplug process.}(hjlhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKDhj"ubh)}(h.suspend - A pointer to a per-policy suspend function which is called with interrupts disabled and _after_ the governor is stopped for the policy.h]h.suspend - A pointer to a per-policy suspend function which is called with interrupts disabled and _after_ the governor is stopped for the policy.}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKGhj"ubh)}(h.resume - A pointer to a per-policy resume function which is called with interrupts disabled and _before_ the governor is started again.h]h.resume - A pointer to a per-policy resume function which is called with interrupts disabled and _before_ the governor is started again.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKKhj"ubh)}(hh.ready - A pointer to a per-policy ready function which is called after the policy is fully initialized.h]hh.ready - A pointer to a per-policy ready function which is called after the policy is fully initialized.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKNhj"ubh)}(hh.attr - A pointer to a NULL-terminated list of "struct freq_attr" which allow to export values to sysfs.h]hl.attr - A pointer to a NULL-terminated list of “struct freq_attr” which allow to export values to sysfs.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKQhj"ubh)}(h7.boost_enabled - If set, boost frequencies are enabled.h]h7.boost_enabled - If set, boost frequencies are enabled.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKThj"ubh)}(hT.set_boost - A pointer to a per-policy function to enable/disable boost frequencies.h]hT.set_boost - A pointer to a per-policy function to enable/disable boost frequencies.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKVhj"ubeh}(h]h ]h"]h$]h&]uh1hhhhK9hjhhubeh}(h]initializationah ]h"]1.1 initializationah$]h&]uh1hhjhhhhhK%ubh)}(hhh](h)}(h1.2 Per-CPU Initializationh]h1.2 Per-CPU Initialization}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK[ubh)}(hXWhenever a new CPU is registered with the device model, or after the cpufreq driver registers itself, the per-policy initialization function cpufreq_driver.init is called if no cpufreq policy existed for the CPU. Note that the .init() and .exit() routines are called only once for the policy and not for each CPU managed by the policy. It takes a ``struct cpufreq_policy *policy`` as argument. What to do now?h](hX[Whenever a new CPU is registered with the device model, or after the cpufreq driver registers itself, the per-policy initialization function cpufreq_driver.init is called if no cpufreq policy existed for the CPU. Note that the .init() and .exit() routines are called only once for the policy and not for each CPU managed by the policy. It takes a }(hjhhhNhNubhliteral)}(h!``struct cpufreq_policy *policy``h]hstruct cpufreq_policy *policy}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh as argument. What to do now?}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK]hjhhubh)}(h7If necessary, activate the CPUfreq support on your CPU.h]h7If necessary, activate the CPUfreq support on your CPU.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKdhjhhubh)}(h3Then, the driver must fill in the following values:h]h3Then, the driver must fill in the following values:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKfhjhhubhtable)}(hhh]htgroup)}(hhh](hcolspec)}(hhh]h}(h]h ]h"]h$]h&]colwidthK#uh1j5hj2ubj6)}(hhh]h}(h]h ]h"]h$]h&]colwidthK&uh1j5hj2ubhtbody)}(hhh](hrow)}(hhh](hentry)}(hhh]h)}(h7policy->cpuinfo.min_freq _and_ policy->cpuinfo.max_freqh]h7policy->cpuinfo.min_freq _and_ policy->cpuinfo.max_freq}(hjZhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKihjWubah}(h]h ]h"]h$]h&]uh1jUhjRubjV)}(hhh]h)}(hIthe minimum and maximum frequency (in kHz) which is supported by this CPUh]hIthe minimum and maximum frequency (in kHz) which is supported by this CPU}(hjqhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKjhjnubah}(h]h ]h"]h$]h&]uh1jUhjRubeh}(h]h ]h"]h$]h&]uh1jPhjMubjQ)}(hhh](jV)}(hhh]h)}(h"policy->cpuinfo.transition_latencyh]h"policy->cpuinfo.transition_latency}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKnhjubah}(h]h ]h"]h$]h&]uh1jUhjubjV)}(hhh]h)}(h}the time it takes on this CPU to switch between two frequencies in nanoseconds (if appropriate, else specify CPUFREQ_ETERNAL)h]h}the time it takes on this CPU to switch between two frequencies in nanoseconds (if appropriate, else specify CPUFREQ_ETERNAL)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKnhjubah}(h]h ]h"]h$]h&]uh1jUhjubeh}(h]h ]h"]h$]h&]uh1jPhjMubjQ)}(hhh](jV)}(hhh]h)}(h policy->curh]h policy->cur}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKshjubah}(h]h ]h"]h$]h&]uh1jUhjubjV)}(hhh]h)}(hmin, policy->max, policy->policy and, if necessary, policy->governorh]hLpolicy->min, policy->max, policy->policy and, if necessary, policy->governor}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKvhjubah}(h]h ]h"]h$]h&]uh1jUhjubjV)}(hhh]h)}(hmust contain the "default policy" for this CPU. A few moments later, cpufreq_driver.verify and either cpufreq_driver.setpolicy or cpufreq_driver.target/target_index is called with these values.h]hmust contain the “default policy” for this CPU. A few moments later, cpufreq_driver.verify and either cpufreq_driver.setpolicy or cpufreq_driver.target/target_index is called with these values.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKyhjubah}(h]h ]h"]h$]h&]uh1jUhjubeh}(h]h ]h"]h$]h&]uh1jPhjMubjQ)}(hhh](jV)}(hhh]h)}(h policy->cpush]h policy->cpus}(hj6hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj3ubah}(h]h ]h"]h$]h&]uh1jUhj0ubjV)}(hhh]h)}(hUpdate this with the masks of the (online + offline) CPUs that do DVFS along with this CPU (i.e. that share clock/voltage rails with it).h]hUpdate this with the masks of the (online + offline) CPUs that do DVFS along with this CPU (i.e. that share clock/voltage rails with it).}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjJubah}(h]h ]h"]h$]h&]uh1jUhj0ubeh}(h]h ]h"]h$]h&]uh1jPhjMubeh}(h]h ]h"]h$]h&]uh1jKhj2ubeh}(h]h ]h"]h$]h&]colsKuh1j0hj-ubah}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubh)}(hFor setting some of these values (cpuinfo.min[max]_freq, policy->min[max]), the frequency table helpers might be helpful. See the section 2 for more information on them.h]hFor setting some of these values (cpuinfo.min[max]_freq, policy->min[max]), the frequency table helpers might be helpful. See the section 2 for more information on them.}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]per-cpu-initializationah ]h"]1.2 per-cpu initializationah$]h&]uh1hhjhhhhhK[ubh)}(hhh](h)}(h 1.3 verifyh]h 1.3 verify}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hXWhen the user decides a new policy (consisting of "policy,governor,min,max") shall be set, this policy must be validated so that incompatible values can be corrected. For verifying these values cpufreq_verify_within_limits(``struct cpufreq_policy *policy``, ``unsigned int min_freq``, ``unsigned int max_freq``) function might be helpful. See section 2 for details on frequency table helpers.h](hWhen the user decides a new policy (consisting of “policy,governor,min,max”) shall be set, this policy must be validated so that incompatible values can be corrected. For verifying these values cpufreq_verify_within_limits(}(hjhhhNhNubj)}(h!``struct cpufreq_policy *policy``h]hstruct cpufreq_policy *policy}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh, }(hjhhhNhNubj)}(h``unsigned int min_freq``h]hunsigned int min_freq}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh, }(hjhhhNhNubj)}(h``unsigned int max_freq``h]hunsigned int max_freq}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhR) function might be helpful. See section 2 for details on frequency table helpers.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hYou need to make sure that at least one valid frequency (or operating range) is within policy->min and policy->max. If necessary, increase policy->max first, and only if this is no solution, decrease policy->min.h]hYou need to make sure that at least one valid frequency (or operating range) is within policy->min and policy->max. If necessary, increase policy->max first, and only if this is no solution, decrease policy->min.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]verifyah ]h"] 1.3 verifyah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h71.4 target or target_index or setpolicy or fast_switch?h]h71.4 target or target_index or setpolicy or fast_switch?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hMost cpufreq drivers or even most cpu frequency scaling algorithms only allow the CPU frequency to be set to predefined fixed values. For these, you use the ->target(), ->target_index() or ->fast_switch() callbacks.h]hMost cpufreq drivers or even most cpu frequency scaling algorithms only allow the CPU frequency to be set to predefined fixed values. For these, you use the ->target(), ->target_index() or ->fast_switch() callbacks.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hSome cpufreq capable processors switch the frequency between certain limits on their own. These shall use the ->setpolicy() callback.h]hSome cpufreq capable processors switch the frequency between certain limits on their own. These shall use the ->setpolicy() callback.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]2target-or-target-index-or-setpolicy-or-fast-switchah ]h"]71.4 target or target_index or setpolicy or fast_switch?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h1.5. target/target_indexh]h1.5. target/target_index}(hj3hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj0hhhhhKubh)}(hThe target_index call has two arguments: ``struct cpufreq_policy *policy``, and ``unsigned int`` index (into the exposed frequency table).h](h)The target_index call has two arguments: }(hjAhhhNhNubj)}(h!``struct cpufreq_policy *policy``h]hstruct cpufreq_policy *policy}(hjIhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjAubh, and }(hjAhhhNhNubj)}(h``unsigned int``h]h unsigned int}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjAubh* index (into the exposed frequency table).}(hjAhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj0hhubh)}(hThe CPUfreq driver must set the new frequency when called here. The actual frequency must be determined by freq_table[index].frequency.h]hThe CPUfreq driver must set the new frequency when called here. The actual frequency must be determined by freq_table[index].frequency.}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj0hhubh)}(hIt should always restore to earlier frequency (i.e. policy->restore_freq) in case of errors, even if we switched to intermediate frequency earlier.h]hIt should always restore to earlier frequency (i.e. policy->restore_freq) in case of errors, even if we switched to intermediate frequency earlier.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj0hhubeh}(h]target-target-indexah ]h"]1.5. target/target_indexah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h Deprecatedh]h Deprecated}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(h}The target call has three arguments: ``struct cpufreq_policy *policy``, unsigned int target_frequency, unsigned int relation.h](h%The target call has three arguments: }(hjhhhNhNubj)}(h!``struct cpufreq_policy *policy``h]hstruct cpufreq_policy *policy}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh7, unsigned int target_frequency, unsigned int relation.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hThe CPUfreq driver must set the new frequency when called here. The actual frequency must be determined using the following rules:h]hThe CPUfreq driver must set the new frequency when called here. The actual frequency must be determined using the following rules:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hhh](h)}(hkeep close to "target_freq"h]h)}(hjh]hkeep close to “target_freq”}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhNubh)}(h>policy->min <= new_freq <= policy->max (THIS MUST BE VALID!!!)h]h)}(hjh]h>policy->min <= new_freq <= policy->max (THIS MUST BE VALID!!!)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhNubh)}(hzif relation==CPUFREQ_REL_L, try to select a new_freq higher than or equal target_freq. ("L for lowest, but no lower than")h]h)}(hzif relation==CPUFREQ_REL_L, try to select a new_freq higher than or equal target_freq. ("L for lowest, but no lower than")h]h~if relation==CPUFREQ_REL_L, try to select a new_freq higher than or equal target_freq. (“L for lowest, but no lower than”)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhNubh)}(h|if relation==CPUFREQ_REL_H, try to select a new_freq lower than or equal target_freq. ("H for highest, but no higher than") h]h)}(h{if relation==CPUFREQ_REL_H, try to select a new_freq lower than or equal target_freq. ("H for highest, but no higher than")h]hif relation==CPUFREQ_REL_H, try to select a new_freq lower than or equal target_freq. (“H for highest, but no higher than”)}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhNubeh}(h]h ]h"]h$]h&]jpjquh1hhhhKhjhhubh)}(hSHere again the frequency table helper might assist you - see section 2 for details.h]hSHere again the frequency table helper might assist you - see section 2 for details.}(hj=hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h] deprecatedah ]h"] deprecatedah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h1.6. fast_switchh]h1.6. fast_switch}(hjVhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjShhhhhKubh)}(hThis function is used for frequency switching from scheduler's context. Not all drivers are expected to implement it, as sleeping from within this callback isn't allowed. This callback must be highly optimized to do switching as fast as possible.h]hThis function is used for frequency switching from scheduler’s context. Not all drivers are expected to implement it, as sleeping from within this callback isn’t allowed. This callback must be highly optimized to do switching as fast as possible.}(hjdhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjShhubh)}(hiThis function has two arguments: ``struct cpufreq_policy *policy`` and ``unsigned int target_frequency``.h](h!This function has two arguments: }(hjrhhhNhNubj)}(h!``struct cpufreq_policy *policy``h]hstruct cpufreq_policy *policy}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjrubh and }(hjrhhhNhNubj)}(h!``unsigned int target_frequency``h]hunsigned int target_frequency}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjrubh.}(hjrhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjShhubeh}(h] fast-switchah ]h"]1.6. fast_switchah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h 1.7 setpolicyh]h 1.7 setpolicy}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hXThe setpolicy call only takes a ``struct cpufreq_policy *policy`` as argument. You need to set the lower limit of the in-processor or in-chipset dynamic frequency switching to policy->min, the upper limit to policy->max, and -if supported- select a performance-oriented setting when policy->policy is CPUFREQ_POLICY_PERFORMANCE, and a powersaving-oriented setting when CPUFREQ_POLICY_POWERSAVE. Also check the reference implementation in drivers/cpufreq/longrun.ch](h The setpolicy call only takes a }(hjhhhNhNubj)}(h!``struct cpufreq_policy *policy``h]hstruct cpufreq_policy *policy}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhX as argument. You need to set the lower limit of the in-processor or in-chipset dynamic frequency switching to policy->min, the upper limit to policy->max, and -if supported- select a performance-oriented setting when policy->policy is CPUFREQ_POLICY_PERFORMANCE, and a powersaving-oriented setting when CPUFREQ_POLICY_POWERSAVE. Also check the reference implementation in drivers/cpufreq/longrun.c}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h] setpolicyah ]h"] 1.7 setpolicyah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h,1.8 get_intermediate and target_intermediateh]h,1.8 get_intermediate and target_intermediate}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hJOnly for drivers with target_index() and CPUFREQ_ASYNC_NOTIFICATION unset.h]hJOnly for drivers with target_index() and CPUFREQ_ASYNC_NOTIFICATION unset.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXQget_intermediate should return a stable intermediate frequency platform wants to switch to, and target_intermediate() should set CPU to that frequency, before jumping to the frequency corresponding to 'index'. Core will take care of sending notifications and driver doesn't have to handle them in target_intermediate() or target_index().h]hXWget_intermediate should return a stable intermediate frequency platform wants to switch to, and target_intermediate() should set CPU to that frequency, before jumping to the frequency corresponding to ‘index’. Core will take care of sending notifications and driver doesn’t have to handle them in target_intermediate() or target_index().}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hDrivers can return '0' from get_intermediate() in case they don't wish to switch to intermediate frequency for some target frequency. In that case core will directly call ->target_index().h]hDrivers can return ‘0’ from get_intermediate() in case they don’t wish to switch to intermediate frequency for some target frequency. In that case core will directly call ->target_index().}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(h|NOTE: ->target_index() should restore to policy->restore_freq in case of failures as core would send notifications for that.h]h|NOTE: ->target_index() should restore to policy->restore_freq in case of failures as core would send notifications for that.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h](get-intermediate-and-target-intermediateah ]h"],1.8 get_intermediate and target_intermediateah$]h&]uh1hhjhhhhhKubeh}(h] what-to-doah ]h"]1. what to do?ah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h2. Frequency Table Helpersh]h2. Frequency Table Helpers}(hjAhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj>hhhhhKubh)}(hXAs most cpufreq processors only allow for being set to a few specific frequencies, a "frequency table" with some functions might assist in some work of the processor driver. Such a "frequency table" consists of an array of struct cpufreq_frequency_table entries, with driver specific values in "driver_data", the corresponding frequency in "frequency" and flags set. At the end of the table, you need to add a cpufreq_frequency_table entry with frequency set to CPUFREQ_TABLE_END. And if you want to skip one entry in the table, set the frequency to CPUFREQ_ENTRY_INVALID. The entries don't need to be in sorted in any particular order, but if they are cpufreq core will do DVFS a bit quickly for them as search for best match is faster.h]hXAs most cpufreq processors only allow for being set to a few specific frequencies, a “frequency table” with some functions might assist in some work of the processor driver. Such a “frequency table” consists of an array of struct cpufreq_frequency_table entries, with driver specific values in “driver_data”, the corresponding frequency in “frequency” and flags set. At the end of the table, you need to add a cpufreq_frequency_table entry with frequency set to CPUFREQ_TABLE_END. And if you want to skip one entry in the table, set the frequency to CPUFREQ_ENTRY_INVALID. The entries don’t need to be in sorted in any particular order, but if they are cpufreq core will do DVFS a bit quickly for them as search for best match is faster.}(hjOhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj>hhubh)}(hThe cpufreq table is verified automatically by the core if the policy contains a valid pointer in its policy->freq_table field.h]hThe cpufreq table is verified automatically by the core if the policy contains a valid pointer in its policy->freq_table field.}(hj]hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj>hhubh)}(hcpufreq_frequency_table_verify() assures that at least one valid frequency is within policy->min and policy->max, and all other criteria are met. This is helpful for the ->verify call.h]hcpufreq_frequency_table_verify() assures that at least one valid frequency is within policy->min and policy->max, and all other criteria are met. This is helpful for the ->verify call.}(hjkhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj>hhubh)}(hcpufreq_frequency_table_target() is the corresponding frequency table helper for the ->target stage. Just pass the values to this function, and this function returns the of the frequency table entry which contains the frequency the CPU shall be set to.h]hcpufreq_frequency_table_target() is the corresponding frequency table helper for the ->target stage. Just pass the values to this function, and this function returns the of the frequency table entry which contains the frequency the CPU shall be set to.}(hjyhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj>hhubh)}(hKThe following macros can be used as iterators over cpufreq_frequency_table:h]hKThe following macros can be used as iterators over cpufreq_frequency_table:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj>hhubh)}(hRcpufreq_for_each_entry(pos, table) - iterates over all entries of frequency table.h]hRcpufreq_for_each_entry(pos, table) - iterates over all entries of frequency table.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj>hhubh)}(hXcpufreq_for_each_valid_entry(pos, table) - iterates over all entries, excluding CPUFREQ_ENTRY_INVALID frequencies. Use arguments "pos" - a ``cpufreq_frequency_table *`` as a loop cursor and "table" - the ``cpufreq_frequency_table *`` you want to iterate over.h](hcpufreq_for_each_valid_entry(pos, table) - iterates over all entries, excluding CPUFREQ_ENTRY_INVALID frequencies. Use arguments “pos” - a }(hjhhhNhNubj)}(h``cpufreq_frequency_table *``h]hcpufreq_frequency_table *}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh( as a loop cursor and “table” - the }(hjhhhNhNubj)}(h``cpufreq_frequency_table *``h]hcpufreq_frequency_table *}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh you want to iterate over.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj>hhubh)}(h For example::h]h For example:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj>hhubh literal_block)}(hstruct cpufreq_frequency_table *pos, *driver_freq_table; cpufreq_for_each_entry(pos, driver_freq_table) { /* Do something with pos */ pos->frequency = ... }h]hstruct cpufreq_frequency_table *pos, *driver_freq_table; cpufreq_for_each_entry(pos, driver_freq_table) { /* Do something with pos */ pos->frequency = ... }}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhMhj>hhubh)}(hIf you need to work with the position of pos within driver_freq_table, do not subtract the pointers, as it is quite costly. Instead, use the macros cpufreq_for_each_entry_idx() and cpufreq_for_each_valid_entry_idx().h]hIf you need to work with the position of pos within driver_freq_table, do not subtract the pointers, as it is quite costly. Instead, use the macros cpufreq_for_each_entry_idx() and cpufreq_for_each_valid_entry_idx().}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj>hhubeh}(h]frequency-table-helpersah ]h"]2. frequency table helpersah$]h&]uh1hhhhhhhhKubeh}(h]/how-to-implement-a-new-cpufreq-processor-driverah ]h"]/how to implement a new cpufreq processor driverah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksjUfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerj3error_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(jj j;j8jjjjjjj-j*jjjPjMjjjjj3j0jju nametypes}(jj;jjjj-jjPjjj3juh}(j hj8jjjjjjjj*jjj0jMjjjSjjj0jjj>u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.