drivers/clk/ti/divider.c
Source file repositories/reference/linux-study-clean/drivers/clk/ti/divider.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/ti/divider.c- Extension
.c- Size
- 12433 bytes
- Lines
- 561
- Domain
- Driver Families
- Bucket
- drivers/clk
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/slab.hlinux/err.hlinux/of.hlinux/of_address.hlinux/clk/ti.hclock.h
Detected Declarations
function Copyrightfunction _setup_maskfunction _get_divfunction _get_table_valfunction _get_valfunction ti_clk_divider_recalc_ratefunction _is_valid_table_divfunction _is_valid_divfunction _div_round_upfunction _div_roundfunction ti_clk_divider_bestdivfunction ti_clk_divider_determine_ratefunction ti_clk_divider_set_ratefunction clk_divider_save_contextfunction clk_divider_restore_contextfunction ti_clk_parse_divider_datafunction ti_clk_get_div_tablefunction _populate_divider_min_maxfunction ti_clk_divider_populatefunction of_ti_divider_clk_setupfunction of_ti_composite_divider_clk_setup
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(clk_hw_get_parent(hw),
MULT_ROUND_UP(rate, i));
now = DIV_ROUND_UP(parent_rate, i);
if (now <= rate && now > best) {
bestdiv = i;
best = now;
*best_parent_rate = parent_rate;
}
}
if (!bestdiv) {
bestdiv = divider->max;
*best_parent_rate =
clk_hw_round_rate(clk_hw_get_parent(hw), 1);
}
return bestdiv;
}
static int ti_clk_divider_determine_rate(struct clk_hw *hw,
struct clk_rate_request *req)
{
int div;
div = ti_clk_divider_bestdiv(hw, req->rate, &req->best_parent_rate);
req->rate = DIV_ROUND_UP(req->best_parent_rate, div);
return 0;
}
static int ti_clk_divider_set_rate(struct clk_hw *hw, unsigned long rate,
unsigned long parent_rate)
{
struct clk_omap_divider *divider;
unsigned int div, value;
u32 val;
if (!hw || !rate)
return -EINVAL;
divider = to_clk_omap_divider(hw);
div = DIV_ROUND_UP(parent_rate, rate);
if (div > divider->max)
div = divider->max;
if (div < divider->min)
div = divider->min;
value = _get_val(divider, div);
val = ti_clk_ll_ops->clk_readl(÷r->reg);
val &= ~(divider->mask << divider->shift);
val |= value << divider->shift;
ti_clk_ll_ops->clk_writel(val, ÷r->reg);
ti_clk_latch(÷r->reg, divider->latch);
return 0;
}
/**
* clk_divider_save_context - Save the divider value
* @hw: pointer struct clk_hw
*
* Save the divider value
*/
static int clk_divider_save_context(struct clk_hw *hw)
{
struct clk_omap_divider *divider = to_clk_omap_divider(hw);
u32 val;
val = ti_clk_ll_ops->clk_readl(÷r->reg) >> divider->shift;
divider->context = val & divider->mask;
return 0;
}
/**
* clk_divider_restore_context - restore the saved the divider value
* @hw: pointer struct clk_hw
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/slab.h`, `linux/err.h`, `linux/of.h`, `linux/of_address.h`, `linux/clk/ti.h`, `clock.h`.
- Detected declarations: `function Copyright`, `function _setup_mask`, `function _get_div`, `function _get_table_val`, `function _get_val`, `function ti_clk_divider_recalc_rate`, `function _is_valid_table_div`, `function _is_valid_div`, `function _div_round_up`, `function _div_round`.
- Atlas domain: Driver Families / drivers/clk.
- Implementation status: source 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.