xref: /rk3399_ARM-atf/include/drivers/nxp/clk/s32cc/s32cc-clk-modules.h (revision af3020e2ae86b71a87d936bb5e7181393874d708)
17c36209bSGhennadi Procopciuc /* SPDX-License-Identifier: BSD-3-Clause */
27c36209bSGhennadi Procopciuc /*
37c36209bSGhennadi Procopciuc  * Copyright 2020-2024 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,
25*af3020e2SGhennadi Procopciuc 	s32cc_part_t,
26*af3020e2SGhennadi Procopciuc 	s32cc_part_block_t,
27*af3020e2SGhennadi 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,
397c36209bSGhennadi Procopciuc };
407c36209bSGhennadi Procopciuc 
417c36209bSGhennadi Procopciuc struct s32cc_clk_obj {
427c36209bSGhennadi Procopciuc 	enum s32cc_clkm_type type;
437c36209bSGhennadi Procopciuc 	uint32_t refcount;
447c36209bSGhennadi Procopciuc };
457c36209bSGhennadi Procopciuc 
467c36209bSGhennadi Procopciuc struct s32cc_osc {
477c36209bSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
487c36209bSGhennadi Procopciuc 	enum s32cc_clk_source source;
497c36209bSGhennadi Procopciuc 	unsigned long freq;
507c36209bSGhennadi Procopciuc 	void *base;
517c36209bSGhennadi Procopciuc };
527c36209bSGhennadi Procopciuc 
537c36209bSGhennadi Procopciuc #define S32CC_OSC_INIT(SOURCE)       \
547c36209bSGhennadi Procopciuc {                                    \
557c36209bSGhennadi Procopciuc 	.desc = {                    \
567c36209bSGhennadi Procopciuc 		.type = s32cc_osc_t, \
577c36209bSGhennadi Procopciuc 	},                           \
587c36209bSGhennadi Procopciuc 	.source = (SOURCE),          \
597c36209bSGhennadi Procopciuc }
607c36209bSGhennadi Procopciuc 
61a8be748aSGhennadi Procopciuc struct s32cc_clkmux {
62a8be748aSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
63a8be748aSGhennadi Procopciuc 	enum s32cc_clk_source module;
64a8be748aSGhennadi Procopciuc 	uint8_t index; /* Mux index in parent module */
65a8be748aSGhennadi Procopciuc 	unsigned long source_id; /* Selected source */
66a8be748aSGhennadi Procopciuc 	uint8_t nclks; /* Number of input clocks */
67a8be748aSGhennadi Procopciuc 	unsigned long clkids[5]; /* IDs of the input clocks */
68a8be748aSGhennadi Procopciuc };
69a8be748aSGhennadi Procopciuc 
70a8be748aSGhennadi Procopciuc #define S32CC_CLKMUX_TYPE_INIT(TYPE, MODULE, INDEX, NCLKS, ...) \
71a8be748aSGhennadi Procopciuc {                                                               \
72a8be748aSGhennadi Procopciuc 	.desc = {                                               \
73a8be748aSGhennadi Procopciuc 		.type = (TYPE),                                 \
74a8be748aSGhennadi Procopciuc 	},                                                      \
75a8be748aSGhennadi Procopciuc 	.module = (MODULE),                                     \
76a8be748aSGhennadi Procopciuc 	.index = (INDEX),                                       \
77a8be748aSGhennadi Procopciuc 	.nclks = (NCLKS),                                       \
78a8be748aSGhennadi Procopciuc 	.clkids = {__VA_ARGS__},                                \
79a8be748aSGhennadi Procopciuc }
80a8be748aSGhennadi Procopciuc 
81a8be748aSGhennadi Procopciuc #define S32CC_CLKMUX_INIT(MODULE, INDEX, NCLKS, ...)     \
82a8be748aSGhennadi Procopciuc 	S32CC_CLKMUX_TYPE_INIT(s32cc_clkmux_t, MODULE,   \
83a8be748aSGhennadi Procopciuc 			       INDEX, NCLKS, __VA_ARGS__)
84a8be748aSGhennadi Procopciuc 
853fa91a94SGhennadi Procopciuc #define S32CC_SHARED_CLKMUX_INIT(MODULE, INDEX, NCLKS, ...)   \
863fa91a94SGhennadi Procopciuc 	S32CC_CLKMUX_TYPE_INIT(s32cc_shared_clkmux_t, MODULE, \
873fa91a94SGhennadi Procopciuc 			       INDEX, NCLKS, __VA_ARGS__)
883fa91a94SGhennadi Procopciuc 
89a8be748aSGhennadi Procopciuc struct s32cc_pll {
90a8be748aSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
91a8be748aSGhennadi Procopciuc 	struct s32cc_clk_obj *source;
92a8be748aSGhennadi Procopciuc 	enum s32cc_clk_source instance;
93a8be748aSGhennadi Procopciuc 	unsigned long vco_freq;
94a8be748aSGhennadi Procopciuc 	uint32_t ndividers;
95a8be748aSGhennadi Procopciuc 	uintptr_t base;
96a8be748aSGhennadi Procopciuc };
97a8be748aSGhennadi Procopciuc 
98a8be748aSGhennadi Procopciuc #define S32CC_PLL_INIT(PLL_MUX_CLK, INSTANCE, NDIVIDERS) \
99a8be748aSGhennadi Procopciuc {                                                        \
100a8be748aSGhennadi Procopciuc 	.desc = {                                        \
101a8be748aSGhennadi Procopciuc 		.type = s32cc_pll_t,                     \
102a8be748aSGhennadi Procopciuc 	},                                               \
103a8be748aSGhennadi Procopciuc 	.source = &(PLL_MUX_CLK).desc,                   \
104a8be748aSGhennadi Procopciuc 	.instance = (INSTANCE),                          \
105a8be748aSGhennadi Procopciuc 	.ndividers = (NDIVIDERS),                        \
106a8be748aSGhennadi Procopciuc }
107a8be748aSGhennadi Procopciuc 
108a8be748aSGhennadi Procopciuc struct s32cc_pll_out_div {
109a8be748aSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
110a8be748aSGhennadi Procopciuc 	struct s32cc_clk_obj *parent;
111a8be748aSGhennadi Procopciuc 	uint32_t index;
112a8be748aSGhennadi Procopciuc 	unsigned long freq;
113a8be748aSGhennadi Procopciuc };
114a8be748aSGhennadi Procopciuc 
115a8be748aSGhennadi Procopciuc #define S32CC_PLL_OUT_DIV_INIT(PARENT, INDEX)  \
116a8be748aSGhennadi Procopciuc {                                              \
117a8be748aSGhennadi Procopciuc 	.desc = {                              \
118a8be748aSGhennadi Procopciuc 		.type = s32cc_pll_out_div_t,   \
119a8be748aSGhennadi Procopciuc 	},                                     \
120a8be748aSGhennadi Procopciuc 	.parent = &(PARENT).desc,              \
121a8be748aSGhennadi Procopciuc 	.index = (INDEX),                      \
122a8be748aSGhennadi Procopciuc }
123a8be748aSGhennadi Procopciuc 
12444e2130aSGhennadi Procopciuc #define S32CC_PLL_OUT_DIV_INIT(PARENT, INDEX)  \
12544e2130aSGhennadi Procopciuc {                                              \
12644e2130aSGhennadi Procopciuc 	.desc = {                              \
12744e2130aSGhennadi Procopciuc 		.type = s32cc_pll_out_div_t,   \
12844e2130aSGhennadi Procopciuc 	},                                     \
12944e2130aSGhennadi Procopciuc 	.parent = &(PARENT).desc,              \
13044e2130aSGhennadi Procopciuc 	.index = (INDEX),                      \
13144e2130aSGhennadi Procopciuc }
13244e2130aSGhennadi Procopciuc 
13344ae54afSGhennadi Procopciuc struct s32cc_dfs {
13444ae54afSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
13544ae54afSGhennadi Procopciuc 	struct s32cc_clk_obj *parent;
13644ae54afSGhennadi Procopciuc 	enum s32cc_clk_source instance;
13744ae54afSGhennadi Procopciuc 	uintptr_t base;
13844ae54afSGhennadi Procopciuc };
13944ae54afSGhennadi Procopciuc 
14044ae54afSGhennadi Procopciuc #define S32CC_DFS_INIT(PARENT, INSTANCE) \
14144ae54afSGhennadi Procopciuc {                                        \
14244ae54afSGhennadi Procopciuc 	.desc = {                        \
14344ae54afSGhennadi Procopciuc 		.type = s32cc_dfs_t,     \
14444ae54afSGhennadi Procopciuc 	},                               \
14544ae54afSGhennadi Procopciuc 	.parent = &(PARENT).desc,        \
14644ae54afSGhennadi Procopciuc 	.instance = (INSTANCE),          \
14744ae54afSGhennadi Procopciuc }
14844ae54afSGhennadi Procopciuc 
14944ae54afSGhennadi Procopciuc struct s32cc_dfs_div {
15044ae54afSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
15144ae54afSGhennadi Procopciuc 	struct s32cc_clk_obj *parent;
15244ae54afSGhennadi Procopciuc 	uint32_t index;
15344ae54afSGhennadi Procopciuc 	unsigned long freq;
15444ae54afSGhennadi Procopciuc };
15544ae54afSGhennadi Procopciuc 
15644ae54afSGhennadi Procopciuc #define S32CC_DFS_DIV_INIT(PARENT, INDEX) \
15744ae54afSGhennadi Procopciuc {                                         \
15844ae54afSGhennadi Procopciuc 	.desc = {                         \
15944ae54afSGhennadi Procopciuc 		.type = s32cc_dfs_div_t,  \
16044ae54afSGhennadi Procopciuc 	},                                \
16144ae54afSGhennadi Procopciuc 	.parent = &(PARENT).desc,         \
16244ae54afSGhennadi Procopciuc 	.index = (INDEX),                 \
16344ae54afSGhennadi Procopciuc }
16444ae54afSGhennadi Procopciuc 
16544e2130aSGhennadi Procopciuc struct s32cc_fixed_div {
16644e2130aSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
16744e2130aSGhennadi Procopciuc 	struct s32cc_clk_obj *parent;
16844e2130aSGhennadi Procopciuc 	uint32_t rate_div;
16944e2130aSGhennadi Procopciuc };
17044e2130aSGhennadi Procopciuc 
17144e2130aSGhennadi Procopciuc #define S32CC_FIXED_DIV_INIT(PARENT, RATE_DIV) \
17244e2130aSGhennadi Procopciuc {                                              \
17344e2130aSGhennadi Procopciuc 	.desc = {                              \
17444e2130aSGhennadi Procopciuc 		.type = s32cc_fixed_div_t,     \
17544e2130aSGhennadi Procopciuc 	},                                     \
17644e2130aSGhennadi Procopciuc 	.parent = &(PARENT).desc,              \
17744e2130aSGhennadi Procopciuc 	.rate_div = (RATE_DIV),                \
17844e2130aSGhennadi Procopciuc }
17944e2130aSGhennadi Procopciuc 
1807c36209bSGhennadi Procopciuc struct s32cc_clk {
1817c36209bSGhennadi Procopciuc 	struct s32cc_clk_obj desc;
1827c36209bSGhennadi Procopciuc 	struct s32cc_clk_obj *module;
1837c36209bSGhennadi Procopciuc 	struct s32cc_clk *pclock;
1847c36209bSGhennadi Procopciuc 	unsigned long min_freq;
1857c36209bSGhennadi Procopciuc 	unsigned long max_freq;
1867c36209bSGhennadi Procopciuc };
1877c36209bSGhennadi Procopciuc 
1887c36209bSGhennadi Procopciuc struct s32cc_clk_array {
1897c36209bSGhennadi Procopciuc 	unsigned long type_mask;
1907c36209bSGhennadi Procopciuc 	struct s32cc_clk **clks;
1917c36209bSGhennadi Procopciuc 	size_t n_clks;
1927c36209bSGhennadi Procopciuc };
1937c36209bSGhennadi Procopciuc 
19444ae54afSGhennadi Procopciuc #define S32CC_FREQ_CLK(PARENT_MODULE, PARENT, MIN_F, MAX_F) \
1957c36209bSGhennadi Procopciuc {                                                           \
1967c36209bSGhennadi Procopciuc 	.desc = {                                           \
1977c36209bSGhennadi Procopciuc 		.type = s32cc_clk_t,                        \
1987c36209bSGhennadi Procopciuc 	},                                                  \
19944ae54afSGhennadi Procopciuc 	.pclock = (PARENT),                                 \
20044ae54afSGhennadi Procopciuc 	.module = (PARENT_MODULE),                          \
2017c36209bSGhennadi Procopciuc 	.min_freq = (MIN_F),                                \
2027c36209bSGhennadi Procopciuc 	.max_freq = (MAX_F),                                \
2037c36209bSGhennadi Procopciuc }
2047c36209bSGhennadi Procopciuc 
2057c36209bSGhennadi Procopciuc #define S32CC_FREQ_MODULE_CLK(PARENT_MODULE, MIN_F, MAX_F) \
20644ae54afSGhennadi Procopciuc 	S32CC_FREQ_CLK(&(PARENT_MODULE).desc, NULL, MIN_F, MAX_F)
2077c36209bSGhennadi Procopciuc 
2087c36209bSGhennadi Procopciuc #define S32CC_MODULE_CLK(PARENT_MODULE) \
2097c36209bSGhennadi Procopciuc 	S32CC_FREQ_MODULE_CLK(PARENT_MODULE, 0, 0)
2107c36209bSGhennadi Procopciuc 
21144ae54afSGhennadi Procopciuc #define S32CC_CHILD_CLK(PARENT, MIN_F, MAX_F) \
21244ae54afSGhennadi Procopciuc 	S32CC_FREQ_CLK(NULL, &(PARENT), MIN_F, MAX_F)
21344ae54afSGhennadi Procopciuc 
214*af3020e2SGhennadi Procopciuc struct s32cc_part {
215*af3020e2SGhennadi Procopciuc 	struct s32cc_clk_obj desc;
216*af3020e2SGhennadi Procopciuc 	uint32_t partition_id;
217*af3020e2SGhennadi Procopciuc };
218*af3020e2SGhennadi Procopciuc 
219*af3020e2SGhennadi Procopciuc #define S32CC_PART(PART_NUM)          \
220*af3020e2SGhennadi Procopciuc {                                     \
221*af3020e2SGhennadi Procopciuc 	.desc = {                     \
222*af3020e2SGhennadi Procopciuc 		.type = s32cc_part_t, \
223*af3020e2SGhennadi Procopciuc 	},                            \
224*af3020e2SGhennadi Procopciuc 	.partition_id = (PART_NUM),   \
225*af3020e2SGhennadi Procopciuc }
226*af3020e2SGhennadi Procopciuc 
227*af3020e2SGhennadi Procopciuc enum s32cc_part_block_type {
228*af3020e2SGhennadi Procopciuc 	s32cc_part_block0,
229*af3020e2SGhennadi Procopciuc 	s32cc_part_block1,
230*af3020e2SGhennadi Procopciuc 	s32cc_part_block2,
231*af3020e2SGhennadi Procopciuc 	s32cc_part_block3,
232*af3020e2SGhennadi Procopciuc 	s32cc_part_block4,
233*af3020e2SGhennadi Procopciuc 	s32cc_part_block5,
234*af3020e2SGhennadi Procopciuc 	s32cc_part_block6,
235*af3020e2SGhennadi Procopciuc 	s32cc_part_block7,
236*af3020e2SGhennadi Procopciuc 	s32cc_part_block8,
237*af3020e2SGhennadi Procopciuc 	s32cc_part_block9,
238*af3020e2SGhennadi Procopciuc 	s32cc_part_block10,
239*af3020e2SGhennadi Procopciuc 	s32cc_part_block11,
240*af3020e2SGhennadi Procopciuc 	s32cc_part_block12,
241*af3020e2SGhennadi Procopciuc 	s32cc_part_block13,
242*af3020e2SGhennadi Procopciuc 	s32cc_part_block14,
243*af3020e2SGhennadi Procopciuc 	s32cc_part_block15,
244*af3020e2SGhennadi Procopciuc };
245*af3020e2SGhennadi Procopciuc 
246*af3020e2SGhennadi Procopciuc struct s32cc_part_block {
247*af3020e2SGhennadi Procopciuc 	struct s32cc_clk_obj desc;
248*af3020e2SGhennadi Procopciuc 	struct s32cc_part *part;
249*af3020e2SGhennadi Procopciuc 	enum s32cc_part_block_type block;
250*af3020e2SGhennadi Procopciuc 	bool status;
251*af3020e2SGhennadi Procopciuc };
252*af3020e2SGhennadi Procopciuc 
253*af3020e2SGhennadi Procopciuc #define S32CC_PART_BLOCK_STATUS(PART_META, BLOCK_TYPE, STATUS) \
254*af3020e2SGhennadi Procopciuc {                                                              \
255*af3020e2SGhennadi Procopciuc 	.desc = {                                              \
256*af3020e2SGhennadi Procopciuc 		.type = s32cc_part_block_t,                    \
257*af3020e2SGhennadi Procopciuc 	},                                                     \
258*af3020e2SGhennadi Procopciuc 	.part = (PART_META),                                   \
259*af3020e2SGhennadi Procopciuc 	.block = (BLOCK_TYPE),                                 \
260*af3020e2SGhennadi Procopciuc 	.status = (STATUS),                                    \
261*af3020e2SGhennadi Procopciuc }
262*af3020e2SGhennadi Procopciuc 
263*af3020e2SGhennadi Procopciuc #define S32CC_PART_BLOCK(PARENT, BLOCK_TYPE) \
264*af3020e2SGhennadi Procopciuc 	S32CC_PART_BLOCK_STATUS(PARENT, BLOCK_TYPE, true)
265*af3020e2SGhennadi Procopciuc 
266*af3020e2SGhennadi Procopciuc #define S32CC_PART_BLOCK_NO_STATUS(PARENT, BLOCK_TYPE) \
267*af3020e2SGhennadi Procopciuc 	S32CC_PART_BLOCK_STATUS(PARENT, BLOCK_TYPE, false)
268*af3020e2SGhennadi Procopciuc 
269*af3020e2SGhennadi Procopciuc struct s32cc_part_block_link {
270*af3020e2SGhennadi Procopciuc 	struct s32cc_clk_obj desc;
271*af3020e2SGhennadi Procopciuc 	struct s32cc_clk_obj *parent;
272*af3020e2SGhennadi Procopciuc 	struct s32cc_part_block *block;
273*af3020e2SGhennadi Procopciuc };
274*af3020e2SGhennadi Procopciuc 
275*af3020e2SGhennadi Procopciuc #define S32CC_PART_BLOCK_LINK(PARENT, BLOCK)     \
276*af3020e2SGhennadi Procopciuc {                                                \
277*af3020e2SGhennadi Procopciuc 	.desc = {                                \
278*af3020e2SGhennadi Procopciuc 		.type = s32cc_part_block_link_t, \
279*af3020e2SGhennadi Procopciuc 	},                                       \
280*af3020e2SGhennadi Procopciuc 	.parent = &(PARENT).desc,                \
281*af3020e2SGhennadi Procopciuc 	.block = (BLOCK),                        \
282*af3020e2SGhennadi Procopciuc }
283*af3020e2SGhennadi Procopciuc 
284d9373519SGhennadi Procopciuc static inline struct s32cc_osc *s32cc_obj2osc(const struct s32cc_clk_obj *mod)
285d9373519SGhennadi Procopciuc {
286d9373519SGhennadi Procopciuc 	uintptr_t osc_addr;
287d9373519SGhennadi Procopciuc 
288d9373519SGhennadi Procopciuc 	osc_addr = ((uintptr_t)mod) - offsetof(struct s32cc_osc, desc);
289d9373519SGhennadi Procopciuc 	return (struct s32cc_osc *)osc_addr;
290d9373519SGhennadi Procopciuc }
291d9373519SGhennadi Procopciuc 
292d9373519SGhennadi Procopciuc static inline struct s32cc_clk *s32cc_obj2clk(const struct s32cc_clk_obj *mod)
293d9373519SGhennadi Procopciuc {
294d9373519SGhennadi Procopciuc 	uintptr_t clk_addr;
295d9373519SGhennadi Procopciuc 
296d9373519SGhennadi Procopciuc 	clk_addr = ((uintptr_t)mod) - offsetof(struct s32cc_clk, desc);
297d9373519SGhennadi Procopciuc 	return (struct s32cc_clk *)clk_addr;
298d9373519SGhennadi Procopciuc }
299d9373519SGhennadi Procopciuc 
30012e7a2cdSGhennadi Procopciuc static inline bool is_s32cc_clk_mux(const struct s32cc_clk *clk)
30112e7a2cdSGhennadi Procopciuc {
30212e7a2cdSGhennadi Procopciuc 	const struct s32cc_clk_obj *module;
30312e7a2cdSGhennadi Procopciuc 
30412e7a2cdSGhennadi Procopciuc 	module = clk->module;
30512e7a2cdSGhennadi Procopciuc 	if (module == NULL) {
30612e7a2cdSGhennadi Procopciuc 		return false;
30712e7a2cdSGhennadi Procopciuc 	}
30812e7a2cdSGhennadi Procopciuc 
3093fa91a94SGhennadi Procopciuc 	return (module->type == s32cc_clkmux_t) ||
3103fa91a94SGhennadi Procopciuc 	    (module->type == s32cc_shared_clkmux_t);
31112e7a2cdSGhennadi Procopciuc }
31212e7a2cdSGhennadi Procopciuc 
31312e7a2cdSGhennadi Procopciuc static inline struct s32cc_clkmux *s32cc_obj2clkmux(const struct s32cc_clk_obj *mod)
31412e7a2cdSGhennadi Procopciuc {
31512e7a2cdSGhennadi Procopciuc 	uintptr_t cmux_addr;
31612e7a2cdSGhennadi Procopciuc 
31712e7a2cdSGhennadi Procopciuc 	cmux_addr = ((uintptr_t)mod) - offsetof(struct s32cc_clkmux, desc);
31812e7a2cdSGhennadi Procopciuc 	return (struct s32cc_clkmux *)cmux_addr;
31912e7a2cdSGhennadi Procopciuc }
32012e7a2cdSGhennadi Procopciuc 
32112e7a2cdSGhennadi Procopciuc static inline struct s32cc_clkmux *s32cc_clk2mux(const struct s32cc_clk *clk)
32212e7a2cdSGhennadi Procopciuc {
32312e7a2cdSGhennadi Procopciuc 	if (!is_s32cc_clk_mux(clk)) {
32412e7a2cdSGhennadi Procopciuc 		return NULL;
32512e7a2cdSGhennadi Procopciuc 	}
32612e7a2cdSGhennadi Procopciuc 
32712e7a2cdSGhennadi Procopciuc 	return s32cc_obj2clkmux(clk->module);
32812e7a2cdSGhennadi Procopciuc }
32912e7a2cdSGhennadi Procopciuc 
3307ad4e231SGhennadi Procopciuc static inline struct s32cc_pll *s32cc_obj2pll(const struct s32cc_clk_obj *mod)
3317ad4e231SGhennadi Procopciuc {
3327ad4e231SGhennadi Procopciuc 	uintptr_t pll_addr;
3337ad4e231SGhennadi Procopciuc 
3347ad4e231SGhennadi Procopciuc 	pll_addr = ((uintptr_t)mod) - offsetof(struct s32cc_pll, desc);
3357ad4e231SGhennadi Procopciuc 	return (struct s32cc_pll *)pll_addr;
3367ad4e231SGhennadi Procopciuc }
3377ad4e231SGhennadi Procopciuc 
338de950ef0SGhennadi Procopciuc static inline struct s32cc_pll_out_div *s32cc_obj2plldiv(const struct s32cc_clk_obj *mod)
339de950ef0SGhennadi Procopciuc {
340de950ef0SGhennadi Procopciuc 	uintptr_t plldiv_addr;
341de950ef0SGhennadi Procopciuc 
342de950ef0SGhennadi Procopciuc 	plldiv_addr = ((uintptr_t)mod) - offsetof(struct s32cc_pll_out_div, desc);
343de950ef0SGhennadi Procopciuc 	return (struct s32cc_pll_out_div *)plldiv_addr;
344de950ef0SGhennadi Procopciuc }
345de950ef0SGhennadi Procopciuc 
34665739db2SGhennadi Procopciuc static inline struct s32cc_fixed_div *s32cc_obj2fixeddiv(const struct s32cc_clk_obj *mod)
34765739db2SGhennadi Procopciuc {
34865739db2SGhennadi Procopciuc 	uintptr_t fdiv_addr;
34965739db2SGhennadi Procopciuc 
35065739db2SGhennadi Procopciuc 	fdiv_addr = ((uintptr_t)mod) - offsetof(struct s32cc_fixed_div, desc);
35165739db2SGhennadi Procopciuc 	return (struct s32cc_fixed_div *)fdiv_addr;
35265739db2SGhennadi Procopciuc }
35365739db2SGhennadi Procopciuc 
35444ae54afSGhennadi Procopciuc static inline struct s32cc_dfs *s32cc_obj2dfs(const struct s32cc_clk_obj *mod)
35544ae54afSGhennadi Procopciuc {
35644ae54afSGhennadi Procopciuc 	uintptr_t dfs_addr;
35744ae54afSGhennadi Procopciuc 
35844ae54afSGhennadi Procopciuc 	dfs_addr = ((uintptr_t)mod) - offsetof(struct s32cc_dfs, desc);
35944ae54afSGhennadi Procopciuc 	return (struct s32cc_dfs *)dfs_addr;
36044ae54afSGhennadi Procopciuc }
36144ae54afSGhennadi Procopciuc 
36244ae54afSGhennadi Procopciuc static inline struct s32cc_dfs_div *s32cc_obj2dfsdiv(const struct s32cc_clk_obj *mod)
36344ae54afSGhennadi Procopciuc {
36444ae54afSGhennadi Procopciuc 	uintptr_t dfs_div_addr;
36544ae54afSGhennadi Procopciuc 
36644ae54afSGhennadi Procopciuc 	dfs_div_addr = ((uintptr_t)mod) - offsetof(struct s32cc_dfs_div, desc);
36744ae54afSGhennadi Procopciuc 	return (struct s32cc_dfs_div *)dfs_div_addr;
36844ae54afSGhennadi Procopciuc }
36944ae54afSGhennadi Procopciuc 
370*af3020e2SGhennadi Procopciuc static inline struct s32cc_part *s32cc_obj2part(const struct s32cc_clk_obj *mod)
371*af3020e2SGhennadi Procopciuc {
372*af3020e2SGhennadi Procopciuc 	uintptr_t part_addr;
373*af3020e2SGhennadi Procopciuc 
374*af3020e2SGhennadi Procopciuc 	part_addr = ((uintptr_t)mod) - offsetof(struct s32cc_part, desc);
375*af3020e2SGhennadi Procopciuc 	return (struct s32cc_part *)part_addr;
376*af3020e2SGhennadi Procopciuc }
377*af3020e2SGhennadi Procopciuc 
378*af3020e2SGhennadi Procopciuc static inline struct s32cc_part_block *
379*af3020e2SGhennadi Procopciuc s32cc_obj2partblock(const struct s32cc_clk_obj *mod)
380*af3020e2SGhennadi Procopciuc {
381*af3020e2SGhennadi Procopciuc 	uintptr_t part_blk_addr;
382*af3020e2SGhennadi Procopciuc 
383*af3020e2SGhennadi Procopciuc 	part_blk_addr = ((uintptr_t)mod) - offsetof(struct s32cc_part_block, desc);
384*af3020e2SGhennadi Procopciuc 	return (struct s32cc_part_block *)part_blk_addr;
385*af3020e2SGhennadi Procopciuc }
386*af3020e2SGhennadi Procopciuc 
387*af3020e2SGhennadi Procopciuc static inline struct s32cc_part_block_link *
388*af3020e2SGhennadi Procopciuc s32cc_obj2partblocklink(const struct s32cc_clk_obj *mod)
389*af3020e2SGhennadi Procopciuc {
390*af3020e2SGhennadi Procopciuc 	uintptr_t blk_link;
391*af3020e2SGhennadi Procopciuc 
392*af3020e2SGhennadi Procopciuc 	blk_link = ((uintptr_t)mod) - offsetof(struct s32cc_part_block_link, desc);
393*af3020e2SGhennadi Procopciuc 	return (struct s32cc_part_block_link *)blk_link;
394*af3020e2SGhennadi Procopciuc }
395*af3020e2SGhennadi Procopciuc 
3967c36209bSGhennadi Procopciuc #endif /* S32CC_CLK_MODULES_H */
397