drivers/clk/clk-fixed-factor.c
Source file repositories/reference/linux-study-clean/drivers/clk/clk-fixed-factor.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/clk-fixed-factor.c- Extension
.c- Size
- 12336 bytes
- Lines
- 425
- 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.
- 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/module.hlinux/clk-provider.hlinux/slab.hlinux/err.hlinux/of.hlinux/platform_device.h
Detected Declarations
function Copyrightfunction clk_factor_determine_ratefunction clk_factor_set_ratefunction clk_factor_recalc_accuracyfunction devm_clk_hw_register_fixed_factor_releasefunction __clk_hw_register_fixed_factorfunction clk_unregister_fixed_factorfunction clk_hw_unregister_fixed_factorfunction of_fixed_factor_clk_setupfunction of_fixed_factor_clk_removefunction of_fixed_factor_clk_probeexport clk_fixed_factor_opsexport devm_clk_hw_register_fixed_factor_indexexport devm_clk_hw_register_fixed_factor_parent_hwexport clk_hw_register_fixed_factor_parent_hwexport clk_hw_register_fixed_factorexport clk_hw_register_fixed_factor_fwnameexport clk_hw_register_fixed_factor_with_accuracy_fwnameexport clk_hw_register_fixed_factor_indexexport clk_register_fixed_factorexport clk_unregister_fixed_factorexport clk_hw_unregister_fixed_factorexport devm_clk_hw_register_fixed_factorexport devm_clk_hw_register_fixed_factor_fwnameexport devm_clk_hw_register_fixed_factor_with_accuracy_fwname
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
*/
#include <linux/module.h>
#include <linux/clk-provider.h>
#include <linux/slab.h>
#include <linux/err.h>
#include <linux/of.h>
#include <linux/platform_device.h>
/*
* DOC: basic fixed multiplier and divider clock that cannot gate
*
* Traits of this clock:
* prepare - clk_prepare only ensures that parents are prepared
* enable - clk_enable only ensures that parents are enabled
* rate - rate is fixed. clk->rate = parent->rate / div * mult
* parent - fixed parent. No clk_set_parent support
*/
static unsigned long clk_factor_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct clk_fixed_factor *fix = to_clk_fixed_factor(hw);
unsigned long long int rate;
rate = (unsigned long long int)parent_rate * fix->mult;
do_div(rate, fix->div);
return (unsigned long)rate;
}
static int clk_factor_determine_rate(struct clk_hw *hw,
struct clk_rate_request *req)
{
struct clk_fixed_factor *fix = to_clk_fixed_factor(hw);
if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) {
unsigned long best_parent;
best_parent = (req->rate / fix->mult) * fix->div;
req->best_parent_rate = clk_hw_round_rate(clk_hw_get_parent(hw), best_parent);
}
req->rate = (req->best_parent_rate / fix->div) * fix->mult;
return 0;
}
static int clk_factor_set_rate(struct clk_hw *hw, unsigned long rate,
unsigned long parent_rate)
{
/*
* We must report success but we can do so unconditionally because
* clk_factor_determine_rate returns values that ensure this call is a
* nop.
*/
return 0;
}
static unsigned long clk_factor_recalc_accuracy(struct clk_hw *hw,
unsigned long parent_accuracy)
{
struct clk_fixed_factor *fix = to_clk_fixed_factor(hw);
if (fix->flags & CLK_FIXED_FACTOR_FIXED_ACCURACY)
return fix->acc;
return parent_accuracy;
}
const struct clk_ops clk_fixed_factor_ops = {
.determine_rate = clk_factor_determine_rate,
.set_rate = clk_factor_set_rate,
.recalc_rate = clk_factor_recalc_rate,
.recalc_accuracy = clk_factor_recalc_accuracy,
};
EXPORT_SYMBOL_GPL(clk_fixed_factor_ops);
static void devm_clk_hw_register_fixed_factor_release(struct device *dev, void *res)
{
struct clk_fixed_factor *fix = res;
/*
* We can not use clk_hw_unregister_fixed_factor, since it will kfree()
* the hw, resulting in double free. Just unregister the hw and let
* devres code kfree() it.
*/
clk_hw_unregister(&fix->hw);
Annotation
- Immediate include surface: `linux/module.h`, `linux/clk-provider.h`, `linux/slab.h`, `linux/err.h`, `linux/of.h`, `linux/platform_device.h`.
- Detected declarations: `function Copyright`, `function clk_factor_determine_rate`, `function clk_factor_set_rate`, `function clk_factor_recalc_accuracy`, `function devm_clk_hw_register_fixed_factor_release`, `function __clk_hw_register_fixed_factor`, `function clk_unregister_fixed_factor`, `function clk_hw_unregister_fixed_factor`, `function of_fixed_factor_clk_setup`, `function of_fixed_factor_clk_remove`.
- Atlas domain: Driver Families / drivers/clk.
- Implementation status: integration 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.