blob: cb3d77ef0f1f06a778892767b6ea6a46f2017e82 [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) 2005
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 * dcl_sim.c
41 *
42 * Project:
43 * --------
44 * Maui_Software
45 *
46 * Description:
47 * ------------
48 * This Module defines DCL (Driver Common Layer) of the SIM card driver.
49 *
50 * Author:
51 * -------
52 * -------
53 *
54 *============================================================================
55 * HISTORY
56 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
57 *------------------------------------------------------------------------------
58 * removed!
59 * removed!
60 * removed!
61 *
62 * removed!
63 * removed!
64 * removed!
65 *
66 * removed!
67 * removed!
68 * removed!
69 *
70 * removed!
71 * removed!
72 * removed!
73 * removed!
74 *
75 * removed!
76 * removed!
77 * removed!
78 * removed!
79 *
80 * removed!
81 * removed!
82 * removed!
83 * removed!
84 *
85 * removed!
86 * removed!
87 * removed!
88 * removed!
89 *
90 * removed!
91 * removed!
92 * removed!
93 *
94 * removed!
95 * removed!
96 * removed!
97 *
98 * removed!
99 * removed!
100 * removed!
101 *
102 * removed!
103 * removed!
104 *
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 * removed!
135 *
136 * removed!
137 * removed!
138 *
139 * removed!
140 * removed!
141 * removed!
142 *
143 * removed!
144 * removed!
145 * removed!
146 *
147 * removed!
148 * removed!
149 * removed!
150 *
151 * removed!
152 * removed!
153 * removed!
154 *
155 * removed!
156 * removed!
157 * removed!
158 *
159 * removed!
160 * removed!
161 * removed!
162 *
163 * removed!
164 * removed!
165 * removed!
166 *
167 * removed!
168 * removed!
169 * removed!
170 *
171 * removed!
172 * removed!
173 * removed!
174 *
175 * removed!
176 * removed!
177 * removed!
178 *
179 * removed!
180 * removed!
181 * removed!
182 *
183 * removed!
184 * removed!
185 * removed!
186 *
187 * removed!
188 * removed!
189 * removed!
190 *
191 * removed!
192 * removed!
193 * removed!
194 *
195 * removed!
196 * removed!
197 * removed!
198 *
199 * removed!
200 * removed!
201 * removed!
202 *
203 * removed!
204 * removed!
205 * removed!
206 *
207 * removed!
208 * removed!
209 * removed!
210 *
211 * removed!
212 * removed!
213 * removed!
214 *
215 * removed!
216 * removed!
217 * removed!
218 *
219 * removed!
220 * removed!
221 * removed!
222 *
223 * removed!
224 * removed!
225 * removed!
226 *
227 * removed!
228 * removed!
229 * removed!
230 *
231 * removed!
232 * removed!
233 *
234 *
235 * removed!
236 * removed!
237 *
238 *
239 * removed!
240 * removed!
241 *
242 *
243 * removed!
244 * removed!
245 *
246 *
247 * removed!
248 * removed!
249 *
250 *
251 * removed!
252 * removed!
253 *
254 *
255 * removed!
256 * removed!
257 *
258 *
259 *------------------------------------------------------------------------------
260 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
261 *============================================================================
262 ****************************************************************************/
263#include "drv_features.h"
264#include "drv_comm.h"
265#include "dcl.h"
266
267#include "sim_al.h"
268#include "sim_drv_HW_reg_MTK.h"
269#include "sim_drv_HW_def_MTK.h"
270#include "sim_drv_SW_struct.h"
271#include "sim_drv_SW_function.h"
272#include "sim_drv_SW_API.h"
273#include "multi_icc_custom.h"
274
275#include "intrCtrl.h"
276
277#include "cache_sw.h"
278#include "init.h"
279#include "kal_public_api.h"
280
281#ifdef DCL_SIM_INTERFACE
282
283#if !defined(DRV_SIM_OFF)
284/**************************************************************************
285following defines static global variables used in this file
286***************************************************************************/
287static kal_bool fgSIMInit = KAL_FALSE;
288static kal_semid dclSimArb = 0;
289
290kal_char sim_shared_dbgstr[256];
291
292#define SIM_RESOURCE_HEAD 0x5a5a5a5a
293#define SIM_RESOURCE_TAIL 0xa5a5a5a5
294
295#define SIM_RSC_HANDLE_UDEF 0xffffffff
296
297typedef struct
298{
299 kal_uint32 guardHead;
300 kal_bool assigned;
301 kal_uint32 thdId;
302 kal_uint32 allocatedPoint;
303 DCL_SIMDriver_t *driver;
304 DCL_SIM_HW_CB driverHandle;
305 kal_uint32 guardTail;
306} DCL_SIM_RESOURCE;
307
308static DCL_SIM_RESOURCE simResource[DCL_SIM_MAX_INTERFACE];
309
310/******************************************************************************************
311*following are extern variables from other file
312******************************************************************************************/
313extern DCL_SIMDriver_t sim_ctrlDriver_All;
314
315extern void sim_init_all_cb(void);
316
317#if 0//defined(SIM_DRV_IC_USB)
318/* under construction !*/
319/* under construction !*/
320/* under construction !*/
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/* under construction !*/
374/* under construction !*/
375/* under construction !*/
376/* under construction !*/
377/* under construction !*/
378/* under construction !*/
379/* under construction !*/
380/* under construction !*/
381/* under construction !*/
382/* under construction !*/
383/* under construction !*/
384/* under construction !*/
385/* under construction !*/
386/* under construction !*/
387/* under construction !*/
388/* under construction !*/
389/* under construction !*/
390/* under construction !*/
391/* under construction !*/
392/* under construction !*/
393/* under construction !*/
394/* under construction !*/
395/* under construction !*/
396/* under construction !*/
397/* under construction !*/
398/* under construction !*/
399/* under construction !*/
400/* under construction !*/
401/* under construction !*/
402/* under construction !*/
403/* under construction !*/
404/* under construction !*/
405#endif
406
407
408/***************************************************************************************
409followings are DCL SD API exported
410*****************************************************************************************/
411/*************************************************************************
412* FUNCTION
413* DclSD_Initialize
414*
415* DESCRIPTION
416* This function is to initialize the SD driver related resource.
417* This function should be called in system initialization before tasks are scheduling.
418*
419* PARAMETERS
420* N/A
421*
422* RETURNS
423* STATUS_OK : this should be the only return value since MSDC_initialize returns nothing.
424*
425*************************************************************************/
426DCL_STATUS DclSIM_Initialize(void)
427{
428 kal_uint32 maskedValue;
429 kal_uint32 loopIndex;
430
431 maskedValue = SaveAndSetIRQMask();
432 if (KAL_FALSE == fgSIMInit)
433 {
434 fgSIMInit = KAL_FALSE;
435 RestoreIRQMask(maskedValue);
436 kal_mem_set(simResource, 0, sizeof(DCL_SIM_RESOURCE) * DCL_SIM_MAX_INTERFACE);
437 if (dclSimArb == 0) dclSimArb = kal_create_sem("SIM_DCL", 1);
438 for (loopIndex = 0; DCL_SIM_MAX_INTERFACE > loopIndex; loopIndex++)
439 {
440 simResource[loopIndex].guardHead = SIM_RESOURCE_HEAD;
441 simResource[loopIndex].guardTail = SIM_RESOURCE_TAIL;
442 simResource[loopIndex].driverHandle = SIM_RSC_HANDLE_UDEF;
443 }
444 sim_init_all_cb();
445#ifdef MEUT_ON_FPGA
446 MT6302_test();
447#endif
448 }
449 else
450 {
451 RestoreIRQMask(maskedValue);
452 }
453
454//#include "drv_iomux.h"
455//IOMUX_set_moudle_func(2, sel_misc_bsi_0);
456
457 return STATUS_OK;
458}
459
460/*************************************************************************
461* FUNCTION
462* DclSD_Initialize
463*
464* DESCRIPTION
465* This function is to get SD DCL handler.
466*
467* PARAMETERS
468* eDev - only valid for DCL_SD.
469* flags -following bit stand for specific meaning.
470* DCL_SD_FLAGS_CARD1: to get a handle for card 1
471* DCL_SD_FLAGS_CARD2: to get a handle for card 2
472* DCL_SD_FLAGS_SIMPLUS: to get a handle for sim plus
473* Other values are prohibited
474* RETURNS
475* DCL_HANDLE_INVALID - Open failed.
476* other value - a valid handle
477*
478*************************************************************************/
479DCL_HANDLE DclSIM_Open(DCL_DEV dev, DCL_FLAGS flags)
480{
481 kal_uint32 retAddr = 0;
482 kal_uint32 thdId;
483 kal_uint32 loopIndex;
484
485 if (dev != DCL_SIM)
486 {
487 kal_uint32 log_size = 0;
488 log_size = kal_sprintf(sim_shared_dbgstr, "Invalid 'dev' param in %s\n\r", __func__);
489 if (log_size > 0) DRV_ICC_print_str(sim_shared_dbgstr);
490
491 return DCL_HANDLE_INVALID;
492 }
493
494#if defined(__RVCT__)
495 /* RVCT doesn't support inline assemlber; bypass temporarily */
496 retAddr = 0;
497#else /* __RVCT__ */
498 /* get the return address */
499 /*__asm
500 {
501 mov retAddr,lr
502 } */
503 __asm__
504 (
505 "move %0, $ra"
506 :"=r"(retAddr)
507 );
508#endif /* __RVCT__ */
509
510 thdId = (kal_uint32)kal_get_current_thread_ID();
511
512 /*
513 In SIM DCL open, we only mark control block as assigned and return handle to user.
514 We don't support one resource used by multiple applications, so the control block will be not re-assigned.
515 Every time this function is called, we just find an unused control block, mark it assigned, and return the handle.
516 */
517
518 kal_take_sem(dclSimArb, KAL_INFINITE_WAIT);
519 for (loopIndex = 0; DCL_SIM_MAX_INTERFACE > loopIndex; loopIndex++)
520 {
521 if (KAL_FALSE == simResource[loopIndex].assigned)
522 {
523 simResource[loopIndex].assigned = KAL_TRUE;
524 simResource[loopIndex].thdId = thdId;
525 simResource[loopIndex].allocatedPoint = retAddr;
526 kal_give_sem(dclSimArb);
527 return (DCL_HANDLE)(&simResource[loopIndex]);
528 }
529 }
530 kal_give_sem(dclSimArb);
531 return DCL_HANDLE_NONE;
532}
533
534DCL_STATUS DclSIM_ReadData(DCL_HANDLE handle, DCL_BUFF *buff, DCL_BUFF_LEN *buf_len, DCL_OPTIONS options)
535{
536 SIM_DEBUG_ASSERT(0);
537 return STATUS_UNSUPPORTED;
538}
539DCL_STATUS DclSIM_WriteData(DCL_HANDLE handle, DCL_BUFF *buff, DCL_BUFF_LEN *buf_len, DCL_OPTIONS options)
540{
541 SIM_DEBUG_ASSERT(0);
542 return STATUS_UNSUPPORTED;
543}
544
545/*************************************************************************
546* FUNCTION
547* DclSIM_Configure
548*
549* DESCRIPTION
550* This function is to configure SIM interface. This is an important funciton since we rely on this function to hook correct function table.
551*
552* PARAMETERS
553* handle - a valid handle return by DclSIM_Open()
554* configure - a ponter to SIM_CONFIG_T structure which is a member of union
555* DCL_CONFIGURE_T.
556* RETURNS
557* STATUS_OK - the configuration is done correctly.
558* STATUS_INVALID_DCL_HANDLE - It's a invalid handle.
559* STATUS_NOT_OPENED - The module has not been opened.
560* STATUS_INVALID_CONFIGURATION - the configuration is not valid.
561*
562*************************************************************************/
563DCL_STATUS DclSIM_Configure(DCL_HANDLE handle, DCL_CONFIGURE_T *configure)
564{
565 SIM_CONFIG_T *prConfg;
566 DCL_SIM_RESOURCE *resource;
567 DCL_STATUS status;
568
569 /*check the handle*/
570 if (0 == handle)
571 {
572 kal_uint32 log_size = 0;
573 log_size = kal_sprintf(sim_shared_dbgstr, "Invalid 'handle' param in %s\n\r", __func__);
574 if (log_size > 0) DRV_ICC_print_str(sim_shared_dbgstr);
575
576 return STATUS_INVALID_DCL_HANDLE;
577 }
578
579 resource = (DCL_SIM_RESOURCE *)handle;
580 if (SIM_RESOURCE_HEAD != resource->guardHead || SIM_RESOURCE_TAIL != resource->guardTail)
581 SIM_DEBUG_ASSERT(0);
582
583 /*state check*/
584 if (SIM_RSC_HANDLE_UDEF != resource->driverHandle || NULL != resource->driver)
585 SIM_DEBUG_ASSERT(0);
586
587 /*configure to use sim_ctrlDriver_Single for single SIM platform*/
588 prConfg = (SIM_CONFIG_T *)configure;
589
590 switch (prConfg->apType)
591 {
592 case SIM_CONFIG_AP_TYPE_PHONE1:
593 resource->driver = (DCL_SIMDriver_t *)&sim_ctrlDriver_All;
594 /*driver handle will be the pointer to hw control block in the future, but before we finish SMD, we fix a workable uint32 here*/
595 resource->driverHandle = SIM_ICC_APPLICATION_PHONE1;
596 status = STATUS_OK;
597 break;
598 case SIM_CONFIG_AP_TYPE_PHONE2:
599 resource->driver = (DCL_SIMDriver_t *)&sim_ctrlDriver_All;
600 /*driver handle will be the pointer to hw control block in the future, but before we finish SMD, we fix a workable uint32 here*/
601 resource->driverHandle = SIM_ICC_APPLICATION_PHONE2;
602 status = STATUS_OK;
603 break;
604 case SIM_CONFIG_AP_TYPE_PHONE3:
605 resource->driver = (DCL_SIMDriver_t *)&sim_ctrlDriver_All;
606 /*driver handle will be the pointer to hw control block in the future, but before we finish SMD, we fix a workable uint32 here*/
607 resource->driverHandle = SIM_ICC_APPLICATION_PHONE3;
608 status = STATUS_OK;
609 break;
610 case SIM_CONFIG_AP_TYPE_PHONE4:
611 resource->driver = (DCL_SIMDriver_t *)&sim_ctrlDriver_All;
612 /*driver handle will be the pointer to hw control block in the future, but before we finish SMD, we fix a workable uint32 here*/
613 resource->driverHandle = SIM_ICC_APPLICATION_PHONE4;
614 status = STATUS_OK;
615 break;
616 default:
617 SIM_DEBUG_ASSERT(0);
618 status = STATUS_INVALID_CONFIGURATION;
619 break;
620 }
621#ifdef __SIM_HOT_SWAP_SUPPORT__
622 SIM_RegHotPlugCb(prConfg->apType, prConfg->hotPlugInCb, prConfg->hotPlugOutCb);
623#endif
624 return status;
625}
626DCL_STATUS DclSIM_RegisterCallback(DCL_HANDLE handle, DCL_EVENT event, PFN_DCL_CALLBACK callback)
627{
628 SIM_DEBUG_ASSERT(0);
629 return STATUS_UNSUPPORTED;
630}
631
632typedef DCL_STATUS(*DCL_SIM_CTRL_API)(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data);
633
634/*dcl add new api : 6. add to new DCL control function*/
635
636DCL_STATUS DCL_SIM_CTRL_API_RST(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
637{
638 DCL_SIM_STATUS status;
639 SIM_CTRL_RST_T *prRst;
640 DCL_SIM_RESOURCE *resource;
641
642 resource = (DCL_SIM_RESOURCE *)handle;
643 prRst = &(data->rSIMRst);
644 status = resource->driver->rst(prRst->ExpectVolt, prRst->ResultVolt, prRst->warm, resource->driverHandle);
645 prRst->rstResult = status;
646#if 0//defined(SIM_DRV_IC_USB)
647/* under construction !*/
648/* under construction !*/
649/* under construction !*/
650#endif
651
652 return STATUS_OK;
653}
654
655DCL_STATUS DCL_SIM_CTRL_API_CMD(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
656{
657 kal_uint32 status;
658 SIM_CTRL_CMD_T *prCmd;
659 DCL_SIM_RESOURCE *resource;
660
661 resource = (DCL_SIM_RESOURCE *)handle;
662 prCmd = &(data->rSIMCmd);
663
664 status = resource->driver->cmd(prCmd->txData, prCmd->txSize, prCmd->rxData, prCmd->rxSize, resource->driverHandle, prCmd->bypass6263);
665
666 *prCmd->statusWord = status;
667
668 return STATUS_OK;
669}
670
671DCL_STATUS DCL_SIM_CTRL_API_PWOFF(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
672{
673 DCL_SIM_RESOURCE *resource;
674
675 resource = (DCL_SIM_RESOURCE *)handle;
676 resource->driver->pwOff(resource->driverHandle);
677
678 return STATUS_OK;
679}
680
681DCL_STATUS DCL_SIM_CTRL_API_GET_CARD_INFO(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
682{
683 SIM_CTRL_GET_CARD_INFO_T *prInfo;
684 DCL_SIM_RESOURCE *resource;
685
686 resource = (DCL_SIM_RESOURCE *)handle;
687 prInfo = &(data->rSIMGetCardInfo);
688 resource->driver->getCardInfo(prInfo->info, resource->driverHandle);
689
690 return STATUS_OK;
691}
692
693DCL_STATUS DCL_SIM_CTRL_API_GET_CARD_ERROR_TYPES_INFO(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
694{
695 SIM_CTRL_GET_CARD_ERROR_TYPES_INFO_T *prInfo;
696 DCL_SIM_RESOURCE *resource;
697
698 resource = (DCL_SIM_RESOURCE *)handle;
699 prInfo = &(data->rSIMGetCardErrorTypesInfo);
700 resource->driver->getCardErrorTypesInfo(prInfo->info, resource->driverHandle);
701
702 return STATUS_OK;
703}
704
705DCL_STATUS DCL_SIM_CTRL_API_SET_SPEED(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
706{
707 SIM_CTRL_SET_MAX_SPEED_T *prSetSpeed;
708 DCL_SIM_RESOURCE *resource;
709
710 resource = (DCL_SIM_RESOURCE *)handle;
711 prSetSpeed = &(data->rSIMSetMaxSpeed);
712 resource->driver->setSpeed(prSetSpeed->speed, resource->driverHandle);
713
714 return STATUS_OK;
715}
716
717DCL_STATUS DCL_SIM_CTRL_API_SET_PREFER_PROTOCOL(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
718{
719 SIM_CTRL_SET_PREFER_PROTOCOL_T *prSetT;
720 DCL_SIM_RESOURCE *resource;
721
722 resource = (DCL_SIM_RESOURCE *)handle;
723 prSetT = &(data->rSIMSetPreferProtocol);
724 resource->driver->setPreferT(prSetT->T, resource->driverHandle);
725
726 return STATUS_OK;
727}
728
729DCL_STATUS DCL_SIM_CTRL_API_SET_CLK_STOP_MODE(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
730{
731 SIM_CTRL_SET_CLK_STOP_MODE_T *prSetClkStop;
732 DCL_SIM_RESOURCE *resource;
733
734 resource = (DCL_SIM_RESOURCE *)handle;
735 prSetClkStop = &(data->rSIMSetClkStopMode);
736 resource->driver->setClockStopMode(prSetClkStop->mode, resource->driverHandle);
737
738 return STATUS_OK;
739}
740
741DCL_STATUS DCL_SIM_CTRL_API_TOUT_TEST(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
742{
743 SIM_CTRL_TOUT_TEST_T *toutTest;
744 DCL_SIM_RESOURCE *resource;
745
746 resource = (DCL_SIM_RESOURCE *)handle;
747 toutTest = &(data->rSIMToutTest);
748 resource->driver->toutTest(toutTest->toutValue, resource->driverHandle);
749
750 return STATUS_OK;
751}
752
753DCL_STATUS DCL_SIM_CTRL_API_GET_CARD_SPEED(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
754{
755 SIM_CTRL_GET_SPEED_T *prSpeed; /*dcl add new api : 8. declare a pointer for the type*/
756 DCL_SIM_RESOURCE *resource;
757
758 resource = (DCL_SIM_RESOURCE *)handle;
759 prSpeed = &(data->rSIMGetSpeed); /*dcl add new api : 9. cast to the pointer of the type*/
760 *prSpeed->speed = resource->driver->getCardSpeed(resource->driverHandle); /*dcl add new api : 10. call the driver function*/
761
762 return STATUS_OK;
763}
764
765DCL_STATUS DCL_SIM_CTRL_API_QUERY_9000(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
766{
767 SIM_CTRL_QUERY_9000_T *prQuery9000;
768 DCL_SIM_RESOURCE *resource;
769
770 resource = (DCL_SIM_RESOURCE *)handle;
771 prQuery9000 = &(data->rSIMQuery9000);
772 *prQuery9000->got9000 = resource->driver->query9000WhenSelect(resource->driverHandle);
773
774 return STATUS_OK;
775}
776
777DCL_STATUS DCL_SIM_CTRL_API_SET_OWNER_TASK(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
778{
779 DCL_SIM_RESOURCE *resource;
780
781 resource = (DCL_SIM_RESOURCE *)handle;
782 resource->driver->setOwnerTask(resource->driverHandle);
783
784 return STATUS_OK;
785
786}
787
788DCL_STATUS DCL_SIM_CTRL_API_GET_CARD_DETECT_STATUS(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
789{
790#ifdef __SIM_GET_CARD_DETECT_STATUS_SUPPORT__
791 SIM_CTRL_GET_CARD_DETECT_STATUS_T *prInfo;
792 DCL_SIM_RESOURCE *resource;
793
794 resource = (DCL_SIM_RESOURCE *)handle;
795 prInfo = &(data->rSIMGetCardDetectStatus);
796 resource->driver->getCardDetectStatus(prInfo->info, resource->driverHandle);
797
798 return STATUS_OK;
799#else
800 return STATUS_UNSUPPORTED;
801#endif
802
803}
804DCL_STATUS DCL_SIM_CTRL_API_SET_SLT_RLT(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
805{
806#ifdef IC_MODULE_TEST
807 SIM_CTRL_SET_SLT_RLT_T *pSIMSetSltRlt;
808 DCL_SIM_RESOURCE *resource;
809
810 resource = (DCL_SIM_RESOURCE *)handle;
811
812 pSIMSetSltRlt = &(data->rSIMSetSltRlt);
813 L1sim_Set_Slt_Rlt(pSIMSetSltRlt->rlt, resource->driverHandle);
814#endif
815 return STATUS_OK;
816}
817
818/*dcl add new api : 7. add to function table*/
819DCL_SIM_CTRL_API DclSIM_APITbl[] =
820{
821 DCL_SIM_CTRL_API_RST, // 0-th
822 DCL_SIM_CTRL_API_CMD,
823 DCL_SIM_CTRL_API_PWOFF,
824 DCL_SIM_CTRL_API_GET_CARD_INFO,
825 DCL_SIM_CTRL_API_GET_CARD_ERROR_TYPES_INFO,
826 DCL_SIM_CTRL_API_SET_SPEED,
827 DCL_SIM_CTRL_API_SET_PREFER_PROTOCOL, // 5-th
828 DCL_SIM_CTRL_API_SET_CLK_STOP_MODE,
829 DCL_SIM_CTRL_API_TOUT_TEST,
830 DCL_SIM_CTRL_API_GET_CARD_SPEED,
831 DCL_SIM_CTRL_API_QUERY_9000,
832 DCL_SIM_CTRL_API_SET_OWNER_TASK,
833 DCL_SIM_CTRL_API_GET_CARD_DETECT_STATUS,
834 DCL_SIM_CTRL_API_SET_SLT_RLT
835};
836
837
838DCL_STATUS DclSIM_Control(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
839{
840 DCL_STATUS status;
841 DCL_SIM_RESOURCE *resource;
842
843 /*check the handle*/
844 if (0 == handle)
845 {
846 kal_uint32 log_size = 0;
847 log_size = kal_sprintf(sim_shared_dbgstr, "Invalid 'handle' param in %s\n\r", __func__);
848 if (log_size > 0) DRV_ICC_print_str(sim_shared_dbgstr);
849
850 return STATUS_INVALID_DCL_HANDLE;
851 }
852 resource = (DCL_SIM_RESOURCE *)handle;
853 if (SIM_RESOURCE_HEAD != resource->guardHead || SIM_RESOURCE_TAIL != resource->guardTail)
854 SIM_DEBUG_ASSERT(0);
855
856 /*state check*/
857 if (SIM_RSC_HANDLE_UDEF == resource->driverHandle)
858 SIM_DEBUG_ASSERT(0);
859
860 /*dispatch*/
861 if (SIM_CTRL_CMD_MAX_VALUE > cmd)
862 {
863 status = DclSIM_APITbl[cmd](handle, cmd, data);
864 }
865 else
866 {
867 SIM_DEBUG_ASSERT(0);
868 status = STATUS_INVALID_CMD;
869 }
870
871 return status;
872}
873
874DCL_STATUS DclSIM_Close(DCL_HANDLE handle)
875{
876 DCL_SIM_RESOURCE *resource;
877
878 /*check the handle*/
879 if (0 == handle)
880 {
881 kal_uint32 log_size = 0;
882 log_size = kal_sprintf(sim_shared_dbgstr, "Invalid 'handle' param in %s\n\r", __func__);
883 if (log_size > 0) DRV_ICC_print_str(sim_shared_dbgstr);
884
885 return STATUS_INVALID_DCL_HANDLE;
886 }
887 resource = (DCL_SIM_RESOURCE *)handle;
888
889 kal_take_sem(dclSimArb, KAL_INFINITE_WAIT);
890 resource->assigned = KAL_FALSE;
891 resource->thdId = 0;
892 resource->allocatedPoint = 0;
893 /*Blue added*/
894 resource->driverHandle = SIM_RSC_HANDLE_UDEF;
895 resource->driver = NULL;
896 kal_give_sem(dclSimArb);
897
898 return STATUS_OK;
899}
900#else /*!defined(DRV_SIM_OFF)*/
901
902
903DCL_STATUS DclSIM_Initialize(void)
904{
905 return STATUS_FAIL;
906}
907
908DCL_HANDLE DclSIM_Open(DCL_DEV dev, DCL_FLAGS flags)
909{
910 return DCL_HANDLE_INVALID;
911}
912
913DCL_STATUS DclSIM_ReadData(DCL_HANDLE handle, DCL_BUFF *buff, DCL_BUFF_LEN buf_len, DCL_OPTIONS options)
914{
915 return STATUS_UNSUPPORTED;
916}
917
918DCL_STATUS DclSIM_WriteData(DCL_HANDLE handle, DCL_BUFF *buff, DCL_BUFF_LEN buf_len, DCL_OPTIONS options)
919{
920 return STATUS_UNSUPPORTED;
921}
922
923DCL_STATUS DclSIM_Configure(DCL_HANDLE handle, DCL_CONFIGURE_T *configure)
924{
925 return STATUS_UNSUPPORTED;
926}
927
928DCL_STATUS DclSIM_RegisterCallback(DCL_HANDLE handle, DCL_EVENT event, PFN_DCL_CALLBACK callback)
929{
930 return STATUS_FAIL;
931}
932
933DCL_STATUS DclSIM_Control(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
934{
935 return STATUS_FAIL;
936}
937
938DCL_STATUS DclSIM_Close(DCL_HANDLE handle)
939{
940 return STATUS_FAIL;
941}
942
943#endif /*!defined(DRV_SIM_OFF) */
944
945#endif /*DCL_SIM_INTERFACE*/