drivers/clk/sunxi/clk-mod0.c
Source file repositories/reference/linux-study-clean/drivers/clk/sunxi/clk-mod0.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/sunxi/clk-mod0.c- Extension
.c- Size
- 8867 bytes
- Lines
- 375
- 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.
- 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.hlinux/clk-provider.hlinux/io.hlinux/of_address.hlinux/platform_device.hlinux/slab.hclk-factors.h
Detected Declarations
struct mmc_phasefunction sun4i_a10_get_mod0_factorsfunction sun4i_a10_mod0_setupfunction sun4i_a10_mod0_clk_probefunction sun9i_a80_mod0_setupfunction sun5i_a13_mbus_setupfunction mmc_get_phasefunction mmc_set_phasefunction sunxi_mmc_setupfunction sun4i_a10_mmc_setupfunction sun9i_a80_mmc_setup
Annotated Snippet
struct mmc_phase {
struct clk_hw hw;
u8 offset;
void __iomem *reg;
spinlock_t *lock;
};
#define to_mmc_phase(_hw) container_of(_hw, struct mmc_phase, hw)
static int mmc_get_phase(struct clk_hw *hw)
{
struct clk *mmc, *mmc_parent, *clk = hw->clk;
struct mmc_phase *phase = to_mmc_phase(hw);
unsigned int mmc_rate, mmc_parent_rate;
u16 step, mmc_div;
u32 value;
u8 delay;
value = readl(phase->reg);
delay = (value >> phase->offset) & 0x3;
if (!delay)
return 180;
/* Get the main MMC clock */
mmc = clk_get_parent(clk);
if (!mmc)
return -EINVAL;
/* And its rate */
mmc_rate = clk_get_rate(mmc);
if (!mmc_rate)
return -EINVAL;
/* Now, get the MMC parent (most likely some PLL) */
mmc_parent = clk_get_parent(mmc);
if (!mmc_parent)
return -EINVAL;
/* And its rate */
mmc_parent_rate = clk_get_rate(mmc_parent);
if (!mmc_parent_rate)
return -EINVAL;
/* Get MMC clock divider */
mmc_div = mmc_parent_rate / mmc_rate;
step = DIV_ROUND_CLOSEST(360, mmc_div);
return delay * step;
}
static int mmc_set_phase(struct clk_hw *hw, int degrees)
{
struct clk *mmc, *mmc_parent, *clk = hw->clk;
struct mmc_phase *phase = to_mmc_phase(hw);
unsigned int mmc_rate, mmc_parent_rate;
unsigned long flags;
u32 value;
u8 delay;
/* Get the main MMC clock */
mmc = clk_get_parent(clk);
if (!mmc)
return -EINVAL;
/* And its rate */
mmc_rate = clk_get_rate(mmc);
if (!mmc_rate)
return -EINVAL;
/* Now, get the MMC parent (most likely some PLL) */
mmc_parent = clk_get_parent(mmc);
if (!mmc_parent)
return -EINVAL;
/* And its rate */
mmc_parent_rate = clk_get_rate(mmc_parent);
if (!mmc_parent_rate)
return -EINVAL;
if (degrees != 180) {
u16 step, mmc_div;
/* Get MMC clock divider */
mmc_div = mmc_parent_rate / mmc_rate;
/*
* We can only outphase the clocks by multiple of the
* PLL's period.
*
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clk-provider.h`, `linux/io.h`, `linux/of_address.h`, `linux/platform_device.h`, `linux/slab.h`, `clk-factors.h`.
- Detected declarations: `struct mmc_phase`, `function sun4i_a10_get_mod0_factors`, `function sun4i_a10_mod0_setup`, `function sun4i_a10_mod0_clk_probe`, `function sun9i_a80_mod0_setup`, `function sun5i_a13_mbus_setup`, `function mmc_get_phase`, `function mmc_set_phase`, `function sunxi_mmc_setup`, `function sun4i_a10_mmc_setup`.
- Atlas domain: Driver Families / drivers/clk.
- Implementation status: source 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.