1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2019 DENX Software Engineering
4 * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
6 #ifndef __MACH_IMX_CLK_H
7 #define __MACH_IMX_CLK_H
9 #include <linux/clk-provider.h>
23 enum imx_pll14xx_type {
28 /* NOTE: Rate table should be kept sorted in descending order. */
29 struct imx_pll14xx_rate_table {
37 struct imx_pll14xx_clk {
38 enum imx_pll14xx_type type;
39 const struct imx_pll14xx_rate_table *rate_table;
44 struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
46 const struct imx_pll14xx_clk *pll_clk);
48 struct clk *clk_register_gate2(struct device *dev, const char *name,
49 const char *parent_name, unsigned long flags,
50 void __iomem *reg, u8 bit_idx, u8 cgr_val,
53 struct clk *imx_clk_pllv3(enum imx_pllv3_type type, const char *name,
54 const char *parent_name, void __iomem *base,
57 static inline struct clk *imx_clk_gate2(const char *name, const char *parent,
58 void __iomem *reg, u8 shift)
60 return clk_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
64 static inline struct clk *imx_clk_gate4(const char *name, const char *parent,
65 void __iomem *reg, u8 shift)
67 return clk_register_gate2(NULL, name, parent,
68 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
72 static inline struct clk *imx_clk_gate4_flags(const char *name,
73 const char *parent, void __iomem *reg, u8 shift,
76 return clk_register_gate2(NULL, name, parent,
77 flags | CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
81 static inline struct clk *imx_clk_fixed_factor(const char *name,
82 const char *parent, unsigned int mult, unsigned int div)
84 return clk_register_fixed_factor(NULL, name, parent,
85 CLK_SET_RATE_PARENT, mult, div);
88 static inline struct clk *imx_clk_divider(const char *name, const char *parent,
89 void __iomem *reg, u8 shift, u8 width)
91 return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
92 reg, shift, width, 0);
95 static inline struct clk *
96 imx_clk_busy_divider(const char *name, const char *parent, void __iomem *reg,
97 u8 shift, u8 width, void __iomem *busy_reg, u8 busy_shift)
99 return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
100 reg, shift, width, 0);
103 static inline struct clk *imx_clk_divider2(const char *name, const char *parent,
104 void __iomem *reg, u8 shift, u8 width)
106 return clk_register_divider(NULL, name, parent,
107 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
108 reg, shift, width, 0);
111 struct clk *imx_clk_pfd(const char *name, const char *parent_name,
112 void __iomem *reg, u8 idx);
114 struct clk *imx_clk_fixup_mux(const char *name, void __iomem *reg,
115 u8 shift, u8 width, const char * const *parents,
116 int num_parents, void (*fixup)(u32 *val));
118 static inline struct clk *imx_clk_mux_flags(const char *name,
119 void __iomem *reg, u8 shift, u8 width,
120 const char * const *parents, int num_parents,
123 return clk_register_mux(NULL, name, parents, num_parents,
124 flags | CLK_SET_RATE_NO_REPARENT, reg, shift,
128 static inline struct clk *imx_clk_mux2_flags(const char *name,
129 void __iomem *reg, u8 shift, u8 width,
130 const char * const *parents,
131 int num_parents, unsigned long flags)
133 return clk_register_mux(NULL, name, parents, num_parents,
134 flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE,
135 reg, shift, width, 0);
138 static inline struct clk *imx_clk_mux(const char *name, void __iomem *reg,
139 u8 shift, u8 width, const char * const *parents,
142 return clk_register_mux(NULL, name, parents, num_parents,
143 CLK_SET_RATE_NO_REPARENT, reg, shift,
147 static inline struct clk *
148 imx_clk_busy_mux(const char *name, void __iomem *reg, u8 shift, u8 width,
149 void __iomem *busy_reg, u8 busy_shift,
150 const char * const *parents, int num_parents)
152 return clk_register_mux(NULL, name, parents, num_parents,
153 CLK_SET_RATE_NO_REPARENT, reg, shift,
157 static inline struct clk *imx_clk_mux2(const char *name, void __iomem *reg,
158 u8 shift, u8 width, const char * const *parents,
161 return clk_register_mux(NULL, name, parents, num_parents,
162 CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE,
163 reg, shift, width, 0);
166 static inline struct clk *imx_clk_gate(const char *name, const char *parent,
167 void __iomem *reg, u8 shift)
169 return clk_register_gate(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
173 static inline struct clk *imx_clk_gate_flags(const char *name, const char *parent,
174 void __iomem *reg, u8 shift, unsigned long flags)
176 return clk_register_gate(NULL, name, parent, flags | CLK_SET_RATE_PARENT, reg,
180 static inline struct clk *imx_clk_gate3(const char *name, const char *parent,
181 void __iomem *reg, u8 shift)
183 return clk_register_gate(NULL, name, parent,
184 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
185 reg, shift, 0, NULL);
188 struct clk *imx8m_clk_composite_flags(const char *name,
189 const char * const *parent_names,
190 int num_parents, void __iomem *reg, unsigned long flags);
192 #define __imx8m_clk_composite(name, parent_names, reg, flags) \
193 imx8m_clk_composite_flags(name, parent_names, \
194 ARRAY_SIZE(parent_names), reg, \
195 flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE)
197 #define imx8m_clk_composite(name, parent_names, reg) \
198 __imx8m_clk_composite(name, parent_names, reg, 0)
200 #define imx8m_clk_composite_critical(name, parent_names, reg) \
201 __imx8m_clk_composite(name, parent_names, reg, CLK_IS_CRITICAL)
203 #endif /* __MACH_IMX_CLK_H */