hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/clk/clk-gate.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0
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 */
....@@ -30,6 +27,22 @@
3027 * parent - fixed parent. No clk_set_parent support
3128 */
3229
30
+static inline u32 clk_gate_readl(struct clk_gate *gate)
31
+{
32
+ if (gate->flags & CLK_GATE_BIG_ENDIAN)
33
+ return ioread32be(gate->reg);
34
+
35
+ return readl(gate->reg);
36
+}
37
+
38
+static inline void clk_gate_writel(struct clk_gate *gate, u32 val)
39
+{
40
+ if (gate->flags & CLK_GATE_BIG_ENDIAN)
41
+ iowrite32be(val, gate->reg);
42
+ else
43
+ writel(val, gate->reg);
44
+}
45
+
3346 /*
3447 * It works on following logic:
3548 *
....@@ -47,7 +60,7 @@
4760 {
4861 struct clk_gate *gate = to_clk_gate(hw);
4962 int set = gate->flags & CLK_GATE_SET_TO_DISABLE ? 1 : 0;
50
- unsigned long uninitialized_var(flags);
63
+ unsigned long flags;
5164 u32 reg;
5265
5366 if (clk_always_on && !enable)
....@@ -65,7 +78,7 @@
6578 if (set)
6679 reg |= BIT(gate->bit_idx);
6780 } else {
68
- reg = clk_readl(gate->reg);
81
+ reg = clk_gate_readl(gate);
6982
7083 if (set)
7184 reg |= BIT(gate->bit_idx);
....@@ -73,7 +86,7 @@
7386 reg &= ~BIT(gate->bit_idx);
7487 }
7588
76
- clk_writel(reg, gate->reg);
89
+ clk_gate_writel(gate, reg);
7790
7891 if (gate->lock)
7992 spin_unlock_irqrestore(gate->lock, flags);
....@@ -98,7 +111,7 @@
98111 u32 reg;
99112 struct clk_gate *gate = to_clk_gate(hw);
100113
101
- reg = clk_readl(gate->reg);
114
+ reg = clk_gate_readl(gate);
102115
103116 /* if a set bit disables this clk, flip it before masking */
104117 if (gate->flags & CLK_GATE_SET_TO_DISABLE)
....@@ -117,26 +130,18 @@
117130 };
118131 EXPORT_SYMBOL_GPL(clk_gate_ops);
119132
120
-/**
121
- * clk_hw_register_gate - register a gate clock with the clock framework
122
- * @dev: device that is registering this clock
123
- * @name: name of this clock
124
- * @parent_name: name of this clock's parent
125
- * @flags: framework-specific flags for this clock
126
- * @reg: register address to control gating of this clock
127
- * @bit_idx: which bit in the register controls gating of this clock
128
- * @clk_gate_flags: gate-specific flags for this clock
129
- * @lock: shared register lock for this clock
130
- */
131
-struct clk_hw *clk_hw_register_gate(struct device *dev, const char *name,
132
- const char *parent_name, unsigned long flags,
133
+struct clk_hw *__clk_hw_register_gate(struct device *dev,
134
+ struct device_node *np, const char *name,
135
+ const char *parent_name, const struct clk_hw *parent_hw,
136
+ const struct clk_parent_data *parent_data,
137
+ unsigned long flags,
133138 void __iomem *reg, u8 bit_idx,
134139 u8 clk_gate_flags, spinlock_t *lock)
135140 {
136141 struct clk_gate *gate;
137142 struct clk_hw *hw;
138143 struct clk_init_data init = {};
139
- int ret;
144
+ int ret = -EINVAL;
140145
141146 if (clk_gate_flags & CLK_GATE_HIWORD_MASK) {
142147 if (bit_idx > 15) {
....@@ -152,9 +157,14 @@
152157
153158 init.name = name;
154159 init.ops = &clk_gate_ops;
155
- init.flags = flags | CLK_IS_BASIC;
160
+ init.flags = flags;
156161 init.parent_names = parent_name ? &parent_name : NULL;
157
- init.num_parents = parent_name ? 1 : 0;
162
+ init.parent_hws = parent_hw ? &parent_hw : NULL;
163
+ init.parent_data = parent_data;
164
+ if (parent_name || parent_hw || parent_data)
165
+ init.num_parents = 1;
166
+ else
167
+ init.num_parents = 0;
158168
159169 /* struct clk_gate assignments */
160170 gate->reg = reg;
....@@ -164,15 +174,19 @@
164174 gate->hw.init = &init;
165175
166176 hw = &gate->hw;
167
- ret = clk_hw_register(dev, hw);
177
+ if (dev || !np)
178
+ ret = clk_hw_register(dev, hw);
179
+ else if (np)
180
+ ret = of_clk_hw_register(np, hw);
168181 if (ret) {
169182 kfree(gate);
170183 hw = ERR_PTR(ret);
171184 }
172185
173186 return hw;
187
+
174188 }
175
-EXPORT_SYMBOL_GPL(clk_hw_register_gate);
189
+EXPORT_SYMBOL_GPL(__clk_hw_register_gate);
176190
177191 struct clk *clk_register_gate(struct device *dev, const char *name,
178192 const char *parent_name, unsigned long flags,