blob: f9db25d39e308cd30c5c4dfc13bb66b61110ced8 [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_gen97.c
40 *
41 * Project:
42 * --------
43 * UMOLYE
44 *
45 * Description:
46 * ------------
47 * PLL Related Functions
48 *
49 * Author:
50 * -------
51 * -------
52 *
53 * ==========================================================================
54 * $Log$
55 *
56 *
57 *
58 ****************************************************************************/
59//wolf: the code below is not ready, just for build pass~
60#ifdef __MTK_TARGET__ /* should NOT be compiled on MODIS */
61
62/*******************************************************************************
63 * Locally Used Options
64 *******************************************************************************/
65
66/*******************************************************************************
67 * Include header files
68 *******************************************************************************/
69
70#include "pll.h"
71#include "kal_public_api.h"
72#include "sync_data.h"
73#include "us_timer.h"
74#include "sleepdrv_common.h"
75
76#define PLL_FM_WIMDOW (0x1FF)
77
78/* Below for debugging */
79const char PLL_FM_clock[PLL_FM_NUM][32] =
80{
81 "AD_MDNRPLL5", /* 0 */
82 "AD_MDNRPLL4_1",
83 "AD_MDNRPLL4_0",
84 "AD_MDNRPLL3",
85 "AD_MDNRPLL2",
86 "AD_MDNRPLL1", /* 5 */
87 "AD_MDNRPLL0",
88 "MDSYS_NRL2_CLOCK",
89 "MDRXSYS_DFESYNC_CLOCK",
90 "MDTOP_F216P7M_CLOCK",
91 "TRACE_MON_CLOCK", /* 10 */
92 "MDSYS_216P7M_CLOCK",
93 "MDRXSYS_RAKE_CLOCK",
94 "MDRXSYS_BRP_CLOCK",
95 "MDRXSYS_VDSP_CLOCK",
96 "MDTOP_LOG_ATB_CLOCK", /* 15 */
97 "FESYS_CSYS_CLOCK",
98 "MDSYS_SHAOLIN_CLOCK",
99 "FESYS_BSI_CLOCK",
100 "MDSYS_MDCORE_CLOCK",
101 "MDSYS_BUS2X_NODCM_CLOCK",/* 20 */
102 "MDSYS_BUS4X_CLOCK",
103 "MDTOP_DBG_CLOCK",
104 "AD_MDBPI_PLL_D7",
105 "AD_MDBPI_PLL_D5",
106 "AD_MDBPI_PLL_D4", /* 25 */
107 "AD_MDBPI_PLL_D3",
108 "AD_MDBPI_PLL_D2",
109 "AD_MDBRP_PLL",
110 "AD_MDVDSP_PLL",
111 "AD_MDMCU_PLL", /* 30 */
112 "DFESYS_RXDFE_BB_CORE_CLOCK",
113 "AD_MDNRPLL4_2",
114 "MDTOP_BUS4X_FIXED_CLOCK",
115 "DA_DRF_26M_CLOCK",
116 "MDTOP_BUS4X_CLOCK", /* 35 */
117 "RXCPC_CPC_CLOCK",
118 "RXDDMBRP_RXDBRP_CLOCK",
119 "RXDDMBRP_RXDDM_CLOCK",
120 "MCORE_MCORE_CLOCK",
121 "VCOREHRAM_VCORE_CLOCK", /* 40 */
122 "VCOREHRAM_HRAM_CLOCK",
123 "FESYS_TXBSRP_CLOCK",
124 "FESYS_MDPLL_CLOCK",
125 "TX_CS_NR_RXT2F_NR_CLOCK",
126 "TX_CS_NR_TXBSRP_NR_CLOCK",/* 45 */
127 "TX_CS_NR_CM_NR_CLOCK",
128 "TX_CS_NR_CS_NR_CLOCK"
129 /* we couldn't add more PLL here... */
130};
131
132PLL_CLK_INFO g_pll_info = {0};
133
134/* Above for debugging */
135
136/**
137 * This function is used to detect ASIC or FPGA version of Palladium
138 */
139__PLL_CODE_IN_BOOT__ kal_bool PLL_FPGA_IS_ASIC(void)
140{
141#if defined(__FPGA__)
142 kal_uint32 asic_flag = *((volatile kal_uint32 *)(0xA0000018)) & (0x1 << 7);
143
144 if (asic_flag == 0)
145 return KAL_TRUE;
146 else
147 return KAL_FALSE;
148#else
149 return KAL_TRUE;
150#endif
151}
152
153__PLL_CODE_IN_BOOT__ void INT_SetPLL_Gen97P(void)
154{
155
156}
157
158__PLL_CODE_IN_BOOT__ kal_uint8 pll_get_current_vpe_id(void)
159{
160 unsigned int vpe_id = 0;
161
162 __asm__ __volatile__(
163 "mfc0 %0, $15, 1" \
164 : "=r" (vpe_id) \
165 :);
166
167 return (vpe_id & 0xF);
168}
169
170/*************************************************************************
171 * FUNCTION
172 * INT_SetPLL
173 *
174 * DESCRIPTION
175 * This function dedicates for PLL setting.
176 *
177 * PARAMETERS
178 * Init mode of PLL
179 *
180 * RETURNS
181 * Note : This function would only call by MD.
182 *************************************************************************/
183__PLL_CODE_IN_BOOT__ void INT_SetPLL(void)
184{
185#if !defined(__COSIM_BYPASS__) && !defined(__ESL_MASE__)
186 if ((pll_get_current_vpe_id() == 0))
187 {
188 if (*REG_MDTOP_PLLMIXED_PLL_DUMMY != MD_PLL_MAGIC_NUM)
189 {/* PLL didn't init by BootRom */
190 PLL_MD_Pll_Init();
191
192 // Make a record that means MD pll has init by MD.
193 *REG_MDTOP_PLLMIXED_PLL_DUMMY = MD_PLL_MAGIC_MD;
194 }
195 }
196#endif // __COSIM_BYPASS__
197}
198
199/*************************************************************************
200 * FUNCTION
201 * PLL_MD_Pll_Init
202 *
203 * DESCRIPTION
204 * This function dedicates for PLL setting.
205 *
206 * PARAMETERS
207 * Init mode of PLL
208 *
209 * RETURNS
210 * Note : This function would call by BootRom and MD!!
211 *************************************************************************/
212__PLL_CODE_IN_BOOT__ void PLL_MD_Pll_Init(void)
213{
214#if !defined(__COSIM_BYPASS__) && !defined(__ESL_MASE__)
215 INT_SetPLL_Gen97P();
216#endif // __COSIM_BYPASS__
217}
218
219 /*------------------------------------------------------------------------
220 * void PLL_Check_26M_ACK_Status
221 * Purpose: Check 26M ACK Status to know 26M is ready.
222 * Parameters:
223 * Input: kal_uint32 identifier: Any value to let us confirm the caller.
224 *
225 * Output: None.
226 *
227 * returns : void.
228 * Note : This function would call by Idle_Service_Handler()
229 *
230 *------------------------------------------------------------------------
231 */
232void PLL_Check_26M_ACK_Status(kal_uint32 identifier)
233{
234 #if defined(__PRODUCTION_RELEASE__) || defined(__MAUI_BASIC__) || defined(__MODEM_ONLY__)
235 /* Do nothing. */
236 #else
237/* under construction !*/
238 #endif
239}
240
241 /*------------------------------------------------------------------------
242 * void PLL_Set_CLK_To_26M
243 * Purpose: Re-configure all the module clocks from PLL to 26M.
244 * Parameters:
245 * Input: None.
246 *
247 * Output: None.
248 *
249 * returns : void.
250 * Note : This function would call by BootRom!!
251 *
252 *------------------------------------------------------------------------
253 */
254__PLL_CODE_IN_BOOT__ void PLL_Set_CLK_To_26M(void)
255{
256 *REG_MDTOP_CLKSW_CLKON_CTL = 0x10001; // set to default value
257 *REG_MDTOP_CLKSW_CLKSEL_CTL = 0x14000; //switch all clock to XTAL frequency
258 *REG_MDTOP_CLKSW_CLKSEL_CTL_2 = 0x0; //switch all clock to XTAL frequency
259 *REG_MDTOP_CLKSW_SDF_ATB_CK_CTL = 0x100001; // switch SDF clock to XTAL frequency
260
261 MO_Sync();
262 // Make a record that means MD pll has been changed to 26M.
263 *REG_MDTOP_PLLMIXED_PLL_DUMMY = MD_PLL_MAGIC_26M;
264}
265
266 /*------------------------------------------------------------------------
267 * void PLL_FrequencyMeter_GetFreq
268 * Purpose: Get specified PLL/module's clock(Mhz).
269 * Parameters:
270 * Input: PLL_FM_SOURCE index: The module you want to measure.
271 *
272 * Output: None.
273 *
274 * returns : The PLL/module's clock(Mhz).
275 * Note : This function would spend at least 20us to measure the clock.
276 *
277 *------------------------------------------------------------------------
278 */
279kal_uint32 PLL_FrequencyMeter_GetFreq(PLL_FM_SOURCE index)
280{
281 kal_uint32 count = 5000, output = 0;
282
283 if ((index < PLL_FM_SOURCE_START) || (index > PLL_FM_SOURCE_END))
284 return 0;
285
286 *REG_MDTOP_CLKSW_CKMON_CTL = PLL_FM_MDSYS_BUS4X_CLOCK; //select source to a valid clock to let reset success.
287
288 *REG_MDTOP_CLKSW_FREQ_METER_CTL = 0; //reset frequency meter
289
290 MO_Sync();
291 ust_us_busyloop(2);//let Frequency Meter reset done
292
293 *REG_MDTOP_CLKSW_CKMON_CTL = 0x300 | index; //divided by 8 and select source
294 *REG_MDTOP_CLKSW_FREQ_METER_XTAL_CNT = PLL_FM_WIMDOW;
295 *REG_MDTOP_CLKSW_FREQ_METER_CTL = 1; //enable frequency meter
296 MO_Sync();
297
298 // wait measure done or timeout
299 while (((*REG_MDTOP_CLKSW_FREQ_METER_CTL) & (1 << 1)) == 0)
300 {
301 count--;
302 if (count == 0)
303 break;
304 }
305
306 if (count == 0)
307 return 0;
308
309 output = *REG_MDTOP_CLKSW_FREQ_METER_CKMON_CNT * 26 * 8 / (PLL_FM_WIMDOW+3);
310
311 *REG_MDTOP_CLKSW_CKMON_CTL = 0; //select source to NULL to save power in flip-flop, save about 0.07mA in 6293
312
313 *REG_MDTOP_CLKSW_FREQ_METER_CTL = 0; //reset frequency meter
314
315 return output;
316}
317
318void PLL_exception_dump(void)
319{
320#if 0
321/* under construction !*/
322/* under construction !*/
323/* under construction !*/
324/* under construction !*/
325/* under construction !*/
326/* under construction !*/
327/* under construction !*/
328/* under construction !*/
329/* under construction !*/
330/* under construction !*/
331/* under construction !*/
332/* under construction !*/
333/* under construction !*/
334/* under construction !*/
335/* under construction !*/
336/* under construction !*/
337/* under construction !*/
338/* under construction !*/
339/* under construction !*/
340/* under construction !*/
341/* under construction !*/
342/* under construction !*/
343/* under construction !*/
344/* under construction !*/
345/* under construction !*/
346/* under construction !*/
347/* under construction !*/
348/* under construction !*/
349/* under construction !*/
350/* under construction !*/
351/* under construction !*/
352/* under construction !*/
353/* under construction !*/
354/* under construction !*/
355/* under construction !*/
356/* under construction !*/
357/* under construction !*/
358/* under construction !*/
359/* under construction !*/
360/* under construction !*/
361/* under construction !*/
362/* under construction !*/
363/* under construction !*/
364/* under construction !*/
365/* under construction !*/
366/* under construction !*/
367/* under construction !*/
368/* under construction !*/
369/* under construction !*/
370/* under construction !*/
371/* under construction !*/
372/* under construction !*/
373#endif
374}
375
376
377/****************************************************************
378 Function for SDF module. (SIB)
379****************************************************************/
380 /*------------------------------------------------------------------------
381 * void PLL_CLKSW_SDF_SRC_CKSEL_Get
382 * Purpose: Get the selection of SDF source clock.
383 * Parameters:
384 * Input: None.
385 *
386 * Output: None.
387 *
388 * returns : The selection of SDF source clock.
389 *
390 * Note :
391 *
392 *------------------------------------------------------------------------
393 */
394kal_uint32 PLL_CLKSW_SDF_SRC_CKSEL_Get()
395{
396 if((*REG_MDTOP_CLKSW_SDF_ATB_CK_CTL&(1<<4))==0)
397 {
398 return CLKSW_SDF_SRC_26M;
399 }
400 else
401 {
402 return (((*REG_MDTOP_CLKSW_SDF_ATB_CK_CTL) & 0x00000180) >> 7);
403 }
404}
405
406 /*------------------------------------------------------------------------
407 * void PLL_CLKSW_SDF_SRC_CKSEL_Div_Get
408 * Purpose: Get the selection of SDF source clock Div.
409 * Parameters:
410 * Input: None.
411 *
412 * Output: None.
413 *
414 * returns : The selection of SDF source clock Div
415 *
416 * Note :
417 *
418 *------------------------------------------------------------------------
419 */
420kal_uint32 PLL_CLKSW_SDF_SRC_CKSEL_Div_Get()
421{
422 return (((*REG_MDTOP_CLKSW_SDF_ATB_CK_CTL) & 0x00000060) >> 5);
423}
424
425 /*------------------------------------------------------------------------
426 * void PLL_CLKSW_SDF_SRC_CKSEL_Set
427 * Purpose: Set the selection of SDF source clock.
428 * Parameters:
429 * Input: PLL_CLKSW_SDF_SRC src_ck: CLKSW_SDF_SRC_xxx in "Pll_gen97.h", src_clk index.
430 * PLL_CLKSW_SDF_SRC_DIV src_div: CLKSW_SDF_SRC_xxx in "Pll_gen97.h", src_div index.
431 * Output: None.
432 *
433 * returns : KAL_TRUE/KAL_FALSE
434 *
435 * Note : Porting from LR12's PLL_SDF_SRC_CKSEL_SET().
436 *
437 *------------------------------------------------------------------------
438 */
439kal_bool PLL_CLKSW_SDF_SRC_CKSEL_Set(PLL_CLKSW_SDF_SRC src_clk, PLL_CLKSW_SDF_SRC_DIV src_div)
440{
441 kal_uint32 /*caller_LR, */tmp = 0;
442 //GET_RETURN_ADDRESS(caller_LR);
443
444 if (src_clk >= CLKSW_SDF_SRC_END)
445 {
446 //EXT_ASSERT(0, caller_LR, src_clk, 0);
447 return KAL_FALSE;
448 }
449
450 if(src_clk == CLKSW_SDF_SRC_26M)
451 {/* Restore to default setting */
452
453 // SDF clock switch to 26Mhz
454 *REG_MDTOP_CLKSW_SDF_ATB_CK_CTL &= ~(1<<4);
455
456 //restore SDF clock source
457 *REG_MDTOP_CLKSW_SDF_ATB_CK_CTL = ((*REG_MDTOP_CLKSW_SDF_ATB_CK_CTL) & 0xFFFFFC1F);
458 }
459 else
460 {
461 // SDF clock switch to 26Mhz
462 *REG_MDTOP_CLKSW_SDF_ATB_CK_CTL &= ~(1<<4);
463
464 //set SDF clock source
465 tmp = (src_clk<<7) | (src_div<<5);
466 *REG_MDTOP_CLKSW_SDF_ATB_CK_CTL = ((*REG_MDTOP_CLKSW_SDF_ATB_CK_CTL) & 0xFFFFFC1F) | (tmp);
467
468 // SDF clock switch to full speed
469 *REG_MDTOP_CLKSW_SDF_ATB_CK_CTL |= (1<<4);
470 }
471
472 MO_Sync();
473
474 return KAL_TRUE;
475}
476
477#endif /* should NOT be compiled on MODIS */