[2/2] clk: Add option to restrict clk-gate2 to one bit toggle
diff mbox series

Message ID 444d2799-3cf6-ce93-4f5e-b144fed15fca@gmail.com
State Changes Requested
Delegated to: Lukasz Majewski
Headers show
Series
  • clk: Generalize clock_gate2 for use outside of imx
Related show

Commit Message

Sean Anderson Dec. 25, 2019, 5:17 a.m. UTC
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 <seanga2@gmail.com>
---
 drivers/clk/clk-gate2.c      | 13 ++++++++++---
 include/linux/clk-provider.h |  2 ++
 2 files changed, 12 insertions(+), 3 deletions(-)

Patch
diff mbox series

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;