summaryrefslogtreecommitdiff
path: root/arch/arm/include/asm/arch-mx7ulp/scg.h
blob: 06a6e9f4f9c3314a3f505f5a0c6b4c515fdb1980 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
 * Copyright (C) 2016 Freescale Semiconductor, Inc.
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#ifndef _ASM_ARCH_SCG_H
#define _ASM_ARCH_SCG_H

#include <common.h>

#ifdef CONFIG_CLK_DEBUG
#define clk_debug(fmt, args...)	printf(fmt, ##args)
#else
#define clk_debug(fmt, args...)
#endif

#define SCG_CCR_SCS_SHIFT		(24)
#define SCG_CCR_SCS_MASK		((0xFUL) << SCG_CCR_SCS_SHIFT)
#define SCG_CCR_DIVCORE_SHIFT		(16)
#define SCG_CCR_DIVCORE_MASK		((0xFUL) << SCG_CCR_DIVCORE_SHIFT)
#define SCG_CCR_DIVPLAT_SHIFT		(12)
#define SCG_CCR_DIVPLAT_MASK		((0xFUL) << SCG_CCR_DIVPLAT_SHIFT)
#define SCG_CCR_DIVEXT_SHIFT		(8)
#define SCG_CCR_DIVEXT_MASK		((0xFUL) << SCG_CCR_DIVEXT_SHIFT)
#define SCG_CCR_DIVBUS_SHIFT		(4)
#define SCG_CCR_DIVBUS_MASK		((0xFUL) << SCG_CCR_DIVBUS_SHIFT)
#define SCG_CCR_DIVSLOW_SHIFT		(0)
#define SCG_CCR_DIVSLOW_MASK		((0xFUL) << SCG_CCR_DIVSLOW_SHIFT)

/* SCG DDR Clock Control Register */
#define SCG_DDRCCR_DDRCS_SHIFT		(24)
#define SCG_DDRCCR_DDRCS_MASK		((0x1UL) << SCG_DDRCCR_DDRCS_SHIFT)

#define SCG_DDRCCR_DDRDIV_SHIFT		(0)
#define SCG_DDRCCR_DDRDIV_MASK		((0x7UL) << SCG_DDRCCR_DDRDIV_SHIFT)

/* SCG NIC Clock Control Register */
#define SCG_NICCCR_NICCS_SHIFT		(28)
#define SCG_NICCCR_NICCS_MASK		((0x1UL) << SCG_NICCCR_NICCS_SHIFT)

#define SCG_NICCCR_NIC0_DIV_SHIFT       (24)
#define SCG_NICCCR_NIC0_DIV_MASK        ((0xFUL) << SCG_NICCCR_NIC0_DIV_SHIFT)

#define SCG_NICCCR_GPU_DIV_SHIFT        (20)
#define SCG_NICCCR_GPU_DIV_MASK         ((0xFUL) << SCG_NICCCR_GPU_DIV_SHIFT)

#define SCG_NICCCR_NIC1_DIV_SHIFT       (16)
#define SCG_NICCCR_NIC1_DIV_MASK        ((0xFUL) << SCG_NICCCR_NIC1_DIV_SHIFT)

#define SCG_NICCCR_NIC1_DIVEXT_SHIFT    (8)
#define SCG_NICCCR_NIC1_DIVEXT_MASK   ((0xFUL) << SCG_NICCCR_NIC1_DIVEXT_SHIFT)

#define SCG_NICCCR_NIC1_DIVBUS_SHIFT    (4)
#define SCG_NICCCR_NIC1_DIVBUS_MASK   ((0xFUL) << SCG_NICCCR_NIC1_DIVBUS_SHIFT)

/* SCG NIC clock status register */
#define SCG_NICCSR_NICCS_SHIFT          (28)
#define SCG_NICCSR_NICCS_MASK           ((0x1UL) << SCG_NICCSR_NICCS_SHIFT)

#define SCG_NICCSR_NIC0DIV_SHIFT        (24)
#define SCG_NICCSR_NIC0DIV_MASK         ((0xFUL) << SCG_NICCSR_NIC0DIV_SHIFT)
#define SCG_NICCSR_GPUDIV_SHIFT         (20)
#define SCG_NICCSR_GPUDIV_MASK          ((0xFUL) << SCG_NICCSR_GPUDIV_SHIFT)
#define SCG_NICCSR_NIC1DIV_SHIFT        (16)
#define SCG_NICCSR_NIC1DIV_MASK         ((0xFUL) << SCG_NICCSR_NIC1DIV_SHIFT)
#define SCG_NICCSR_NIC1EXTDIV_SHIFT     (8)
#define SCG_NICCSR_NIC1EXTDIV_MASK      ((0xFUL) << SCG_NICCSR_NIC1EXTDIV_SHIFT)
#define SCG_NICCSR_NIC1BUSDIV_SHIFT     (4)
#define SCG_NICCSR_NIC1BUSDIV_MASK      ((0xFUL) << SCG_NICCSR_NIC1BUSDIV_SHIFT)

/* SCG Slow IRC Control Status Register */
#define SCG_SIRC_CSR_SIRCVLD_SHIFT      (24)
#define SCG_SIRC_CSR_SIRCVLD_MASK       ((0x1UL) << SCG_SIRC_CSR_SIRCVLD_SHIFT)

#define SCG_SIRC_CSR_SIRCEN_SHIFT       (0)
#define SCG_SIRC_CSR_SIRCEN_MASK        ((0x1UL) << SCG_SIRC_CSR_SIRCEN_SHIFT)

/* SCG Slow IRC Configuration Register */
#define SCG_SIRCCFG_RANGE_SHIFT         (0)
#define SCG_SIRCCFG_RANGE_MASK          ((0x1UL) << SCG_SIRCCFG_RANGE_SHIFT)
#define SCG_SIRCCFG_RANGE_4M            ((0x0UL) << SCG_SIRCCFG_RANGE_SHIFT)
#define SCG_SIRCCFG_RANGE_16M           ((0x1UL) << SCG_SIRCCFG_RANGE_SHIFT)

/* SCG Slow IRC Divide Register */
#define SCG_SIRCDIV_DIV3_SHIFT          (16)
#define SCG_SIRCDIV_DIV3_MASK           ((0x7UL) << SCG_SIRCDIV_DIV3_SHIFT)

#define SCG_SIRCDIV_DIV2_SHIFT          (8)
#define SCG_SIRCDIV_DIV2_MASK           ((0x7UL) << SCG_SIRCDIV_DIV2_SHIFT)

#define SCG_SIRCDIV_DIV1_SHIFT          (0)
#define SCG_SIRCDIV_DIV1_MASK           ((0x7UL) << SCG_SIRCDIV_DIV1_SHIFT)
/*
 * FIRC/SIRC DIV1 ==> xIRC_PLAT_CLK
 * FIRC/SIRC DIV2 ==> xIRC_BUS_CLK
 * FIRC/SIRC DIV3 ==> xIRC_SLOW_CLK
 */

/* SCG Fast IRC Control Status Register */
#define SCG_FIRC_CSR_FIRCVLD_SHIFT      (24)
#define SCG_FIRC_CSR_FIRCVLD_MASK       ((0x1UL) << SCG_FIRC_CSR_FIRCVLD_SHIFT)

#define SCG_FIRC_CSR_FIRCEN_SHIFT       (0)
#define SCG_FIRC_CSR_FIRCEN_MASK        ((0x1UL) << SCG_FIRC_CSR_FIRCEN_SHIFT)

/* SCG Fast IRC Divide Register */
#define SCG_FIRCDIV_DIV3_SHIFT          (16)
#define SCG_FIRCDIV_DIV3_MASK           ((0x7UL) << SCG_FIRCDIV_DIV3_SHIFT)

#define SCG_FIRCDIV_DIV2_SHIFT          (8)
#define SCG_FIRCDIV_DIV2_MASK           ((0x7UL) << SCG_FIRCDIV_DIV2_SHIFT)

#define SCG_FIRCDIV_DIV1_SHIFT          (0)
#define SCG_FIRCDIV_DIV1_MASK           ((0x7UL) << SCG_FIRCDIV_DIV1_SHIFT)

#define SCG_FIRCCFG_RANGE_SHIFT         (0)
#define SCG_FIRCCFG_RANGE_MASK          ((0x3UL) << SCG_FIRCCFG_RANGE_SHIFT)

#define SCG_FIRCCFG_RANGE_SHIFT         (0)
#define SCG_FIRCCFG_RANGE_48M           ((0x0UL) << SCG_FIRCCFG_RANGE_SHIFT)

/* SCG System OSC Control Status Register */
#define SCG_SOSC_CSR_SOSCVLD_SHIFT      (24)
#define SCG_SOSC_CSR_SOSCVLD_MASK       ((0x1UL) << SCG_SOSC_CSR_SOSCVLD_SHIFT)

/* SCG Fast IRC Divide Register */
#define SCG_SOSCDIV_DIV3_SHIFT          (16)
#define SCG_SOSCDIV_DIV3_MASK           ((0x7UL) << SCG_SOSCDIV_DIV3_SHIFT)

#define SCG_SOSCDIV_DIV2_SHIFT          (8)
#define SCG_SOSCDIV_DIV2_MASK           ((0x7UL) << SCG_SOSCDIV_DIV2_SHIFT)

#define SCG_SOSCDIV_DIV1_SHIFT          (0)
#define SCG_SOSCDIV_DIV1_MASK           ((0x7UL) << SCG_SOSCDIV_DIV1_SHIFT)

/* SCG RTC OSC Control Status Register */
#define SCG_ROSC_CSR_ROSCVLD_SHIFT      (24)
#define SCG_ROSC_CSR_ROSCVLD_MASK       ((0x1UL) << SCG_ROSC_CSR_ROSCVLD_SHIFT)

#define SCG_SPLL_CSR_SPLLVLD_SHIFT      (24)
#define SCG_SPLL_CSR_SPLLVLD_MASK       ((0x1UL) << SCG_SPLL_CSR_SPLLVLD_SHIFT)
#define SCG_SPLL_CSR_SPLLEN_SHIFT       (0)
#define SCG_SPLL_CSR_SPLLEN_MASK        ((0x1UL) << SCG_SPLL_CSR_SPLLEN_SHIFT)
#define SCG_APLL_CSR_APLLEN_SHIFT       (0)
#define SCG_APLL_CSR_APLLEN_MASK        (0x1UL)
#define SCG_APLL_CSR_APLLVLD_MASK       (0x01000000)

#define SCG_UPLL_CSR_UPLLVLD_MASK       (0x01000000)


#define SCG_PLL_PFD3_GATE_MASK          (0x80000000)
#define SCG_PLL_PFD2_GATE_MASK          (0x00800000)
#define SCG_PLL_PFD1_GATE_MASK          (0x00008000)
#define SCG_PLL_PFD0_GATE_MASK          (0x00000080)
#define SCG_PLL_PFD3_VALID_MASK         (0x40000000)
#define SCG_PLL_PFD2_VALID_MASK         (0x00400000)
#define SCG_PLL_PFD1_VALID_MASK         (0x00004000)
#define SCG_PLL_PFD0_VALID_MASK         (0x00000040)

#define SCG_PLL_PFD0_FRAC_SHIFT         (0)
#define SCG_PLL_PFD0_FRAC_MASK          ((0x3F) << SCG_PLL_PFD0_FRAC_SHIFT)
#define SCG_PLL_PFD1_FRAC_SHIFT         (8)
#define SCG_PLL_PFD1_FRAC_MASK          ((0x3F) << SCG_PLL_PFD1_FRAC_SHIFT)
#define SCG_PLL_PFD2_FRAC_SHIFT         (16)
#define SCG_PLL_PFD2_FRAC_MASK          ((0x3F) << SCG_PLL_PFD2_FRAC_SHIFT)
#define SCG_PLL_PFD3_FRAC_SHIFT         (24)
#define SCG_PLL_PFD3_FRAC_MASK          ((0x3F) << SCG_PLL_PFD3_FRAC_SHIFT)

#define SCG_PLL_CFG_POSTDIV2_SHIFT      (28)
#define SCG_PLL_CFG_POSTDIV2_MASK       ((0xFUL) << SCG_PLL_CFG_POSTDIV2_SHIFT)
#define SCG_PLL_CFG_POSTDIV1_SHIFT      (24)
#define SCG_PLL_CFG_POSTDIV1_MASK       ((0xFUL) << SCG_PLL_CFG_POSTDIV1_SHIFT)
#define SCG_PLL_CFG_MULT_SHIFT          (16)
#define SCG1_SPLL_CFG_MULT_MASK         ((0x7FUL) << SCG_PLL_CFG_MULT_SHIFT)
#define SCG_APLL_CFG_MULT_MASK          ((0x7FUL) << SCG_PLL_CFG_MULT_SHIFT)
#define SCG_PLL_CFG_PFDSEL_SHIFT        (14)
#define SCG_PLL_CFG_PFDSEL_MASK         ((0x3UL) << SCG_PLL_CFG_PFDSEL_SHIFT)
#define SCG_PLL_CFG_PREDIV_SHIFT        (8)
#define SCG_PLL_CFG_PREDIV_MASK         ((0x7UL) << SCG_PLL_CFG_PREDIV_SHIFT)
#define SCG_PLL_CFG_BYPASS_SHIFT        (2)
/* 0: SPLL, 1: bypass */
#define SCG_PLL_CFG_BYPASS_MASK         ((0x1UL) << SCG_PLL_CFG_BYPASS_SHIFT)
#define SCG_PLL_CFG_PLLSEL_SHIFT        (1)
/* 0: pll, 1: pfd */
#define SCG_PLL_CFG_PLLSEL_MASK         ((0x1UL) << SCG_PLL_CFG_PLLSEL_SHIFT)
#define SCG_PLL_CFG_CLKSRC_SHIFT        (0)
/* 0: Sys-OSC, 1: FIRC */
#define SCG_PLL_CFG_CLKSRC_MASK         ((0x1UL) << SCG_PLL_CFG_CLKSRC_SHIFT)
#define SCG0_SPLL_CFG_MULT_SHIFT        (17)
/* 0: Multiplier = 20, 1: Multiplier = 22 */
#define SCG0_SPLL_CFG_MULT_MASK         ((0x1UL) << SCG0_SPLL_CFG_MULT_SHIFT)

#define PLL_USB_EN_USB_CLKS_MASK	(0x01 << 6)
#define PLL_USB_PWR_MASK		(0x01 << 12)
#define PLL_USB_ENABLE_MASK		(0x01 << 13)
#define PLL_USB_BYPASS_MASK		(0x01 << 16)
#define PLL_USB_REG_ENABLE_MASK		(0x01 << 21)
#define PLL_USB_DIV_SEL_MASK		(0x07 << 22)
#define PLL_USB_LOCK_MASK		(0x01 << 31)

enum scg_clk {
	SCG_SOSC_CLK,
	SCG_FIRC_CLK,
	SCG_SIRC_CLK,
	SCG_ROSC_CLK,
	SCG_SIRC_DIV1_CLK,
	SCG_SIRC_DIV2_CLK,
	SCG_SIRC_DIV3_CLK,
	SCG_FIRC_DIV1_CLK,
	SCG_FIRC_DIV2_CLK,
	SCG_FIRC_DIV3_CLK,
	SCG_SOSC_DIV1_CLK,
	SCG_SOSC_DIV2_CLK,
	SCG_SOSC_DIV3_CLK,
	SCG_CORE_CLK,
	SCG_BUS_CLK,
	SCG_SPLL_PFD0_CLK,
	SCG_SPLL_PFD1_CLK,
	SCG_SPLL_PFD2_CLK,
	SCG_SPLL_PFD3_CLK,
	SCG_DDR_CLK,
	SCG_NIC0_CLK,
	SCG_GPU_CLK,
	SCG_NIC1_CLK,
	SCG_NIC1_BUS_CLK,
	SCG_NIC1_EXT_CLK,
	SCG_APLL_PFD0_CLK,
	SCG_APLL_PFD1_CLK,
	SCG_APLL_PFD2_CLK,
	SCG_APLL_PFD3_CLK,
	USB_PLL_OUT,
	MIPI_PLL_OUT
};

enum scg_sys_src {
	SCG_SCS_SYS_OSC = 1,
	SCG_SCS_SLOW_IRC,
	SCG_SCS_FAST_IRC,
	SCG_SCS_RTC_OSC,
	SCG_SCS_AUX_PLL,
	SCG_SCS_SYS_PLL,
	SCG_SCS_USBPHY_PLL,
};

/* PLL supported by i.mx7ulp */
enum pll_clocks {
	PLL_M4_SPLL,	/* M4 SPLL */
	PLL_M4_APLL,	/* M4 APLL*/
	PLL_A7_SPLL,	/* A7 SPLL */
	PLL_A7_APLL,	/* A7 APLL */
	PLL_USB,	/* USB PLL*/
	PLL_MIPI,	/* MIPI PLL */
};

typedef struct scg_regs {
	u32 verid;	/* VERSION_ID */
	u32 param;	/*  PARAMETER */
	u32 rsvd11[2];

	u32 csr;	/*  Clock Status Register */
	u32 rccr;	/*  Run Clock Control Register */
	u32 vccr;	/*  VLPR Clock Control Register */
	u32 hccr;	/*  HSRUN Clock Control Register */
	u32 clkoutcnfg;	/*  SCG CLKOUT Configuration Register */
	u32 rsvd12[3];
	u32 ddrccr;	/*  SCG DDR Clock Control Register */
	u32 rsvd13[3];
	u32 nicccr;	/*  NIC Clock Control Register */
	u32 niccsr;	/*  NIC Clock Status Register */
	u32 rsvd10[46];

	u32 sosccsr;	/*  System OSC Control Status Register, offset 0x100 */
	u32 soscdiv;	/*  System OSC Divide Register */
	u32 sosccfg;	/*  System Oscillator Configuration Register */
	u32 sosctest;	/*  System Oscillator Test Register */
	u32 rsvd20[60];

	u32 sirccsr;	/*  Slow IRC Control Status Register, offset 0x200 */
	u32 sircdiv;	/*  Slow IRC Divide Register */
	u32 sirccfg;	/*  Slow IRC Configuration Register */
	u32 sirctrim;	/*  Slow IRC Trim Register */
	u32 loptrim;	/*  Low Power Oscillator Trim Register */
	u32 sirctest;	/*  Slow IRC Test Register */
	u32 rsvd30[58];

	u32 firccsr;	/*  Fast IRC Control Status Register, offset 0x300 */
	u32 fircdiv;
	u32 firccfg;
	u32 firctcfg;	/*  Fast IRC Trim Configuration Register */
	u32 firctriml;	/*  Fast IRC Trim Low Register */
	u32 firctrimh;
	u32 fircstat;	/*  Fast IRC Status Register */
	u32 firctest;	/*  Fast IRC Test Register */
	u32 rsvd40[56];

	u32 rtccsr;	/*  RTC OSC Control Status Register, offset 0x400 */
	u32 rsvd50[63];

	u32 apllcsr; /*  Auxiliary PLL Control Status Register, offset 0x500 */
	u32 aplldiv;	/*  Auxiliary PLL Divider Register */
	u32 apllcfg;	/*  Auxiliary PLL Configuration Register */
	u32 apllpfd;	/*  Auxiliary PLL PFD Register */
	u32 apllnum;	/*  Auxiliary PLL Numerator Register */
	u32 aplldenom;	/*  Auxiliary PLL Denominator Register */
	u32 apllss;	/*  Auxiliary PLL Spread Spectrum Register */
	u32 rsvd60[55];
	u32 apllock_cnfg; /*  Auxiliary PLL LOCK Configuration Register */
	u32 rsvd61[1];

	u32 spllcsr;	/*  System PLL Control Status Register, offset 0x600 */
	u32 splldiv;	/*  System PLL Divide Register */
	u32 spllcfg;	/*  System PLL Configuration Register */
	u32 spllpfd;	/*  System PLL Test Register */
	u32 spllnum;	/*  System PLL Numerator Register */
	u32 splldenom;	/*  System PLL Denominator Register */
	u32 spllss;	/*  System PLL Spread Spectrum Register */
	u32 rsvd70[55];
	u32 spllock_cnfg;	/*  System PLL LOCK Configuration Register */
	u32 rsvd71[1];

	u32 upllcsr;	/*  USB PLL Control Status Register, offset 0x700 */
	u32 uplldiv;	/*  USB PLL Divide Register */
	u32 upllcfg;	/*  USB PLL Configuration Register */
} scg_t, *scg_p;

u32 scg_clk_get_rate(enum scg_clk clk);
int scg_enable_pll_pfd(enum scg_clk clk, u32 frac);
int scg_enable_usb_pll(bool usb_control);
u32 decode_pll(enum pll_clocks pll);

void scg_a7_rccr_init(void);
void scg_a7_spll_init(void);
void scg_a7_ddrclk_init(void);
void scg_a7_apll_init(void);
void scg_a7_firc_init(void);
void scg_a7_nicclk_init(void);
void scg_a7_sys_clk_sel(enum scg_sys_src clk);
void scg_a7_info(void);
void scg_a7_soscdiv_init(void);

#endif