forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/clk/imx/clk-gate2.c
....@@ -1,15 +1,13 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
34 * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
85 *
96 * Gated clock implementation
107 */
118
129 #include <linux/clk-provider.h>
10
+#include <linux/export.h>
1311 #include <linux/module.h>
1412 #include <linux/slab.h>
1513 #include <linux/io.h>
....@@ -18,7 +16,7 @@
1816 #include "clk.h"
1917
2018 /**
21
- * DOC: basic gatable clock which can gate and ungate it's ouput
19
+ * DOC: basic gateable clock which can gate and ungate its output
2220 *
2321 * Traits of this clock:
2422 * prepare - clk_(un)prepare only ensures parent is (un)prepared
....@@ -43,29 +41,34 @@
4341 {
4442 struct clk_gate2 *gate = to_clk_gate2(hw);
4543 u32 reg;
46
- unsigned long flags = 0;
44
+ unsigned long flags;
45
+ int ret = 0;
4746
4847 spin_lock_irqsave(gate->lock, flags);
4948
5049 if (gate->share_count && (*gate->share_count)++ > 0)
5150 goto out;
5251
53
- reg = readl(gate->reg);
54
- reg &= ~(3 << gate->bit_idx);
55
- reg |= gate->cgr_val << gate->bit_idx;
56
- writel(reg, gate->reg);
52
+ if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT) {
53
+ ret = clk_gate_ops.enable(hw);
54
+ } else {
55
+ reg = readl(gate->reg);
56
+ reg &= ~(3 << gate->bit_idx);
57
+ reg |= gate->cgr_val << gate->bit_idx;
58
+ writel(reg, gate->reg);
59
+ }
5760
5861 out:
5962 spin_unlock_irqrestore(gate->lock, flags);
6063
61
- return 0;
64
+ return ret;
6265 }
6366
6467 static void clk_gate2_disable(struct clk_hw *hw)
6568 {
6669 struct clk_gate2 *gate = to_clk_gate2(hw);
6770 u32 reg;
68
- unsigned long flags = 0;
71
+ unsigned long flags;
6972
7073 spin_lock_irqsave(gate->lock, flags);
7174
....@@ -76,9 +79,13 @@
7679 goto out;
7780 }
7881
79
- reg = readl(gate->reg);
80
- reg &= ~(3 << gate->bit_idx);
81
- writel(reg, gate->reg);
82
+ if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT) {
83
+ clk_gate_ops.disable(hw);
84
+ } else {
85
+ reg = readl(gate->reg);
86
+ reg &= ~(3 << gate->bit_idx);
87
+ writel(reg, gate->reg);
88
+ }
8289
8390 out:
8491 spin_unlock_irqrestore(gate->lock, flags);
....@@ -98,14 +105,20 @@
98105 {
99106 struct clk_gate2 *gate = to_clk_gate2(hw);
100107
108
+ if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT)
109
+ return clk_gate_ops.is_enabled(hw);
110
+
101111 return clk_gate2_reg_is_enabled(gate->reg, gate->bit_idx);
102112 }
103113
104114 static void clk_gate2_disable_unused(struct clk_hw *hw)
105115 {
106116 struct clk_gate2 *gate = to_clk_gate2(hw);
107
- unsigned long flags = 0;
117
+ unsigned long flags;
108118 u32 reg;
119
+
120
+ if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT)
121
+ return;
109122
110123 spin_lock_irqsave(gate->lock, flags);
111124
....@@ -125,15 +138,16 @@
125138 .is_enabled = clk_gate2_is_enabled,
126139 };
127140
128
-struct clk *clk_register_gate2(struct device *dev, const char *name,
141
+struct clk_hw *clk_hw_register_gate2(struct device *dev, const char *name,
129142 const char *parent_name, unsigned long flags,
130143 void __iomem *reg, u8 bit_idx, u8 cgr_val,
131144 u8 clk_gate2_flags, spinlock_t *lock,
132145 unsigned int *share_count)
133146 {
134147 struct clk_gate2 *gate;
135
- struct clk *clk;
136
- struct clk_init_data init = {};
148
+ struct clk_hw *hw;
149
+ struct clk_init_data init;
150
+ int ret;
137151
138152 gate = kzalloc(sizeof(struct clk_gate2), GFP_KERNEL);
139153 if (!gate)
....@@ -154,10 +168,14 @@
154168 init.num_parents = parent_name ? 1 : 0;
155169
156170 gate->hw.init = &init;
171
+ hw = &gate->hw;
157172
158
- clk = clk_register(dev, &gate->hw);
159
- if (IS_ERR(clk))
173
+ ret = clk_hw_register(dev, hw);
174
+ if (ret) {
160175 kfree(gate);
176
+ return ERR_PTR(ret);
177
+ }
161178
162
- return clk;
179
+ return hw;
163180 }
181
+EXPORT_SYMBOL_GPL(clk_hw_register_gate2);