drivers/clk/clk-gpio.c
Source file repositories/reference/linux-study-clean/drivers/clk/clk-gpio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/clk-gpio.c- Extension
.c- Size
- 10952 bytes
- Lines
- 427
- 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-provider.hlinux/export.hlinux/slab.hlinux/gpio/consumer.hlinux/err.hlinux/device.hlinux/of.hlinux/platform_device.hlinux/regulator/consumer.h
Detected Declarations
struct clk_gpiostruct clk_gated_fixedfunction clk_gpio_gate_enablefunction clk_gpio_gate_disablefunction clk_gpio_gate_is_enabledfunction clk_sleeping_gpio_gate_preparefunction clk_sleeping_gpio_gate_unpreparefunction clk_sleeping_gpio_gate_is_preparedfunction clk_gpio_mux_get_parentfunction clk_gpio_mux_set_parentfunction gpio_clk_driver_probefunction clk_gated_fixed_recalc_ratefunction clk_gated_fixed_preparefunction clk_gated_fixed_unpreparefunction clk_gated_fixed_is_preparedfunction clk_sleeping_gated_fixed_preparefunction clk_sleeping_gated_fixed_unpreparefunction clk_gated_fixed_probe
Annotated Snippet
struct clk_gpio {
struct clk_hw hw;
struct gpio_desc *gpiod;
};
#define to_clk_gpio(_hw) container_of(_hw, struct clk_gpio, hw)
static int clk_gpio_gate_enable(struct clk_hw *hw)
{
struct clk_gpio *clk = to_clk_gpio(hw);
gpiod_set_value(clk->gpiod, 1);
return 0;
}
static void clk_gpio_gate_disable(struct clk_hw *hw)
{
struct clk_gpio *clk = to_clk_gpio(hw);
gpiod_set_value(clk->gpiod, 0);
}
static int clk_gpio_gate_is_enabled(struct clk_hw *hw)
{
struct clk_gpio *clk = to_clk_gpio(hw);
return gpiod_get_value(clk->gpiod);
}
static const struct clk_ops clk_gpio_gate_ops = {
.enable = clk_gpio_gate_enable,
.disable = clk_gpio_gate_disable,
.is_enabled = clk_gpio_gate_is_enabled,
};
static int clk_sleeping_gpio_gate_prepare(struct clk_hw *hw)
{
struct clk_gpio *clk = to_clk_gpio(hw);
gpiod_set_value_cansleep(clk->gpiod, 1);
return 0;
}
static void clk_sleeping_gpio_gate_unprepare(struct clk_hw *hw)
{
struct clk_gpio *clk = to_clk_gpio(hw);
gpiod_set_value_cansleep(clk->gpiod, 0);
}
static int clk_sleeping_gpio_gate_is_prepared(struct clk_hw *hw)
{
struct clk_gpio *clk = to_clk_gpio(hw);
return gpiod_get_value_cansleep(clk->gpiod);
}
static const struct clk_ops clk_sleeping_gpio_gate_ops = {
.prepare = clk_sleeping_gpio_gate_prepare,
.unprepare = clk_sleeping_gpio_gate_unprepare,
.is_prepared = clk_sleeping_gpio_gate_is_prepared,
};
/**
* DOC: basic clock multiplexer which can be controlled with a gpio output
* Traits of this clock:
* prepare - clk_prepare only ensures that parents are prepared
* rate - rate is only affected by parent switching. No clk_set_rate support
* parent - parent is adjustable through clk_set_parent
*/
static u8 clk_gpio_mux_get_parent(struct clk_hw *hw)
{
struct clk_gpio *clk = to_clk_gpio(hw);
return gpiod_get_value_cansleep(clk->gpiod);
}
static int clk_gpio_mux_set_parent(struct clk_hw *hw, u8 index)
{
struct clk_gpio *clk = to_clk_gpio(hw);
gpiod_set_value_cansleep(clk->gpiod, index);
return 0;
}
static const struct clk_ops clk_gpio_mux_ops = {
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/export.h`, `linux/slab.h`, `linux/gpio/consumer.h`, `linux/err.h`, `linux/device.h`, `linux/of.h`, `linux/platform_device.h`.
- Detected declarations: `struct clk_gpio`, `struct clk_gated_fixed`, `function clk_gpio_gate_enable`, `function clk_gpio_gate_disable`, `function clk_gpio_gate_is_enabled`, `function clk_sleeping_gpio_gate_prepare`, `function clk_sleeping_gpio_gate_unprepare`, `function clk_sleeping_gpio_gate_is_prepared`, `function clk_gpio_mux_get_parent`, `function clk_gpio_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.