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