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