1 /*
2 * Copyright (c) 2018, Diego Sueiro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <ccm_imx7d.h>
8 #include <ccm_analog_imx7d.h>
9 #include "soc_clk_freq.h"
10
11 #ifdef CONFIG_PWM_IMX
get_pwm_clock_freq(PWM_Type * base)12 uint32_t get_pwm_clock_freq(PWM_Type *base)
13 {
14 uint32_t root;
15 uint32_t hz;
16 uint32_t pre, post;
17
18 switch ((uint32_t)base) {
19 case PWM1_BASE:
20 root = CCM_GetRootMux(CCM, ccmRootPwm1);
21 CCM_GetRootDivider(CCM, ccmRootPwm1, &pre, &post);
22 break;
23 case PWM2_BASE:
24 root = CCM_GetRootMux(CCM, ccmRootPwm2);
25 CCM_GetRootDivider(CCM, ccmRootPwm2, &pre, &post);
26 break;
27 case PWM3_BASE:
28 root = CCM_GetRootMux(CCM, ccmRootPwm3);
29 CCM_GetRootDivider(CCM, ccmRootPwm3, &pre, &post);
30 break;
31 case PWM4_BASE:
32 root = CCM_GetRootMux(CCM, ccmRootPwm4);
33 CCM_GetRootDivider(CCM, ccmRootPwm4, &pre, &post);
34 break;
35 default:
36 return 0;
37 }
38
39 switch (root) {
40 case ccmRootmuxPwmOsc24m:
41 hz = 24000000U;
42 break;
43 case ccmRootmuxPwmSysPllDiv4:
44 hz = CCM_ANALOG_GetSysPllFreq(CCM_ANALOG) >> 2;
45 break;
46 default:
47 return 0;
48 }
49
50 return hz / (pre + 1) / (post + 1);
51 }
52 #endif /* CONFIG_PWM_IMX */
53