drivers/clk/hisilicon/clk-hisi-phase.c
Source file repositories/reference/linux-study-clean/drivers/clk/hisilicon/clk-hisi-phase.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/hisilicon/clk-hisi-phase.c- Extension
.c- Size
- 2762 bytes
- Lines
- 122
- 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/err.hlinux/io.hlinux/module.hlinux/platform_device.hlinux/slab.hclk.h
Detected Declarations
struct clk_hisi_phasefunction hisi_phase_regval_to_degreesfunction hisi_clk_get_phasefunction hisi_phase_degrees_to_regvalfunction hisi_clk_set_phaseexport clk_register_hisi_phase
Annotated Snippet
struct clk_hisi_phase {
struct clk_hw hw;
void __iomem *reg;
u32 *phase_degrees;
u32 *phase_regvals;
u8 phase_num;
u32 mask;
u8 shift;
u8 flags;
spinlock_t *lock;
};
#define to_clk_hisi_phase(_hw) container_of(_hw, struct clk_hisi_phase, hw)
static int hisi_phase_regval_to_degrees(struct clk_hisi_phase *phase,
u32 regval)
{
int i;
for (i = 0; i < phase->phase_num; i++)
if (phase->phase_regvals[i] == regval)
return phase->phase_degrees[i];
return -EINVAL;
}
static int hisi_clk_get_phase(struct clk_hw *hw)
{
struct clk_hisi_phase *phase = to_clk_hisi_phase(hw);
u32 regval;
regval = readl(phase->reg);
regval = (regval & phase->mask) >> phase->shift;
return hisi_phase_regval_to_degrees(phase, regval);
}
static int hisi_phase_degrees_to_regval(struct clk_hisi_phase *phase,
int degrees)
{
int i;
for (i = 0; i < phase->phase_num; i++)
if (phase->phase_degrees[i] == degrees)
return phase->phase_regvals[i];
return -EINVAL;
}
static int hisi_clk_set_phase(struct clk_hw *hw, int degrees)
{
struct clk_hisi_phase *phase = to_clk_hisi_phase(hw);
unsigned long flags = 0;
int regval;
u32 val;
regval = hisi_phase_degrees_to_regval(phase, degrees);
if (regval < 0)
return regval;
spin_lock_irqsave(phase->lock, flags);
val = readl(phase->reg);
val &= ~phase->mask;
val |= regval << phase->shift;
writel(val, phase->reg);
spin_unlock_irqrestore(phase->lock, flags);
return 0;
}
static const struct clk_ops clk_phase_ops = {
.get_phase = hisi_clk_get_phase,
.set_phase = hisi_clk_set_phase,
};
struct clk *clk_register_hisi_phase(struct device *dev,
const struct hisi_phase_clock *clks,
void __iomem *base, spinlock_t *lock)
{
struct clk_hisi_phase *phase;
struct clk_init_data init;
phase = devm_kzalloc(dev, sizeof(struct clk_hisi_phase), GFP_KERNEL);
if (!phase)
return ERR_PTR(-ENOMEM);
init.name = clks->name;
init.ops = &clk_phase_ops;
Annotation
- Immediate include surface: `linux/err.h`, `linux/io.h`, `linux/module.h`, `linux/platform_device.h`, `linux/slab.h`, `clk.h`.
- Detected declarations: `struct clk_hisi_phase`, `function hisi_phase_regval_to_degrees`, `function hisi_clk_get_phase`, `function hisi_phase_degrees_to_regval`, `function hisi_clk_set_phase`, `export clk_register_hisi_phase`.
- 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.