blob: 11f5dca1175b7d88d3e7198ec0e9b5355103d3c3 [file] [log] [blame]
Lukasz Majewski4de44bb2019-06-24 15:50:45 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2019 DENX Software Engineering
4 * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
5 */
6#ifndef __MACH_IMX_CLK_H
7#define __MACH_IMX_CLK_H
8
9#include <linux/clk-provider.h>
10
11enum imx_pllv3_type {
12 IMX_PLLV3_GENERIC,
Jesse Taube4303cd12022-07-26 01:43:42 -040013 IMX_PLLV3_GENERICV2,
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020014 IMX_PLLV3_SYS,
15 IMX_PLLV3_USB,
16 IMX_PLLV3_USB_VF610,
17 IMX_PLLV3_AV,
18 IMX_PLLV3_ENET,
19 IMX_PLLV3_ENET_IMX7,
20 IMX_PLLV3_SYS_VF610,
21 IMX_PLLV3_DDR_IMX7,
22};
23
Peng Fan134cf092019-08-19 07:53:58 +000024enum imx_pll14xx_type {
25 PLL_1416X,
26 PLL_1443X,
27};
28
29/* NOTE: Rate table should be kept sorted in descending order. */
30struct imx_pll14xx_rate_table {
31 unsigned int rate;
32 unsigned int pdiv;
33 unsigned int mdiv;
34 unsigned int sdiv;
35 unsigned int kdiv;
36};
37
38struct imx_pll14xx_clk {
39 enum imx_pll14xx_type type;
40 const struct imx_pll14xx_rate_table *rate_table;
41 int rate_count;
42 int flags;
43};
44
Angus Ainslie73d75ec2022-03-29 07:02:40 -070045extern struct imx_pll14xx_clk imx_1416x_pll;
46extern struct imx_pll14xx_clk imx_1443x_pll;
47extern struct imx_pll14xx_clk imx_1443x_dram_pll;
48
Peng Fan134cf092019-08-19 07:53:58 +000049struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
50 void __iomem *base,
51 const struct imx_pll14xx_clk *pll_clk);
52
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020053struct clk *clk_register_gate2(struct device *dev, const char *name,
54 const char *parent_name, unsigned long flags,
55 void __iomem *reg, u8 bit_idx, u8 cgr_val,
Michael Trimarchi29c56cf2022-08-30 16:41:38 +020056 u8 clk_gate_flags, unsigned int *share_count);
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020057
58struct clk *imx_clk_pllv3(enum imx_pllv3_type type, const char *name,
59 const char *parent_name, void __iomem *base,
60 u32 div_mask);
61
62static inline struct clk *imx_clk_gate2(const char *name, const char *parent,
63 void __iomem *reg, u8 shift)
64{
65 return clk_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
Michael Trimarchi29c56cf2022-08-30 16:41:38 +020066 shift, 0x3, 0, NULL);
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020067}
68
Michael Trimarchi29c56cf2022-08-30 16:41:38 +020069static inline struct clk *imx_clk_gate2_shared(const char *name,
70 const char *parent,
71 void __iomem *reg, u8 shift,
72 unsigned int *share_count)
73{
74 return clk_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
75 shift, 0x3, 0, share_count);
76}
77
78static inline struct clk *imx_clk_gate2_shared2(const char *name,
79 const char *parent,
80 void __iomem *reg, u8 shift,
81 unsigned int *share_count)
82{
83 return clk_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT |
84 CLK_OPS_PARENT_ENABLE, reg, shift, 0x3, 0,
85 share_count);
86}
87
Peng Fanf8c3ca12019-07-31 07:01:42 +000088static inline struct clk *imx_clk_gate4(const char *name, const char *parent,
89 void __iomem *reg, u8 shift)
90{
91 return clk_register_gate2(NULL, name, parent,
92 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
Michael Trimarchi29c56cf2022-08-30 16:41:38 +020093 reg, shift, 0x3, 0, NULL);
Peng Fanf8c3ca12019-07-31 07:01:42 +000094}
95
96static inline struct clk *imx_clk_gate4_flags(const char *name,
97 const char *parent, void __iomem *reg, u8 shift,
98 unsigned long flags)
99{
100 return clk_register_gate2(NULL, name, parent,
101 flags | CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
Michael Trimarchi29c56cf2022-08-30 16:41:38 +0200102 reg, shift, 0x3, 0, NULL);
Peng Fanf8c3ca12019-07-31 07:01:42 +0000103}
104
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200105static inline struct clk *imx_clk_fixed_factor(const char *name,
106 const char *parent, unsigned int mult, unsigned int div)
107{
108 return clk_register_fixed_factor(NULL, name, parent,
109 CLK_SET_RATE_PARENT, mult, div);
110}
111
112static inline struct clk *imx_clk_divider(const char *name, const char *parent,
113 void __iomem *reg, u8 shift, u8 width)
114{
115 return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
116 reg, shift, width, 0);
117}
118
Lukasz Majewski2f665412019-10-15 12:44:57 +0200119static inline struct clk *
120imx_clk_busy_divider(const char *name, const char *parent, void __iomem *reg,
121 u8 shift, u8 width, void __iomem *busy_reg, u8 busy_shift)
122{
123 return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
124 reg, shift, width, 0);
125}
126
Peng Fanf8c3ca12019-07-31 07:01:42 +0000127static inline struct clk *imx_clk_divider2(const char *name, const char *parent,
128 void __iomem *reg, u8 shift, u8 width)
129{
130 return clk_register_divider(NULL, name, parent,
131 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
132 reg, shift, width, 0);
133}
134
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200135struct clk *imx_clk_pfd(const char *name, const char *parent_name,
136 void __iomem *reg, u8 idx);
137
138struct clk *imx_clk_fixup_mux(const char *name, void __iomem *reg,
139 u8 shift, u8 width, const char * const *parents,
140 int num_parents, void (*fixup)(u32 *val));
141
Peng Fanf8c3ca12019-07-31 07:01:42 +0000142static inline struct clk *imx_clk_mux_flags(const char *name,
143 void __iomem *reg, u8 shift, u8 width,
144 const char * const *parents, int num_parents,
145 unsigned long flags)
146{
147 return clk_register_mux(NULL, name, parents, num_parents,
148 flags | CLK_SET_RATE_NO_REPARENT, reg, shift,
149 width, 0);
150}
151
Peng Fan1333f5e2019-12-30 16:56:25 +0800152static inline struct clk *imx_clk_mux2_flags(const char *name,
153 void __iomem *reg, u8 shift, u8 width,
154 const char * const *parents,
155 int num_parents, unsigned long flags)
156{
157 return clk_register_mux(NULL, name, parents, num_parents,
158 flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE,
159 reg, shift, width, 0);
160}
161
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200162static inline struct clk *imx_clk_mux(const char *name, void __iomem *reg,
163 u8 shift, u8 width, const char * const *parents,
164 int num_parents)
165{
166 return clk_register_mux(NULL, name, parents, num_parents,
167 CLK_SET_RATE_NO_REPARENT, reg, shift,
168 width, 0);
169}
170
Lukasz Majewski2f665412019-10-15 12:44:57 +0200171static inline struct clk *
172imx_clk_busy_mux(const char *name, void __iomem *reg, u8 shift, u8 width,
173 void __iomem *busy_reg, u8 busy_shift,
174 const char * const *parents, int num_parents)
175{
176 return clk_register_mux(NULL, name, parents, num_parents,
177 CLK_SET_RATE_NO_REPARENT, reg, shift,
178 width, 0);
179}
180
Peng Fanf8c3ca12019-07-31 07:01:42 +0000181static inline struct clk *imx_clk_mux2(const char *name, void __iomem *reg,
182 u8 shift, u8 width, const char * const *parents,
183 int num_parents)
184{
185 return clk_register_mux(NULL, name, parents, num_parents,
186 CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE,
187 reg, shift, width, 0);
188}
189
190static inline struct clk *imx_clk_gate(const char *name, const char *parent,
191 void __iomem *reg, u8 shift)
192{
193 return clk_register_gate(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
194 shift, 0, NULL);
195}
196
197static inline struct clk *imx_clk_gate_flags(const char *name, const char *parent,
198 void __iomem *reg, u8 shift, unsigned long flags)
199{
200 return clk_register_gate(NULL, name, parent, flags | CLK_SET_RATE_PARENT, reg,
201 shift, 0, NULL);
202}
203
204static inline struct clk *imx_clk_gate3(const char *name, const char *parent,
205 void __iomem *reg, u8 shift)
206{
207 return clk_register_gate(NULL, name, parent,
208 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
209 reg, shift, 0, NULL);
210}
211
212struct clk *imx8m_clk_composite_flags(const char *name,
213 const char * const *parent_names,
214 int num_parents, void __iomem *reg, unsigned long flags);
215
216#define __imx8m_clk_composite(name, parent_names, reg, flags) \
217 imx8m_clk_composite_flags(name, parent_names, \
218 ARRAY_SIZE(parent_names), reg, \
219 flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE)
220
221#define imx8m_clk_composite(name, parent_names, reg) \
222 __imx8m_clk_composite(name, parent_names, reg, 0)
223
224#define imx8m_clk_composite_critical(name, parent_names, reg) \
225 __imx8m_clk_composite(name, parent_names, reg, CLK_IS_CRITICAL)
226
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200227#endif /* __MACH_IMX_CLK_H */