Skip to content

Commit 1e54afe

Browse files
abelvesaShawn Guo
authored andcommitted
clk: imx: gate2: Allow single bit gating clock
Audiomix on i.MX8MP registers two gates that share the same enable count but use the same bit to control the gate instead of two bits. By adding the flag IMX_CLK_GATE2_SINGLE_BIT we allow the gate2 to use the generic gate ops for enable, disable and is_enabled. For the disable_unused, nothing happens if this flag is specified. Signed-off-by: Abel Vesa <[email protected]> Reviewed-by: Stephen Boyd <[email protected]> Signed-off-by: Shawn Guo <[email protected]>
1 parent 9558b51 commit 1e54afe

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

drivers/clk/imx/clk-gate2.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,26 @@ static int clk_gate2_enable(struct clk_hw *hw)
4141
struct clk_gate2 *gate = to_clk_gate2(hw);
4242
u32 reg;
4343
unsigned long flags;
44+
int ret = 0;
4445

4546
spin_lock_irqsave(gate->lock, flags);
4647

4748
if (gate->share_count && (*gate->share_count)++ > 0)
4849
goto out;
4950

50-
reg = readl(gate->reg);
51-
reg &= ~(3 << gate->bit_idx);
52-
reg |= gate->cgr_val << gate->bit_idx;
53-
writel(reg, gate->reg);
51+
if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT) {
52+
ret = clk_gate_ops.enable(hw);
53+
} else {
54+
reg = readl(gate->reg);
55+
reg &= ~(3 << gate->bit_idx);
56+
reg |= gate->cgr_val << gate->bit_idx;
57+
writel(reg, gate->reg);
58+
}
5459

5560
out:
5661
spin_unlock_irqrestore(gate->lock, flags);
5762

58-
return 0;
63+
return ret;
5964
}
6065

6166
static void clk_gate2_disable(struct clk_hw *hw)
@@ -73,9 +78,13 @@ static void clk_gate2_disable(struct clk_hw *hw)
7378
goto out;
7479
}
7580

76-
reg = readl(gate->reg);
77-
reg &= ~(3 << gate->bit_idx);
78-
writel(reg, gate->reg);
81+
if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT) {
82+
clk_gate_ops.disable(hw);
83+
} else {
84+
reg = readl(gate->reg);
85+
reg &= ~(3 << gate->bit_idx);
86+
writel(reg, gate->reg);
87+
}
7988

8089
out:
8190
spin_unlock_irqrestore(gate->lock, flags);
@@ -95,6 +104,9 @@ static int clk_gate2_is_enabled(struct clk_hw *hw)
95104
{
96105
struct clk_gate2 *gate = to_clk_gate2(hw);
97106

107+
if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT)
108+
return clk_gate_ops.is_enabled(hw);
109+
98110
return clk_gate2_reg_is_enabled(gate->reg, gate->bit_idx);
99111
}
100112

@@ -104,6 +116,9 @@ static void clk_gate2_disable_unused(struct clk_hw *hw)
104116
unsigned long flags;
105117
u32 reg;
106118

119+
if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT)
120+
return;
121+
107122
spin_lock_irqsave(gate->lock, flags);
108123

109124
if (!gate->share_count || *gate->share_count == 0) {

drivers/clk/imx/clk.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <linux/spinlock.h>
66
#include <linux/clk-provider.h>
77

8+
#define IMX_CLK_GATE2_SINGLE_BIT 1
9+
810
extern spinlock_t imx_ccm_lock;
911

1012
void imx_check_clocks(struct clk *clks[], unsigned int count);
@@ -355,6 +357,17 @@ static inline struct clk_hw *imx_clk_hw_gate2_shared2(const char *name,
355357
&imx_ccm_lock, share_count);
356358
}
357359

360+
static inline struct clk_hw *imx_dev_clk_hw_gate_shared(struct device *dev,
361+
const char *name, const char *parent,
362+
void __iomem *reg, u8 shift,
363+
unsigned int *share_count)
364+
{
365+
return clk_hw_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT |
366+
CLK_OPS_PARENT_ENABLE, reg, shift, 0x3,
367+
IMX_CLK_GATE2_SINGLE_BIT,
368+
&imx_ccm_lock, share_count);
369+
}
370+
358371
static inline struct clk *imx_clk_gate2_cgr(const char *name,
359372
const char *parent, void __iomem *reg, u8 shift, u8 cgr_val)
360373
{

0 commit comments

Comments
 (0)