drivers/clk/imx/clk-gpr-mux.c
Source file repositories/reference/linux-study-clean/drivers/clk/imx/clk-gpr-mux.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/imx/clk-gpr-mux.c- Extension
.c- Size
- 2527 bytes
- Lines
- 115
- 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/module.hlinux/clk-provider.hlinux/errno.hlinux/export.hlinux/io.hlinux/slab.hlinux/regmap.hlinux/mfd/syscon.hclk.h
Detected Declarations
struct imx_clk_gprfunction imx_clk_gpr_mux_get_parentfunction imx_clk_gpr_mux_set_parent
Annotated Snippet
struct imx_clk_gpr {
struct clk_hw hw;
struct regmap *regmap;
u32 mask;
u32 reg;
const u32 *mux_table;
};
static struct imx_clk_gpr *to_imx_clk_gpr(struct clk_hw *hw)
{
return container_of(hw, struct imx_clk_gpr, hw);
}
static u8 imx_clk_gpr_mux_get_parent(struct clk_hw *hw)
{
struct imx_clk_gpr *priv = to_imx_clk_gpr(hw);
unsigned int val;
int ret;
ret = regmap_read(priv->regmap, priv->reg, &val);
if (ret)
goto get_parent_err;
val &= priv->mask;
ret = clk_mux_val_to_index(hw, priv->mux_table, 0, val);
if (ret < 0)
goto get_parent_err;
return ret;
get_parent_err:
pr_err("%s: failed to get parent (%pe)\n",
clk_hw_get_name(hw), ERR_PTR(ret));
/* return some realistic non negative value. Potentially we could
* give index to some dummy error parent.
*/
return 0;
}
static int imx_clk_gpr_mux_set_parent(struct clk_hw *hw, u8 index)
{
struct imx_clk_gpr *priv = to_imx_clk_gpr(hw);
unsigned int val = clk_mux_index_to_val(priv->mux_table, 0, index);
return regmap_update_bits(priv->regmap, priv->reg, priv->mask, val);
}
static const struct clk_ops imx_clk_gpr_mux_ops = {
.get_parent = imx_clk_gpr_mux_get_parent,
.set_parent = imx_clk_gpr_mux_set_parent,
.determine_rate = __clk_mux_determine_rate,
};
struct clk_hw *imx_clk_gpr_mux(const char *name, const char *compatible,
u32 reg, const char **parent_names,
u8 num_parents, const u32 *mux_table, u32 mask)
{
struct clk_init_data init = { };
struct imx_clk_gpr *priv;
struct regmap *regmap;
struct clk_hw *hw;
int ret;
regmap = syscon_regmap_lookup_by_compatible(compatible);
if (IS_ERR(regmap)) {
pr_err("failed to find %s regmap\n", compatible);
return ERR_CAST(regmap);
}
priv = kzalloc_obj(*priv);
if (!priv)
return ERR_PTR(-ENOMEM);
init.name = name;
init.ops = &imx_clk_gpr_mux_ops;
init.parent_names = parent_names;
init.num_parents = num_parents;
init.flags = CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE;
priv->hw.init = &init;
priv->regmap = regmap;
priv->mux_table = mux_table;
priv->reg = reg;
priv->mask = mask;
hw = &priv->hw;
ret = clk_hw_register(NULL, &priv->hw);
if (ret) {
Annotation
- Immediate include surface: `linux/module.h`, `linux/clk-provider.h`, `linux/errno.h`, `linux/export.h`, `linux/io.h`, `linux/slab.h`, `linux/regmap.h`, `linux/mfd/syscon.h`.
- Detected declarations: `struct imx_clk_gpr`, `function imx_clk_gpr_mux_get_parent`, `function imx_clk_gpr_mux_set_parent`.
- 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.