1 #include <linux/slab.h>
12 void _Set_D_SsfdcRdCmd (BYTE
);
13 void _Set_D_SsfdcRdAddr (BYTE
);
14 void _Set_D_SsfdcRdChip (void);
15 void _Set_D_SsfdcRdStandby (void);
16 void _Start_D_SsfdcRdHwECC (void);
17 void _Stop_D_SsfdcRdHwECC (void);
18 void _Load_D_SsfdcRdHwECC (BYTE
);
19 void _Set_D_SsfdcWrCmd (BYTE
);
20 void _Set_D_SsfdcWrAddr (BYTE
);
21 void _Set_D_SsfdcWrBlock (void);
22 void _Set_D_SsfdcWrStandby (void);
23 void _Start_D_SsfdcWrHwECC (void);
24 void _Load_D_SsfdcWrHwECC (BYTE
);
25 int _Check_D_SsfdcBusy (WORD
);
26 int _Check_D_SsfdcStatus (void);
27 void _Reset_D_SsfdcErr (void);
28 void _Read_D_SsfdcBuf (BYTE
*);
29 void _Write_D_SsfdcBuf (BYTE
*);
30 void _Read_D_SsfdcByte (BYTE
*);
31 void _ReadRedt_D_SsfdcBuf (BYTE
*);
32 void _WriteRedt_D_SsfdcBuf (BYTE
*);
33 BYTE
_Check_D_DevCode (BYTE
);
35 void _Set_D_ECCdata (BYTE
,BYTE
*);
36 void _Calc_D_ECCdata (BYTE
*);
38 //void SM_ReadDataWithDMA (PFDO_DEVICE_EXTENSION, BYTE *, WORD);
39 //void SM_WriteDataWithDMA (PFDO_DEVICE_EXTENSION, BYTE *, WORD);
41 struct SSFDCTYPE Ssfdc
;
43 struct CIS_AREA CisArea
;
45 static BYTE EccBuf
[6];
46 extern PBYTE SMHostAddr
;
47 extern DWORD ErrXDCode
;
49 extern WORD ReadBlock
;
50 extern WORD WriteBlock
;
52 //KEVENT SM_DMADoneEvent;
54 #define EVEN 0 // Even Page for 256byte/page
55 #define ODD 1 // Odd Page for 256byte/page
58 //SmartMedia Redundant buffer data Control Subroutine
59 //----- Check_D_DataBlank() --------------------------------------------
60 int Check_D_DataBlank(BYTE
*redundant
)
64 for(i
=0; i
<REDTSIZE
; i
++)
65 if (*redundant
++!=0xFF)
71 //----- Check_D_FailBlock() --------------------------------------------
72 int Check_D_FailBlock(BYTE
*redundant
)
74 redundant
+=REDT_BLOCK
;
80 if (hweight8(*redundant
)<7)
86 //----- Check_D_DataStatus() -------------------------------------------
87 int Check_D_DataStatus(BYTE
*redundant
)
95 ErrXDCode
= ERR_DataStatus
;
101 if (hweight8(*redundant
)<5)
107 //----- Load_D_LogBlockAddr() ------------------------------------------
108 int Load_D_LogBlockAddr(BYTE
*redundant
)
111 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
112 //ADDRESS_T bb = (ADDRESS_T) &Media;
114 addr1
=(WORD
)*(redundant
+REDT_ADDR1H
)*0x0100+(WORD
)*(redundant
+REDT_ADDR1L
);
115 addr2
=(WORD
)*(redundant
+REDT_ADDR2H
)*0x0100+(WORD
)*(redundant
+REDT_ADDR2L
);
118 if ((addr1
&0xF000)==0x1000)
119 { Media
.LogBlock
=(addr1
&0x0FFF)/2; return(SMSUCCESS
); }
121 if (hweight16((WORD
)(addr1
^addr2
))!=0x01) return(ERROR
);
123 if ((addr1
&0xF000)==0x1000)
124 if (!(hweight16(addr1
) &0x01))
125 { Media
.LogBlock
=(addr1
&0x0FFF)/2; return(SMSUCCESS
); }
127 if ((addr2
&0xF000)==0x1000)
128 if (!(hweight16(addr2
) &0x01))
129 { Media
.LogBlock
=(addr2
&0x0FFF)/2; return(SMSUCCESS
); }
134 //----- Clr_D_RedundantData() ------------------------------------------
135 void Clr_D_RedundantData(BYTE
*redundant
)
139 for(i
=0; i
<REDTSIZE
; i
++)
143 //----- Set_D_LogBlockAddr() -------------------------------------------
144 void Set_D_LogBlockAddr(BYTE
*redundant
)
148 *(redundant
+REDT_BLOCK
)=0xFF;
149 *(redundant
+REDT_DATA
) =0xFF;
150 addr
=Media
.LogBlock
*2+0x1000;
152 if ((hweight16(addr
)%2))
155 *(redundant
+REDT_ADDR1H
)=*(redundant
+REDT_ADDR2H
)=(BYTE
)(addr
/0x0100);
156 *(redundant
+REDT_ADDR1L
)=*(redundant
+REDT_ADDR2L
)=(BYTE
)addr
;
159 //----- Set_D_FailBlock() ----------------------------------------------
160 void Set_D_FailBlock(BYTE
*redundant
)
164 for(i
=0; i
<REDTSIZE
; i
++)
165 *redundant
++=(BYTE
)((i
==REDT_BLOCK
)?0xF0:0xFF);
168 //----- Set_D_DataStaus() ----------------------------------------------
169 void Set_D_DataStaus(BYTE
*redundant
)
171 redundant
+=REDT_DATA
;
175 //SmartMedia Function Command Subroutine
177 //----- Ssfdc_D_Reset() ------------------------------------------------
178 void Ssfdc_D_Reset(struct us_data
*us
)
180 //NTSTATUS ntStatus = STATUS_SUCCESS;
181 //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
184 //printk("Ssfdc_D_Reset --- But do nothing !!\n");
186 /* RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
187 pBulkCbw->dCBWSignature = CBW_SIGNTURE;
188 pBulkCbw->bCBWLun = CBW_LUN;
189 //pBulkCbw->dCBWDataTransferLength = 0x200;
190 pBulkCbw->bmCBWFlags = 0x80;
191 pBulkCbw->CBWCb[0] = 0xF2;
192 pBulkCbw->CBWCb[1] = 0x07;
194 ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_READ, NULL);
196 if (!NT_SUCCESS(ntStatus))
198 ENE_Print("Ssfdc_D_Reset Fail !!\n");
203 //----- Ssfdc_D_ReadCisSect() ------------------------------------------
204 int Ssfdc_D_ReadCisSect(struct us_data
*us
, BYTE
*buf
,BYTE
*redundant
)
208 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
209 //ADDRESS_T bb = (ADDRESS_T) &Media;
211 zone
=Media
.Zone
; block
=Media
.PhyBlock
; sector
=Media
.Sector
;
213 Media
.PhyBlock
=CisArea
.PhyBlock
;
214 Media
.Sector
=CisArea
.Sector
;
216 if (Ssfdc_D_ReadSect(us
,buf
,redundant
))
218 Media
.Zone
=zone
; Media
.PhyBlock
=block
; Media
.Sector
=sector
;
222 Media
.Zone
=zone
; Media
.PhyBlock
=block
; Media
.Sector
=sector
;
226 ////----- Ssfdc_D_WriteRedtMode() ----------------------------------------
227 //void Ssfdc_D_WriteRedtMode(void)
229 // _Set_D_SsfdcRdCmd (RST_CHIP);
230 // _Check_D_SsfdcBusy (BUSY_RESET);
231 // _Set_D_SsfdcRdCmd (READ_REDT);
232 // _Check_D_SsfdcBusy (BUSY_READ);
233 // _Set_D_SsfdcRdStandby ();
236 ////----- Ssfdc_D_ReadID() -----------------------------------------------
237 //void Ssfdc_D_ReadID(BYTE *buf, BYTE ReadID)
239 // _Set_D_SsfdcRdCmd (ReadID);
240 // _Set_D_SsfdcRdChip ();
241 // _Read_D_SsfdcByte (buf++);
242 // _Read_D_SsfdcByte (buf++);
243 // _Read_D_SsfdcByte (buf++);
244 // _Read_D_SsfdcByte (buf);
245 // _Set_D_SsfdcRdStandby ();
249 //----- Ssfdc_D_ReadSect() ---------------------------------------------
250 int Ssfdc_D_ReadSect(struct us_data
*us
, BYTE
*buf
,BYTE
*redundant
)
252 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
256 result
= ENE_LoadBinCode(us
, SM_RW_PATTERN
);
257 if (result
!= USB_STOR_XFER_GOOD
)
259 printk("Load SM RW Code Fail !!\n");
260 return USB_STOR_TRANSPORT_ERROR
;
263 addr
= (WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+Media
.PhyBlock
;
264 addr
= addr
*(WORD
)Ssfdc
.MaxSectors
+Media
.Sector
;
267 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
268 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
269 bcb
->DataTransferLength
= 0x200;
273 bcb
->CDB
[4] = (BYTE
)addr
;
274 bcb
->CDB
[3] = (BYTE
)(addr
/0x0100);
275 bcb
->CDB
[2] = Media
.Zone
/2;
277 result
= ENE_SendScsiCmd(us
, FDIR_READ
, buf
, 0);
278 if (result
!= USB_STOR_XFER_GOOD
)
279 return USB_STOR_TRANSPORT_ERROR
;
282 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
283 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
284 bcb
->DataTransferLength
= 0x10;
288 bcb
->CDB
[4] = (BYTE
)addr
;
289 bcb
->CDB
[3] = (BYTE
)(addr
/0x0100);
290 bcb
->CDB
[2] = Media
.Zone
/2;
294 result
= ENE_SendScsiCmd(us
, FDIR_READ
, redundant
, 0);
295 if (result
!= USB_STOR_XFER_GOOD
)
296 return USB_STOR_TRANSPORT_ERROR
;
298 return USB_STOR_TRANSPORT_GOOD
;
301 //----- Ssfdc_D_ReadBlock() ---------------------------------------------
302 int Ssfdc_D_ReadBlock(struct us_data
*us
, WORD count
, BYTE
*buf
,BYTE
*redundant
)
304 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
308 //printk("Ssfdc_D_ReadBlock\n");
309 result
= ENE_LoadBinCode(us
, SM_RW_PATTERN
);
310 if (result
!= USB_STOR_XFER_GOOD
)
312 printk("Load SM RW Code Fail !!\n");
313 return USB_STOR_TRANSPORT_ERROR
;
316 addr
= (WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+Media
.PhyBlock
;
317 addr
= addr
*(WORD
)Ssfdc
.MaxSectors
+Media
.Sector
;
320 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
321 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
322 bcb
->DataTransferLength
= 0x200*count
;
326 bcb
->CDB
[4] = (BYTE
)addr
;
327 bcb
->CDB
[3] = (BYTE
)(addr
/0x0100);
328 bcb
->CDB
[2] = Media
.Zone
/2;
330 result
= ENE_SendScsiCmd(us
, FDIR_READ
, buf
, 0);
331 if (result
!= USB_STOR_XFER_GOOD
)
332 return USB_STOR_TRANSPORT_ERROR
;
335 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
336 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
337 bcb
->DataTransferLength
= 0x10;
341 bcb
->CDB
[4] = (BYTE
)addr
;
342 bcb
->CDB
[3] = (BYTE
)(addr
/0x0100);
343 bcb
->CDB
[2] = Media
.Zone
/2;
347 result
= ENE_SendScsiCmd(us
, FDIR_READ
, redundant
, 0);
348 if (result
!= USB_STOR_XFER_GOOD
)
349 return USB_STOR_TRANSPORT_ERROR
;
351 return USB_STOR_TRANSPORT_GOOD
;
354 ////----- Ssfdc_D_ReadSect_DMA() ---------------------------------------------
355 //int Ssfdc_D_ReadSect_DMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
357 // WORD SectByteCount, addr;
361 // if (!_Hw_D_ChkCardIn())
363 // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
364 // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
365 // // cycle starting address
366 // SM_STARTADDR_LSB = 0x00;
367 // SM_STARTADDR_IISB = (BYTE)addr;
368 // SM_STARTADDR_IIISB = (BYTE)(addr/0x0100);
369 // SM_STARTADDR_MSB = Media.Zone/2;
371 // //Sector byte count = 0x200(DMA)
372 // SectByteCount = 0x20f;
373 // SM_BYTECNT_LO = (BYTE)SectByteCount;
374 // SM_CMD_CTRL3 = (SM_CMD_CTRL3 & 0xFC) | (BYTE)(SectByteCount/0x0100);
375 // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate )
376 // SM_FIFO_CTRL = (SM_APB08_MASK | SM_DMAEN_MASK | SM_DMA_UPSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK);
378 // SM_FIFO_CTRL = (SM_APB32_MASK | SM_DMAEN_MASK | SM_DMA_UPSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK);
380 // _Hw_D_EccRdReset();
381 // _Hw_D_EccRdStart();
383 // SM_CMD_CTRL1 = (SM_CMD_READ_1);
384 // SM_CMD_CTRL1 = (SM_CMD_READ_1 | SM_CMD_START_BIT);
386 // SectByteCount = 0x1ff;
387 // //SM_ReadDataWithDMA(fdoExt, buf, SectByteCount);
388 // //_ReadRedt_D_SsfdcBuf(redundant);
389 // len = 0x1000 - ((WORD)(buf) & 0x0FFF);
392 // SM_ReadDataWithDMA(fdoExt, buf, len-1);
393 // SM_ReadDataWithDMA(fdoExt, buf+len, SectByteCount-len);
394 // //ENE_Print("Read DMA !!! buf1 = %p, len = %x, buf2 = %p\n", buf, len, buf+len);
397 // SM_ReadDataWithDMA(fdoExt, buf, SectByteCount);
399 // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate )
401 // _ReadRedt_D_SsfdcBuf(redundant);
405 // Buffer[0] = READ_PORT_DWORD(SM_REG_DATA);
406 // Buffer[1] = READ_PORT_DWORD(SM_REG_DATA);
407 // Buffer[2] = READ_PORT_DWORD(SM_REG_DATA);
408 // Buffer[3] = READ_PORT_DWORD(SM_REG_DATA);
409 // memcpy(redundant, Buffer, 0x10);
412 // while ( _Hw_D_ChkCardIn() )
414 // if((READ_PORT_BYTE(SM_REG_INT_STATUS) & 0x10))
416 // WRITE_PORT_BYTE(SM_REG_INT_STATUS, 0x10);
420 // _Hw_D_EccRdStop();
421 // _Hw_D_SetRdStandby();
422 // _Load_D_SsfdcRdHwECC(EVEN);
424 // _Calc_D_ECCdata(buf);
425 // _Set_D_SsfdcRdStandby();
427 // if (!_Hw_D_ChkCardIn())
429 // return(SMSUCCESS);
432 ////----- Ssfdc_D_ReadSect_PIO() ---------------------------------------------
433 //int Ssfdc_D_ReadSect_PIO(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
435 // _Set_D_SsfdcRdCmd(READ);
436 // _Set_D_SsfdcRdAddr(EVEN);
438 // if (_Check_D_SsfdcBusy(BUSY_READ))
439 // { _Reset_D_SsfdcErr(); return(ERROR); }
441 // _Start_D_SsfdcRdHwECC();
442 // _Read_D_SsfdcBuf(buf);
443 // _Stop_D_SsfdcRdHwECC();
444 // _ReadRedt_D_SsfdcBuf(redundant);
445 // _Load_D_SsfdcRdHwECC(EVEN);
447 // if (_Check_D_SsfdcBusy(BUSY_READ))
448 // { _Reset_D_SsfdcErr(); return(ERROR); }
450 // _Calc_D_ECCdata(buf);
451 // _Set_D_SsfdcRdStandby();
452 // return(SMSUCCESS);
456 //----- Ssfdc_D_WriteSect() --------------------------------------------
457 int Ssfdc_D_WriteSect(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
459 PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
463 //ENE_Print("SMILSUB --- Ssfdc_D_WriteSect\n");
464 ENE_LoadBinCode(fdoExt, SM_RW_PATTERN);
466 addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
467 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
470 RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
471 pBulkCbw->dCBWSignature = CBW_SIGNTURE;
472 pBulkCbw->bCBWLun = CBW_LUN;
473 pBulkCbw->dCBWDataTransferLength = 0x200;
474 pBulkCbw->bmCBWFlags = 0x00;
475 pBulkCbw->CBWCb[0] = 0xF0;
476 pBulkCbw->CBWCb[1] = 0x04;
477 //pBulkCbw->CBWCb[4] = (BYTE)addr;
478 //pBulkCbw->CBWCb[3] = (BYTE)(addr/0x0100);
479 //pBulkCbw->CBWCb[2] = Media.Zone/2;
480 //pBulkCbw->CBWCb[5] = *(redundant+REDT_ADDR1H);
481 //pBulkCbw->CBWCb[6] = *(redundant+REDT_ADDR1L);
482 pBulkCbw->CBWCb[7] = (BYTE)addr;
483 pBulkCbw->CBWCb[6] = (BYTE)(addr/0x0100);
484 pBulkCbw->CBWCb[5] = Media.Zone/2;
485 pBulkCbw->CBWCb[8] = *(redundant+REDT_ADDR1H);
486 pBulkCbw->CBWCb[9] = *(redundant+REDT_ADDR1L);
488 ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_WRITE, buf);
490 if (!NT_SUCCESS(ntStatus))
495 // BYTE bf[0x200], rdd[0x10];
498 // RtlZeroMemory(bf, 0x200);
499 // RtlZeroMemory(rdd, 0x10);
500 // ntStatus = SM_ReadBlock(fdoExt, bf, rdd);
501 // for (i=0; i<0x200; i++)
503 // if (buf[i] != bf[i])
504 // ENE_Print("buf[%x] = %x, bf[%x] = %x\n", buf, bf);
506 // if (!NT_SUCCESS(ntStatus))
507 // ENE_Print("Error\n");
513 //----- Ssfdc_D_CopyBlock() --------------------------------------------
514 int Ssfdc_D_CopyBlock(struct us_data
*us
, WORD count
, BYTE
*buf
,BYTE
*redundant
)
516 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
518 //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
520 WORD ReadAddr
, WriteAddr
;
522 //printk("Ssfdc_D_WriteSect --- ZONE = %x, ReadBlock = %x, WriteBlock = %x\n", Media.Zone, ReadBlock, WriteBlock);
524 result
= ENE_LoadBinCode(us
, SM_RW_PATTERN
);
525 if (result
!= USB_STOR_XFER_GOOD
)
527 printk("Load SM RW Code Fail !!\n");
528 return USB_STOR_TRANSPORT_ERROR
;
531 ReadAddr
= (WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+ReadBlock
;
532 ReadAddr
= ReadAddr
*(WORD
)Ssfdc
.MaxSectors
;
533 WriteAddr
= (WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+WriteBlock
;
534 WriteAddr
= WriteAddr
*(WORD
)Ssfdc
.MaxSectors
;
537 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
538 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
539 bcb
->DataTransferLength
= 0x200*count
;
543 bcb
->CDB
[7] = (BYTE
)WriteAddr
;
544 bcb
->CDB
[6] = (BYTE
)(WriteAddr
/0x0100);
545 bcb
->CDB
[5] = Media
.Zone
/2;
546 bcb
->CDB
[8] = *(redundant
+REDT_ADDR1H
);
547 bcb
->CDB
[9] = *(redundant
+REDT_ADDR1L
);
548 bcb
->CDB
[10] = Media
.Sector
;
550 if (ReadBlock
!= NO_ASSIGN
)
552 bcb
->CDB
[4] = (BYTE
)ReadAddr
;
553 bcb
->CDB
[3] = (BYTE
)(ReadAddr
/0x0100);
554 bcb
->CDB
[2] = Media
.Zone
/2;
559 result
= ENE_SendScsiCmd(us
, FDIR_WRITE
, buf
, 0);
560 if (result
!= USB_STOR_XFER_GOOD
)
561 return USB_STOR_TRANSPORT_ERROR
;
563 return USB_STOR_TRANSPORT_GOOD
;
566 //----- Ssfdc_D_WriteBlock() --------------------------------------------
567 int Ssfdc_D_WriteBlock(PFDO_DEVICE_EXTENSION fdoExt, WORD count, BYTE *buf,BYTE *redundant)
569 PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
573 //ENE_Print("SMILSUB --- Ssfdc_D_WriteSect\n");
574 ENE_LoadBinCode(fdoExt, SM_RW_PATTERN);
576 addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
577 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
580 RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
581 pBulkCbw->dCBWSignature = CBW_SIGNTURE;
582 pBulkCbw->bCBWLun = CBW_LUN;
583 pBulkCbw->dCBWDataTransferLength = 0x200*count;
584 pBulkCbw->bmCBWFlags = 0x00;
585 pBulkCbw->CBWCb[0] = 0xF0;
586 pBulkCbw->CBWCb[1] = 0x04;
587 pBulkCbw->CBWCb[7] = (BYTE)addr;
588 pBulkCbw->CBWCb[6] = (BYTE)(addr/0x0100);
589 pBulkCbw->CBWCb[5] = Media.Zone/2;
590 pBulkCbw->CBWCb[8] = *(redundant+REDT_ADDR1H);
591 pBulkCbw->CBWCb[9] = *(redundant+REDT_ADDR1L);
593 ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_WRITE, buf);
595 if (!NT_SUCCESS(ntStatus))
600 // BYTE bf[0x200], rdd[0x10];
603 // RtlZeroMemory(bf, 0x200);
604 // RtlZeroMemory(rdd, 0x10);
605 // ntStatus = SM_ReadBlock(fdoExt, bf, rdd);
606 // for (i=0; i<0x200; i++)
608 // if (buf[i] != bf[i])
609 // ENE_Print("buf[%x] = %x, bf[%x] = %x\n", buf, bf);
611 // if (!NT_SUCCESS(ntStatus))
612 // ENE_Print("Error\n");
618 ////----- Ssfdc_D_WriteSect_DMA() --------------------------------------------
619 //int Ssfdc_D_WriteSect_DMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
621 // WORD SectByteCount, addr;
625 // if (!_Hw_D_ChkCardIn())
627 // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
628 // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
629 // // cycle starting address
630 // SM_STARTADDR_LSB = 0x00;
631 // SM_STARTADDR_IISB = (BYTE)addr;
632 // SM_STARTADDR_IIISB = (BYTE)(addr/0x0100);
633 // SM_STARTADDR_MSB = Media.Zone/2;
635 // //Sector byte count (DMA)
636 // SectByteCount = 0x20f;
637 // SM_BYTECNT_LO = (BYTE)SectByteCount;
638 // SM_CMD_CTRL3 = (SM_CMD_CTRL3 & 0xFC) | 0x20 | (BYTE)(SectByteCount/0x0100);
639 // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate )
640 // SM_FIFO_CTRL = (SM_APB08_MASK | SM_DMAEN_MASK | SM_DMA_DOWNSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK);
642 // SM_FIFO_CTRL = (SM_APB32_MASK | SM_DMAEN_MASK | SM_DMA_DOWNSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK);
644 // _Hw_D_EccRdReset();
645 // _Hw_D_EccRdStart();
647 // SM_CMD_CTRL1 = SM_CMD_PAGPRGM_TRUE;
648 // SM_CMD_CTRL1 = (SM_CMD_PAGPRGM_TRUE | SM_CMD_START_BIT);
650 // SectByteCount = 0x1ff;
651 // //SM_WriteDataWithDMA(fdoExt, buf, SectByteCount);
652 // //_WriteRedt_D_SsfdcBuf(redundant);
653 // len = 0x1000 - ((WORD)(buf) & 0x0FFF);
656 // SM_WriteDataWithDMA(fdoExt, buf, len-1);
657 // SM_WriteDataWithDMA(fdoExt, buf+len, SectByteCount-len);
658 // //ENE_Print("Read DMA !!! buf1 = %p, len = %x, buf2 = %p\n", buf, len, buf+len);
661 // SM_WriteDataWithDMA(fdoExt, buf, SectByteCount);
663 // //T1 = (ULONGLONG)buf & 0xFFFFFFFFFFFFF000;
664 // //T2 = ((ULONGLONG)buf + 0x1FF) & 0xFFFFFFFFFFFFF000;
666 // // ENE_Print("Ssfdc_D_WriteSect_DMA !!! buf = %p, T1 = %p, T2 = %p\n", buf, T1, T2);
669 // // l1 = (WORD)(T2 - (ULONGLONG)buf);
670 // // SM_WriteDataWithDMA(fdoExt, buf, l1-1);
671 // // SM_WriteDataWithDMA(fdoExt, (PBYTE)T2, SectByteCount-l1);
674 // // SM_WriteDataWithDMA(fdoExt, buf, SectByteCount);
676 // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate )
678 // _WriteRedt_D_SsfdcBuf(redundant);
682 // memcpy(Buffer, redundant, 0x10);
683 // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[0]);
684 // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[1]);
685 // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[2]);
686 // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[3]);
689 // while ( _Hw_D_ChkCardIn() )
691 // if ((READ_PORT_BYTE(SM_REG_INT_STATUS) & 0x10))
693 // WRITE_PORT_BYTE(SM_REG_INT_STATUS, 0x10);
697 // _Hw_D_EccRdStop();
698 // _Hw_D_SetRdStandby();
700 // _Set_D_SsfdcWrStandby();
701 // _Set_D_SsfdcRdStandby();
702 // if (!_Hw_D_ChkCardIn())
705 // return(SMSUCCESS);
708 ////----- Ssfdc_D_WriteSect_PIO() --------------------------------------------
709 //int Ssfdc_D_WriteSect_PIO(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
711 // _Calc_D_ECCdata(buf);
712 // _Set_D_SsfdcWrCmd(WRDATA);
713 // _Set_D_SsfdcWrAddr(EVEN);
714 // _Start_D_SsfdcWrHwECC();
716 // _Write_D_SsfdcBuf(buf);
718 // _Load_D_SsfdcWrHwECC(EVEN);
719 // _Set_D_ECCdata(EVEN,redundant);
721 // _WriteRedt_D_SsfdcBuf(redundant);
723 // _Set_D_SsfdcWrCmd(WRITE);
725 // if (_Check_D_SsfdcBusy(BUSY_PROG))
726 // { _Reset_D_SsfdcErr(); return(ERROR); }
728 // _Set_D_SsfdcWrStandby();
729 // _Set_D_SsfdcRdStandby();
730 // return(SMSUCCESS);
733 //----- Ssfdc_D_WriteSectForCopy() -------------------------------------
734 int Ssfdc_D_WriteSectForCopy(struct us_data
*us
, BYTE
*buf
, BYTE
*redundant
)
736 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
738 //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
742 //printk("SMILSUB --- Ssfdc_D_WriteSectForCopy\n");
743 result
= ENE_LoadBinCode(us
, SM_RW_PATTERN
);
744 if (result
!= USB_STOR_XFER_GOOD
)
746 printk("Load SM RW Code Fail !!\n");
747 return USB_STOR_TRANSPORT_ERROR
;
751 addr
= (WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+Media
.PhyBlock
;
752 addr
= addr
*(WORD
)Ssfdc
.MaxSectors
+Media
.Sector
;
755 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
756 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
757 bcb
->DataTransferLength
= 0x200;
761 bcb
->CDB
[7] = (BYTE
)addr
;
762 bcb
->CDB
[6] = (BYTE
)(addr
/0x0100);
763 bcb
->CDB
[5] = Media
.Zone
/2;
764 bcb
->CDB
[8] = *(redundant
+REDT_ADDR1H
);
765 bcb
->CDB
[9] = *(redundant
+REDT_ADDR1L
);
767 result
= ENE_SendScsiCmd(us
, FDIR_WRITE
, buf
, 0);
768 if (result
!= USB_STOR_XFER_GOOD
)
769 return USB_STOR_TRANSPORT_ERROR
;
771 return USB_STOR_TRANSPORT_GOOD
;
775 //----- Ssfdc_D_EraseBlock() -------------------------------------------
776 int Ssfdc_D_EraseBlock(struct us_data
*us
)
778 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
782 result
= ENE_LoadBinCode(us
, SM_RW_PATTERN
);
783 if (result
!= USB_STOR_XFER_GOOD
)
785 printk("Load SM RW Code Fail !!\n");
786 return USB_STOR_TRANSPORT_ERROR
;
789 addr
=(WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+Media
.PhyBlock
;
790 addr
=addr
*(WORD
)Ssfdc
.MaxSectors
;
792 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
793 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
794 bcb
->DataTransferLength
= 0x200;
798 bcb
->CDB
[7] = (BYTE
)addr
;
799 bcb
->CDB
[6] = (BYTE
)(addr
/0x0100);
800 bcb
->CDB
[5] = Media
.Zone
/2;
802 result
= ENE_SendScsiCmd(us
, FDIR_READ
, NULL
, 0);
803 if (result
!= USB_STOR_XFER_GOOD
)
804 return USB_STOR_TRANSPORT_ERROR
;
806 return USB_STOR_TRANSPORT_GOOD
;
810 //----- Ssfdc_D_ReadRedtData() -----------------------------------------
811 int Ssfdc_D_ReadRedtData(struct us_data
*us
, BYTE
*redundant
)
813 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
818 result
= ENE_LoadBinCode(us
, SM_RW_PATTERN
);
819 if (result
!= USB_STOR_XFER_GOOD
)
821 printk("Load SM RW Code Fail !!\n");
822 return USB_STOR_TRANSPORT_ERROR
;
825 addr
= (WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+Media
.PhyBlock
;
826 addr
= addr
*(WORD
)Ssfdc
.MaxSectors
+Media
.Sector
;
828 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
829 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
830 bcb
->DataTransferLength
= 0x10;
834 bcb
->CDB
[4] = (BYTE
)addr
;
835 bcb
->CDB
[3] = (BYTE
)(addr
/0x0100);
836 bcb
->CDB
[2] = Media
.Zone
/2;
840 buf
= kmalloc(0x10, GFP_KERNEL
);
841 //result = ENE_SendScsiCmd(us, FDIR_READ, redundant, 0);
842 result
= ENE_SendScsiCmd(us
, FDIR_READ
, buf
, 0);
843 memcpy(redundant
, buf
, 0x10);
845 if (result
!= USB_STOR_XFER_GOOD
)
846 return USB_STOR_TRANSPORT_ERROR
;
848 return USB_STOR_TRANSPORT_GOOD
;
852 //----- Ssfdc_D_WriteRedtData() ----------------------------------------
853 int Ssfdc_D_WriteRedtData(struct us_data
*us
, BYTE
*redundant
)
855 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
857 //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
861 result
= ENE_LoadBinCode(us
, SM_RW_PATTERN
);
862 if (result
!= USB_STOR_XFER_GOOD
)
864 printk("Load SM RW Code Fail !!\n");
865 return USB_STOR_TRANSPORT_ERROR
;
868 addr
= (WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+Media
.PhyBlock
;
869 addr
= addr
*(WORD
)Ssfdc
.MaxSectors
+Media
.Sector
;
871 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
872 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
873 bcb
->DataTransferLength
= 0x10;
877 bcb
->CDB
[7] = (BYTE
)addr
;
878 bcb
->CDB
[6] = (BYTE
)(addr
/0x0100);
879 bcb
->CDB
[5] = Media
.Zone
/2;
880 bcb
->CDB
[8] = *(redundant
+REDT_ADDR1H
);
881 bcb
->CDB
[9] = *(redundant
+REDT_ADDR1L
);
883 result
= ENE_SendScsiCmd(us
, FDIR_READ
, NULL
, 0);
884 if (result
!= USB_STOR_XFER_GOOD
)
885 return USB_STOR_TRANSPORT_ERROR
;
887 return USB_STOR_TRANSPORT_GOOD
;
890 //----- Ssfdc_D_CheckStatus() ------------------------------------------
891 int Ssfdc_D_CheckStatus(void)
895 //_Set_D_SsfdcRdCmd(RDSTATUS);
897 //if (_Check_D_SsfdcStatus())
898 //{ _Set_D_SsfdcRdStandby(); return(ERROR); }
900 //_Set_D_SsfdcRdStandby();
904 ////NAND Memory (SmartMedia) Control Subroutine for Read Data
905 ////----- _Set_D_SsfdcRdCmd() --------------------------------------------
906 //void _Set_D_SsfdcRdCmd(BYTE cmd)
909 // _Hw_D_OutData(cmd);
910 // _Hw_D_SetRdData();
913 ////----- _Set_D_SsfdcRdAddr() -------------------------------------------
914 //void _Set_D_SsfdcRdAddr(BYTE add)
917 // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
918 // ADDRESS_T bb = (ADDRESS_T) &Media;
920 // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
921 // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
923 // //if ((Ssfdc.Attribute &MPS)==PS256) // for 256byte/page
924 // // addr=addr*2+(WORD)add;
926 // _Hw_D_SetRdAddr();
927 // _Hw_D_OutData(0x00);
928 // _Hw_D_OutData((BYTE)addr);
929 // _Hw_D_OutData((BYTE)(addr/0x0100));
931 // if ((Ssfdc.Attribute &MADC)==AD4CYC)
932 // _Hw_D_OutData((BYTE)(Media.Zone/2)); // Patch
934 // _Hw_D_SetRdData();
937 ////----- _Set_D_SsfdcRdChip() -------------------------------------------
938 //void _Set_D_SsfdcRdChip(void)
940 // _Hw_D_SetRdAddr();
941 // _Hw_D_OutData(0x00);
942 // _Hw_D_SetRdData();
945 ////----- _Set_D_SsfdcRdStandby() ----------------------------------------
946 //void _Set_D_SsfdcRdStandby(void)
948 // _Hw_D_SetRdStandby();
951 ////----- _Start_D_SsfdcRdHwECC() ----------------------------------------
952 //void _Start_D_SsfdcRdHwECC(void)
954 //#ifdef HW_ECC_SUPPORTED
955 // _Hw_D_EccRdReset();
957 // _Hw_D_EccRdStart();
961 ////----- _Stop_D_SsfdcRdHwECC() -----------------------------------------
962 //void _Stop_D_SsfdcRdHwECC(void)
964 //#ifdef HW_ECC_SUPPORTED
965 // _Hw_D_EccRdStop();
969 ////----- _Load_D_SsfdcRdHwECC() -----------------------------------------
970 //void _Load_D_SsfdcRdHwECC(BYTE add)
972 //#ifdef HW_ECC_SUPPORTED
973 // _Hw_D_EccRdRead();
974 // //if (!(add==ODD && (Ssfdc.Attribute &MPS)==PS256))
976 // EccBuf[0]=_Hw_D_InData();
977 // EccBuf[1]=_Hw_D_InData();
978 // EccBuf[2]=_Hw_D_InData();
981 // //if (!(add==EVEN && (Ssfdc.Attribute &MPS)==PS256))
983 // EccBuf[3]=_Hw_D_InData();
984 // EccBuf[4]=_Hw_D_InData();
985 // EccBuf[5]=_Hw_D_InData();
988 // _Hw_D_EccRdStop();
992 ////NAND Memory (SmartMedia) Control Subroutine for Write Data
994 ////----- _Set_D_SsfdcWrCmd() -----------------------------------------
995 //void _Set_D_SsfdcWrCmd(BYTE cmd)
998 // _Hw_D_OutData(cmd);
999 // _Hw_D_SetWrData();
1002 ////----- _Set_D_SsfdcWrAddr() -----------------------------------------
1003 //void _Set_D_SsfdcWrAddr(BYTE add)
1006 // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1007 // ADDRESS_T bb = (ADDRESS_T) &Media;
1009 // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
1010 // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
1012 // //if ((Ssfdc.Attribute &MPS)==PS256) // for 256byte/page
1013 // // addr=addr*2+(WORD)add;
1015 // _Hw_D_SetWrAddr();
1016 // _Hw_D_OutData(0x00);
1017 // _Hw_D_OutData((BYTE)addr);
1018 // _Hw_D_OutData((BYTE)(addr/0x0100));
1020 // if ((Ssfdc.Attribute &MADC)==AD4CYC)
1021 // _Hw_D_OutData((BYTE)(Media.Zone/2)); // Patch
1023 // _Hw_D_SetWrData();
1026 ////----- _Set_D_SsfdcWrBlock() -----------------------------------------
1027 //void _Set_D_SsfdcWrBlock(void)
1030 // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1031 // ADDRESS_T bb = (ADDRESS_T) &Media;
1033 // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
1034 // addr=addr*(WORD)Ssfdc.MaxSectors;
1036 // //if ((Ssfdc.Attribute &MPS)==PS256) // for 256byte/page
1039 // _Hw_D_SetWrAddr();
1040 // _Hw_D_OutData((BYTE)addr);
1041 // _Hw_D_OutData((BYTE)(addr/0x0100));
1043 // if ((Ssfdc.Attribute &MADC)==AD4CYC)
1044 // _Hw_D_OutData((BYTE)(Media.Zone/2)); // Patch
1046 // _Hw_D_SetWrData();
1049 ////----- _Set_D_SsfdcWrStandby() -----------------------------------------
1050 //void _Set_D_SsfdcWrStandby(void)
1052 // _Hw_D_SetWrStandby();
1055 ////----- _Start_D_SsfdcWrHwECC() -----------------------------------------
1056 //void _Start_D_SsfdcWrHwECC(void)
1058 //#ifdef HW_ECC_SUPPORTED
1059 // _Hw_D_EccWrReset();
1061 // _Hw_D_EccWrStart();
1065 ////----- _Load_D_SsfdcWrHwECC() -----------------------------------------
1066 //void _Load_D_SsfdcWrHwECC(BYTE add)
1068 //#ifdef HW_ECC_SUPPORTED
1069 // _Hw_D_EccWrRead();
1070 // //if (!(add==ODD && (Ssfdc.Attribute &MPS)==PS256))
1072 // EccBuf[0]=_Hw_D_InData();
1073 // EccBuf[1]=_Hw_D_InData();
1074 // EccBuf[2]=_Hw_D_InData();
1077 // //if (!(add==EVEN && (Ssfdc.Attribute &MPS)==PS256))
1079 // EccBuf[3]=_Hw_D_InData();
1080 // EccBuf[4]=_Hw_D_InData();
1081 // EccBuf[5]=_Hw_D_InData();
1084 // _Hw_D_EccWrStop();
1088 ////NAND Memory (SmartMedia) Control Subroutine
1089 ////----- _Check_D_SsfdcBusy() -------------------------------------------
1090 //int _Check_D_SsfdcBusy(WORD time)
1095 // if (!_Hw_D_ChkBusy())
1096 // return(SMSUCCESS);
1099 // } while (count<=time);
1104 ////----- _Check_D_SsfdcStatus() -----------------------------------------
1105 //int _Check_D_SsfdcStatus(void)
1107 // if (_Hw_D_InData() & WR_FAIL)
1110 // return(SMSUCCESS);
1114 ////----- _Reset_D_SsfdcErr() -----------------------------------------
1115 //void _Reset_D_SsfdcErr(void)
1119 // _Hw_D_SetRdCmd();
1120 // _Hw_D_OutData(RST_CHIP);
1121 // _Hw_D_SetRdData();
1124 // if (!_Hw_D_ChkBusy())
1128 // } while (count<=BUSY_RESET);
1130 // _Hw_D_SetRdStandby();
1133 ////NAND Memory (SmartMedia) Buffer Data Xfer Subroutine
1134 ////----- SM_ReadDataWithDMA() -----------------------------------------
1135 //void SM_ReadDataWithDMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *databuf, WORD SectByteCount)
1137 // PHYSICAL_ADDRESS Addr;
1138 // LARGE_INTEGER ptimeout ;
1140 // KeClearEvent(&fdoExt->SM_DMADoneEvent);
1142 // Addr = MmGetPhysicalAddress(databuf);
1144 // WRITE_PORT_DWORD(SM_DMA_ADDR_REG, (DWORD)Addr.LowPart);
1145 // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 0);
1146 // WRITE_PORT_WORD(SM_DMA_BYTE_COUNT_REG, SectByteCount);
1148 // while ( _Hw_D_ChkCardIn() )
1150 // if ((READ_PORT_BYTE(SM_REG_FIFO_STATUS) & 0x80))
1153 // if (!_Hw_D_ChkCardIn()) return;
1154 // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 0x01);
1156 // ptimeout.QuadPart = 2000 * (-10000); // 2 sec
1157 // KeWaitForSingleObject(&fdoExt->SM_DMADoneEvent, Executive, KernelMode, FALSE, &ptimeout);
1158 // _Hw_D_SetDMAIntMask();
1161 ////----- SM_WriteDataWithDMA() -----------------------------------------
1162 //void SM_WriteDataWithDMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *databuf, WORD SectByteCount)
1164 // PHYSICAL_ADDRESS Addr;
1165 // LARGE_INTEGER ptimeout ;
1167 // KeClearEvent(&fdoExt->SM_DMADoneEvent);
1169 // Addr = MmGetPhysicalAddress(databuf);
1171 // WRITE_PORT_DWORD(SM_DMA_ADDR_REG, (DWORD)Addr.LowPart);
1172 // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 2);
1173 // WRITE_PORT_WORD(SM_DMA_BYTE_COUNT_REG, SectByteCount);
1175 // while ( _Hw_D_ChkCardIn() )
1177 // if ((READ_PORT_BYTE(SM_REG_FIFO_STATUS) & 0x40))
1180 // if (!_Hw_D_ChkCardIn()) return;
1181 // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 0x03);
1183 // ptimeout.QuadPart = 2000 * (-10000); // 2 sec
1184 // KeWaitForSingleObject(&fdoExt->SM_DMADoneEvent, Executive, KernelMode, FALSE, &ptimeout);
1185 // _Hw_D_SetDMAIntMask();
1188 ////----- _Read_D_SsfdcBuf() -----------------------------------------
1189 //void _Read_D_SsfdcBuf(BYTE *databuf)
1193 // //for(i=0x0000;i<(((Ssfdc.Attribute &MPS)==PS256)?0x0100:0x0200);i++)
1194 // for(i=0; i<0x200; i++)
1195 // *databuf++ =_Hw_D_InData();
1198 ////----- _Write_D_SsfdcBuf() -----------------------------------------
1199 //void _Write_D_SsfdcBuf(BYTE *databuf)
1203 // //for(i=0x0000;i<(((Ssfdc.Attribute &MPS)==PS256)?0x0100:0x0200);i++)
1204 // for(i=0; i<0x200; i++)
1205 // _Hw_D_OutData(*databuf++);
1208 ////----- _Read_D_SsfdcByte() -----------------------------------------
1209 //void _Read_D_SsfdcByte(BYTE *databuf)
1211 // *databuf=(BYTE)_Hw_D_InData();
1214 ////----- _ReadRedt_D_SsfdcBuf() -----------------------------------------
1215 //void _ReadRedt_D_SsfdcBuf(BYTE *redundant)
1219 // //for(i=0x00;i<(((Ssfdc.Attribute &MPS)==PS256)?0x08:0x10);i++)
1220 // for(i=0; i<0x10; i++)
1221 // redundant[i] =_Hw_D_InData();
1224 ////----- _WriteRedt_D_SsfdcBuf() -----------------------------------------
1225 //void _WriteRedt_D_SsfdcBuf(BYTE *redundant)
1229 // //for(i=0x00;i<(((Ssfdc.Attribute &MPS)==PS256)?0x08:0x10);i++)
1230 // for(i=0; i<0x10; i++)
1231 // _Hw_D_OutData(*redundant++);
1234 //SmartMedia ID Code Check & Mode Set Subroutine
1235 //----- Set_D_SsfdcModel() ---------------------------------------------
1236 int Set_D_SsfdcModel(BYTE dcode
)
1238 switch (_Check_D_DevCode(dcode
)) {
1240 Ssfdc
.Model
= SSFDC1MB
;
1241 Ssfdc
.Attribute
= FLASH
| AD3CYC
| BS16
| PS256
;
1243 Ssfdc
.MaxBlocks
= 256;
1244 Ssfdc
.MaxLogBlocks
= 250;
1245 Ssfdc
.MaxSectors
= 8;
1248 Ssfdc
.Model
= SSFDC2MB
;
1249 Ssfdc
.Attribute
= FLASH
| AD3CYC
| BS16
| PS256
;
1251 Ssfdc
.MaxBlocks
= 512;
1252 Ssfdc
.MaxLogBlocks
= 500;
1253 Ssfdc
.MaxSectors
= 8;
1256 Ssfdc
.Model
= SSFDC4MB
;
1257 Ssfdc
.Attribute
= FLASH
| AD3CYC
| BS16
| PS512
;
1259 Ssfdc
.MaxBlocks
= 512;
1260 Ssfdc
.MaxLogBlocks
= 500;
1261 Ssfdc
.MaxSectors
= 16;
1264 Ssfdc
.Model
= SSFDC8MB
;
1265 Ssfdc
.Attribute
= FLASH
| AD3CYC
| BS16
| PS512
;
1267 Ssfdc
.MaxBlocks
= 1024;
1268 Ssfdc
.MaxLogBlocks
= 1000;
1269 Ssfdc
.MaxSectors
= 16;
1272 Ssfdc
.Model
= SSFDC16MB
;
1273 Ssfdc
.Attribute
= FLASH
| AD3CYC
| BS32
| PS512
;
1275 Ssfdc
.MaxBlocks
= 1024;
1276 Ssfdc
.MaxLogBlocks
= 1000;
1277 Ssfdc
.MaxSectors
= 32;
1280 Ssfdc
.Model
= SSFDC32MB
;
1281 Ssfdc
.Attribute
= FLASH
| AD3CYC
| BS32
| PS512
;
1283 Ssfdc
.MaxBlocks
= 1024;
1284 Ssfdc
.MaxLogBlocks
= 1000;
1285 Ssfdc
.MaxSectors
= 32;
1288 Ssfdc
.Model
= SSFDC64MB
;
1289 Ssfdc
.Attribute
= FLASH
| AD4CYC
| BS32
| PS512
;
1291 Ssfdc
.MaxBlocks
= 1024;
1292 Ssfdc
.MaxLogBlocks
= 1000;
1293 Ssfdc
.MaxSectors
= 32;
1296 Ssfdc
.Model
= SSFDC128MB
;
1297 Ssfdc
.Attribute
= FLASH
| AD4CYC
| BS32
| PS512
;
1299 Ssfdc
.MaxBlocks
= 1024;
1300 Ssfdc
.MaxLogBlocks
= 1000;
1301 Ssfdc
.MaxSectors
= 32;
1304 Ssfdc
.Model
= SSFDC256MB
;
1305 Ssfdc
.Attribute
= FLASH
| AD4CYC
| BS32
| PS512
;
1306 Ssfdc
.MaxZones
= 16;
1307 Ssfdc
.MaxBlocks
= 1024;
1308 Ssfdc
.MaxLogBlocks
= 1000;
1309 Ssfdc
.MaxSectors
= 32;
1312 Ssfdc
.Model
= SSFDC512MB
;
1313 Ssfdc
.Attribute
= FLASH
| AD4CYC
| BS32
| PS512
;
1314 Ssfdc
.MaxZones
= 32;
1315 Ssfdc
.MaxBlocks
= 1024;
1316 Ssfdc
.MaxLogBlocks
= 1000;
1317 Ssfdc
.MaxSectors
= 32;
1320 Ssfdc
.Model
= SSFDC1GB
;
1321 Ssfdc
.Attribute
= FLASH
| AD4CYC
| BS32
| PS512
;
1322 Ssfdc
.MaxZones
= 64;
1323 Ssfdc
.MaxBlocks
= 1024;
1324 Ssfdc
.MaxLogBlocks
= 1000;
1325 Ssfdc
.MaxSectors
= 32;
1328 Ssfdc
.Model
= SSFDC2GB
;
1329 Ssfdc
.Attribute
= FLASH
| AD4CYC
| BS32
| PS512
;
1330 Ssfdc
.MaxZones
= 128;
1331 Ssfdc
.MaxBlocks
= 1024;
1332 Ssfdc
.MaxLogBlocks
= 1000;
1333 Ssfdc
.MaxSectors
= 32;
1336 Ssfdc
.Model
= NOSSFDC
;
1343 //----- _Check_D_DevCode() ---------------------------------------------
1344 BYTE
_Check_D_DevCode(BYTE dcode
)
1349 case 0xEC: return(SSFDC1MB
); // 8Mbit (1M) NAND
1351 case 0xEA: return(SSFDC2MB
); // 16Mbit (2M) NAND
1354 case 0xE5: return(SSFDC4MB
); // 32Mbit (4M) NAND
1355 case 0xE6: return(SSFDC8MB
); // 64Mbit (8M) NAND
1356 case 0x73: return(SSFDC16MB
); // 128Mbit (16M)NAND
1357 case 0x75: return(SSFDC32MB
); // 256Mbit (32M)NAND
1358 case 0x76: return(SSFDC64MB
); // 512Mbit (64M)NAND
1359 case 0x79: return(SSFDC128MB
); // 1Gbit(128M)NAND
1360 case 0x71: return(SSFDC256MB
);
1361 case 0xDC: return(SSFDC512MB
);
1362 case 0xD3: return(SSFDC1GB
);
1363 case 0xD5: return(SSFDC2GB
);
1364 default: return(NOSSFDC
);
1368 ////SmartMedia Power Control Subroutine
1369 ////----- Cnt_D_Reset() ----------------------------------------------
1370 //void Cnt_D_Reset(void)
1373 // _Hw_D_SetRdStandby();
1377 ////----- Cnt_D_PowerOn() ----------------------------------------------
1378 //int Cnt_D_PowerOn(void)
1380 // // No support 5V.
1381 // _Hw_D_EnableVcc3VOn(); // Set SM_REG_CTRL_5 Reg. to 3V
1383 // _Hw_D_SetRdStandby();
1384 // _Wait_D_Timer(TIME_PON);
1386 // if (_Hw_D_ChkPower())
1388 // _Hw_D_EnableOB(); // Set SM_REG_CTRL_5 Reg. to 0x83
1389 // return(SMSUCCESS);
1392 // _Hw_D_SetVccOff();
1396 ////----- Cnt_D_PowerOff() ----------------------------------------------
1397 //void Cnt_D_PowerOff(void)
1399 // _Hw_D_SetRdStandby();
1400 // _Hw_D_SetVccOff();
1404 ////----- Cnt_D_LedOn() ----------------------------------------------
1405 //void Cnt_D_LedOn(void)
1410 ////----- Cnt_D_LedOff() ----------------------------------------------
1411 //void Cnt_D_LedOff(void)
1416 ////----- Check_D_CntPower() ----------------------------------------------
1417 //int Check_D_CntPower(void)
1419 // if (_Hw_D_ChkPower())
1420 // return(SMSUCCESS); // Power On
1422 // return(ERROR); // Power Off
1425 ////----- Check_D_CardExist() ----------------------------------------------
1426 //int Check_D_CardExist(void)
1430 // if (!_Hw_D_ChkStatus()) // Not Status Change
1431 // if (_Hw_D_ChkCardIn())
1432 // return(SMSUCCESS); // Card exist in Slot
1434 // for(i=0,j=0,k=0; i<16; i++) {
1435 // if (_Hw_D_ChkCardIn()) // Status Change
1445 // return(SMSUCCESS); // Card exist in Slot
1447 // return(ERROR); // NO Card exist in Slot
1449 // _Wait_D_Timer(TIME_CDCHK);
1455 ////----- Check_D_CardStsChg() ----------------------------------------------
1456 //int Check_D_CardStsChg(void)
1458 // if (_Hw_D_ChkStatus())
1459 // return(ERROR); // Status Change
1461 // return(SMSUCCESS); // Not Status Change
1464 ////----- Check_D_SsfdcWP() ----------------------------------------------
1465 //int Check_D_SsfdcWP(void)
1466 //{ // ERROR: WP, SMSUCCESS: Not WP
1469 // for(i=0; i<8; i++) {
1470 // if (_Hw_D_ChkWP())
1472 // _Wait_D_Timer(TIME_WPCHK);
1475 // return(SMSUCCESS);
1479 //SmartMedia ECC Control Subroutine
1480 //----- Check_D_ReadError() ----------------------------------------------
1481 int Check_D_ReadError(BYTE
*redundant
)
1486 //----- Check_D_Correct() ----------------------------------------------
1487 int Check_D_Correct(BYTE
*buf
,BYTE
*redundant
)
1492 //----- Check_D_CISdata() ----------------------------------------------
1493 int Check_D_CISdata(BYTE
*buf
, BYTE
*redundant
)
1495 BYTE cis
[] = {0x01, 0x03, 0xD9, 0x01, 0xFF, 0x18, 0x02,
1498 int cis_len
= sizeof(cis
);
1500 if (!IsSSFDCCompliance
&& !IsXDCompliance
)
1503 if (!memcmp(redundant
+ 0x0D, EccBuf
, 3))
1504 return memcmp(buf
, cis
, cis_len
);
1506 if (!_Correct_D_SwECC(buf
, redundant
+ 0x0D, EccBuf
))
1507 return memcmp(buf
, cis
, cis_len
);
1510 if (!memcmp(redundant
+ 0x08, EccBuf
+ 0x03, 3))
1511 return memcmp(buf
, cis
, cis_len
);
1513 if (!_Correct_D_SwECC(buf
, redundant
+ 0x08, EccBuf
+ 0x03))
1514 return memcmp(buf
, cis
, cis_len
);
1519 //----- Set_D_RightECC() ----------------------------------------------
1520 void Set_D_RightECC(BYTE
*redundant
)
1522 // Driver ¤£°µ ECC Check
1524 //StringCopy((char *)(redundant+0x0D),(char *)EccBuf,3);
1525 //StringCopy((char *)(redundant+0x08),(char *)(EccBuf+0x03),3);
1528 ////----- _Calc_D_ECCdata() ----------------------------------------------
1529 //void _Calc_D_ECCdata(BYTE *buf)
1531 //#ifdef HW_ECC_SUPPORTED
1533 // _Calculate_D_SwECC(buf,EccBuf);
1535 // _Calculate_D_SwECC(buf,EccBuf+0x03);
1539 ////----- _Set_D_ECCdata() ----------------------------------------------
1540 //void _Set_D_ECCdata(BYTE add,BYTE *redundant)
1542 // //if (add==EVEN && (Ssfdc.Attribute &MPS)==PS256)
1545 // // for 256byte/page
1546 // StringCopy((char *)(redundant+0x0D),(char *)EccBuf,3);
1547 // StringCopy((char *)(redundant+0x08),(char *)(EccBuf+0x03),3);
1552 //----- SM_ReadBlock() ---------------------------------------------
1553 int SM_ReadBlock(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
1555 PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
1559 ENE_LoadBinCode(fdoExt, SM_RW_PATTERN);
1561 addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
1562 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
1565 RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
1566 pBulkCbw->dCBWSignature = CBW_SIGNTURE;
1567 pBulkCbw->bCBWLun = CBW_LUN;
1568 pBulkCbw->dCBWDataTransferLength = 0x200;
1569 pBulkCbw->bmCBWFlags = 0x80;
1570 pBulkCbw->CBWCb[0] = 0xF1;
1571 pBulkCbw->CBWCb[1] = 0x02;
1572 pBulkCbw->CBWCb[4] = (BYTE)addr;
1573 pBulkCbw->CBWCb[3] = (BYTE)(addr/0x0100);
1574 pBulkCbw->CBWCb[2] = Media.Zone/2;
1576 ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_READ, buf);
1578 if (!NT_SUCCESS(ntStatus))
1582 RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
1583 pBulkCbw->dCBWSignature = CBW_SIGNTURE;
1584 pBulkCbw->bCBWLun = CBW_LUN;
1585 pBulkCbw->dCBWDataTransferLength = 0x10;
1586 pBulkCbw->bmCBWFlags = 0x80;
1587 pBulkCbw->CBWCb[0] = 0xF1;
1588 pBulkCbw->CBWCb[1] = 0x03;
1589 pBulkCbw->CBWCb[4] = (BYTE)addr;
1590 pBulkCbw->CBWCb[3] = (BYTE)(addr/0x0100);
1591 pBulkCbw->CBWCb[2] = Media.Zone/2;
1592 pBulkCbw->CBWCb[5] = 0;
1593 pBulkCbw->CBWCb[6] = 1;
1595 ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_READ, redundant);
1597 if (!NT_SUCCESS(ntStatus))