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" |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 5 | |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 6 | #include "smcommon.h" |
| 7 | #include "smil.h" |
| 8 | |
| 9 | void _Set_D_SsfdcRdCmd (BYTE); |
| 10 | void _Set_D_SsfdcRdAddr (BYTE); |
| 11 | void _Set_D_SsfdcRdChip (void); |
| 12 | void _Set_D_SsfdcRdStandby (void); |
| 13 | void _Start_D_SsfdcRdHwECC (void); |
| 14 | void _Stop_D_SsfdcRdHwECC (void); |
| 15 | void _Load_D_SsfdcRdHwECC (BYTE); |
| 16 | void _Set_D_SsfdcWrCmd (BYTE); |
| 17 | void _Set_D_SsfdcWrAddr (BYTE); |
| 18 | void _Set_D_SsfdcWrBlock (void); |
| 19 | void _Set_D_SsfdcWrStandby (void); |
| 20 | void _Start_D_SsfdcWrHwECC (void); |
| 21 | void _Load_D_SsfdcWrHwECC (BYTE); |
| 22 | int _Check_D_SsfdcBusy (WORD); |
| 23 | int _Check_D_SsfdcStatus (void); |
| 24 | void _Reset_D_SsfdcErr (void); |
| 25 | void _Read_D_SsfdcBuf (BYTE *); |
| 26 | void _Write_D_SsfdcBuf (BYTE *); |
| 27 | void _Read_D_SsfdcByte (BYTE *); |
| 28 | void _ReadRedt_D_SsfdcBuf (BYTE *); |
| 29 | void _WriteRedt_D_SsfdcBuf (BYTE *); |
| 30 | BYTE _Check_D_DevCode (BYTE); |
| 31 | |
| 32 | void _Set_D_ECCdata (BYTE,BYTE *); |
| 33 | void _Calc_D_ECCdata (BYTE *); |
| 34 | |
Ruslan Pisarev | 74a5e01 | 2011-07-22 14:17:04 +0300 | [diff] [blame^] | 35 | |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 36 | struct SSFDCTYPE Ssfdc; |
| 37 | struct ADDRESS Media; |
| 38 | struct CIS_AREA CisArea; |
| 39 | |
Randy Dunlap | d8aba9d | 2011-05-09 10:46:24 -0700 | [diff] [blame] | 40 | static BYTE EccBuf[6]; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 41 | extern PBYTE SMHostAddr; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 42 | extern DWORD ErrXDCode; |
| 43 | |
| 44 | extern WORD ReadBlock; |
| 45 | extern WORD WriteBlock; |
| 46 | |
Ruslan Pisarev | 74a5e01 | 2011-07-22 14:17:04 +0300 | [diff] [blame^] | 47 | |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 48 | |
| 49 | #define EVEN 0 // Even Page for 256byte/page |
| 50 | #define ODD 1 // Odd Page for 256byte/page |
| 51 | |
| 52 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 53 | //SmartMedia Redundant buffer data Control Subroutine |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 54 | //----- Check_D_DataBlank() -------------------------------------------- |
| 55 | int Check_D_DataBlank(BYTE *redundant) |
| 56 | { |
| 57 | char i; |
| 58 | |
| 59 | for(i=0; i<REDTSIZE; i++) |
| 60 | if (*redundant++!=0xFF) |
| 61 | return(ERROR); |
| 62 | |
Randy Dunlap | fb03d4f | 2011-05-09 10:47:51 -0700 | [diff] [blame] | 63 | return(SMSUCCESS); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | //----- Check_D_FailBlock() -------------------------------------------- |
| 67 | int Check_D_FailBlock(BYTE *redundant) |
| 68 | { |
| 69 | redundant+=REDT_BLOCK; |
| 70 | |
| 71 | if (*redundant==0xFF) |
Randy Dunlap | fb03d4f | 2011-05-09 10:47:51 -0700 | [diff] [blame] | 72 | return(SMSUCCESS); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 73 | if (!*redundant) |
| 74 | return(ERROR); |
Roel Van Nyen | 2f7cf8d | 2011-02-27 23:20:24 +0100 | [diff] [blame] | 75 | if (hweight8(*redundant)<7) |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 76 | return(ERROR); |
| 77 | |
Randy Dunlap | fb03d4f | 2011-05-09 10:47:51 -0700 | [diff] [blame] | 78 | return(SMSUCCESS); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | //----- Check_D_DataStatus() ------------------------------------------- |
| 82 | int Check_D_DataStatus(BYTE *redundant) |
| 83 | { |
| 84 | redundant+=REDT_DATA; |
| 85 | |
| 86 | if (*redundant==0xFF) |
Randy Dunlap | fb03d4f | 2011-05-09 10:47:51 -0700 | [diff] [blame] | 87 | return(SMSUCCESS); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 88 | if (!*redundant) |
| 89 | { |
| 90 | ErrXDCode = ERR_DataStatus; |
| 91 | return(ERROR); |
| 92 | } |
| 93 | else |
| 94 | ErrXDCode = NO_ERROR; |
| 95 | |
Roel Van Nyen | 2f7cf8d | 2011-02-27 23:20:24 +0100 | [diff] [blame] | 96 | if (hweight8(*redundant)<5) |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 97 | return(ERROR); |
| 98 | |
Randy Dunlap | fb03d4f | 2011-05-09 10:47:51 -0700 | [diff] [blame] | 99 | return(SMSUCCESS); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | //----- Load_D_LogBlockAddr() ------------------------------------------ |
| 103 | int Load_D_LogBlockAddr(BYTE *redundant) |
| 104 | { |
| 105 | WORD addr1,addr2; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 106 | |
| 107 | addr1=(WORD)*(redundant+REDT_ADDR1H)*0x0100+(WORD)*(redundant+REDT_ADDR1L); |
| 108 | addr2=(WORD)*(redundant+REDT_ADDR2H)*0x0100+(WORD)*(redundant+REDT_ADDR2L); |
| 109 | |
| 110 | if (addr1==addr2) |
| 111 | if ((addr1 &0xF000)==0x1000) |
Randy Dunlap | fb03d4f | 2011-05-09 10:47:51 -0700 | [diff] [blame] | 112 | { Media.LogBlock=(addr1 &0x0FFF)/2; return(SMSUCCESS); } |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 113 | |
Roel Van Nyen | 2f7cf8d | 2011-02-27 23:20:24 +0100 | [diff] [blame] | 114 | if (hweight16((WORD)(addr1^addr2))!=0x01) return(ERROR); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 115 | |
| 116 | if ((addr1 &0xF000)==0x1000) |
Roel Van Nyen | 2f7cf8d | 2011-02-27 23:20:24 +0100 | [diff] [blame] | 117 | if (!(hweight16(addr1) &0x01)) |
Randy Dunlap | fb03d4f | 2011-05-09 10:47:51 -0700 | [diff] [blame] | 118 | { Media.LogBlock=(addr1 &0x0FFF)/2; return(SMSUCCESS); } |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 119 | |
| 120 | if ((addr2 &0xF000)==0x1000) |
Roel Van Nyen | 2f7cf8d | 2011-02-27 23:20:24 +0100 | [diff] [blame] | 121 | if (!(hweight16(addr2) &0x01)) |
Randy Dunlap | fb03d4f | 2011-05-09 10:47:51 -0700 | [diff] [blame] | 122 | { Media.LogBlock=(addr2 &0x0FFF)/2; return(SMSUCCESS); } |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 123 | |
| 124 | return(ERROR); |
| 125 | } |
| 126 | |
| 127 | //----- Clr_D_RedundantData() ------------------------------------------ |
| 128 | void Clr_D_RedundantData(BYTE *redundant) |
| 129 | { |
| 130 | char i; |
| 131 | |
| 132 | for(i=0; i<REDTSIZE; i++) |
| 133 | *(redundant+i)=0xFF; |
| 134 | } |
| 135 | |
| 136 | //----- Set_D_LogBlockAddr() ------------------------------------------- |
| 137 | void Set_D_LogBlockAddr(BYTE *redundant) |
| 138 | { |
| 139 | WORD addr; |
| 140 | |
| 141 | *(redundant+REDT_BLOCK)=0xFF; |
| 142 | *(redundant+REDT_DATA) =0xFF; |
| 143 | addr=Media.LogBlock*2+0x1000; |
| 144 | |
Roel Van Nyen | 2f7cf8d | 2011-02-27 23:20:24 +0100 | [diff] [blame] | 145 | if ((hweight16(addr)%2)) |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 146 | addr++; |
| 147 | |
| 148 | *(redundant+REDT_ADDR1H)=*(redundant+REDT_ADDR2H)=(BYTE)(addr/0x0100); |
| 149 | *(redundant+REDT_ADDR1L)=*(redundant+REDT_ADDR2L)=(BYTE)addr; |
| 150 | } |
| 151 | |
| 152 | //----- Set_D_FailBlock() ---------------------------------------------- |
| 153 | void Set_D_FailBlock(BYTE *redundant) |
| 154 | { |
| 155 | char i; |
| 156 | |
| 157 | for(i=0; i<REDTSIZE; i++) |
| 158 | *redundant++=(BYTE)((i==REDT_BLOCK)?0xF0:0xFF); |
| 159 | } |
| 160 | |
| 161 | //----- Set_D_DataStaus() ---------------------------------------------- |
| 162 | void Set_D_DataStaus(BYTE *redundant) |
| 163 | { |
| 164 | redundant+=REDT_DATA; |
| 165 | *redundant=0x00; |
| 166 | } |
| 167 | |
| 168 | //SmartMedia Function Command Subroutine |
| 169 | // 6250 CMD 6 |
| 170 | //----- Ssfdc_D_Reset() ------------------------------------------------ |
| 171 | void Ssfdc_D_Reset(struct us_data *us) |
| 172 | { |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 173 | return; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | //----- Ssfdc_D_ReadCisSect() ------------------------------------------ |
| 177 | int Ssfdc_D_ReadCisSect(struct us_data *us, BYTE *buf,BYTE *redundant) |
| 178 | { |
| 179 | BYTE zone,sector; |
| 180 | WORD block; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 181 | |
| 182 | zone=Media.Zone; block=Media.PhyBlock; sector=Media.Sector; |
| 183 | Media.Zone=0; |
| 184 | Media.PhyBlock=CisArea.PhyBlock; |
| 185 | Media.Sector=CisArea.Sector; |
| 186 | |
| 187 | if (Ssfdc_D_ReadSect(us,buf,redundant)) |
| 188 | { |
| 189 | Media.Zone=zone; Media.PhyBlock=block; Media.Sector=sector; |
| 190 | return(ERROR); |
| 191 | } |
| 192 | |
| 193 | Media.Zone=zone; Media.PhyBlock=block; Media.Sector=sector; |
Randy Dunlap | fb03d4f | 2011-05-09 10:47:51 -0700 | [diff] [blame] | 194 | return(SMSUCCESS); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 195 | } |
Ruslan Pisarev | 74a5e01 | 2011-07-22 14:17:04 +0300 | [diff] [blame^] | 196 | |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 197 | // 6250 CMD 1 |
| 198 | //----- Ssfdc_D_ReadSect() --------------------------------------------- |
| 199 | int Ssfdc_D_ReadSect(struct us_data *us, BYTE *buf,BYTE *redundant) |
| 200 | { |
| 201 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; |
| 202 | int result; |
| 203 | WORD addr; |
| 204 | |
| 205 | result = ENE_LoadBinCode(us, SM_RW_PATTERN); |
| 206 | if (result != USB_STOR_XFER_GOOD) |
| 207 | { |
| 208 | printk("Load SM RW Code Fail !!\n"); |
| 209 | return USB_STOR_TRANSPORT_ERROR; |
| 210 | } |
| 211 | |
| 212 | addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; |
| 213 | addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; |
| 214 | |
| 215 | // Read sect data |
Konstantin Katuev | 307ae1d | 2010-10-29 12:18:18 +1100 | [diff] [blame] | 216 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 217 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
| 218 | bcb->DataTransferLength = 0x200; |
| 219 | bcb->Flags = 0x80; |
| 220 | bcb->CDB[0] = 0xF1; |
| 221 | bcb->CDB[1] = 0x02; |
| 222 | bcb->CDB[4] = (BYTE)addr; |
| 223 | bcb->CDB[3] = (BYTE)(addr/0x0100); |
| 224 | bcb->CDB[2] = Media.Zone/2; |
| 225 | |
| 226 | result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0); |
| 227 | if (result != USB_STOR_XFER_GOOD) |
| 228 | return USB_STOR_TRANSPORT_ERROR; |
| 229 | |
| 230 | // Read redundant |
Konstantin Katuev | 307ae1d | 2010-10-29 12:18:18 +1100 | [diff] [blame] | 231 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 232 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
| 233 | bcb->DataTransferLength = 0x10; |
| 234 | bcb->Flags = 0x80; |
| 235 | bcb->CDB[0] = 0xF1; |
| 236 | bcb->CDB[1] = 0x03; |
| 237 | bcb->CDB[4] = (BYTE)addr; |
| 238 | bcb->CDB[3] = (BYTE)(addr/0x0100); |
| 239 | bcb->CDB[2] = Media.Zone/2; |
| 240 | bcb->CDB[8] = 0; |
| 241 | bcb->CDB[9] = 1; |
| 242 | |
| 243 | result = ENE_SendScsiCmd(us, FDIR_READ, redundant, 0); |
| 244 | if (result != USB_STOR_XFER_GOOD) |
| 245 | return USB_STOR_TRANSPORT_ERROR; |
| 246 | |
| 247 | return USB_STOR_TRANSPORT_GOOD; |
| 248 | } |
| 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 | |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 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 | |
| 264 | addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; |
| 265 | addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; |
| 266 | |
| 267 | // Read sect data |
Konstantin Katuev | 307ae1d | 2010-10-29 12:18:18 +1100 | [diff] [blame] | 268 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 269 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
| 270 | bcb->DataTransferLength = 0x200*count; |
| 271 | bcb->Flags = 0x80; |
| 272 | bcb->CDB[0] = 0xF1; |
| 273 | bcb->CDB[1] = 0x02; |
| 274 | bcb->CDB[4] = (BYTE)addr; |
| 275 | bcb->CDB[3] = (BYTE)(addr/0x0100); |
| 276 | bcb->CDB[2] = Media.Zone/2; |
| 277 | |
| 278 | result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0); |
| 279 | if (result != USB_STOR_XFER_GOOD) |
| 280 | return USB_STOR_TRANSPORT_ERROR; |
| 281 | |
| 282 | // Read redundant |
Konstantin Katuev | 307ae1d | 2010-10-29 12:18:18 +1100 | [diff] [blame] | 283 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 284 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
| 285 | bcb->DataTransferLength = 0x10; |
| 286 | bcb->Flags = 0x80; |
| 287 | bcb->CDB[0] = 0xF1; |
| 288 | bcb->CDB[1] = 0x03; |
| 289 | bcb->CDB[4] = (BYTE)addr; |
| 290 | bcb->CDB[3] = (BYTE)(addr/0x0100); |
| 291 | bcb->CDB[2] = Media.Zone/2; |
| 292 | bcb->CDB[8] = 0; |
| 293 | bcb->CDB[9] = 1; |
| 294 | |
| 295 | result = ENE_SendScsiCmd(us, FDIR_READ, redundant, 0); |
| 296 | if (result != USB_STOR_XFER_GOOD) |
| 297 | return USB_STOR_TRANSPORT_ERROR; |
| 298 | |
| 299 | return USB_STOR_TRANSPORT_GOOD; |
| 300 | } |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 301 | |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 302 | |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 303 | //----- Ssfdc_D_CopyBlock() -------------------------------------------- |
| 304 | int Ssfdc_D_CopyBlock(struct us_data *us, WORD count, BYTE *buf,BYTE *redundant) |
| 305 | { |
| 306 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; |
| 307 | int result; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 308 | WORD ReadAddr, WriteAddr; |
| 309 | |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 310 | result = ENE_LoadBinCode(us, SM_RW_PATTERN); |
| 311 | if (result != USB_STOR_XFER_GOOD) |
| 312 | { |
| 313 | printk("Load SM RW Code Fail !!\n"); |
| 314 | return USB_STOR_TRANSPORT_ERROR; |
| 315 | } |
| 316 | |
| 317 | ReadAddr = (WORD)Media.Zone*Ssfdc.MaxBlocks+ReadBlock; |
| 318 | ReadAddr = ReadAddr*(WORD)Ssfdc.MaxSectors; |
| 319 | WriteAddr = (WORD)Media.Zone*Ssfdc.MaxBlocks+WriteBlock; |
| 320 | WriteAddr = WriteAddr*(WORD)Ssfdc.MaxSectors; |
| 321 | |
| 322 | // Write sect data |
Konstantin Katuev | 307ae1d | 2010-10-29 12:18:18 +1100 | [diff] [blame] | 323 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 324 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
| 325 | bcb->DataTransferLength = 0x200*count; |
| 326 | bcb->Flags = 0x00; |
| 327 | bcb->CDB[0] = 0xF0; |
| 328 | bcb->CDB[1] = 0x08; |
| 329 | bcb->CDB[7] = (BYTE)WriteAddr; |
| 330 | bcb->CDB[6] = (BYTE)(WriteAddr/0x0100); |
| 331 | bcb->CDB[5] = Media.Zone/2; |
| 332 | bcb->CDB[8] = *(redundant+REDT_ADDR1H); |
| 333 | bcb->CDB[9] = *(redundant+REDT_ADDR1L); |
| 334 | bcb->CDB[10] = Media.Sector; |
| 335 | |
| 336 | if (ReadBlock != NO_ASSIGN) |
| 337 | { |
| 338 | bcb->CDB[4] = (BYTE)ReadAddr; |
| 339 | bcb->CDB[3] = (BYTE)(ReadAddr/0x0100); |
| 340 | bcb->CDB[2] = Media.Zone/2; |
| 341 | } |
| 342 | else |
| 343 | bcb->CDB[11] = 1; |
| 344 | |
| 345 | result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0); |
| 346 | if (result != USB_STOR_XFER_GOOD) |
| 347 | return USB_STOR_TRANSPORT_ERROR; |
| 348 | |
| 349 | return USB_STOR_TRANSPORT_GOOD; |
| 350 | } |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 351 | |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 352 | //----- Ssfdc_D_WriteSectForCopy() ------------------------------------- |
| 353 | int Ssfdc_D_WriteSectForCopy(struct us_data *us, BYTE *buf, BYTE *redundant) |
| 354 | { |
| 355 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; |
| 356 | int result; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 357 | WORD addr; |
| 358 | |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 359 | result = ENE_LoadBinCode(us, SM_RW_PATTERN); |
| 360 | if (result != USB_STOR_XFER_GOOD) |
| 361 | { |
| 362 | printk("Load SM RW Code Fail !!\n"); |
| 363 | return USB_STOR_TRANSPORT_ERROR; |
| 364 | } |
| 365 | |
| 366 | |
| 367 | addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; |
| 368 | addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; |
| 369 | |
| 370 | // Write sect data |
Konstantin Katuev | 307ae1d | 2010-10-29 12:18:18 +1100 | [diff] [blame] | 371 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 372 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
| 373 | bcb->DataTransferLength = 0x200; |
| 374 | bcb->Flags = 0x00; |
| 375 | bcb->CDB[0] = 0xF0; |
| 376 | bcb->CDB[1] = 0x04; |
| 377 | bcb->CDB[7] = (BYTE)addr; |
| 378 | bcb->CDB[6] = (BYTE)(addr/0x0100); |
| 379 | bcb->CDB[5] = Media.Zone/2; |
Joe Perches | 859171c | 2010-11-14 19:04:48 -0800 | [diff] [blame] | 380 | bcb->CDB[8] = *(redundant+REDT_ADDR1H); |
| 381 | bcb->CDB[9] = *(redundant+REDT_ADDR1L); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 382 | |
| 383 | result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0); |
| 384 | if (result != USB_STOR_XFER_GOOD) |
| 385 | return USB_STOR_TRANSPORT_ERROR; |
| 386 | |
| 387 | return USB_STOR_TRANSPORT_GOOD; |
| 388 | } |
| 389 | |
| 390 | // 6250 CMD 5 |
| 391 | //----- Ssfdc_D_EraseBlock() ------------------------------------------- |
| 392 | int Ssfdc_D_EraseBlock(struct us_data *us) |
| 393 | { |
| 394 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; |
| 395 | int result; |
| 396 | WORD addr; |
| 397 | |
| 398 | result = ENE_LoadBinCode(us, SM_RW_PATTERN); |
| 399 | if (result != USB_STOR_XFER_GOOD) |
| 400 | { |
| 401 | printk("Load SM RW Code Fail !!\n"); |
| 402 | return USB_STOR_TRANSPORT_ERROR; |
| 403 | } |
| 404 | |
| 405 | addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; |
| 406 | addr=addr*(WORD)Ssfdc.MaxSectors; |
| 407 | |
Konstantin Katuev | 307ae1d | 2010-10-29 12:18:18 +1100 | [diff] [blame] | 408 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 409 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
| 410 | bcb->DataTransferLength = 0x200; |
| 411 | bcb->Flags = 0x80; |
| 412 | bcb->CDB[0] = 0xF2; |
| 413 | bcb->CDB[1] = 0x06; |
| 414 | bcb->CDB[7] = (BYTE)addr; |
| 415 | bcb->CDB[6] = (BYTE)(addr/0x0100); |
| 416 | bcb->CDB[5] = Media.Zone/2; |
| 417 | |
| 418 | result = ENE_SendScsiCmd(us, FDIR_READ, NULL, 0); |
| 419 | if (result != USB_STOR_XFER_GOOD) |
| 420 | return USB_STOR_TRANSPORT_ERROR; |
| 421 | |
| 422 | return USB_STOR_TRANSPORT_GOOD; |
| 423 | } |
| 424 | |
| 425 | // 6250 CMD 2 |
| 426 | //----- Ssfdc_D_ReadRedtData() ----------------------------------------- |
| 427 | int Ssfdc_D_ReadRedtData(struct us_data *us, BYTE *redundant) |
| 428 | { |
| 429 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; |
| 430 | int result; |
| 431 | WORD addr; |
| 432 | BYTE *buf; |
| 433 | |
| 434 | result = ENE_LoadBinCode(us, SM_RW_PATTERN); |
| 435 | if (result != USB_STOR_XFER_GOOD) |
| 436 | { |
| 437 | printk("Load SM RW Code Fail !!\n"); |
| 438 | return USB_STOR_TRANSPORT_ERROR; |
| 439 | } |
| 440 | |
| 441 | addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; |
| 442 | addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; |
| 443 | |
Konstantin Katuev | 307ae1d | 2010-10-29 12:18:18 +1100 | [diff] [blame] | 444 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 445 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
| 446 | bcb->DataTransferLength = 0x10; |
| 447 | bcb->Flags = 0x80; |
| 448 | bcb->CDB[0] = 0xF1; |
| 449 | bcb->CDB[1] = 0x03; |
| 450 | bcb->CDB[4] = (BYTE)addr; |
| 451 | bcb->CDB[3] = (BYTE)(addr/0x0100); |
| 452 | bcb->CDB[2] = Media.Zone/2; |
| 453 | bcb->CDB[8] = 0; |
| 454 | bcb->CDB[9] = 1; |
| 455 | |
| 456 | buf = kmalloc(0x10, GFP_KERNEL); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 457 | result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0); |
| 458 | memcpy(redundant, buf, 0x10); |
| 459 | kfree(buf); |
| 460 | if (result != USB_STOR_XFER_GOOD) |
| 461 | return USB_STOR_TRANSPORT_ERROR; |
| 462 | |
| 463 | return USB_STOR_TRANSPORT_GOOD; |
| 464 | } |
| 465 | |
| 466 | // 6250 CMD 4 |
| 467 | //----- Ssfdc_D_WriteRedtData() ---------------------------------------- |
| 468 | int Ssfdc_D_WriteRedtData(struct us_data *us, BYTE *redundant) |
| 469 | { |
| 470 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; |
| 471 | int result; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 472 | WORD addr; |
| 473 | |
| 474 | result = ENE_LoadBinCode(us, SM_RW_PATTERN); |
| 475 | if (result != USB_STOR_XFER_GOOD) |
| 476 | { |
| 477 | printk("Load SM RW Code Fail !!\n"); |
| 478 | return USB_STOR_TRANSPORT_ERROR; |
| 479 | } |
| 480 | |
| 481 | addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; |
| 482 | addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; |
| 483 | |
Konstantin Katuev | 307ae1d | 2010-10-29 12:18:18 +1100 | [diff] [blame] | 484 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 485 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
| 486 | bcb->DataTransferLength = 0x10; |
| 487 | bcb->Flags = 0x80; |
| 488 | bcb->CDB[0] = 0xF2; |
| 489 | bcb->CDB[1] = 0x05; |
| 490 | bcb->CDB[7] = (BYTE)addr; |
| 491 | bcb->CDB[6] = (BYTE)(addr/0x0100); |
| 492 | bcb->CDB[5] = Media.Zone/2; |
| 493 | bcb->CDB[8] = *(redundant+REDT_ADDR1H); |
| 494 | bcb->CDB[9] = *(redundant+REDT_ADDR1L); |
| 495 | |
| 496 | result = ENE_SendScsiCmd(us, FDIR_READ, NULL, 0); |
| 497 | if (result != USB_STOR_XFER_GOOD) |
| 498 | return USB_STOR_TRANSPORT_ERROR; |
| 499 | |
| 500 | return USB_STOR_TRANSPORT_GOOD; |
| 501 | } |
| 502 | |
| 503 | //----- Ssfdc_D_CheckStatus() ------------------------------------------ |
| 504 | int Ssfdc_D_CheckStatus(void) |
| 505 | { |
Randy Dunlap | fb03d4f | 2011-05-09 10:47:51 -0700 | [diff] [blame] | 506 | return(SMSUCCESS); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 507 | } |
Ruslan Pisarev | 74a5e01 | 2011-07-22 14:17:04 +0300 | [diff] [blame^] | 508 | |
| 509 | |
| 510 | |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 511 | //SmartMedia ID Code Check & Mode Set Subroutine |
| 512 | //----- Set_D_SsfdcModel() --------------------------------------------- |
| 513 | int Set_D_SsfdcModel(BYTE dcode) |
| 514 | { |
| 515 | switch (_Check_D_DevCode(dcode)) { |
| 516 | case SSFDC1MB: |
| 517 | Ssfdc.Model = SSFDC1MB; |
| 518 | Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS256; |
| 519 | Ssfdc.MaxZones = 1; |
| 520 | Ssfdc.MaxBlocks = 256; |
| 521 | Ssfdc.MaxLogBlocks = 250; |
| 522 | Ssfdc.MaxSectors = 8; |
| 523 | break; |
| 524 | case SSFDC2MB: |
| 525 | Ssfdc.Model = SSFDC2MB; |
| 526 | Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS256; |
| 527 | Ssfdc.MaxZones = 1; |
| 528 | Ssfdc.MaxBlocks = 512; |
| 529 | Ssfdc.MaxLogBlocks = 500; |
| 530 | Ssfdc.MaxSectors = 8; |
| 531 | break; |
| 532 | case SSFDC4MB: |
| 533 | Ssfdc.Model = SSFDC4MB; |
| 534 | Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS512; |
| 535 | Ssfdc.MaxZones = 1; |
| 536 | Ssfdc.MaxBlocks = 512; |
| 537 | Ssfdc.MaxLogBlocks = 500; |
| 538 | Ssfdc.MaxSectors = 16; |
| 539 | break; |
| 540 | case SSFDC8MB: |
| 541 | Ssfdc.Model = SSFDC8MB; |
| 542 | Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS512; |
| 543 | Ssfdc.MaxZones = 1; |
| 544 | Ssfdc.MaxBlocks = 1024; |
| 545 | Ssfdc.MaxLogBlocks = 1000; |
| 546 | Ssfdc.MaxSectors = 16; |
| 547 | break; |
| 548 | case SSFDC16MB: |
| 549 | Ssfdc.Model = SSFDC16MB; |
| 550 | Ssfdc.Attribute = FLASH | AD3CYC | BS32 | PS512; |
| 551 | Ssfdc.MaxZones = 1; |
| 552 | Ssfdc.MaxBlocks = 1024; |
| 553 | Ssfdc.MaxLogBlocks = 1000; |
| 554 | Ssfdc.MaxSectors = 32; |
| 555 | break; |
| 556 | case SSFDC32MB: |
| 557 | Ssfdc.Model = SSFDC32MB; |
| 558 | Ssfdc.Attribute = FLASH | AD3CYC | BS32 | PS512; |
| 559 | Ssfdc.MaxZones = 2; |
| 560 | Ssfdc.MaxBlocks = 1024; |
| 561 | Ssfdc.MaxLogBlocks = 1000; |
| 562 | Ssfdc.MaxSectors = 32; |
| 563 | break; |
| 564 | case SSFDC64MB: |
| 565 | Ssfdc.Model = SSFDC64MB; |
| 566 | Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; |
| 567 | Ssfdc.MaxZones = 4; |
| 568 | Ssfdc.MaxBlocks = 1024; |
| 569 | Ssfdc.MaxLogBlocks = 1000; |
| 570 | Ssfdc.MaxSectors = 32; |
| 571 | break; |
| 572 | case SSFDC128MB: |
| 573 | Ssfdc.Model = SSFDC128MB; |
| 574 | Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; |
| 575 | Ssfdc.MaxZones = 8; |
| 576 | Ssfdc.MaxBlocks = 1024; |
| 577 | Ssfdc.MaxLogBlocks = 1000; |
| 578 | Ssfdc.MaxSectors = 32; |
| 579 | break; |
| 580 | case SSFDC256MB: |
| 581 | Ssfdc.Model = SSFDC256MB; |
| 582 | Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; |
| 583 | Ssfdc.MaxZones = 16; |
| 584 | Ssfdc.MaxBlocks = 1024; |
| 585 | Ssfdc.MaxLogBlocks = 1000; |
| 586 | Ssfdc.MaxSectors = 32; |
| 587 | break; |
| 588 | case SSFDC512MB: |
| 589 | Ssfdc.Model = SSFDC512MB; |
| 590 | Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; |
| 591 | Ssfdc.MaxZones = 32; |
| 592 | Ssfdc.MaxBlocks = 1024; |
| 593 | Ssfdc.MaxLogBlocks = 1000; |
| 594 | Ssfdc.MaxSectors = 32; |
| 595 | break; |
| 596 | case SSFDC1GB: |
| 597 | Ssfdc.Model = SSFDC1GB; |
| 598 | Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; |
| 599 | Ssfdc.MaxZones = 64; |
| 600 | Ssfdc.MaxBlocks = 1024; |
| 601 | Ssfdc.MaxLogBlocks = 1000; |
| 602 | Ssfdc.MaxSectors = 32; |
| 603 | break; |
| 604 | case SSFDC2GB: |
| 605 | Ssfdc.Model = SSFDC2GB; |
| 606 | Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; |
| 607 | Ssfdc.MaxZones = 128; |
| 608 | Ssfdc.MaxBlocks = 1024; |
| 609 | Ssfdc.MaxLogBlocks = 1000; |
| 610 | Ssfdc.MaxSectors = 32; |
| 611 | break; |
| 612 | default: |
| 613 | Ssfdc.Model = NOSSFDC; |
| 614 | return(ERROR); |
| 615 | } |
| 616 | |
Randy Dunlap | fb03d4f | 2011-05-09 10:47:51 -0700 | [diff] [blame] | 617 | return(SMSUCCESS); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | //----- _Check_D_DevCode() --------------------------------------------- |
| 621 | BYTE _Check_D_DevCode(BYTE dcode) |
| 622 | { |
| 623 | switch(dcode){ |
| 624 | case 0x6E: |
| 625 | case 0xE8: |
| 626 | case 0xEC: return(SSFDC1MB); // 8Mbit (1M) NAND |
| 627 | case 0x64: |
| 628 | case 0xEA: return(SSFDC2MB); // 16Mbit (2M) NAND |
| 629 | case 0x6B: |
| 630 | case 0xE3: |
| 631 | case 0xE5: return(SSFDC4MB); // 32Mbit (4M) NAND |
| 632 | case 0xE6: return(SSFDC8MB); // 64Mbit (8M) NAND |
| 633 | case 0x73: return(SSFDC16MB); // 128Mbit (16M)NAND |
| 634 | case 0x75: return(SSFDC32MB); // 256Mbit (32M)NAND |
| 635 | case 0x76: return(SSFDC64MB); // 512Mbit (64M)NAND |
| 636 | case 0x79: return(SSFDC128MB); // 1Gbit(128M)NAND |
| 637 | case 0x71: return(SSFDC256MB); |
| 638 | case 0xDC: return(SSFDC512MB); |
| 639 | case 0xD3: return(SSFDC1GB); |
| 640 | case 0xD5: return(SSFDC2GB); |
| 641 | default: return(NOSSFDC); |
| 642 | } |
| 643 | } |
Ruslan Pisarev | 74a5e01 | 2011-07-22 14:17:04 +0300 | [diff] [blame^] | 644 | |
| 645 | |
| 646 | |
| 647 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 648 | //SmartMedia ECC Control Subroutine |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 649 | //----- Check_D_ReadError() ---------------------------------------------- |
| 650 | int Check_D_ReadError(BYTE *redundant) |
| 651 | { |
Randy Dunlap | fb03d4f | 2011-05-09 10:47:51 -0700 | [diff] [blame] | 652 | return SMSUCCESS; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | //----- Check_D_Correct() ---------------------------------------------- |
| 656 | int Check_D_Correct(BYTE *buf,BYTE *redundant) |
| 657 | { |
Randy Dunlap | fb03d4f | 2011-05-09 10:47:51 -0700 | [diff] [blame] | 658 | return SMSUCCESS; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | //----- Check_D_CISdata() ---------------------------------------------- |
| 662 | int Check_D_CISdata(BYTE *buf, BYTE *redundant) |
| 663 | { |
Javier Martinez Canillas | 1b5b4e1 | 2011-01-02 23:14:26 +0100 | [diff] [blame] | 664 | BYTE cis[] = {0x01, 0x03, 0xD9, 0x01, 0xFF, 0x18, 0x02, |
| 665 | 0xDF, 0x01, 0x20}; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 666 | |
Javier Martinez Canillas | 1b5b4e1 | 2011-01-02 23:14:26 +0100 | [diff] [blame] | 667 | int cis_len = sizeof(cis); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 668 | |
Javier Martinez Canillas | 1b5b4e1 | 2011-01-02 23:14:26 +0100 | [diff] [blame] | 669 | if (!IsSSFDCCompliance && !IsXDCompliance) |
Randy Dunlap | fb03d4f | 2011-05-09 10:47:51 -0700 | [diff] [blame] | 670 | return SMSUCCESS; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 671 | |
Javier Martinez Canillas | 1b5b4e1 | 2011-01-02 23:14:26 +0100 | [diff] [blame] | 672 | if (!memcmp(redundant + 0x0D, EccBuf, 3)) |
| 673 | return memcmp(buf, cis, cis_len); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 674 | |
Javier Martinez Canillas | 1b5b4e1 | 2011-01-02 23:14:26 +0100 | [diff] [blame] | 675 | if (!_Correct_D_SwECC(buf, redundant + 0x0D, EccBuf)) |
| 676 | return memcmp(buf, cis, cis_len); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 677 | |
Javier Martinez Canillas | 1b5b4e1 | 2011-01-02 23:14:26 +0100 | [diff] [blame] | 678 | buf += 0x100; |
| 679 | if (!memcmp(redundant + 0x08, EccBuf + 0x03, 3)) |
| 680 | return memcmp(buf, cis, cis_len); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 681 | |
Javier Martinez Canillas | 1b5b4e1 | 2011-01-02 23:14:26 +0100 | [diff] [blame] | 682 | if (!_Correct_D_SwECC(buf, redundant + 0x08, EccBuf + 0x03)) |
| 683 | return memcmp(buf, cis, cis_len); |
| 684 | |
| 685 | return ERROR; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | //----- Set_D_RightECC() ---------------------------------------------- |
| 689 | void Set_D_RightECC(BYTE *redundant) |
| 690 | { |
| 691 | // Driver ¤£°µ ECC Check |
| 692 | return; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 693 | } |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 694 | |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 695 | |