Merge remote-tracking branch 'cleancache/linux-next'
[linux-2.6/next.git] / drivers / staging / keucr / smilsub.c
blob4fe47422eb7940865e1a5ce293c3fccfc5771edb
1 #include <linux/slab.h>
2 #include "usb.h"
3 #include "scsiglue.h"
4 #include "transport.h"
5 //#include "init.h"
7 //#include "stdlib.h"
8 //#include "EUCR6SK.h"
9 #include "smcommon.h"
10 #include "smil.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;
42 struct ADDRESS Media;
43 struct CIS_AREA CisArea;
45 BYTE EccBuf[6];
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 Control Subroutine
61 //----- Check_D_DataBlank() --------------------------------------------
62 int Check_D_DataBlank(BYTE *redundant)
64 char i;
66 for(i=0; i<REDTSIZE; i++)
67 if (*redundant++!=0xFF)
68 return(ERROR);
70 return(SUCCESS);
73 //----- Check_D_FailBlock() --------------------------------------------
74 int Check_D_FailBlock(BYTE *redundant)
76 redundant+=REDT_BLOCK;
78 if (*redundant==0xFF)
79 return(SUCCESS);
80 if (!*redundant)
81 return(ERROR);
82 if (hweight8(*redundant)<7)
83 return(ERROR);
85 return(SUCCESS);
88 //----- Check_D_DataStatus() -------------------------------------------
89 int Check_D_DataStatus(BYTE *redundant)
91 redundant+=REDT_DATA;
93 if (*redundant==0xFF)
94 return(SUCCESS);
95 if (!*redundant)
97 ErrXDCode = ERR_DataStatus;
98 return(ERROR);
100 else
101 ErrXDCode = NO_ERROR;
103 if (hweight8(*redundant)<5)
104 return(ERROR);
106 return(SUCCESS);
109 //----- Load_D_LogBlockAddr() ------------------------------------------
110 int Load_D_LogBlockAddr(BYTE *redundant)
112 WORD addr1,addr2;
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);
119 if (addr1==addr2)
120 if ((addr1 &0xF000)==0x1000)
121 { Media.LogBlock=(addr1 &0x0FFF)/2; return(SUCCESS); }
123 if (hweight16((WORD)(addr1^addr2))!=0x01) return(ERROR);
125 if ((addr1 &0xF000)==0x1000)
126 if (!(hweight16(addr1) &0x01))
127 { Media.LogBlock=(addr1 &0x0FFF)/2; return(SUCCESS); }
129 if ((addr2 &0xF000)==0x1000)
130 if (!(hweight16(addr2) &0x01))
131 { Media.LogBlock=(addr2 &0x0FFF)/2; return(SUCCESS); }
133 return(ERROR);
136 //----- Clr_D_RedundantData() ------------------------------------------
137 void Clr_D_RedundantData(BYTE *redundant)
139 char i;
141 for(i=0; i<REDTSIZE; i++)
142 *(redundant+i)=0xFF;
145 //----- Set_D_LogBlockAddr() -------------------------------------------
146 void Set_D_LogBlockAddr(BYTE *redundant)
148 WORD addr;
150 *(redundant+REDT_BLOCK)=0xFF;
151 *(redundant+REDT_DATA) =0xFF;
152 addr=Media.LogBlock*2+0x1000;
154 if ((hweight16(addr)%2))
155 addr++;
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)
164 char i;
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;
174 *redundant=0x00;
177 //SmartMedia Function Command Subroutine
178 // 6250 CMD 6
179 //----- Ssfdc_D_Reset() ------------------------------------------------
180 void Ssfdc_D_Reset(struct us_data *us)
182 //NTSTATUS ntStatus = STATUS_SUCCESS;
183 //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
184 //BYTE buf[0x200];
186 //printk("Ssfdc_D_Reset --- But do nothing !!\n");
187 return;
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");
201 //return ntStatus;
205 //----- Ssfdc_D_ReadCisSect() ------------------------------------------
206 int Ssfdc_D_ReadCisSect(struct us_data *us, BYTE *buf,BYTE *redundant)
208 BYTE zone,sector;
209 WORD block;
210 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
211 //ADDRESS_T bb = (ADDRESS_T) &Media;
213 zone=Media.Zone; block=Media.PhyBlock; sector=Media.Sector;
214 Media.Zone=0;
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;
221 return(ERROR);
224 Media.Zone=zone; Media.PhyBlock=block; Media.Sector=sector;
225 return(SUCCESS);
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 ();
250 // 6250 CMD 1
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;
255 int result;
256 WORD addr;
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;
268 // Read sect data
269 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
270 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
271 bcb->DataTransferLength = 0x200;
272 bcb->Flags = 0x80;
273 bcb->CDB[0] = 0xF1;
274 bcb->CDB[1] = 0x02;
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;
283 // Read redundant
284 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
285 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
286 bcb->DataTransferLength = 0x10;
287 bcb->Flags = 0x80;
288 bcb->CDB[0] = 0xF1;
289 bcb->CDB[1] = 0x03;
290 bcb->CDB[4] = (BYTE)addr;
291 bcb->CDB[3] = (BYTE)(addr/0x0100);
292 bcb->CDB[2] = Media.Zone/2;
293 bcb->CDB[8] = 0;
294 bcb->CDB[9] = 1;
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;
307 int result;
308 WORD addr;
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;
321 // Read sect data
322 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
323 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
324 bcb->DataTransferLength = 0x200*count;
325 bcb->Flags = 0x80;
326 bcb->CDB[0] = 0xF1;
327 bcb->CDB[1] = 0x02;
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;
336 // Read redundant
337 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
338 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
339 bcb->DataTransferLength = 0x10;
340 bcb->Flags = 0x80;
341 bcb->CDB[0] = 0xF1;
342 bcb->CDB[1] = 0x03;
343 bcb->CDB[4] = (BYTE)addr;
344 bcb->CDB[3] = (BYTE)(addr/0x0100);
345 bcb->CDB[2] = Media.Zone/2;
346 bcb->CDB[8] = 0;
347 bcb->CDB[9] = 1;
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;
360 // DWORD Buffer[4];
361 // WORD len;
363 // if (!_Hw_D_ChkCardIn())
364 // return(ERROR);
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);
379 // else
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);
392 // if (len < 0x200)
393 // {
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);
397 // }
398 // else
399 // SM_ReadDataWithDMA(fdoExt, buf, SectByteCount);
401 // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate )
402 // {
403 // _ReadRedt_D_SsfdcBuf(redundant);
404 // }
405 // else
406 // {
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);
412 // }
414 // while ( _Hw_D_ChkCardIn() )
415 // {
416 // if((READ_PORT_BYTE(SM_REG_INT_STATUS) & 0x10))
417 // {
418 // WRITE_PORT_BYTE(SM_REG_INT_STATUS, 0x10);
419 // break;
420 // }
421 // }
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())
430 // return(ERROR);
431 // return(SUCCESS);
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();
454 // return(SUCCESS);
457 // 6250 CMD 3
458 //----- Ssfdc_D_WriteSect() --------------------------------------------
459 int Ssfdc_D_WriteSect(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
461 PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
462 NTSTATUS ntStatus;
463 WORD addr;
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;
471 // Write sect data
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))
493 return(ERROR);
495 // // For Test
496 // {
497 // BYTE bf[0x200], rdd[0x10];
498 // ULONG i;
500 // RtlZeroMemory(bf, 0x200);
501 // RtlZeroMemory(rdd, 0x10);
502 // ntStatus = SM_ReadBlock(fdoExt, bf, rdd);
503 // for (i=0; i<0x200; i++)
504 // {
505 // if (buf[i] != bf[i])
506 // ENE_Print("buf[%x] = %x, bf[%x] = %x\n", buf, bf);
507 // }
508 // if (!NT_SUCCESS(ntStatus))
509 // ENE_Print("Error\n");
510 // }
512 return(SUCCESS);
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;
519 int result;
520 //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
521 //NTSTATUS ntStatus;
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;
538 // Write sect data
539 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
540 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
541 bcb->DataTransferLength = 0x200*count;
542 bcb->Flags = 0x00;
543 bcb->CDB[0] = 0xF0;
544 bcb->CDB[1] = 0x08;
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;
558 else
559 bcb->CDB[11] = 1;
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;
572 NTSTATUS ntStatus;
573 WORD addr;
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;
581 // Write sect data
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))
598 return(ERROR);
600 // // For Test
601 // {
602 // BYTE bf[0x200], rdd[0x10];
603 // ULONG i;
605 // RtlZeroMemory(bf, 0x200);
606 // RtlZeroMemory(rdd, 0x10);
607 // ntStatus = SM_ReadBlock(fdoExt, bf, rdd);
608 // for (i=0; i<0x200; i++)
609 // {
610 // if (buf[i] != bf[i])
611 // ENE_Print("buf[%x] = %x, bf[%x] = %x\n", buf, bf);
612 // }
613 // if (!NT_SUCCESS(ntStatus))
614 // ENE_Print("Error\n");
615 // }
617 return(SUCCESS);
620 ////----- Ssfdc_D_WriteSect_DMA() --------------------------------------------
621 //int Ssfdc_D_WriteSect_DMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
623 // WORD SectByteCount, addr;
624 // DWORD Buffer[4];
625 // WORD len;
627 // if (!_Hw_D_ChkCardIn())
628 // return(ERROR);
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);
643 // else
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);
656 // if (len < 0x200)
657 // {
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);
661 // }
662 // else
663 // SM_WriteDataWithDMA(fdoExt, buf, SectByteCount);
665 // //T1 = (ULONGLONG)buf & 0xFFFFFFFFFFFFF000;
666 // //T2 = ((ULONGLONG)buf + 0x1FF) & 0xFFFFFFFFFFFFF000;
667 // //if (T1 != T2)
668 // // ENE_Print("Ssfdc_D_WriteSect_DMA !!! buf = %p, T1 = %p, T2 = %p\n", buf, T1, T2);
669 // //if (T2-T1)
670 // //{
671 // // l1 = (WORD)(T2 - (ULONGLONG)buf);
672 // // SM_WriteDataWithDMA(fdoExt, buf, l1-1);
673 // // SM_WriteDataWithDMA(fdoExt, (PBYTE)T2, SectByteCount-l1);
674 // //}
675 // //else
676 // // SM_WriteDataWithDMA(fdoExt, buf, SectByteCount);
678 // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate )
679 // {
680 // _WriteRedt_D_SsfdcBuf(redundant);
681 // }
682 // else
683 // {
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]);
689 // }
691 // while ( _Hw_D_ChkCardIn() )
692 // {
693 // if ((READ_PORT_BYTE(SM_REG_INT_STATUS) & 0x10))
694 // {
695 // WRITE_PORT_BYTE(SM_REG_INT_STATUS, 0x10);
696 // break;
697 // }
698 // }
699 // _Hw_D_EccRdStop();
700 // _Hw_D_SetRdStandby();
702 // _Set_D_SsfdcWrStandby();
703 // _Set_D_SsfdcRdStandby();
704 // if (!_Hw_D_ChkCardIn())
705 // return(ERROR);
707 // return(SUCCESS);
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();
732 // return(SUCCESS);
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;
739 int result;
740 //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
741 //NTSTATUS ntStatus;
742 WORD addr;
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;
756 // Write sect data
757 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
758 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
759 bcb->DataTransferLength = 0x200;
760 bcb->Flags = 0x00;
761 bcb->CDB[0] = 0xF0;
762 bcb->CDB[1] = 0x04;
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;
776 // 6250 CMD 5
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;
781 int result;
782 WORD addr;
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;
797 bcb->Flags = 0x80;
798 bcb->CDB[0] = 0xF2;
799 bcb->CDB[1] = 0x06;
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;
811 // 6250 CMD 2
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;
816 int result;
817 WORD addr;
818 BYTE *buf;
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;
833 bcb->Flags = 0x80;
834 bcb->CDB[0] = 0xF1;
835 bcb->CDB[1] = 0x03;
836 bcb->CDB[4] = (BYTE)addr;
837 bcb->CDB[3] = (BYTE)(addr/0x0100);
838 bcb->CDB[2] = Media.Zone/2;
839 bcb->CDB[8] = 0;
840 bcb->CDB[9] = 1;
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);
846 kfree(buf);
847 if (result != USB_STOR_XFER_GOOD)
848 return USB_STOR_TRANSPORT_ERROR;
850 return USB_STOR_TRANSPORT_GOOD;
853 // 6250 CMD 4
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;
858 int result;
859 //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
860 //NTSTATUS ntStatus;
861 WORD addr;
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;
876 bcb->Flags = 0x80;
877 bcb->CDB[0] = 0xF2;
878 bcb->CDB[1] = 0x05;
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)
895 // Driver ¤£°µ
896 return(SUCCESS);
897 //_Set_D_SsfdcRdCmd(RDSTATUS);
899 //if (_Check_D_SsfdcStatus())
900 //{ _Set_D_SsfdcRdStandby(); return(ERROR); }
902 //_Set_D_SsfdcRdStandby();
903 //return(SUCCESS);
906 ////NAND Memory (SmartMedia) Control Subroutine for Read Data
907 ////----- _Set_D_SsfdcRdCmd() --------------------------------------------
908 //void _Set_D_SsfdcRdCmd(BYTE cmd)
910 // _Hw_D_SetRdCmd();
911 // _Hw_D_OutData(cmd);
912 // _Hw_D_SetRdData();
915 ////----- _Set_D_SsfdcRdAddr() -------------------------------------------
916 //void _Set_D_SsfdcRdAddr(BYTE add)
918 // WORD addr;
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();
958 // _Hw_D_InData();
959 // _Hw_D_EccRdStart();
960 //#endif
963 ////----- _Stop_D_SsfdcRdHwECC() -----------------------------------------
964 //void _Stop_D_SsfdcRdHwECC(void)
966 //#ifdef HW_ECC_SUPPORTED
967 // _Hw_D_EccRdStop();
968 //#endif
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))
977 // {
978 // EccBuf[0]=_Hw_D_InData();
979 // EccBuf[1]=_Hw_D_InData();
980 // EccBuf[2]=_Hw_D_InData();
981 // }
983 // //if (!(add==EVEN && (Ssfdc.Attribute &MPS)==PS256))
984 // {
985 // EccBuf[3]=_Hw_D_InData();
986 // EccBuf[4]=_Hw_D_InData();
987 // EccBuf[5]=_Hw_D_InData();
988 // }
990 // _Hw_D_EccRdStop();
991 //#endif
994 ////NAND Memory (SmartMedia) Control Subroutine for Write Data
996 ////----- _Set_D_SsfdcWrCmd() -----------------------------------------
997 //void _Set_D_SsfdcWrCmd(BYTE cmd)
999 // _Hw_D_SetWrCmd();
1000 // _Hw_D_OutData(cmd);
1001 // _Hw_D_SetWrData();
1004 ////----- _Set_D_SsfdcWrAddr() -----------------------------------------
1005 //void _Set_D_SsfdcWrAddr(BYTE add)
1007 // WORD addr;
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)
1031 // WORD addr;
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
1039 // // addr=addr*2;
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();
1062 // _Hw_D_InData();
1063 // _Hw_D_EccWrStart();
1064 //#endif
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))
1073 // {
1074 // EccBuf[0]=_Hw_D_InData();
1075 // EccBuf[1]=_Hw_D_InData();
1076 // EccBuf[2]=_Hw_D_InData();
1077 // }
1079 // //if (!(add==EVEN && (Ssfdc.Attribute &MPS)==PS256))
1080 // {
1081 // EccBuf[3]=_Hw_D_InData();
1082 // EccBuf[4]=_Hw_D_InData();
1083 // EccBuf[5]=_Hw_D_InData();
1084 // }
1086 // _Hw_D_EccWrStop();
1087 //#endif
1090 ////NAND Memory (SmartMedia) Control Subroutine
1091 ////----- _Check_D_SsfdcBusy() -------------------------------------------
1092 //int _Check_D_SsfdcBusy(WORD time)
1094 // WORD count = 0;
1096 // do {
1097 // if (!_Hw_D_ChkBusy())
1098 // return(SUCCESS);
1099 // EDelay(100);
1100 // count++;
1101 // } while (count<=time);
1103 // return(ERROR);
1106 ////----- _Check_D_SsfdcStatus() -----------------------------------------
1107 //int _Check_D_SsfdcStatus(void)
1109 // if (_Hw_D_InData() & WR_FAIL)
1110 // return(ERROR);
1112 // return(SUCCESS);
1115 //// For 712
1116 ////----- _Reset_D_SsfdcErr() -----------------------------------------
1117 //void _Reset_D_SsfdcErr(void)
1119 // WORD count = 0;
1121 // _Hw_D_SetRdCmd();
1122 // _Hw_D_OutData(RST_CHIP);
1123 // _Hw_D_SetRdData();
1125 // do {
1126 // if (!_Hw_D_ChkBusy())
1127 // break;
1128 // EDelay(100);
1129 // count++;
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() )
1151 // {
1152 // if ((READ_PORT_BYTE(SM_REG_FIFO_STATUS) & 0x80))
1153 // break;
1154 // }
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() )
1178 // {
1179 // if ((READ_PORT_BYTE(SM_REG_FIFO_STATUS) & 0x40))
1180 // break;
1181 // }
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)
1193 // int i;
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)
1203 // int i;
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)
1219 // char i;
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)
1229 // char i;
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)) {
1241 case SSFDC1MB:
1242 Ssfdc.Model = SSFDC1MB;
1243 Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS256;
1244 Ssfdc.MaxZones = 1;
1245 Ssfdc.MaxBlocks = 256;
1246 Ssfdc.MaxLogBlocks = 250;
1247 Ssfdc.MaxSectors = 8;
1248 break;
1249 case SSFDC2MB:
1250 Ssfdc.Model = SSFDC2MB;
1251 Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS256;
1252 Ssfdc.MaxZones = 1;
1253 Ssfdc.MaxBlocks = 512;
1254 Ssfdc.MaxLogBlocks = 500;
1255 Ssfdc.MaxSectors = 8;
1256 break;
1257 case SSFDC4MB:
1258 Ssfdc.Model = SSFDC4MB;
1259 Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS512;
1260 Ssfdc.MaxZones = 1;
1261 Ssfdc.MaxBlocks = 512;
1262 Ssfdc.MaxLogBlocks = 500;
1263 Ssfdc.MaxSectors = 16;
1264 break;
1265 case SSFDC8MB:
1266 Ssfdc.Model = SSFDC8MB;
1267 Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS512;
1268 Ssfdc.MaxZones = 1;
1269 Ssfdc.MaxBlocks = 1024;
1270 Ssfdc.MaxLogBlocks = 1000;
1271 Ssfdc.MaxSectors = 16;
1272 break;
1273 case SSFDC16MB:
1274 Ssfdc.Model = SSFDC16MB;
1275 Ssfdc.Attribute = FLASH | AD3CYC | BS32 | PS512;
1276 Ssfdc.MaxZones = 1;
1277 Ssfdc.MaxBlocks = 1024;
1278 Ssfdc.MaxLogBlocks = 1000;
1279 Ssfdc.MaxSectors = 32;
1280 break;
1281 case SSFDC32MB:
1282 Ssfdc.Model = SSFDC32MB;
1283 Ssfdc.Attribute = FLASH | AD3CYC | BS32 | PS512;
1284 Ssfdc.MaxZones = 2;
1285 Ssfdc.MaxBlocks = 1024;
1286 Ssfdc.MaxLogBlocks = 1000;
1287 Ssfdc.MaxSectors = 32;
1288 break;
1289 case SSFDC64MB:
1290 Ssfdc.Model = SSFDC64MB;
1291 Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512;
1292 Ssfdc.MaxZones = 4;
1293 Ssfdc.MaxBlocks = 1024;
1294 Ssfdc.MaxLogBlocks = 1000;
1295 Ssfdc.MaxSectors = 32;
1296 break;
1297 case SSFDC128MB:
1298 Ssfdc.Model = SSFDC128MB;
1299 Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512;
1300 Ssfdc.MaxZones = 8;
1301 Ssfdc.MaxBlocks = 1024;
1302 Ssfdc.MaxLogBlocks = 1000;
1303 Ssfdc.MaxSectors = 32;
1304 break;
1305 case SSFDC256MB:
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;
1312 break;
1313 case SSFDC512MB:
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;
1320 break;
1321 case SSFDC1GB:
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;
1328 break;
1329 case SSFDC2GB:
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;
1336 break;
1337 default:
1338 Ssfdc.Model = NOSSFDC;
1339 return(ERROR);
1342 return(SUCCESS);
1345 //----- _Check_D_DevCode() ---------------------------------------------
1346 BYTE _Check_D_DevCode(BYTE dcode)
1348 switch(dcode){
1349 case 0x6E:
1350 case 0xE8:
1351 case 0xEC: return(SSFDC1MB); // 8Mbit (1M) NAND
1352 case 0x64:
1353 case 0xEA: return(SSFDC2MB); // 16Mbit (2M) NAND
1354 case 0x6B:
1355 case 0xE3:
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 Control Subroutine
1371 ////----- Cnt_D_Reset() ----------------------------------------------
1372 //void Cnt_D_Reset(void)
1374 // _Hw_D_LedOff();
1375 // _Hw_D_SetRdStandby();
1376 // _Hw_D_VccOff();
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
1384 // _Hw_D_VccOn();
1385 // _Hw_D_SetRdStandby();
1386 // _Wait_D_Timer(TIME_PON);
1388 // if (_Hw_D_ChkPower())
1389 // {
1390 // _Hw_D_EnableOB(); // Set SM_REG_CTRL_5 Reg. to 0x83
1391 // return(SUCCESS);
1392 // }
1394 // _Hw_D_SetVccOff();
1395 // return(ERROR);
1398 ////----- Cnt_D_PowerOff() ----------------------------------------------
1399 //void Cnt_D_PowerOff(void)
1401 // _Hw_D_SetRdStandby();
1402 // _Hw_D_SetVccOff();
1403 // _Hw_D_VccOff();
1406 ////----- Cnt_D_LedOn() ----------------------------------------------
1407 //void Cnt_D_LedOn(void)
1409 // _Hw_D_LedOn();
1412 ////----- Cnt_D_LedOff() ----------------------------------------------
1413 //void Cnt_D_LedOff(void)
1415 // _Hw_D_LedOff();
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)
1430 // char i,j,k;
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
1438 // {
1439 // j++; k=0;
1440 // }
1441 // else
1442 // {
1443 // j=0; k++;
1444 // }
1446 // if (j>3)
1447 // return(SUCCESS); // Card exist in Slot
1448 // if (k>3)
1449 // return(ERROR); // NO Card exist in Slot
1451 // _Wait_D_Timer(TIME_CDCHK);
1452 // }
1454 // return(ERROR);
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
1469 // char i;
1471 // for(i=0; i<8; i++) {
1472 // if (_Hw_D_ChkWP())
1473 // return(ERROR);
1474 // _Wait_D_Timer(TIME_WPCHK);
1475 // }
1477 // return(SUCCESS);
1481 //SmartMedia ECC Control Subroutine
1482 //----- Check_D_ReadError() ----------------------------------------------
1483 int Check_D_ReadError(BYTE *redundant)
1485 return SUCCESS;
1488 //----- Check_D_Correct() ----------------------------------------------
1489 int Check_D_Correct(BYTE *buf,BYTE *redundant)
1491 return SUCCESS;
1494 //----- Check_D_CISdata() ----------------------------------------------
1495 int Check_D_CISdata(BYTE *buf, BYTE *redundant)
1497 BYTE cis[] = {0x01, 0x03, 0xD9, 0x01, 0xFF, 0x18, 0x02,
1498 0xDF, 0x01, 0x20};
1500 int cis_len = sizeof(cis);
1502 if (!IsSSFDCCompliance && !IsXDCompliance)
1503 return SUCCESS;
1505 if (!memcmp(redundant + 0x0D, EccBuf, 3))
1506 return memcmp(buf, cis, cis_len);
1508 if (!_Correct_D_SwECC(buf, redundant + 0x0D, EccBuf))
1509 return memcmp(buf, cis, cis_len);
1511 buf += 0x100;
1512 if (!memcmp(redundant + 0x08, EccBuf + 0x03, 3))
1513 return memcmp(buf, cis, cis_len);
1515 if (!_Correct_D_SwECC(buf, redundant + 0x08, EccBuf + 0x03))
1516 return memcmp(buf, cis, cis_len);
1518 return ERROR;
1521 //----- Set_D_RightECC() ----------------------------------------------
1522 void Set_D_RightECC(BYTE *redundant)
1524 // Driver ¤£°µ ECC Check
1525 return;
1526 //StringCopy((char *)(redundant+0x0D),(char *)EccBuf,3);
1527 //StringCopy((char *)(redundant+0x08),(char *)(EccBuf+0x03),3);
1530 ////----- _Calc_D_ECCdata() ----------------------------------------------
1531 //void _Calc_D_ECCdata(BYTE *buf)
1533 //#ifdef HW_ECC_SUPPORTED
1534 //#else
1535 // _Calculate_D_SwECC(buf,EccBuf);
1536 // buf+=0x0100;
1537 // _Calculate_D_SwECC(buf,EccBuf+0x03);
1538 //#endif
1541 ////----- _Set_D_ECCdata() ----------------------------------------------
1542 //void _Set_D_ECCdata(BYTE add,BYTE *redundant)
1544 // //if (add==EVEN && (Ssfdc.Attribute &MPS)==PS256)
1545 // // return;
1547 // // for 256byte/page
1548 // StringCopy((char *)(redundant+0x0D),(char *)EccBuf,3);
1549 // StringCopy((char *)(redundant+0x08),(char *)(EccBuf+0x03),3);
1554 //----- SM_ReadBlock() ---------------------------------------------
1555 int SM_ReadBlock(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
1557 PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
1558 NTSTATUS ntStatus;
1559 WORD addr;
1561 ENE_LoadBinCode(fdoExt, SM_RW_PATTERN);
1563 addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
1564 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
1566 // Read sect data
1567 RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
1568 pBulkCbw->dCBWSignature = CBW_SIGNTURE;
1569 pBulkCbw->bCBWLun = CBW_LUN;
1570 pBulkCbw->dCBWDataTransferLength = 0x200;
1571 pBulkCbw->bmCBWFlags = 0x80;
1572 pBulkCbw->CBWCb[0] = 0xF1;
1573 pBulkCbw->CBWCb[1] = 0x02;
1574 pBulkCbw->CBWCb[4] = (BYTE)addr;
1575 pBulkCbw->CBWCb[3] = (BYTE)(addr/0x0100);
1576 pBulkCbw->CBWCb[2] = Media.Zone/2;
1578 ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_READ, buf);
1580 if (!NT_SUCCESS(ntStatus))
1581 return(ERROR);
1583 // Read redundant
1584 RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
1585 pBulkCbw->dCBWSignature = CBW_SIGNTURE;
1586 pBulkCbw->bCBWLun = CBW_LUN;
1587 pBulkCbw->dCBWDataTransferLength = 0x10;
1588 pBulkCbw->bmCBWFlags = 0x80;
1589 pBulkCbw->CBWCb[0] = 0xF1;
1590 pBulkCbw->CBWCb[1] = 0x03;
1591 pBulkCbw->CBWCb[4] = (BYTE)addr;
1592 pBulkCbw->CBWCb[3] = (BYTE)(addr/0x0100);
1593 pBulkCbw->CBWCb[2] = Media.Zone/2;
1594 pBulkCbw->CBWCb[5] = 0;
1595 pBulkCbw->CBWCb[6] = 1;
1597 ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_READ, redundant);
1599 if (!NT_SUCCESS(ntStatus))
1600 return(ERROR);
1602 return(SUCCESS);