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