blob: 0e1eaf03d41954f9a166f4644eeda7b23f0b6b5e [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
Angus Ainslie73d75ec2022-03-29 07:02:40 -070044extern struct imx_pll14xx_clk imx_1416x_pll;
45extern struct imx_pll14xx_clk imx_1443x_pll;
46extern struct imx_pll14xx_clk imx_1443x_dram_pll;
47
Peng Fan134cf092019-08-19 07:53:58 +000048struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
49 void __iomem *base,
50 const struct imx_pll14xx_clk *pll_clk);
51
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020052struct clk *clk_register_gate2(struct device *dev, const char *name,
53 const char *parent_name, unsigned long flags,
54 void __iomem *reg, u8 bit_idx, u8 cgr_val,
55 u8 clk_gate_flags);
56
57struct clk *imx_clk_pllv3(enum imx_pllv3_type type, const char *name,
58 const char *parent_name, void __iomem *base,
59 u32 div_mask);
60
61static inline struct clk *imx_clk_gate2(const char *name, const char *parent,
62 void __iomem *reg, u8 shift)
63{
64 return clk_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
65 shift, 0x3, 0);
66}
67
Peng Fanf8c3ca12019-07-31 07:01:42 +000068static inline struct clk *imx_clk_gate4(const char *name, const char *parent,
69 void __iomem *reg, u8 shift)
70{
71 return clk_register_gate2(NULL, name, parent,
72 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
73 reg, shift, 0x3, 0);
74}
75
76static inline struct clk *imx_clk_gate4_flags(const char *name,
77 const char *parent, void __iomem *reg, u8 shift,
78 unsigned long flags)
79{
80 return clk_register_gate2(NULL, name, parent,
81 flags | CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
82 reg, shift, 0x3, 0);
83}
84
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020085static inline struct clk *imx_clk_fixed_factor(const char *name,
86 const char *parent, unsigned int mult, unsigned int div)
87{
88 return clk_register_fixed_factor(NULL, name, parent,
89 CLK_SET_RATE_PARENT, mult, div);
90}
91
92static inline struct clk *imx_clk_divider(const char *name, const char *parent,
93 void __iomem *reg, u8 shift, u8 width)
94{
95 return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
96 reg, shift, width, 0);
97}
98
Lukasz Majewski2f665412019-10-15 12:44:57 +020099static inline struct clk *
100imx_clk_busy_divider(const char *name, const char *parent, void __iomem *reg,
101 u8 shift, u8 width, void __iomem *busy_reg, u8 busy_shift)
102{
103 return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
104 reg, shift, width, 0);
105}
106
Peng Fanf8c3ca12019-07-31 07:01:42 +0000107static inline struct clk *imx_clk_divider2(const char *name, const char *parent,
108 void __iomem *reg, u8 shift, u8 width)
109{
110 return clk_register_divider(NULL, name, parent,
111 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
112 reg, shift, width, 0);
113}
114
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200115struct clk *imx_clk_pfd(const char *name, const char *parent_name,
116 void __iomem *reg, u8 idx);
117
118struct clk *imx_clk_fixup_mux(const char *name, void __iomem *reg,
119 u8 shift, u8 width, const char * const *parents,
120 int num_parents, void (*fixup)(u32 *val));
121
Peng Fanf8c3ca12019-07-31 07:01:42 +0000122static inline struct clk *imx_clk_mux_flags(const char *name,
123 void __iomem *reg, u8 shift, u8 width,
124 const char * const *parents, int num_parents,
125 unsigned long flags)
126{
127 return clk_register_mux(NULL, name, parents, num_parents,
128 flags | CLK_SET_RATE_NO_REPARENT, reg, shift,
129 width, 0);
130}
131
Peng Fan1333f5e2019-12-30 16:56:25 +0800132static inline struct clk *imx_clk_mux2_flags(const char *name,
133 void __iomem *reg, u8 shift, u8 width,
134 const char * const *parents,
135 int num_parents, unsigned long flags)
136{
137 return clk_register_mux(NULL, name, parents, num_parents,
138 flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE,
139 reg, shift, width, 0);
140}
141
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200142static inline struct clk *imx_clk_mux(const char *name, void __iomem *reg,
143 u8 shift, u8 width, const char * const *parents,
144 int num_parents)
145{
146 return clk_register_mux(NULL, name, parents, num_parents,
147 CLK_SET_RATE_NO_REPARENT, reg, shift,
148 width, 0);
149}
150
Lukasz Majewski2f665412019-10-15 12:44:57 +0200151static inline struct clk *
152imx_clk_busy_mux(const char *name, void __iomem *reg, u8 shift, u8 width,
153 void __iomem *busy_reg, u8 busy_shift,
154 const char * const *parents, int num_parents)
155{
156 return clk_register_mux(NULL, name, parents, num_parents,
157 CLK_SET_RATE_NO_REPARENT, reg, shift,
158 width, 0);
159}
160
Peng Fanf8c3ca12019-07-31 07:01:42 +0000161static inline struct clk *imx_clk_mux2(const char *name, void __iomem *reg,
162 u8 shift, u8 width, const char * const *parents,
163 int num_parents)
164{
165 return clk_register_mux(NULL, name, parents, num_parents,
166 CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE,
167 reg, shift, width, 0);
168}
169
170static inline struct clk *imx_clk_gate(const char *name, const char *parent,
171 void __iomem *reg, u8 shift)
172{
173 return clk_register_gate(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
174 shift, 0, NULL);
175}
176
177static inline struct clk *imx_clk_gate_flags(const char *name, const char *parent,
178 void __iomem *reg, u8 shift, unsigned long flags)
179{
180 return clk_register_gate(NULL, name, parent, flags | CLK_SET_RATE_PARENT, reg,
181 shift, 0, NULL);
182}
183
184static inline struct clk *imx_clk_gate3(const char *name, const char *parent,
185 void __iomem *reg, u8 shift)
186{
187 return clk_register_gate(NULL, name, parent,
188 CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
189 reg, shift, 0, NULL);
190}
191
192struct clk *imx8m_clk_composite_flags(const char *name,
193 const char * const *parent_names,
194 int num_parents, void __iomem *reg, unsigned long flags);
195
196#define __imx8m_clk_composite(name, parent_names, reg, flags) \
197 imx8m_clk_composite_flags(name, parent_names, \
198 ARRAY_SIZE(parent_names), reg, \
199 flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE)
200
201#define imx8m_clk_composite(name, parent_names, reg) \
202 __imx8m_clk_composite(name, parent_names, reg, 0)
203
204#define imx8m_clk_composite_critical(name, parent_names, reg) \
205 __imx8m_clk_composite(name, parent_names, reg, CLK_IS_CRITICAL)
206
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200207#endif /* __MACH_IMX_CLK_H */