blob: 60f287046b9ee102e97b4ad62c5753f75e9750b4 [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,
13 IMX_PLLV3_SYS,
14 IMX_PLLV3_USB,
15 IMX_PLLV3_USB_VF610,
16 IMX_PLLV3_AV,
17 IMX_PLLV3_ENET,
18 IMX_PLLV3_ENET_IMX7,
19 IMX_PLLV3_SYS_VF610,
20 IMX_PLLV3_DDR_IMX7,
21};
22
Peng Fan134cf092019-08-19 07:53:58 +000023enum imx_pll14xx_type {
24 PLL_1416X,
25 PLL_1443X,
26};
27
28/* NOTE: Rate table should be kept sorted in descending order. */
29struct imx_pll14xx_rate_table {
30 unsigned int rate;
31 unsigned int pdiv;
32 unsigned int mdiv;
33 unsigned int sdiv;
34 unsigned int kdiv;
35};
36
37struct imx_pll14xx_clk {
38 enum imx_pll14xx_type type;
39 const struct imx_pll14xx_rate_table *rate_table;
40 int rate_count;
41 int flags;
42};
43
44struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
45 void __iomem *base,
46 const struct imx_pll14xx_clk *pll_clk);
47
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020048struct 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,
51 u8 clk_gate_flags);
52
53struct clk *imx_clk_pllv3(enum imx_pllv3_type type, const char *name,
54 const char *parent_name, void __iomem *base,
55 u32 div_mask);
56
57static inline struct clk *imx_clk_gate2(const char *name, const char *parent,
58 void __iomem *reg, u8 shift)
59{
60 return clk_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
61 shift, 0x3, 0);
62}
63
Peng Fanf8c3ca12019-07-31 07:01:42 +000064static inline struct clk *imx_clk_gate4(const char *name, const char *parent,
65 void __iomem *reg, u8 shift)
66{
67 return clk_register_gate2(NULL, name, parent,
68 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
69 reg, shift, 0x3, 0);
70}
71
72static inline struct clk *imx_clk_gate4_flags(const char *name,
73 const char *parent, void __iomem *reg, u8 shift,
74 unsigned long flags)
75{
76 return clk_register_gate2(NULL, name, parent,
77 flags | CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
78 reg, shift, 0x3, 0);
79}
80
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020081static inline struct clk *imx_clk_fixed_factor(const char *name,
82 const char *parent, unsigned int mult, unsigned int div)
83{
84 return clk_register_fixed_factor(NULL, name, parent,
85 CLK_SET_RATE_PARENT, mult, div);
86}
87
88static inline struct clk *imx_clk_divider(const char *name, const char *parent,
89 void __iomem *reg, u8 shift, u8 width)
90{
91 return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
92 reg, shift, width, 0);
93}
94
Lukasz Majewski2f665412019-10-15 12:44:57 +020095static inline struct clk *
96imx_clk_busy_divider(const char *name, const char *parent, void __iomem *reg,
97 u8 shift, u8 width, void __iomem *busy_reg, u8 busy_shift)
98{
99 return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
100 reg, shift, width, 0);
101}
102
Peng Fanf8c3ca12019-07-31 07:01:42 +0000103static inline struct clk *imx_clk_divider2(const char *name, const char *parent,
104 void __iomem *reg, u8 shift, u8 width)
105{
106 return clk_register_divider(NULL, name, parent,
107 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
108 reg, shift, width, 0);
109}
110
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200111struct clk *imx_clk_pfd(const char *name, const char *parent_name,
112 void __iomem *reg, u8 idx);
113
114struct 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));
117
Peng Fanf8c3ca12019-07-31 07:01:42 +0000118static 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,
121 unsigned long flags)
122{
123 return clk_register_mux(NULL, name, parents, num_parents,
124 flags | CLK_SET_RATE_NO_REPARENT, reg, shift,
125 width, 0);
126}
127
Peng Fan1333f5e2019-12-30 16:56:25 +0800128static 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)
132{
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);
136}
137
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200138static inline struct clk *imx_clk_mux(const char *name, void __iomem *reg,
139 u8 shift, u8 width, const char * const *parents,
140 int num_parents)
141{
142 return clk_register_mux(NULL, name, parents, num_parents,
143 CLK_SET_RATE_NO_REPARENT, reg, shift,
144 width, 0);
145}
146
Lukasz Majewski2f665412019-10-15 12:44:57 +0200147static inline struct clk *
148imx_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)
151{
152 return clk_register_mux(NULL, name, parents, num_parents,
153 CLK_SET_RATE_NO_REPARENT, reg, shift,
154 width, 0);
155}
156
Peng Fanf8c3ca12019-07-31 07:01:42 +0000157static inline struct clk *imx_clk_mux2(const char *name, void __iomem *reg,
158 u8 shift, u8 width, const char * const *parents,
159 int num_parents)
160{
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);
164}
165
166static inline struct clk *imx_clk_gate(const char *name, const char *parent,
167 void __iomem *reg, u8 shift)
168{
169 return clk_register_gate(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
170 shift, 0, NULL);
171}
172
173static inline struct clk *imx_clk_gate_flags(const char *name, const char *parent,
174 void __iomem *reg, u8 shift, unsigned long flags)
175{
176 return clk_register_gate(NULL, name, parent, flags | CLK_SET_RATE_PARENT, reg,
177 shift, 0, NULL);
178}
179
180static inline struct clk *imx_clk_gate3(const char *name, const char *parent,
181 void __iomem *reg, u8 shift)
182{
183 return clk_register_gate(NULL, name, parent,
184 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
185 reg, shift, 0, NULL);
186}
187
188struct clk *imx8m_clk_composite_flags(const char *name,
189 const char * const *parent_names,
190 int num_parents, void __iomem *reg, unsigned long flags);
191
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)
196
197#define imx8m_clk_composite(name, parent_names, reg) \
198 __imx8m_clk_composite(name, parent_names, reg, 0)
199
200#define imx8m_clk_composite_critical(name, parent_names, reg) \
201 __imx8m_clk_composite(name, parent_names, reg, CLK_IS_CRITICAL)
202
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200203#endif /* __MACH_IMX_CLK_H */