drivers/clk/clk-scpi.c
Source file repositories/reference/linux-study-clean/drivers/clk/clk-scpi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/clk-scpi.c- Extension
.c- Size
- 7543 bytes
- Lines
- 314
- 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/device.hlinux/err.hlinux/of.hlinux/module.hlinux/platform_device.hlinux/scpi_protocol.h
Detected Declarations
struct scpi_clkstruct scpi_clk_datafunction scpi_clk_recalc_ratefunction scpi_clk_determine_ratefunction scpi_clk_set_ratefunction __scpi_dvfs_round_ratefunction scpi_dvfs_recalc_ratefunction scpi_dvfs_determine_ratefunction __scpi_find_dvfs_indexfunction scpi_dvfs_set_ratefunction scpi_clk_ops_initfunction scpi_of_clk_src_getfunction scpi_clk_addfunction scpi_clocks_removefunction scpi_clocks_probefunction for_each_available_child_of_node_scoped
Annotated Snippet
struct scpi_clk {
u32 id;
struct clk_hw hw;
struct scpi_dvfs_info *info;
struct scpi_ops *scpi_ops;
};
#define to_scpi_clk(clk) container_of(clk, struct scpi_clk, hw)
static struct platform_device *cpufreq_dev;
static unsigned long scpi_clk_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct scpi_clk *clk = to_scpi_clk(hw);
return clk->scpi_ops->clk_get_val(clk->id);
}
static int scpi_clk_determine_rate(struct clk_hw *hw,
struct clk_rate_request *req)
{
/*
* We can't figure out what rate it will be, so just return the
* rate back to the caller. scpi_clk_recalc_rate() will be called
* after the rate is set and we'll know what rate the clock is
* running at then.
*/
return 0;
}
static int scpi_clk_set_rate(struct clk_hw *hw, unsigned long rate,
unsigned long parent_rate)
{
struct scpi_clk *clk = to_scpi_clk(hw);
return clk->scpi_ops->clk_set_val(clk->id, rate);
}
static const struct clk_ops scpi_clk_ops = {
.recalc_rate = scpi_clk_recalc_rate,
.determine_rate = scpi_clk_determine_rate,
.set_rate = scpi_clk_set_rate,
};
/* find closest match to given frequency in OPP table */
static long __scpi_dvfs_round_rate(struct scpi_clk *clk, unsigned long rate)
{
int idx;
unsigned long fmin = 0, fmax = ~0, ftmp;
const struct scpi_opp *opp = clk->info->opps;
for (idx = 0; idx < clk->info->count; idx++, opp++) {
ftmp = opp->freq;
if (ftmp >= rate) {
if (ftmp <= fmax)
fmax = ftmp;
break;
} else if (ftmp >= fmin) {
fmin = ftmp;
}
}
return fmax != ~0 ? fmax : fmin;
}
static unsigned long scpi_dvfs_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct scpi_clk *clk = to_scpi_clk(hw);
int idx = clk->scpi_ops->dvfs_get_idx(clk->id);
const struct scpi_opp *opp;
if (idx < 0)
return 0;
opp = clk->info->opps + idx;
return opp->freq;
}
static int scpi_dvfs_determine_rate(struct clk_hw *hw,
struct clk_rate_request *req)
{
struct scpi_clk *clk = to_scpi_clk(hw);
req->rate = __scpi_dvfs_round_rate(clk, req->rate);
return 0;
}
static int __scpi_find_dvfs_index(struct scpi_clk *clk, unsigned long rate)
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/device.h`, `linux/err.h`, `linux/of.h`, `linux/module.h`, `linux/platform_device.h`, `linux/scpi_protocol.h`.
- Detected declarations: `struct scpi_clk`, `struct scpi_clk_data`, `function scpi_clk_recalc_rate`, `function scpi_clk_determine_rate`, `function scpi_clk_set_rate`, `function __scpi_dvfs_round_rate`, `function scpi_dvfs_recalc_rate`, `function scpi_dvfs_determine_rate`, `function __scpi_find_dvfs_index`, `function scpi_dvfs_set_rate`.
- 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.