Currently clk-gate2 only works on clocks with a 2-bit enable/disable state. This
patch adds an option to work with clocks with a 1-bit enable.

Signed-off-by: Sean Anderson <[email protected]>
---
 drivers/clk/clk-gate2.c      | 13 ++++++++++---
 include/linux/clk-provider.h |  2 ++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/clk-gate2.c b/drivers/clk/clk-gate2.c
index cfe21e5496..565d9e49ca 100644
--- a/drivers/clk/clk-gate2.c
+++ b/drivers/clk/clk-gate2.c
@@ -29,8 +29,12 @@ static int clk_gate2_enable(struct clk *clk)
        u32 reg;

        reg = readl(gate->reg);
-       reg &= ~(3 << gate->bit_idx);
-       reg |= gate->cgr_val << gate->bit_idx;
+       if (gate->flags & CLK_GATE2_SINGLE_BIT) {
+               reg |= BIT(gate->bit_idx);
+       } else {
+               reg &= ~(3 << gate->bit_idx);
+               reg |= gate->cgr_val << gate->bit_idx;
+       }
        writel(reg, gate->reg);

        return 0;
@@ -42,7 +46,10 @@ static int clk_gate2_disable(struct clk *clk)
        u32 reg;

        reg = readl(gate->reg);
-       reg &= ~(3 << gate->bit_idx);
+       if (gate->flags & CLK_GATE2_SINGLE_BIT)
+               reg &= ~BIT(gate->bit_idx);
+       else
+               reg &= ~(3 << gate->bit_idx);
        writel(reg, gate->reg);

        return 0;
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index f510291018..c904586e2c 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -155,6 +155,8 @@ struct clk_composite {

 #define to_clk_composite(_clk) container_of(_clk, struct clk_composite, clk)

+#define CLK_GATE2_SINGLE_BIT BIT(0)
+
 struct clk_gate2 {
        struct clk clk;
        void __iomem    *reg;
-- 
2.24.1

Reply via email to