rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | /***************************************************************************** |
| 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) 2014 |
| 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 | * |
| 38 | * Filename: |
| 39 | * --------- |
| 40 | * cmif.c |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * |
| 49 | * |
| 50 | * |
| 51 | * Author: |
| 52 | * ------- |
| 53 | * ------- |
| 54 | * |
| 55 | *============================================================================ |
| 56 | * HISTORY |
| 57 | * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 58 | *------------------------------------------------------------------------------ |
| 59 | * removed! |
| 60 | * removed! |
| 61 | * removed! |
| 62 | * |
| 63 | * removed! |
| 64 | * removed! |
| 65 | * |
| 66 | * removed! |
| 67 | * removed! |
| 68 | * removed! |
| 69 | * removed! |
| 70 | * |
| 71 | * removed! |
| 72 | * removed! |
| 73 | * removed! |
| 74 | * removed! |
| 75 | * removed! |
| 76 | * removed! |
| 77 | * removed! |
| 78 | * removed! |
| 79 | * |
| 80 | * removed! |
| 81 | * removed! |
| 82 | * removed! |
| 83 | * removed! |
| 84 | * removed! |
| 85 | * removed! |
| 86 | * removed! |
| 87 | * |
| 88 | * removed! |
| 89 | * removed! |
| 90 | * removed! |
| 91 | * removed! |
| 92 | * |
| 93 | * removed! |
| 94 | * removed! |
| 95 | * removed! |
| 96 | * removed! |
| 97 | * |
| 98 | * removed! |
| 99 | * removed! |
| 100 | * removed! |
| 101 | * removed! |
| 102 | * |
| 103 | * removed! |
| 104 | * removed! |
| 105 | * removed! |
| 106 | * removed! |
| 107 | * |
| 108 | * removed! |
| 109 | * removed! |
| 110 | * removed! |
| 111 | * |
| 112 | * removed! |
| 113 | * removed! |
| 114 | * removed! |
| 115 | * |
| 116 | * removed! |
| 117 | * removed! |
| 118 | * removed! |
| 119 | * |
| 120 | * removed! |
| 121 | * removed! |
| 122 | * removed! |
| 123 | * |
| 124 | * removed! |
| 125 | * removed! |
| 126 | * removed! |
| 127 | * |
| 128 | * removed! |
| 129 | * removed! |
| 130 | * removed! |
| 131 | * |
| 132 | * removed! |
| 133 | * removed! |
| 134 | * |
| 135 | * removed! |
| 136 | * removed! |
| 137 | * removed! |
| 138 | * |
| 139 | * removed! |
| 140 | * removed! |
| 141 | * removed! |
| 142 | * |
| 143 | * |
| 144 | * |
| 145 | *------------------------------------------------------------------------------ |
| 146 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 147 | *============================================================================ |
| 148 | ****************************************************************************/ |
| 149 | |
| 150 | #include "drv_cmif_l1core.h" |
| 151 | #include "kal_hrt_api.h" |
| 152 | #include "gen93_proj_config.h" |
| 153 | |
| 154 | #if defined(__CMIF_DEBUG__) |
| 155 | #include "us_timer.h" |
| 156 | #endif |
| 157 | |
| 158 | #if defined(__MD32S_CMIF_DRV_TEST__) |
| 159 | #include "intrCtrl.h" |
| 160 | #include "kal_public_api.h" |
| 161 | #include "kal_general_types.h" |
| 162 | |
| 163 | |
| 164 | #define dbg_print(str, args...) |
| 165 | #endif /* __MD32S_CMIF_DRV_TEST__ */ |
| 166 | |
| 167 | |
| 168 | /******************************************************************************* |
| 169 | * Function prototypes |
| 170 | *******************************************************************************/ |
| 171 | #if defined(__CMIF_DEBUG__) |
| 172 | extern CMIF_DebugRecordList cmif_debug_records[CMIF_VPE_NUM]; |
| 173 | #endif |
| 174 | |
| 175 | |
| 176 | #if !defined(__CMIF_DEBUG__) |
| 177 | void cmif_InterruptHandlerInternal(volatile cmif_uint32* sreg, |
| 178 | volatile cmif_uint32* creg, |
| 179 | CMIF_InterruptEntryFun* handler, |
| 180 | cmif_bool* auto_eoi); |
| 181 | #else /* __CMIF_DEBUG__ */ |
| 182 | void cmif_InterruptHandlerInternal(volatile cmif_uint32* sreg, |
| 183 | volatile cmif_uint32* creg, |
| 184 | CMIF_InterruptEntryFun* handler, |
| 185 | cmif_bool* auto_eoi, |
| 186 | CMIF_DebugInterruptType interrupt_type); |
| 187 | #endif /* __CMIF_DEBUG__ */ |
| 188 | |
| 189 | /******************************************************************************* |
| 190 | * Functions - Common Part |
| 191 | *******************************************************************************/ |
| 192 | void CMIF_DefaultISR(CMIF_Mask_t* mask) |
| 193 | { |
| 194 | // code 1: status register value, code 2: status register addr, code 3: u3g, fpc_1x, do_pd, foe_1x (0~3) |
| 195 | CMIF_ASSERT(0, mask->mask31_0, |
| 196 | (cmif_uint32)mask->status_reg_addr, |
| 197 | ((cmif_uint32)mask->status_reg_addr - (cmif_uint32)CMIF_M2C_U3G_RAKE_STATUS) / CMIF_NEXT_INT_OFFSET); |
| 198 | |
| 199 | //CMIF_ASSERT(0, mask->mask31_0, 0, 0); |
| 200 | } |
| 201 | |
| 202 | #if defined(__CMIF_DEBUG__) |
| 203 | void cmif_DebugAddRecord(cmif_uint32 status, |
| 204 | cmif_uint32 set_addr, |
| 205 | cmif_uint32 set_value, |
| 206 | cmif_uint32 caller) |
| 207 | { |
| 208 | |
| 209 | cmif_uint32 save_index = 0; |
| 210 | cmif_uint32 vpe_id = kal_get_current_vpe_id(); |
| 211 | CMIF_ASSERT(vpe_id < CMIF_VPE_NUM, vpe_id, CMIF_VPE_NUM, 0); |
| 212 | |
| 213 | CMIF_DebugRecordList *cmif_debug_records_ptr = &cmif_debug_records[vpe_id]; |
| 214 | |
| 215 | /* 93,95 legacey code */ |
| 216 | /* |
| 217 | cmif_uint32 mask; |
| 218 | |
| 219 | mask = kal_hrt_SaveAndSetIRQMask(); |
| 220 | |
| 221 | // fetch and add top_index atomically. |
| 222 | save_index = cmif_debug_records_ptr->top_index; |
| 223 | |
| 224 | ++(cmif_debug_records_ptr->top_index); |
| 225 | if(cmif_debug_records_ptr->top_index == CMIF_DEBUG_ISR_HANDLE_CODE_SIZE){ |
| 226 | cmif_debug_records_ptr->top_index = 0; |
| 227 | } |
| 228 | |
| 229 | kal_hrt_RestoreIRQMask(mask); |
| 230 | */ |
| 231 | |
| 232 | save_index = kal_atomic_inc_circular_index(&(cmif_debug_records_ptr->top_index), CMIF_DEBUG_API_RECORD_SIZE); |
| 233 | |
| 234 | cmif_debug_records_ptr->records[save_index].time = ust_get_current_time(); |
| 235 | cmif_debug_records_ptr->records[save_index].status = status; |
| 236 | cmif_debug_records_ptr->records[save_index].set_addr = set_addr; |
| 237 | cmif_debug_records_ptr->records[save_index].set_value = set_value; |
| 238 | cmif_debug_records_ptr->records[save_index].caller = caller; |
| 239 | } |
| 240 | #endif /* __CMIF_DEBUG__ */ |
| 241 | |
| 242 | /** |
| 243 | * General interrupt handler function |
| 244 | * |
| 245 | * @param[in] sreg CMIF interrupt status register |
| 246 | * @param[in] creg CMIF interrupt clean register |
| 247 | * @param[in] handler CMIF user entry function lists |
| 248 | * @param[in] core CMIF interrupt core type - BRP, DFE and RAKE (Debug only) |
| 249 | * @param[in] interrupt_type CMIF interrupt type - U3G or U4G (Debug only) |
| 250 | **/ |
| 251 | #if !defined(__CMIF_DEBUG__) |
| 252 | void cmif_InterruptHandlerInternal(volatile cmif_uint32* sreg, |
| 253 | volatile cmif_uint32* creg, |
| 254 | CMIF_InterruptEntryFun* handler, |
| 255 | cmif_bool* auto_eoi |
| 256 | ) |
| 257 | #else /* __CMIF_DEBUG__ */ |
| 258 | void cmif_InterruptHandlerInternal(volatile cmif_uint32* sreg, |
| 259 | volatile cmif_uint32* creg, |
| 260 | CMIF_InterruptEntryFun* handler, |
| 261 | cmif_bool* auto_eoi, |
| 262 | CMIF_DebugInterruptType interrupt_type) |
| 263 | #endif /* __CMIF_DEBUG__ */ |
| 264 | { |
| 265 | cmif_uint32 eidx; // entry function index |
| 266 | CMIF_Mask_t cmif_mask; |
| 267 | #if defined(__CMIF_DEBUG__) |
| 268 | cmif_uint32 caller; |
| 269 | CMIF_GET_RETURN_ADDRESS(caller); |
| 270 | #endif /* __CMIF_DEBUG__ */ |
| 271 | |
| 272 | // for debug usage |
| 273 | cmif_mask.status_reg_addr = (cmif_uint32 *)sreg; |
| 274 | // read the sreg to the mask |
| 275 | cmif_mask.mask31_0 = CMIF_REG_READ(sreg); |
| 276 | |
| 277 | while(cmif_mask.mask31_0){ |
| 278 | // find the lsb |
| 279 | eidx = CMIF_GET_LSB(cmif_mask.mask31_0); |
| 280 | |
| 281 | // invoke the user register interupt handler function |
| 282 | (*handler[eidx])((CMIF_Mask_t *)&cmif_mask); |
| 283 | |
| 284 | // if the `irq_auto_eoi` is CMIF_TRUE, clean the interupt bit |
| 285 | if(auto_eoi[eidx] == CMIF_TRUE){ |
| 286 | |
| 287 | /* In 6291, JADE CMIF has a clear fail bug */ |
| 288 | /* This workaround ensure the clear transaction is success */ |
| 289 | #if defined(__CMIF_DRV_SW_WORKAROUND__) |
| 290 | do{ |
| 291 | #endif |
| 292 | CMIF_REG_WRITE(creg, 1 << eidx); |
| 293 | #if defined(__CMIF_DRV_SW_WORKAROUND__) |
| 294 | }while((CMIF_REG_READ(sreg) >> eidx) & 0x1); |
| 295 | #endif |
| 296 | |
| 297 | #if defined(__CMIF_DEBUG__) |
| 298 | cmif_DebugAddRecord(cmif_mask.mask31_0, (cmif_uint32)creg, (1 << eidx), caller); |
| 299 | #endif /* __CMIF_DEBUG__ */ |
| 300 | } |
| 301 | |
| 302 | #if defined(__CMIF_DEBUG__) |
| 303 | cmif_DebugAddISRHandle(eidx, interrupt_type); |
| 304 | #endif /* __CMIF_DEBUG__ */ |
| 305 | |
| 306 | // read the sreg to the mask |
| 307 | cmif_mask.mask31_0 = CMIF_REG_READ(sreg); |
| 308 | |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | |
| 313 | /******************************************************************************* |
| 314 | * Functions - Driver test |
| 315 | *******************************************************************************/ |
| 316 | |
| 317 | #if defined(__MD32S_CMIF_DRV_TEST__) |
| 318 | |
| 319 | extern CMIF_Ctrl_t cmif_ctrl_rake_u3g; |
| 320 | extern CMIF_Ctrl_t cmif_ctrl_rake_fpc_1x; |
| 321 | extern CMIF_Ctrl_t cmif_ctrl_rake_do_pd; |
| 322 | extern CMIF_Ctrl_t cmif_ctrl_rake_foe_1x; |
| 323 | |
| 324 | |
| 325 | extern cmif_uint32 cmif_drvtest_case; |
| 326 | extern cmif_uint32 cmif_drvtest_prev_irq; |
| 327 | extern cmif_uint32 cmif_drvtest_irq_test_success; |
| 328 | |
| 329 | extern void CMIF_DriverAPIM2CTest(CMIF_Ctrl_t* ctrl); |
| 330 | extern void CMIF_DriverAPIC2MTest(CMIF_Ctrl_t* ctrl); |
| 331 | |
| 332 | extern void CMIF_DriverISRTestC2M(CMIF_Ctrl_t* ctrl, cmif_uint32 case_num); |
| 333 | extern void CMIF_DriverISRTestM2C(CMIF_Ctrl_t* ctrl, cmif_uint32 case_num); |
| 334 | |
| 335 | void cmif_drv_test_sync(CMIF_Ctrl_t* ctrl) |
| 336 | { |
| 337 | volatile cmif_uint32* sync = ctrl->sync; |
| 338 | |
| 339 | while(sync[1] == 1) ; |
| 340 | sync[1] = 1; |
| 341 | |
| 342 | while(sync[0] == 0) ; |
| 343 | sync[0] = 0; |
| 344 | } |
| 345 | |
| 346 | |
| 347 | void CMIF_DriverAPITest() |
| 348 | { |
| 349 | CMIF_DriverAPIM2CTest(&cmif_ctrl_rake_u3g); |
| 350 | CMIF_DriverAPIC2MTest(&cmif_ctrl_rake_u3g); |
| 351 | |
| 352 | CMIF_DriverAPIM2CTest(&cmif_ctrl_rake_fpc_1x); |
| 353 | CMIF_DriverAPIM2CTest(&cmif_ctrl_rake_do_pd); |
| 354 | CMIF_DriverAPIM2CTest(&cmif_ctrl_rake_foe_1x); |
| 355 | } |
| 356 | |
| 357 | |
| 358 | void CMIF_DisableInterrupt() |
| 359 | { |
| 360 | // MCU Part |
| 361 | IRQMask(IRQID_RAKE_CMIF_M2C_IRQ_U3G); |
| 362 | IRQMask(IRQID_RAKE_CMIF_M2C_IRQ_FPC_1X); |
| 363 | IRQMask(IRQID_RAKE_CMIF_M2C_IRQ_DO_PD); |
| 364 | IRQMask(IRQID_RAKE_CMIF_M2C_IRQ_FOE_1X); |
| 365 | } |
| 366 | |
| 367 | void CMIF_EnableInterrupt() |
| 368 | { |
| 369 | extern void CMIF_Init(); |
| 370 | CMIF_Init(); |
| 371 | } |
| 372 | |
| 373 | void CMIF_ClearPendingInterrupt() |
| 374 | { |
| 375 | #if 0 |
| 376 | /* under construction !*/ |
| 377 | /* under construction !*/ |
| 378 | #endif |
| 379 | } |
| 380 | |
| 381 | void CMIF_InterruptTest() |
| 382 | { |
| 383 | // test rake u3g |
| 384 | CMIF_DriverISRTestC2M(&cmif_ctrl_rake_u3g, 1); |
| 385 | CMIF_DriverISRTestM2C(&cmif_ctrl_rake_u3g, 1); |
| 386 | |
| 387 | CMIF_DriverISRTestC2M(&cmif_ctrl_rake_u3g, 2); |
| 388 | CMIF_DriverISRTestM2C(&cmif_ctrl_rake_u3g, 2); |
| 389 | |
| 390 | CMIF_DriverISRTestM2C(&cmif_ctrl_rake_fpc_1x, 1); |
| 391 | CMIF_DriverISRTestM2C(&cmif_ctrl_rake_fpc_1x, 2); |
| 392 | |
| 393 | CMIF_DriverISRTestM2C(&cmif_ctrl_rake_do_pd, 1); |
| 394 | CMIF_DriverISRTestM2C(&cmif_ctrl_rake_do_pd, 2); |
| 395 | |
| 396 | CMIF_DriverISRTestM2C(&cmif_ctrl_rake_foe_1x, 1); |
| 397 | CMIF_DriverISRTestM2C(&cmif_ctrl_rake_foe_1x, 2); |
| 398 | } |
| 399 | |
| 400 | /* how to run cmif driver test ? */ |
| 401 | /* MD32 Side: insert CMIF_DriverTest to basic load function */ |
| 402 | /* CR4 Side: insert CMIF_DriverTest to idle task function */ |
| 403 | |
| 404 | void CMIF_DriverTest() |
| 405 | { |
| 406 | #if __CMIF_MD32S_CORE__ |
| 407 | extern void CMIF_DriverInitTest(); |
| 408 | CMIF_DriverInitTest(); |
| 409 | #endif |
| 410 | |
| 411 | CMIF_DisableInterrupt(); |
| 412 | dbg_print("-- CMIF API Test Start.\n"); |
| 413 | CMIF_DisableInterrupt(); |
| 414 | CMIF_DriverAPITest(); |
| 415 | dbg_print("-- CMIF API Test End.\n"); |
| 416 | |
| 417 | dbg_print("-- CMIF Interrupt Start.\n"); |
| 418 | CMIF_EnableInterrupt(); |
| 419 | CMIF_InterruptTest(); |
| 420 | dbg_print("-- CMIF Interrupt End.\n"); |
| 421 | |
| 422 | while(1); |
| 423 | } |
| 424 | |
| 425 | #endif /* __MD32S_CMIF_DRV_TEST__ */ |
| 426 | |