blob: 46dee35a6735212cd37cc4a03796fd5bbbb109b3 [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,
56 u8 clk_gate_flags);
57
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,
66 shift, 0x3, 0);
67}
68
Peng Fanf8c3ca12019-07-31 07:01:42 +000069static inline struct clk *imx_clk_gate4(const char *name, const char *parent,
70 void __iomem *reg, u8 shift)
71{
72 return clk_register_gate2(NULL, name, parent,
73 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
74 reg, shift, 0x3, 0);
75}
76
77static inline struct clk *imx_clk_gate4_flags(const char *name,
78 const char *parent, void __iomem *reg, u8 shift,
79 unsigned long flags)
80{
81 return clk_register_gate2(NULL, name, parent,
82 flags | CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
83 reg, shift, 0x3, 0);
84}
85
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020086static inline struct clk *imx_clk_fixed_factor(const char *name,
87 const char *parent, unsigned int mult, unsigned int div)
88{
89 return clk_register_fixed_factor(NULL, name, parent,
90 CLK_SET_RATE_PARENT, mult, div);
91}
92
93static inline struct clk *imx_clk_divider(const char *name, const char *parent,
94 void __iomem *reg, u8 shift, u8 width)
95{
96 return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
97 reg, shift, width, 0);
98}
99
Lukasz Majewski2f665412019-10-15 12:44:57 +0200100static inline struct clk *
101imx_clk_busy_divider(const char *name, const char *parent, void __iomem *reg,
102 u8 shift, u8 width, void __iomem *busy_reg, u8 busy_shift)
103{
104 return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
105 reg, shift, width, 0);
106}
107
Peng Fanf8c3ca12019-07-31 07:01:42 +0000108static inline struct clk *imx_clk_divider2(const char *name, const char *parent,
109 void __iomem *reg, u8 shift, u8 width)
110{
111 return clk_register_divider(NULL, name, parent,
112 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
113 reg, shift, width, 0);
114}
115
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200116struct clk *imx_clk_pfd(const char *name, const char *parent_name,
117 void __iomem *reg, u8 idx);
118
119struct clk *imx_clk_fixup_mux(const char *name, void __iomem *reg,
120 u8 shift, u8 width, const char * const *parents,
121 int num_parents, void (*fixup)(u32 *val));
122
Peng Fanf8c3ca12019-07-31 07:01:42 +0000123static inline struct clk *imx_clk_mux_flags(const char *name,
124 void __iomem *reg, u8 shift, u8 width,
125 const char * const *parents, int num_parents,
126 unsigned long flags)
127{
128 return clk_register_mux(NULL, name, parents, num_parents,
129 flags | CLK_SET_RATE_NO_REPARENT, reg, shift,
130 width, 0);
131}
132
Peng Fan1333f5e2019-12-30 16:56:25 +0800133static inline struct clk *imx_clk_mux2_flags(const char *name,
134 void __iomem *reg, u8 shift, u8 width,
135 const char * const *parents,
136 int num_parents, unsigned long flags)
137{
138 return clk_register_mux(NULL, name, parents, num_parents,
139 flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE,
140 reg, shift, width, 0);
141}
142
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200143static inline struct clk *imx_clk_mux(const char *name, void __iomem *reg,
144 u8 shift, u8 width, const char * const *parents,
145 int num_parents)
146{
147 return clk_register_mux(NULL, name, parents, num_parents,
148 CLK_SET_RATE_NO_REPARENT, reg, shift,
149 width, 0);
150}
151
Lukasz Majewski2f665412019-10-15 12:44:57 +0200152static inline struct clk *
153imx_clk_busy_mux(const char *name, void __iomem *reg, u8 shift, u8 width,
154 void __iomem *busy_reg, u8 busy_shift,
155 const char * const *parents, int num_parents)
156{
157 return clk_register_mux(NULL, name, parents, num_parents,
158 CLK_SET_RATE_NO_REPARENT, reg, shift,
159 width, 0);
160}
161
Peng Fanf8c3ca12019-07-31 07:01:42 +0000162static inline struct clk *imx_clk_mux2(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 | CLK_OPS_PARENT_ENABLE,
168 reg, shift, width, 0);
169}
170
171static inline struct clk *imx_clk_gate(const char *name, const char *parent,
172 void __iomem *reg, u8 shift)
173{
174 return clk_register_gate(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
175 shift, 0, NULL);
176}
177
178static inline struct clk *imx_clk_gate_flags(const char *name, const char *parent,
179 void __iomem *reg, u8 shift, unsigned long flags)
180{
181 return clk_register_gate(NULL, name, parent, flags | CLK_SET_RATE_PARENT, reg,
182 shift, 0, NULL);
183}
184
185static inline struct clk *imx_clk_gate3(const char *name, const char *parent,
186 void __iomem *reg, u8 shift)
187{
188 return clk_register_gate(NULL, name, parent,
189 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
190 reg, shift, 0, NULL);
191}
192
193struct clk *imx8m_clk_composite_flags(const char *name,
194 const char * const *parent_names,
195 int num_parents, void __iomem *reg, unsigned long flags);
196
197#define __imx8m_clk_composite(name, parent_names, reg, flags) \
198 imx8m_clk_composite_flags(name, parent_names, \
199 ARRAY_SIZE(parent_names), reg, \
200 flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE)
201
202#define imx8m_clk_composite(name, parent_names, reg) \
203 __imx8m_clk_composite(name, parent_names, reg, 0)
204
205#define imx8m_clk_composite_critical(name, parent_names, reg) \
206 __imx8m_clk_composite(name, parent_names, reg, CLK_IS_CRITICAL)
207
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200208#endif /* __MACH_IMX_CLK_H */