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,
22*63d536feSGhennadi Procopciuc s32cc_cgm_div_t,
23a8be748aSGhennadi Procopciuc s32cc_clkmux_t,
243fa91a94SGhennadi Procopciuc s32cc_shared_clkmux_t,
2544e2130aSGhennadi Procopciuc s32cc_fixed_div_t,
26af3020e2SGhennadi Procopciuc s32cc_part_t,
27af3020e2SGhennadi Procopciuc s32cc_part_block_t,
28af3020e2SGhennadi Procopciuc s32cc_part_block_link_t,
297c36209bSGhennadi Procopciuc };
307c36209bSGhennadi Procopciuc
317c36209bSGhennadi Procopciuc enum s32cc_clk_source {
327c36209bSGhennadi Procopciuc S32CC_FIRC,
337c36209bSGhennadi Procopciuc S32CC_FXOSC,
347c36209bSGhennadi Procopciuc S32CC_SIRC,
35a8be748aSGhennadi Procopciuc S32CC_ARM_PLL,
3644ae54afSGhennadi Procopciuc S32CC_ARM_DFS,
378653352aSGhennadi Procopciuc S32CC_PERIPH_PLL,
389dbca85dSGhennadi Procopciuc S32CC_CGM0,
393fa91a94SGhennadi Procopciuc S32CC_CGM1,
4018c2b137SGhennadi Procopciuc S32CC_DDR_PLL,
4129f8a952SGhennadi Procopciuc S32CC_PERIPH_DFS,
424a2ca718SGhennadi Procopciuc S32CC_CGM5,
437c36209bSGhennadi Procopciuc };
447c36209bSGhennadi Procopciuc
457c36209bSGhennadi Procopciuc struct s32cc_clk_obj {
467c36209bSGhennadi Procopciuc enum s32cc_clkm_type type;
477c36209bSGhennadi Procopciuc uint32_t refcount;
487c36209bSGhennadi Procopciuc };
497c36209bSGhennadi Procopciuc
507c36209bSGhennadi Procopciuc struct s32cc_osc {
517c36209bSGhennadi Procopciuc struct s32cc_clk_obj desc;
527c36209bSGhennadi Procopciuc enum s32cc_clk_source source;
537c36209bSGhennadi Procopciuc unsigned long freq;
547c36209bSGhennadi Procopciuc void *base;
557c36209bSGhennadi Procopciuc };
567c36209bSGhennadi Procopciuc
57bd691136SGhennadi Procopciuc #define S32CC_OSC_INIT_FREQ(SOURCE, FREQ) \
587c36209bSGhennadi Procopciuc { \
597c36209bSGhennadi Procopciuc .desc = { \
607c36209bSGhennadi Procopciuc .type = s32cc_osc_t, \
617c36209bSGhennadi Procopciuc }, \
627c36209bSGhennadi Procopciuc .source = (SOURCE), \
63bd691136SGhennadi Procopciuc .freq = (FREQ), \
647c36209bSGhennadi Procopciuc }
657c36209bSGhennadi Procopciuc
66bd691136SGhennadi Procopciuc #define S32CC_OSC_INIT(SOURCE) \
67bd691136SGhennadi Procopciuc S32CC_OSC_INIT_FREQ(SOURCE, 0)
68bd691136SGhennadi Procopciuc
69a8be748aSGhennadi Procopciuc struct s32cc_clkmux {
70a8be748aSGhennadi Procopciuc struct s32cc_clk_obj desc;
71a8be748aSGhennadi Procopciuc enum s32cc_clk_source module;
72a8be748aSGhennadi Procopciuc uint8_t index; /* Mux index in parent module */
73a8be748aSGhennadi Procopciuc unsigned long source_id; /* Selected source */
74a8be748aSGhennadi Procopciuc uint8_t nclks; /* Number of input clocks */
75a8be748aSGhennadi Procopciuc unsigned long clkids[5]; /* IDs of the input clocks */
76a8be748aSGhennadi Procopciuc };
77a8be748aSGhennadi Procopciuc
78a8be748aSGhennadi Procopciuc #define S32CC_CLKMUX_TYPE_INIT(TYPE, MODULE, INDEX, NCLKS, ...) \
79a8be748aSGhennadi Procopciuc { \
80a8be748aSGhennadi Procopciuc .desc = { \
81a8be748aSGhennadi Procopciuc .type = (TYPE), \
82a8be748aSGhennadi Procopciuc }, \
83a8be748aSGhennadi Procopciuc .module = (MODULE), \
84a8be748aSGhennadi Procopciuc .index = (INDEX), \
85a8be748aSGhennadi Procopciuc .nclks = (NCLKS), \
86a8be748aSGhennadi Procopciuc .clkids = {__VA_ARGS__}, \
87a8be748aSGhennadi Procopciuc }
88a8be748aSGhennadi Procopciuc
89a8be748aSGhennadi Procopciuc #define S32CC_CLKMUX_INIT(MODULE, INDEX, NCLKS, ...) \
90a8be748aSGhennadi Procopciuc S32CC_CLKMUX_TYPE_INIT(s32cc_clkmux_t, MODULE, \
91a8be748aSGhennadi Procopciuc INDEX, NCLKS, __VA_ARGS__)
92a8be748aSGhennadi Procopciuc
933fa91a94SGhennadi Procopciuc #define S32CC_SHARED_CLKMUX_INIT(MODULE, INDEX, NCLKS, ...) \
943fa91a94SGhennadi Procopciuc S32CC_CLKMUX_TYPE_INIT(s32cc_shared_clkmux_t, MODULE, \
953fa91a94SGhennadi Procopciuc INDEX, NCLKS, __VA_ARGS__)
963fa91a94SGhennadi Procopciuc
97a8be748aSGhennadi Procopciuc struct s32cc_pll {
98a8be748aSGhennadi Procopciuc struct s32cc_clk_obj desc;
99a8be748aSGhennadi Procopciuc struct s32cc_clk_obj *source;
100a8be748aSGhennadi Procopciuc enum s32cc_clk_source instance;
101a8be748aSGhennadi Procopciuc unsigned long vco_freq;
102a8be748aSGhennadi Procopciuc uint32_t ndividers;
103a8be748aSGhennadi Procopciuc uintptr_t base;
104a8be748aSGhennadi Procopciuc };
105a8be748aSGhennadi Procopciuc
106a8be748aSGhennadi Procopciuc #define S32CC_PLL_INIT(PLL_MUX_CLK, INSTANCE, NDIVIDERS) \
107a8be748aSGhennadi Procopciuc { \
108a8be748aSGhennadi Procopciuc .desc = { \
109a8be748aSGhennadi Procopciuc .type = s32cc_pll_t, \
110a8be748aSGhennadi Procopciuc }, \
111a8be748aSGhennadi Procopciuc .source = &(PLL_MUX_CLK).desc, \
112a8be748aSGhennadi Procopciuc .instance = (INSTANCE), \
113a8be748aSGhennadi Procopciuc .ndividers = (NDIVIDERS), \
114a8be748aSGhennadi Procopciuc }
115a8be748aSGhennadi Procopciuc
116a8be748aSGhennadi Procopciuc struct s32cc_pll_out_div {
117a8be748aSGhennadi Procopciuc struct s32cc_clk_obj desc;
118a8be748aSGhennadi Procopciuc struct s32cc_clk_obj *parent;
119a8be748aSGhennadi Procopciuc uint32_t index;
120a8be748aSGhennadi Procopciuc unsigned long freq;
121a8be748aSGhennadi Procopciuc };
122a8be748aSGhennadi Procopciuc
123a8be748aSGhennadi Procopciuc #define S32CC_PLL_OUT_DIV_INIT(PARENT, INDEX) \
124a8be748aSGhennadi Procopciuc { \
125a8be748aSGhennadi Procopciuc .desc = { \
126a8be748aSGhennadi Procopciuc .type = s32cc_pll_out_div_t, \
127a8be748aSGhennadi Procopciuc }, \
128a8be748aSGhennadi Procopciuc .parent = &(PARENT).desc, \
129a8be748aSGhennadi Procopciuc .index = (INDEX), \
130a8be748aSGhennadi Procopciuc }
131a8be748aSGhennadi Procopciuc
13244e2130aSGhennadi Procopciuc #define S32CC_PLL_OUT_DIV_INIT(PARENT, INDEX) \
13344e2130aSGhennadi Procopciuc { \
13444e2130aSGhennadi Procopciuc .desc = { \
13544e2130aSGhennadi Procopciuc .type = s32cc_pll_out_div_t, \
13644e2130aSGhennadi Procopciuc }, \
13744e2130aSGhennadi Procopciuc .parent = &(PARENT).desc, \
13844e2130aSGhennadi Procopciuc .index = (INDEX), \
13944e2130aSGhennadi Procopciuc }
14044e2130aSGhennadi Procopciuc
14144ae54afSGhennadi Procopciuc struct s32cc_dfs {
14244ae54afSGhennadi Procopciuc struct s32cc_clk_obj desc;
14344ae54afSGhennadi Procopciuc struct s32cc_clk_obj *parent;
14444ae54afSGhennadi Procopciuc enum s32cc_clk_source instance;
14544ae54afSGhennadi Procopciuc uintptr_t base;
14644ae54afSGhennadi Procopciuc };
14744ae54afSGhennadi Procopciuc
14844ae54afSGhennadi Procopciuc #define S32CC_DFS_INIT(PARENT, INSTANCE) \
14944ae54afSGhennadi Procopciuc { \
15044ae54afSGhennadi Procopciuc .desc = { \
15144ae54afSGhennadi Procopciuc .type = s32cc_dfs_t, \
15244ae54afSGhennadi Procopciuc }, \
15344ae54afSGhennadi Procopciuc .parent = &(PARENT).desc, \
15444ae54afSGhennadi Procopciuc .instance = (INSTANCE), \
15544ae54afSGhennadi Procopciuc }
15644ae54afSGhennadi Procopciuc
15744ae54afSGhennadi Procopciuc struct s32cc_dfs_div {
15844ae54afSGhennadi Procopciuc struct s32cc_clk_obj desc;
15944ae54afSGhennadi Procopciuc struct s32cc_clk_obj *parent;
16044ae54afSGhennadi Procopciuc uint32_t index;
16144ae54afSGhennadi Procopciuc unsigned long freq;
16244ae54afSGhennadi Procopciuc };
16344ae54afSGhennadi Procopciuc
16444ae54afSGhennadi Procopciuc #define S32CC_DFS_DIV_INIT(PARENT, INDEX) \
16544ae54afSGhennadi Procopciuc { \
16644ae54afSGhennadi Procopciuc .desc = { \
16744ae54afSGhennadi Procopciuc .type = s32cc_dfs_div_t, \
16844ae54afSGhennadi Procopciuc }, \
16944ae54afSGhennadi Procopciuc .parent = &(PARENT).desc, \
17044ae54afSGhennadi Procopciuc .index = (INDEX), \
17144ae54afSGhennadi Procopciuc }
17244ae54afSGhennadi Procopciuc
17344e2130aSGhennadi Procopciuc struct s32cc_fixed_div {
17444e2130aSGhennadi Procopciuc struct s32cc_clk_obj desc;
17544e2130aSGhennadi Procopciuc struct s32cc_clk_obj *parent;
17644e2130aSGhennadi Procopciuc uint32_t rate_div;
17744e2130aSGhennadi Procopciuc };
17844e2130aSGhennadi Procopciuc
17944e2130aSGhennadi Procopciuc #define S32CC_FIXED_DIV_INIT(PARENT, RATE_DIV) \
18044e2130aSGhennadi Procopciuc { \
18144e2130aSGhennadi Procopciuc .desc = { \
18244e2130aSGhennadi Procopciuc .type = s32cc_fixed_div_t, \
18344e2130aSGhennadi Procopciuc }, \
18444e2130aSGhennadi Procopciuc .parent = &(PARENT).desc, \
18544e2130aSGhennadi Procopciuc .rate_div = (RATE_DIV), \
18644e2130aSGhennadi Procopciuc }
18744e2130aSGhennadi Procopciuc
1887c36209bSGhennadi Procopciuc struct s32cc_clk {
1897c36209bSGhennadi Procopciuc struct s32cc_clk_obj desc;
1907c36209bSGhennadi Procopciuc struct s32cc_clk_obj *module;
1917c36209bSGhennadi Procopciuc struct s32cc_clk *pclock;
1927c36209bSGhennadi Procopciuc unsigned long min_freq;
1937c36209bSGhennadi Procopciuc unsigned long max_freq;
1947c36209bSGhennadi Procopciuc };
1957c36209bSGhennadi Procopciuc
1967c36209bSGhennadi Procopciuc struct s32cc_clk_array {
1977c36209bSGhennadi Procopciuc unsigned long type_mask;
1987c36209bSGhennadi Procopciuc struct s32cc_clk **clks;
1997c36209bSGhennadi Procopciuc size_t n_clks;
2007c36209bSGhennadi Procopciuc };
2017c36209bSGhennadi Procopciuc
20244ae54afSGhennadi Procopciuc #define S32CC_FREQ_CLK(PARENT_MODULE, PARENT, MIN_F, MAX_F) \
2037c36209bSGhennadi Procopciuc { \
2047c36209bSGhennadi Procopciuc .desc = { \
2057c36209bSGhennadi Procopciuc .type = s32cc_clk_t, \
2067c36209bSGhennadi Procopciuc }, \
20744ae54afSGhennadi Procopciuc .pclock = (PARENT), \
20844ae54afSGhennadi Procopciuc .module = (PARENT_MODULE), \
2097c36209bSGhennadi Procopciuc .min_freq = (MIN_F), \
2107c36209bSGhennadi Procopciuc .max_freq = (MAX_F), \
2117c36209bSGhennadi Procopciuc }
2127c36209bSGhennadi Procopciuc
2137c36209bSGhennadi Procopciuc #define S32CC_FREQ_MODULE_CLK(PARENT_MODULE, MIN_F, MAX_F) \
21444ae54afSGhennadi Procopciuc S32CC_FREQ_CLK(&(PARENT_MODULE).desc, NULL, MIN_F, MAX_F)
2157c36209bSGhennadi Procopciuc
2167c36209bSGhennadi Procopciuc #define S32CC_MODULE_CLK(PARENT_MODULE) \
2177c36209bSGhennadi Procopciuc S32CC_FREQ_MODULE_CLK(PARENT_MODULE, 0, 0)
2187c36209bSGhennadi Procopciuc
21944ae54afSGhennadi Procopciuc #define S32CC_CHILD_CLK(PARENT, MIN_F, MAX_F) \
22044ae54afSGhennadi Procopciuc S32CC_FREQ_CLK(NULL, &(PARENT), MIN_F, MAX_F)
22144ae54afSGhennadi Procopciuc
222af3020e2SGhennadi Procopciuc struct s32cc_part {
223af3020e2SGhennadi Procopciuc struct s32cc_clk_obj desc;
224af3020e2SGhennadi Procopciuc uint32_t partition_id;
225af3020e2SGhennadi Procopciuc };
226af3020e2SGhennadi Procopciuc
227af3020e2SGhennadi Procopciuc #define S32CC_PART(PART_NUM) \
228af3020e2SGhennadi Procopciuc { \
229af3020e2SGhennadi Procopciuc .desc = { \
230af3020e2SGhennadi Procopciuc .type = s32cc_part_t, \
231af3020e2SGhennadi Procopciuc }, \
232af3020e2SGhennadi Procopciuc .partition_id = (PART_NUM), \
233af3020e2SGhennadi Procopciuc }
234af3020e2SGhennadi Procopciuc
235af3020e2SGhennadi Procopciuc enum s32cc_part_block_type {
236af3020e2SGhennadi Procopciuc s32cc_part_block0,
237af3020e2SGhennadi Procopciuc s32cc_part_block1,
238af3020e2SGhennadi Procopciuc s32cc_part_block2,
239af3020e2SGhennadi Procopciuc s32cc_part_block3,
240af3020e2SGhennadi Procopciuc s32cc_part_block4,
241af3020e2SGhennadi Procopciuc s32cc_part_block5,
242af3020e2SGhennadi Procopciuc s32cc_part_block6,
243af3020e2SGhennadi Procopciuc s32cc_part_block7,
244af3020e2SGhennadi Procopciuc s32cc_part_block8,
245af3020e2SGhennadi Procopciuc s32cc_part_block9,
246af3020e2SGhennadi Procopciuc s32cc_part_block10,
247af3020e2SGhennadi Procopciuc s32cc_part_block11,
248af3020e2SGhennadi Procopciuc s32cc_part_block12,
249af3020e2SGhennadi Procopciuc s32cc_part_block13,
250af3020e2SGhennadi Procopciuc s32cc_part_block14,
251af3020e2SGhennadi Procopciuc s32cc_part_block15,
252af3020e2SGhennadi Procopciuc };
253af3020e2SGhennadi Procopciuc
254af3020e2SGhennadi Procopciuc struct s32cc_part_block {
255af3020e2SGhennadi Procopciuc struct s32cc_clk_obj desc;
256af3020e2SGhennadi Procopciuc struct s32cc_part *part;
257af3020e2SGhennadi Procopciuc enum s32cc_part_block_type block;
258af3020e2SGhennadi Procopciuc bool status;
259af3020e2SGhennadi Procopciuc };
260af3020e2SGhennadi Procopciuc
261af3020e2SGhennadi Procopciuc #define S32CC_PART_BLOCK_STATUS(PART_META, BLOCK_TYPE, STATUS) \
262af3020e2SGhennadi Procopciuc { \
263af3020e2SGhennadi Procopciuc .desc = { \
264af3020e2SGhennadi Procopciuc .type = s32cc_part_block_t, \
265af3020e2SGhennadi Procopciuc }, \
266af3020e2SGhennadi Procopciuc .part = (PART_META), \
267af3020e2SGhennadi Procopciuc .block = (BLOCK_TYPE), \
268af3020e2SGhennadi Procopciuc .status = (STATUS), \
269af3020e2SGhennadi Procopciuc }
270af3020e2SGhennadi Procopciuc
271af3020e2SGhennadi Procopciuc #define S32CC_PART_BLOCK(PARENT, BLOCK_TYPE) \
272af3020e2SGhennadi Procopciuc S32CC_PART_BLOCK_STATUS(PARENT, BLOCK_TYPE, true)
273af3020e2SGhennadi Procopciuc
274af3020e2SGhennadi Procopciuc #define S32CC_PART_BLOCK_NO_STATUS(PARENT, BLOCK_TYPE) \
275af3020e2SGhennadi Procopciuc S32CC_PART_BLOCK_STATUS(PARENT, BLOCK_TYPE, false)
276af3020e2SGhennadi Procopciuc
277af3020e2SGhennadi Procopciuc struct s32cc_part_block_link {
278af3020e2SGhennadi Procopciuc struct s32cc_clk_obj desc;
279af3020e2SGhennadi Procopciuc struct s32cc_clk_obj *parent;
280af3020e2SGhennadi Procopciuc struct s32cc_part_block *block;
281af3020e2SGhennadi Procopciuc };
282af3020e2SGhennadi Procopciuc
283af3020e2SGhennadi Procopciuc #define S32CC_PART_BLOCK_LINK(PARENT, BLOCK) \
284af3020e2SGhennadi Procopciuc { \
285af3020e2SGhennadi Procopciuc .desc = { \
286af3020e2SGhennadi Procopciuc .type = s32cc_part_block_link_t, \
287af3020e2SGhennadi Procopciuc }, \
288af3020e2SGhennadi Procopciuc .parent = &(PARENT).desc, \
289af3020e2SGhennadi Procopciuc .block = (BLOCK), \
290af3020e2SGhennadi Procopciuc }
291af3020e2SGhennadi Procopciuc
292*63d536feSGhennadi Procopciuc struct s32cc_cgm_div {
293*63d536feSGhennadi Procopciuc struct s32cc_clk_obj desc;
294*63d536feSGhennadi Procopciuc struct s32cc_clk_obj *parent;
295*63d536feSGhennadi Procopciuc unsigned long freq;
296*63d536feSGhennadi Procopciuc uint32_t index;
297*63d536feSGhennadi Procopciuc };
298*63d536feSGhennadi Procopciuc
299*63d536feSGhennadi Procopciuc #define S32CC_CGM_DIV_INIT(PARENT, INDEX) \
300*63d536feSGhennadi Procopciuc { \
301*63d536feSGhennadi Procopciuc .desc = { \
302*63d536feSGhennadi Procopciuc .type = s32cc_cgm_div_t, \
303*63d536feSGhennadi Procopciuc }, \
304*63d536feSGhennadi Procopciuc .parent = &(PARENT).desc, \
305*63d536feSGhennadi Procopciuc .index = (INDEX), \
306*63d536feSGhennadi Procopciuc }
307*63d536feSGhennadi Procopciuc
s32cc_obj2osc(const struct s32cc_clk_obj * mod)308d9373519SGhennadi Procopciuc static inline struct s32cc_osc *s32cc_obj2osc(const struct s32cc_clk_obj *mod)
309d9373519SGhennadi Procopciuc {
310d9373519SGhennadi Procopciuc uintptr_t osc_addr;
311d9373519SGhennadi Procopciuc
312d9373519SGhennadi Procopciuc osc_addr = ((uintptr_t)mod) - offsetof(struct s32cc_osc, desc);
313d9373519SGhennadi Procopciuc return (struct s32cc_osc *)osc_addr;
314d9373519SGhennadi Procopciuc }
315d9373519SGhennadi Procopciuc
s32cc_obj2clk(const struct s32cc_clk_obj * mod)316d9373519SGhennadi Procopciuc static inline struct s32cc_clk *s32cc_obj2clk(const struct s32cc_clk_obj *mod)
317d9373519SGhennadi Procopciuc {
318d9373519SGhennadi Procopciuc uintptr_t clk_addr;
319d9373519SGhennadi Procopciuc
320d9373519SGhennadi Procopciuc clk_addr = ((uintptr_t)mod) - offsetof(struct s32cc_clk, desc);
321d9373519SGhennadi Procopciuc return (struct s32cc_clk *)clk_addr;
322d9373519SGhennadi Procopciuc }
323d9373519SGhennadi Procopciuc
is_s32cc_clk_mux(const struct s32cc_clk * clk)32412e7a2cdSGhennadi Procopciuc static inline bool is_s32cc_clk_mux(const struct s32cc_clk *clk)
32512e7a2cdSGhennadi Procopciuc {
32612e7a2cdSGhennadi Procopciuc const struct s32cc_clk_obj *module;
32712e7a2cdSGhennadi Procopciuc
32812e7a2cdSGhennadi Procopciuc module = clk->module;
32912e7a2cdSGhennadi Procopciuc if (module == NULL) {
33012e7a2cdSGhennadi Procopciuc return false;
33112e7a2cdSGhennadi Procopciuc }
33212e7a2cdSGhennadi Procopciuc
3333fa91a94SGhennadi Procopciuc return (module->type == s32cc_clkmux_t) ||
3343fa91a94SGhennadi Procopciuc (module->type == s32cc_shared_clkmux_t);
33512e7a2cdSGhennadi Procopciuc }
33612e7a2cdSGhennadi Procopciuc
s32cc_obj2clkmux(const struct s32cc_clk_obj * mod)33712e7a2cdSGhennadi Procopciuc static inline struct s32cc_clkmux *s32cc_obj2clkmux(const struct s32cc_clk_obj *mod)
33812e7a2cdSGhennadi Procopciuc {
33912e7a2cdSGhennadi Procopciuc uintptr_t cmux_addr;
34012e7a2cdSGhennadi Procopciuc
34112e7a2cdSGhennadi Procopciuc cmux_addr = ((uintptr_t)mod) - offsetof(struct s32cc_clkmux, desc);
34212e7a2cdSGhennadi Procopciuc return (struct s32cc_clkmux *)cmux_addr;
34312e7a2cdSGhennadi Procopciuc }
34412e7a2cdSGhennadi Procopciuc
s32cc_clk2mux(const struct s32cc_clk * clk)34512e7a2cdSGhennadi Procopciuc static inline struct s32cc_clkmux *s32cc_clk2mux(const struct s32cc_clk *clk)
34612e7a2cdSGhennadi Procopciuc {
34712e7a2cdSGhennadi Procopciuc if (!is_s32cc_clk_mux(clk)) {
34812e7a2cdSGhennadi Procopciuc return NULL;
34912e7a2cdSGhennadi Procopciuc }
35012e7a2cdSGhennadi Procopciuc
35112e7a2cdSGhennadi Procopciuc return s32cc_obj2clkmux(clk->module);
35212e7a2cdSGhennadi Procopciuc }
35312e7a2cdSGhennadi Procopciuc
s32cc_obj2pll(const struct s32cc_clk_obj * mod)3547ad4e231SGhennadi Procopciuc static inline struct s32cc_pll *s32cc_obj2pll(const struct s32cc_clk_obj *mod)
3557ad4e231SGhennadi Procopciuc {
3567ad4e231SGhennadi Procopciuc uintptr_t pll_addr;
3577ad4e231SGhennadi Procopciuc
3587ad4e231SGhennadi Procopciuc pll_addr = ((uintptr_t)mod) - offsetof(struct s32cc_pll, desc);
3597ad4e231SGhennadi Procopciuc return (struct s32cc_pll *)pll_addr;
3607ad4e231SGhennadi Procopciuc }
3617ad4e231SGhennadi Procopciuc
s32cc_obj2plldiv(const struct s32cc_clk_obj * mod)362de950ef0SGhennadi Procopciuc static inline struct s32cc_pll_out_div *s32cc_obj2plldiv(const struct s32cc_clk_obj *mod)
363de950ef0SGhennadi Procopciuc {
364de950ef0SGhennadi Procopciuc uintptr_t plldiv_addr;
365de950ef0SGhennadi Procopciuc
366de950ef0SGhennadi Procopciuc plldiv_addr = ((uintptr_t)mod) - offsetof(struct s32cc_pll_out_div, desc);
367de950ef0SGhennadi Procopciuc return (struct s32cc_pll_out_div *)plldiv_addr;
368de950ef0SGhennadi Procopciuc }
369de950ef0SGhennadi Procopciuc
s32cc_obj2fixeddiv(const struct s32cc_clk_obj * mod)37065739db2SGhennadi Procopciuc static inline struct s32cc_fixed_div *s32cc_obj2fixeddiv(const struct s32cc_clk_obj *mod)
37165739db2SGhennadi Procopciuc {
37265739db2SGhennadi Procopciuc uintptr_t fdiv_addr;
37365739db2SGhennadi Procopciuc
37465739db2SGhennadi Procopciuc fdiv_addr = ((uintptr_t)mod) - offsetof(struct s32cc_fixed_div, desc);
37565739db2SGhennadi Procopciuc return (struct s32cc_fixed_div *)fdiv_addr;
37665739db2SGhennadi Procopciuc }
37765739db2SGhennadi Procopciuc
s32cc_obj2dfs(const struct s32cc_clk_obj * mod)37844ae54afSGhennadi Procopciuc static inline struct s32cc_dfs *s32cc_obj2dfs(const struct s32cc_clk_obj *mod)
37944ae54afSGhennadi Procopciuc {
38044ae54afSGhennadi Procopciuc uintptr_t dfs_addr;
38144ae54afSGhennadi Procopciuc
38244ae54afSGhennadi Procopciuc dfs_addr = ((uintptr_t)mod) - offsetof(struct s32cc_dfs, desc);
38344ae54afSGhennadi Procopciuc return (struct s32cc_dfs *)dfs_addr;
38444ae54afSGhennadi Procopciuc }
38544ae54afSGhennadi Procopciuc
s32cc_obj2dfsdiv(const struct s32cc_clk_obj * mod)38644ae54afSGhennadi Procopciuc static inline struct s32cc_dfs_div *s32cc_obj2dfsdiv(const struct s32cc_clk_obj *mod)
38744ae54afSGhennadi Procopciuc {
38844ae54afSGhennadi Procopciuc uintptr_t dfs_div_addr;
38944ae54afSGhennadi Procopciuc
39044ae54afSGhennadi Procopciuc dfs_div_addr = ((uintptr_t)mod) - offsetof(struct s32cc_dfs_div, desc);
39144ae54afSGhennadi Procopciuc return (struct s32cc_dfs_div *)dfs_div_addr;
39244ae54afSGhennadi Procopciuc }
39344ae54afSGhennadi Procopciuc
s32cc_obj2part(const struct s32cc_clk_obj * mod)394af3020e2SGhennadi Procopciuc static inline struct s32cc_part *s32cc_obj2part(const struct s32cc_clk_obj *mod)
395af3020e2SGhennadi Procopciuc {
396af3020e2SGhennadi Procopciuc uintptr_t part_addr;
397af3020e2SGhennadi Procopciuc
398af3020e2SGhennadi Procopciuc part_addr = ((uintptr_t)mod) - offsetof(struct s32cc_part, desc);
399af3020e2SGhennadi Procopciuc return (struct s32cc_part *)part_addr;
400af3020e2SGhennadi Procopciuc }
401af3020e2SGhennadi Procopciuc
402af3020e2SGhennadi Procopciuc static inline struct s32cc_part_block *
s32cc_obj2partblock(const struct s32cc_clk_obj * mod)403af3020e2SGhennadi Procopciuc s32cc_obj2partblock(const struct s32cc_clk_obj *mod)
404af3020e2SGhennadi Procopciuc {
405af3020e2SGhennadi Procopciuc uintptr_t part_blk_addr;
406af3020e2SGhennadi Procopciuc
407af3020e2SGhennadi Procopciuc part_blk_addr = ((uintptr_t)mod) - offsetof(struct s32cc_part_block, desc);
408af3020e2SGhennadi Procopciuc return (struct s32cc_part_block *)part_blk_addr;
409af3020e2SGhennadi Procopciuc }
410af3020e2SGhennadi Procopciuc
411af3020e2SGhennadi Procopciuc static inline struct s32cc_part_block_link *
s32cc_obj2partblocklink(const struct s32cc_clk_obj * mod)412af3020e2SGhennadi Procopciuc s32cc_obj2partblocklink(const struct s32cc_clk_obj *mod)
413af3020e2SGhennadi Procopciuc {
414af3020e2SGhennadi Procopciuc uintptr_t blk_link;
415af3020e2SGhennadi Procopciuc
416af3020e2SGhennadi Procopciuc blk_link = ((uintptr_t)mod) - offsetof(struct s32cc_part_block_link, desc);
417af3020e2SGhennadi Procopciuc return (struct s32cc_part_block_link *)blk_link;
418af3020e2SGhennadi Procopciuc }
419af3020e2SGhennadi Procopciuc
s32cc_obj2cgmdiv(const struct s32cc_clk_obj * mod)420*63d536feSGhennadi Procopciuc static inline struct s32cc_cgm_div *s32cc_obj2cgmdiv(const struct s32cc_clk_obj *mod)
421*63d536feSGhennadi Procopciuc {
422*63d536feSGhennadi Procopciuc uintptr_t cgm_div_addr;
423*63d536feSGhennadi Procopciuc
424*63d536feSGhennadi Procopciuc cgm_div_addr = ((uintptr_t)mod) - offsetof(struct s32cc_cgm_div, desc);
425*63d536feSGhennadi Procopciuc return (struct s32cc_cgm_div *)cgm_div_addr;
426*63d536feSGhennadi Procopciuc }
427*63d536feSGhennadi Procopciuc
4287c36209bSGhennadi Procopciuc #endif /* S32CC_CLK_MODULES_H */
429