Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
| 2 | /* |
| 3 | * Copyright 2020-2024 NXP |
| 4 | */ |
| 5 | #ifndef S32CC_CLK_MODULES_H |
| 6 | #define S32CC_CLK_MODULES_H |
| 7 | |
| 8 | #include <inttypes.h> |
| 9 | #include <stddef.h> |
| 10 | |
| 11 | #define MHZ UL(1000000) |
| 12 | #define GHZ (UL(1000) * MHZ) |
| 13 | |
| 14 | enum s32cc_clkm_type { |
| 15 | s32cc_osc_t, |
| 16 | s32cc_clk_t, |
| 17 | }; |
| 18 | |
| 19 | enum s32cc_clk_source { |
| 20 | S32CC_FIRC, |
| 21 | S32CC_FXOSC, |
| 22 | S32CC_SIRC, |
| 23 | }; |
| 24 | |
| 25 | struct s32cc_clk_obj { |
| 26 | enum s32cc_clkm_type type; |
| 27 | uint32_t refcount; |
| 28 | }; |
| 29 | |
| 30 | struct s32cc_osc { |
| 31 | struct s32cc_clk_obj desc; |
| 32 | enum s32cc_clk_source source; |
| 33 | unsigned long freq; |
| 34 | void *base; |
| 35 | }; |
| 36 | |
| 37 | #define S32CC_OSC_INIT(SOURCE) \ |
| 38 | { \ |
| 39 | .desc = { \ |
| 40 | .type = s32cc_osc_t, \ |
| 41 | }, \ |
| 42 | .source = (SOURCE), \ |
| 43 | } |
| 44 | |
| 45 | struct s32cc_clk { |
| 46 | struct s32cc_clk_obj desc; |
| 47 | struct s32cc_clk_obj *module; |
| 48 | struct s32cc_clk *pclock; |
| 49 | unsigned long min_freq; |
| 50 | unsigned long max_freq; |
| 51 | }; |
| 52 | |
| 53 | struct s32cc_clk_array { |
| 54 | unsigned long type_mask; |
| 55 | struct s32cc_clk **clks; |
| 56 | size_t n_clks; |
| 57 | }; |
| 58 | |
| 59 | #define S32CC_FREQ_MODULE(PARENT_MODULE, MIN_F, MAX_F) \ |
| 60 | { \ |
| 61 | .desc = { \ |
| 62 | .type = s32cc_clk_t, \ |
| 63 | }, \ |
| 64 | .module = &(PARENT_MODULE).desc, \ |
| 65 | .min_freq = (MIN_F), \ |
| 66 | .max_freq = (MAX_F), \ |
| 67 | } |
| 68 | |
| 69 | #define S32CC_FREQ_MODULE_CLK(PARENT_MODULE, MIN_F, MAX_F) \ |
| 70 | S32CC_FREQ_MODULE(PARENT_MODULE, MIN_F, MAX_F) |
| 71 | |
| 72 | #define S32CC_MODULE_CLK(PARENT_MODULE) \ |
| 73 | S32CC_FREQ_MODULE_CLK(PARENT_MODULE, 0, 0) |
| 74 | |
Ghennadi Procopciuc | 0d52577 | 2024-06-12 08:09:19 +0300 | [diff] [blame] | 75 | static inline struct s32cc_osc *s32cc_obj2osc(const struct s32cc_clk_obj *mod) |
| 76 | { |
| 77 | uintptr_t osc_addr; |
| 78 | |
| 79 | osc_addr = ((uintptr_t)mod) - offsetof(struct s32cc_osc, desc); |
| 80 | return (struct s32cc_osc *)osc_addr; |
| 81 | } |
| 82 | |
| 83 | static inline struct s32cc_clk *s32cc_obj2clk(const struct s32cc_clk_obj *mod) |
| 84 | { |
| 85 | uintptr_t clk_addr; |
| 86 | |
| 87 | clk_addr = ((uintptr_t)mod) - offsetof(struct s32cc_clk, desc); |
| 88 | return (struct s32cc_clk *)clk_addr; |
| 89 | } |
| 90 | |
Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 91 | #endif /* S32CC_CLK_MODULES_H */ |