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
;
46 extern PBYTE SMHostAddr
;
47 extern BYTE IsSSFDCCompliance
;
48 extern BYTE IsXDCompliance
;
49 extern DWORD ErrXDCode
;
51 extern WORD ReadBlock
;
52 extern WORD WriteBlock
;
54 //KEVENT SM_DMADoneEvent;
56 #define EVEN 0 // Even Page for 256byte/page
57 #define ODD 1 // Odd Page for 256byte/page
60 //SmartMedia Redundant buffer data Controll Subroutine
61 //----- Check_D_DataBlank() --------------------------------------------
62 int Check_D_DataBlank(BYTE
*redundant
)
66 for(i
=0; i
<REDTSIZE
; i
++)
67 if (*redundant
++!=0xFF)
73 //----- Check_D_FailBlock() --------------------------------------------
74 int Check_D_FailBlock(BYTE
*redundant
)
76 redundant
+=REDT_BLOCK
;
82 if (Bit_D_Count(*redundant
)<7)
88 //----- Check_D_DataStatus() -------------------------------------------
89 int Check_D_DataStatus(BYTE
*redundant
)
97 ErrXDCode
= ERR_DataStatus
;
101 ErrXDCode
= NO_ERROR
;
103 if (Bit_D_Count(*redundant
)<5)
109 //----- Load_D_LogBlockAddr() ------------------------------------------
110 int Load_D_LogBlockAddr(BYTE
*redundant
)
113 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
114 //ADDRESS_T bb = (ADDRESS_T) &Media;
116 addr1
=(WORD
)*(redundant
+REDT_ADDR1H
)*0x0100+(WORD
)*(redundant
+REDT_ADDR1L
);
117 addr2
=(WORD
)*(redundant
+REDT_ADDR2H
)*0x0100+(WORD
)*(redundant
+REDT_ADDR2L
);
120 if ((addr1
&0xF000)==0x1000)
121 { Media
.LogBlock
=(addr1
&0x0FFF)/2; return(SUCCESS
); }
123 if (Bit_D_CountWord((WORD
)(addr1
^addr2
))!=0x01) return(ERROR
);
125 if ((addr1
&0xF000)==0x1000)
126 if (!(Bit_D_CountWord(addr1
) &0x01))
127 { Media
.LogBlock
=(addr1
&0x0FFF)/2; return(SUCCESS
); }
129 if ((addr2
&0xF000)==0x1000)
130 if (!(Bit_D_CountWord(addr2
) &0x01))
131 { Media
.LogBlock
=(addr2
&0x0FFF)/2; return(SUCCESS
); }
136 //----- Clr_D_RedundantData() ------------------------------------------
137 void Clr_D_RedundantData(BYTE
*redundant
)
141 for(i
=0; i
<REDTSIZE
; i
++)
145 //----- Set_D_LogBlockAddr() -------------------------------------------
146 void Set_D_LogBlockAddr(BYTE
*redundant
)
150 *(redundant
+REDT_BLOCK
)=0xFF;
151 *(redundant
+REDT_DATA
) =0xFF;
152 addr
=Media
.LogBlock
*2+0x1000;
154 if ((Bit_D_CountWord(addr
)%2))
157 *(redundant
+REDT_ADDR1H
)=*(redundant
+REDT_ADDR2H
)=(BYTE
)(addr
/0x0100);
158 *(redundant
+REDT_ADDR1L
)=*(redundant
+REDT_ADDR2L
)=(BYTE
)addr
;
161 //----- Set_D_FailBlock() ----------------------------------------------
162 void Set_D_FailBlock(BYTE
*redundant
)
166 for(i
=0; i
<REDTSIZE
; i
++)
167 *redundant
++=(BYTE
)((i
==REDT_BLOCK
)?0xF0:0xFF);
170 //----- Set_D_DataStaus() ----------------------------------------------
171 void Set_D_DataStaus(BYTE
*redundant
)
173 redundant
+=REDT_DATA
;
177 //SmartMedia Function Command Subroutine
179 //----- Ssfdc_D_Reset() ------------------------------------------------
180 void Ssfdc_D_Reset(struct us_data
*us
)
182 //NTSTATUS ntStatus = STATUS_SUCCESS;
183 //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
186 //printk("Ssfdc_D_Reset --- But do nothing !!\n");
188 /* RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
189 pBulkCbw->dCBWSignature = CBW_SIGNTURE;
190 pBulkCbw->bCBWLun = CBW_LUN;
191 //pBulkCbw->dCBWDataTransferLength = 0x200;
192 pBulkCbw->bmCBWFlags = 0x80;
193 pBulkCbw->CBWCb[0] = 0xF2;
194 pBulkCbw->CBWCb[1] = 0x07;
196 ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_READ, NULL);
198 if (!NT_SUCCESS(ntStatus))
200 ENE_Print("Ssfdc_D_Reset Fail !!\n");
205 //----- Ssfdc_D_ReadCisSect() ------------------------------------------
206 int Ssfdc_D_ReadCisSect(struct us_data
*us
, BYTE
*buf
,BYTE
*redundant
)
210 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
211 //ADDRESS_T bb = (ADDRESS_T) &Media;
213 zone
=Media
.Zone
; block
=Media
.PhyBlock
; sector
=Media
.Sector
;
215 Media
.PhyBlock
=CisArea
.PhyBlock
;
216 Media
.Sector
=CisArea
.Sector
;
218 if (Ssfdc_D_ReadSect(us
,buf
,redundant
))
220 Media
.Zone
=zone
; Media
.PhyBlock
=block
; Media
.Sector
=sector
;
224 Media
.Zone
=zone
; Media
.PhyBlock
=block
; Media
.Sector
=sector
;
228 ////----- Ssfdc_D_WriteRedtMode() ----------------------------------------
229 //void Ssfdc_D_WriteRedtMode(void)
231 // _Set_D_SsfdcRdCmd (RST_CHIP);
232 // _Check_D_SsfdcBusy (BUSY_RESET);
233 // _Set_D_SsfdcRdCmd (READ_REDT);
234 // _Check_D_SsfdcBusy (BUSY_READ);
235 // _Set_D_SsfdcRdStandby ();
238 ////----- Ssfdc_D_ReadID() -----------------------------------------------
239 //void Ssfdc_D_ReadID(BYTE *buf, BYTE ReadID)
241 // _Set_D_SsfdcRdCmd (ReadID);
242 // _Set_D_SsfdcRdChip ();
243 // _Read_D_SsfdcByte (buf++);
244 // _Read_D_SsfdcByte (buf++);
245 // _Read_D_SsfdcByte (buf++);
246 // _Read_D_SsfdcByte (buf);
247 // _Set_D_SsfdcRdStandby ();
251 //----- Ssfdc_D_ReadSect() ---------------------------------------------
252 int Ssfdc_D_ReadSect(struct us_data
*us
, BYTE
*buf
,BYTE
*redundant
)
254 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
258 result
= ENE_LoadBinCode(us
, SM_RW_PATTERN
);
259 if (result
!= USB_STOR_XFER_GOOD
)
261 printk("Load SM RW Code Fail !!\n");
262 return USB_STOR_TRANSPORT_ERROR
;
265 addr
= (WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+Media
.PhyBlock
;
266 addr
= addr
*(WORD
)Ssfdc
.MaxSectors
+Media
.Sector
;
269 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
270 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
271 bcb
->DataTransferLength
= 0x200;
275 bcb
->CDB
[4] = (BYTE
)addr
;
276 bcb
->CDB
[3] = (BYTE
)(addr
/0x0100);
277 bcb
->CDB
[2] = Media
.Zone
/2;
279 result
= ENE_SendScsiCmd(us
, FDIR_READ
, buf
, 0);
280 if (result
!= USB_STOR_XFER_GOOD
)
281 return USB_STOR_TRANSPORT_ERROR
;
284 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
285 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
286 bcb
->DataTransferLength
= 0x10;
290 bcb
->CDB
[4] = (BYTE
)addr
;
291 bcb
->CDB
[3] = (BYTE
)(addr
/0x0100);
292 bcb
->CDB
[2] = Media
.Zone
/2;
296 result
= ENE_SendScsiCmd(us
, FDIR_READ
, redundant
, 0);
297 if (result
!= USB_STOR_XFER_GOOD
)
298 return USB_STOR_TRANSPORT_ERROR
;
300 return USB_STOR_TRANSPORT_GOOD
;
303 //----- Ssfdc_D_ReadBlock() ---------------------------------------------
304 int Ssfdc_D_ReadBlock(struct us_data
*us
, WORD count
, BYTE
*buf
,BYTE
*redundant
)
306 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
310 //printk("Ssfdc_D_ReadBlock\n");
311 result
= ENE_LoadBinCode(us
, SM_RW_PATTERN
);
312 if (result
!= USB_STOR_XFER_GOOD
)
314 printk("Load SM RW Code Fail !!\n");
315 return USB_STOR_TRANSPORT_ERROR
;
318 addr
= (WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+Media
.PhyBlock
;
319 addr
= addr
*(WORD
)Ssfdc
.MaxSectors
+Media
.Sector
;
322 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
323 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
324 bcb
->DataTransferLength
= 0x200*count
;
328 bcb
->CDB
[4] = (BYTE
)addr
;
329 bcb
->CDB
[3] = (BYTE
)(addr
/0x0100);
330 bcb
->CDB
[2] = Media
.Zone
/2;
332 result
= ENE_SendScsiCmd(us
, FDIR_READ
, buf
, 0);
333 if (result
!= USB_STOR_XFER_GOOD
)
334 return USB_STOR_TRANSPORT_ERROR
;
337 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
338 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
339 bcb
->DataTransferLength
= 0x10;
343 bcb
->CDB
[4] = (BYTE
)addr
;
344 bcb
->CDB
[3] = (BYTE
)(addr
/0x0100);
345 bcb
->CDB
[2] = Media
.Zone
/2;
349 result
= ENE_SendScsiCmd(us
, FDIR_READ
, redundant
, 0);
350 if (result
!= USB_STOR_XFER_GOOD
)
351 return USB_STOR_TRANSPORT_ERROR
;
353 return USB_STOR_TRANSPORT_GOOD
;
356 ////----- Ssfdc_D_ReadSect_DMA() ---------------------------------------------
357 //int Ssfdc_D_ReadSect_DMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
359 // WORD SectByteCount, addr;
363 // if (!_Hw_D_ChkCardIn())
365 // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
366 // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
367 // // cycle starting address
368 // SM_STARTADDR_LSB = 0x00;
369 // SM_STARTADDR_IISB = (BYTE)addr;
370 // SM_STARTADDR_IIISB = (BYTE)(addr/0x0100);
371 // SM_STARTADDR_MSB = Media.Zone/2;
373 // //Sector byte count = 0x200(DMA)
374 // SectByteCount = 0x20f;
375 // SM_BYTECNT_LO = (BYTE)SectByteCount;
376 // SM_CMD_CTRL3 = (SM_CMD_CTRL3 & 0xFC) | (BYTE)(SectByteCount/0x0100);
377 // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate )
378 // SM_FIFO_CTRL = (SM_APB08_MASK | SM_DMAEN_MASK | SM_DMA_UPSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK);
380 // SM_FIFO_CTRL = (SM_APB32_MASK | SM_DMAEN_MASK | SM_DMA_UPSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK);
382 // _Hw_D_EccRdReset();
383 // _Hw_D_EccRdStart();
385 // SM_CMD_CTRL1 = (SM_CMD_READ_1);
386 // SM_CMD_CTRL1 = (SM_CMD_READ_1 | SM_CMD_START_BIT);
388 // SectByteCount = 0x1ff;
389 // //SM_ReadDataWithDMA(fdoExt, buf, SectByteCount);
390 // //_ReadRedt_D_SsfdcBuf(redundant);
391 // len = 0x1000 - ((WORD)(buf) & 0x0FFF);
394 // SM_ReadDataWithDMA(fdoExt, buf, len-1);
395 // SM_ReadDataWithDMA(fdoExt, buf+len, SectByteCount-len);
396 // //ENE_Print("Read DMA !!! buf1 = %p, len = %x, buf2 = %p\n", buf, len, buf+len);
399 // SM_ReadDataWithDMA(fdoExt, buf, SectByteCount);
401 // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate )
403 // _ReadRedt_D_SsfdcBuf(redundant);
407 // Buffer[0] = READ_PORT_DWORD(SM_REG_DATA);
408 // Buffer[1] = READ_PORT_DWORD(SM_REG_DATA);
409 // Buffer[2] = READ_PORT_DWORD(SM_REG_DATA);
410 // Buffer[3] = READ_PORT_DWORD(SM_REG_DATA);
411 // memcpy(redundant, Buffer, 0x10);
414 // while ( _Hw_D_ChkCardIn() )
416 // if((READ_PORT_BYTE(SM_REG_INT_STATUS) & 0x10))
418 // WRITE_PORT_BYTE(SM_REG_INT_STATUS, 0x10);
422 // _Hw_D_EccRdStop();
423 // _Hw_D_SetRdStandby();
424 // _Load_D_SsfdcRdHwECC(EVEN);
426 // _Calc_D_ECCdata(buf);
427 // _Set_D_SsfdcRdStandby();
429 // if (!_Hw_D_ChkCardIn())
434 ////----- Ssfdc_D_ReadSect_PIO() ---------------------------------------------
435 //int Ssfdc_D_ReadSect_PIO(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
437 // _Set_D_SsfdcRdCmd(READ);
438 // _Set_D_SsfdcRdAddr(EVEN);
440 // if (_Check_D_SsfdcBusy(BUSY_READ))
441 // { _Reset_D_SsfdcErr(); return(ERROR); }
443 // _Start_D_SsfdcRdHwECC();
444 // _Read_D_SsfdcBuf(buf);
445 // _Stop_D_SsfdcRdHwECC();
446 // _ReadRedt_D_SsfdcBuf(redundant);
447 // _Load_D_SsfdcRdHwECC(EVEN);
449 // if (_Check_D_SsfdcBusy(BUSY_READ))
450 // { _Reset_D_SsfdcErr(); return(ERROR); }
452 // _Calc_D_ECCdata(buf);
453 // _Set_D_SsfdcRdStandby();
458 //----- Ssfdc_D_WriteSect() --------------------------------------------
459 int Ssfdc_D_WriteSect(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
461 PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
465 //ENE_Print("SMILSUB --- Ssfdc_D_WriteSect\n");
466 ENE_LoadBinCode(fdoExt, SM_RW_PATTERN);
468 addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
469 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
472 RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
473 pBulkCbw->dCBWSignature = CBW_SIGNTURE;
474 pBulkCbw->bCBWLun = CBW_LUN;
475 pBulkCbw->dCBWDataTransferLength = 0x200;
476 pBulkCbw->bmCBWFlags = 0x00;
477 pBulkCbw->CBWCb[0] = 0xF0;
478 pBulkCbw->CBWCb[1] = 0x04;
479 //pBulkCbw->CBWCb[4] = (BYTE)addr;
480 //pBulkCbw->CBWCb[3] = (BYTE)(addr/0x0100);
481 //pBulkCbw->CBWCb[2] = Media.Zone/2;
482 //pBulkCbw->CBWCb[5] = *(redundant+REDT_ADDR1H);
483 //pBulkCbw->CBWCb[6] = *(redundant+REDT_ADDR1L);
484 pBulkCbw->CBWCb[7] = (BYTE)addr;
485 pBulkCbw->CBWCb[6] = (BYTE)(addr/0x0100);
486 pBulkCbw->CBWCb[5] = Media.Zone/2;
487 pBulkCbw->CBWCb[8] = *(redundant+REDT_ADDR1H);
488 pBulkCbw->CBWCb[9] = *(redundant+REDT_ADDR1L);
490 ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_WRITE, buf);
492 if (!NT_SUCCESS(ntStatus))
497 // BYTE bf[0x200], rdd[0x10];
500 // RtlZeroMemory(bf, 0x200);
501 // RtlZeroMemory(rdd, 0x10);
502 // ntStatus = SM_ReadBlock(fdoExt, bf, rdd);
503 // for (i=0; i<0x200; i++)
505 // if (buf[i] != bf[i])
506 // ENE_Print("buf[%x] = %x, bf[%x] = %x\n", buf, bf);
508 // if (!NT_SUCCESS(ntStatus))
509 // ENE_Print("Error\n");
515 //----- Ssfdc_D_CopyBlock() --------------------------------------------
516 int Ssfdc_D_CopyBlock(struct us_data
*us
, WORD count
, BYTE
*buf
,BYTE
*redundant
)
518 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
520 //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
522 WORD ReadAddr
, WriteAddr
;
524 //printk("Ssfdc_D_WriteSect --- ZONE = %x, ReadBlock = %x, WriteBlock = %x\n", Media.Zone, ReadBlock, WriteBlock);
526 result
= ENE_LoadBinCode(us
, SM_RW_PATTERN
);
527 if (result
!= USB_STOR_XFER_GOOD
)
529 printk("Load SM RW Code Fail !!\n");
530 return USB_STOR_TRANSPORT_ERROR
;
533 ReadAddr
= (WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+ReadBlock
;
534 ReadAddr
= ReadAddr
*(WORD
)Ssfdc
.MaxSectors
;
535 WriteAddr
= (WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+WriteBlock
;
536 WriteAddr
= WriteAddr
*(WORD
)Ssfdc
.MaxSectors
;
539 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
540 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
541 bcb
->DataTransferLength
= 0x200*count
;
545 bcb
->CDB
[7] = (BYTE
)WriteAddr
;
546 bcb
->CDB
[6] = (BYTE
)(WriteAddr
/0x0100);
547 bcb
->CDB
[5] = Media
.Zone
/2;
548 bcb
->CDB
[8] = *(redundant
+REDT_ADDR1H
);
549 bcb
->CDB
[9] = *(redundant
+REDT_ADDR1L
);
550 bcb
->CDB
[10] = Media
.Sector
;
552 if (ReadBlock
!= NO_ASSIGN
)
554 bcb
->CDB
[4] = (BYTE
)ReadAddr
;
555 bcb
->CDB
[3] = (BYTE
)(ReadAddr
/0x0100);
556 bcb
->CDB
[2] = Media
.Zone
/2;
561 result
= ENE_SendScsiCmd(us
, FDIR_WRITE
, buf
, 0);
562 if (result
!= USB_STOR_XFER_GOOD
)
563 return USB_STOR_TRANSPORT_ERROR
;
565 return USB_STOR_TRANSPORT_GOOD
;
568 //----- Ssfdc_D_WriteBlock() --------------------------------------------
569 int Ssfdc_D_WriteBlock(PFDO_DEVICE_EXTENSION fdoExt, WORD count, BYTE *buf,BYTE *redundant)
571 PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
575 //ENE_Print("SMILSUB --- Ssfdc_D_WriteSect\n");
576 ENE_LoadBinCode(fdoExt, SM_RW_PATTERN);
578 addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
579 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
582 RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
583 pBulkCbw->dCBWSignature = CBW_SIGNTURE;
584 pBulkCbw->bCBWLun = CBW_LUN;
585 pBulkCbw->dCBWDataTransferLength = 0x200*count;
586 pBulkCbw->bmCBWFlags = 0x00;
587 pBulkCbw->CBWCb[0] = 0xF0;
588 pBulkCbw->CBWCb[1] = 0x04;
589 pBulkCbw->CBWCb[7] = (BYTE)addr;
590 pBulkCbw->CBWCb[6] = (BYTE)(addr/0x0100);
591 pBulkCbw->CBWCb[5] = Media.Zone/2;
592 pBulkCbw->CBWCb[8] = *(redundant+REDT_ADDR1H);
593 pBulkCbw->CBWCb[9] = *(redundant+REDT_ADDR1L);
595 ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_WRITE, buf);
597 if (!NT_SUCCESS(ntStatus))
602 // BYTE bf[0x200], rdd[0x10];
605 // RtlZeroMemory(bf, 0x200);
606 // RtlZeroMemory(rdd, 0x10);
607 // ntStatus = SM_ReadBlock(fdoExt, bf, rdd);
608 // for (i=0; i<0x200; i++)
610 // if (buf[i] != bf[i])
611 // ENE_Print("buf[%x] = %x, bf[%x] = %x\n", buf, bf);
613 // if (!NT_SUCCESS(ntStatus))
614 // ENE_Print("Error\n");
620 ////----- Ssfdc_D_WriteSect_DMA() --------------------------------------------
621 //int Ssfdc_D_WriteSect_DMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
623 // WORD SectByteCount, addr;
627 // if (!_Hw_D_ChkCardIn())
629 // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
630 // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
631 // // cycle starting address
632 // SM_STARTADDR_LSB = 0x00;
633 // SM_STARTADDR_IISB = (BYTE)addr;
634 // SM_STARTADDR_IIISB = (BYTE)(addr/0x0100);
635 // SM_STARTADDR_MSB = Media.Zone/2;
637 // //Sector byte count (DMA)
638 // SectByteCount = 0x20f;
639 // SM_BYTECNT_LO = (BYTE)SectByteCount;
640 // SM_CMD_CTRL3 = (SM_CMD_CTRL3 & 0xFC) | 0x20 | (BYTE)(SectByteCount/0x0100);
641 // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate )
642 // SM_FIFO_CTRL = (SM_APB08_MASK | SM_DMAEN_MASK | SM_DMA_DOWNSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK);
644 // SM_FIFO_CTRL = (SM_APB32_MASK | SM_DMAEN_MASK | SM_DMA_DOWNSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK);
646 // _Hw_D_EccRdReset();
647 // _Hw_D_EccRdStart();
649 // SM_CMD_CTRL1 = SM_CMD_PAGPRGM_TRUE;
650 // SM_CMD_CTRL1 = (SM_CMD_PAGPRGM_TRUE | SM_CMD_START_BIT);
652 // SectByteCount = 0x1ff;
653 // //SM_WriteDataWithDMA(fdoExt, buf, SectByteCount);
654 // //_WriteRedt_D_SsfdcBuf(redundant);
655 // len = 0x1000 - ((WORD)(buf) & 0x0FFF);
658 // SM_WriteDataWithDMA(fdoExt, buf, len-1);
659 // SM_WriteDataWithDMA(fdoExt, buf+len, SectByteCount-len);
660 // //ENE_Print("Read DMA !!! buf1 = %p, len = %x, buf2 = %p\n", buf, len, buf+len);
663 // SM_WriteDataWithDMA(fdoExt, buf, SectByteCount);
665 // //T1 = (ULONGLONG)buf & 0xFFFFFFFFFFFFF000;
666 // //T2 = ((ULONGLONG)buf + 0x1FF) & 0xFFFFFFFFFFFFF000;
668 // // ENE_Print("Ssfdc_D_WriteSect_DMA !!! buf = %p, T1 = %p, T2 = %p\n", buf, T1, T2);
671 // // l1 = (WORD)(T2 - (ULONGLONG)buf);
672 // // SM_WriteDataWithDMA(fdoExt, buf, l1-1);
673 // // SM_WriteDataWithDMA(fdoExt, (PBYTE)T2, SectByteCount-l1);
676 // // SM_WriteDataWithDMA(fdoExt, buf, SectByteCount);
678 // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate )
680 // _WriteRedt_D_SsfdcBuf(redundant);
684 // memcpy(Buffer, redundant, 0x10);
685 // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[0]);
686 // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[1]);
687 // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[2]);
688 // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[3]);
691 // while ( _Hw_D_ChkCardIn() )
693 // if ((READ_PORT_BYTE(SM_REG_INT_STATUS) & 0x10))
695 // WRITE_PORT_BYTE(SM_REG_INT_STATUS, 0x10);
699 // _Hw_D_EccRdStop();
700 // _Hw_D_SetRdStandby();
702 // _Set_D_SsfdcWrStandby();
703 // _Set_D_SsfdcRdStandby();
704 // if (!_Hw_D_ChkCardIn())
710 ////----- Ssfdc_D_WriteSect_PIO() --------------------------------------------
711 //int Ssfdc_D_WriteSect_PIO(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
713 // _Calc_D_ECCdata(buf);
714 // _Set_D_SsfdcWrCmd(WRDATA);
715 // _Set_D_SsfdcWrAddr(EVEN);
716 // _Start_D_SsfdcWrHwECC();
718 // _Write_D_SsfdcBuf(buf);
720 // _Load_D_SsfdcWrHwECC(EVEN);
721 // _Set_D_ECCdata(EVEN,redundant);
723 // _WriteRedt_D_SsfdcBuf(redundant);
725 // _Set_D_SsfdcWrCmd(WRITE);
727 // if (_Check_D_SsfdcBusy(BUSY_PROG))
728 // { _Reset_D_SsfdcErr(); return(ERROR); }
730 // _Set_D_SsfdcWrStandby();
731 // _Set_D_SsfdcRdStandby();
735 //----- Ssfdc_D_WriteSectForCopy() -------------------------------------
736 int Ssfdc_D_WriteSectForCopy(struct us_data
*us
, BYTE
*buf
, BYTE
*redundant
)
738 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
740 //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
744 //printk("SMILSUB --- Ssfdc_D_WriteSectForCopy\n");
745 result
= ENE_LoadBinCode(us
, SM_RW_PATTERN
);
746 if (result
!= USB_STOR_XFER_GOOD
)
748 printk("Load SM RW Code Fail !!\n");
749 return USB_STOR_TRANSPORT_ERROR
;
753 addr
= (WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+Media
.PhyBlock
;
754 addr
= addr
*(WORD
)Ssfdc
.MaxSectors
+Media
.Sector
;
757 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
758 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
759 bcb
->DataTransferLength
= 0x200;
763 bcb
->CDB
[7] = (BYTE
)addr
;
764 bcb
->CDB
[6] = (BYTE
)(addr
/0x0100);
765 bcb
->CDB
[5] = Media
.Zone
/2;
766 bcb
->CDB
[8] = *(redundant
+REDT_ADDR1H
);;
767 bcb
->CDB
[9] = *(redundant
+REDT_ADDR1L
);;
769 result
= ENE_SendScsiCmd(us
, FDIR_WRITE
, buf
, 0);
770 if (result
!= USB_STOR_XFER_GOOD
)
771 return USB_STOR_TRANSPORT_ERROR
;
773 return USB_STOR_TRANSPORT_GOOD
;
777 //----- Ssfdc_D_EraseBlock() -------------------------------------------
778 int Ssfdc_D_EraseBlock(struct us_data
*us
)
780 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
784 result
= ENE_LoadBinCode(us
, SM_RW_PATTERN
);
785 if (result
!= USB_STOR_XFER_GOOD
)
787 printk("Load SM RW Code Fail !!\n");
788 return USB_STOR_TRANSPORT_ERROR
;
791 addr
=(WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+Media
.PhyBlock
;
792 addr
=addr
*(WORD
)Ssfdc
.MaxSectors
;
794 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
795 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
796 bcb
->DataTransferLength
= 0x200;
800 bcb
->CDB
[7] = (BYTE
)addr
;
801 bcb
->CDB
[6] = (BYTE
)(addr
/0x0100);
802 bcb
->CDB
[5] = Media
.Zone
/2;
804 result
= ENE_SendScsiCmd(us
, FDIR_READ
, NULL
, 0);
805 if (result
!= USB_STOR_XFER_GOOD
)
806 return USB_STOR_TRANSPORT_ERROR
;
808 return USB_STOR_TRANSPORT_GOOD
;
812 //----- Ssfdc_D_ReadRedtData() -----------------------------------------
813 int Ssfdc_D_ReadRedtData(struct us_data
*us
, BYTE
*redundant
)
815 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
820 result
= ENE_LoadBinCode(us
, SM_RW_PATTERN
);
821 if (result
!= USB_STOR_XFER_GOOD
)
823 printk("Load SM RW Code Fail !!\n");
824 return USB_STOR_TRANSPORT_ERROR
;
827 addr
= (WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+Media
.PhyBlock
;
828 addr
= addr
*(WORD
)Ssfdc
.MaxSectors
+Media
.Sector
;
830 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
831 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
832 bcb
->DataTransferLength
= 0x10;
836 bcb
->CDB
[4] = (BYTE
)addr
;
837 bcb
->CDB
[3] = (BYTE
)(addr
/0x0100);
838 bcb
->CDB
[2] = Media
.Zone
/2;
842 buf
= kmalloc(0x10, GFP_KERNEL
);
843 //result = ENE_SendScsiCmd(us, FDIR_READ, redundant, 0);
844 result
= ENE_SendScsiCmd(us
, FDIR_READ
, buf
, 0);
845 memcpy(redundant
, buf
, 0x10);
847 if (result
!= USB_STOR_XFER_GOOD
)
848 return USB_STOR_TRANSPORT_ERROR
;
850 return USB_STOR_TRANSPORT_GOOD
;
854 //----- Ssfdc_D_WriteRedtData() ----------------------------------------
855 int Ssfdc_D_WriteRedtData(struct us_data
*us
, BYTE
*redundant
)
857 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
859 //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
863 result
= ENE_LoadBinCode(us
, SM_RW_PATTERN
);
864 if (result
!= USB_STOR_XFER_GOOD
)
866 printk("Load SM RW Code Fail !!\n");
867 return USB_STOR_TRANSPORT_ERROR
;
870 addr
= (WORD
)Media
.Zone
*Ssfdc
.MaxBlocks
+Media
.PhyBlock
;
871 addr
= addr
*(WORD
)Ssfdc
.MaxSectors
+Media
.Sector
;
873 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
874 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
875 bcb
->DataTransferLength
= 0x10;
879 bcb
->CDB
[7] = (BYTE
)addr
;
880 bcb
->CDB
[6] = (BYTE
)(addr
/0x0100);
881 bcb
->CDB
[5] = Media
.Zone
/2;
882 bcb
->CDB
[8] = *(redundant
+REDT_ADDR1H
);
883 bcb
->CDB
[9] = *(redundant
+REDT_ADDR1L
);
885 result
= ENE_SendScsiCmd(us
, FDIR_READ
, NULL
, 0);
886 if (result
!= USB_STOR_XFER_GOOD
)
887 return USB_STOR_TRANSPORT_ERROR
;
889 return USB_STOR_TRANSPORT_GOOD
;
892 //----- Ssfdc_D_CheckStatus() ------------------------------------------
893 int Ssfdc_D_CheckStatus(void)
897 //_Set_D_SsfdcRdCmd(RDSTATUS);
899 //if (_Check_D_SsfdcStatus())
900 //{ _Set_D_SsfdcRdStandby(); return(ERROR); }
902 //_Set_D_SsfdcRdStandby();
906 ////NAND Memory (SmartMedia) Control Subroutine for Read Data
907 ////----- _Set_D_SsfdcRdCmd() --------------------------------------------
908 //void _Set_D_SsfdcRdCmd(BYTE cmd)
911 // _Hw_D_OutData(cmd);
912 // _Hw_D_SetRdData();
915 ////----- _Set_D_SsfdcRdAddr() -------------------------------------------
916 //void _Set_D_SsfdcRdAddr(BYTE add)
919 // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
920 // ADDRESS_T bb = (ADDRESS_T) &Media;
922 // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
923 // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
925 // //if ((Ssfdc.Attribute &MPS)==PS256) // for 256byte/page
926 // // addr=addr*2+(WORD)add;
928 // _Hw_D_SetRdAddr();
929 // _Hw_D_OutData(0x00);
930 // _Hw_D_OutData((BYTE)addr);
931 // _Hw_D_OutData((BYTE)(addr/0x0100));
933 // if ((Ssfdc.Attribute &MADC)==AD4CYC)
934 // _Hw_D_OutData((BYTE)(Media.Zone/2)); // Patch
936 // _Hw_D_SetRdData();
939 ////----- _Set_D_SsfdcRdChip() -------------------------------------------
940 //void _Set_D_SsfdcRdChip(void)
942 // _Hw_D_SetRdAddr();
943 // _Hw_D_OutData(0x00);
944 // _Hw_D_SetRdData();
947 ////----- _Set_D_SsfdcRdStandby() ----------------------------------------
948 //void _Set_D_SsfdcRdStandby(void)
950 // _Hw_D_SetRdStandby();
953 ////----- _Start_D_SsfdcRdHwECC() ----------------------------------------
954 //void _Start_D_SsfdcRdHwECC(void)
956 //#ifdef HW_ECC_SUPPORTED
957 // _Hw_D_EccRdReset();
959 // _Hw_D_EccRdStart();
963 ////----- _Stop_D_SsfdcRdHwECC() -----------------------------------------
964 //void _Stop_D_SsfdcRdHwECC(void)
966 //#ifdef HW_ECC_SUPPORTED
967 // _Hw_D_EccRdStop();
971 ////----- _Load_D_SsfdcRdHwECC() -----------------------------------------
972 //void _Load_D_SsfdcRdHwECC(BYTE add)
974 //#ifdef HW_ECC_SUPPORTED
975 // _Hw_D_EccRdRead();
976 // //if (!(add==ODD && (Ssfdc.Attribute &MPS)==PS256))
978 // EccBuf[0]=_Hw_D_InData();
979 // EccBuf[1]=_Hw_D_InData();
980 // EccBuf[2]=_Hw_D_InData();
983 // //if (!(add==EVEN && (Ssfdc.Attribute &MPS)==PS256))
985 // EccBuf[3]=_Hw_D_InData();
986 // EccBuf[4]=_Hw_D_InData();
987 // EccBuf[5]=_Hw_D_InData();
990 // _Hw_D_EccRdStop();
994 ////NAND Memory (SmartMedia) Control Subroutine for Write Data
996 ////----- _Set_D_SsfdcWrCmd() -----------------------------------------
997 //void _Set_D_SsfdcWrCmd(BYTE cmd)
1000 // _Hw_D_OutData(cmd);
1001 // _Hw_D_SetWrData();
1004 ////----- _Set_D_SsfdcWrAddr() -----------------------------------------
1005 //void _Set_D_SsfdcWrAddr(BYTE add)
1008 // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1009 // ADDRESS_T bb = (ADDRESS_T) &Media;
1011 // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
1012 // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
1014 // //if ((Ssfdc.Attribute &MPS)==PS256) // for 256byte/page
1015 // // addr=addr*2+(WORD)add;
1017 // _Hw_D_SetWrAddr();
1018 // _Hw_D_OutData(0x00);
1019 // _Hw_D_OutData((BYTE)addr);
1020 // _Hw_D_OutData((BYTE)(addr/0x0100));
1022 // if ((Ssfdc.Attribute &MADC)==AD4CYC)
1023 // _Hw_D_OutData((BYTE)(Media.Zone/2)); // Patch
1025 // _Hw_D_SetWrData();
1028 ////----- _Set_D_SsfdcWrBlock() -----------------------------------------
1029 //void _Set_D_SsfdcWrBlock(void)
1032 // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1033 // ADDRESS_T bb = (ADDRESS_T) &Media;
1035 // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
1036 // addr=addr*(WORD)Ssfdc.MaxSectors;
1038 // //if ((Ssfdc.Attribute &MPS)==PS256) // for 256byte/page
1041 // _Hw_D_SetWrAddr();
1042 // _Hw_D_OutData((BYTE)addr);
1043 // _Hw_D_OutData((BYTE)(addr/0x0100));
1045 // if ((Ssfdc.Attribute &MADC)==AD4CYC)
1046 // _Hw_D_OutData((BYTE)(Media.Zone/2)); // Patch
1048 // _Hw_D_SetWrData();
1051 ////----- _Set_D_SsfdcWrStandby() -----------------------------------------
1052 //void _Set_D_SsfdcWrStandby(void)
1054 // _Hw_D_SetWrStandby();
1057 ////----- _Start_D_SsfdcWrHwECC() -----------------------------------------
1058 //void _Start_D_SsfdcWrHwECC(void)
1060 //#ifdef HW_ECC_SUPPORTED
1061 // _Hw_D_EccWrReset();
1063 // _Hw_D_EccWrStart();
1067 ////----- _Load_D_SsfdcWrHwECC() -----------------------------------------
1068 //void _Load_D_SsfdcWrHwECC(BYTE add)
1070 //#ifdef HW_ECC_SUPPORTED
1071 // _Hw_D_EccWrRead();
1072 // //if (!(add==ODD && (Ssfdc.Attribute &MPS)==PS256))
1074 // EccBuf[0]=_Hw_D_InData();
1075 // EccBuf[1]=_Hw_D_InData();
1076 // EccBuf[2]=_Hw_D_InData();
1079 // //if (!(add==EVEN && (Ssfdc.Attribute &MPS)==PS256))
1081 // EccBuf[3]=_Hw_D_InData();
1082 // EccBuf[4]=_Hw_D_InData();
1083 // EccBuf[5]=_Hw_D_InData();
1086 // _Hw_D_EccWrStop();
1090 ////NAND Memory (SmartMedia) Control Subroutine
1091 ////----- _Check_D_SsfdcBusy() -------------------------------------------
1092 //int _Check_D_SsfdcBusy(WORD time)
1097 // if (!_Hw_D_ChkBusy())
1101 // } while (count<=time);
1106 ////----- _Check_D_SsfdcStatus() -----------------------------------------
1107 //int _Check_D_SsfdcStatus(void)
1109 // if (_Hw_D_InData() & WR_FAIL)
1116 ////----- _Reset_D_SsfdcErr() -----------------------------------------
1117 //void _Reset_D_SsfdcErr(void)
1121 // _Hw_D_SetRdCmd();
1122 // _Hw_D_OutData(RST_CHIP);
1123 // _Hw_D_SetRdData();
1126 // if (!_Hw_D_ChkBusy())
1130 // } while (count<=BUSY_RESET);
1132 // _Hw_D_SetRdStandby();
1135 ////NAND Memory (SmartMedia) Buffer Data Xfer Subroutine
1136 ////----- SM_ReadDataWithDMA() -----------------------------------------
1137 //void SM_ReadDataWithDMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *databuf, WORD SectByteCount)
1139 // PHYSICAL_ADDRESS Addr;
1140 // LARGE_INTEGER ptimeout ;
1142 // KeClearEvent(&fdoExt->SM_DMADoneEvent);
1144 // Addr = MmGetPhysicalAddress(databuf);
1146 // WRITE_PORT_DWORD(SM_DMA_ADDR_REG, (DWORD)Addr.LowPart);
1147 // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 0);
1148 // WRITE_PORT_WORD(SM_DMA_BYTE_COUNT_REG, SectByteCount);
1150 // while ( _Hw_D_ChkCardIn() )
1152 // if ((READ_PORT_BYTE(SM_REG_FIFO_STATUS) & 0x80))
1155 // if (!_Hw_D_ChkCardIn()) return;
1156 // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 0x01);
1158 // ptimeout.QuadPart = 2000 * (-10000); // 2 sec
1159 // KeWaitForSingleObject(&fdoExt->SM_DMADoneEvent, Executive, KernelMode, FALSE, &ptimeout);
1160 // _Hw_D_SetDMAIntMask();
1163 ////----- SM_WriteDataWithDMA() -----------------------------------------
1164 //void SM_WriteDataWithDMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *databuf, WORD SectByteCount)
1166 // PHYSICAL_ADDRESS Addr;
1167 // LARGE_INTEGER ptimeout ;
1169 // KeClearEvent(&fdoExt->SM_DMADoneEvent);
1171 // Addr = MmGetPhysicalAddress(databuf);
1173 // WRITE_PORT_DWORD(SM_DMA_ADDR_REG, (DWORD)Addr.LowPart);
1174 // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 2);
1175 // WRITE_PORT_WORD(SM_DMA_BYTE_COUNT_REG, SectByteCount);
1177 // while ( _Hw_D_ChkCardIn() )
1179 // if ((READ_PORT_BYTE(SM_REG_FIFO_STATUS) & 0x40))
1182 // if (!_Hw_D_ChkCardIn()) return;
1183 // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 0x03);
1185 // ptimeout.QuadPart = 2000 * (-10000); // 2 sec
1186 // KeWaitForSingleObject(&fdoExt->SM_DMADoneEvent, Executive, KernelMode, FALSE, &ptimeout);
1187 // _Hw_D_SetDMAIntMask();
1190 ////----- _Read_D_SsfdcBuf() -----------------------------------------
1191 //void _Read_D_SsfdcBuf(BYTE *databuf)
1195 // //for(i=0x0000;i<(((Ssfdc.Attribute &MPS)==PS256)?0x0100:0x0200);i++)
1196 // for(i=0; i<0x200; i++)
1197 // *databuf++ =_Hw_D_InData();
1200 ////----- _Write_D_SsfdcBuf() -----------------------------------------
1201 //void _Write_D_SsfdcBuf(BYTE *databuf)
1205 // //for(i=0x0000;i<(((Ssfdc.Attribute &MPS)==PS256)?0x0100:0x0200);i++)
1206 // for(i=0; i<0x200; i++)
1207 // _Hw_D_OutData(*databuf++);
1210 ////----- _Read_D_SsfdcByte() -----------------------------------------
1211 //void _Read_D_SsfdcByte(BYTE *databuf)
1213 // *databuf=(BYTE)_Hw_D_InData();
1216 ////----- _ReadRedt_D_SsfdcBuf() -----------------------------------------
1217 //void _ReadRedt_D_SsfdcBuf(BYTE *redundant)
1221 // //for(i=0x00;i<(((Ssfdc.Attribute &MPS)==PS256)?0x08:0x10);i++)
1222 // for(i=0; i<0x10; i++)
1223 // redundant[i] =_Hw_D_InData();
1226 ////----- _WriteRedt_D_SsfdcBuf() -----------------------------------------
1227 //void _WriteRedt_D_SsfdcBuf(BYTE *redundant)
1231 // //for(i=0x00;i<(((Ssfdc.Attribute &MPS)==PS256)?0x08:0x10);i++)
1232 // for(i=0; i<0x10; i++)
1233 // _Hw_D_OutData(*redundant++);
1236 //SmartMedia ID Code Check & Mode Set Subroutine
1237 //----- Set_D_SsfdcModel() ---------------------------------------------
1238 int Set_D_SsfdcModel(BYTE dcode
)
1240 switch (_Check_D_DevCode(dcode
)) {
1242 Ssfdc
.Model
= SSFDC1MB
;
1243 Ssfdc
.Attribute
= FLASH
| AD3CYC
| BS16
| PS256
;
1245 Ssfdc
.MaxBlocks
= 256;
1246 Ssfdc
.MaxLogBlocks
= 250;
1247 Ssfdc
.MaxSectors
= 8;
1250 Ssfdc
.Model
= SSFDC2MB
;
1251 Ssfdc
.Attribute
= FLASH
| AD3CYC
| BS16
| PS256
;
1253 Ssfdc
.MaxBlocks
= 512;
1254 Ssfdc
.MaxLogBlocks
= 500;
1255 Ssfdc
.MaxSectors
= 8;
1258 Ssfdc
.Model
= SSFDC4MB
;
1259 Ssfdc
.Attribute
= FLASH
| AD3CYC
| BS16
| PS512
;
1261 Ssfdc
.MaxBlocks
= 512;
1262 Ssfdc
.MaxLogBlocks
= 500;
1263 Ssfdc
.MaxSectors
= 16;
1266 Ssfdc
.Model
= SSFDC8MB
;
1267 Ssfdc
.Attribute
= FLASH
| AD3CYC
| BS16
| PS512
;
1269 Ssfdc
.MaxBlocks
= 1024;
1270 Ssfdc
.MaxLogBlocks
= 1000;
1271 Ssfdc
.MaxSectors
= 16;
1274 Ssfdc
.Model
= SSFDC16MB
;
1275 Ssfdc
.Attribute
= FLASH
| AD3CYC
| BS32
| PS512
;
1277 Ssfdc
.MaxBlocks
= 1024;
1278 Ssfdc
.MaxLogBlocks
= 1000;
1279 Ssfdc
.MaxSectors
= 32;
1282 Ssfdc
.Model
= SSFDC32MB
;
1283 Ssfdc
.Attribute
= FLASH
| AD3CYC
| BS32
| PS512
;
1285 Ssfdc
.MaxBlocks
= 1024;
1286 Ssfdc
.MaxLogBlocks
= 1000;
1287 Ssfdc
.MaxSectors
= 32;
1290 Ssfdc
.Model
= SSFDC64MB
;
1291 Ssfdc
.Attribute
= FLASH
| AD4CYC
| BS32
| PS512
;
1293 Ssfdc
.MaxBlocks
= 1024;
1294 Ssfdc
.MaxLogBlocks
= 1000;
1295 Ssfdc
.MaxSectors
= 32;
1298 Ssfdc
.Model
= SSFDC128MB
;
1299 Ssfdc
.Attribute
= FLASH
| AD4CYC
| BS32
| PS512
;
1301 Ssfdc
.MaxBlocks
= 1024;
1302 Ssfdc
.MaxLogBlocks
= 1000;
1303 Ssfdc
.MaxSectors
= 32;
1306 Ssfdc
.Model
= SSFDC256MB
;
1307 Ssfdc
.Attribute
= FLASH
| AD4CYC
| BS32
| PS512
;
1308 Ssfdc
.MaxZones
= 16;
1309 Ssfdc
.MaxBlocks
= 1024;
1310 Ssfdc
.MaxLogBlocks
= 1000;
1311 Ssfdc
.MaxSectors
= 32;
1314 Ssfdc
.Model
= SSFDC512MB
;
1315 Ssfdc
.Attribute
= FLASH
| AD4CYC
| BS32
| PS512
;
1316 Ssfdc
.MaxZones
= 32;
1317 Ssfdc
.MaxBlocks
= 1024;
1318 Ssfdc
.MaxLogBlocks
= 1000;
1319 Ssfdc
.MaxSectors
= 32;
1322 Ssfdc
.Model
= SSFDC1GB
;
1323 Ssfdc
.Attribute
= FLASH
| AD4CYC
| BS32
| PS512
;
1324 Ssfdc
.MaxZones
= 64;
1325 Ssfdc
.MaxBlocks
= 1024;
1326 Ssfdc
.MaxLogBlocks
= 1000;
1327 Ssfdc
.MaxSectors
= 32;
1330 Ssfdc
.Model
= SSFDC2GB
;
1331 Ssfdc
.Attribute
= FLASH
| AD4CYC
| BS32
| PS512
;
1332 Ssfdc
.MaxZones
= 128;
1333 Ssfdc
.MaxBlocks
= 1024;
1334 Ssfdc
.MaxLogBlocks
= 1000;
1335 Ssfdc
.MaxSectors
= 32;
1338 Ssfdc
.Model
= NOSSFDC
;
1345 //----- _Check_D_DevCode() ---------------------------------------------
1346 BYTE
_Check_D_DevCode(BYTE dcode
)
1351 case 0xEC: return(SSFDC1MB
); // 8Mbit (1M) NAND
1353 case 0xEA: return(SSFDC2MB
); // 16Mbit (2M) NAND
1356 case 0xE5: return(SSFDC4MB
); // 32Mbit (4M) NAND
1357 case 0xE6: return(SSFDC8MB
); // 64Mbit (8M) NAND
1358 case 0x73: return(SSFDC16MB
); // 128Mbit (16M)NAND
1359 case 0x75: return(SSFDC32MB
); // 256Mbit (32M)NAND
1360 case 0x76: return(SSFDC64MB
); // 512Mbit (64M)NAND
1361 case 0x79: return(SSFDC128MB
); // 1Gbit(128M)NAND
1362 case 0x71: return(SSFDC256MB
);
1363 case 0xDC: return(SSFDC512MB
);
1364 case 0xD3: return(SSFDC1GB
);
1365 case 0xD5: return(SSFDC2GB
);
1366 default: return(NOSSFDC
);
1370 ////SmartMedia Power Controll Subroutine
1371 ////----- Cnt_D_Reset() ----------------------------------------------
1372 //void Cnt_D_Reset(void)
1375 // _Hw_D_SetRdStandby();
1379 ////----- Cnt_D_PowerOn() ----------------------------------------------
1380 //int Cnt_D_PowerOn(void)
1382 // // No support 5V.
1383 // _Hw_D_EnableVcc3VOn(); // Set SM_REG_CTRL_5 Reg. to 3V
1385 // _Hw_D_SetRdStandby();
1386 // _Wait_D_Timer(TIME_PON);
1388 // if (_Hw_D_ChkPower())
1390 // _Hw_D_EnableOB(); // Set SM_REG_CTRL_5 Reg. to 0x83
1394 // _Hw_D_SetVccOff();
1398 ////----- Cnt_D_PowerOff() ----------------------------------------------
1399 //void Cnt_D_PowerOff(void)
1401 // _Hw_D_SetRdStandby();
1402 // _Hw_D_SetVccOff();
1406 ////----- Cnt_D_LedOn() ----------------------------------------------
1407 //void Cnt_D_LedOn(void)
1412 ////----- Cnt_D_LedOff() ----------------------------------------------
1413 //void Cnt_D_LedOff(void)
1418 ////----- Check_D_CntPower() ----------------------------------------------
1419 //int Check_D_CntPower(void)
1421 // if (_Hw_D_ChkPower())
1422 // return(SUCCESS); // Power On
1424 // return(ERROR); // Power Off
1427 ////----- Check_D_CardExist() ----------------------------------------------
1428 //int Check_D_CardExist(void)
1432 // if (!_Hw_D_ChkStatus()) // Not Status Change
1433 // if (_Hw_D_ChkCardIn())
1434 // return(SUCCESS); // Card exist in Slot
1436 // for(i=0,j=0,k=0; i<16; i++) {
1437 // if (_Hw_D_ChkCardIn()) // Status Change
1447 // return(SUCCESS); // Card exist in Slot
1449 // return(ERROR); // NO Card exist in Slot
1451 // _Wait_D_Timer(TIME_CDCHK);
1457 ////----- Check_D_CardStsChg() ----------------------------------------------
1458 //int Check_D_CardStsChg(void)
1460 // if (_Hw_D_ChkStatus())
1461 // return(ERROR); // Status Change
1463 // return(SUCCESS); // Not Status Change
1466 ////----- Check_D_SsfdcWP() ----------------------------------------------
1467 //int Check_D_SsfdcWP(void)
1468 //{ // ERROR: WP, SUCCESS: Not WP
1471 // for(i=0; i<8; i++) {
1472 // if (_Hw_D_ChkWP())
1474 // _Wait_D_Timer(TIME_WPCHK);
1481 //SmartMedia ECC Controll Subroutine
1482 //----- Check_D_ReadError() ----------------------------------------------
1483 int Check_D_ReadError(BYTE
*redundant
)
1485 // Driver ¤£°µ ECC Check
1487 if (!StringCmp((char *)(redundant
+0x0D),(char *)EccBuf
,3))
1488 if (!StringCmp((char *)(redundant
+0x08),(char *)(EccBuf
+0x03),3))
1494 //----- Check_D_Correct() ----------------------------------------------
1495 int Check_D_Correct(BYTE
*buf
,BYTE
*redundant
)
1497 // Driver ¤£°µ ECC Check
1499 if (StringCmp((char *)(redundant
+0x0D),(char *)EccBuf
,3))
1500 if (_Correct_D_SwECC(buf
,redundant
+0x0D,EccBuf
))
1504 if (StringCmp((char *)(redundant
+0x08),(char *)(EccBuf
+0x03),3))
1505 if (_Correct_D_SwECC(buf
,redundant
+0x08,EccBuf
+0x03))
1511 //----- Check_D_CISdata() ----------------------------------------------
1512 int Check_D_CISdata(BYTE
*buf
, BYTE
*redundant
)
1514 BYTE cis
[]={0x01,0x03,0xD9,0x01,0xFF,0x18,0x02,0xDF,0x01,0x20};
1516 if (!IsSSFDCCompliance
&& !IsXDCompliance
)
1517 return(SUCCESS
); // ¥Ø«e¬°±j¨î SUCCESS [Arnold 02-08-23] SSFDC ´ú¸Õ, ¤£¯à±j¨î SUCCESS
1519 if (!StringCmp((char *)(redundant
+0x0D),(char *)EccBuf
,3))
1520 return(StringCmp((char *)buf
,(char *)cis
,10));
1522 if (!_Correct_D_SwECC(buf
,redundant
+0x0D,EccBuf
))
1523 return(StringCmp((char *)buf
,(char *)cis
,10));
1526 if (!StringCmp((char *)(redundant
+0x08),(char *)(EccBuf
+0x03),3))
1527 return(StringCmp((char *)buf
,(char *)cis
,10));
1529 if (!_Correct_D_SwECC(buf
,redundant
+0x08,EccBuf
+0x03))
1530 return(StringCmp((char *)buf
,(char *)cis
,10));
1535 //----- Set_D_RightECC() ----------------------------------------------
1536 void Set_D_RightECC(BYTE
*redundant
)
1538 // Driver ¤£°µ ECC Check
1540 //StringCopy((char *)(redundant+0x0D),(char *)EccBuf,3);
1541 //StringCopy((char *)(redundant+0x08),(char *)(EccBuf+0x03),3);
1544 ////----- _Calc_D_ECCdata() ----------------------------------------------
1545 //void _Calc_D_ECCdata(BYTE *buf)
1547 //#ifdef HW_ECC_SUPPORTED
1549 // _Calculate_D_SwECC(buf,EccBuf);
1551 // _Calculate_D_SwECC(buf,EccBuf+0x03);
1555 ////----- _Set_D_ECCdata() ----------------------------------------------
1556 //void _Set_D_ECCdata(BYTE add,BYTE *redundant)
1558 // //if (add==EVEN && (Ssfdc.Attribute &MPS)==PS256)
1561 // // for 256byte/page
1562 // StringCopy((char *)(redundant+0x0D),(char *)EccBuf,3);
1563 // StringCopy((char *)(redundant+0x08),(char *)(EccBuf+0x03),3);
1567 char Bit_D_Count(BYTE cdata
)
1572 bitcount
+=(WORD
)(cdata
&0x01);
1576 return((char)bitcount
);
1580 char Bit_D_CountWord(WORD cdata
)
1585 bitcount
+=(cdata
&0x01);
1589 return((char)bitcount
);
1592 void StringCopy(char *stringA
, char *stringB
, int count
)
1596 for(i
=0; i
<count
; i
++)
1597 *stringA
++ = *stringB
++;
1601 int StringCmp(char *stringA
, char *stringB
, int count
)
1605 for (i
=0;i
<count
;i
++)
1606 if (*stringA
++ != *stringB
++)
1612 //----- SM_ReadBlock() ---------------------------------------------
1613 int SM_ReadBlock(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
1615 PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
1619 ENE_LoadBinCode(fdoExt, SM_RW_PATTERN);
1621 addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
1622 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
1625 RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
1626 pBulkCbw->dCBWSignature = CBW_SIGNTURE;
1627 pBulkCbw->bCBWLun = CBW_LUN;
1628 pBulkCbw->dCBWDataTransferLength = 0x200;
1629 pBulkCbw->bmCBWFlags = 0x80;
1630 pBulkCbw->CBWCb[0] = 0xF1;
1631 pBulkCbw->CBWCb[1] = 0x02;
1632 pBulkCbw->CBWCb[4] = (BYTE)addr;
1633 pBulkCbw->CBWCb[3] = (BYTE)(addr/0x0100);
1634 pBulkCbw->CBWCb[2] = Media.Zone/2;
1636 ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_READ, buf);
1638 if (!NT_SUCCESS(ntStatus))
1642 RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
1643 pBulkCbw->dCBWSignature = CBW_SIGNTURE;
1644 pBulkCbw->bCBWLun = CBW_LUN;
1645 pBulkCbw->dCBWDataTransferLength = 0x10;
1646 pBulkCbw->bmCBWFlags = 0x80;
1647 pBulkCbw->CBWCb[0] = 0xF1;
1648 pBulkCbw->CBWCb[1] = 0x03;
1649 pBulkCbw->CBWCb[4] = (BYTE)addr;
1650 pBulkCbw->CBWCb[3] = (BYTE)(addr/0x0100);
1651 pBulkCbw->CBWCb[2] = Media.Zone/2;
1652 pBulkCbw->CBWCb[5] = 0;
1653 pBulkCbw->CBWCb[6] = 1;
1655 ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_READ, redundant);
1657 if (!NT_SUCCESS(ntStatus))