drivers/clk/rockchip/clk-gate-grf.c
Source file repositories/reference/linux-study-clean/drivers/clk/rockchip/clk-gate-grf.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/rockchip/clk-gate-grf.c- Extension
.c- Size
- 2781 bytes
- Lines
- 106
- 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.
- 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/regmap.hlinux/slab.hclk.h
Detected Declarations
struct rockchip_gate_grffunction rockchip_gate_grf_enablefunction rockchip_gate_grf_disablefunction rockchip_gate_grf_is_enabled
Annotated Snippet
struct rockchip_gate_grf {
struct clk_hw hw;
struct regmap *regmap;
unsigned int reg;
unsigned int shift;
u8 flags;
};
#define to_gate_grf(_hw) container_of(_hw, struct rockchip_gate_grf, hw)
static int rockchip_gate_grf_enable(struct clk_hw *hw)
{
struct rockchip_gate_grf *gate = to_gate_grf(hw);
u32 val = !(gate->flags & CLK_GATE_SET_TO_DISABLE) ? BIT(gate->shift) : 0;
u32 hiword = ((gate->flags & CLK_GATE_HIWORD_MASK) ? 1 : 0) << (gate->shift + 16);
int ret;
ret = regmap_update_bits(gate->regmap, gate->reg,
hiword | BIT(gate->shift), hiword | val);
return ret;
}
static void rockchip_gate_grf_disable(struct clk_hw *hw)
{
struct rockchip_gate_grf *gate = to_gate_grf(hw);
u32 val = !(gate->flags & CLK_GATE_SET_TO_DISABLE) ? 0 : BIT(gate->shift);
u32 hiword = ((gate->flags & CLK_GATE_HIWORD_MASK) ? 1 : 0) << (gate->shift + 16);
regmap_update_bits(gate->regmap, gate->reg,
hiword | BIT(gate->shift), hiword | val);
}
static int rockchip_gate_grf_is_enabled(struct clk_hw *hw)
{
struct rockchip_gate_grf *gate = to_gate_grf(hw);
bool invert = !!(gate->flags & CLK_GATE_SET_TO_DISABLE);
int ret;
ret = regmap_test_bits(gate->regmap, gate->reg, BIT(gate->shift));
if (ret < 0)
ret = 0;
return invert ? 1 - ret : ret;
}
static const struct clk_ops rockchip_gate_grf_ops = {
.enable = rockchip_gate_grf_enable,
.disable = rockchip_gate_grf_disable,
.is_enabled = rockchip_gate_grf_is_enabled,
};
struct clk *rockchip_clk_register_gate_grf(const char *name,
const char *parent_name, unsigned long flags,
struct regmap *regmap, unsigned int reg, unsigned int shift,
u8 gate_flags)
{
struct rockchip_gate_grf *gate;
struct clk_init_data init;
struct clk *clk;
if (IS_ERR(regmap)) {
pr_err("%s: regmap not available\n", __func__);
return ERR_PTR(-EOPNOTSUPP);
}
gate = kzalloc_obj(*gate);
if (!gate)
return ERR_PTR(-ENOMEM);
init.name = name;
init.flags = flags;
init.num_parents = parent_name ? 1 : 0;
init.parent_names = parent_name ? &parent_name : NULL;
init.ops = &rockchip_gate_grf_ops;
gate->hw.init = &init;
gate->regmap = regmap;
gate->reg = reg;
gate->shift = shift;
gate->flags = gate_flags;
clk = clk_register(NULL, &gate->hw);
if (IS_ERR(clk))
kfree(gate);
return clk;
}
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clk-provider.h`, `linux/regmap.h`, `linux/slab.h`, `clk.h`.
- Detected declarations: `struct rockchip_gate_grf`, `function rockchip_gate_grf_enable`, `function rockchip_gate_grf_disable`, `function rockchip_gate_grf_is_enabled`.
- Atlas domain: Driver Families / drivers/clk.
- Implementation status: source 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.