drivers/clk/tegra/clk-tegra124-emc.c
Source file repositories/reference/linux-study-clean/drivers/clk/tegra/clk-tegra124-emc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/tegra/clk-tegra124-emc.c- Extension
.c- Size
- 14079 bytes
- Lines
- 577
- 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/clk.hlinux/clkdev.hlinux/clk/tegra.hlinux/delay.hlinux/export.hlinux/io.hlinux/module.hlinux/of_address.hlinux/of_platform.hlinux/platform_device.hlinux/sort.hlinux/string.hsoc/tegra/fuse.hclk.h
Detected Declarations
struct emc_timingstruct tegra_clk_emcfunction emc_recalc_ratefunction emc_determine_ratefunction emc_get_parentfunction emc_set_timingfunction emc_set_ratefunction load_one_timing_from_dtfunction cmp_timingsfunction load_timings_from_dtfunction for_each_child_of_node_scopedfunction for_each_child_of_nodefunction tegra124_clk_set_emc_callbacksfunction tegra124_clk_emc_driver_availableexport tegra124_clk_set_emc_callbacks
Annotated Snippet
struct emc_timing {
unsigned long rate, parent_rate;
u8 parent_index;
struct clk *parent;
u32 ram_code;
};
struct tegra_clk_emc {
struct clk_hw hw;
void __iomem *clk_regs;
struct clk *prev_parent;
bool changing_timing;
struct device_node *emc_node;
struct tegra_emc *emc;
int num_timings;
struct emc_timing *timings;
spinlock_t *lock;
tegra124_emc_prepare_timing_change_cb *prepare_timing_change;
tegra124_emc_complete_timing_change_cb *complete_timing_change;
};
/* Common clock framework callback implementations */
static unsigned long emc_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct tegra_clk_emc *tegra;
u32 val, div;
tegra = container_of(hw, struct tegra_clk_emc, hw);
/*
* CCF wrongly assumes that the parent won't change during set_rate,
* so get the parent rate explicitly.
*/
parent_rate = clk_hw_get_rate(clk_hw_get_parent(hw));
val = readl(tegra->clk_regs + CLK_SOURCE_EMC);
div = val & CLK_SOURCE_EMC_EMC_2X_CLK_DIVISOR_MASK;
return parent_rate / (div + 2) * 2;
}
/*
* Rounds up unless no higher rate exists, in which case down. This way is
* safer since things have EMC rate floors. Also don't touch parent_rate
* since we don't want the CCF to play with our parent clocks.
*/
static int emc_determine_rate(struct clk_hw *hw, struct clk_rate_request *req)
{
struct tegra_clk_emc *tegra;
u8 ram_code = tegra_read_ram_code();
struct emc_timing *timing = NULL;
int i, k, t;
tegra = container_of(hw, struct tegra_clk_emc, hw);
for (k = 0; k < tegra->num_timings; k++) {
if (tegra->timings[k].ram_code == ram_code)
break;
}
for (t = k; t < tegra->num_timings; t++) {
if (tegra->timings[t].ram_code != ram_code)
break;
}
for (i = k; i < t; i++) {
timing = tegra->timings + i;
if (timing->rate < req->rate && i != t - 1)
continue;
if (timing->rate > req->max_rate) {
i = max(i, k + 1);
req->rate = tegra->timings[i - 1].rate;
return 0;
}
if (timing->rate < req->min_rate)
continue;
req->rate = timing->rate;
return 0;
}
if (timing) {
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/clk.h`, `linux/clkdev.h`, `linux/clk/tegra.h`, `linux/delay.h`, `linux/export.h`, `linux/io.h`, `linux/module.h`.
- Detected declarations: `struct emc_timing`, `struct tegra_clk_emc`, `function emc_recalc_rate`, `function emc_determine_rate`, `function emc_get_parent`, `function emc_set_timing`, `function emc_set_rate`, `function load_one_timing_from_dt`, `function cmp_timings`, `function load_timings_from_dt`.
- 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.