drivers/clk/renesas/clk-mstp.c
Source file repositories/reference/linux-study-clean/drivers/clk/renesas/clk-mstp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/renesas/clk-mstp.c- Extension
.c- Size
- 8162 bytes
- Lines
- 347
- 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/clk.hlinux/clk-provider.hlinux/clk/renesas.hlinux/device.hlinux/io.hlinux/iopoll.hlinux/of.hlinux/of_address.hlinux/pm_clock.hlinux/pm_domain.hlinux/slab.hlinux/spinlock.h
Detected Declarations
struct mstp_clock_groupstruct mstp_clockfunction cpg_mstp_readfunction cpg_mstp_writefunction cpg_mstp_clock_endisablefunction cpg_mstp_clock_enablefunction cpg_mstp_clock_disablefunction cpg_mstp_clock_is_enabledfunction cpg_mstp_clock_registerfunction cpg_mstp_clocks_initfunction cpg_mstp_attach_devfunction cpg_mstp_detach_devfunction cpg_mstp_add_clk_domainfunction cpg_mstp_pd_init_provider
Annotated Snippet
struct mstp_clock_group {
struct clk_onecell_data data;
void __iomem *smstpcr;
void __iomem *mstpsr;
spinlock_t lock;
bool width_8bit;
struct clk *clks[];
};
/**
* struct mstp_clock - MSTP gating clock
* @hw: handle between common and hardware-specific interfaces
* @bit_index: control bit index
* @group: MSTP clocks group
*/
struct mstp_clock {
struct clk_hw hw;
u32 bit_index;
struct mstp_clock_group *group;
};
#define to_mstp_clock(_hw) container_of(_hw, struct mstp_clock, hw)
static inline u32 cpg_mstp_read(struct mstp_clock_group *group,
u32 __iomem *reg)
{
return group->width_8bit ? readb(reg) : readl(reg);
}
static inline void cpg_mstp_write(struct mstp_clock_group *group, u32 val,
u32 __iomem *reg)
{
group->width_8bit ? writeb(val, reg) : writel(val, reg);
}
static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable)
{
struct mstp_clock *clock = to_mstp_clock(hw);
struct mstp_clock_group *group = clock->group;
u32 bitmask = BIT(clock->bit_index);
unsigned long flags;
u32 value;
int ret;
spin_lock_irqsave(&group->lock, flags);
value = cpg_mstp_read(group, group->smstpcr);
if (enable)
value &= ~bitmask;
else
value |= bitmask;
cpg_mstp_write(group, value, group->smstpcr);
if (!group->mstpsr) {
/* dummy read to ensure write has completed */
cpg_mstp_read(group, group->smstpcr);
barrier_data(group->smstpcr);
}
spin_unlock_irqrestore(&group->lock, flags);
if (!enable || !group->mstpsr)
return 0;
/* group->width_8bit is always false if group->mstpsr is present */
ret = readl_poll_timeout_atomic(group->mstpsr, value,
!(value & bitmask), 0, 10);
if (ret)
pr_err("%s: failed to enable %p[%d]\n", __func__,
group->smstpcr, clock->bit_index);
return ret;
}
static int cpg_mstp_clock_enable(struct clk_hw *hw)
{
return cpg_mstp_clock_endisable(hw, true);
}
static void cpg_mstp_clock_disable(struct clk_hw *hw)
{
cpg_mstp_clock_endisable(hw, false);
}
static int cpg_mstp_clock_is_enabled(struct clk_hw *hw)
{
struct mstp_clock *clock = to_mstp_clock(hw);
struct mstp_clock_group *group = clock->group;
u32 value;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clk-provider.h`, `linux/clk/renesas.h`, `linux/device.h`, `linux/io.h`, `linux/iopoll.h`, `linux/of.h`, `linux/of_address.h`.
- Detected declarations: `struct mstp_clock_group`, `struct mstp_clock`, `function cpg_mstp_read`, `function cpg_mstp_write`, `function cpg_mstp_clock_endisable`, `function cpg_mstp_clock_enable`, `function cpg_mstp_clock_disable`, `function cpg_mstp_clock_is_enabled`, `function cpg_mstp_clock_register`, `function cpg_mstp_clocks_init`.
- 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.