aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/rt2860/common
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2009-10-21 16:44:35 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-12-11 15:23:12 -0500
commit44c68c23b16c85127d187fd720f95aa2e7a94d2e (patch)
tree467612eb4cbb0d2cc3fe2ba9a27ba31088b24be0 /drivers/staging/rt2860/common
parent782f1111256557c75415f57cd360ebf9d1377a55 (diff)
Staging: rt28x0: remove optional loading of EEPROM from file in eFuse mode
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/rt2860/common')
-rw-r--r--drivers/staging/rt2860/common/cmm_profile.c10
-rw-r--r--drivers/staging/rt2860/common/ee_efuse.c788
-rw-r--r--drivers/staging/rt2860/common/eeprom.c3
-rw-r--r--drivers/staging/rt2860/common/rtmp_init.c9
4 files changed, 1 insertions, 809 deletions
diff --git a/drivers/staging/rt2860/common/cmm_profile.c b/drivers/staging/rt2860/common/cmm_profile.c
index 056cffda42b..117ee077728 100644
--- a/drivers/staging/rt2860/common/cmm_profile.c
+++ b/drivers/staging/rt2860/common/cmm_profile.c
@@ -1194,16 +1194,6 @@ NDIS_STATUS RTMPSetProfileParameters(
1194 retval = RT_CfgSetCountryRegion(pAd, tmpbuf, BAND_5G); 1194 retval = RT_CfgSetCountryRegion(pAd, tmpbuf, BAND_5G);
1195 DBGPRINT(RT_DEBUG_TRACE, ("CountryRegionABand=%d\n", pAd->CommonCfg.CountryRegionForABand)); 1195 DBGPRINT(RT_DEBUG_TRACE, ("CountryRegionABand=%d\n", pAd->CommonCfg.CountryRegionForABand));
1196 } 1196 }
1197#ifdef RTMP_EFUSE_SUPPORT
1198#ifdef RT30xx
1199 //EfuseBufferMode
1200 if(RTMPGetKeyParameter("EfuseBufferMode", tmpbuf, 25, pBuffer, TRUE))
1201 {
1202 pAd->bEEPROMFile = (UCHAR) simple_strtol(tmpbuf, 0, 10);
1203 DBGPRINT(RT_DEBUG_TRACE, ("EfuseBufferMode=%d\n", pAd->bUseEfuse));
1204 }
1205#endif // RT30xx //
1206#endif // RTMP_EFUSE_SUPPORT //
1207 //CountryCode 1197 //CountryCode
1208 if(RTMPGetKeyParameter("CountryCode", tmpbuf, 25, pBuffer, TRUE)) 1198 if(RTMPGetKeyParameter("CountryCode", tmpbuf, 25, pBuffer, TRUE))
1209 { 1199 {
diff --git a/drivers/staging/rt2860/common/ee_efuse.c b/drivers/staging/rt2860/common/ee_efuse.c
index 5807cc4ff96..4bff473ccf3 100644
--- a/drivers/staging/rt2860/common/ee_efuse.c
+++ b/drivers/staging/rt2860/common/ee_efuse.c
@@ -67,21 +67,6 @@ typedef union _EFUSE_CTRL_STRUC {
67 UINT32 word; 67 UINT32 word;
68} EFUSE_CTRL_STRUC, *PEFUSE_CTRL_STRUC; 68} EFUSE_CTRL_STRUC, *PEFUSE_CTRL_STRUC;
69 69
70static VOID eFuseWritePhysical(
71 IN PRTMP_ADAPTER pAd,
72 PUSHORT lpInBuffer,
73 ULONG nInBufferSize,
74 PUCHAR lpOutBuffer,
75 ULONG nOutBufferSize);
76
77
78static NTSTATUS eFuseWriteRegistersFromBin(
79 IN PRTMP_ADAPTER pAd,
80 IN USHORT Offset,
81 IN USHORT Length,
82 IN USHORT* pData);
83
84
85/* 70/*
86======================================================================== 71========================================================================
87 72
@@ -281,164 +266,6 @@ static VOID eFuseReadPhysical(
281 266
282======================================================================== 267========================================================================
283*/ 268*/
284static VOID eFusePhysicalWriteRegisters(
285 IN PRTMP_ADAPTER pAd,
286 IN USHORT Offset,
287 IN USHORT Length,
288 OUT USHORT* pData)
289{
290 EFUSE_CTRL_STRUC eFuseCtrlStruc;
291 int i;
292 USHORT efuseDataOffset;
293 UINT32 data, eFuseDataBuffer[4];
294
295 //Step0. Write 16-byte of data to EFUSE_DATA0-3 (0x590-0x59C), where EFUSE_DATA0 is the LSB DW, EFUSE_DATA3 is the MSB DW.
296
297 /////////////////////////////////////////////////////////////////
298 //read current values of 16-byte block
299 RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrlStruc.word);
300
301 //Step0. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment.
302 eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0;
303
304 //Step1. Write EFSROM_MODE (0x580, bit7:bit6) to 1.
305 eFuseCtrlStruc.field.EFSROM_MODE = 1;
306
307 //Step2. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical read procedure.
308 eFuseCtrlStruc.field.EFSROM_KICK = 1;
309
310 NdisMoveMemory(&data, &eFuseCtrlStruc, 4);
311 RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data);
312
313 //Step3. Polling EFSROM_KICK(0x580, bit30) until it become 0 again.
314 i = 0;
315 while(i < 500)
316 {
317 RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrlStruc.word);
318
319 if(eFuseCtrlStruc.field.EFSROM_KICK == 0)
320 break;
321 RTMPusecDelay(2);
322 i++;
323 }
324
325 //Step4. Read 16-byte of data from EFUSE_DATA0-3 (0x59C-0x590)
326 efuseDataOffset = EFUSE_DATA3;
327 for(i=0; i< 4; i++)
328 {
329 RTMP_IO_READ32(pAd, efuseDataOffset, (PUINT32) &eFuseDataBuffer[i]);
330 efuseDataOffset -= 4;
331 }
332
333 //Update the value, the offset is multiple of 2, length is 2
334 efuseDataOffset = (Offset & 0xc) >> 2;
335 data = pData[0] & 0xffff;
336 //The offset should be 0x***10 or 0x***00
337 if((Offset % 4) != 0)
338 {
339 eFuseDataBuffer[efuseDataOffset] = (eFuseDataBuffer[efuseDataOffset] & 0xffff) | (data << 16);
340 }
341 else
342 {
343 eFuseDataBuffer[efuseDataOffset] = (eFuseDataBuffer[efuseDataOffset] & 0xffff0000) | data;
344 }
345
346 efuseDataOffset = EFUSE_DATA3;
347 for(i=0; i< 4; i++)
348 {
349 RTMP_IO_WRITE32(pAd, efuseDataOffset, eFuseDataBuffer[i]);
350 efuseDataOffset -= 4;
351 }
352 /////////////////////////////////////////////////////////////////
353
354 //Step1. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment.
355
356 RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrlStruc.word);
357
358 eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0;
359
360 //Step2. Write EFSROM_MODE (0x580, bit7:bit6) to 3.
361 eFuseCtrlStruc.field.EFSROM_MODE = 3;
362
363 //Step3. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical write procedure.
364 eFuseCtrlStruc.field.EFSROM_KICK = 1;
365
366 NdisMoveMemory(&data, &eFuseCtrlStruc, 4);
367 RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data);
368
369 //Step4. Polling EFSROM_KICK(0x580, bit30) until it become 0 again. It¡¦s done.
370 i = 0;
371
372 while(i < 500)
373 {
374 RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrlStruc.word);
375
376 if(eFuseCtrlStruc.field.EFSROM_KICK == 0)
377 break;
378
379 RTMPusecDelay(2);
380 i++;
381 }
382}
383
384/*
385========================================================================
386
387 Routine Description:
388
389 Arguments:
390
391 Return Value:
392
393 Note:
394
395========================================================================
396*/
397static VOID eFuseWritePhysical(
398 IN PRTMP_ADAPTER pAd,
399 PUSHORT lpInBuffer,
400 ULONG nInBufferSize,
401 PUCHAR lpOutBuffer,
402 ULONG nOutBufferSize
403)
404{
405 USHORT* pInBuf = (USHORT*)lpInBuffer;
406 int i;
407 //USHORT* pOutBuf = (USHORT*)ioBuffer;
408 USHORT Offset = pInBuf[0]; // addr
409 USHORT Length = pInBuf[1]; // length
410 USHORT* pValueX = &pInBuf[2]; // value ...
411
412 DBGPRINT(RT_DEBUG_TRACE, ("eFuseWritePhysical Offset=0x%x, length=%d\n", Offset, Length));
413
414 {
415 // Little-endian S | S Big-endian
416 // addr 3 2 1 0 | 0 1 2 3
417 // Ori-V D C B A | A B C D
418 // After swapping
419 // D C B A | D C B A
420 // Both the little and big-endian use the same sequence to write data.
421 // Therefore, we only need swap data when read the data.
422 for (i=0; i<Length; i+=2)
423 {
424 eFusePhysicalWriteRegisters(pAd, Offset+i, 2, &pValueX[i/2]);
425 }
426 }
427}
428
429/*
430========================================================================
431
432 Routine Description:
433
434 Arguments:
435
436 Return Value:
437
438 Note:
439
440========================================================================
441*/
442INT set_eFuseGetFreeBlockCount_Proc( 269INT set_eFuseGetFreeBlockCount_Proc(
443 IN PRTMP_ADAPTER pAd, 270 IN PRTMP_ADAPTER pAd,
444 IN PSTRING arg) 271 IN PSTRING arg)
@@ -492,442 +319,12 @@ USHORT InBuf[3];
492 return TRUE; 319 return TRUE;
493} 320}
494 321
495
496INT set_eFuseLoadFromBin_Proc(
497 IN PRTMP_ADAPTER pAd,
498 IN PSTRING arg)
499{
500 PSTRING src;
501 RTMP_OS_FD srcf;
502 RTMP_OS_FS_INFO osfsInfo;
503 INT retval, memSize;
504 PSTRING buffer, memPtr;
505 INT i = 0,j=0,k=1;
506 USHORT *PDATA;
507 USHORT DATA;
508
509 memSize = 128 + MAX_EEPROM_BIN_FILE_SIZE + sizeof(USHORT) * 8;
510 memPtr = kmalloc(memSize, MEM_ALLOC_FLAG);
511 if (memPtr == NULL)
512 return FALSE;
513
514 NdisZeroMemory(memPtr, memSize);
515 src = memPtr; // kmalloc(128, MEM_ALLOC_FLAG);
516 buffer = src + 128; // kmalloc(MAX_EEPROM_BIN_FILE_SIZE, MEM_ALLOC_FLAG);
517 PDATA = (USHORT*)(buffer + MAX_EEPROM_BIN_FILE_SIZE); // kmalloc(sizeof(USHORT)*8,MEM_ALLOC_FLAG);
518
519 if(strlen(arg)>0)
520 NdisMoveMemory(src, arg, strlen(arg));
521 else
522 NdisMoveMemory(src, EFUSE_EEPROM_DEFULT_FILE, strlen(EFUSE_EEPROM_DEFULT_FILE));
523 DBGPRINT(RT_DEBUG_TRACE, ("FileName=%s\n",src));
524
525 RtmpOSFSInfoChange(&osfsInfo, TRUE);
526
527 srcf = RtmpOSFileOpen(src, O_RDONLY, 0);
528 if (IS_FILE_OPEN_ERR(srcf))
529 {
530 DBGPRINT(RT_DEBUG_ERROR, ("--> Error opening file %s\n", src));
531 retval = FALSE;
532 goto recoverFS;
533 }
534 else
535 {
536 // The object must have a read method
537 while(RtmpOSFileRead(srcf, &buffer[i], 1)==1)
538 {
539 i++;
540 if(i>MAX_EEPROM_BIN_FILE_SIZE)
541 {
542 DBGPRINT(RT_DEBUG_ERROR, ("--> Error reading file %s, file size too large[>%d]\n", src, MAX_EEPROM_BIN_FILE_SIZE));
543 retval = FALSE;
544 goto closeFile;
545 }
546 }
547
548 retval = RtmpOSFileClose(srcf);
549 if (retval)
550 DBGPRINT(RT_DEBUG_TRACE, ("--> Error closing file %s\n", src));
551 }
552
553
554 RtmpOSFSInfoChange(&osfsInfo, FALSE);
555
556 for(j=0;j<i;j++)
557 {
558 DBGPRINT(RT_DEBUG_TRACE, ("%02X ",buffer[j]&0xff));
559 if((j+1)%2==0)
560 PDATA[j/2%8]=((buffer[j]<<8)&0xff00)|(buffer[j-1]&0xff);
561 if(j%16==0)
562 {
563 k=buffer[j];
564 }
565 else
566 {
567 k&=buffer[j];
568 if((j+1)%16==0)
569 {
570 DBGPRINT(RT_DEBUG_TRACE, (" result=%02X,blk=%02x\n",k,j/16));
571 if(k!=0xff)
572 eFuseWriteRegistersFromBin(pAd,(USHORT)j-15, 16, PDATA);
573 else
574 {
575 if(eFuseReadRegisters(pAd,j, 2,(PUSHORT)&DATA)!=0x3f)
576 eFuseWriteRegistersFromBin(pAd,(USHORT)j-15, 16, PDATA);
577 }
578 /*
579 for(l=0;l<8;l++)
580 printk("%04x ",PDATA[l]);
581 printk("\n");
582 */
583 NdisZeroMemory(PDATA,16);
584 }
585 }
586 }
587
588 return TRUE;
589
590closeFile:
591 if (srcf)
592 RtmpOSFileClose(srcf);
593
594recoverFS:
595 RtmpOSFSInfoChange(&osfsInfo, FALSE);
596
597
598 if (memPtr)
599 kfree(memPtr);
600
601 return retval;
602}
603
604
605static NTSTATUS eFuseWriteRegistersFromBin(
606 IN PRTMP_ADAPTER pAd,
607 IN USHORT Offset,
608 IN USHORT Length,
609 IN USHORT* pData)
610{
611 USHORT i;
612 USHORT eFuseData;
613 USHORT LogicalAddress, BlkNum = 0xffff;
614 UCHAR EFSROM_AOUT,Loop=0;
615 EFUSE_CTRL_STRUC eFuseCtrlStruc;
616 USHORT efuseDataOffset;
617 UINT32 data,tempbuffer;
618 USHORT addr,tmpaddr, InBuf[3], tmpOffset;
619 UINT32 buffer[4];
620 BOOLEAN bWriteSuccess = TRUE;
621 BOOLEAN bNotWrite=TRUE;
622 BOOLEAN bAllocateNewBlk=TRUE;
623
624 DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegistersFromBin Offset=%x, pData=%04x:%04x:%04x:%04x\n", Offset, *pData,*(pData+1),*(pData+2),*(pData+3)));
625
626 do
627 {
628 //Step 0. find the entry in the mapping table
629 //The address of EEPROM is 2-bytes alignment.
630 //The last bit is used for alignment, so it must be 0.
631 Loop++;
632 tmpOffset = Offset & 0xfffe;
633 EFSROM_AOUT = eFuseReadRegisters(pAd, tmpOffset, 2, &eFuseData);
634
635 if( EFSROM_AOUT == 0x3f)
636 { //find available logical address pointer
637 //the logical address does not exist, find an empty one
638 //from the first address of block 45=16*45=0x2d0 to the last address of block 47
639 //==>48*16-3(reserved)=2FC
640 bAllocateNewBlk=TRUE;
641 for (i=EFUSE_USAGE_MAP_START; i<=EFUSE_USAGE_MAP_END; i+=2)
642 {
643 //Retrive the logical block nubmer form each logical address pointer
644 //It will access two logical address pointer each time.
645 eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress);
646 if( (LogicalAddress & 0xff) == 0)
647 {//Not used logical address pointer
648 BlkNum = i-EFUSE_USAGE_MAP_START;
649 break;
650 }
651 else if(( (LogicalAddress >> 8) & 0xff) == 0)
652 {//Not used logical address pointer
653 if (i != EFUSE_USAGE_MAP_END)
654 {
655 BlkNum = i-EFUSE_USAGE_MAP_START+1;
656 }
657 break;
658 }
659 }
660 }
661 else
662 {
663 bAllocateNewBlk=FALSE;
664 BlkNum = EFSROM_AOUT;
665 }
666
667 DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegisters BlkNum = %d \n", BlkNum));
668
669 if(BlkNum == 0xffff)
670 {
671 DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegisters: out of free E-fuse space!!!\n"));
672 return FALSE;
673 }
674 //Step 1.1.0
675 //If the block is not existing in mapping table, create one
676 //and write down the 16-bytes data to the new block
677 if(bAllocateNewBlk)
678 {
679 DBGPRINT(RT_DEBUG_TRACE, ("Allocate New Blk\n"));
680 efuseDataOffset = EFUSE_DATA3;
681 for(i=0; i< 4; i++)
682 {
683 DBGPRINT(RT_DEBUG_TRACE, ("Allocate New Blk, Data%d=%04x%04x\n",3-i,pData[2*i+1],pData[2*i]));
684 tempbuffer=((pData[2*i+1]<<16)&0xffff0000)|pData[2*i];
685
686
687 RTMP_IO_WRITE32(pAd, efuseDataOffset,tempbuffer);
688 efuseDataOffset -= 4;
689
690 }
691 /////////////////////////////////////////////////////////////////
692
693 //Step1.1.1. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment.
694 RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrlStruc.word);
695 eFuseCtrlStruc.field.EFSROM_AIN = BlkNum* 0x10 ;
696
697 //Step1.1.2. Write EFSROM_MODE (0x580, bit7:bit6) to 3.
698 eFuseCtrlStruc.field.EFSROM_MODE = 3;
699
700 //Step1.1.3. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical write procedure.
701 eFuseCtrlStruc.field.EFSROM_KICK = 1;
702
703 NdisMoveMemory(&data, &eFuseCtrlStruc, 4);
704
705 RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data);
706
707 //Step1.1.4. Polling EFSROM_KICK(0x580, bit30) until it become 0 again. It¡¦s done.
708 i = 0;
709 while(i < 100)
710 {
711 RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc);
712
713 if(eFuseCtrlStruc.field.EFSROM_KICK == 0)
714 break;
715
716 RTMPusecDelay(2);
717 i++;
718 }
719
720 }
721 else
722 { //Step1.2.
723 //If the same logical number is existing, check if the writting data and the data
724 //saving in this block are the same.
725 /////////////////////////////////////////////////////////////////
726 //read current values of 16-byte block
727 RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrlStruc.word);
728
729 //Step1.2.0. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment.
730 eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0;
731
732 //Step1.2.1. Write EFSROM_MODE (0x580, bit7:bit6) to 1.
733 eFuseCtrlStruc.field.EFSROM_MODE = 0;
734
735 //Step1.2.2. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical read procedure.
736 eFuseCtrlStruc.field.EFSROM_KICK = 1;
737
738 NdisMoveMemory(&data, &eFuseCtrlStruc, 4);
739 RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data);
740
741 //Step1.2.3. Polling EFSROM_KICK(0x580, bit30) until it become 0 again.
742 i = 0;
743 while(i < 500)
744 {
745 RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc);
746
747 if(eFuseCtrlStruc.field.EFSROM_KICK == 0)
748 break;
749 RTMPusecDelay(2);
750 i++;
751 }
752
753 //Step1.2.4. Read 16-byte of data from EFUSE_DATA0-3 (0x59C-0x590)
754 efuseDataOffset = EFUSE_DATA3;
755 for(i=0; i< 4; i++)
756 {
757 RTMP_IO_READ32(pAd, efuseDataOffset, (PUINT32) &buffer[i]);
758 efuseDataOffset -= 4;
759 }
760 //Step1.2.5. Check if the data of efuse and the writing data are the same.
761 for(i =0; i<4; i++)
762 {
763 tempbuffer=((pData[2*i+1]<<16)&0xffff0000)|pData[2*i];
764 DBGPRINT(RT_DEBUG_TRACE, ("buffer[%d]=%x,pData[%d]=%x,pData[%d]=%x,tempbuffer=%x\n",i,buffer[i],2*i,pData[2*i],2*i+1,pData[2*i+1],tempbuffer));
765
766 if(((buffer[i]&0xffff0000)==(pData[2*i+1]<<16))&&((buffer[i]&0xffff)==pData[2*i]))
767 bNotWrite&=TRUE;
768 else
769 {
770 bNotWrite&=FALSE;
771 break;
772 }
773 }
774 if(!bNotWrite)
775 {
776 printk("The data is not the same\n");
777
778 for(i =0; i<8; i++)
779 {
780 addr = BlkNum * 0x10 ;
781
782 InBuf[0] = addr+2*i;
783 InBuf[1] = 2;
784 InBuf[2] = pData[i];
785
786 eFuseWritePhysical(pAd, &InBuf[0], 6, NULL, 2);
787 }
788
789 }
790 else
791 return TRUE;
792 }
793
794
795
796 //Step 2. Write mapping table
797 addr = EFUSE_USAGE_MAP_START+BlkNum;
798
799 tmpaddr = addr;
800
801 if(addr % 2 != 0)
802 addr = addr -1;
803 InBuf[0] = addr;
804 InBuf[1] = 2;
805
806 //convert the address from 10 to 8 bit ( bit7, 6 = parity and bit5 ~ 0 = bit9~4), and write to logical map entry
807 tmpOffset = Offset;
808 tmpOffset >>= 4;
809 tmpOffset |= ((~((tmpOffset & 0x01) ^ ( tmpOffset >> 1 & 0x01) ^ (tmpOffset >> 2 & 0x01) ^ (tmpOffset >> 3 & 0x01))) << 6) & 0x40;
810 tmpOffset |= ((~( (tmpOffset >> 2 & 0x01) ^ (tmpOffset >> 3 & 0x01) ^ (tmpOffset >> 4 & 0x01) ^ ( tmpOffset >> 5 & 0x01))) << 7) & 0x80;
811
812 // write the logical address
813 if(tmpaddr%2 != 0)
814 InBuf[2] = tmpOffset<<8;
815 else
816 InBuf[2] = tmpOffset;
817
818 eFuseWritePhysical(pAd,&InBuf[0], 6, NULL, 0);
819
820 //Step 3. Compare data if not the same, invalidate the mapping entry, then re-write the data until E-fuse is exhausted
821 bWriteSuccess = TRUE;
822 for(i =0; i<8; i++)
823 {
824 addr = BlkNum * 0x10 ;
825
826 InBuf[0] = addr+2*i;
827 InBuf[1] = 2;
828 InBuf[2] = 0x0;
829
830 eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2);
831 DBGPRINT(RT_DEBUG_TRACE, ("addr=%x, buffer[i]=%x,InBuf[2]=%x\n",InBuf[0],pData[i],InBuf[2]));
832 if(pData[i] != InBuf[2])
833 {
834 bWriteSuccess = FALSE;
835 break;
836 }
837 }
838
839 //Step 4. invlidate mapping entry and find a free mapping entry if not succeed
840
841 if (!bWriteSuccess&&Loop<2)
842 {
843 DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegistersFromBin::Not bWriteSuccess BlkNum = %d\n", BlkNum));
844
845 // the offset of current mapping entry
846 addr = EFUSE_USAGE_MAP_START+BlkNum;
847
848 //find a new mapping entry
849 BlkNum = 0xffff;
850 for (i=EFUSE_USAGE_MAP_START; i<=EFUSE_USAGE_MAP_END; i+=2)
851 {
852 eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress);
853 if( (LogicalAddress & 0xff) == 0)
854 {
855 BlkNum = i-EFUSE_USAGE_MAP_START;
856 break;
857 }
858 else if(( (LogicalAddress >> 8) & 0xff) == 0)
859 {
860 if (i != EFUSE_USAGE_MAP_END)
861 {
862 BlkNum = i+1-EFUSE_USAGE_MAP_START;
863 }
864 break;
865 }
866 }
867 DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegistersFromBin::Not bWriteSuccess new BlkNum = %d\n", BlkNum));
868 if(BlkNum == 0xffff)
869 {
870 DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegistersFromBin: out of free E-fuse space!!!\n"));
871 return FALSE;
872 }
873
874 //invalidate the original mapping entry if new entry is not found
875 tmpaddr = addr;
876
877 if(addr % 2 != 0)
878 addr = addr -1;
879 InBuf[0] = addr;
880 InBuf[1] = 2;
881
882 eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2);
883
884 // write the logical address
885 if(tmpaddr%2 != 0)
886 {
887 // Invalidate the high byte
888 for (i=8; i<15; i++)
889 {
890 if( ( (InBuf[2] >> i) & 0x01) == 0)
891 {
892 InBuf[2] |= (0x1 <<i);
893 break;
894 }
895 }
896 }
897 else
898 {
899 // invalidate the low byte
900 for (i=0; i<8; i++)
901 {
902 if( ( (InBuf[2] >> i) & 0x01) == 0)
903 {
904 InBuf[2] |= (0x1 <<i);
905 break;
906 }
907 }
908 }
909 eFuseWritePhysical(pAd, &InBuf[0], 6, NULL, 0);
910 }
911
912 }
913 while(!bWriteSuccess&&Loop<2);
914
915 return TRUE;
916}
917
918
919int rtmp_ee_efuse_read16( 322int rtmp_ee_efuse_read16(
920 IN RTMP_ADAPTER *pAd, 323 IN RTMP_ADAPTER *pAd,
921 IN USHORT Offset, 324 IN USHORT Offset,
922 OUT USHORT *pValue) 325 OUT USHORT *pValue)
923{ 326{
924 if(pAd->bFroceEEPROMBuffer || pAd->bEEPROMFile) 327 eFuseReadRegisters(pAd, Offset, 2, pValue);
925 {
926 DBGPRINT(RT_DEBUG_TRACE, ("Read from EEPROM Buffer\n"));
927 NdisMoveMemory(pValue, &(pAd->EEPROMImage[Offset]), 2);
928 }
929 else
930 eFuseReadRegisters(pAd, Offset, 2, pValue);
931 return (*pValue); 328 return (*pValue);
932} 329}
933 330
@@ -944,177 +341,6 @@ int RtmpEfuseSupportCheck(
944 return 0; 341 return 0;
945} 342}
946 343
947INT set_eFuseBufferModeWriteBack_Proc(
948 IN PRTMP_ADAPTER pAd,
949 IN PSTRING arg)
950{
951 UINT Enable;
952
953
954 if(strlen(arg)>0)
955 {
956 Enable= simple_strtol(arg, 0, 16);
957 }
958 else
959 return FALSE;
960 if(Enable==1)
961 {
962 DBGPRINT(RT_DEBUG_TRACE, ("set_eFuseBufferMode_Proc:: Call WRITEEEPROMBUF"));
963 eFuseWriteEeeppromBuf(pAd);
964 }
965 else
966 return FALSE;
967 return TRUE;
968}
969
970
971/*
972 ========================================================================
973
974 Routine Description:
975 Load EEPROM from bin file for eFuse mode
976
977 Arguments:
978 Adapter Pointer to our adapter
979
980 Return Value:
981 NDIS_STATUS_SUCCESS firmware image load ok
982 NDIS_STATUS_FAILURE image not found
983
984 IRQL = PASSIVE_LEVEL
985
986 ========================================================================
987*/
988INT eFuseLoadEEPROM(
989 IN PRTMP_ADAPTER pAd)
990{
991 PSTRING src = NULL;
992 INT retval;
993 RTMP_OS_FD srcf;
994 RTMP_OS_FS_INFO osFSInfo;
995
996
997 src=EFUSE_BUFFER_PATH;
998 DBGPRINT(RT_DEBUG_TRACE, ("FileName=%s\n",src));
999
1000
1001 RtmpOSFSInfoChange(&osFSInfo, TRUE);
1002
1003 if (src && *src)
1004 {
1005 srcf = RtmpOSFileOpen(src, O_RDONLY, 0);
1006 if (IS_FILE_OPEN_ERR(srcf))
1007 {
1008 DBGPRINT(RT_DEBUG_ERROR, ("--> Error %ld opening %s\n", -PTR_ERR(srcf),src));
1009 return FALSE;
1010 }
1011 else
1012 {
1013
1014 memset(pAd->EEPROMImage, 0x00, MAX_EEPROM_BIN_FILE_SIZE);
1015
1016
1017 retval =RtmpOSFileRead(srcf, (PSTRING)pAd->EEPROMImage, MAX_EEPROM_BIN_FILE_SIZE);
1018 if (retval > 0)
1019 {
1020 RTMPSetProfileParameters(pAd, (PSTRING)pAd->EEPROMImage);
1021 retval = NDIS_STATUS_SUCCESS;
1022 }
1023 else
1024 DBGPRINT(RT_DEBUG_ERROR, ("Read file \"%s\" failed(errCode=%d)!\n", src, retval));
1025
1026 }
1027
1028
1029 }
1030 else
1031 {
1032 DBGPRINT(RT_DEBUG_ERROR, ("--> Error src or srcf is null\n"));
1033 return FALSE;
1034
1035 }
1036
1037 retval=RtmpOSFileClose(srcf);
1038
1039 if (retval)
1040 {
1041 DBGPRINT(RT_DEBUG_TRACE, ("--> Error %d closing %s\n", -retval, src));
1042 }
1043
1044
1045 RtmpOSFSInfoChange(&osFSInfo, FALSE);
1046
1047 return TRUE;
1048}
1049
1050INT eFuseWriteEeeppromBuf(
1051 IN PRTMP_ADAPTER pAd)
1052{
1053
1054 PSTRING src = NULL;
1055 INT retval;
1056 RTMP_OS_FD srcf;
1057 RTMP_OS_FS_INFO osFSInfo;
1058
1059
1060 src=EFUSE_BUFFER_PATH;
1061 DBGPRINT(RT_DEBUG_TRACE, ("FileName=%s\n",src));
1062
1063 RtmpOSFSInfoChange(&osFSInfo, TRUE);
1064
1065
1066
1067 if (src && *src)
1068 {
1069 srcf = RtmpOSFileOpen(src, O_WRONLY|O_CREAT, 0);
1070
1071 if (IS_FILE_OPEN_ERR(srcf))
1072 {
1073 DBGPRINT(RT_DEBUG_ERROR, ("--> Error %ld opening %s\n", -PTR_ERR(srcf),src));
1074 return FALSE;
1075 }
1076 else
1077 {
1078/*
1079 // The object must have a read method
1080 if (srcf->f_op && srcf->f_op->write)
1081 {
1082 // The object must have a read method
1083 srcf->f_op->write(srcf, pAd->EEPROMImage, 1024, &srcf->f_pos);
1084
1085 }
1086 else
1087 {
1088 DBGPRINT(RT_DEBUG_ERROR, ("--> Error!! System doest not support read function\n"));
1089 return FALSE;
1090 }
1091*/
1092
1093 RtmpOSFileWrite(srcf, (PSTRING)pAd->EEPROMImage,MAX_EEPROM_BIN_FILE_SIZE);
1094
1095 }
1096
1097
1098 }
1099 else
1100 {
1101 DBGPRINT(RT_DEBUG_ERROR, ("--> Error src or srcf is null\n"));
1102 return FALSE;
1103
1104 }
1105
1106 retval=RtmpOSFileClose(srcf);
1107
1108 if (retval)
1109 {
1110 DBGPRINT(RT_DEBUG_TRACE, ("--> Error %d closing %s\n", -retval, src));
1111 }
1112
1113 RtmpOSFSInfoChange(&osFSInfo, FALSE);
1114 return TRUE;
1115}
1116
1117
1118VOID eFuseGetFreeBlockCount(IN PRTMP_ADAPTER pAd, 344VOID eFuseGetFreeBlockCount(IN PRTMP_ADAPTER pAd,
1119 PUINT EfuseFreeBlock) 345 PUINT EfuseFreeBlock)
1120{ 346{
@@ -1151,18 +377,6 @@ INT eFuse_init(
1151 UINT EfuseFreeBlock=0; 377 UINT EfuseFreeBlock=0;
1152 DBGPRINT(RT_DEBUG_ERROR, ("NVM is Efuse and its size =%x[%x-%x] \n",EFUSE_USAGE_MAP_SIZE,EFUSE_USAGE_MAP_START,EFUSE_USAGE_MAP_END)); 378 DBGPRINT(RT_DEBUG_ERROR, ("NVM is Efuse and its size =%x[%x-%x] \n",EFUSE_USAGE_MAP_SIZE,EFUSE_USAGE_MAP_START,EFUSE_USAGE_MAP_END));
1153 eFuseGetFreeBlockCount(pAd, &EfuseFreeBlock); 379 eFuseGetFreeBlockCount(pAd, &EfuseFreeBlock);
1154 //If the used block of efuse is less than 5. We assume the default value
1155 // of this efuse is empty and change to the buffer mode in odrder to
1156 //bring up interfaces successfully.
1157 if(EfuseFreeBlock > (EFUSE_USAGE_MAP_END-5))
1158 {
1159 DBGPRINT(RT_DEBUG_ERROR, ("NVM is Efuse and the information is too less to bring up interface. Force to use EEPROM Buffer Mode\n"));
1160 pAd->bFroceEEPROMBuffer = TRUE;
1161 eFuseLoadEEPROM(pAd);
1162 }
1163 else
1164 pAd->bFroceEEPROMBuffer = FALSE;
1165 DBGPRINT(RT_DEBUG_TRACE, ("NVM is Efuse and force to use EEPROM Buffer Mode=%x\n",pAd->bFroceEEPROMBuffer));
1166 380
1167 return 0; 381 return 0;
1168} 382}
diff --git a/drivers/staging/rt2860/common/eeprom.c b/drivers/staging/rt2860/common/eeprom.c
index d7a2664bb73..39276ca64c1 100644
--- a/drivers/staging/rt2860/common/eeprom.c
+++ b/drivers/staging/rt2860/common/eeprom.c
@@ -69,10 +69,7 @@ INT RtmpChipOpsEepromHook(
69 return 0 ; 69 return 0 ;
70 } 70 }
71 else 71 else
72 {
73 pAd->bFroceEEPROMBuffer = FALSE;
74 DBGPRINT(RT_DEBUG_TRACE, ("NVM is EEPROM\n")); 72 DBGPRINT(RT_DEBUG_TRACE, ("NVM is EEPROM\n"));
75 }
76#endif // RTMP_EFUSE_SUPPORT // 73#endif // RTMP_EFUSE_SUPPORT //
77#endif // RT30xx // 74#endif // RT30xx //
78 75
diff --git a/drivers/staging/rt2860/common/rtmp_init.c b/drivers/staging/rt2860/common/rtmp_init.c
index 9e1c73dbfb2..fe8327b9b13 100644
--- a/drivers/staging/rt2860/common/rtmp_init.c
+++ b/drivers/staging/rt2860/common/rtmp_init.c
@@ -694,15 +694,6 @@ VOID NICReadEEPROMParameters(
694 694
695 if (pAd->chipOps.eeinit) 695 if (pAd->chipOps.eeinit)
696 pAd->chipOps.eeinit(pAd); 696 pAd->chipOps.eeinit(pAd);
697#ifdef RTMP_EFUSE_SUPPORT
698#ifdef RT30xx
699 if(!pAd->bFroceEEPROMBuffer && pAd->bEEPROMFile)
700 {
701 DBGPRINT(RT_DEBUG_TRACE, ("--> NICReadEEPROMParameters::(Efuse)Load to EEPROM Buffer Mode\n"));
702 eFuseLoadEEPROM(pAd);
703 }
704#endif // RT30xx //
705#endif // RTMP_EFUSE_SUPPORT //
706 697
707 // Init EEPROM Address Number, before access EEPROM; if 93c46, EEPROMAddressNum=6, else if 93c66, EEPROMAddressNum=8 698 // Init EEPROM Address Number, before access EEPROM; if 93c46, EEPROMAddressNum=6, else if 93c66, EEPROMAddressNum=8
708 RTMP_IO_READ32(pAd, E2PROM_CSR, &data); 699 RTMP_IO_READ32(pAd, E2PROM_CSR, &data);