blob: 7cda55b1d789c2110649f04e403c49fe4274f152 [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) 2001
8*
9*****************************************************************************/
10
11/*****************************************************************************
12 *
13 * Filename:
14 * ---------
15 * sdiotest.c
16 *
17 * Project:
18 * --------
19 * Maui_Software
20 *
21 * Description:
22 * ------------
23 * SDIO test code
24 *
25 * Author:
26 * -------
27 * -------
28 *
29 *============================================================================
30 * HISTORY
31 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
32 *------------------------------------------------------------------------------
33
34 *------------------------------------------------------------------------------
35 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
36 *============================================================================
37 ****************************************************************************/
38
39// MTK
40#include "drv_features.h"
41#include "drv_comm.h"
42#include "msdc_reg_adap.h"
43#include "reg_base.h"
44#include "intrCtrl.h"
45
46// SDIO
47#include "msdc_def.h"
48#include "sd_def.h"
49#include "sdio_def.h"
50#include "sdio_test.h"
51#include "sdio_sw.h"
52
53#if (defined(__MSDC_SD_MMC__)&&defined(__MSDC_SD_SDIO__)) || defined(__MSDC2_SD_SDIO__)
54extern cmd52_config_struct cmd52_config;
55extern cmd53_config_struct cmd53_config;
56#define WIFI_FUNC 1
57
58
59
60__align(4) kal_uint8 buffer[1024];
61extern __align(4) kal_uint8 sdio_cccr_reg[SDIO_CCCR_SIZE];
62extern __align(4) kal_uint8 sdio_fbr_reg[SDIO_FBR_SIZE];
63extern __align(4) kal_uint8 sdio_tuple[SDIO_MAX_FUCN_ID][SDIO_TUPLE_SIZE];
64volatile kal_uint32 cmd = 0, arg = 0;
65volatile kal_uint32 flag52 = 1, flag53 = 0, flag_SD = 0, flag_4bit = 1;
66cmd52_config_struct cmd52_config;
67cmd53_config_struct cmd53_config;
68void SDIO_test_main2(void);
69extern MSDC_HANDLE *msdc2_handle ;
70
71void sdio_clr_int(void)
72{
73 UINT32 mcrValue;
74 //SDIO_Register_Read_poll(SDIO_FUCN_1, MCR_ISAR, (kal_uint32*)&mcrValue , SDIO_FIX);
75 //NIC_MCR_READ(NULL, MCR_ISAR, &mcrValue);
76}
77void test_hisr(void)
78{
79 dbg_print("interrupt callback\r\n");
80 sdio_clr_int();
81}
82
83
84void test_sdio_ini(void)
85{
86 SDC_CMD_STATUS status;
87 kal_uint8 version;
88 kal_uint16 tick;
89 kal_bool ready;
90 kal_uint32 retry_count=0;
91 kal_uint32 block_size=0;
92
93
94 /*initialize*/
95 dbg_print("SDIO initilaization start\r\n");
96 status=SDIO_Initialize();
97 dbg_print("SDIO initilaization end=%d\r\n", status);
98 dbg_print("SDIO test start\r\n");
99
100 /*CCCR verison*/
101 status=SDIO_read_CCCR_ver(&version);
102 dbg_print("read CCCR ver status %d ver %d \r\n", status, version);
103 /*SDIO verison*/
104 status=SDIO_read_SDIO_ver(&version);
105 dbg_print("read SDIO ver status %d ver %d \r\n", status, version);
106 /*SD verison*/
107 status=SDIO_read_SD_ver(&version);
108 dbg_print("read SDIO SD status %d ver %d \r\n", status, version);
109
110 /* check card capability*/
111 status=SDIO_read_capacity();
112 if(!status)
113 {
114 dbg_print("SDC %d%\r\n", SDIO_support_SDC());
115 dbg_print("SMB %d%\r\n", SDIO_support_SMB());
116 dbg_print("SRW %d%\r\n", SDIO_support_SRW());
117 dbg_print("SBS %d%\r\n", SDIO_support_SBS());
118 dbg_print("S4MI %d%\r\n", SDIO_support_S4MI());
119 //dbg_print("E4MI %d%\r\n", SDIO_enable_E4MI(KAL_TRUE));
120 dbg_print("LSC %d%\r\n", SDIO_support_LSC());
121 dbg_print("4BLS %d%\r\n", SDIO_support_4BLS());
122 }
123 else
124 {
125 dbg_print("read capacity %d failed \r\n", cmd52_config.adrs);
126 }
127
128 /* enable SDIO function*/
129 retry_count=0;
130
131
132 /* set the block size of func1 to 128*/
133
134 dbg_print("set function block size %d \r\n", 128);
135
136 status=SDIO_configure_BLK_size(SDIO_FUCN_1, 128);
137 dbg_print("set block size (function 1) %d\r\n", status);
138 status=SDIO_configure_BLK_size(SDIO_FUCN_0, 128);
139 dbg_print("set block size(function 0) %d\r\n", status);
140
141 // config the sdio controller
142 MSDC_SetBits32(SDC_CFG, SDC_CFG_SDIO);// enable SDIO mode
143 MSDC_WriteReg32(SDIO_CFG, 1); // enable SDIO interrupt
144
145 // *****************************************//
146 // always turn on the serial clock
147 // MSDC_SetBits32(MSDC_CFG, MSDC_CFG_SCKON);
148 // *****************************************//
149
150
151
152 status=SDIO_query_IO_id(SDIO_INTERFACE_WLAN);
153 dbg_print("SDIO_INTERFACE_WLAN function id =%d\r\n", status);
154
155 status=SDIO_query_IO_id(SDIO_INTERFACE_WLAN);
156 dbg_print("SDIO_INTERFACE_WLAN function id =%d\r\n", status);
157 block_size=SDIO_query_BLK_size(SDIO_FUCN_1);
158 dbg_print("function 1 block size =%d\r\n", block_size);
159
160 SDIO_int_registration(SDIO_FUCN_1, test_hisr);
161 status=SDIO_enable_IO_Int(SDIO_FUCN_0, KAL_TRUE);
162 dbg_print("enable card int%d \r\n",status);
163 status=SDIO_enable_IO_Int(SDIO_FUCN_1, KAL_TRUE);
164 dbg_print("enable function %d int%d \r\n",SDIO_FUCN_1, status);
165 /* read all configuration register of CCCR*/
166 status=SDIO_read_CCCR();
167 dbg_print("read all CCCR=%d\r\n", status);
168 status=SDIO_read_FBR(1);
169 dbg_print("read all FBR=%d\r\n", status);
170
171
172 /*start WiFi test*/
173#ifndef MSDC2_SDIO_DVT
174 if(KAL_TRUE == gMSDC_Handle->mIsInitialized)
175#else
176 if(KAL_TRUE == msdc2_handle->mIsInitialized)
177#endif
178 {
179 SDIO_test_main2();
180 SDIO_test_main();
181 }
182 else{
183 return;
184 }
185 while(0)
186 {
187 if(flag52)
188 {
189 cmd52_config.rw = SDIO_READ;
190 cmd52_config.func = 0;
191 cmd52_config.raw = KAL_FALSE;
192 cmd52_config.stop = KAL_FALSE;
193 cmd52_config.adrs = 0;
194 cmd52_config.data = 0;
195 SDIO_Cmd52(&cmd52_config);
196 }
197 // check SMB first (Support Multi-Block)
198 // config the block size
199 if(flag53)
200 {
201 cmd53_config.rw = SDIO_READ;
202 cmd53_config.func = 0;
203 cmd53_config.block = KAL_FALSE;
204 cmd53_config.buffer = (kal_uint32)buffer;
205 cmd53_config.count = 4;
206 cmd53_config.op = SDIO_INC;
207 cmd53_config.adrs = 0;
208 SDIO_Cmd53(&cmd53_config);
209 //dbg_print("SDIO initilaization end=%d\r\n", status);
210 }
211 }
212
213}
214
215
216
217kal_bool IPC_2126_MCR_Read(kal_uint16 offset, kal_uint32 *pValue)
218{
219 kal_bool status;
220 #if 1
221 status = SDIO_Register_Read(SDIO_FUCN_1,
222 (kal_uint32) offset,
223 pValue,
224 SDIO_FIX);
225 return status;
226 #else
227/* under construction !*/
228/* under construction !*/
229/* under construction !*/
230/* under construction !*/
231/* under construction !*/
232/* under construction !*/
233/* under construction !*/
234/* under construction !*/
235 #endif
236}
237void IPC_2126_MCR_Read_N(kal_uint16 offset, kal_uint32 pValue, kal_uint32 count, kal_bool block )
238{
239 cmd53_config.rw = SDIO_READ;
240 cmd53_config.func = WIFI_FUNC;
241 cmd53_config.block = block;
242 cmd53_config.buffer = (kal_uint32)pValue;
243 cmd53_config.count = count;
244 cmd53_config.op = SDIO_FIX;
245 cmd53_config.adrs = (kal_uint32)offset;
246 SDIO_Cmd53(&cmd53_config);
247
248}
249kal_bool IPC_2126_MCR_Write(kal_uint16 offset, kal_uint32 value)
250{
251 kal_uint32 tmp = value;
252 kal_bool status;
253 #if 1
254 status = SDIO_Register_Write(SDIO_FUCN_1,
255 (kal_uint32) offset,
256 value,
257 SDIO_FIX);
258
259 return status;
260 #else
261/* under construction !*/
262/* under construction !*/
263/* under construction !*/
264/* under construction !*/
265/* under construction !*/
266/* under construction !*/
267/* under construction !*/
268/* under construction !*/
269 #endif
270}
271void IPC_2126_MCR_Write_N(kal_uint16 offset, kal_uint32 value, kal_uint32 count, kal_bool block )
272{
273 cmd53_config.rw = SDIO_WRITE;
274 cmd53_config.func = WIFI_FUNC;
275 cmd53_config.block = block;
276 cmd53_config.buffer = (kal_uint32)value;
277 cmd53_config.count = count;
278 cmd53_config.op = SDIO_FIX;
279 cmd53_config.adrs = (kal_uint32)offset;
280 SDIO_Cmd53(&cmd53_config);
281
282}
283/*----------------------------------------------------------------*/
284/*!
285* \brief
286*
287* \param
288* \return
289*/
290/*----------------------------------------------------------------*/
291volatile kal_bool my_flag = 1;
292volatile kal_bool my_flag_2 = 0;
293__align(4) kal_uint8 value[1024]= {0xff};
294int SDIO_test_main(void)
295{
296 kal_uint32 mcrValue;
297 int tbttCount = 0;
298 kal_uint32 test_count=0;
299 kal_bool pending;
300 SDC_CMD_STATUS status;
301 //SDIO_ARG arg;
302
303 kal_uint32 i;
304 kal_uint32 loopTestIndex;
305
306 /* Reset chip and enable all clocks */
307 NIC_MCR_WRITE(NULL, MCR_SCR, (SCR_BB_MRST | SCR_MAC_RST |
308 SCR_BB_SIORST | SCR_MAC_REGRST));
309 NIC_MCR_WRITE(NULL, MCR_SCR, SCR_CLK_ALL_EN);
310 NIC_MCR_READ(NULL, MCR_SCR, value);
311
312 /* Here maybe need delay for OSC stable */
313 for(i=0;i<10000;i++);
314
315 /* Check chip ID */
316 NIC_MCR_READ(NULL, MCR_PCICR, &mcrValue);
317 //printk("IPN2128 ChipIDVersion read test: [0x%08lX] \n", mcrValue);
318 if ((mcrValue & CHIP_ID_MASK) != CHIP_ID_REV) {
319 //printk(KERN_ALERT "IPN2128 not found... \n");
320 }
321 //if(my_flag)
322 NIC_MCR_WRITE(NULL, MCR_SDCR, BITS(4,6)); /* Use enhanced mode */
323
324 /* Reset TSF and enable TBTT interrupt */
325 /* Set our local TSF timer to 0 */
326 NIC_MCR_WRITE(NULL, MCR_TTAR1, 0);
327 NIC_MCR_WRITE(NULL, MCR_TTAR2, 0);
328 NIC_MCR_WRITE(NULL, MCR_TTAR0, TTAR0_TSF_TIMER_VALUE_CHANGE);
329
330 /* Set the next TBTT time and the TBTT event generation period. */
331 NIC_MCR_WRITE(NULL, MCR_NTTCR, ((100) &
332 NTTCR_NEXT_TBTT_TIME) | (100 << 16));
333
334 /* Enable the TBTT event generator. */
335 NIC_MCR_WRITE(NULL, MCR_MPTCR, MPTCR_EN_COMP_NEXT_TBTT_TIME | MPTCR_TBTT_ENABLE);
336
337 /* Enable interrupt */ //IER_PRE_TBTT_INT, IER_SDIO_ABNORMAL_INT
338 NIC_MCR_WRITE(NULL, MCR_IER, IER_GLOBAL_ENABLE | IER_TBTT_INT);
339 NIC_MCR_READ(NULL, MCR_IER, &mcrValue);
340
341 /* In loop, cmd53 is repeated to test interrupt event with cmd53 read */
342 while (1)
343 {
344
345 /*cmd52_config.rw = SDIO_READ;
346 cmd52_config.func = 0;
347 cmd52_config.raw = KAL_FALSE;
348 cmd52_config.stop = KAL_FALSE;
349 cmd52_config.adrs = 5;
350 cmd52_config.data = 0;
351 SDIO_Cmd52(&cmd52_config);*/
352 //status=SDIO_check_IO_Int(SDIO_FUCN_1, &pending);
353 //if( pending != 0 )
354 if(mcrValue!=0)
355 {
356 tbttCount++;
357 dbg_print("Int Pending %d \r\n", pending);
358 dbg_print("TBTT count %d \r\n", tbttCount);
359 NIC_MCR_READ(NULL, MCR_ISAR, &mcrValue);
360 dbg_print("ISAR %d \r\n", mcrValue);
361 }
362 else
363 NIC_MCR_READ(NULL, MCR_ISAR, &mcrValue);
364 /*
365 NIC_MCR_READ(NULL, MCR_ISAR, &mcrValue);
366 if (mcrValue & ISAR_TBTT_INT) {
367 tbttCount++;
368 //printk("TBTT event occurs %d\n", tbttCount);
369 */
370 if (tbttCount >= 10) break; /* 10sec */
371
372 }
373
374 /* Enable interrupt of abnormal interrupt */
375 NIC_MCR_WRITE(NULL, MCR_IER, IER_GLOBAL_ENABLE | IER_SDIO_ABNORMAL_INT);
376 NIC_MCR_READ(NULL, MCR_IER, &mcrValue);
377
378#if 1
379 /* Do illegal (byte/block) Read/Write to trigger abnormal interrupt */
380 loopTestIndex = 30;
381 while (loopTestIndex--)
382 {
383 kal_uint8 test;
384
385 dbg_print("start %d int test\r\n", test_count);
386
387 test = 0;
388
389 test++;
390 IPC_2126_MCR_Read_N(0x0128,(kal_uint32)&value[0],8, KAL_FALSE);
391 status=SDIO_check_IO_Int(SDIO_FUCN_1, &pending);
392#ifndef MSDC2_SDIO_DVT
393 if(MSDC_Reg(SDIO_STA) == 1)
394#else
395 if(MSDC_Reg(SDIO_STA2) == 1)
396#endif
397 test--;
398 //NIC_MCR_READ(NULL, MCR_ISAR, &mcrValue);
399 //dbg_print("ISAR %d \r\n", mcrValue);
400 if(test)
401 ASSERT(0);
402
403 test++;
404 IPC_2126_MCR_Write_N(0x0128,(kal_uint32)&value[0],8, KAL_FALSE);
405 status=SDIO_check_IO_Int(SDIO_FUCN_1, &pending);
406#ifndef MSDC2_SDIO_DVT
407 if(MSDC_Reg(SDIO_STA) == 1)
408#else
409 if(MSDC_Reg(SDIO_STA2) == 1)
410#endif
411 test--;
412 //NIC_MCR_READ(NULL, MCR_ISAR, &mcrValue);
413 //dbg_print("ISAR %d \r\n", mcrValue);
414 if(test)
415 ASSERT(0);
416
417 test++;
418 IPC_2126_MCR_Write_N(0x0128,(kal_uint32)&value[0], 1, KAL_TRUE);
419 status=SDIO_check_IO_Int(SDIO_FUCN_1, &pending);
420#ifndef MSDC2_SDIO_DVT
421 if(MSDC_Reg(SDIO_STA) == 1)
422#else
423 if(MSDC_Reg(SDIO_STA2) == 1)
424#endif
425 test--;
426 NIC_MCR_READ(NULL, MCR_ISAR, &mcrValue);
427 //dbg_print("ISAR %d \r\n", mcrValue);
428 if(test)
429 ASSERT(0);
430
431 test++;
432 IPC_2126_MCR_Read_N(0x0128,(kal_uint32)&value[0], 1, KAL_TRUE);
433 status=SDIO_check_IO_Int(SDIO_FUCN_1, &pending);
434#ifndef MSDC2_SDIO_DVT
435 if(MSDC_Reg(SDIO_STA) == 1)
436#else
437 if(MSDC_Reg(SDIO_STA2) == 1)
438#endif
439 test--;
440 //NIC_MCR_READ(NULL, MCR_ISAR, &mcrValue);
441 //dbg_print("ISAR %d \r\n", mcrValue);
442 if(test)
443 ASSERT(0);
444
445 #if 0
446 #if 0
447/* under construction !*/
448/* under construction !*/
449/* under construction !*/
450 #endif
451/* under construction !*/
452/* under construction !*/
453/* under construction !*/
454 #if 0
455/* under construction !*/
456/* under construction !*/
457/* under construction !*/
458 #endif
459/* under construction !*/
460/* under construction !*/
461/* under construction !*/
462/* under construction !*/
463 #if 0
464/* under construction !*/
465/* under construction !*/
466/* under construction !*/
467 #endif
468/* under construction !*/
469/* under construction !*/
470/* under construction !*/
471/* under construction !*/
472 #if 0
473/* under construction !*/
474/* under construction !*/
475/* under construction !*/
476 #endif
477/* under construction !*/
478/* under construction !*/
479/* under construction !*/
480#endif
481 if(my_flag_2)
482 break;
483 }
484#endif
485
486 return 0;
487} /* end of main() */
488
489
490void SDIO_test_main2(void)
491{
492 UINT32 mcrValue;
493 UINT32 tmcrValue;
494 UINT32 i;
495 UINT8 mcr[4];
496 int tbttCount;
497 SDC_CMD_STATUS status;
498 kal_uint32 j;
499
500
501 /* Reset chip and enable all clocks */
502 NIC_MCR_WRITE(NULL, MCR_SCR, (SCR_BB_MRST | SCR_MAC_RST |
503 SCR_BB_SIORST | SCR_MAC_REGRST));
504 for(j=0;j<100000;j++);
505 /* Here delay 1us to complete reset process */
506 NIC_MCR_WRITE(NULL, MCR_SCR, SCR_CLK_ALL_EN);
507 /* Check chip ID */
508 NIC_MCR_READ(NULL, MCR_PCICR, &mcrValue);
509 IPC_2126_MCR_Read_N(0x0128,(kal_uint32)&value[0], 4, KAL_TRUE);
510 //SDIO_Register_Read(SDIO_FUCN_1, MCR_PCICR, (kal_uint32*)&tmcrValue, SDIO_FIX);
511 //SDIO_Data_Read(SDIO_FUCN_1, MCR_PCICR, &mcr[0], SDIO_FIX, 4, KAL_FALSE);
512
513 //printk("IPN2128 ChipIDVersion read test: [0x%08lX] \n", mcrValue);
514 if ((mcrValue & CHIP_ID_MASK) != CHIP_ID_REV) {
515 //printk(KERN_ALERT "IPN2128 not found... \n");
516 }
517 NIC_MCR_WRITE(NULL, MCR_SDCR, BITS(4,6)); /* Use enhanced mode */
518
519 /* Reset TSF and enable TBTT interrupt */
520 /* Set our local TSF timer to 0 */
521 NIC_MCR_WRITE(NULL, MCR_TTAR1, 0);
522 NIC_MCR_WRITE(NULL, MCR_TTAR2, 0);
523 NIC_MCR_WRITE(NULL, MCR_TTAR0, TTAR0_TSF_TIMER_VALUE_CHANGE);
524
525 /* Set the next TBTT time and the TBTT event generation period (20ms). */
526 NIC_MCR_WRITE(NULL, MCR_NTTCR, ((100) &
527 NTTCR_NEXT_TBTT_TIME) | (20 << 16));
528
529 /* Enable the TBTT event generator. */
530 NIC_MCR_WRITE(NULL, MCR_MPTCR, MPTCR_EN_COMP_NEXT_TBTT_TIME | MPTCR_TBTT_ENABLE);
531
532 /* Enable interrupt */
533 NIC_MCR_WRITE(NULL, MCR_IER, IER_GLOBAL_ENABLE | IER_TBTT_INT | IER_SDIO_ABNORMAL_INT);
534
535#if 1
536 /* In loop, cmd53 is repeated to test interrupt event with cmd53 read */
537 tbttCount = 0;
538 dbg_print("trigger interrupt during sigle block \r\n");
539 while (1)
540 {
541 kal_bool pending;
542 //status=SDIO_check_IO_Int(SDIO_FUCN_1, &pending);
543 NIC_MCR_READ(NULL, MCR_ISAR, &mcrValue);
544 if (mcrValue & ISAR_TBTT_INT)
545 {
546 kal_uint32 test_count;
547 tbttCount++;
548 dbg_print("TBTT event occurs %d\r\n", tbttCount);
549 for(test_count=0;test_count<100;test_count++)
550 {}
551 if (tbttCount >= 100) break; /* 10sec */
552 }
553 }
554#endif
555
556#if 1
557 /* Read/Writel multiple block with TBTT interrupt */
558 while (1) {
559 /*
560 arg = BUILD_IO_RW_EXTENDED_ARG(SDIO_RWFLAG_WRITE,
561 1, SDIO_IO_BLOCK_MODE, SDIO_IO_FIX_ADDR, 0x0128, 4);
562 sdioCmd53ReadWrite(x_slot, arg, (__u8*)&value[0]);
563 */
564
565
566 /*
567 arg = BUILD_IO_RW_EXTENDED_ARG(SDIO_RWFLAG_READ,
568 1, SDIO_IO_BLOCK_MODE, SDIO_IO_FIX_ADDR, 0x0128, 4);
569 sdioCmd53ReadWrite(x_slot, arg, (__u8*)&value[0]);
570 */
571 dbg_print("trigger interrupt during multiple block \r\n");
572 memset(value, 0, 1024);
573 IPC_2126_MCR_Write_N(0x0128,(kal_uint32)&value[0], 4, KAL_TRUE);
574 //memset(value, 0x5, 1024);
575 NIC_MCR_READ(NULL, MCR_ISAR, &mcrValue); /* Clear TBTT Interrupt */
576 //IPC_2126_MCR_Read_N(0x0128,(kal_uint32)&value[0], 128, KAL_FALSE);
577 //IPC_2126_MCR_Read_N(0x0128,(kal_uint32)&value[128], 128, KAL_FALSE);
578 //IPC_2126_MCR_Read_N(0x0128,(kal_uint32)&value[256], 128, KAL_FALSE);
579 //IPC_2126_MCR_Read_N(0x0128,(kal_uint32)&value[384], 128, KAL_FALSE);
580 //memset(value, 0x5, 1024);
581 NIC_MCR_READ(NULL, MCR_ISAR, &mcrValue); /* Clear TBTT Interrupt */
582 IPC_2126_MCR_Read_N(0x0128,(kal_uint32)&value[0], 4, KAL_TRUE);
583 NIC_MCR_READ(NULL, MCR_ISAR, &mcrValue); /* Clear TBTT Interrupt */
584 NIC_MCR_READ(NULL, 0x118, &mcrValue);
585
586 if(my_flag)
587 break;
588
589
590 }
591#endif
592
593}
594#endif
595
596