smilsub.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  1. #include <linux/slab.h>
  2. #include "usb.h"
  3. #include "scsiglue.h"
  4. #include "transport.h"
  5. //#include "init.h"
  6. //#include "stdlib.h"
  7. //#include "EUCR6SK.h"
  8. #include "smcommon.h"
  9. #include "smil.h"
  10. void _Set_D_SsfdcRdCmd (BYTE);
  11. void _Set_D_SsfdcRdAddr (BYTE);
  12. void _Set_D_SsfdcRdChip (void);
  13. void _Set_D_SsfdcRdStandby (void);
  14. void _Start_D_SsfdcRdHwECC (void);
  15. void _Stop_D_SsfdcRdHwECC (void);
  16. void _Load_D_SsfdcRdHwECC (BYTE);
  17. void _Set_D_SsfdcWrCmd (BYTE);
  18. void _Set_D_SsfdcWrAddr (BYTE);
  19. void _Set_D_SsfdcWrBlock (void);
  20. void _Set_D_SsfdcWrStandby (void);
  21. void _Start_D_SsfdcWrHwECC (void);
  22. void _Load_D_SsfdcWrHwECC (BYTE);
  23. int _Check_D_SsfdcBusy (WORD);
  24. int _Check_D_SsfdcStatus (void);
  25. void _Reset_D_SsfdcErr (void);
  26. void _Read_D_SsfdcBuf (BYTE *);
  27. void _Write_D_SsfdcBuf (BYTE *);
  28. void _Read_D_SsfdcByte (BYTE *);
  29. void _ReadRedt_D_SsfdcBuf (BYTE *);
  30. void _WriteRedt_D_SsfdcBuf (BYTE *);
  31. BYTE _Check_D_DevCode (BYTE);
  32. void _Set_D_ECCdata (BYTE,BYTE *);
  33. void _Calc_D_ECCdata (BYTE *);
  34. //void SM_ReadDataWithDMA (PFDO_DEVICE_EXTENSION, BYTE *, WORD);
  35. //void SM_WriteDataWithDMA (PFDO_DEVICE_EXTENSION, BYTE *, WORD);
  36. //
  37. struct SSFDCTYPE Ssfdc;
  38. struct ADDRESS Media;
  39. struct CIS_AREA CisArea;
  40. static BYTE EccBuf[6];
  41. extern PBYTE SMHostAddr;
  42. extern DWORD ErrXDCode;
  43. extern WORD ReadBlock;
  44. extern WORD WriteBlock;
  45. //KEVENT SM_DMADoneEvent;
  46. #define EVEN 0 // Even Page for 256byte/page
  47. #define ODD 1 // Odd Page for 256byte/page
  48. //SmartMedia Redundant buffer data Control Subroutine
  49. //----- Check_D_DataBlank() --------------------------------------------
  50. int Check_D_DataBlank(BYTE *redundant)
  51. {
  52. char i;
  53. for(i=0; i<REDTSIZE; i++)
  54. if (*redundant++!=0xFF)
  55. return(ERROR);
  56. return(SMSUCCESS);
  57. }
  58. //----- Check_D_FailBlock() --------------------------------------------
  59. int Check_D_FailBlock(BYTE *redundant)
  60. {
  61. redundant+=REDT_BLOCK;
  62. if (*redundant==0xFF)
  63. return(SMSUCCESS);
  64. if (!*redundant)
  65. return(ERROR);
  66. if (hweight8(*redundant)<7)
  67. return(ERROR);
  68. return(SMSUCCESS);
  69. }
  70. //----- Check_D_DataStatus() -------------------------------------------
  71. int Check_D_DataStatus(BYTE *redundant)
  72. {
  73. redundant+=REDT_DATA;
  74. if (*redundant==0xFF)
  75. return(SMSUCCESS);
  76. if (!*redundant)
  77. {
  78. ErrXDCode = ERR_DataStatus;
  79. return(ERROR);
  80. }
  81. else
  82. ErrXDCode = NO_ERROR;
  83. if (hweight8(*redundant)<5)
  84. return(ERROR);
  85. return(SMSUCCESS);
  86. }
  87. //----- Load_D_LogBlockAddr() ------------------------------------------
  88. int Load_D_LogBlockAddr(BYTE *redundant)
  89. {
  90. WORD addr1,addr2;
  91. //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
  92. //ADDRESS_T bb = (ADDRESS_T) &Media;
  93. addr1=(WORD)*(redundant+REDT_ADDR1H)*0x0100+(WORD)*(redundant+REDT_ADDR1L);
  94. addr2=(WORD)*(redundant+REDT_ADDR2H)*0x0100+(WORD)*(redundant+REDT_ADDR2L);
  95. if (addr1==addr2)
  96. if ((addr1 &0xF000)==0x1000)
  97. { Media.LogBlock=(addr1 &0x0FFF)/2; return(SMSUCCESS); }
  98. if (hweight16((WORD)(addr1^addr2))!=0x01) return(ERROR);
  99. if ((addr1 &0xF000)==0x1000)
  100. if (!(hweight16(addr1) &0x01))
  101. { Media.LogBlock=(addr1 &0x0FFF)/2; return(SMSUCCESS); }
  102. if ((addr2 &0xF000)==0x1000)
  103. if (!(hweight16(addr2) &0x01))
  104. { Media.LogBlock=(addr2 &0x0FFF)/2; return(SMSUCCESS); }
  105. return(ERROR);
  106. }
  107. //----- Clr_D_RedundantData() ------------------------------------------
  108. void Clr_D_RedundantData(BYTE *redundant)
  109. {
  110. char i;
  111. for(i=0; i<REDTSIZE; i++)
  112. *(redundant+i)=0xFF;
  113. }
  114. //----- Set_D_LogBlockAddr() -------------------------------------------
  115. void Set_D_LogBlockAddr(BYTE *redundant)
  116. {
  117. WORD addr;
  118. *(redundant+REDT_BLOCK)=0xFF;
  119. *(redundant+REDT_DATA) =0xFF;
  120. addr=Media.LogBlock*2+0x1000;
  121. if ((hweight16(addr)%2))
  122. addr++;
  123. *(redundant+REDT_ADDR1H)=*(redundant+REDT_ADDR2H)=(BYTE)(addr/0x0100);
  124. *(redundant+REDT_ADDR1L)=*(redundant+REDT_ADDR2L)=(BYTE)addr;
  125. }
  126. //----- Set_D_FailBlock() ----------------------------------------------
  127. void Set_D_FailBlock(BYTE *redundant)
  128. {
  129. char i;
  130. for(i=0; i<REDTSIZE; i++)
  131. *redundant++=(BYTE)((i==REDT_BLOCK)?0xF0:0xFF);
  132. }
  133. //----- Set_D_DataStaus() ----------------------------------------------
  134. void Set_D_DataStaus(BYTE *redundant)
  135. {
  136. redundant+=REDT_DATA;
  137. *redundant=0x00;
  138. }
  139. //SmartMedia Function Command Subroutine
  140. // 6250 CMD 6
  141. //----- Ssfdc_D_Reset() ------------------------------------------------
  142. void Ssfdc_D_Reset(struct us_data *us)
  143. {
  144. //NTSTATUS ntStatus = STATUS_SUCCESS;
  145. //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
  146. //BYTE buf[0x200];
  147. //printk("Ssfdc_D_Reset --- But do nothing !!\n");
  148. return;
  149. /* RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
  150. pBulkCbw->dCBWSignature = CBW_SIGNTURE;
  151. pBulkCbw->bCBWLun = CBW_LUN;
  152. //pBulkCbw->dCBWDataTransferLength = 0x200;
  153. pBulkCbw->bmCBWFlags = 0x80;
  154. pBulkCbw->CBWCb[0] = 0xF2;
  155. pBulkCbw->CBWCb[1] = 0x07;
  156. ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_READ, NULL);
  157. if (!NT_SUCCESS(ntStatus))
  158. {
  159. ENE_Print("Ssfdc_D_Reset Fail !!\n");
  160. //return ntStatus;
  161. }*/
  162. }
  163. //----- Ssfdc_D_ReadCisSect() ------------------------------------------
  164. int Ssfdc_D_ReadCisSect(struct us_data *us, BYTE *buf,BYTE *redundant)
  165. {
  166. BYTE zone,sector;
  167. WORD block;
  168. //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
  169. //ADDRESS_T bb = (ADDRESS_T) &Media;
  170. zone=Media.Zone; block=Media.PhyBlock; sector=Media.Sector;
  171. Media.Zone=0;
  172. Media.PhyBlock=CisArea.PhyBlock;
  173. Media.Sector=CisArea.Sector;
  174. if (Ssfdc_D_ReadSect(us,buf,redundant))
  175. {
  176. Media.Zone=zone; Media.PhyBlock=block; Media.Sector=sector;
  177. return(ERROR);
  178. }
  179. Media.Zone=zone; Media.PhyBlock=block; Media.Sector=sector;
  180. return(SMSUCCESS);
  181. }
  182. /*
  183. ////----- Ssfdc_D_WriteRedtMode() ----------------------------------------
  184. //void Ssfdc_D_WriteRedtMode(void)
  185. //{
  186. // _Set_D_SsfdcRdCmd (RST_CHIP);
  187. // _Check_D_SsfdcBusy (BUSY_RESET);
  188. // _Set_D_SsfdcRdCmd (READ_REDT);
  189. // _Check_D_SsfdcBusy (BUSY_READ);
  190. // _Set_D_SsfdcRdStandby ();
  191. //}
  192. //
  193. ////----- Ssfdc_D_ReadID() -----------------------------------------------
  194. //void Ssfdc_D_ReadID(BYTE *buf, BYTE ReadID)
  195. //{
  196. // _Set_D_SsfdcRdCmd (ReadID);
  197. // _Set_D_SsfdcRdChip ();
  198. // _Read_D_SsfdcByte (buf++);
  199. // _Read_D_SsfdcByte (buf++);
  200. // _Read_D_SsfdcByte (buf++);
  201. // _Read_D_SsfdcByte (buf);
  202. // _Set_D_SsfdcRdStandby ();
  203. //}
  204. */
  205. // 6250 CMD 1
  206. //----- Ssfdc_D_ReadSect() ---------------------------------------------
  207. int Ssfdc_D_ReadSect(struct us_data *us, BYTE *buf,BYTE *redundant)
  208. {
  209. struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
  210. int result;
  211. WORD addr;
  212. result = ENE_LoadBinCode(us, SM_RW_PATTERN);
  213. if (result != USB_STOR_XFER_GOOD)
  214. {
  215. printk("Load SM RW Code Fail !!\n");
  216. return USB_STOR_TRANSPORT_ERROR;
  217. }
  218. addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
  219. addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
  220. // Read sect data
  221. memset(bcb, 0, sizeof(struct bulk_cb_wrap));
  222. bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
  223. bcb->DataTransferLength = 0x200;
  224. bcb->Flags = 0x80;
  225. bcb->CDB[0] = 0xF1;
  226. bcb->CDB[1] = 0x02;
  227. bcb->CDB[4] = (BYTE)addr;
  228. bcb->CDB[3] = (BYTE)(addr/0x0100);
  229. bcb->CDB[2] = Media.Zone/2;
  230. result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0);
  231. if (result != USB_STOR_XFER_GOOD)
  232. return USB_STOR_TRANSPORT_ERROR;
  233. // Read redundant
  234. memset(bcb, 0, sizeof(struct bulk_cb_wrap));
  235. bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
  236. bcb->DataTransferLength = 0x10;
  237. bcb->Flags = 0x80;
  238. bcb->CDB[0] = 0xF1;
  239. bcb->CDB[1] = 0x03;
  240. bcb->CDB[4] = (BYTE)addr;
  241. bcb->CDB[3] = (BYTE)(addr/0x0100);
  242. bcb->CDB[2] = Media.Zone/2;
  243. bcb->CDB[8] = 0;
  244. bcb->CDB[9] = 1;
  245. result = ENE_SendScsiCmd(us, FDIR_READ, redundant, 0);
  246. if (result != USB_STOR_XFER_GOOD)
  247. return USB_STOR_TRANSPORT_ERROR;
  248. return USB_STOR_TRANSPORT_GOOD;
  249. }
  250. //----- Ssfdc_D_ReadBlock() ---------------------------------------------
  251. int Ssfdc_D_ReadBlock(struct us_data *us, WORD count, BYTE *buf,BYTE *redundant)
  252. {
  253. struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
  254. int result;
  255. WORD addr;
  256. //printk("Ssfdc_D_ReadBlock\n");
  257. result = ENE_LoadBinCode(us, SM_RW_PATTERN);
  258. if (result != USB_STOR_XFER_GOOD)
  259. {
  260. printk("Load SM RW Code Fail !!\n");
  261. return USB_STOR_TRANSPORT_ERROR;
  262. }
  263. addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
  264. addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
  265. // Read sect data
  266. memset(bcb, 0, sizeof(struct bulk_cb_wrap));
  267. bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
  268. bcb->DataTransferLength = 0x200*count;
  269. bcb->Flags = 0x80;
  270. bcb->CDB[0] = 0xF1;
  271. bcb->CDB[1] = 0x02;
  272. bcb->CDB[4] = (BYTE)addr;
  273. bcb->CDB[3] = (BYTE)(addr/0x0100);
  274. bcb->CDB[2] = Media.Zone/2;
  275. result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0);
  276. if (result != USB_STOR_XFER_GOOD)
  277. return USB_STOR_TRANSPORT_ERROR;
  278. // Read redundant
  279. memset(bcb, 0, sizeof(struct bulk_cb_wrap));
  280. bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
  281. bcb->DataTransferLength = 0x10;
  282. bcb->Flags = 0x80;
  283. bcb->CDB[0] = 0xF1;
  284. bcb->CDB[1] = 0x03;
  285. bcb->CDB[4] = (BYTE)addr;
  286. bcb->CDB[3] = (BYTE)(addr/0x0100);
  287. bcb->CDB[2] = Media.Zone/2;
  288. bcb->CDB[8] = 0;
  289. bcb->CDB[9] = 1;
  290. result = ENE_SendScsiCmd(us, FDIR_READ, redundant, 0);
  291. if (result != USB_STOR_XFER_GOOD)
  292. return USB_STOR_TRANSPORT_ERROR;
  293. return USB_STOR_TRANSPORT_GOOD;
  294. }
  295. /*
  296. ////----- Ssfdc_D_ReadSect_DMA() ---------------------------------------------
  297. //int Ssfdc_D_ReadSect_DMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
  298. //{
  299. // WORD SectByteCount, addr;
  300. // DWORD Buffer[4];
  301. // WORD len;
  302. //
  303. // if (!_Hw_D_ChkCardIn())
  304. // return(ERROR);
  305. // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
  306. // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
  307. // // cycle starting address
  308. // SM_STARTADDR_LSB = 0x00;
  309. // SM_STARTADDR_IISB = (BYTE)addr;
  310. // SM_STARTADDR_IIISB = (BYTE)(addr/0x0100);
  311. // SM_STARTADDR_MSB = Media.Zone/2;
  312. //
  313. // //Sector byte count = 0x200(DMA)
  314. // SectByteCount = 0x20f;
  315. // SM_BYTECNT_LO = (BYTE)SectByteCount;
  316. // SM_CMD_CTRL3 = (SM_CMD_CTRL3 & 0xFC) | (BYTE)(SectByteCount/0x0100);
  317. // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate )
  318. // SM_FIFO_CTRL = (SM_APB08_MASK | SM_DMAEN_MASK | SM_DMA_UPSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK);
  319. // else
  320. // SM_FIFO_CTRL = (SM_APB32_MASK | SM_DMAEN_MASK | SM_DMA_UPSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK);
  321. //
  322. // _Hw_D_EccRdReset();
  323. // _Hw_D_EccRdStart();
  324. //
  325. // SM_CMD_CTRL1 = (SM_CMD_READ_1);
  326. // SM_CMD_CTRL1 = (SM_CMD_READ_1 | SM_CMD_START_BIT);
  327. //
  328. // SectByteCount = 0x1ff;
  329. // //SM_ReadDataWithDMA(fdoExt, buf, SectByteCount);
  330. // //_ReadRedt_D_SsfdcBuf(redundant);
  331. // len = 0x1000 - ((WORD)(buf) & 0x0FFF);
  332. // if (len < 0x200)
  333. // {
  334. // SM_ReadDataWithDMA(fdoExt, buf, len-1);
  335. // SM_ReadDataWithDMA(fdoExt, buf+len, SectByteCount-len);
  336. // //ENE_Print("Read DMA !!! buf1 = %p, len = %x, buf2 = %p\n", buf, len, buf+len);
  337. // }
  338. // else
  339. // SM_ReadDataWithDMA(fdoExt, buf, SectByteCount);
  340. //
  341. // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate )
  342. // {
  343. // _ReadRedt_D_SsfdcBuf(redundant);
  344. // }
  345. // else
  346. // {
  347. // Buffer[0] = READ_PORT_DWORD(SM_REG_DATA);
  348. // Buffer[1] = READ_PORT_DWORD(SM_REG_DATA);
  349. // Buffer[2] = READ_PORT_DWORD(SM_REG_DATA);
  350. // Buffer[3] = READ_PORT_DWORD(SM_REG_DATA);
  351. // memcpy(redundant, Buffer, 0x10);
  352. // }
  353. //
  354. // while ( _Hw_D_ChkCardIn() )
  355. // {
  356. // if((READ_PORT_BYTE(SM_REG_INT_STATUS) & 0x10))
  357. // {
  358. // WRITE_PORT_BYTE(SM_REG_INT_STATUS, 0x10);
  359. // break;
  360. // }
  361. // }
  362. // _Hw_D_EccRdStop();
  363. // _Hw_D_SetRdStandby();
  364. // _Load_D_SsfdcRdHwECC(EVEN);
  365. //
  366. // _Calc_D_ECCdata(buf);
  367. // _Set_D_SsfdcRdStandby();
  368. //
  369. // if (!_Hw_D_ChkCardIn())
  370. // return(ERROR);
  371. // return(SMSUCCESS);
  372. //}
  373. //
  374. ////----- Ssfdc_D_ReadSect_PIO() ---------------------------------------------
  375. //int Ssfdc_D_ReadSect_PIO(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
  376. //{
  377. // _Set_D_SsfdcRdCmd(READ);
  378. // _Set_D_SsfdcRdAddr(EVEN);
  379. //
  380. // if (_Check_D_SsfdcBusy(BUSY_READ))
  381. // { _Reset_D_SsfdcErr(); return(ERROR); }
  382. //
  383. // _Start_D_SsfdcRdHwECC();
  384. // _Read_D_SsfdcBuf(buf);
  385. // _Stop_D_SsfdcRdHwECC();
  386. // _ReadRedt_D_SsfdcBuf(redundant);
  387. // _Load_D_SsfdcRdHwECC(EVEN);
  388. //
  389. // if (_Check_D_SsfdcBusy(BUSY_READ))
  390. // { _Reset_D_SsfdcErr(); return(ERROR); }
  391. //
  392. // _Calc_D_ECCdata(buf);
  393. // _Set_D_SsfdcRdStandby();
  394. // return(SMSUCCESS);
  395. //}
  396. // 6250 CMD 3
  397. //----- Ssfdc_D_WriteSect() --------------------------------------------
  398. int Ssfdc_D_WriteSect(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
  399. {
  400. PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
  401. NTSTATUS ntStatus;
  402. WORD addr;
  403. //ENE_Print("SMILSUB --- Ssfdc_D_WriteSect\n");
  404. ENE_LoadBinCode(fdoExt, SM_RW_PATTERN);
  405. addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
  406. addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
  407. // Write sect data
  408. RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
  409. pBulkCbw->dCBWSignature = CBW_SIGNTURE;
  410. pBulkCbw->bCBWLun = CBW_LUN;
  411. pBulkCbw->dCBWDataTransferLength = 0x200;
  412. pBulkCbw->bmCBWFlags = 0x00;
  413. pBulkCbw->CBWCb[0] = 0xF0;
  414. pBulkCbw->CBWCb[1] = 0x04;
  415. //pBulkCbw->CBWCb[4] = (BYTE)addr;
  416. //pBulkCbw->CBWCb[3] = (BYTE)(addr/0x0100);
  417. //pBulkCbw->CBWCb[2] = Media.Zone/2;
  418. //pBulkCbw->CBWCb[5] = *(redundant+REDT_ADDR1H);
  419. //pBulkCbw->CBWCb[6] = *(redundant+REDT_ADDR1L);
  420. pBulkCbw->CBWCb[7] = (BYTE)addr;
  421. pBulkCbw->CBWCb[6] = (BYTE)(addr/0x0100);
  422. pBulkCbw->CBWCb[5] = Media.Zone/2;
  423. pBulkCbw->CBWCb[8] = *(redundant+REDT_ADDR1H);
  424. pBulkCbw->CBWCb[9] = *(redundant+REDT_ADDR1L);
  425. ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_WRITE, buf);
  426. if (!NT_SUCCESS(ntStatus))
  427. return(ERROR);
  428. // // For Test
  429. // {
  430. // BYTE bf[0x200], rdd[0x10];
  431. // ULONG i;
  432. //
  433. // RtlZeroMemory(bf, 0x200);
  434. // RtlZeroMemory(rdd, 0x10);
  435. // ntStatus = SM_ReadBlock(fdoExt, bf, rdd);
  436. // for (i=0; i<0x200; i++)
  437. // {
  438. // if (buf[i] != bf[i])
  439. // ENE_Print("buf[%x] = %x, bf[%x] = %x\n", buf, bf);
  440. // }
  441. // if (!NT_SUCCESS(ntStatus))
  442. // ENE_Print("Error\n");
  443. // }
  444. return(SMSUCCESS);
  445. }
  446. */
  447. //----- Ssfdc_D_CopyBlock() --------------------------------------------
  448. int Ssfdc_D_CopyBlock(struct us_data *us, WORD count, BYTE *buf,BYTE *redundant)
  449. {
  450. struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
  451. int result;
  452. //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
  453. //NTSTATUS ntStatus;
  454. WORD ReadAddr, WriteAddr;
  455. //printk("Ssfdc_D_WriteSect --- ZONE = %x, ReadBlock = %x, WriteBlock = %x\n", Media.Zone, ReadBlock, WriteBlock);
  456. result = ENE_LoadBinCode(us, SM_RW_PATTERN);
  457. if (result != USB_STOR_XFER_GOOD)
  458. {
  459. printk("Load SM RW Code Fail !!\n");
  460. return USB_STOR_TRANSPORT_ERROR;
  461. }
  462. ReadAddr = (WORD)Media.Zone*Ssfdc.MaxBlocks+ReadBlock;
  463. ReadAddr = ReadAddr*(WORD)Ssfdc.MaxSectors;
  464. WriteAddr = (WORD)Media.Zone*Ssfdc.MaxBlocks+WriteBlock;
  465. WriteAddr = WriteAddr*(WORD)Ssfdc.MaxSectors;
  466. // Write sect data
  467. memset(bcb, 0, sizeof(struct bulk_cb_wrap));
  468. bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
  469. bcb->DataTransferLength = 0x200*count;
  470. bcb->Flags = 0x00;
  471. bcb->CDB[0] = 0xF0;
  472. bcb->CDB[1] = 0x08;
  473. bcb->CDB[7] = (BYTE)WriteAddr;
  474. bcb->CDB[6] = (BYTE)(WriteAddr/0x0100);
  475. bcb->CDB[5] = Media.Zone/2;
  476. bcb->CDB[8] = *(redundant+REDT_ADDR1H);
  477. bcb->CDB[9] = *(redundant+REDT_ADDR1L);
  478. bcb->CDB[10] = Media.Sector;
  479. if (ReadBlock != NO_ASSIGN)
  480. {
  481. bcb->CDB[4] = (BYTE)ReadAddr;
  482. bcb->CDB[3] = (BYTE)(ReadAddr/0x0100);
  483. bcb->CDB[2] = Media.Zone/2;
  484. }
  485. else
  486. bcb->CDB[11] = 1;
  487. result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0);
  488. if (result != USB_STOR_XFER_GOOD)
  489. return USB_STOR_TRANSPORT_ERROR;
  490. return USB_STOR_TRANSPORT_GOOD;
  491. }
  492. /*
  493. //----- Ssfdc_D_WriteBlock() --------------------------------------------
  494. int Ssfdc_D_WriteBlock(PFDO_DEVICE_EXTENSION fdoExt, WORD count, BYTE *buf,BYTE *redundant)
  495. {
  496. PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
  497. NTSTATUS ntStatus;
  498. WORD addr;
  499. //ENE_Print("SMILSUB --- Ssfdc_D_WriteSect\n");
  500. ENE_LoadBinCode(fdoExt, SM_RW_PATTERN);
  501. addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
  502. addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
  503. // Write sect data
  504. RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
  505. pBulkCbw->dCBWSignature = CBW_SIGNTURE;
  506. pBulkCbw->bCBWLun = CBW_LUN;
  507. pBulkCbw->dCBWDataTransferLength = 0x200*count;
  508. pBulkCbw->bmCBWFlags = 0x00;
  509. pBulkCbw->CBWCb[0] = 0xF0;
  510. pBulkCbw->CBWCb[1] = 0x04;
  511. pBulkCbw->CBWCb[7] = (BYTE)addr;
  512. pBulkCbw->CBWCb[6] = (BYTE)(addr/0x0100);
  513. pBulkCbw->CBWCb[5] = Media.Zone/2;
  514. pBulkCbw->CBWCb[8] = *(redundant+REDT_ADDR1H);
  515. pBulkCbw->CBWCb[9] = *(redundant+REDT_ADDR1L);
  516. ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_WRITE, buf);
  517. if (!NT_SUCCESS(ntStatus))
  518. return(ERROR);
  519. // // For Test
  520. // {
  521. // BYTE bf[0x200], rdd[0x10];
  522. // ULONG i;
  523. //
  524. // RtlZeroMemory(bf, 0x200);
  525. // RtlZeroMemory(rdd, 0x10);
  526. // ntStatus = SM_ReadBlock(fdoExt, bf, rdd);
  527. // for (i=0; i<0x200; i++)
  528. // {
  529. // if (buf[i] != bf[i])
  530. // ENE_Print("buf[%x] = %x, bf[%x] = %x\n", buf, bf);
  531. // }
  532. // if (!NT_SUCCESS(ntStatus))
  533. // ENE_Print("Error\n");
  534. // }
  535. return(SMSUCCESS);
  536. }
  537. //
  538. ////----- Ssfdc_D_WriteSect_DMA() --------------------------------------------
  539. //int Ssfdc_D_WriteSect_DMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
  540. //{
  541. // WORD SectByteCount, addr;
  542. // DWORD Buffer[4];
  543. // WORD len;
  544. //
  545. // if (!_Hw_D_ChkCardIn())
  546. // return(ERROR);
  547. // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
  548. // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
  549. // // cycle starting address
  550. // SM_STARTADDR_LSB = 0x00;
  551. // SM_STARTADDR_IISB = (BYTE)addr;
  552. // SM_STARTADDR_IIISB = (BYTE)(addr/0x0100);
  553. // SM_STARTADDR_MSB = Media.Zone/2;
  554. //
  555. // //Sector byte count (DMA)
  556. // SectByteCount = 0x20f;
  557. // SM_BYTECNT_LO = (BYTE)SectByteCount;
  558. // SM_CMD_CTRL3 = (SM_CMD_CTRL3 & 0xFC) | 0x20 | (BYTE)(SectByteCount/0x0100);
  559. // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate )
  560. // SM_FIFO_CTRL = (SM_APB08_MASK | SM_DMAEN_MASK | SM_DMA_DOWNSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK);
  561. // else
  562. // SM_FIFO_CTRL = (SM_APB32_MASK | SM_DMAEN_MASK | SM_DMA_DOWNSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK);
  563. //
  564. // _Hw_D_EccRdReset();
  565. // _Hw_D_EccRdStart();
  566. //
  567. // SM_CMD_CTRL1 = SM_CMD_PAGPRGM_TRUE;
  568. // SM_CMD_CTRL1 = (SM_CMD_PAGPRGM_TRUE | SM_CMD_START_BIT);
  569. //
  570. // SectByteCount = 0x1ff;
  571. // //SM_WriteDataWithDMA(fdoExt, buf, SectByteCount);
  572. // //_WriteRedt_D_SsfdcBuf(redundant);
  573. // len = 0x1000 - ((WORD)(buf) & 0x0FFF);
  574. // if (len < 0x200)
  575. // {
  576. // SM_WriteDataWithDMA(fdoExt, buf, len-1);
  577. // SM_WriteDataWithDMA(fdoExt, buf+len, SectByteCount-len);
  578. // //ENE_Print("Read DMA !!! buf1 = %p, len = %x, buf2 = %p\n", buf, len, buf+len);
  579. // }
  580. // else
  581. // SM_WriteDataWithDMA(fdoExt, buf, SectByteCount);
  582. //
  583. // //T1 = (ULONGLONG)buf & 0xFFFFFFFFFFFFF000;
  584. // //T2 = ((ULONGLONG)buf + 0x1FF) & 0xFFFFFFFFFFFFF000;
  585. // //if (T1 != T2)
  586. // // ENE_Print("Ssfdc_D_WriteSect_DMA !!! buf = %p, T1 = %p, T2 = %p\n", buf, T1, T2);
  587. // //if (T2-T1)
  588. // //{
  589. // // l1 = (WORD)(T2 - (ULONGLONG)buf);
  590. // // SM_WriteDataWithDMA(fdoExt, buf, l1-1);
  591. // // SM_WriteDataWithDMA(fdoExt, (PBYTE)T2, SectByteCount-l1);
  592. // //}
  593. // //else
  594. // // SM_WriteDataWithDMA(fdoExt, buf, SectByteCount);
  595. //
  596. // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate )
  597. // {
  598. // _WriteRedt_D_SsfdcBuf(redundant);
  599. // }
  600. // else
  601. // {
  602. // memcpy(Buffer, redundant, 0x10);
  603. // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[0]);
  604. // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[1]);
  605. // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[2]);
  606. // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[3]);
  607. // }
  608. //
  609. // while ( _Hw_D_ChkCardIn() )
  610. // {
  611. // if ((READ_PORT_BYTE(SM_REG_INT_STATUS) & 0x10))
  612. // {
  613. // WRITE_PORT_BYTE(SM_REG_INT_STATUS, 0x10);
  614. // break;
  615. // }
  616. // }
  617. // _Hw_D_EccRdStop();
  618. // _Hw_D_SetRdStandby();
  619. //
  620. // _Set_D_SsfdcWrStandby();
  621. // _Set_D_SsfdcRdStandby();
  622. // if (!_Hw_D_ChkCardIn())
  623. // return(ERROR);
  624. //
  625. // return(SMSUCCESS);
  626. //}
  627. //
  628. ////----- Ssfdc_D_WriteSect_PIO() --------------------------------------------
  629. //int Ssfdc_D_WriteSect_PIO(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
  630. //{
  631. // _Calc_D_ECCdata(buf);
  632. // _Set_D_SsfdcWrCmd(WRDATA);
  633. // _Set_D_SsfdcWrAddr(EVEN);
  634. // _Start_D_SsfdcWrHwECC();
  635. //
  636. // _Write_D_SsfdcBuf(buf);
  637. //
  638. // _Load_D_SsfdcWrHwECC(EVEN);
  639. // _Set_D_ECCdata(EVEN,redundant);
  640. //
  641. // _WriteRedt_D_SsfdcBuf(redundant);
  642. //
  643. // _Set_D_SsfdcWrCmd(WRITE);
  644. //
  645. // if (_Check_D_SsfdcBusy(BUSY_PROG))
  646. // { _Reset_D_SsfdcErr(); return(ERROR); }
  647. //
  648. // _Set_D_SsfdcWrStandby();
  649. // _Set_D_SsfdcRdStandby();
  650. // return(SMSUCCESS);
  651. //}
  652. */
  653. //----- Ssfdc_D_WriteSectForCopy() -------------------------------------
  654. int Ssfdc_D_WriteSectForCopy(struct us_data *us, BYTE *buf, BYTE *redundant)
  655. {
  656. struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
  657. int result;
  658. //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
  659. //NTSTATUS ntStatus;
  660. WORD addr;
  661. //printk("SMILSUB --- Ssfdc_D_WriteSectForCopy\n");
  662. result = ENE_LoadBinCode(us, SM_RW_PATTERN);
  663. if (result != USB_STOR_XFER_GOOD)
  664. {
  665. printk("Load SM RW Code Fail !!\n");
  666. return USB_STOR_TRANSPORT_ERROR;
  667. }
  668. addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
  669. addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
  670. // Write sect data
  671. memset(bcb, 0, sizeof(struct bulk_cb_wrap));
  672. bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
  673. bcb->DataTransferLength = 0x200;
  674. bcb->Flags = 0x00;
  675. bcb->CDB[0] = 0xF0;
  676. bcb->CDB[1] = 0x04;
  677. bcb->CDB[7] = (BYTE)addr;
  678. bcb->CDB[6] = (BYTE)(addr/0x0100);
  679. bcb->CDB[5] = Media.Zone/2;
  680. bcb->CDB[8] = *(redundant+REDT_ADDR1H);
  681. bcb->CDB[9] = *(redundant+REDT_ADDR1L);
  682. result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0);
  683. if (result != USB_STOR_XFER_GOOD)
  684. return USB_STOR_TRANSPORT_ERROR;
  685. return USB_STOR_TRANSPORT_GOOD;
  686. }
  687. // 6250 CMD 5
  688. //----- Ssfdc_D_EraseBlock() -------------------------------------------
  689. int Ssfdc_D_EraseBlock(struct us_data *us)
  690. {
  691. struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
  692. int result;
  693. WORD addr;
  694. result = ENE_LoadBinCode(us, SM_RW_PATTERN);
  695. if (result != USB_STOR_XFER_GOOD)
  696. {
  697. printk("Load SM RW Code Fail !!\n");
  698. return USB_STOR_TRANSPORT_ERROR;
  699. }
  700. addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
  701. addr=addr*(WORD)Ssfdc.MaxSectors;
  702. memset(bcb, 0, sizeof(struct bulk_cb_wrap));
  703. bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
  704. bcb->DataTransferLength = 0x200;
  705. bcb->Flags = 0x80;
  706. bcb->CDB[0] = 0xF2;
  707. bcb->CDB[1] = 0x06;
  708. bcb->CDB[7] = (BYTE)addr;
  709. bcb->CDB[6] = (BYTE)(addr/0x0100);
  710. bcb->CDB[5] = Media.Zone/2;
  711. result = ENE_SendScsiCmd(us, FDIR_READ, NULL, 0);
  712. if (result != USB_STOR_XFER_GOOD)
  713. return USB_STOR_TRANSPORT_ERROR;
  714. return USB_STOR_TRANSPORT_GOOD;
  715. }
  716. // 6250 CMD 2
  717. //----- Ssfdc_D_ReadRedtData() -----------------------------------------
  718. int Ssfdc_D_ReadRedtData(struct us_data *us, BYTE *redundant)
  719. {
  720. struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
  721. int result;
  722. WORD addr;
  723. BYTE *buf;
  724. result = ENE_LoadBinCode(us, SM_RW_PATTERN);
  725. if (result != USB_STOR_XFER_GOOD)
  726. {
  727. printk("Load SM RW Code Fail !!\n");
  728. return USB_STOR_TRANSPORT_ERROR;
  729. }
  730. addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
  731. addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
  732. memset(bcb, 0, sizeof(struct bulk_cb_wrap));
  733. bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
  734. bcb->DataTransferLength = 0x10;
  735. bcb->Flags = 0x80;
  736. bcb->CDB[0] = 0xF1;
  737. bcb->CDB[1] = 0x03;
  738. bcb->CDB[4] = (BYTE)addr;
  739. bcb->CDB[3] = (BYTE)(addr/0x0100);
  740. bcb->CDB[2] = Media.Zone/2;
  741. bcb->CDB[8] = 0;
  742. bcb->CDB[9] = 1;
  743. buf = kmalloc(0x10, GFP_KERNEL);
  744. //result = ENE_SendScsiCmd(us, FDIR_READ, redundant, 0);
  745. result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0);
  746. memcpy(redundant, buf, 0x10);
  747. kfree(buf);
  748. if (result != USB_STOR_XFER_GOOD)
  749. return USB_STOR_TRANSPORT_ERROR;
  750. return USB_STOR_TRANSPORT_GOOD;
  751. }
  752. // 6250 CMD 4
  753. //----- Ssfdc_D_WriteRedtData() ----------------------------------------
  754. int Ssfdc_D_WriteRedtData(struct us_data *us, BYTE *redundant)
  755. {
  756. struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
  757. int result;
  758. //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
  759. //NTSTATUS ntStatus;
  760. WORD addr;
  761. result = ENE_LoadBinCode(us, SM_RW_PATTERN);
  762. if (result != USB_STOR_XFER_GOOD)
  763. {
  764. printk("Load SM RW Code Fail !!\n");
  765. return USB_STOR_TRANSPORT_ERROR;
  766. }
  767. addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
  768. addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
  769. memset(bcb, 0, sizeof(struct bulk_cb_wrap));
  770. bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
  771. bcb->DataTransferLength = 0x10;
  772. bcb->Flags = 0x80;
  773. bcb->CDB[0] = 0xF2;
  774. bcb->CDB[1] = 0x05;
  775. bcb->CDB[7] = (BYTE)addr;
  776. bcb->CDB[6] = (BYTE)(addr/0x0100);
  777. bcb->CDB[5] = Media.Zone/2;
  778. bcb->CDB[8] = *(redundant+REDT_ADDR1H);
  779. bcb->CDB[9] = *(redundant+REDT_ADDR1L);
  780. result = ENE_SendScsiCmd(us, FDIR_READ, NULL, 0);
  781. if (result != USB_STOR_XFER_GOOD)
  782. return USB_STOR_TRANSPORT_ERROR;
  783. return USB_STOR_TRANSPORT_GOOD;
  784. }
  785. //----- Ssfdc_D_CheckStatus() ------------------------------------------
  786. int Ssfdc_D_CheckStatus(void)
  787. {
  788. // Driver ¤£°µ
  789. return(SMSUCCESS);
  790. //_Set_D_SsfdcRdCmd(RDSTATUS);
  791. //
  792. //if (_Check_D_SsfdcStatus())
  793. //{ _Set_D_SsfdcRdStandby(); return(ERROR); }
  794. //
  795. //_Set_D_SsfdcRdStandby();
  796. //return(SMSUCCESS);
  797. }
  798. /*
  799. ////NAND Memory (SmartMedia) Control Subroutine for Read Data
  800. ////----- _Set_D_SsfdcRdCmd() --------------------------------------------
  801. //void _Set_D_SsfdcRdCmd(BYTE cmd)
  802. //{
  803. // _Hw_D_SetRdCmd();
  804. // _Hw_D_OutData(cmd);
  805. // _Hw_D_SetRdData();
  806. //}
  807. //
  808. ////----- _Set_D_SsfdcRdAddr() -------------------------------------------
  809. //void _Set_D_SsfdcRdAddr(BYTE add)
  810. //{
  811. // WORD addr;
  812. // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
  813. // ADDRESS_T bb = (ADDRESS_T) &Media;
  814. //
  815. // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
  816. // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
  817. //
  818. // //if ((Ssfdc.Attribute &MPS)==PS256) // for 256byte/page
  819. // // addr=addr*2+(WORD)add;
  820. //
  821. // _Hw_D_SetRdAddr();
  822. // _Hw_D_OutData(0x00);
  823. // _Hw_D_OutData((BYTE)addr);
  824. // _Hw_D_OutData((BYTE)(addr/0x0100));
  825. //
  826. // if ((Ssfdc.Attribute &MADC)==AD4CYC)
  827. // _Hw_D_OutData((BYTE)(Media.Zone/2)); // Patch
  828. //
  829. // _Hw_D_SetRdData();
  830. //}
  831. //
  832. ////----- _Set_D_SsfdcRdChip() -------------------------------------------
  833. //void _Set_D_SsfdcRdChip(void)
  834. //{
  835. // _Hw_D_SetRdAddr();
  836. // _Hw_D_OutData(0x00);
  837. // _Hw_D_SetRdData();
  838. //}
  839. //
  840. ////----- _Set_D_SsfdcRdStandby() ----------------------------------------
  841. //void _Set_D_SsfdcRdStandby(void)
  842. //{
  843. // _Hw_D_SetRdStandby();
  844. //}
  845. //
  846. ////----- _Start_D_SsfdcRdHwECC() ----------------------------------------
  847. //void _Start_D_SsfdcRdHwECC(void)
  848. //{
  849. //#ifdef HW_ECC_SUPPORTED
  850. // _Hw_D_EccRdReset();
  851. // _Hw_D_InData();
  852. // _Hw_D_EccRdStart();
  853. //#endif
  854. //}
  855. //
  856. ////----- _Stop_D_SsfdcRdHwECC() -----------------------------------------
  857. //void _Stop_D_SsfdcRdHwECC(void)
  858. //{
  859. //#ifdef HW_ECC_SUPPORTED
  860. // _Hw_D_EccRdStop();
  861. //#endif
  862. //}
  863. //
  864. ////----- _Load_D_SsfdcRdHwECC() -----------------------------------------
  865. //void _Load_D_SsfdcRdHwECC(BYTE add)
  866. //{
  867. //#ifdef HW_ECC_SUPPORTED
  868. // _Hw_D_EccRdRead();
  869. // //if (!(add==ODD && (Ssfdc.Attribute &MPS)==PS256))
  870. // {
  871. // EccBuf[0]=_Hw_D_InData();
  872. // EccBuf[1]=_Hw_D_InData();
  873. // EccBuf[2]=_Hw_D_InData();
  874. // }
  875. //
  876. // //if (!(add==EVEN && (Ssfdc.Attribute &MPS)==PS256))
  877. // {
  878. // EccBuf[3]=_Hw_D_InData();
  879. // EccBuf[4]=_Hw_D_InData();
  880. // EccBuf[5]=_Hw_D_InData();
  881. // }
  882. //
  883. // _Hw_D_EccRdStop();
  884. //#endif
  885. //}
  886. //
  887. ////NAND Memory (SmartMedia) Control Subroutine for Write Data
  888. //
  889. ////----- _Set_D_SsfdcWrCmd() -----------------------------------------
  890. //void _Set_D_SsfdcWrCmd(BYTE cmd)
  891. //{
  892. // _Hw_D_SetWrCmd();
  893. // _Hw_D_OutData(cmd);
  894. // _Hw_D_SetWrData();
  895. //}
  896. //
  897. ////----- _Set_D_SsfdcWrAddr() -----------------------------------------
  898. //void _Set_D_SsfdcWrAddr(BYTE add)
  899. //{
  900. // WORD addr;
  901. // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
  902. // ADDRESS_T bb = (ADDRESS_T) &Media;
  903. //
  904. // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
  905. // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
  906. //
  907. // //if ((Ssfdc.Attribute &MPS)==PS256) // for 256byte/page
  908. // // addr=addr*2+(WORD)add;
  909. //
  910. // _Hw_D_SetWrAddr();
  911. // _Hw_D_OutData(0x00);
  912. // _Hw_D_OutData((BYTE)addr);
  913. // _Hw_D_OutData((BYTE)(addr/0x0100));
  914. //
  915. // if ((Ssfdc.Attribute &MADC)==AD4CYC)
  916. // _Hw_D_OutData((BYTE)(Media.Zone/2)); // Patch
  917. //
  918. // _Hw_D_SetWrData();
  919. //}
  920. //
  921. ////----- _Set_D_SsfdcWrBlock() -----------------------------------------
  922. //void _Set_D_SsfdcWrBlock(void)
  923. //{
  924. // WORD addr;
  925. // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
  926. // ADDRESS_T bb = (ADDRESS_T) &Media;
  927. //
  928. // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
  929. // addr=addr*(WORD)Ssfdc.MaxSectors;
  930. //
  931. // //if ((Ssfdc.Attribute &MPS)==PS256) // for 256byte/page
  932. // // addr=addr*2;
  933. //
  934. // _Hw_D_SetWrAddr();
  935. // _Hw_D_OutData((BYTE)addr);
  936. // _Hw_D_OutData((BYTE)(addr/0x0100));
  937. //
  938. // if ((Ssfdc.Attribute &MADC)==AD4CYC)
  939. // _Hw_D_OutData((BYTE)(Media.Zone/2)); // Patch
  940. //
  941. // _Hw_D_SetWrData();
  942. //}
  943. //
  944. ////----- _Set_D_SsfdcWrStandby() -----------------------------------------
  945. //void _Set_D_SsfdcWrStandby(void)
  946. //{
  947. // _Hw_D_SetWrStandby();
  948. //}
  949. //
  950. ////----- _Start_D_SsfdcWrHwECC() -----------------------------------------
  951. //void _Start_D_SsfdcWrHwECC(void)
  952. //{
  953. //#ifdef HW_ECC_SUPPORTED
  954. // _Hw_D_EccWrReset();
  955. // _Hw_D_InData();
  956. // _Hw_D_EccWrStart();
  957. //#endif
  958. //}
  959. //
  960. ////----- _Load_D_SsfdcWrHwECC() -----------------------------------------
  961. //void _Load_D_SsfdcWrHwECC(BYTE add)
  962. //{
  963. //#ifdef HW_ECC_SUPPORTED
  964. // _Hw_D_EccWrRead();
  965. // //if (!(add==ODD && (Ssfdc.Attribute &MPS)==PS256))
  966. // {
  967. // EccBuf[0]=_Hw_D_InData();
  968. // EccBuf[1]=_Hw_D_InData();
  969. // EccBuf[2]=_Hw_D_InData();
  970. // }
  971. //
  972. // //if (!(add==EVEN && (Ssfdc.Attribute &MPS)==PS256))
  973. // {
  974. // EccBuf[3]=_Hw_D_InData();
  975. // EccBuf[4]=_Hw_D_InData();
  976. // EccBuf[5]=_Hw_D_InData();
  977. // }
  978. //
  979. // _Hw_D_EccWrStop();
  980. //#endif
  981. //}
  982. //
  983. ////NAND Memory (SmartMedia) Control Subroutine
  984. ////----- _Check_D_SsfdcBusy() -------------------------------------------
  985. //int _Check_D_SsfdcBusy(WORD time)
  986. //{
  987. // WORD count = 0;
  988. //
  989. // do {
  990. // if (!_Hw_D_ChkBusy())
  991. // return(SMSUCCESS);
  992. // EDelay(100);
  993. // count++;
  994. // } while (count<=time);
  995. //
  996. // return(ERROR);
  997. //}
  998. //
  999. ////----- _Check_D_SsfdcStatus() -----------------------------------------
  1000. //int _Check_D_SsfdcStatus(void)
  1001. //{
  1002. // if (_Hw_D_InData() & WR_FAIL)
  1003. // return(ERROR);
  1004. //
  1005. // return(SMSUCCESS);
  1006. //}
  1007. //
  1008. //// For 712
  1009. ////----- _Reset_D_SsfdcErr() -----------------------------------------
  1010. //void _Reset_D_SsfdcErr(void)
  1011. //{
  1012. // WORD count = 0;
  1013. //
  1014. // _Hw_D_SetRdCmd();
  1015. // _Hw_D_OutData(RST_CHIP);
  1016. // _Hw_D_SetRdData();
  1017. //
  1018. // do {
  1019. // if (!_Hw_D_ChkBusy())
  1020. // break;
  1021. // EDelay(100);
  1022. // count++;
  1023. // } while (count<=BUSY_RESET);
  1024. //
  1025. // _Hw_D_SetRdStandby();
  1026. //}
  1027. //
  1028. ////NAND Memory (SmartMedia) Buffer Data Xfer Subroutine
  1029. ////----- SM_ReadDataWithDMA() -----------------------------------------
  1030. //void SM_ReadDataWithDMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *databuf, WORD SectByteCount)
  1031. //{
  1032. // PHYSICAL_ADDRESS Addr;
  1033. // LARGE_INTEGER ptimeout ;
  1034. //
  1035. // KeClearEvent(&fdoExt->SM_DMADoneEvent);
  1036. //
  1037. // Addr = MmGetPhysicalAddress(databuf);
  1038. //
  1039. // WRITE_PORT_DWORD(SM_DMA_ADDR_REG, (DWORD)Addr.LowPart);
  1040. // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 0);
  1041. // WRITE_PORT_WORD(SM_DMA_BYTE_COUNT_REG, SectByteCount);
  1042. //
  1043. // while ( _Hw_D_ChkCardIn() )
  1044. // {
  1045. // if ((READ_PORT_BYTE(SM_REG_FIFO_STATUS) & 0x80))
  1046. // break;
  1047. // }
  1048. // if (!_Hw_D_ChkCardIn()) return;
  1049. // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 0x01);
  1050. //
  1051. // ptimeout.QuadPart = 2000 * (-10000); // 2 sec
  1052. // KeWaitForSingleObject(&fdoExt->SM_DMADoneEvent, Executive, KernelMode, FALSE, &ptimeout);
  1053. // _Hw_D_SetDMAIntMask();
  1054. //}
  1055. //
  1056. ////----- SM_WriteDataWithDMA() -----------------------------------------
  1057. //void SM_WriteDataWithDMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *databuf, WORD SectByteCount)
  1058. //{
  1059. // PHYSICAL_ADDRESS Addr;
  1060. // LARGE_INTEGER ptimeout ;
  1061. //
  1062. // KeClearEvent(&fdoExt->SM_DMADoneEvent);
  1063. //
  1064. // Addr = MmGetPhysicalAddress(databuf);
  1065. //
  1066. // WRITE_PORT_DWORD(SM_DMA_ADDR_REG, (DWORD)Addr.LowPart);
  1067. // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 2);
  1068. // WRITE_PORT_WORD(SM_DMA_BYTE_COUNT_REG, SectByteCount);
  1069. //
  1070. // while ( _Hw_D_ChkCardIn() )
  1071. // {
  1072. // if ((READ_PORT_BYTE(SM_REG_FIFO_STATUS) & 0x40))
  1073. // break;
  1074. // }
  1075. // if (!_Hw_D_ChkCardIn()) return;
  1076. // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 0x03);
  1077. //
  1078. // ptimeout.QuadPart = 2000 * (-10000); // 2 sec
  1079. // KeWaitForSingleObject(&fdoExt->SM_DMADoneEvent, Executive, KernelMode, FALSE, &ptimeout);
  1080. // _Hw_D_SetDMAIntMask();
  1081. //}
  1082. //
  1083. ////----- _Read_D_SsfdcBuf() -----------------------------------------
  1084. //void _Read_D_SsfdcBuf(BYTE *databuf)
  1085. //{
  1086. // int i;
  1087. //
  1088. // //for(i=0x0000;i<(((Ssfdc.Attribute &MPS)==PS256)?0x0100:0x0200);i++)
  1089. // for(i=0; i<0x200; i++)
  1090. // *databuf++ =_Hw_D_InData();
  1091. //}
  1092. //
  1093. ////----- _Write_D_SsfdcBuf() -----------------------------------------
  1094. //void _Write_D_SsfdcBuf(BYTE *databuf)
  1095. //{
  1096. // int i;
  1097. //
  1098. // //for(i=0x0000;i<(((Ssfdc.Attribute &MPS)==PS256)?0x0100:0x0200);i++)
  1099. // for(i=0; i<0x200; i++)
  1100. // _Hw_D_OutData(*databuf++);
  1101. //}
  1102. //
  1103. ////----- _Read_D_SsfdcByte() -----------------------------------------
  1104. //void _Read_D_SsfdcByte(BYTE *databuf)
  1105. //{
  1106. // *databuf=(BYTE)_Hw_D_InData();
  1107. //}
  1108. //
  1109. ////----- _ReadRedt_D_SsfdcBuf() -----------------------------------------
  1110. //void _ReadRedt_D_SsfdcBuf(BYTE *redundant)
  1111. //{
  1112. // char i;
  1113. //
  1114. // //for(i=0x00;i<(((Ssfdc.Attribute &MPS)==PS256)?0x08:0x10);i++)
  1115. // for(i=0; i<0x10; i++)
  1116. // redundant[i] =_Hw_D_InData();
  1117. //}
  1118. //
  1119. ////----- _WriteRedt_D_SsfdcBuf() -----------------------------------------
  1120. //void _WriteRedt_D_SsfdcBuf(BYTE *redundant)
  1121. //{
  1122. // char i;
  1123. //
  1124. // //for(i=0x00;i<(((Ssfdc.Attribute &MPS)==PS256)?0x08:0x10);i++)
  1125. // for(i=0; i<0x10; i++)
  1126. // _Hw_D_OutData(*redundant++);
  1127. //}
  1128. */
  1129. //SmartMedia ID Code Check & Mode Set Subroutine
  1130. //----- Set_D_SsfdcModel() ---------------------------------------------
  1131. int Set_D_SsfdcModel(BYTE dcode)
  1132. {
  1133. switch (_Check_D_DevCode(dcode)) {
  1134. case SSFDC1MB:
  1135. Ssfdc.Model = SSFDC1MB;
  1136. Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS256;
  1137. Ssfdc.MaxZones = 1;
  1138. Ssfdc.MaxBlocks = 256;
  1139. Ssfdc.MaxLogBlocks = 250;
  1140. Ssfdc.MaxSectors = 8;
  1141. break;
  1142. case SSFDC2MB:
  1143. Ssfdc.Model = SSFDC2MB;
  1144. Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS256;
  1145. Ssfdc.MaxZones = 1;
  1146. Ssfdc.MaxBlocks = 512;
  1147. Ssfdc.MaxLogBlocks = 500;
  1148. Ssfdc.MaxSectors = 8;
  1149. break;
  1150. case SSFDC4MB:
  1151. Ssfdc.Model = SSFDC4MB;
  1152. Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS512;
  1153. Ssfdc.MaxZones = 1;
  1154. Ssfdc.MaxBlocks = 512;
  1155. Ssfdc.MaxLogBlocks = 500;
  1156. Ssfdc.MaxSectors = 16;
  1157. break;
  1158. case SSFDC8MB:
  1159. Ssfdc.Model = SSFDC8MB;
  1160. Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS512;
  1161. Ssfdc.MaxZones = 1;
  1162. Ssfdc.MaxBlocks = 1024;
  1163. Ssfdc.MaxLogBlocks = 1000;
  1164. Ssfdc.MaxSectors = 16;
  1165. break;
  1166. case SSFDC16MB:
  1167. Ssfdc.Model = SSFDC16MB;
  1168. Ssfdc.Attribute = FLASH | AD3CYC | BS32 | PS512;
  1169. Ssfdc.MaxZones = 1;
  1170. Ssfdc.MaxBlocks = 1024;
  1171. Ssfdc.MaxLogBlocks = 1000;
  1172. Ssfdc.MaxSectors = 32;
  1173. break;
  1174. case SSFDC32MB:
  1175. Ssfdc.Model = SSFDC32MB;
  1176. Ssfdc.Attribute = FLASH | AD3CYC | BS32 | PS512;
  1177. Ssfdc.MaxZones = 2;
  1178. Ssfdc.MaxBlocks = 1024;
  1179. Ssfdc.MaxLogBlocks = 1000;
  1180. Ssfdc.MaxSectors = 32;
  1181. break;
  1182. case SSFDC64MB:
  1183. Ssfdc.Model = SSFDC64MB;
  1184. Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512;
  1185. Ssfdc.MaxZones = 4;
  1186. Ssfdc.MaxBlocks = 1024;
  1187. Ssfdc.MaxLogBlocks = 1000;
  1188. Ssfdc.MaxSectors = 32;
  1189. break;
  1190. case SSFDC128MB:
  1191. Ssfdc.Model = SSFDC128MB;
  1192. Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512;
  1193. Ssfdc.MaxZones = 8;
  1194. Ssfdc.MaxBlocks = 1024;
  1195. Ssfdc.MaxLogBlocks = 1000;
  1196. Ssfdc.MaxSectors = 32;
  1197. break;
  1198. case SSFDC256MB:
  1199. Ssfdc.Model = SSFDC256MB;
  1200. Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512;
  1201. Ssfdc.MaxZones = 16;
  1202. Ssfdc.MaxBlocks = 1024;
  1203. Ssfdc.MaxLogBlocks = 1000;
  1204. Ssfdc.MaxSectors = 32;
  1205. break;
  1206. case SSFDC512MB:
  1207. Ssfdc.Model = SSFDC512MB;
  1208. Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512;
  1209. Ssfdc.MaxZones = 32;
  1210. Ssfdc.MaxBlocks = 1024;
  1211. Ssfdc.MaxLogBlocks = 1000;
  1212. Ssfdc.MaxSectors = 32;
  1213. break;
  1214. case SSFDC1GB:
  1215. Ssfdc.Model = SSFDC1GB;
  1216. Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512;
  1217. Ssfdc.MaxZones = 64;
  1218. Ssfdc.MaxBlocks = 1024;
  1219. Ssfdc.MaxLogBlocks = 1000;
  1220. Ssfdc.MaxSectors = 32;
  1221. break;
  1222. case SSFDC2GB:
  1223. Ssfdc.Model = SSFDC2GB;
  1224. Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512;
  1225. Ssfdc.MaxZones = 128;
  1226. Ssfdc.MaxBlocks = 1024;
  1227. Ssfdc.MaxLogBlocks = 1000;
  1228. Ssfdc.MaxSectors = 32;
  1229. break;
  1230. default:
  1231. Ssfdc.Model = NOSSFDC;
  1232. return(ERROR);
  1233. }
  1234. return(SMSUCCESS);
  1235. }
  1236. //----- _Check_D_DevCode() ---------------------------------------------
  1237. BYTE _Check_D_DevCode(BYTE dcode)
  1238. {
  1239. switch(dcode){
  1240. case 0x6E:
  1241. case 0xE8:
  1242. case 0xEC: return(SSFDC1MB); // 8Mbit (1M) NAND
  1243. case 0x64:
  1244. case 0xEA: return(SSFDC2MB); // 16Mbit (2M) NAND
  1245. case 0x6B:
  1246. case 0xE3:
  1247. case 0xE5: return(SSFDC4MB); // 32Mbit (4M) NAND
  1248. case 0xE6: return(SSFDC8MB); // 64Mbit (8M) NAND
  1249. case 0x73: return(SSFDC16MB); // 128Mbit (16M)NAND
  1250. case 0x75: return(SSFDC32MB); // 256Mbit (32M)NAND
  1251. case 0x76: return(SSFDC64MB); // 512Mbit (64M)NAND
  1252. case 0x79: return(SSFDC128MB); // 1Gbit(128M)NAND
  1253. case 0x71: return(SSFDC256MB);
  1254. case 0xDC: return(SSFDC512MB);
  1255. case 0xD3: return(SSFDC1GB);
  1256. case 0xD5: return(SSFDC2GB);
  1257. default: return(NOSSFDC);
  1258. }
  1259. }
  1260. /*
  1261. ////SmartMedia Power Control Subroutine
  1262. ////----- Cnt_D_Reset() ----------------------------------------------
  1263. //void Cnt_D_Reset(void)
  1264. //{
  1265. // _Hw_D_LedOff();
  1266. // _Hw_D_SetRdStandby();
  1267. // _Hw_D_VccOff();
  1268. //}
  1269. //
  1270. ////----- Cnt_D_PowerOn() ----------------------------------------------
  1271. //int Cnt_D_PowerOn(void)
  1272. //{
  1273. // // No support 5V.
  1274. // _Hw_D_EnableVcc3VOn(); // Set SM_REG_CTRL_5 Reg. to 3V
  1275. // _Hw_D_VccOn();
  1276. // _Hw_D_SetRdStandby();
  1277. // _Wait_D_Timer(TIME_PON);
  1278. //
  1279. // if (_Hw_D_ChkPower())
  1280. // {
  1281. // _Hw_D_EnableOB(); // Set SM_REG_CTRL_5 Reg. to 0x83
  1282. // return(SMSUCCESS);
  1283. // }
  1284. //
  1285. // _Hw_D_SetVccOff();
  1286. // return(ERROR);
  1287. //}
  1288. //
  1289. ////----- Cnt_D_PowerOff() ----------------------------------------------
  1290. //void Cnt_D_PowerOff(void)
  1291. //{
  1292. // _Hw_D_SetRdStandby();
  1293. // _Hw_D_SetVccOff();
  1294. // _Hw_D_VccOff();
  1295. //}
  1296. //
  1297. ////----- Cnt_D_LedOn() ----------------------------------------------
  1298. //void Cnt_D_LedOn(void)
  1299. //{
  1300. // _Hw_D_LedOn();
  1301. //}
  1302. //
  1303. ////----- Cnt_D_LedOff() ----------------------------------------------
  1304. //void Cnt_D_LedOff(void)
  1305. //{
  1306. // _Hw_D_LedOff();
  1307. //}
  1308. //
  1309. ////----- Check_D_CntPower() ----------------------------------------------
  1310. //int Check_D_CntPower(void)
  1311. //{
  1312. // if (_Hw_D_ChkPower())
  1313. // return(SMSUCCESS); // Power On
  1314. //
  1315. // return(ERROR); // Power Off
  1316. //}
  1317. //
  1318. ////----- Check_D_CardExist() ----------------------------------------------
  1319. //int Check_D_CardExist(void)
  1320. //{
  1321. // char i,j,k;
  1322. //
  1323. // if (!_Hw_D_ChkStatus()) // Not Status Change
  1324. // if (_Hw_D_ChkCardIn())
  1325. // return(SMSUCCESS); // Card exist in Slot
  1326. //
  1327. // for(i=0,j=0,k=0; i<16; i++) {
  1328. // if (_Hw_D_ChkCardIn()) // Status Change
  1329. // {
  1330. // j++; k=0;
  1331. // }
  1332. // else
  1333. // {
  1334. // j=0; k++;
  1335. // }
  1336. //
  1337. // if (j>3)
  1338. // return(SMSUCCESS); // Card exist in Slot
  1339. // if (k>3)
  1340. // return(ERROR); // NO Card exist in Slot
  1341. //
  1342. // _Wait_D_Timer(TIME_CDCHK);
  1343. // }
  1344. //
  1345. // return(ERROR);
  1346. //}
  1347. //
  1348. ////----- Check_D_CardStsChg() ----------------------------------------------
  1349. //int Check_D_CardStsChg(void)
  1350. //{
  1351. // if (_Hw_D_ChkStatus())
  1352. // return(ERROR); // Status Change
  1353. //
  1354. // return(SMSUCCESS); // Not Status Change
  1355. //}
  1356. //
  1357. ////----- Check_D_SsfdcWP() ----------------------------------------------
  1358. //int Check_D_SsfdcWP(void)
  1359. //{ // ERROR: WP, SMSUCCESS: Not WP
  1360. // char i;
  1361. //
  1362. // for(i=0; i<8; i++) {
  1363. // if (_Hw_D_ChkWP())
  1364. // return(ERROR);
  1365. // _Wait_D_Timer(TIME_WPCHK);
  1366. // }
  1367. //
  1368. // return(SMSUCCESS);
  1369. //}
  1370. //
  1371. */
  1372. //SmartMedia ECC Control Subroutine
  1373. //----- Check_D_ReadError() ----------------------------------------------
  1374. int Check_D_ReadError(BYTE *redundant)
  1375. {
  1376. return SMSUCCESS;
  1377. }
  1378. //----- Check_D_Correct() ----------------------------------------------
  1379. int Check_D_Correct(BYTE *buf,BYTE *redundant)
  1380. {
  1381. return SMSUCCESS;
  1382. }
  1383. //----- Check_D_CISdata() ----------------------------------------------
  1384. int Check_D_CISdata(BYTE *buf, BYTE *redundant)
  1385. {
  1386. BYTE cis[] = {0x01, 0x03, 0xD9, 0x01, 0xFF, 0x18, 0x02,
  1387. 0xDF, 0x01, 0x20};
  1388. int cis_len = sizeof(cis);
  1389. if (!IsSSFDCCompliance && !IsXDCompliance)
  1390. return SMSUCCESS;
  1391. if (!memcmp(redundant + 0x0D, EccBuf, 3))
  1392. return memcmp(buf, cis, cis_len);
  1393. if (!_Correct_D_SwECC(buf, redundant + 0x0D, EccBuf))
  1394. return memcmp(buf, cis, cis_len);
  1395. buf += 0x100;
  1396. if (!memcmp(redundant + 0x08, EccBuf + 0x03, 3))
  1397. return memcmp(buf, cis, cis_len);
  1398. if (!_Correct_D_SwECC(buf, redundant + 0x08, EccBuf + 0x03))
  1399. return memcmp(buf, cis, cis_len);
  1400. return ERROR;
  1401. }
  1402. //----- Set_D_RightECC() ----------------------------------------------
  1403. void Set_D_RightECC(BYTE *redundant)
  1404. {
  1405. // Driver ¤£°µ ECC Check
  1406. return;
  1407. //StringCopy((char *)(redundant+0x0D),(char *)EccBuf,3);
  1408. //StringCopy((char *)(redundant+0x08),(char *)(EccBuf+0x03),3);
  1409. }
  1410. /*
  1411. ////----- _Calc_D_ECCdata() ----------------------------------------------
  1412. //void _Calc_D_ECCdata(BYTE *buf)
  1413. //{
  1414. //#ifdef HW_ECC_SUPPORTED
  1415. //#else
  1416. // _Calculate_D_SwECC(buf,EccBuf);
  1417. // buf+=0x0100;
  1418. // _Calculate_D_SwECC(buf,EccBuf+0x03);
  1419. //#endif
  1420. //}
  1421. //
  1422. ////----- _Set_D_ECCdata() ----------------------------------------------
  1423. //void _Set_D_ECCdata(BYTE add,BYTE *redundant)
  1424. //{
  1425. // //if (add==EVEN && (Ssfdc.Attribute &MPS)==PS256)
  1426. // // return;
  1427. //
  1428. // // for 256byte/page
  1429. // StringCopy((char *)(redundant+0x0D),(char *)EccBuf,3);
  1430. // StringCopy((char *)(redundant+0x08),(char *)(EccBuf+0x03),3);
  1431. //}
  1432. */
  1433. /*
  1434. //----- SM_ReadBlock() ---------------------------------------------
  1435. int SM_ReadBlock(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant)
  1436. {
  1437. PBULK_CBW pBulkCbw = fdoExt->pBulkCbw;
  1438. NTSTATUS ntStatus;
  1439. WORD addr;
  1440. ENE_LoadBinCode(fdoExt, SM_RW_PATTERN);
  1441. addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
  1442. addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
  1443. // Read sect data
  1444. RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
  1445. pBulkCbw->dCBWSignature = CBW_SIGNTURE;
  1446. pBulkCbw->bCBWLun = CBW_LUN;
  1447. pBulkCbw->dCBWDataTransferLength = 0x200;
  1448. pBulkCbw->bmCBWFlags = 0x80;
  1449. pBulkCbw->CBWCb[0] = 0xF1;
  1450. pBulkCbw->CBWCb[1] = 0x02;
  1451. pBulkCbw->CBWCb[4] = (BYTE)addr;
  1452. pBulkCbw->CBWCb[3] = (BYTE)(addr/0x0100);
  1453. pBulkCbw->CBWCb[2] = Media.Zone/2;
  1454. ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_READ, buf);
  1455. if (!NT_SUCCESS(ntStatus))
  1456. return(ERROR);
  1457. // Read redundant
  1458. RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW));
  1459. pBulkCbw->dCBWSignature = CBW_SIGNTURE;
  1460. pBulkCbw->bCBWLun = CBW_LUN;
  1461. pBulkCbw->dCBWDataTransferLength = 0x10;
  1462. pBulkCbw->bmCBWFlags = 0x80;
  1463. pBulkCbw->CBWCb[0] = 0xF1;
  1464. pBulkCbw->CBWCb[1] = 0x03;
  1465. pBulkCbw->CBWCb[4] = (BYTE)addr;
  1466. pBulkCbw->CBWCb[3] = (BYTE)(addr/0x0100);
  1467. pBulkCbw->CBWCb[2] = Media.Zone/2;
  1468. pBulkCbw->CBWCb[5] = 0;
  1469. pBulkCbw->CBWCb[6] = 1;
  1470. ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_READ, redundant);
  1471. if (!NT_SUCCESS(ntStatus))
  1472. return(ERROR);
  1473. return(SMSUCCESS);
  1474. }*/