Skip to contentSkip to conversation

clk: Add option to restrict clk-gate2 to one bit toggle

PATCH New Sean Anderson 1 participant 1 message Dec 25, 2019 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 clk: Add option to restrict clk-gate2 to one bit toggle

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.

---
 drivers/clk/clk-gate2.c      | 13 ++++++++++---
 include/linux/clk-provider.h |  2 ++
 2 files changed, 12 insertions(+), 3 deletions(-)
drivers/clk/clk-gate2.c +10 -3
index cfe21e5496..565d9e49ca 100644
@@ -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;
include/linux/clk-provider.h +2 -0
index f510291018..c904586e2c 100644
@@ -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;
Signature · 1 line
2.24.1