Skip to content

Commit ace73b7

Browse files
committed
clk: spacemit: ccu_mix: add inverted enable gate clock
K3 SoC has the clock IP which support to write value 0 for enabling the clock, while write 1 for disabling it, thus the enable BIT is inverted. So, introduce a flag to support the inverted gate clock. Link: https://lore.kernel.org/r/20260108-k3-clk-v5-2-42a11b74ad58@gentoo.org Signed-off-by: Yixun Lan <dlan@gentoo.org>
1 parent efe897b commit ace73b7

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

drivers/clk/spacemit/ccu_mix.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,30 @@
1616
static void ccu_gate_disable(struct clk_hw *hw)
1717
{
1818
struct ccu_mix *mix = hw_to_ccu_mix(hw);
19+
struct ccu_gate_config *gate = &mix->gate;
20+
u32 val = gate->inverted ? gate->mask : 0;
1921

20-
ccu_update(&mix->common, ctrl, mix->gate.mask, 0);
22+
ccu_update(&mix->common, ctrl, gate->mask, val);
2123
}
2224

2325
static int ccu_gate_enable(struct clk_hw *hw)
2426
{
2527
struct ccu_mix *mix = hw_to_ccu_mix(hw);
2628
struct ccu_gate_config *gate = &mix->gate;
29+
u32 val = gate->inverted ? 0 : gate->mask;
2730

28-
ccu_update(&mix->common, ctrl, gate->mask, gate->mask);
29-
31+
ccu_update(&mix->common, ctrl, gate->mask, val);
3032
return 0;
3133
}
3234

3335
static int ccu_gate_is_enabled(struct clk_hw *hw)
3436
{
3537
struct ccu_mix *mix = hw_to_ccu_mix(hw);
3638
struct ccu_gate_config *gate = &mix->gate;
39+
u32 tmp = ccu_read(&mix->common, ctrl) & gate->mask;
40+
u32 val = gate->inverted ? 0 : gate->mask;
3741

38-
return (ccu_read(&mix->common, ctrl) & gate->mask) == gate->mask;
42+
return !!(tmp == val);
3943
}
4044

4145
static unsigned long ccu_factor_recalc_rate(struct clk_hw *hw,

drivers/clk/spacemit/ccu_mix.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
*
1717
* @mask: Mask to enable the gate. Some clocks may have more than one bit
1818
* set in this field.
19+
* @inverted: Enable bit is inverted, 1 - disable clock, 0 - enable clock
1920
*/
2021
struct ccu_gate_config {
2122
u32 mask;
23+
bool inverted;
2224
};
2325

2426
struct ccu_factor_config {
@@ -48,6 +50,7 @@ struct ccu_mix {
4850
#define CCU_FACTOR_INIT(_div, _mul) { .div = _div, .mul = _mul }
4951
#define CCU_MUX_INIT(_shift, _width) { .shift = _shift, .width = _width }
5052
#define CCU_DIV_INIT(_shift, _width) { .shift = _shift, .width = _width }
53+
#define CCU_GATE_FLAGS_INIT(_mask, _inverted) { .mask = _mask, .inverted = _inverted }
5154

5255
#define CCU_PARENT_HW(_parent) { .hw = &_parent.common.hw }
5356
#define CCU_PARENT_NAME(_name) { .fw_name = #_name }
@@ -101,6 +104,15 @@ static struct ccu_mix _name = { \
101104
} \
102105
}
103106

107+
#define CCU_GATE_FLAGS_DEFINE(_name, _parent, _reg_ctrl, _mask_gate, _inverted, _flags) \
108+
static struct ccu_mix _name = { \
109+
.gate = CCU_GATE_FLAGS_INIT(_mask_gate, _inverted), \
110+
.common = { \
111+
.reg_ctrl = _reg_ctrl, \
112+
CCU_MIX_INITHW(_name, _parent, spacemit_ccu_gate_ops, _flags), \
113+
} \
114+
}
115+
104116
#define CCU_FACTOR_GATE_FLAGS_DEFINE(_name, _parent, _reg_ctrl, _mask_gate, _div, \
105117
_mul, _flags) \
106118
static struct ccu_mix _name = { \

0 commit comments

Comments
 (0)