xref: /rk3399_ARM-atf/include/drivers/nxp/clk/s32cc/s32cc-clk-modules.h (revision 29f8a952cbbc7ee91188464cdf01b243735d41f8)
17c36209bSGhennadi Procopciuc /* SPDX-License-Identifier: BSD-3-Clause */
27c36209bSGhennadi Procopciuc /*
3bd691136SGhennadi Procopciuc  * Copyright 2020-2025 NXP
47c36209bSGhennadi Procopciuc  */
57c36209bSGhennadi Procopciuc #ifndef S32CC_CLK_MODULES_H
67c36209bSGhennadi Procopciuc #define S32CC_CLK_MODULES_H
77c36209bSGhennadi Procopciuc 
87c36209bSGhennadi Procopciuc #include <inttypes.h>
912e7a2cdSGhennadi Procopciuc #include <stdbool.h>
107c36209bSGhennadi Procopciuc #include <stddef.h>
117c36209bSGhennadi Procopciuc 
127c36209bSGhennadi Procopciuc #define MHZ	UL(1000000)
137c36209bSGhennadi Procopciuc #define GHZ	(UL(1000) * MHZ)
147c36209bSGhennadi Procopciuc 
157c36209bSGhennadi Procopciuc enum s32cc_clkm_type {
167c36209bSGhennadi Procopciuc 	s32cc_osc_t,
177c36209bSGhennadi Procopciuc 	s32cc_clk_t,
18a8be748aSGhennadi Procopciuc 	s32cc_pll_t,
19a8be748aSGhennadi Procopciuc 	s32cc_pll_out_div_t,
2044ae54afSGhennadi Procopciuc 	s32cc_dfs_t,
2144ae54afSGhennadi Procopciuc 	s32cc_dfs_div_t,
22a8be748aSGhennadi Procopciuc 	s32cc_clkmux_t,
233fa91a94SGhennadi Procopciuc 	s32cc_shared_clkmux_t,
2444e2130aSGhennadi Procopciuc 	s32cc_fixed_div_t,
25af3020e2SGhennadi Procopciuc 	s32cc_part_t,
26af3020e2SGhennadi Procopciuc 	s32cc_part_block_t,
27af3020e2SGhennadi Procopciuc 	s32cc_part_block_link_t,
287c36209bSGhennadi Procopciuc };
297c36209bSGhennadi Procopciuc 
307c36209bSGhennadi Procopciuc enum s32cc_clk_source {
317c36209bSGhennadi Procopciuc 	S32CC_FIRC,
327c36209bSGhennadi Procopciuc 	S32CC_FXOSC,
337c36209bSGhennadi Procopciuc 	S32CC_SIRC,
34a8be748aSGhennadi Procopciuc 	S32CC_ARM_PLL,
3544ae54afSGhennadi Procopciuc 	S32CC_ARM_DFS,
368653352aSGhennadi Procopciuc 	S32CC_PERIPH_PLL,
379dbca85dSGhennadi Procopciuc 	S32CC_CGM0,
383fa91a94SGhennadi Procopciuc 	S32CC_CGM1,
3918c2b137SGhennadi Procopciuc 	S32CC_DDR_PLL,
40*29f8a952SGhennadi Procopciuc 	S32CC_PERIPH_DFS,
414a2ca718SGhennadi Procopciuc 	S32CC_CGM5,
427c36209bSGhennadi Procopciuc };
437c36209bSGhennadi Procopciuc 
447c36209bSGhennadi Procopciuc struct s32cc_clk_obj {
457c36209bSGhennadi Procopciuc 	enum s32cc_clkm_type type;
467c36209bSGhennadi Procopciuc 	uint32_t refcount;
477c36209bSGhennadi Procopciuc };
487c36209bSGhennadi Procopciuc 
497c36209bSGhennadi Procopciuc struct s32cc_osc {
507c36209bSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
517c36209bSGhennadi Procopciuc 	enum s32cc_clk_source source;
527c36209bSGhennadi Procopciuc 	unsigned long freq;
537c36209bSGhennadi Procopciuc 	void *base;
547c36209bSGhennadi Procopciuc };
557c36209bSGhennadi Procopciuc 
56bd691136SGhennadi Procopciuc #define S32CC_OSC_INIT_FREQ(SOURCE, FREQ) \
577c36209bSGhennadi Procopciuc {                                         \
587c36209bSGhennadi Procopciuc 	.desc = {                         \
597c36209bSGhennadi Procopciuc 		.type = s32cc_osc_t,      \
607c36209bSGhennadi Procopciuc 	},                                \
617c36209bSGhennadi Procopciuc 	.source = (SOURCE),               \
62bd691136SGhennadi Procopciuc 	.freq = (FREQ),                   \
637c36209bSGhennadi Procopciuc }
647c36209bSGhennadi Procopciuc 
65bd691136SGhennadi Procopciuc #define S32CC_OSC_INIT(SOURCE) \
66bd691136SGhennadi Procopciuc 	S32CC_OSC_INIT_FREQ(SOURCE, 0)
67bd691136SGhennadi Procopciuc 
68a8be748aSGhennadi Procopciuc struct s32cc_clkmux {
69a8be748aSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
70a8be748aSGhennadi Procopciuc 	enum s32cc_clk_source module;
71a8be748aSGhennadi Procopciuc 	uint8_t index; /* Mux index in parent module */
72a8be748aSGhennadi Procopciuc 	unsigned long source_id; /* Selected source */
73a8be748aSGhennadi Procopciuc 	uint8_t nclks; /* Number of input clocks */
74a8be748aSGhennadi Procopciuc 	unsigned long clkids[5]; /* IDs of the input clocks */
75a8be748aSGhennadi Procopciuc };
76a8be748aSGhennadi Procopciuc 
77a8be748aSGhennadi Procopciuc #define S32CC_CLKMUX_TYPE_INIT(TYPE, MODULE, INDEX, NCLKS, ...) \
78a8be748aSGhennadi Procopciuc {                                                               \
79a8be748aSGhennadi Procopciuc 	.desc = {                                               \
80a8be748aSGhennadi Procopciuc 		.type = (TYPE),                                 \
81a8be748aSGhennadi Procopciuc 	},                                                      \
82a8be748aSGhennadi Procopciuc 	.module = (MODULE),                                     \
83a8be748aSGhennadi Procopciuc 	.index = (INDEX),                                       \
84a8be748aSGhennadi Procopciuc 	.nclks = (NCLKS),                                       \
85a8be748aSGhennadi Procopciuc 	.clkids = {__VA_ARGS__},                                \
86a8be748aSGhennadi Procopciuc }
87a8be748aSGhennadi Procopciuc 
88a8be748aSGhennadi Procopciuc #define S32CC_CLKMUX_INIT(MODULE, INDEX, NCLKS, ...)     \
89a8be748aSGhennadi Procopciuc 	S32CC_CLKMUX_TYPE_INIT(s32cc_clkmux_t, MODULE,   \
90a8be748aSGhennadi Procopciuc 			       INDEX, NCLKS, __VA_ARGS__)
91a8be748aSGhennadi Procopciuc 
923fa91a94SGhennadi Procopciuc #define S32CC_SHARED_CLKMUX_INIT(MODULE, INDEX, NCLKS, ...)   \
933fa91a94SGhennadi Procopciuc 	S32CC_CLKMUX_TYPE_INIT(s32cc_shared_clkmux_t, MODULE, \
943fa91a94SGhennadi Procopciuc 			       INDEX, NCLKS, __VA_ARGS__)
953fa91a94SGhennadi Procopciuc 
96a8be748aSGhennadi Procopciuc struct s32cc_pll {
97a8be748aSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
98a8be748aSGhennadi Procopciuc 	struct s32cc_clk_obj *source;
99a8be748aSGhennadi Procopciuc 	enum s32cc_clk_source instance;
100a8be748aSGhennadi Procopciuc 	unsigned long vco_freq;
101a8be748aSGhennadi Procopciuc 	uint32_t ndividers;
102a8be748aSGhennadi Procopciuc 	uintptr_t base;
103a8be748aSGhennadi Procopciuc };
104a8be748aSGhennadi Procopciuc 
105a8be748aSGhennadi Procopciuc #define S32CC_PLL_INIT(PLL_MUX_CLK, INSTANCE, NDIVIDERS) \
106a8be748aSGhennadi Procopciuc {                                                        \
107a8be748aSGhennadi Procopciuc 	.desc = {                                        \
108a8be748aSGhennadi Procopciuc 		.type = s32cc_pll_t,                     \
109a8be748aSGhennadi Procopciuc 	},                                               \
110a8be748aSGhennadi Procopciuc 	.source = &(PLL_MUX_CLK).desc,                   \
111a8be748aSGhennadi Procopciuc 	.instance = (INSTANCE),                          \
112a8be748aSGhennadi Procopciuc 	.ndividers = (NDIVIDERS),                        \
113a8be748aSGhennadi Procopciuc }
114a8be748aSGhennadi Procopciuc 
115a8be748aSGhennadi Procopciuc struct s32cc_pll_out_div {
116a8be748aSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
117a8be748aSGhennadi Procopciuc 	struct s32cc_clk_obj *parent;
118a8be748aSGhennadi Procopciuc 	uint32_t index;
119a8be748aSGhennadi Procopciuc 	unsigned long freq;
120a8be748aSGhennadi Procopciuc };
121a8be748aSGhennadi Procopciuc 
122a8be748aSGhennadi Procopciuc #define S32CC_PLL_OUT_DIV_INIT(PARENT, INDEX)  \
123a8be748aSGhennadi Procopciuc {                                              \
124a8be748aSGhennadi Procopciuc 	.desc = {                              \
125a8be748aSGhennadi Procopciuc 		.type = s32cc_pll_out_div_t,   \
126a8be748aSGhennadi Procopciuc 	},                                     \
127a8be748aSGhennadi Procopciuc 	.parent = &(PARENT).desc,              \
128a8be748aSGhennadi Procopciuc 	.index = (INDEX),                      \
129a8be748aSGhennadi Procopciuc }
130a8be748aSGhennadi Procopciuc 
13144e2130aSGhennadi Procopciuc #define S32CC_PLL_OUT_DIV_INIT(PARENT, INDEX)  \
13244e2130aSGhennadi Procopciuc {                                              \
13344e2130aSGhennadi Procopciuc 	.desc = {                              \
13444e2130aSGhennadi Procopciuc 		.type = s32cc_pll_out_div_t,   \
13544e2130aSGhennadi Procopciuc 	},                                     \
13644e2130aSGhennadi Procopciuc 	.parent = &(PARENT).desc,              \
13744e2130aSGhennadi Procopciuc 	.index = (INDEX),                      \
13844e2130aSGhennadi Procopciuc }
13944e2130aSGhennadi Procopciuc 
14044ae54afSGhennadi Procopciuc struct s32cc_dfs {
14144ae54afSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
14244ae54afSGhennadi Procopciuc 	struct s32cc_clk_obj *parent;
14344ae54afSGhennadi Procopciuc 	enum s32cc_clk_source instance;
14444ae54afSGhennadi Procopciuc 	uintptr_t base;
14544ae54afSGhennadi Procopciuc };
14644ae54afSGhennadi Procopciuc 
14744ae54afSGhennadi Procopciuc #define S32CC_DFS_INIT(PARENT, INSTANCE) \
14844ae54afSGhennadi Procopciuc {                                        \
14944ae54afSGhennadi Procopciuc 	.desc = {                        \
15044ae54afSGhennadi Procopciuc 		.type = s32cc_dfs_t,     \
15144ae54afSGhennadi Procopciuc 	},                               \
15244ae54afSGhennadi Procopciuc 	.parent = &(PARENT).desc,        \
15344ae54afSGhennadi Procopciuc 	.instance = (INSTANCE),          \
15444ae54afSGhennadi Procopciuc }
15544ae54afSGhennadi Procopciuc 
15644ae54afSGhennadi Procopciuc struct s32cc_dfs_div {
15744ae54afSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
15844ae54afSGhennadi Procopciuc 	struct s32cc_clk_obj *parent;
15944ae54afSGhennadi Procopciuc 	uint32_t index;
16044ae54afSGhennadi Procopciuc 	unsigned long freq;
16144ae54afSGhennadi Procopciuc };
16244ae54afSGhennadi Procopciuc 
16344ae54afSGhennadi Procopciuc #define S32CC_DFS_DIV_INIT(PARENT, INDEX) \
16444ae54afSGhennadi Procopciuc {                                         \
16544ae54afSGhennadi Procopciuc 	.desc = {                         \
16644ae54afSGhennadi Procopciuc 		.type = s32cc_dfs_div_t,  \
16744ae54afSGhennadi Procopciuc 	},                                \
16844ae54afSGhennadi Procopciuc 	.parent = &(PARENT).desc,         \
16944ae54afSGhennadi Procopciuc 	.index = (INDEX),                 \
17044ae54afSGhennadi Procopciuc }
17144ae54afSGhennadi Procopciuc 
17244e2130aSGhennadi Procopciuc struct s32cc_fixed_div {
17344e2130aSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
17444e2130aSGhennadi Procopciuc 	struct s32cc_clk_obj *parent;
17544e2130aSGhennadi Procopciuc 	uint32_t rate_div;
17644e2130aSGhennadi Procopciuc };
17744e2130aSGhennadi Procopciuc 
17844e2130aSGhennadi Procopciuc #define S32CC_FIXED_DIV_INIT(PARENT, RATE_DIV) \
17944e2130aSGhennadi Procopciuc {                                              \
18044e2130aSGhennadi Procopciuc 	.desc = {                              \
18144e2130aSGhennadi Procopciuc 		.type = s32cc_fixed_div_t,     \
18244e2130aSGhennadi Procopciuc 	},                                     \
18344e2130aSGhennadi Procopciuc 	.parent = &(PARENT).desc,              \
18444e2130aSGhennadi Procopciuc 	.rate_div = (RATE_DIV),                \
18544e2130aSGhennadi Procopciuc }
18644e2130aSGhennadi Procopciuc 
1877c36209bSGhennadi Procopciuc struct s32cc_clk {
1887c36209bSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
1897c36209bSGhennadi Procopciuc 	struct s32cc_clk_obj *module;
1907c36209bSGhennadi Procopciuc 	struct s32cc_clk *pclock;
1917c36209bSGhennadi Procopciuc 	unsigned long min_freq;
1927c36209bSGhennadi Procopciuc 	unsigned long max_freq;
1937c36209bSGhennadi Procopciuc };
1947c36209bSGhennadi Procopciuc 
1957c36209bSGhennadi Procopciuc struct s32cc_clk_array {
1967c36209bSGhennadi Procopciuc 	unsigned long type_mask;
1977c36209bSGhennadi Procopciuc 	struct s32cc_clk **clks;
1987c36209bSGhennadi Procopciuc 	size_t n_clks;
1997c36209bSGhennadi Procopciuc };
2007c36209bSGhennadi Procopciuc 
20144ae54afSGhennadi Procopciuc #define S32CC_FREQ_CLK(PARENT_MODULE, PARENT, MIN_F, MAX_F) \
2027c36209bSGhennadi Procopciuc {                                                           \
2037c36209bSGhennadi Procopciuc 	.desc = {                                           \
2047c36209bSGhennadi Procopciuc 		.type = s32cc_clk_t,                        \
2057c36209bSGhennadi Procopciuc 	},                                                  \
20644ae54afSGhennadi Procopciuc 	.pclock = (PARENT),                                 \
20744ae54afSGhennadi Procopciuc 	.module = (PARENT_MODULE),                          \
2087c36209bSGhennadi Procopciuc 	.min_freq = (MIN_F),                                \
2097c36209bSGhennadi Procopciuc 	.max_freq = (MAX_F),                                \
2107c36209bSGhennadi Procopciuc }
2117c36209bSGhennadi Procopciuc 
2127c36209bSGhennadi Procopciuc #define S32CC_FREQ_MODULE_CLK(PARENT_MODULE, MIN_F, MAX_F) \
21344ae54afSGhennadi Procopciuc 	S32CC_FREQ_CLK(&(PARENT_MODULE).desc, NULL, MIN_F, MAX_F)
2147c36209bSGhennadi Procopciuc 
2157c36209bSGhennadi Procopciuc #define S32CC_MODULE_CLK(PARENT_MODULE) \
2167c36209bSGhennadi Procopciuc 	S32CC_FREQ_MODULE_CLK(PARENT_MODULE, 0, 0)
2177c36209bSGhennadi Procopciuc 
21844ae54afSGhennadi Procopciuc #define S32CC_CHILD_CLK(PARENT, MIN_F, MAX_F) \
21944ae54afSGhennadi Procopciuc 	S32CC_FREQ_CLK(NULL, &(PARENT), MIN_F, MAX_F)
22044ae54afSGhennadi Procopciuc 
221af3020e2SGhennadi Procopciuc struct s32cc_part {
222af3020e2SGhennadi Procopciuc 	struct s32cc_clk_obj desc;
223af3020e2SGhennadi Procopciuc 	uint32_t partition_id;
224af3020e2SGhennadi Procopciuc };
225af3020e2SGhennadi Procopciuc 
226af3020e2SGhennadi Procopciuc #define S32CC_PART(PART_NUM)          \
227af3020e2SGhennadi Procopciuc {                                     \
228af3020e2SGhennadi Procopciuc 	.desc = {                     \
229af3020e2SGhennadi Procopciuc 		.type = s32cc_part_t, \
230af3020e2SGhennadi Procopciuc 	},                            \
231af3020e2SGhennadi Procopciuc 	.partition_id = (PART_NUM),   \
232af3020e2SGhennadi Procopciuc }
233af3020e2SGhennadi Procopciuc 
234af3020e2SGhennadi Procopciuc enum s32cc_part_block_type {
235af3020e2SGhennadi Procopciuc 	s32cc_part_block0,
236af3020e2SGhennadi Procopciuc 	s32cc_part_block1,
237af3020e2SGhennadi Procopciuc 	s32cc_part_block2,
238af3020e2SGhennadi Procopciuc 	s32cc_part_block3,
239af3020e2SGhennadi Procopciuc 	s32cc_part_block4,
240af3020e2SGhennadi Procopciuc 	s32cc_part_block5,
241af3020e2SGhennadi Procopciuc 	s32cc_part_block6,
242af3020e2SGhennadi Procopciuc 	s32cc_part_block7,
243af3020e2SGhennadi Procopciuc 	s32cc_part_block8,
244af3020e2SGhennadi Procopciuc 	s32cc_part_block9,
245af3020e2SGhennadi Procopciuc 	s32cc_part_block10,
246af3020e2SGhennadi Procopciuc 	s32cc_part_block11,
247af3020e2SGhennadi Procopciuc 	s32cc_part_block12,
248af3020e2SGhennadi Procopciuc 	s32cc_part_block13,
249af3020e2SGhennadi Procopciuc 	s32cc_part_block14,
250af3020e2SGhennadi Procopciuc 	s32cc_part_block15,
251af3020e2SGhennadi Procopciuc };
252af3020e2SGhennadi Procopciuc 
253af3020e2SGhennadi Procopciuc struct s32cc_part_block {
254af3020e2SGhennadi Procopciuc 	struct s32cc_clk_obj desc;
255af3020e2SGhennadi Procopciuc 	struct s32cc_part *part;
256af3020e2SGhennadi Procopciuc 	enum s32cc_part_block_type block;
257af3020e2SGhennadi Procopciuc 	bool status;
258af3020e2SGhennadi Procopciuc };
259af3020e2SGhennadi Procopciuc 
260af3020e2SGhennadi Procopciuc #define S32CC_PART_BLOCK_STATUS(PART_META, BLOCK_TYPE, STATUS) \
261af3020e2SGhennadi Procopciuc {                                                              \
262af3020e2SGhennadi Procopciuc 	.desc = {                                              \
263af3020e2SGhennadi Procopciuc 		.type = s32cc_part_block_t,                    \
264af3020e2SGhennadi Procopciuc 	},                                                     \
265af3020e2SGhennadi Procopciuc 	.part = (PART_META),                                   \
266af3020e2SGhennadi Procopciuc 	.block = (BLOCK_TYPE),                                 \
267af3020e2SGhennadi Procopciuc 	.status = (STATUS),                                    \
268af3020e2SGhennadi Procopciuc }
269af3020e2SGhennadi Procopciuc 
270af3020e2SGhennadi Procopciuc #define S32CC_PART_BLOCK(PARENT, BLOCK_TYPE) \
271af3020e2SGhennadi Procopciuc 	S32CC_PART_BLOCK_STATUS(PARENT, BLOCK_TYPE, true)
272af3020e2SGhennadi Procopciuc 
273af3020e2SGhennadi Procopciuc #define S32CC_PART_BLOCK_NO_STATUS(PARENT, BLOCK_TYPE) \
274af3020e2SGhennadi Procopciuc 	S32CC_PART_BLOCK_STATUS(PARENT, BLOCK_TYPE, false)
275af3020e2SGhennadi Procopciuc 
276af3020e2SGhennadi Procopciuc struct s32cc_part_block_link {
277af3020e2SGhennadi Procopciuc 	struct s32cc_clk_obj desc;
278af3020e2SGhennadi Procopciuc 	struct s32cc_clk_obj *parent;
279af3020e2SGhennadi Procopciuc 	struct s32cc_part_block *block;
280af3020e2SGhennadi Procopciuc };
281af3020e2SGhennadi Procopciuc 
282af3020e2SGhennadi Procopciuc #define S32CC_PART_BLOCK_LINK(PARENT, BLOCK)     \
283af3020e2SGhennadi Procopciuc {                                                \
284af3020e2SGhennadi Procopciuc 	.desc = {                                \
285af3020e2SGhennadi Procopciuc 		.type = s32cc_part_block_link_t, \
286af3020e2SGhennadi Procopciuc 	},                                       \
287af3020e2SGhennadi Procopciuc 	.parent = &(PARENT).desc,                \
288af3020e2SGhennadi Procopciuc 	.block = (BLOCK),                        \
289af3020e2SGhennadi Procopciuc }
290af3020e2SGhennadi Procopciuc 
291d9373519SGhennadi Procopciuc static inline struct s32cc_osc *s32cc_obj2osc(const struct s32cc_clk_obj *mod)
292d9373519SGhennadi Procopciuc {
293d9373519SGhennadi Procopciuc 	uintptr_t osc_addr;
294d9373519SGhennadi Procopciuc 
295d9373519SGhennadi Procopciuc 	osc_addr = ((uintptr_t)mod) - offsetof(struct s32cc_osc, desc);
296d9373519SGhennadi Procopciuc 	return (struct s32cc_osc *)osc_addr;
297d9373519SGhennadi Procopciuc }
298d9373519SGhennadi Procopciuc 
299d9373519SGhennadi Procopciuc static inline struct s32cc_clk *s32cc_obj2clk(const struct s32cc_clk_obj *mod)
300d9373519SGhennadi Procopciuc {
301d9373519SGhennadi Procopciuc 	uintptr_t clk_addr;
302d9373519SGhennadi Procopciuc 
303d9373519SGhennadi Procopciuc 	clk_addr = ((uintptr_t)mod) - offsetof(struct s32cc_clk, desc);
304d9373519SGhennadi Procopciuc 	return (struct s32cc_clk *)clk_addr;
305d9373519SGhennadi Procopciuc }
306d9373519SGhennadi Procopciuc 
30712e7a2cdSGhennadi Procopciuc static inline bool is_s32cc_clk_mux(const struct s32cc_clk *clk)
30812e7a2cdSGhennadi Procopciuc {
30912e7a2cdSGhennadi Procopciuc 	const struct s32cc_clk_obj *module;
31012e7a2cdSGhennadi Procopciuc 
31112e7a2cdSGhennadi Procopciuc 	module = clk->module;
31212e7a2cdSGhennadi Procopciuc 	if (module == NULL) {
31312e7a2cdSGhennadi Procopciuc 		return false;
31412e7a2cdSGhennadi Procopciuc 	}
31512e7a2cdSGhennadi Procopciuc 
3163fa91a94SGhennadi Procopciuc 	return (module->type == s32cc_clkmux_t) ||
3173fa91a94SGhennadi Procopciuc 	    (module->type == s32cc_shared_clkmux_t);
31812e7a2cdSGhennadi Procopciuc }
31912e7a2cdSGhennadi Procopciuc 
32012e7a2cdSGhennadi Procopciuc static inline struct s32cc_clkmux *s32cc_obj2clkmux(const struct s32cc_clk_obj *mod)
32112e7a2cdSGhennadi Procopciuc {
32212e7a2cdSGhennadi Procopciuc 	uintptr_t cmux_addr;
32312e7a2cdSGhennadi Procopciuc 
32412e7a2cdSGhennadi Procopciuc 	cmux_addr = ((uintptr_t)mod) - offsetof(struct s32cc_clkmux, desc);
32512e7a2cdSGhennadi Procopciuc 	return (struct s32cc_clkmux *)cmux_addr;
32612e7a2cdSGhennadi Procopciuc }
32712e7a2cdSGhennadi Procopciuc 
32812e7a2cdSGhennadi Procopciuc static inline struct s32cc_clkmux *s32cc_clk2mux(const struct s32cc_clk *clk)
32912e7a2cdSGhennadi Procopciuc {
33012e7a2cdSGhennadi Procopciuc 	if (!is_s32cc_clk_mux(clk)) {
33112e7a2cdSGhennadi Procopciuc 		return NULL;
33212e7a2cdSGhennadi Procopciuc 	}
33312e7a2cdSGhennadi Procopciuc 
33412e7a2cdSGhennadi Procopciuc 	return s32cc_obj2clkmux(clk->module);
33512e7a2cdSGhennadi Procopciuc }
33612e7a2cdSGhennadi Procopciuc 
3377ad4e231SGhennadi Procopciuc static inline struct s32cc_pll *s32cc_obj2pll(const struct s32cc_clk_obj *mod)
3387ad4e231SGhennadi Procopciuc {
3397ad4e231SGhennadi Procopciuc 	uintptr_t pll_addr;
3407ad4e231SGhennadi Procopciuc 
3417ad4e231SGhennadi Procopciuc 	pll_addr = ((uintptr_t)mod) - offsetof(struct s32cc_pll, desc);
3427ad4e231SGhennadi Procopciuc 	return (struct s32cc_pll *)pll_addr;
3437ad4e231SGhennadi Procopciuc }
3447ad4e231SGhennadi Procopciuc 
345de950ef0SGhennadi Procopciuc static inline struct s32cc_pll_out_div *s32cc_obj2plldiv(const struct s32cc_clk_obj *mod)
346de950ef0SGhennadi Procopciuc {
347de950ef0SGhennadi Procopciuc 	uintptr_t plldiv_addr;
348de950ef0SGhennadi Procopciuc 
349de950ef0SGhennadi Procopciuc 	plldiv_addr = ((uintptr_t)mod) - offsetof(struct s32cc_pll_out_div, desc);
350de950ef0SGhennadi Procopciuc 	return (struct s32cc_pll_out_div *)plldiv_addr;
351de950ef0SGhennadi Procopciuc }
352de950ef0SGhennadi Procopciuc 
35365739db2SGhennadi Procopciuc static inline struct s32cc_fixed_div *s32cc_obj2fixeddiv(const struct s32cc_clk_obj *mod)
35465739db2SGhennadi Procopciuc {
35565739db2SGhennadi Procopciuc 	uintptr_t fdiv_addr;
35665739db2SGhennadi Procopciuc 
35765739db2SGhennadi Procopciuc 	fdiv_addr = ((uintptr_t)mod) - offsetof(struct s32cc_fixed_div, desc);
35865739db2SGhennadi Procopciuc 	return (struct s32cc_fixed_div *)fdiv_addr;
35965739db2SGhennadi Procopciuc }
36065739db2SGhennadi Procopciuc 
36144ae54afSGhennadi Procopciuc static inline struct s32cc_dfs *s32cc_obj2dfs(const struct s32cc_clk_obj *mod)
36244ae54afSGhennadi Procopciuc {
36344ae54afSGhennadi Procopciuc 	uintptr_t dfs_addr;
36444ae54afSGhennadi Procopciuc 
36544ae54afSGhennadi Procopciuc 	dfs_addr = ((uintptr_t)mod) - offsetof(struct s32cc_dfs, desc);
36644ae54afSGhennadi Procopciuc 	return (struct s32cc_dfs *)dfs_addr;
36744ae54afSGhennadi Procopciuc }
36844ae54afSGhennadi Procopciuc 
36944ae54afSGhennadi Procopciuc static inline struct s32cc_dfs_div *s32cc_obj2dfsdiv(const struct s32cc_clk_obj *mod)
37044ae54afSGhennadi Procopciuc {
37144ae54afSGhennadi Procopciuc 	uintptr_t dfs_div_addr;
37244ae54afSGhennadi Procopciuc 
37344ae54afSGhennadi Procopciuc 	dfs_div_addr = ((uintptr_t)mod) - offsetof(struct s32cc_dfs_div, desc);
37444ae54afSGhennadi Procopciuc 	return (struct s32cc_dfs_div *)dfs_div_addr;
37544ae54afSGhennadi Procopciuc }
37644ae54afSGhennadi Procopciuc 
377af3020e2SGhennadi Procopciuc static inline struct s32cc_part *s32cc_obj2part(const struct s32cc_clk_obj *mod)
378af3020e2SGhennadi Procopciuc {
379af3020e2SGhennadi Procopciuc 	uintptr_t part_addr;
380af3020e2SGhennadi Procopciuc 
381af3020e2SGhennadi Procopciuc 	part_addr = ((uintptr_t)mod) - offsetof(struct s32cc_part, desc);
382af3020e2SGhennadi Procopciuc 	return (struct s32cc_part *)part_addr;
383af3020e2SGhennadi Procopciuc }
384af3020e2SGhennadi Procopciuc 
385af3020e2SGhennadi Procopciuc static inline struct s32cc_part_block *
386af3020e2SGhennadi Procopciuc s32cc_obj2partblock(const struct s32cc_clk_obj *mod)
387af3020e2SGhennadi Procopciuc {
388af3020e2SGhennadi Procopciuc 	uintptr_t part_blk_addr;
389af3020e2SGhennadi Procopciuc 
390af3020e2SGhennadi Procopciuc 	part_blk_addr = ((uintptr_t)mod) - offsetof(struct s32cc_part_block, desc);
391af3020e2SGhennadi Procopciuc 	return (struct s32cc_part_block *)part_blk_addr;
392af3020e2SGhennadi Procopciuc }
393af3020e2SGhennadi Procopciuc 
394af3020e2SGhennadi Procopciuc static inline struct s32cc_part_block_link *
395af3020e2SGhennadi Procopciuc s32cc_obj2partblocklink(const struct s32cc_clk_obj *mod)
396af3020e2SGhennadi Procopciuc {
397af3020e2SGhennadi Procopciuc 	uintptr_t blk_link;
398af3020e2SGhennadi Procopciuc 
399af3020e2SGhennadi Procopciuc 	blk_link = ((uintptr_t)mod) - offsetof(struct s32cc_part_block_link, desc);
400af3020e2SGhennadi Procopciuc 	return (struct s32cc_part_block_link *)blk_link;
401af3020e2SGhennadi Procopciuc }
402af3020e2SGhennadi Procopciuc 
4037c36209bSGhennadi Procopciuc #endif /* S32CC_CLK_MODULES_H */
404