drivers/clk/clk-divider.c
Source file repositories/reference/linux-study-clean/drivers/clk/clk-divider.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/clk-divider.c- Extension
.c- Size
- 16282 bytes
- Lines
- 631
- Domain
- Driver Families
- Bucket
- drivers/clk
- 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.
- 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-provider.hlinux/device.hlinux/module.hlinux/slab.hlinux/io.hlinux/err.hlinux/string.hlinux/log2.h
Detected Declarations
function Copyrightfunction clk_div_writelfunction _get_table_maxdivfunction _get_table_mindivfunction _get_maxdivfunction _get_table_divfunction _get_divfunction _get_table_valfunction _get_valfunction divider_recalc_ratefunction clk_divider_recalc_ratefunction _is_valid_table_divfunction _is_valid_divfunction _round_up_tablefunction _round_down_tablefunction _div_round_upfunction _div_round_closestfunction _div_roundfunction _is_best_divfunction _next_divfunction clk_divider_bestdivfunction divider_determine_ratefunction divider_ro_determine_ratefunction clk_divider_determine_ratefunction divider_get_valfunction clk_divider_set_ratefunction clk_unregister_dividerfunction clk_hw_unregister_dividerfunction devm_clk_hw_release_dividerexport divider_recalc_rateexport divider_determine_rateexport divider_ro_determine_rateexport divider_get_valexport clk_divider_opsexport clk_divider_ro_opsexport __clk_hw_register_dividerexport clk_register_divider_tableexport clk_unregister_dividerexport clk_hw_unregister_dividerexport __devm_clk_hw_register_divider
Annotated Snippet
if (rate * i == parent_rate_saved) {
/*
* It's the most ideal case if the requested rate can be
* divided from parent clock without needing to change
* parent rate, so return the divider immediately.
*/
*best_parent_rate = parent_rate_saved;
return i;
}
parent_rate = clk_hw_round_rate(parent, rate * i);
now = DIV_ROUND_UP_ULL((u64)parent_rate, i);
if (_is_best_div(rate, now, best, flags)) {
bestdiv = i;
best = now;
*best_parent_rate = parent_rate;
}
}
if (!bestdiv) {
bestdiv = _get_maxdiv(table, width, flags);
*best_parent_rate = clk_hw_round_rate(parent, 1);
}
return bestdiv;
}
int divider_determine_rate(struct clk_hw *hw, struct clk_rate_request *req,
const struct clk_div_table *table, u8 width,
unsigned long flags)
{
int div;
div = clk_divider_bestdiv(hw, req->best_parent_hw, req->rate,
&req->best_parent_rate, table, width, flags);
req->rate = DIV_ROUND_UP_ULL((u64)req->best_parent_rate, div);
return 0;
}
EXPORT_SYMBOL_GPL(divider_determine_rate);
int divider_ro_determine_rate(struct clk_hw *hw, struct clk_rate_request *req,
const struct clk_div_table *table, u8 width,
unsigned long flags, unsigned int val)
{
int div;
div = _get_div(table, val, flags, width);
/* Even a read-only clock can propagate a rate change */
if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) {
if (!req->best_parent_hw)
return -EINVAL;
req->best_parent_rate = clk_hw_round_rate(req->best_parent_hw,
req->rate * div);
}
req->rate = DIV_ROUND_UP_ULL((u64)req->best_parent_rate, div);
return 0;
}
EXPORT_SYMBOL_GPL(divider_ro_determine_rate);
static int clk_divider_determine_rate(struct clk_hw *hw,
struct clk_rate_request *req)
{
struct clk_divider *divider = to_clk_divider(hw);
/* if read only, just return current value */
if (divider->flags & CLK_DIVIDER_READ_ONLY) {
u32 val;
val = clk_div_readl(divider) >> divider->shift;
val &= clk_div_mask(divider->width);
return divider_ro_determine_rate(hw, req, divider->table,
divider->width,
divider->flags, val);
}
return divider_determine_rate(hw, req, divider->table, divider->width,
divider->flags);
}
int divider_get_val(unsigned long rate, unsigned long parent_rate,
const struct clk_div_table *table, u8 width,
unsigned long flags)
{
unsigned int div, value;
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/device.h`, `linux/module.h`, `linux/slab.h`, `linux/io.h`, `linux/err.h`, `linux/string.h`, `linux/log2.h`.
- Detected declarations: `function Copyright`, `function clk_div_writel`, `function _get_table_maxdiv`, `function _get_table_mindiv`, `function _get_maxdiv`, `function _get_table_div`, `function _get_div`, `function _get_table_val`, `function _get_val`, `function divider_recalc_rate`.
- Atlas domain: Driver Families / drivers/clk.
- Implementation status: integration 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.