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