pm_api_clock.h 7.3 KB
Newer Older
1
/*
2
 * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
8
9
10
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

/*
 * ZynqMP system level PM-API functions for clock control.
 */

11
12
#ifndef PM_API_CLOCK_H
#define PM_API_CLOCK_H
13

14
15
#include <lib/utils_def.h>

16
17
#include "pm_common.h"

18
19
#define CLK_NAME_LEN		U(15)
#define MAX_PARENTS		U(100)
Rajan Vaja's avatar
Rajan Vaja committed
20
21
22
23
#define CLK_NA_PARENT		-1
#define CLK_DUMMY_PARENT	-2

/* Flags for parent id */
24
25
26
27
28
29
30
#define PARENT_CLK_SELF		U(0)
#define PARENT_CLK_NODE1	U(1)
#define PARENT_CLK_NODE2	U(2)
#define PARENT_CLK_NODE3	U(3)
#define PARENT_CLK_NODE4	U(4)
#define PARENT_CLK_EXTERNAL	U(5)
#define PARENT_CLK_MIO0_MIO77	U(6)
Rajan Vaja's avatar
Rajan Vaja committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

#define CLK_SET_RATE_GATE	BIT(0) /* must be gated across rate change */
#define CLK_SET_PARENT_GATE	BIT(1) /* must be gated across re-parent */
#define CLK_SET_RATE_PARENT	BIT(2) /* propagate rate change up one level */
#define CLK_IGNORE_UNUSED	BIT(3) /* do not gate even if unused */
/* unused */
#define CLK_IS_BASIC		BIT(5) /* Basic clk, can't do a to_clk_foo() */
#define CLK_GET_RATE_NOCACHE	BIT(6) /* do not use the cached clk rate */
#define CLK_SET_RATE_NO_REPARENT BIT(7) /* don't re-parent on rate change */
#define CLK_GET_ACCURACY_NOCACHE BIT(8) /* do not use the cached clk accuracy */
#define CLK_RECALC_NEW_RATES	BIT(9) /* recalc rates after notifications */
#define CLK_SET_RATE_UNGATE	BIT(10) /* clock needs to run to set rate */
#define CLK_IS_CRITICAL		BIT(11) /* do not gate, ever */
/* parents need enable during gate/ungate, set rate and re-parent */
#define CLK_OPS_PARENT_ENABLE	BIT(12)

#define CLK_DIVIDER_ONE_BASED		BIT(0)
#define CLK_DIVIDER_POWER_OF_TWO	BIT(1)
#define CLK_DIVIDER_ALLOW_ZERO		BIT(2)
#define CLK_DIVIDER_HIWORD_MASK		BIT(3)
#define CLK_DIVIDER_ROUND_CLOSEST	BIT(4)
#define CLK_DIVIDER_READ_ONLY		BIT(5)
#define CLK_DIVIDER_MAX_AT_ZERO		BIT(6)
54
#define CLK_FRAC		BIT(8)
Rajan Vaja's avatar
Rajan Vaja committed
55
56
57

#define END_OF_CLK     "END_OF_CLK"

58
//CLock Ids
59
enum clock_id {
Rajan Vaja's avatar
Rajan Vaja committed
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
	CLK_IOPLL,
	CLK_RPLL,
	CLK_APLL,
	CLK_DPLL,
	CLK_VPLL,
	CLK_IOPLL_TO_FPD,
	CLK_RPLL_TO_FPD,
	CLK_APLL_TO_LPD,
	CLK_DPLL_TO_LPD,
	CLK_VPLL_TO_LPD,
	CLK_ACPU,
	CLK_ACPU_HALF,
	CLK_DBG_FPD,
	CLK_DBG_LPD,
	CLK_DBG_TRACE,
	CLK_DBG_TSTMP,
	CLK_DP_VIDEO_REF,
	CLK_DP_AUDIO_REF,
	CLK_DP_STC_REF,
	CLK_GDMA_REF,
	CLK_DPDMA_REF,
	CLK_DDR_REF,
	CLK_SATA_REF,
	CLK_PCIE_REF,
	CLK_GPU_REF,
	CLK_GPU_PP0_REF,
	CLK_GPU_PP1_REF,
	CLK_TOPSW_MAIN,
	CLK_TOPSW_LSBUS,
	CLK_GTGREF0_REF,
	CLK_LPD_SWITCH,
	CLK_LPD_LSBUS,
	CLK_USB0_BUS_REF,
	CLK_USB1_BUS_REF,
	CLK_USB3_DUAL_REF,
	CLK_USB0,
	CLK_USB1,
	CLK_CPU_R5,
	CLK_CPU_R5_CORE,
	CLK_CSU_SPB,
	CLK_CSU_PLL,
	CLK_PCAP,
	CLK_IOU_SWITCH,
	CLK_GEM_TSU_REF,
	CLK_GEM_TSU,
	CLK_GEM0_TX,
	CLK_GEM1_TX,
	CLK_GEM2_TX,
	CLK_GEM3_TX,
109
110
111
112
	CLK_GEM0_RX,
	CLK_GEM1_RX,
	CLK_GEM2_RX,
	CLK_GEM3_RX,
Rajan Vaja's avatar
Rajan Vaja committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
	CLK_QSPI_REF,
	CLK_SDIO0_REF,
	CLK_SDIO1_REF,
	CLK_UART0_REF,
	CLK_UART1_REF,
	CLK_SPI0_REF,
	CLK_SPI1_REF,
	CLK_NAND_REF,
	CLK_I2C0_REF,
	CLK_I2C1_REF,
	CLK_CAN0_REF,
	CLK_CAN1_REF,
	CLK_CAN0,
	CLK_CAN1,
	CLK_DLL_REF,
	CLK_ADMA_REF,
	CLK_TIMESTAMP_REF,
	CLK_AMS_REF,
	CLK_PL0_REF,
	CLK_PL1_REF,
	CLK_PL2_REF,
	CLK_PL3_REF,
135
	CLK_FPD_WDT,
Rajan Vaja's avatar
Rajan Vaja committed
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
	CLK_IOPLL_INT,
	CLK_IOPLL_PRE_SRC,
	CLK_IOPLL_HALF,
	CLK_IOPLL_INT_MUX,
	CLK_IOPLL_POST_SRC,
	CLK_RPLL_INT,
	CLK_RPLL_PRE_SRC,
	CLK_RPLL_HALF,
	CLK_RPLL_INT_MUX,
	CLK_RPLL_POST_SRC,
	CLK_APLL_INT,
	CLK_APLL_PRE_SRC,
	CLK_APLL_HALF,
	CLK_APLL_INT_MUX,
	CLK_APLL_POST_SRC,
	CLK_DPLL_INT,
	CLK_DPLL_PRE_SRC,
	CLK_DPLL_HALF,
	CLK_DPLL_INT_MUX,
	CLK_DPLL_POST_SRC,
	CLK_VPLL_INT,
	CLK_VPLL_PRE_SRC,
	CLK_VPLL_HALF,
	CLK_VPLL_INT_MUX,
	CLK_VPLL_POST_SRC,
	CLK_CAN0_MIO,
	CLK_CAN1_MIO,
163
	CLK_ACPU_FULL,
164
165
166
167
168
169
170
171
	CLK_GEM0_REF,
	CLK_GEM1_REF,
	CLK_GEM2_REF,
	CLK_GEM3_REF,
	CLK_GEM0_REF_UNGATED,
	CLK_GEM1_REF_UNGATED,
	CLK_GEM2_REF_UNGATED,
	CLK_GEM3_REF_UNGATED,
172
	CLK_LPD_WDT,
173
	END_OF_OUTPUT_CLKS,
Rajan Vaja's avatar
Rajan Vaja committed
174
175
};

176
177
178
179
180
#define CLK_MAX_OUTPUT_CLK (unsigned int)(END_OF_OUTPUT_CLKS)

//External clock ids
enum {
	EXT_CLK_PSS_REF = END_OF_OUTPUT_CLKS,
Rajan Vaja's avatar
Rajan Vaja committed
181
182
183
184
185
186
	EXT_CLK_VIDEO,
	EXT_CLK_PSS_ALT_REF,
	EXT_CLK_AUX_REF,
	EXT_CLK_GT_CRX_REF,
	EXT_CLK_SWDT0,
	EXT_CLK_SWDT1,
187
188
189
190
191
192
193
194
	EXT_CLK_GEM0_TX_EMIO,
	EXT_CLK_GEM1_TX_EMIO,
	EXT_CLK_GEM2_TX_EMIO,
	EXT_CLK_GEM3_TX_EMIO,
	EXT_CLK_GEM0_RX_EMIO,
	EXT_CLK_GEM1_RX_EMIO,
	EXT_CLK_GEM2_RX_EMIO,
	EXT_CLK_GEM3_RX_EMIO,
Rajan Vaja's avatar
Rajan Vaja committed
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
	EXT_CLK_MIO50_OR_MIO51,
	EXT_CLK_MIO0,
	EXT_CLK_MIO1,
	EXT_C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IO70,
	EXT_CLK_MIO71,
	EXT_CLK_MIO72,
	EXT_CLK_MIO73,
	EXT_CLK_MIO74,
	EXT_CLK_MIO75,
	EXT_CLK_MIO76,
	EXT_CLK_MIO77,
274
	END_OF_CLKS,
Rajan Vaja's avatar
Rajan Vaja committed
275
276
};

277
278
279
280
281
282
283
284
285
286
287
288
289
290
#define CLK_MAX (unsigned int)(END_OF_CLKS)

//CLock types
#define CLK_TYPE_OUTPUT 0U
#define	CLK_TYPE_EXTERNAL  1U

//Topology types
#define TYPE_INVALID 0U
#define	TYPE_MUX 1U
#define	TYPE_PLL 2U
#define	TYPE_FIXEDFACTOR 3U
#define	TYPE_DIV1 4U
#define	TYPE_DIV2 5U
#define	TYPE_GATE 6U
Rajan Vaja's avatar
Rajan Vaja committed
291

292
293
struct pm_pll;
struct pm_pll *pm_clock_get_pll(enum clock_id clock_id);
294
struct pm_pll *pm_clock_get_pll_by_related_clk(enum clock_id clock_id);
295
uint8_t pm_clock_has_div(unsigned int clock_id, enum pm_clock_div_id div_id);
296
297

enum pm_ret_status pm_api_clock_get_name(unsigned int clock_id, char *name);
298
enum pm_ret_status pm_api_clock_get_num_clocks(unsigned int *nclocks);
299
300
301
302
303
304
305
306
307
308
309
enum pm_ret_status pm_api_clock_get_topology(unsigned int clock_id,
					     unsigned int index,
					     uint32_t *topology);
enum pm_ret_status pm_api_clock_get_fixedfactor_params(unsigned int clock_id,
						       uint32_t *mul,
						       uint32_t *div);
enum pm_ret_status pm_api_clock_get_parents(unsigned int clock_id,
					    unsigned int index,
					    uint32_t *parents);
enum pm_ret_status pm_api_clock_get_attributes(unsigned int clock_id,
					       uint32_t *attr);
310
311
312

enum pm_ret_status pm_clock_get_pll_node_id(enum clock_id clock_id,
					    enum pm_node_id *node_id);
313
enum pm_ret_status pm_clock_id_is_valid(unsigned int clock_id);
314

315
enum pm_ret_status pm_clock_pll_enable(struct pm_pll *pll);
316
enum pm_ret_status pm_clock_pll_disable(struct pm_pll *pll);
317
318
enum pm_ret_status pm_clock_pll_get_state(struct pm_pll *pll,
					  unsigned int *state);
319
320
321
enum pm_ret_status pm_clock_pll_set_parent(struct pm_pll *pll,
					   enum clock_id clock_id,
					   unsigned int parent_index);
322
323
324
enum pm_ret_status pm_clock_pll_get_parent(struct pm_pll *pll,
					   enum clock_id clock_id,
					   unsigned int *parent_index);
325
326
enum pm_ret_status pm_clock_set_pll_mode(enum clock_id clock_id,
					 unsigned int mode);
327
328
enum pm_ret_status pm_clock_get_pll_mode(enum clock_id clock_id,
					 unsigned int *mode);
Rajan Vaja's avatar
Rajan Vaja committed
329

330
#endif /* PM_API_CLOCK_H */