drivers/cpufreq/cpufreq-dt.c
Source file repositories/reference/linux-study-clean/drivers/cpufreq/cpufreq-dt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/cpufreq/cpufreq-dt.c- Extension
.c- Size
- 8713 bytes
- Lines
- 348
- Domain
- Driver Families
- Bucket
- drivers/cpufreq
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/cpu.hlinux/cpufreq.hlinux/cpumask.hlinux/err.hlinux/list.hlinux/module.hlinux/of.hlinux/pm_opp.hlinux/platform_device.hlinux/regulator/consumer.hlinux/slab.hlinux/thermal.hcpufreq-dt.h
Detected Declarations
struct private_datafunction list_for_each_entryfunction set_targetfunction cpufreq_initfunction cpufreq_onlinefunction cpufreq_offlinefunction cpufreq_exitfunction dt_cpufreq_early_initfunction dt_cpufreq_releasefunction list_for_each_entry_safefunction dt_cpufreq_probefunction dt_cpufreq_removeexport cpufreq_dt_pdev_register
Annotated Snippet
struct private_data {
struct list_head node;
cpumask_var_t cpus;
struct device *cpu_dev;
struct cpufreq_frequency_table *freq_table;
bool have_static_opps;
int opp_token;
};
static LIST_HEAD(priv_list);
static struct private_data *cpufreq_dt_find_data(int cpu)
{
struct private_data *priv;
list_for_each_entry(priv, &priv_list, node) {
if (cpumask_test_cpu(cpu, priv->cpus))
return priv;
}
return NULL;
}
static int set_target(struct cpufreq_policy *policy, unsigned int index)
{
struct private_data *priv = policy->driver_data;
unsigned long freq = policy->freq_table[index].frequency;
return dev_pm_opp_set_rate(priv->cpu_dev, freq * 1000);
}
/*
* An earlier version of opp-v1 bindings used to name the regulator
* "cpu0-supply", we still need to handle that for backwards compatibility.
*/
static const char *find_supply_name(struct device *dev)
{
struct device_node *np __free(device_node) = of_node_get(dev->of_node);
int cpu = dev->id;
/* This must be valid for sure */
if (WARN_ON(!np))
return NULL;
/* Try "cpu0" for older DTs */
if (!cpu && of_property_present(np, "cpu0-supply"))
return "cpu0";
if (of_property_present(np, "cpu-supply"))
return "cpu";
dev_dbg(dev, "no regulator for cpu%d\n", cpu);
return NULL;
}
static int cpufreq_init(struct cpufreq_policy *policy)
{
struct private_data *priv;
struct device *cpu_dev;
struct clk *cpu_clk;
unsigned int transition_latency;
int ret;
priv = cpufreq_dt_find_data(policy->cpu);
if (!priv) {
pr_err("failed to find data for cpu%d\n", policy->cpu);
return -ENODEV;
}
cpu_dev = priv->cpu_dev;
cpu_clk = clk_get(cpu_dev, NULL);
if (IS_ERR(cpu_clk)) {
ret = PTR_ERR(cpu_clk);
dev_err(cpu_dev, "%s: failed to get clk: %d\n", __func__, ret);
return ret;
}
transition_latency = dev_pm_opp_get_max_transition_latency(cpu_dev);
if (!transition_latency)
transition_latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
cpumask_copy(policy->cpus, priv->cpus);
policy->driver_data = priv;
policy->clk = cpu_clk;
policy->freq_table = priv->freq_table;
policy->suspend_freq = dev_pm_opp_get_suspend_opp_freq(cpu_dev) / 1000;
policy->cpuinfo.transition_latency = transition_latency;
policy->dvfs_possible_from_any_cpu = true;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/cpu.h`, `linux/cpufreq.h`, `linux/cpumask.h`, `linux/err.h`, `linux/list.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct private_data`, `function list_for_each_entry`, `function set_target`, `function cpufreq_init`, `function cpufreq_online`, `function cpufreq_offline`, `function cpufreq_exit`, `function dt_cpufreq_early_init`, `function dt_cpufreq_release`, `function list_for_each_entry_safe`.
- Atlas domain: Driver Families / drivers/cpufreq.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.