blob: 5a1c27cfd887cc4e0b634b4a469ea2dc1bbd7b85 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2012
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*******************************************************************************
37 * Filename:
38 * ---------
39 * pll_gen93m17.c
40 *
41 * Project:
42 * --------
43 * UMOLYA
44 *
45 * Description:
46 * ------------
47 * PLL Related Functions
48 *
49 * Author:
50 * -------
51 * -------
52 *
53 * ==========================================================================
54 * $Log$
55 *
56 * 01 22 2018 jun-ying.huang
57 * [MOLY00303289] [Merlot call for check-in][PLL][DCM]Add Macro for MT6761(=Merlot)
58 * .
59 *
60 * 11 30 2017 jun-ying.huang
61 * [MOLY00293064] [Sylvia][PLL]Update 26M settle time in REG_MDTOP_PLLMIXED_DCXO_PLL_SETTLE_CTL
62 * .
63 *
64 * 10 25 2017 jun-ying.huang
65 * [MOLY00285159] [PLL][DCM]Add Macro for MT6765(=Cervino)
66 * .
67 *
68 * 09 01 2017 jun-ying.huang
69 * [MOLY00275084] [6293]Add PLL_SEC Module related code to get SW version.
70 * .
71 *
72 * 08 21 2017 jun-ying.huang
73 * [MOLY00272509] [Sylvia][PLL]Add MT6771 Macro for PLL due to Sylvia MT6771 Call for check in
74 * .
75 *
76 * 07 12 2017 jun-ying.huang
77 * [MOLY00260131] [PLL]Update Frequency Meter
78 * .
79 *
80 * 06 16 2017 jun-ying.huang
81 * [MOLY00256086] [MT6739][Zion][Gen93][System Service] Workaround for MDCIRQ clock issue
82 * .
83 *
84 * 06 09 2017 jun-ying.huang
85 * [MOLY00244484] [Zion]Add compile option for ZION in PLL.
86 * Add compile option for ZION and Workaround for CIRQ APB sync issue- Let BUS2x clock use MDBPIPLL_0/6 = 101 MHz
87 *
88 * 04 14 2017 jun-ying.huang
89 * [MOLY00241010] [MT6763][DCM][PLL]Enable mdsys_bus2x & fesys_bus2x power aware and update PLL driver to apply golden setting
90 * .
91 *
92 * 03 30 2017 jun-ying.huang
93 * [MOLY00238573] [MT6293][PLL][FMA]Update Frequency meter driver and add comment for FMA
94 * .
95 *
96 * 03 06 2017 jun-ying.huang
97 * [MOLY00223031] [6293][PLL]Update PLL init flow
98 * .
99 *
100 * 01 05 2017 jun-ying.huang
101 * [MOLY00223031] [6293][PLL]Update PLL init flow
102 * .
103 *
104 * 12 16 2016 jun-ying.huang
105 * [MOLY00218782] [System service][PLL][6293]Add compile option for MT6763
106 * .
107 *
108 * 12 07 2016 jun-ying.huang
109 * [MOLY00217275] [System service][PLL][6293]Update PLL init flow and porting driver for user
110 * .
111 *
112 * 11 20 2016 jun-ying.huang
113 * [MOLY00214278] [System service][PLL][6293]Update PLL_FrequencyMeter_GetFreq() driver
114 * .
115 *
116 * 11 06 2016 jun-ying.huang
117 * [MOLY00211600] [System service][PLL]Add debug info in PLL driver
118 * .
119 *
120 * 10 14 2016 jun-ying.huang
121 * [MOLY00207095] [System service][PLL]Update PLL driver for DVFS users.
122 * Add PLL function for DVFS
123 *
124 * 09 19 2016 alan-tl.lin
125 * [MOLY00174466] [UMOLYA] PLL porting
126 * [PLL]
127 * 1. Fix FPGA_IS_ASIC() detection rule
128 * 2. Update BPIPLL settings : Disalbe /7 clock by default
129 *
130 * 08 02 2016 alan-tl.lin
131 * [MOLY00174466] [UMOLYA] PLL porting
132 * [PLL] Update PLL init flow from DE's update : Use POSDIV /4, not using internal devider
133 *
134 * 07 11 2016 alan-tl.lin
135 * [MOLY00184725] UMOLYA ESL/MASE porting
136 * [PLL] Add compile option for ESL
137 *
138 * 06 15 2016 alan-tl.lin
139 * [MOLY00173527] [PLL] Driver porting
140 * [PLL] PLL init first porting
141 *
142 * 04 15 2016 alan-tl.lin
143 * [MOLY00174466] [UMOLYA] PLL porting
144 * [PLL] Initial porting
145 *
146 * 03 30 2016 alan-tl.lin
147 * [MOLY00171849] [GEN93] Fix build error
148 * [PLL/PDN] Add compile option for GEN93
149 *
150 *
151 ****************************************************************************/
152
153#ifdef __MTK_TARGET__ /* should NOT be compiled on MODIS */
154
155/*******************************************************************************
156 * Locally Used Options
157 *******************************************************************************/
158
159/*******************************************************************************
160 * Include header files
161 *******************************************************************************/
162
163#include "pll.h"
164#include "kal_public_api.h"
165#include "sync_data.h"
166#include "us_timer.h"
167
168/*******************************************************************************
169 * external functions
170 *******************************************************************************/
171extern void PLL_SEC_SW_VERSION_ENHANCE();
172
173#define PLL_FM_WIMDOW (0x1FF)
174
175/* Below for debugging */
176
177const char PLL_FM_clock[PLL_FM_NUM][32] =
178{
179 "TRACE_MON_CLOCK", /* 0 */
180 "MDSYS_208M_CLOCK",
181 "MDRXSYS_RAKE_CLOCK",
182 "MDRXSYS_BRP_CLOCK",
183 "MDRXSYS_VDSP_CLOCK",
184 "MDTOP_LOG_GTB_CLOCK", /* 5 */
185 "FESYS_CSYS_CLOCK",
186 "FESYS_TXSYS_CLOCK",
187 "FESYS_BSI_CLOCK",
188 "MDSYS_MDCORE_CLOCK",
189 "MDSYS_BUS2X_NODCM_CLOCK", /* 10 */
190 "MDSYS_BUS2X_CLOCK",
191 "MDTOP_DBG_CLOCK",
192 "MDTOP_F32K_CLOCK",
193 "MDBPI_PLL_0_DIV2",
194 "MDBPI_PLL_2", /* 15 */
195 "MDBPI_PLL_1",
196 "MDBPI_PLL_0",
197 "MDTX_PLL",
198 "MDBRP_PLL",
199 "MDVDSP_PLL", /* 20 */
200 "MDMCU_PLL",
201/* below no use */
202 "null_22",
203 "null_23",
204 "null_24",
205 "null_25",
206 "null_26",
207 "null_27",
208 "null_28",
209 "null_29"
210};
211
212PLL_CLK_INFO g_pll_info = {0};
213
214/* Above for debugging */
215
216/**
217 * This function is used to detect ASIC or FPGA version of Palladium
218 */
219__PLL_CODE_IN_BOOT__ kal_bool PLL_FPGA_IS_ASIC(void)
220{
221#if defined(__FPGA__)
222 kal_uint32 asic_flag = *((volatile kal_uint32 *)(0xA0000018)) & (0x1 << 7);
223
224 if (asic_flag == 0)
225 return KAL_TRUE;
226 else
227 return KAL_FALSE;
228#else
229 return KAL_TRUE;
230#endif
231}
232
233__PLL_CODE_IN_BOOT__ void INT_SetPLL_Gen93M17(void)
234{
235
236#if defined(MT6763) || defined(MT6771) || defined(MT6765) || defined(MT6761)/* BIANCO or SYLVIA or CERVINO or MERLOT */
237
238 #if defined(MT6763) || defined(MT6765) || defined(MT6761)/* BIANCO or CERVINO or MERLOT */
239 // Default md_srclkena_ack settle time = 136T 32K
240 *REG_MDTOP_PLLMIXED_DCXO_PLL_SETTLE_CTL = 0x02020E88;
241 #elif defined(MT6771)/* SYLVIA */
242 // Default md_srclkena_ack settle time = 147T 32K
243 *REG_MDTOP_PLLMIXED_DCXO_PLL_SETTLE_CTL = 0x02020E93;
244 #else
245 #error "Unsupported Chip Target in PLL Module"
246 #endif
247
248 *REG_MDTOP_PLLMIXED_MDBPIPLL_CTL0 = 0x801713B1; // fixed 600MHz(/4), 343MHz(/7), 267MHz(/9) /* Fvco = 2400M */
249 *REG_MDTOP_PLLMIXED_MDTXPLL_CTL0 = 0x80171400; // 300MHz /* Fvco = 2400M */
250 *REG_MDTOP_PLLMIXED_MDBRPPLL_CTL0 = 0x80229E00; // 400MHz /* Fvco = 3600M */
251 *REG_MDTOP_PLLMIXED_MDVDSPPLL_CTL0 = 0x80204E00; // 672MHz /* Fvco = 3360M */
252 *REG_MDTOP_PLLMIXED_MDMCUPLL_CTL0 = 0x80213C00; // 864MHz /* Fvco = 3456M */
253 MO_Sync();
254
255 /*
256 * Polling until MDMCUPLL complete frequency adjustment
257 * Once MDMCUPLL complete, other PLL should complete too
258 */
259 while ((*REG_MDTOP_PLLMIXED_MDMCUPLL_STS >> 14) & 0x1) {};
260
261 // Default disable BPI /7 clock
262 *REG_MDTOP_PLLMIXED_MDBPIPLL_CTL1 = *REG_MDTOP_PLLMIXED_MDBPIPLL_CTL1 & (~(0x80));
263
264 #if defined(MT6761)/* MERLOT */
265 /* Use default value */
266 #else/* BIANCO or SYLVIA or CERVINO */
267 /*TINFO="MDSYS_INIT: Update ABB MDPLL control register default value"*/
268 *REG_MDTOP_PLLMIXED_MDPLL_CTL1 = 0x4C43100;
269 #endif
270
271#elif defined(MT6739)/* ZION */
272 *REG_MDTOP_PLLMIXED_MDBPIPLL_CTL0 = 0x80118000; // fixed 606MHz(/4), 260MHz(/7) /* Fvco = 1820M */
273 *REG_MDTOP_PLLMIXED_MDTXPLL_CTL0 = 0x800B8A00; // 300MHz /* Fvco = 1200M */
274 *REG_MDTOP_PLLMIXED_MDBRPPLL_CTL0 = 0x80114E00; // 300MHz /* Fvco = 1800M */
275 *REG_MDTOP_PLLMIXED_MDVDSPPLL_CTL0 = 0x80114E00; // 450MHz /* Fvco = 1800M */
276 *REG_MDTOP_PLLMIXED_MDMCUPLL_CTL0 = 0x800B8A00; // 600MHz /* Fvco = 1200M */
277 MO_Sync();
278
279 while ((*REG_MDTOP_PLLMIXED_MDMCUPLL_STS >> 14)&0x1); //Polling until MDMCUPLL complete frequency adjustment
280 //Once MDBPIPLL complete, other PLL should complete too
281
282 //In L17, MDPLL should be turn-on first manually, since first calabration requires longer time (100us).
283 /*TINFO="MDSYS_INIT: MDPLL_208M_OUT_EN off"*/
284 *REG_MDTOP_PLLMIXED_MDPLL_CTL2 &= ~(0x10000);
285 /*TINFO="MDSYS_INIT: SW Force ON MDPLL"*/
286 *REG_MDTOP_PLLMIXED_PLL_SW_CTL0 = 0x10000;
287 *REG_MDTOP_PLLMIXED_PLL_SW_CTL0 = 0x10001;
288 MO_Sync();
289 /*TINFO="MDSYS_INIT: Wait at least 100us"*/
290 ust_us_busyloop(101);
291
292 /*TINFO="MDSYS_INIT: SW Force OFF MDPLL"*/
293 *REG_MDTOP_PLLMIXED_PLL_SW_CTL0 = 0x10000;
294 *REG_MDTOP_PLLMIXED_PLL_SW_CTL0 = 0x0;
295 /*TINFO="MDSYS_INIT: MDPLL_208M_OUT_EN on"*/
296 *REG_MDTOP_PLLMIXED_MDPLL_CTL2 |= 0x10000;
297 MO_Sync();
298 /*TINFO="MDSYS_INIT: Wait 1us"*/
299 ust_us_busyloop(1);
300
301 /*TINFO="MDSYS_INIT: Disable AUTOK_EN, MDPLL settle time is 20us NOW (AUTOK_EN can only be setting when MDPLL_EN is OFF, so we add 1us to avoid signals competition)"*/
302 *REG_MDTOP_PLLMIXED_MDPLL_CTL1 &= ~(0x4000000);
303 MO_Sync();
304 /*TINFO="MDSYS_INIT: Wait 1us"*/
305 ust_us_busyloop(1);
306#else
307 #error "Unsupported Chip Target in PLL Module"
308#endif
309
310 /* Force TXPLL ON due to TOPSM couldn't enable this PLL by default, TXPLL would be disable after DVFS Init.
311 other PLL ON controlled by HW" */
312 *REG_MDTOP_PLLMIXED_PLL_ON_CTL = 0x100010;
313 MO_Sync();
314
315 #if defined(__PALLADIUM__)
316 if (PLL_FPGA_IS_ASIC() == KAL_TRUE) {
317 while ((*REG_MDTOP_CLKSW_MDSYS_BUS_FLEXCKGEN_STS & 0x8000) != 0x8000) {};
318 }
319 #else // Not PALLADIUM
320 #if !defined(__FPGA__)
321 /*
322 * Wait MD bus clock ready
323 * Once MD bus ready, other clock should be ready too
324 * In FPGA, the following status checking must be removed since there is no flex ck gen in FPGA.
325 */
326 while ((*REG_MDTOP_CLKSW_MDSYS_BUS_FLEXCKGEN_STS & 0x8000) != 0x8000) {};
327 #endif // __FPGA__
328 #endif // __PALLADIUM__
329
330 // Switch MDMCU & MD BUS clock to PLL frequency
331 *REG_MDTOP_CLKSW_CLKSEL_CTL |= 0x3;
332 MO_Sync();
333
334 // Switch all clock to PLL frequency
335 *REG_MDTOP_CLKSW_CLKSEL_CTL |= 0x58103FC;
336 MO_Sync();
337
338 // Switch SDF clock to PLL frequency
339 *REG_MDTOP_CLKSW_SDF_CK_CTL |= 0x10;
340 MO_Sync();
341
342 // Turn off all SW clock request, except ATB
343 *REG_MDTOP_CLKSW_CLKON_CTL = 0x1;
344 MO_Sync();
345
346 // Clear PLL ADJ RDY IRQ fired by initial period adjustment
347 *REG_MDTOP_PLLMIXED_PLL_HP_RDY_IRQ = 0xFFFF;
348 MO_Sync();
349
350 // Mask all PLL ADJ RDY IRQ
351 *REG_MDTOP_PLLMIXED_PLL_HP_RDY_IRQ_MASK = 0xFFFF;
352 MO_Sync();
353
354 // Make a record that means MD pll has been initialized.
355 /* Note: We use "MD_PLL_MAGIC_NUM|0x1" to know PLL init in MD C code.
356 If AP init PLL, it would be "MD_PLL_MAGIC_NUM". */
357 *REG_MDTOP_PLLMIXED_PLL_DUMMY = (MD_PLL_MAGIC_NUM|0x1);
358 MO_Sync();
359
360}
361
362__PLL_CODE_IN_BOOT__ kal_uint8 pll_get_current_vpe_id(void)
363{
364 unsigned int vpe_id = 0;
365
366 __asm__ __volatile__(
367 "mfc0 %0, $15, 1" \
368 : "=r" (vpe_id) \
369 :);
370
371 return (vpe_id & 0xF);
372}
373
374/*************************************************************************
375 * FUNCTION
376 * INT_SetPLL
377 *
378 * DESCRIPTION
379 * This function dedicates for PLL setting.
380 *
381 * PARAMETERS
382 * Init mode of PLL
383 *
384 * RETURNS
385 *************************************************************************/
386__PLL_CODE_IN_BOOT__ void INT_SetPLL(void)
387{
388#if !defined(__COSIM_BYPASS__) && !defined(__ESL_MASE__)
389 if ((pll_get_current_vpe_id() == 0))
390 {
391 if (*REG_MDTOP_PLLMIXED_PLL_DUMMY != MD_PLL_MAGIC_NUM)
392 {
393 INT_SetPLL_Gen93M17();
394 }
395
396 PLL_SEC_SW_VERSION_ENHANCE();
397
398 }
399#endif // __COSIM_BYPASS__
400}
401
402 /*------------------------------------------------------------------------
403 * void PLL_FrequencyMeter_GetFreq
404 * Purpose: Get specified PLL/module's clock(Mhz).
405 * Parameters:
406 * Input: PLL_FM_SOURCE index: The module you want to measure.
407 *
408 * Output: None.
409 *
410 * returns : The PLL/module's clock(Mhz).
411 * Note : This function would spend at least 20us to measure the clock.
412 *
413 *------------------------------------------------------------------------
414 */
415kal_uint32 PLL_FrequencyMeter_GetFreq(PLL_FM_SOURCE index)
416{
417 kal_uint32 count = 2000, output = 0;
418
419 if ((index < PLL_FM_SOURCE_START) || (index > PLL_FM_SOURCE_END))
420 return 0;
421
422 *REG_MDTOP_CLKSW_CKMON_CTL = PLL_FM_MDSYS_MDCORE_CLOCK; //select source to a valid clock to let reset success.
423
424 *REG_MDTOP_CLKSW_FREQ_METER_CTL = 0; //reset frequency meter
425
426 MO_Sync();
427 ust_us_busyloop(2);//let Frequency Meter reset done
428
429 *REG_MDTOP_CLKSW_CKMON_CTL = 0x300 | index; //divided by 8 and select source
430 *REG_MDTOP_CLKSW_FREQ_METER_XTAL_CNT = PLL_FM_WIMDOW;
431 *REG_MDTOP_CLKSW_FREQ_METER_CTL = 1; //enable frequency meter
432 MO_Sync();
433
434 // wait measure done or timeout
435 while (((*REG_MDTOP_CLKSW_FREQ_METER_CTL) & (1 << 1)) == 0)
436 {
437 count--;
438 if (count == 0)
439 break;
440 }
441
442 if (count == 0)
443 return 0;
444
445 output = *REG_MDTOP_CLKSW_FREQ_METER_CKMON_CNT * 26 * 8 / (PLL_FM_WIMDOW+3);
446
447 *REG_MDTOP_CLKSW_CKMON_CTL = 0; //select source to NULL to save power in flip-flop, save about 0.07mA in 6293
448
449 *REG_MDTOP_CLKSW_FREQ_METER_CTL = 0; //reset frequency meter
450
451 return output;
452}
453
454void PLL_exception_dump(void)
455{
456 g_pll_info.clock_trace_mon = PLL_FrequencyMeter_GetFreq(PLL_FM_TRACE_MON_CLOCK);
457 g_pll_info.clock_mdsys_208m = PLL_FrequencyMeter_GetFreq(PLL_FM_MDSYS_208M_CLOCK);
458 g_pll_info.clock_mdrxsys_rake = PLL_FrequencyMeter_GetFreq(PLL_FM_MDRXSYS_RAKE_CLOCK);
459 g_pll_info.clock_mdrxsys_brp = PLL_FrequencyMeter_GetFreq(PLL_FM_MDRXSYS_BRP_CLOCK);
460 g_pll_info.clock_mdrxsys_vdsp = PLL_FrequencyMeter_GetFreq(PLL_FM_MDRXSYS_VDSP_CLOCK);
461 g_pll_info.clock_mdtop_log_gtb = PLL_FrequencyMeter_GetFreq(PLL_FM_MDTOP_LOG_GTB_CLOCK);
462 g_pll_info.clock_fesys_csys = PLL_FrequencyMeter_GetFreq(PLL_FM_FESYS_CSYS_CLOCK);
463 g_pll_info.clock_fesys_txsys = PLL_FrequencyMeter_GetFreq(PLL_FM_FESYS_TXSYS_CLOCK);
464 g_pll_info.clock_fesys_bsi = PLL_FrequencyMeter_GetFreq(PLL_FM_FESYS_BSI_CLOCK);
465 g_pll_info.clock_mdsys_mdcore = PLL_FrequencyMeter_GetFreq(PLL_FM_MDSYS_MDCORE_CLOCK);
466 g_pll_info.clock_mdsys_bus2x_nodcm = PLL_FrequencyMeter_GetFreq(PLL_FM_MDSYS_BUS2X_NODCM_CLOCK);
467 g_pll_info.clock_mdsys_bus2x = PLL_FrequencyMeter_GetFreq(PLL_FM_MDSYS_BUS2X_CLOCK);
468 g_pll_info.clock_mdtop_dbg = PLL_FrequencyMeter_GetFreq(PLL_FM_MDTOP_DBG_CLOCK);
469 g_pll_info.clock_mdtop_f32k = PLL_FrequencyMeter_GetFreq(PLL_FM_MDTOP_F32K_CLOCK);
470
471 g_pll_info.pll_MDBPI0_div2 = PLL_FrequencyMeter_GetFreq(PLL_FM_MDBPI_PLL_0_DIV2);
472 g_pll_info.pll_MDBPI2 = PLL_FrequencyMeter_GetFreq(PLL_FM_MDBPI_PLL_2);
473 g_pll_info.pll_MDBPI1 = PLL_FrequencyMeter_GetFreq(PLL_FM_MDBPI_PLL_1);
474 g_pll_info.pll_MDBPI0 = PLL_FrequencyMeter_GetFreq(PLL_FM_MDBPI_PLL_0);
475 g_pll_info.pll_MDTX = PLL_FrequencyMeter_GetFreq(PLL_FM_MDTX_PLL);
476 g_pll_info.pll_MDBRP = PLL_FrequencyMeter_GetFreq(PLL_FM_MDBRP_PLL);
477 g_pll_info.pll_MDVDSP = PLL_FrequencyMeter_GetFreq(PLL_FM_MDVDSP_PLL);
478 g_pll_info.pll_MDMCU = PLL_FrequencyMeter_GetFreq(PLL_FM_MDMCU_PLL);
479
480}
481
482 /*------------------------------------------------------------------------
483 * void PLL_PLLMIXED_PLL_ON_CTL
484 * Purpose: SW force on pll or restore to HW mode.
485 * Parameters:
486 * Input: PLL_SOURCE pll: PLL_xxx in "Pll_gen93m17.h", module index.
487 * kal_bool force_on:
488 * KAL_TRUE => SW force on pll.
489 * KAL_FALSE => Restore to HW mode.
490 *
491 * Output: None.
492 *
493 * returns :
494 * KAL_TRUE/KAL_FALSE
495 * Note : Porting from LR12's md_pll_sw_force_on().
496 *
497 *------------------------------------------------------------------------
498 */
499kal_bool PLL_PLLMIXED_PLL_ON_CTL(PLL_SOURCE pll, kal_bool force_on)
500{/* Note: There is one user now, if there are more user, we should add spinlock to protect race condition. */
501 kal_uint32 caller_LR;
502 kal_uint32 bit_offset = 0;
503 GET_RETURN_ADDRESS(caller_LR);
504
505 switch(pll)
506 {
507 case PLL_MDTX:
508 bit_offset = 1 << 4;
509 if(force_on)
510 {
511 // Switch to s/w mode and force on
512 *REG_MDTOP_PLLMIXED_PLL_ON_CTL |= ( bit_offset|(bit_offset<<16) );
513 MO_Sync();
514 /* Note: This polling may spend 62~63 us due to HW PLL state machine. */
515 while((*REG_MDTOP_PLLMIXED_MDTXPLL_STS & 0xF) != 0x6){}
516 }
517 else
518 {
519 // Switch to h/w mode
520 *REG_MDTOP_PLLMIXED_PLL_ON_CTL &= ~( bit_offset|(bit_offset<<16) );
521 MO_Sync();
522 }
523 break;
524
525 default:/* Un-support pll */
526 EXT_ASSERT(0, caller_LR, pll, 0);
527 return KAL_FALSE;
528 break;
529 }
530
531 return KAL_TRUE;
532}
533
534 /*------------------------------------------------------------------------
535 * void PLL_CLKSW_FLEXCKGEN_SEL_PLLSEL_Set
536 * Purpose: Configure specified module's PLL source selection.
537 * Parameters:
538 * Input: PLL_CLKSW_FLEXCKGEN module: xxx_FLEXCKGEN in "Pll_gen93m17.h", module index.
539 * PLL_CLKSW_FLEXCKGEN_PLL_SRC pll_sel: CLKSW_FLEXCKGEN_PLL_SRC_x(x=0~3) in "Pll_gen93m17.h", PLL source number.
540 * Output: None
541 * returns : None
542 * Note : Only support TXSYS_FLEXCKGEN now.(To avoid mis-control. We didn't support other modules before they request it.)
543 *
544 *------------------------------------------------------------------------
545 */
546void PLL_CLKSW_FLEXCKGEN_SEL_PLLSEL_Set(PLL_CLKSW_FLEXCKGEN module, PLL_CLKSW_FLEXCKGEN_PLL_SRC pll_sel)
547{
548 kal_uint32 caller_LR;
549 GET_RETURN_ADDRESS(caller_LR);
550
551 /* Configuration rage check */
552 if(module<CLKSW_FLEXCKGEN_START || module>=CLKSW_FLEXCKGEN_END || pll_sel < CLKSW_FLEXCKGEN_PLL_SRC_0 || pll_sel > CLKSW_FLEXCKGEN_PLL_SRC_3)
553 {
554 EXT_ASSERT(0, caller_LR, module, pll_sel);
555 }
556
557 switch(module)
558 {
559 case TXSYS_FLEXCKGEN:
560 *REG_MDTOP_CLKSW_TXSYS_FLEXCKGEN_SEL = ((*REG_MDTOP_CLKSW_TXSYS_FLEXCKGEN_SEL) & 0xFFFFFFCF) | (pll_sel<<4);
561 break;
562
563 default:/* Un-support module */
564 EXT_ASSERT(0, caller_LR, module, pll_sel);
565 break;
566 }
567
568 MO_Sync();
569}
570
571 /*------------------------------------------------------------------------
572 * void PLL_CLKSW_FLEXCKGEN_SEL_DIVSEL_Set
573 * Purpose: Configure specified module's PLL divisor.
574 * Parameters:
575 * Input: PLL_CLKSW_FLEXCKGEN module: xxx_FLEXCKGEN in "Pll_gen93m17.h", module index.
576 * PLL_CLKSW_FLEXCKGEN_DIV div_sel: CLKSW_FLEXCKGEN_DIV_x(x=1~8) in "Pll_gen93m17.h", flexckgen divisor.
577 * Output: None
578 * returns : None
579 * Note : Only support TXSYS_FLEXCKGEN now.(To avoid mis-control. We didn't support other modules before they request it.)
580 *
581 *------------------------------------------------------------------------
582 */
583void PLL_CLKSW_FLEXCKGEN_SEL_DIVSEL_Set(PLL_CLKSW_FLEXCKGEN module, PLL_CLKSW_FLEXCKGEN_DIV div_sel)
584{
585 kal_uint32 caller_LR;
586 GET_RETURN_ADDRESS(caller_LR);
587
588 /* Configuration rage check */
589 if(module<CLKSW_FLEXCKGEN_START || module>=CLKSW_FLEXCKGEN_END || div_sel < CLKSW_FLEXCKGEN_DIV_1 || div_sel > CLKSW_FLEXCKGEN_DIV_8)
590 {
591 EXT_ASSERT(0, caller_LR, module, div_sel);
592 }
593
594 switch(module)
595 {
596 case TXSYS_FLEXCKGEN:
597 *REG_MDTOP_CLKSW_TXSYS_FLEXCKGEN_SEL = ((*REG_MDTOP_CLKSW_TXSYS_FLEXCKGEN_SEL) & 0xFFFFFFF8) | (div_sel);
598 break;
599
600 default:/* Un-support module */
601 EXT_ASSERT(0, caller_LR, module, div_sel);
602 break;
603 }
604
605 MO_Sync();
606}
607
608 /*------------------------------------------------------------------------
609 * void PLL_CLKSW_FLEXCKGEN_SEL_Get
610 * Purpose: Get specified module's PLL source selection and divisor.
611 * Parameters:
612 * Input: PLL_CLKSW_FLEXCKGEN module: xxx_FLEXCKGEN in "Pll_gen93m17.h", module index.
613 *
614 * Output: kal_uint32 *pll_sel: The PLL source selection(0~3).
615 * kal_uint32 *div_sel: The PLL divisor(0~7).
616 * returns : None
617 * Note : None.
618 *
619 *------------------------------------------------------------------------
620 */
621void PLL_CLKSW_FLEXCKGEN_SEL_Get(PLL_CLKSW_FLEXCKGEN module, kal_uint32 *pll_sel, kal_uint32 *div_sel)
622{
623 kal_uint32 caller_LR, reg_val = 0;
624 GET_RETURN_ADDRESS(caller_LR);
625
626 if(module<CLKSW_FLEXCKGEN_START || module>=CLKSW_FLEXCKGEN_END)
627 {
628 EXT_ASSERT(0, caller_LR, module, 0);
629 }
630
631 switch(module)
632 {
633 case MDCORE_FLEXCKGEN:
634 reg_val = (*REG_MDTOP_CLKSW_MDCORE_FLEXCKGEN_SEL);
635 break;
636
637 case MDSYS_BUS_FLEXCKGEN:
638 reg_val = (*REG_MDTOP_CLKSW_MDSYS_BUS_FLEXCKGEN_SEL);
639 break;
640
641 case VDSP_FLEXCKGEN:
642 reg_val = (*REG_MDTOP_CLKSW_VDSP_FLEXCKGEN_SEL);
643 break;
644
645 case BRP_FLEXCKGEN:
646 reg_val = (*REG_MDTOP_CLKSW_BRP_FLEXCKGEN_SEL);
647 break;
648
649 case RAKE_FLEXCKGEN:
650 reg_val = (*REG_MDTOP_CLKSW_RAKE_FLEXCKGEN_SEL);
651 break;
652
653 case TXSYS_FLEXCKGEN:
654 reg_val = (*REG_MDTOP_CLKSW_TXSYS_FLEXCKGEN_SEL);
655 break;
656
657 case CSSYS_FLEXCKGEN:
658 reg_val = (*REG_MDTOP_CLKSW_CSSYS_FLEXCKGEN_SEL);
659 break;
660
661 case MD2G_FLEXCKGEN:
662 reg_val = (*REG_MDTOP_CLKSW_MD2G_FLEXCKGEN_SEL);
663 break;
664
665 case BSI_FLEXCKGEN:
666 reg_val = (*REG_MDTOP_CLKSW_BSI_FLEXCKGEN_SEL);
667 break;
668
669 case DBG_FLEXCKGEN:
670 reg_val = (*REG_MDTOP_CLKSW_DBG_FLEXCKGEN_SEL);
671 break;
672
673 case LOG_ATB_FLEXCKGEN:
674 reg_val = (*REG_MDTOP_CLKSW_LOG_ATB_FLEXCKGEN_SEL);
675 break;
676
677 default:/* Un-support module */
678 EXT_ASSERT(0, caller_LR, module, 0);
679 break;
680 }
681
682 *pll_sel = (reg_val & 0x30)>>4;
683 *div_sel = (reg_val & 0x7);
684
685}
686
687 /*------------------------------------------------------------------------
688 * void PLL_CLKSW_FLEXCKGEN_STS_Get
689 * Purpose: Get specified module's clock generator status.
690 * Parameters:
691 * Input: PLL_CLKSW_FLEXCKGEN module: xxx_FLEXCKGEN in "Pll_gen93m17.h", module index.
692 *
693 * Output: kal_uint32 *ck_rdy: clock ready.
694 * kal_uint32 *ckgen_state: clock generator state(0:CKSEL_UPDATE, 1:CG_OFF, 2:CG_ON).
695 * kal_uint32 *pll_req: clock request PLL source (one-hot).
696 * returns : None
697 * Note : None.
698 *
699 *------------------------------------------------------------------------
700 */
701void PLL_CLKSW_FLEXCKGEN_STS_Get(PLL_CLKSW_FLEXCKGEN module, kal_uint32 *ck_rdy, kal_uint32 *ckgen_state, kal_uint32 *pll_req)
702{
703 kal_uint32 caller_LR, reg_val = 0;
704 GET_RETURN_ADDRESS(caller_LR);
705
706 if(module<CLKSW_FLEXCKGEN_START || module>=CLKSW_FLEXCKGEN_END)
707 {
708 EXT_ASSERT(0, caller_LR, module, 0);
709 }
710
711 switch(module)
712 {
713 case MDCORE_FLEXCKGEN:
714 reg_val = (*REG_MDTOP_CLKSW_MDCORE_FLEXCKGEN_STS);
715 break;
716
717 case MDSYS_BUS_FLEXCKGEN:
718 reg_val = (*REG_MDTOP_CLKSW_MDSYS_BUS_FLEXCKGEN_STS);
719 break;
720
721 case VDSP_FLEXCKGEN:
722 reg_val = (*REG_MDTOP_CLKSW_VDSP_FLEXCKGEN_STS);
723 break;
724
725 case BRP_FLEXCKGEN:
726 reg_val = (*REG_MDTOP_CLKSW_BRP_FLEXCKGEN_STS);
727 break;
728
729 case RAKE_FLEXCKGEN:
730 reg_val = (*REG_MDTOP_CLKSW_RAKE_FLEXCKGEN_STS);
731 break;
732
733 case TXSYS_FLEXCKGEN:
734 reg_val = (*REG_MDTOP_CLKSW_TXSYS_FLEXCKGEN_STS);
735 break;
736
737 case CSSYS_FLEXCKGEN:
738 reg_val = (*REG_MDTOP_CLKSW_CSSYS_FLEXCKGEN_STS);
739 break;
740
741 case MD2G_FLEXCKGEN:
742 reg_val = (*REG_MDTOP_CLKSW_MD2G_FLEXCKGEN_STS);
743 break;
744
745 case BSI_FLEXCKGEN:
746 reg_val = (*REG_MDTOP_CLKSW_BSI_FLEXCKGEN_STS);
747 break;
748
749 case DBG_FLEXCKGEN:
750 reg_val = (*REG_MDTOP_CLKSW_DBG_FLEXCKGEN_STS);
751 break;
752
753 case LOG_ATB_FLEXCKGEN:
754 reg_val = (*REG_MDTOP_CLKSW_LOG_ATB_FLEXCKGEN_STS);
755 break;
756
757 default:/* Un-support module */
758 EXT_ASSERT(0, caller_LR, module, 0);
759 break;
760 }
761
762 *ck_rdy = (reg_val & 0x8000)>>15;
763 *ckgen_state = (reg_val & 0x300)>>8;
764 *pll_req = reg_val & 0xF;
765
766}
767
768 /*------------------------------------------------------------------------
769 * void PLL_CLKSW_MDTOPSM_SW_CTL
770 * Purpose: SW force on module clock request or restore to HW mode.
771 * Parameters:
772 * Input: PLL_CLKSW_MDTOPSM_SW_CTL_SRC module: CLKSW_MDTOPSM_xxx_CK in "Pll_gen93m17.h", module index.
773 * kal_bool force_on:
774 * KAL_TRUE => SW force on module clock request.
775 * KAL_FALSE => Restore to HW mode.
776 *
777 * Output: None.
778 *
779 * returns :
780 * KAL_TRUE/KAL_FALSE
781 * Note : Porting from LR12's md_pll_sw_req_clk_on() and md_pll_sw_req_clk_off().
782 *
783 *------------------------------------------------------------------------
784 */
785kal_bool PLL_CLKSW_MDTOPSM_SW_CTL(PLL_CLKSW_MDTOPSM_SW_CTL_SRC module, kal_bool force_on)
786{/* Note: There is one user now, if there are more user, we should add spinlock to protect race condition. */
787 kal_uint32 caller_LR/*, count = 0*/;
788 GET_RETURN_ADDRESS(caller_LR);
789
790 switch(module)
791 {
792#if 0 /* DBG_CK on/off should call TOPSM's function, so we disable this function here. */
793/* under construction !*/
794/* under construction !*/
795/* under construction !*/
796/* under construction !*/
797/* under construction !*/
798/* under construction !*/
799/* under construction !*/
800/* under construction !*/
801/* under construction !*/
802/* under construction !*/
803/* under construction !*/
804/* under construction !*/
805/* under construction !*/
806/* under construction !*/
807/* under construction !*/
808/* under construction !*/
809/* under construction !*/
810/* under construction !*/
811/* under construction !*/
812/* under construction !*/
813/* under construction !*/
814/* under construction !*/
815/* under construction !*/
816/* under construction !*/
817/* under construction !*/
818/* under construction !*/
819/* under construction !*/
820/* under construction !*/
821/* under construction !*/
822/* under construction !*/
823/* under construction !*/
824/* under construction !*/
825/* under construction !*/
826#endif
827 default:/* Un-support module */
828 EXT_ASSERT(0, caller_LR, module, 0);
829 return KAL_FALSE;
830 break;
831 }
832
833 return KAL_TRUE;
834
835}
836
837/****************************************************************
838 Function for SDF module. (uSIB)
839****************************************************************/
840 /*------------------------------------------------------------------------
841 * void PLL_CLKSW_SDF_SRC_CKSEL_Get
842 * Purpose: Get the selection of SDF source clock.
843 * Parameters:
844 * Input: None.
845 *
846 * Output: None.
847 *
848 * returns : The selection of SDF source clock
849 *
850 * Note : Porting from LR12's PLL_SDF_SRC_CKSEL_GET().
851 *
852 *------------------------------------------------------------------------
853 */
854kal_uint32 PLL_CLKSW_SDF_SRC_CKSEL_Get()
855{
856 if((*REG_MDTOP_CLKSW_SDF_CK_CTL&(1<<4))==0)
857 {
858 return CLKSW_SDF_SRC_26M;
859 }
860 else
861 {
862 return (((*REG_MDTOP_CLKSW_SDF_CK_CTL) & 0x00000700) >> 8);
863 }
864}
865
866 /*------------------------------------------------------------------------
867 * void PLL_CLKSW_SDF_SRC_CKSEL_Set
868 * Purpose: Set the selection of SDF source clock.
869 * Parameters:
870 * Input: PLL_CLKSW_SDF_SRC src_ck: CLKSW_SDF_SRC_xxx in "Pll_gen93m17.h", src_clk index.
871 *
872 * Output: None.
873 *
874 * returns : KAL_TRUE/KAL_FALSE
875 *
876 * Note : Porting from LR12's PLL_SDF_SRC_CKSEL_SET().
877 *
878 *------------------------------------------------------------------------
879 */
880kal_bool PLL_CLKSW_SDF_SRC_CKSEL_Set(PLL_CLKSW_SDF_SRC src_clk)
881{
882 kal_uint32 caller_LR;
883 GET_RETURN_ADDRESS(caller_LR);
884
885 if (src_clk >= CLKSW_SDF_SRC_END)
886 {
887 EXT_ASSERT(0, caller_LR, src_clk, 0);
888 return KAL_FALSE;
889 }
890
891 if(src_clk == CLKSW_SDF_SRC_26M)
892 {/* Restore to default setting */
893
894 // SDF clock switch to 26Mhz
895 *REG_MDTOP_CLKSW_SDF_CK_CTL &= ~(1<<4);
896
897 //restore SDF clock source
898 *REG_MDTOP_CLKSW_SDF_CK_CTL = ((*REG_MDTOP_CLKSW_SDF_CK_CTL) & 0xFFFFF8FF) | (CLKSW_SDF_SRC_BPIPLL<<8);
899 }
900 else
901 {
902 // SDF clock switch to 26Mhz
903 *REG_MDTOP_CLKSW_SDF_CK_CTL &= ~(1<<4);
904
905 //set SDF clock source
906 *REG_MDTOP_CLKSW_SDF_CK_CTL = ((*REG_MDTOP_CLKSW_SDF_CK_CTL) & 0xFFFFF8FF) | (src_clk<<8);
907
908 // SDF clock switch to full speed
909 *REG_MDTOP_CLKSW_SDF_CK_CTL |= (1<<4);
910 }
911
912 MO_Sync();
913
914 return KAL_TRUE;
915}
916
917 /*------------------------------------------------------------------------
918 * void PLL_CLKSW_SDF_CK_Req
919 * Purpose: Request the SDF source clock or not.
920 * Parameters:
921 * Input: kal_bool clk_req: KAL_TRUE/KAL_FALSE.
922 *
923 * Output: None.
924 *
925 * returns : None
926 *
927 * Note : Porting from LR12's PLL_SDF_CK_ON() & PLL_SDF_CK_OFF().
928 *
929 *------------------------------------------------------------------------
930 */
931void PLL_CLKSW_SDF_CK_Req(kal_bool clk_req)
932{
933 if(clk_req)
934 {/* SDF clock request */
935 *REG_MDTOP_CLKSW_SDF_CK_CTL = *REG_MDTOP_CLKSW_SDF_CK_CTL | (1 << 0);
936 }
937 else
938 {/* No SDF clock request */
939 *REG_MDTOP_CLKSW_SDF_CK_CTL = *REG_MDTOP_CLKSW_SDF_CK_CTL & ~(1 << 0);
940 }
941
942 MO_Sync();
943}
944
945#endif /* should NOT be compiled on MODIS */