drivers/clk/clk.c
Source file repositories/reference/linux-study-clean/drivers/clk/clk.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/clk.c- Extension
.c- Size
- 142720 bytes
- Lines
- 5587
- Domain
- Driver Families
- Bucket
- drivers/clk
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/clk-conf.hlinux/clkdev.hlinux/clk.hlinux/clk-provider.hlinux/device.hlinux/err.hlinux/hashtable.hlinux/init.hlinux/list.hlinux/module.hlinux/mutex.hlinux/of.hlinux/pm_runtime.hlinux/sched.hlinux/slab.hlinux/spinlock.hlinux/string.hlinux/stringhash.hclk.htrace/events/clk.hlinux/debugfs.h
Detected Declarations
struct clk_parent_mapstruct clk_corestruct clkstruct clk_notifier_devresstruct of_clk_providerstruct clock_providerfunction clk_pm_runtime_getfunction clk_pm_runtime_putfunction clk_pm_runtime_get_allfunction clk_pm_runtime_put_allfunction clk_pm_runtime_initfunction clk_prepare_lockfunction clk_prepare_unlockfunction clk_enable_lockfunction clk_enable_unlockfunction clk_core_rate_is_protectedfunction clk_core_is_preparedfunction clk_core_is_enabledfunction pm_runtime_getfunction clk_hw_get_num_parentsfunction of_parse_clkspecfunction of_clk_get_hw_from_clkspecfunction clk_core_fill_parent_indexfunction clk_hw_get_parent_by_indexfunction __clk_get_enable_countfunction clk_core_get_rate_nolockfunction clk_hw_get_ratefunction clk_core_get_accuracy_no_lockfunction clk_hw_get_flagsfunction clk_hw_is_preparedfunction clk_hw_is_enabledfunction __clk_is_enabledfunction mux_is_better_ratefunction clk_core_has_parentfunction clk_core_forward_rate_reqfunction clk_core_determine_rate_no_reparentfunction clk_mux_determine_rate_flagsfunction clk_core_get_boundariesfunction clk_hw_get_rate_rangefunction clk_core_check_boundariesfunction clk_hw_set_rate_rangefunction callbackfunction __clk_mux_determine_rate_closestfunction callbackfunction clk_core_rate_unprotectfunction clk_core_rate_nuke_protectfunction clk_rate_exclusive_putfunction clk_core_rate_protect
Annotated Snippet
static const struct file_operations current_parent_rw_fops = {
.open = current_parent_open,
.write = current_parent_write,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
#endif
static int clk_duty_cycle_show(struct seq_file *s, void *data)
{
struct clk_core *core = s->private;
struct clk_duty *duty = &core->duty;
seq_printf(s, "%u/%u\n", duty->num, duty->den);
return 0;
}
DEFINE_SHOW_ATTRIBUTE(clk_duty_cycle);
static int clk_min_rate_show(struct seq_file *s, void *data)
{
struct clk_core *core = s->private;
unsigned long min_rate, max_rate;
clk_prepare_lock();
clk_core_get_boundaries(core, &min_rate, &max_rate);
clk_prepare_unlock();
seq_printf(s, "%lu\n", min_rate);
return 0;
}
DEFINE_SHOW_ATTRIBUTE(clk_min_rate);
static int clk_max_rate_show(struct seq_file *s, void *data)
{
struct clk_core *core = s->private;
unsigned long min_rate, max_rate;
clk_prepare_lock();
clk_core_get_boundaries(core, &min_rate, &max_rate);
clk_prepare_unlock();
seq_printf(s, "%lu\n", max_rate);
return 0;
}
DEFINE_SHOW_ATTRIBUTE(clk_max_rate);
static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry)
{
struct dentry *root;
if (!core || !pdentry)
return;
root = debugfs_create_dir(core->name, pdentry);
core->dentry = root;
debugfs_create_file("clk_rate", clk_rate_mode, root, core,
&clk_rate_fops);
debugfs_create_file("clk_min_rate", 0444, root, core, &clk_min_rate_fops);
debugfs_create_file("clk_max_rate", 0444, root, core, &clk_max_rate_fops);
debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy);
debugfs_create_file("clk_phase", clk_phase_mode, root, core,
&clk_phase_fops);
debugfs_create_file("clk_flags", 0444, root, core, &clk_flags_fops);
debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count);
debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count);
debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count);
debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count);
debugfs_create_file("clk_duty_cycle", 0444, root, core,
&clk_duty_cycle_fops);
#ifdef CLOCK_ALLOW_WRITE_DEBUGFS
debugfs_create_file("clk_prepare_enable", 0644, root, core,
&clk_prepare_enable_fops);
if (core->num_parents > 1)
debugfs_create_file("clk_parent", 0644, root, core,
¤t_parent_rw_fops);
else
#endif
if (core->num_parents > 0)
debugfs_create_file("clk_parent", 0444, root, core,
¤t_parent_fops);
if (core->num_parents > 1)
debugfs_create_file("clk_possible_parents", 0444, root, core,
&possible_parents_fops);
if (core->ops->debug_init)
Annotation
- Immediate include surface: `linux/clk/clk-conf.h`, `linux/clkdev.h`, `linux/clk.h`, `linux/clk-provider.h`, `linux/device.h`, `linux/err.h`, `linux/hashtable.h`, `linux/init.h`.
- Detected declarations: `struct clk_parent_map`, `struct clk_core`, `struct clk`, `struct clk_notifier_devres`, `struct of_clk_provider`, `struct clock_provider`, `function clk_pm_runtime_get`, `function clk_pm_runtime_put`, `function clk_pm_runtime_get_all`, `function clk_pm_runtime_put_all`.
- Atlas domain: Driver Families / drivers/clk.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.