1 /*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * o Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * o Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include "clock_freq.h"
33 #include "ccm_imx7d.h"
34 #include "ccm_analog_imx7d.h"
35
36 /*FUNCTION**********************************************************************
37 *
38 * Function Name : get_gpt_clock_freq
39 * Description : Get clock frequency applies to the GPT module
40 *
41 *END**************************************************************************/
get_gpt_clock_freq(GPT_Type * base)42 uint32_t get_gpt_clock_freq(GPT_Type *base)
43 {
44 uint32_t root;
45 uint32_t hz;
46 uint32_t pre, post;
47
48 switch ((uint32_t)base) {
49 case GPT3_BASE:
50 root = CCM_GetRootMux(CCM, ccmRootGpt3);
51 CCM_GetRootDivider(CCM, ccmRootGpt3, &pre, &post);
52 break;
53 case GPT4_BASE:
54 root = CCM_GetRootMux(CCM, ccmRootGpt4);
55 CCM_GetRootDivider(CCM, ccmRootGpt4, &pre, &post);
56 break;
57 default:
58 return 0;
59 }
60
61 switch (root) {
62 case ccmRootmuxGptOsc24m:
63 hz = 24000000;
64 break;
65 case ccmRootmuxGptSysPllPfd0:
66 hz = CCM_ANALOG_GetPfdFreq(CCM_ANALOG, ccmAnalogPfd0Frac);
67 break;
68 default:
69 return 0;
70 }
71
72 return hz / (pre + 1) / (post + 1);
73 }
74
75 /*FUNCTION**********************************************************************
76 *
77 * Function Name : get_ecspi_clock_freq
78 * Description : Get clock frequency applys to the ECSPI module
79 *
80 *END**************************************************************************/
get_ecspi_clock_freq(ECSPI_Type * base)81 uint32_t get_ecspi_clock_freq(ECSPI_Type *base)
82 {
83 uint32_t root;
84 uint32_t hz;
85 uint32_t pre, post;
86
87 switch ((uint32_t)base) {
88 case ECSPI1_BASE:
89 root = CCM_GetRootMux(CCM, ccmRootEcspi1);
90 CCM_GetRootDivider(CCM, ccmRootEcspi1, &pre, &post);
91 break;
92 case ECSPI2_BASE:
93 root = CCM_GetRootMux(CCM, ccmRootEcspi2);
94 CCM_GetRootDivider(CCM, ccmRootEcspi2, &pre, &post);
95 break;
96 default:
97 return 0;
98 }
99
100 switch (root) {
101 case ccmRootmuxEcspiOsc24m:
102 hz = 24000000;
103 break;
104 case ccmRootmuxEcspiSysPllPfd4:
105 hz = CCM_ANALOG_GetPfdFreq(CCM_ANALOG, ccmAnalogPfd4Frac);
106 break;
107 default:
108 return 0;
109 }
110
111 return hz / (pre + 1) / (post + 1);
112 }
113
114 /*FUNCTION**********************************************************************
115 *
116 * Function Name : get_flexcan_clock_freq
117 * Description : Get clock frequency applys to the FLEXCAN module
118 *
119 *END**************************************************************************/
get_flexcan_clock_freq(CAN_Type * base)120 uint32_t get_flexcan_clock_freq(CAN_Type *base)
121 {
122 uint32_t root;
123 uint32_t hz;
124 uint32_t pre, post;
125
126 switch ((uint32_t)base) {
127 case CAN1_BASE:
128 root = CCM_GetRootMux(CCM, ccmRootCan1);
129 CCM_GetRootDivider(CCM, ccmRootCan1, &pre, &post);
130 break;
131 case CAN2_BASE:
132 root = CCM_GetRootMux(CCM, ccmRootCan2);
133 CCM_GetRootDivider(CCM, ccmRootCan2, &pre, &post);
134 break;
135 default:
136 return 0;
137 }
138
139 switch (root) {
140 case ccmRootmuxCanOsc24m:
141 hz = 24000000;
142 break;
143 case ccmRootmuxCanSysPllDiv4:
144 hz = CCM_ANALOG_GetSysPllFreq(CCM_ANALOG) >> 2;
145 break;
146 case ccmRootmuxCanSysPllDiv1:
147 hz = CCM_ANALOG_GetSysPllFreq(CCM_ANALOG);
148 break;
149 default:
150 return 0;
151 }
152
153 return hz / (pre + 1) / (post + 1);
154 }
155
156 /*FUNCTION**********************************************************************
157 *
158 * Function Name : get_I2C_clock_freq
159 * Description : Get clock frequency applys to the I2C module
160 *
161 *END**************************************************************************/
get_i2c_clock_freq(I2C_Type * base)162 uint32_t get_i2c_clock_freq(I2C_Type *base)
163 {
164 uint32_t root;
165 uint32_t hz;
166 uint32_t pre, post;
167
168 switch ((uint32_t)base) {
169 case I2C1_BASE:
170 root = CCM_GetRootMux(CCM, ccmRootI2c1);
171 CCM_GetRootDivider(CCM, ccmRootI2c1, &pre, &post);
172 break;
173 case I2C2_BASE:
174 root = CCM_GetRootMux(CCM, ccmRootI2c2);
175 CCM_GetRootDivider(CCM, ccmRootI2c2, &pre, &post);
176 break;
177 case I2C3_BASE:
178 root = CCM_GetRootMux(CCM, ccmRootI2c3);
179 CCM_GetRootDivider(CCM, ccmRootI2c3, &pre, &post);
180 break;
181 case I2C4_BASE:
182 root = CCM_GetRootMux(CCM, ccmRootI2c4);
183 CCM_GetRootDivider(CCM, ccmRootI2c4, &pre, &post);
184 break;
185 default:
186 return 0;
187 }
188
189 switch (root) {
190 case ccmRootmuxI2cOsc24m:
191 hz = 24000000;
192 break;
193 case ccmRootmuxI2cSysPllDiv4:
194 hz = CCM_ANALOG_GetSysPllFreq(CCM_ANALOG) >> 2;
195 break;
196 default:
197 return 0;
198 }
199
200 return hz / (pre + 1) / (post + 1);
201 }
202
203 /*FUNCTION**********************************************************************
204 *
205 * Function Name : get_uart_clock_freq
206 * Description : Get clock frequency applys to the UART module
207 *
208 *END**************************************************************************/
get_uart_clock_freq(UART_Type * base)209 uint32_t get_uart_clock_freq(UART_Type *base)
210 {
211 uint32_t root;
212 uint32_t hz;
213 uint32_t pre, post;
214
215 switch ((uint32_t)base) {
216 case UART1_BASE:
217 root = CCM_GetRootMux(CCM, ccmRootUart1);
218 CCM_GetRootDivider(CCM, ccmRootUart1, &pre, &post);
219 break;
220 case UART2_BASE:
221 root = CCM_GetRootMux(CCM, ccmRootUart2);
222 CCM_GetRootDivider(CCM, ccmRootUart2, &pre, &post);
223 break;
224 case UART3_BASE:
225 root = CCM_GetRootMux(CCM, ccmRootUart3);
226 CCM_GetRootDivider(CCM, ccmRootUart3, &pre, &post);
227 break;
228 case UART4_BASE:
229 root = CCM_GetRootMux(CCM, ccmRootUart4);
230 CCM_GetRootDivider(CCM, ccmRootUart4, &pre, &post);
231 break;
232 case UART5_BASE:
233 root = CCM_GetRootMux(CCM, ccmRootUart5);
234 CCM_GetRootDivider(CCM, ccmRootUart5, &pre, &post);
235 break;
236 case UART6_BASE:
237 root = CCM_GetRootMux(CCM, ccmRootUart6);
238 CCM_GetRootDivider(CCM, ccmRootUart6, &pre, &post);
239 break;
240 case UART7_BASE:
241 root = CCM_GetRootMux(CCM, ccmRootUart7);
242 CCM_GetRootDivider(CCM, ccmRootUart7, &pre, &post);
243 break;
244 default:
245 return 0;
246 }
247
248 switch (root) {
249 case ccmRootmuxUartOsc24m:
250 hz = 24000000;
251 break;
252 case ccmRootmuxUartSysPllDiv2:
253 hz = CCM_ANALOG_GetSysPllFreq(CCM_ANALOG) >> 1;
254 break;
255 case ccmRootmuxUartSysPllDiv1:
256 hz = CCM_ANALOG_GetSysPllFreq(CCM_ANALOG);
257 break;
258 default:
259 return 0;
260 }
261
262 return hz / (pre + 1) / (post + 1);
263 }
264
265 /*******************************************************************************
266 * EOF
267 ******************************************************************************/
268