drivers/clk/qcom/clk-spmi-pmic-div.c
Source file repositories/reference/linux-study-clean/drivers/clk/qcom/clk-spmi-pmic-div.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/qcom/clk-spmi-pmic-div.c- Extension
.c- Size
- 6938 bytes
- Lines
- 287
- 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/bitops.hlinux/cleanup.hlinux/clk.hlinux/clk-provider.hlinux/delay.hlinux/err.hlinux/log2.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/regmap.hlinux/slab.hlinux/types.h
Detected Declarations
struct clkdivstruct spmi_pmic_div_clk_ccfunction div_factor_to_divfunction div_to_div_factorfunction is_spmi_pmic_clkdiv_enabledfunction __spmi_pmic_clkdiv_set_enable_statefunction spmi_pmic_clkdiv_set_enable_statefunction clk_spmi_pmic_div_enablefunction clk_spmi_pmic_div_disablefunction clk_spmi_pmic_div_determine_ratefunction clk_spmi_pmic_div_recalc_ratefunction clk_spmi_pmic_div_set_ratefunction spmi_pmic_div_clk_hw_getfunction spmi_pmic_clkdiv_probe
Annotated Snippet
struct clkdiv {
struct regmap *regmap;
u16 base;
spinlock_t lock;
struct clk_hw hw;
unsigned int cxo_period_ns;
};
static inline struct clkdiv *to_clkdiv(struct clk_hw *hw)
{
return container_of(hw, struct clkdiv, hw);
}
static inline unsigned int div_factor_to_div(unsigned int div_factor)
{
if (!div_factor)
div_factor = 1;
return 1 << (div_factor - 1);
}
static inline unsigned int div_to_div_factor(unsigned int div)
{
return min(ilog2(div) + 1, 7);
}
static bool is_spmi_pmic_clkdiv_enabled(struct clkdiv *clkdiv)
{
unsigned int val = 0;
regmap_read(clkdiv->regmap, clkdiv->base + REG_EN_CTL, &val);
return val & REG_EN_MASK;
}
static int
__spmi_pmic_clkdiv_set_enable_state(struct clkdiv *clkdiv, bool enable,
unsigned int div_factor)
{
int ret;
unsigned int ns = clkdiv->cxo_period_ns;
unsigned int div = div_factor_to_div(div_factor);
ret = regmap_update_bits(clkdiv->regmap, clkdiv->base + REG_EN_CTL,
REG_EN_MASK, enable ? REG_EN_MASK : 0);
if (ret)
return ret;
if (enable)
ndelay((2 + 3 * div) * ns);
else
ndelay(3 * div * ns);
return 0;
}
static int spmi_pmic_clkdiv_set_enable_state(struct clkdiv *clkdiv, bool enable)
{
unsigned int div_factor;
regmap_read(clkdiv->regmap, clkdiv->base + REG_DIV_CTL1, &div_factor);
div_factor &= DIV_CTL1_DIV_FACTOR_MASK;
return __spmi_pmic_clkdiv_set_enable_state(clkdiv, enable, div_factor);
}
static int clk_spmi_pmic_div_enable(struct clk_hw *hw)
{
struct clkdiv *clkdiv = to_clkdiv(hw);
unsigned long flags;
int ret;
spin_lock_irqsave(&clkdiv->lock, flags);
ret = spmi_pmic_clkdiv_set_enable_state(clkdiv, true);
spin_unlock_irqrestore(&clkdiv->lock, flags);
return ret;
}
static void clk_spmi_pmic_div_disable(struct clk_hw *hw)
{
struct clkdiv *clkdiv = to_clkdiv(hw);
unsigned long flags;
spin_lock_irqsave(&clkdiv->lock, flags);
spmi_pmic_clkdiv_set_enable_state(clkdiv, false);
spin_unlock_irqrestore(&clkdiv->lock, flags);
}
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/cleanup.h`, `linux/clk.h`, `linux/clk-provider.h`, `linux/delay.h`, `linux/err.h`, `linux/log2.h`, `linux/module.h`.
- Detected declarations: `struct clkdiv`, `struct spmi_pmic_div_clk_cc`, `function div_factor_to_div`, `function div_to_div_factor`, `function is_spmi_pmic_clkdiv_enabled`, `function __spmi_pmic_clkdiv_set_enable_state`, `function spmi_pmic_clkdiv_set_enable_state`, `function clk_spmi_pmic_div_enable`, `function clk_spmi_pmic_div_disable`, `function clk_spmi_pmic_div_determine_rate`.
- 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.