1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __MACH_IMX_CLK_H
3 #define __MACH_IMX_CLK_H
5 #include <linux/spinlock.h>
6 #include <linux/clk-provider.h>
8 extern spinlock_t imx_ccm_lock;
10 void imx_check_clocks(struct clk *clks[], unsigned int count);
11 void imx_check_clk_hws(struct clk_hw *clks[], unsigned int count);
12 void imx_register_uart_clocks(struct clk ** const clks[]);
13 void imx_mmdc_mask_handshake(void __iomem *ccm_base, unsigned int chn);
14 void imx_unregister_clocks(struct clk *clks[], unsigned int count);
16 extern void imx_cscmr1_fixup(u32 *val);
27 enum imx_sccg_pll_type {
32 enum imx_pll14xx_type {
37 /* NOTE: Rate table should be kept sorted in descending order. */
38 struct imx_pll14xx_rate_table {
46 struct imx_pll14xx_clk {
47 enum imx_pll14xx_type type;
48 const struct imx_pll14xx_rate_table *rate_table;
53 #define imx_clk_cpu(name, parent_name, div, mux, pll, step) \
54 imx_clk_hw_cpu(name, parent_name, div, mux, pll, step)->clk
56 #define clk_register_gate2(dev, name, parent_name, flags, reg, bit_idx, \
57 cgr_val, clk_gate_flags, lock, share_count) \
58 clk_hw_register_gate2(dev, name, parent_name, flags, reg, bit_idx, \
59 cgr_val, clk_gate_flags, lock, share_count)->clk
61 #define imx_clk_pllv3(type, name, parent_name, base, div_mask) \
62 imx_clk_hw_pllv3(type, name, parent_name, base, div_mask)->clk
64 #define imx_clk_pfd(name, parent_name, reg, idx) \
65 imx_clk_hw_pfd(name, parent_name, reg, idx)->clk
67 #define imx_clk_gate_exclusive(name, parent, reg, shift, exclusive_mask) \
68 imx_clk_hw_gate_exclusive(name, parent, reg, shift, exclusive_mask)->clk
70 #define imx_clk_fixed_factor(name, parent, mult, div) \
71 imx_clk_hw_fixed_factor(name, parent, mult, div)->clk
73 #define imx_clk_divider2(name, parent, reg, shift, width) \
74 imx_clk_hw_divider2(name, parent, reg, shift, width)->clk
76 #define imx_clk_gate_dis(name, parent, reg, shift) \
77 imx_clk_hw_gate_dis(name, parent, reg, shift)->clk
79 #define imx_clk_gate2(name, parent, reg, shift) \
80 imx_clk_hw_gate2(name, parent, reg, shift)->clk
82 #define imx_clk_gate2_flags(name, parent, reg, shift, flags) \
83 imx_clk_hw_gate2_flags(name, parent, reg, shift, flags)->clk
85 #define imx_clk_gate2_shared2(name, parent, reg, shift, share_count) \
86 imx_clk_hw_gate2_shared2(name, parent, reg, shift, share_count)->clk
88 #define imx_clk_gate3(name, parent, reg, shift) \
89 imx_clk_hw_gate3(name, parent, reg, shift)->clk
91 #define imx_clk_gate4(name, parent, reg, shift) \
92 imx_clk_hw_gate4(name, parent, reg, shift)->clk
94 #define imx_clk_mux(name, reg, shift, width, parents, num_parents) \
95 imx_clk_hw_mux(name, reg, shift, width, parents, num_parents)->clk
97 struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
98 void __iomem *base, const struct imx_pll14xx_clk *pll_clk);
100 struct clk *imx_clk_pllv1(enum imx_pllv1_type type, const char *name,
101 const char *parent, void __iomem *base);
103 struct clk *imx_clk_pllv2(const char *name, const char *parent,
106 struct clk *imx_clk_frac_pll(const char *name, const char *parent_name,
109 struct clk *imx_clk_sccg_pll(const char *name,
110 const char * const *parent_names,
112 u8 parent, u8 bypass1, u8 bypass2,
114 unsigned long flags);
116 enum imx_pllv3_type {
129 struct clk_hw *imx_clk_hw_pllv3(enum imx_pllv3_type type, const char *name,
130 const char *parent_name, void __iomem *base, u32 div_mask);
132 #define PLL_1416X_RATE(_rate, _m, _p, _s) \
140 #define PLL_1443X_RATE(_rate, _m, _p, _s, _k) \
149 struct clk_hw *imx_clk_pllv4(const char *name, const char *parent_name,
152 struct clk_hw *clk_hw_register_gate2(struct device *dev, const char *name,
153 const char *parent_name, unsigned long flags,
154 void __iomem *reg, u8 bit_idx, u8 cgr_val,
155 u8 clk_gate_flags, spinlock_t *lock,
156 unsigned int *share_count);
158 struct clk * imx_obtain_fixed_clock(
159 const char *name, unsigned long rate);
161 struct clk_hw *imx_obtain_fixed_clock_hw(
162 const char *name, unsigned long rate);
164 struct clk_hw *imx_obtain_fixed_clk_hw(struct device_node *np,
167 struct clk_hw *imx_clk_hw_gate_exclusive(const char *name, const char *parent,
168 void __iomem *reg, u8 shift, u32 exclusive_mask);
170 struct clk_hw *imx_clk_hw_pfd(const char *name, const char *parent_name,
171 void __iomem *reg, u8 idx);
173 struct clk_hw *imx_clk_pfdv2(const char *name, const char *parent_name,
174 void __iomem *reg, u8 idx);
176 struct clk_hw *imx_clk_hw_busy_divider(const char *name, const char *parent_name,
177 void __iomem *reg, u8 shift, u8 width,
178 void __iomem *busy_reg, u8 busy_shift);
180 struct clk_hw *imx_clk_hw_busy_mux(const char *name, void __iomem *reg, u8 shift,
181 u8 width, void __iomem *busy_reg, u8 busy_shift,
182 const char * const *parent_names, int num_parents);
184 struct clk_hw *imx7ulp_clk_composite(const char *name,
185 const char * const *parent_names,
186 int num_parents, bool mux_present,
187 bool rate_present, bool gate_present,
190 struct clk_hw *imx_clk_hw_fixup_divider(const char *name, const char *parent,
191 void __iomem *reg, u8 shift, u8 width,
192 void (*fixup)(u32 *val));
194 struct clk_hw *imx_clk_hw_fixup_mux(const char *name, void __iomem *reg,
195 u8 shift, u8 width, const char * const *parents,
196 int num_parents, void (*fixup)(u32 *val));
198 static inline struct clk *imx_clk_fixed(const char *name, int rate)
200 return clk_register_fixed_rate(NULL, name, NULL, 0, rate);
203 static inline struct clk_hw *imx_clk_hw_fixed(const char *name, int rate)
205 return clk_hw_register_fixed_rate(NULL, name, NULL, 0, rate);
208 static inline struct clk_hw *imx_clk_hw_mux_ldb(const char *name, void __iomem *reg,
209 u8 shift, u8 width, const char * const *parents,
212 return clk_hw_register_mux(NULL, name, parents, num_parents,
213 CLK_SET_RATE_NO_REPARENT | CLK_SET_RATE_PARENT, reg,
214 shift, width, CLK_MUX_READ_ONLY, &imx_ccm_lock);
217 static inline struct clk_hw *imx_clk_hw_fixed_factor(const char *name,
218 const char *parent, unsigned int mult, unsigned int div)
220 return clk_hw_register_fixed_factor(NULL, name, parent,
221 CLK_SET_RATE_PARENT, mult, div);
224 static inline struct clk *imx_clk_divider(const char *name, const char *parent,
225 void __iomem *reg, u8 shift, u8 width)
227 return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
228 reg, shift, width, 0, &imx_ccm_lock);
231 static inline struct clk_hw *imx_clk_hw_divider(const char *name,
233 void __iomem *reg, u8 shift,
236 return clk_hw_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
237 reg, shift, width, 0, &imx_ccm_lock);
240 static inline struct clk *imx_clk_divider_flags(const char *name,
241 const char *parent, void __iomem *reg, u8 shift, u8 width,
244 return clk_register_divider(NULL, name, parent, flags,
245 reg, shift, width, 0, &imx_ccm_lock);
248 static inline struct clk_hw *imx_clk_hw_divider_flags(const char *name,
250 void __iomem *reg, u8 shift,
251 u8 width, unsigned long flags)
253 return clk_hw_register_divider(NULL, name, parent, flags,
254 reg, shift, width, 0, &imx_ccm_lock);
257 static inline struct clk_hw *imx_clk_hw_divider2(const char *name, const char *parent,
258 void __iomem *reg, u8 shift, u8 width)
260 return clk_hw_register_divider(NULL, name, parent,
261 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
262 reg, shift, width, 0, &imx_ccm_lock);
265 static inline struct clk *imx_clk_divider2_flags(const char *name,
266 const char *parent, void __iomem *reg, u8 shift, u8 width,
269 return clk_register_divider(NULL, name, parent,
270 flags | CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
271 reg, shift, width, 0, &imx_ccm_lock);
274 static inline struct clk *imx_clk_gate(const char *name, const char *parent,
275 void __iomem *reg, u8 shift)
277 return clk_register_gate(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
278 shift, 0, &imx_ccm_lock);
281 static inline struct clk_hw *imx_clk_hw_gate_flags(const char *name, const char *parent,
282 void __iomem *reg, u8 shift, unsigned long flags)
284 return clk_hw_register_gate(NULL, name, parent, flags | CLK_SET_RATE_PARENT, reg,
285 shift, 0, &imx_ccm_lock);
288 static inline struct clk_hw *imx_clk_hw_gate(const char *name, const char *parent,
289 void __iomem *reg, u8 shift)
291 return clk_hw_register_gate(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
292 shift, 0, &imx_ccm_lock);
295 static inline struct clk_hw *imx_clk_hw_gate_dis(const char *name, const char *parent,
296 void __iomem *reg, u8 shift)
298 return clk_hw_register_gate(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
299 shift, CLK_GATE_SET_TO_DISABLE, &imx_ccm_lock);
302 static inline struct clk_hw *imx_clk_hw_gate_dis_flags(const char *name, const char *parent,
303 void __iomem *reg, u8 shift, unsigned long flags)
305 return clk_hw_register_gate(NULL, name, parent, flags | CLK_SET_RATE_PARENT, reg,
306 shift, CLK_GATE_SET_TO_DISABLE, &imx_ccm_lock);
309 static inline struct clk_hw *imx_clk_hw_gate2(const char *name, const char *parent,
310 void __iomem *reg, u8 shift)
312 return clk_hw_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
313 shift, 0x3, 0, &imx_ccm_lock, NULL);
316 static inline struct clk_hw *imx_clk_hw_gate2_flags(const char *name, const char *parent,
317 void __iomem *reg, u8 shift, unsigned long flags)
319 return clk_hw_register_gate2(NULL, name, parent, flags | CLK_SET_RATE_PARENT, reg,
320 shift, 0x3, 0, &imx_ccm_lock, NULL);
323 static inline struct clk_hw *imx_clk_hw_gate2_shared(const char *name,
324 const char *parent, void __iomem *reg, u8 shift,
325 unsigned int *share_count)
327 return clk_hw_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
328 shift, 0x3, 0, &imx_ccm_lock, share_count);
331 static inline struct clk_hw *imx_clk_hw_gate2_shared2(const char *name,
332 const char *parent, void __iomem *reg, u8 shift,
333 unsigned int *share_count)
335 return clk_hw_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT |
336 CLK_OPS_PARENT_ENABLE, reg, shift, 0x3, 0,
337 &imx_ccm_lock, share_count);
340 static inline struct clk *imx_clk_gate2_cgr(const char *name,
341 const char *parent, void __iomem *reg, u8 shift, u8 cgr_val)
343 return clk_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
344 shift, cgr_val, 0, &imx_ccm_lock, NULL);
347 static inline struct clk_hw *imx_clk_hw_gate3(const char *name, const char *parent,
348 void __iomem *reg, u8 shift)
350 return clk_hw_register_gate(NULL, name, parent,
351 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
352 reg, shift, 0, &imx_ccm_lock);
355 static inline struct clk *imx_clk_gate3_flags(const char *name,
356 const char *parent, void __iomem *reg, u8 shift,
359 return clk_register_gate(NULL, name, parent,
360 flags | CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
361 reg, shift, 0, &imx_ccm_lock);
364 static inline struct clk_hw *imx_clk_hw_gate4(const char *name, const char *parent,
365 void __iomem *reg, u8 shift)
367 return clk_hw_register_gate2(NULL, name, parent,
368 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
369 reg, shift, 0x3, 0, &imx_ccm_lock, NULL);
372 static inline struct clk *imx_clk_gate4_flags(const char *name,
373 const char *parent, void __iomem *reg, u8 shift,
376 return clk_register_gate2(NULL, name, parent,
377 flags | CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
378 reg, shift, 0x3, 0, &imx_ccm_lock, NULL);
381 static inline struct clk_hw *imx_clk_hw_mux(const char *name, void __iomem *reg,
382 u8 shift, u8 width, const char * const *parents,
385 return clk_hw_register_mux(NULL, name, parents, num_parents,
386 CLK_SET_RATE_NO_REPARENT, reg, shift,
387 width, 0, &imx_ccm_lock);
390 static inline struct clk *imx_clk_mux2(const char *name, void __iomem *reg,
391 u8 shift, u8 width, const char * const *parents,
394 return clk_register_mux(NULL, name, parents, num_parents,
395 CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE,
396 reg, shift, width, 0, &imx_ccm_lock);
399 static inline struct clk_hw *imx_clk_hw_mux2(const char *name, void __iomem *reg,
401 const char * const *parents,
404 return clk_hw_register_mux(NULL, name, parents, num_parents,
405 CLK_SET_RATE_NO_REPARENT |
406 CLK_OPS_PARENT_ENABLE,
407 reg, shift, width, 0, &imx_ccm_lock);
410 static inline struct clk *imx_clk_mux_flags(const char *name,
411 void __iomem *reg, u8 shift, u8 width,
412 const char * const *parents, int num_parents,
415 return clk_register_mux(NULL, name, parents, num_parents,
416 flags | CLK_SET_RATE_NO_REPARENT, reg, shift, width, 0,
420 static inline struct clk *imx_clk_mux2_flags(const char *name,
421 void __iomem *reg, u8 shift, u8 width,
422 const char * const *parents,
423 int num_parents, unsigned long flags)
425 return clk_register_mux(NULL, name, parents, num_parents,
426 flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE,
427 reg, shift, width, 0, &imx_ccm_lock);
430 static inline struct clk_hw *imx_clk_hw_mux_flags(const char *name,
431 void __iomem *reg, u8 shift,
433 const char * const *parents,
437 return clk_hw_register_mux(NULL, name, parents, num_parents,
438 flags | CLK_SET_RATE_NO_REPARENT,
439 reg, shift, width, 0, &imx_ccm_lock);
442 struct clk_hw *imx_clk_hw_cpu(const char *name, const char *parent_name,
443 struct clk *div, struct clk *mux, struct clk *pll,
446 struct clk *imx8m_clk_composite_flags(const char *name,
447 const char * const *parent_names,
448 int num_parents, void __iomem *reg,
449 unsigned long flags);
451 #define __imx8m_clk_composite(name, parent_names, reg, flags) \
452 imx8m_clk_composite_flags(name, parent_names, \
453 ARRAY_SIZE(parent_names), reg, \
454 flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE)
456 #define imx8m_clk_composite(name, parent_names, reg) \
457 __imx8m_clk_composite(name, parent_names, reg, 0)
459 #define imx8m_clk_composite_critical(name, parent_names, reg) \
460 __imx8m_clk_composite(name, parent_names, reg, CLK_IS_CRITICAL)
462 struct clk_hw *imx_clk_divider_gate(const char *name, const char *parent_name,
463 unsigned long flags, void __iomem *reg, u8 shift, u8 width,
464 u8 clk_divider_flags, const struct clk_div_table *table,