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