2 * Copyright (C) 2016 Maxime Ripard
3 * Maxime Ripard <maxime.ripard@free-electrons.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
11 #include <linux/clk-provider.h>
15 void ccu_gate_helper_disable(struct ccu_common
*common
, u32 gate
)
23 spin_lock_irqsave(common
->lock
, flags
);
25 reg
= readl(common
->base
+ common
->reg
);
26 writel(reg
& ~gate
, common
->base
+ common
->reg
);
28 spin_unlock_irqrestore(common
->lock
, flags
);
31 static void ccu_gate_disable(struct clk_hw
*hw
)
33 struct ccu_gate
*cg
= hw_to_ccu_gate(hw
);
35 return ccu_gate_helper_disable(&cg
->common
, cg
->enable
);
38 int ccu_gate_helper_enable(struct ccu_common
*common
, u32 gate
)
46 spin_lock_irqsave(common
->lock
, flags
);
48 reg
= readl(common
->base
+ common
->reg
);
49 writel(reg
| gate
, common
->base
+ common
->reg
);
51 spin_unlock_irqrestore(common
->lock
, flags
);
56 static int ccu_gate_enable(struct clk_hw
*hw
)
58 struct ccu_gate
*cg
= hw_to_ccu_gate(hw
);
60 return ccu_gate_helper_enable(&cg
->common
, cg
->enable
);
63 int ccu_gate_helper_is_enabled(struct ccu_common
*common
, u32 gate
)
68 return readl(common
->base
+ common
->reg
) & gate
;
71 static int ccu_gate_is_enabled(struct clk_hw
*hw
)
73 struct ccu_gate
*cg
= hw_to_ccu_gate(hw
);
75 return ccu_gate_helper_is_enabled(&cg
->common
, cg
->enable
);
78 const struct clk_ops ccu_gate_ops
= {
79 .disable
= ccu_gate_disable
,
80 .enable
= ccu_gate_enable
,
81 .is_enabled
= ccu_gate_is_enabled
,