Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2024 NXP |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | #include <s32cc-clk-ids.h> |
| 7 | #include <s32cc-clk-utils.h> |
| 8 | |
| 9 | static struct s32cc_clk *s32cc_clk_get_from_array(const struct s32cc_clk_array *arr, |
| 10 | unsigned long clk_id) |
| 11 | { |
| 12 | unsigned long type, id; |
| 13 | |
| 14 | type = S32CC_CLK_TYPE(clk_id); |
| 15 | |
| 16 | if (type != arr->type_mask) { |
| 17 | return NULL; |
| 18 | } |
| 19 | |
| 20 | id = S32CC_CLK_ID(clk_id); |
| 21 | |
| 22 | if (id >= arr->n_clks) { |
| 23 | return NULL; |
| 24 | } |
| 25 | |
| 26 | return arr->clks[id]; |
| 27 | } |
| 28 | |
| 29 | struct s32cc_clk *s32cc_get_clk_from_table(const struct s32cc_clk_array *const *clk_arr, |
| 30 | size_t size, |
| 31 | unsigned long clk_id) |
| 32 | { |
| 33 | struct s32cc_clk *clk; |
| 34 | size_t i; |
| 35 | |
| 36 | for (i = 0; i < size; i++) { |
| 37 | clk = s32cc_clk_get_from_array(clk_arr[i], clk_id); |
| 38 | if (clk != NULL) { |
| 39 | return clk; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | return NULL; |
| 44 | } |