13 #include <linux/module.h>
14 #include <linux/slab.h>
17 #include <linux/string.h>
29 #define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)
44 static void clk_gate_endisable(
struct clk_hw *
hw,
int enable)
47 int set = gate->flags & CLK_GATE_SET_TO_DISABLE ? 1 : 0;
48 unsigned long flags = 0;
56 reg =
readl(gate->reg);
59 reg |=
BIT(gate->bit_idx);
61 reg &= ~
BIT(gate->bit_idx);
66 spin_unlock_irqrestore(gate->lock, flags);
69 static int clk_gate_enable(
struct clk_hw *
hw)
71 clk_gate_endisable(hw, 1);
76 static void clk_gate_disable(
struct clk_hw *
hw)
78 clk_gate_endisable(hw, 0);
81 static int clk_gate_is_enabled(
struct clk_hw *
hw)
86 reg =
readl(gate->reg);
89 if (gate->flags & CLK_GATE_SET_TO_DISABLE)
90 reg ^=
BIT(gate->bit_idx);
92 reg &=
BIT(gate->bit_idx);
98 .enable = clk_gate_enable,
99 .disable = clk_gate_disable,
100 .is_enabled = clk_gate_is_enabled,
116 const char *parent_name,
unsigned long flags,
120 struct clk_gate *gate;
122 struct clk_init_data init;
125 gate = kzalloc(
sizeof(
struct clk_gate),
GFP_KERNEL);
127 pr_err(
"%s: could not allocate gated clk\n", __func__);
133 init.flags = flags | CLK_IS_BASIC;
134 init.parent_names = (parent_name ? &parent_name:
NULL);
135 init.num_parents = (parent_name ? 1 : 0);
139 gate->bit_idx = bit_idx;
140 gate->flags = clk_gate_flags;
142 gate->hw.init = &
init;