Merge tag 'scsi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb...
[deliverable/linux.git] / drivers / staging / keucr / smilsub.c
1 #include <linux/slab.h>
2 #include "usb.h"
3 #include "scsiglue.h"
4 #include "transport.h"
5
6 #include "smcommon.h"
7 #include "smil.h"
8
9 static u8 _Check_D_DevCode(u8);
10 static u32 ErrXDCode;
11 static u8 IsSSFDCCompliance;
12 static u8 IsXDCompliance;
13
14 struct keucr_media_info Ssfdc;
15 struct keucr_media_address Media;
16 struct keucr_media_area CisArea;
17
18 static u8 EccBuf[6];
19
20 #define EVEN 0 /* Even Page for 256byte/page */
21 #define ODD 1 /* Odd Page for 256byte/page */
22
23
24 /* SmartMedia Redundant buffer data Control Subroutine
25 *----- Check_D_DataBlank() --------------------------------------------
26 */
27 int Check_D_DataBlank(u8 *redundant)
28 {
29 char i;
30
31 for (i = 0; i < REDTSIZE; i++)
32 if (*redundant++ != 0xFF)
33 return ERROR;
34
35 return SMSUCCESS;
36 }
37
38 /* ----- Check_D_FailBlock() -------------------------------------------- */
39 int Check_D_FailBlock(u8 *redundant)
40 {
41 redundant += REDT_BLOCK;
42
43 if (*redundant == 0xFF)
44 return SMSUCCESS;
45 if (!*redundant)
46 return ERROR;
47 if (hweight8(*redundant) < 7)
48 return ERROR;
49
50 return SMSUCCESS;
51 }
52
53 /* ----- Check_D_DataStatus() ------------------------------------------- */
54 int Check_D_DataStatus(u8 *redundant)
55 {
56 redundant += REDT_DATA;
57
58 if (*redundant == 0xFF)
59 return SMSUCCESS;
60 if (!*redundant) {
61 ErrXDCode = ERR_DataStatus;
62 return ERROR;
63 } else
64 ErrXDCode = NO_ERROR;
65
66 if (hweight8(*redundant) < 5)
67 return ERROR;
68
69 return SMSUCCESS;
70 }
71
72 /* ----- Load_D_LogBlockAddr() ------------------------------------------ */
73 int Load_D_LogBlockAddr(u8 *redundant)
74 {
75 u16 addr1, addr2;
76
77 addr1 = (u16)*(redundant + REDT_ADDR1H)*0x0100 +
78 (u16)*(redundant + REDT_ADDR1L);
79 addr2 = (u16)*(redundant + REDT_ADDR2H)*0x0100 +
80 (u16)*(redundant + REDT_ADDR2L);
81
82 if (addr1 == addr2)
83 if ((addr1 & 0xF000) == 0x1000) {
84 Media.LogBlock = (addr1 & 0x0FFF) / 2;
85 return SMSUCCESS;
86 }
87
88 if (hweight16((u16)(addr1^addr2)) != 0x01)
89 return ERROR;
90
91 if ((addr1 & 0xF000) == 0x1000)
92 if (!(hweight16(addr1) & 0x01)) {
93 Media.LogBlock = (addr1 & 0x0FFF) / 2;
94 return SMSUCCESS;
95 }
96
97 if ((addr2 & 0xF000) == 0x1000)
98 if (!(hweight16(addr2) & 0x01)) {
99 Media.LogBlock = (addr2 & 0x0FFF) / 2;
100 return SMSUCCESS;
101 }
102
103 return ERROR;
104 }
105
106 /* ----- Clr_D_RedundantData() ------------------------------------------ */
107 void Clr_D_RedundantData(u8 *redundant)
108 {
109 char i;
110
111 for (i = 0; i < REDTSIZE; i++)
112 *(redundant + i) = 0xFF;
113 }
114
115 /* ----- Set_D_LogBlockAddr() ------------------------------------------- */
116 void Set_D_LogBlockAddr(u8 *redundant)
117 {
118 u16 addr;
119
120 *(redundant + REDT_BLOCK) = 0xFF;
121 *(redundant + REDT_DATA) = 0xFF;
122 addr = Media.LogBlock*2 + 0x1000;
123
124 if ((hweight16(addr) % 2))
125 addr++;
126
127 *(redundant + REDT_ADDR1H) = *(redundant + REDT_ADDR2H) =
128 (u8)(addr / 0x0100);
129 *(redundant + REDT_ADDR1L) = *(redundant + REDT_ADDR2L) = (u8)addr;
130 }
131
132 /*----- Set_D_FailBlock() ---------------------------------------------- */
133 void Set_D_FailBlock(u8 *redundant)
134 {
135 char i;
136
137 for (i = 0; i < REDTSIZE; i++)
138 *redundant++ = (u8)((i == REDT_BLOCK) ? 0xF0 : 0xFF);
139 }
140
141 /* ----- Set_D_DataStaus() ---------------------------------------------- */
142 void Set_D_DataStaus(u8 *redundant)
143 {
144 redundant += REDT_DATA;
145 *redundant = 0x00;
146 }
147
148 /* SmartMedia Function Command Subroutine
149 * 6250 CMD 6
150 */
151 /* ----- Ssfdc_D_Reset() ------------------------------------------------ */
152 void Ssfdc_D_Reset(struct us_data *us)
153 {
154 return;
155 }
156
157 /* ----- Ssfdc_D_ReadCisSect() ------------------------------------------ */
158 int Ssfdc_D_ReadCisSect(struct us_data *us, u8 *buf, u8 *redundant)
159 {
160 u8 zone, sector;
161 u16 block;
162
163 zone = Media.Zone; block = Media.PhyBlock; sector = Media.Sector;
164 Media.Zone = 0;
165 Media.PhyBlock = CisArea.PhyBlock;
166 Media.Sector = CisArea.Sector;
167
168 if (Ssfdc_D_ReadSect(us, buf, redundant)) {
169 Media.Zone = zone;
170 Media.PhyBlock = block;
171 Media.Sector = sector;
172 return ERROR;
173 }
174
175 Media.Zone = zone; Media.PhyBlock = block; Media.Sector = sector;
176 return SMSUCCESS;
177 }
178
179 /* 6250 CMD 1 */
180 /* ----- Ssfdc_D_ReadSect() --------------------------------------------- */
181 int Ssfdc_D_ReadSect(struct us_data *us, u8 *buf, u8 *redundant)
182 {
183 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
184 int result;
185 u16 addr;
186
187 result = ENE_LoadBinCode(us, SM_RW_PATTERN);
188 if (result != USB_STOR_XFER_GOOD) {
189 dev_err(&us->pusb_dev->dev,
190 "Failed to load SmartMedia read/write code\n");
191 return USB_STOR_TRANSPORT_ERROR;
192 }
193
194 addr = (u16)Media.Zone*Ssfdc.MaxBlocks + Media.PhyBlock;
195 addr = addr*(u16)Ssfdc.MaxSectors + Media.Sector;
196
197 /* Read sect data */
198 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
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;
204 bcb->CDB[4] = (u8)addr;
205 bcb->CDB[3] = (u8)(addr / 0x0100);
206 bcb->CDB[2] = Media.Zone / 2;
207
208 result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0);
209 if (result != USB_STOR_XFER_GOOD)
210 return USB_STOR_TRANSPORT_ERROR;
211
212 /* Read redundant */
213 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
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;
219 bcb->CDB[4] = (u8)addr;
220 bcb->CDB[3] = (u8)(addr / 0x0100);
221 bcb->CDB[2] = Media.Zone / 2;
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
232 /* ----- Ssfdc_D_ReadBlock() --------------------------------------------- */
233 int Ssfdc_D_ReadBlock(struct us_data *us, u16 count, u8 *buf,
234 u8 *redundant)
235 {
236 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
237 int result;
238 u16 addr;
239
240 result = ENE_LoadBinCode(us, SM_RW_PATTERN);
241 if (result != USB_STOR_XFER_GOOD) {
242 dev_err(&us->pusb_dev->dev,
243 "Failed to load SmartMedia read/write code\n");
244 return USB_STOR_TRANSPORT_ERROR;
245 }
246
247 addr = (u16)Media.Zone*Ssfdc.MaxBlocks + Media.PhyBlock;
248 addr = addr*(u16)Ssfdc.MaxSectors + Media.Sector;
249
250 /* Read sect data */
251 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
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;
257 bcb->CDB[4] = (u8)addr;
258 bcb->CDB[3] = (u8)(addr / 0x0100);
259 bcb->CDB[2] = Media.Zone / 2;
260
261 result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0);
262 if (result != USB_STOR_XFER_GOOD)
263 return USB_STOR_TRANSPORT_ERROR;
264
265 /* Read redundant */
266 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
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;
272 bcb->CDB[4] = (u8)addr;
273 bcb->CDB[3] = (u8)(addr / 0x0100);
274 bcb->CDB[2] = Media.Zone / 2;
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 }
284
285
286 /* ----- Ssfdc_D_CopyBlock() -------------------------------------------- */
287 int Ssfdc_D_CopyBlock(struct us_data *us, u16 count, u8 *buf,
288 u8 *redundant)
289 {
290 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
291 int result;
292 u16 ReadAddr, WriteAddr;
293
294 result = ENE_LoadBinCode(us, SM_RW_PATTERN);
295 if (result != USB_STOR_XFER_GOOD) {
296 dev_err(&us->pusb_dev->dev,
297 "Failed to load SmartMedia read/write code\n");
298 return USB_STOR_TRANSPORT_ERROR;
299 }
300
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;
305
306 /* Write sect data */
307 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
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;
313 bcb->CDB[7] = (u8)WriteAddr;
314 bcb->CDB[6] = (u8)(WriteAddr / 0x0100);
315 bcb->CDB[5] = Media.Zone / 2;
316 bcb->CDB[8] = *(redundant + REDT_ADDR1H);
317 bcb->CDB[9] = *(redundant + REDT_ADDR1L);
318 bcb->CDB[10] = Media.Sector;
319
320 if (ReadBlock != NO_ASSIGN) {
321 bcb->CDB[4] = (u8)ReadAddr;
322 bcb->CDB[3] = (u8)(ReadAddr / 0x0100);
323 bcb->CDB[2] = Media.Zone / 2;
324 } else
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 }
333
334 /* ----- Ssfdc_D_WriteSectForCopy() ------------------------------------- */
335 int Ssfdc_D_WriteSectForCopy(struct us_data *us, u8 *buf, u8 *redundant)
336 {
337 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
338 int result;
339 u16 addr;
340
341 result = ENE_LoadBinCode(us, SM_RW_PATTERN);
342 if (result != USB_STOR_XFER_GOOD) {
343 dev_err(&us->pusb_dev->dev,
344 "Failed to load SmartMedia read/write code\n");
345 return USB_STOR_TRANSPORT_ERROR;
346 }
347
348
349 addr = (u16)Media.Zone*Ssfdc.MaxBlocks + Media.PhyBlock;
350 addr = addr*(u16)Ssfdc.MaxSectors + Media.Sector;
351
352 /* Write sect data */
353 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
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;
359 bcb->CDB[7] = (u8)addr;
360 bcb->CDB[6] = (u8)(addr / 0x0100);
361 bcb->CDB[5] = Media.Zone / 2;
362 bcb->CDB[8] = *(redundant + REDT_ADDR1H);
363 bcb->CDB[9] = *(redundant + REDT_ADDR1L);
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
372 /* 6250 CMD 5 */
373 /* ----- Ssfdc_D_EraseBlock() ------------------------------------------- */
374 int Ssfdc_D_EraseBlock(struct us_data *us)
375 {
376 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
377 int result;
378 u16 addr;
379
380 result = ENE_LoadBinCode(us, SM_RW_PATTERN);
381 if (result != USB_STOR_XFER_GOOD) {
382 dev_err(&us->pusb_dev->dev,
383 "Failed to load SmartMedia read/write code\n");
384 return USB_STOR_TRANSPORT_ERROR;
385 }
386
387 addr = (u16)Media.Zone*Ssfdc.MaxBlocks + Media.PhyBlock;
388 addr = addr*(u16)Ssfdc.MaxSectors;
389
390 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
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;
396 bcb->CDB[7] = (u8)addr;
397 bcb->CDB[6] = (u8)(addr / 0x0100);
398 bcb->CDB[5] = Media.Zone / 2;
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
407 /* 6250 CMD 2 */
408 /*----- Ssfdc_D_ReadRedtData() ----------------------------------------- */
409 int Ssfdc_D_ReadRedtData(struct us_data *us, u8 *redundant)
410 {
411 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
412 int result;
413 u16 addr;
414 u8 *buf;
415
416 result = ENE_LoadBinCode(us, SM_RW_PATTERN);
417 if (result != USB_STOR_XFER_GOOD) {
418 dev_err(&us->pusb_dev->dev,
419 "Failed to load SmartMedia read/write code\n");
420 return USB_STOR_TRANSPORT_ERROR;
421 }
422
423 addr = (u16)Media.Zone*Ssfdc.MaxBlocks + Media.PhyBlock;
424 addr = addr*(u16)Ssfdc.MaxSectors + Media.Sector;
425
426 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
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;
432 bcb->CDB[4] = (u8)addr;
433 bcb->CDB[3] = (u8)(addr / 0x0100);
434 bcb->CDB[2] = Media.Zone / 2;
435 bcb->CDB[8] = 0;
436 bcb->CDB[9] = 1;
437
438 buf = kmalloc(0x10, GFP_KERNEL);
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
448 /* 6250 CMD 4 */
449 /* ----- Ssfdc_D_WriteRedtData() ---------------------------------------- */
450 int Ssfdc_D_WriteRedtData(struct us_data *us, u8 *redundant)
451 {
452 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
453 int result;
454 u16 addr;
455
456 result = ENE_LoadBinCode(us, SM_RW_PATTERN);
457 if (result != USB_STOR_XFER_GOOD) {
458 dev_err(&us->pusb_dev->dev,
459 "Failed to load SmartMedia read/write code\n");
460 return USB_STOR_TRANSPORT_ERROR;
461 }
462
463 addr = (u16)Media.Zone*Ssfdc.MaxBlocks + Media.PhyBlock;
464 addr = addr*(u16)Ssfdc.MaxSectors + Media.Sector;
465
466 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
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;
472 bcb->CDB[7] = (u8)addr;
473 bcb->CDB[6] = (u8)(addr / 0x0100);
474 bcb->CDB[5] = Media.Zone / 2;
475 bcb->CDB[8] = *(redundant + REDT_ADDR1H);
476 bcb->CDB[9] = *(redundant + REDT_ADDR1L);
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
485 /* ----- Ssfdc_D_CheckStatus() ------------------------------------------ */
486 int Ssfdc_D_CheckStatus(void)
487 {
488 return SMSUCCESS;
489 }
490
491
492
493 /* SmartMedia ID Code Check & Mode Set Subroutine
494 * ----- Set_D_SsfdcModel() ---------------------------------------------
495 */
496 int Set_D_SsfdcModel(u8 dcode)
497 {
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
600 return SMSUCCESS;
601 }
602
603 /* ----- _Check_D_DevCode() --------------------------------------------- */
604 static u8 _Check_D_DevCode(u8 dcode)
605 {
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 }
626 }
627
628
629
630
631 /* SmartMedia ECC Control Subroutine
632 * ----- Check_D_ReadError() ----------------------------------------------
633 */
634 int Check_D_ReadError(u8 *redundant)
635 {
636 return SMSUCCESS;
637 }
638
639 /* ----- Check_D_Correct() ---------------------------------------------- */
640 int Check_D_Correct(u8 *buf, u8 *redundant)
641 {
642 return SMSUCCESS;
643 }
644
645 /* ----- Check_D_CISdata() ---------------------------------------------- */
646 int Check_D_CISdata(u8 *buf, u8 *redundant)
647 {
648 u8 cis[] = {0x01, 0x03, 0xD9, 0x01, 0xFF, 0x18, 0x02,
649 0xDF, 0x01, 0x20};
650
651 int cis_len = sizeof(cis);
652
653 if (!IsSSFDCCompliance && !IsXDCompliance)
654 return SMSUCCESS;
655
656 if (!memcmp(redundant + 0x0D, EccBuf, 3))
657 return memcmp(buf, cis, cis_len);
658
659 if (!_Correct_D_SwECC(buf, redundant + 0x0D, EccBuf))
660 return memcmp(buf, cis, cis_len);
661
662 buf += 0x100;
663 if (!memcmp(redundant + 0x08, EccBuf + 0x03, 3))
664 return memcmp(buf, cis, cis_len);
665
666 if (!_Correct_D_SwECC(buf, redundant + 0x08, EccBuf + 0x03))
667 return memcmp(buf, cis, cis_len);
668
669 return ERROR;
670 }
671
672 /* ----- Set_D_RightECC() ---------------------------------------------- */
673 void Set_D_RightECC(u8 *redundant)
674 {
675 /* Driver ECC Check */
676 return;
677 }
678
679
This page took 0.04671 seconds and 5 git commands to generate.