2 * Copyright © 2009 - Maxim Levitsky
3 * Common routines & support for xD format
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 #include <linux/kernel.h>
10 #include <linux/mtd/nand.h>
11 #include "sm_common.h"
13 static struct nand_ecclayout nand_oob_sm
= {
15 .eccpos
= {8, 9, 10, 13, 14, 15},
17 {.offset
= 0 , .length
= 4}, /* reserved */
18 {.offset
= 6 , .length
= 2}, /* LBA1 */
19 {.offset
= 11, .length
= 2} /* LBA2 */
23 /* NOTE: This layout is is not compatabable with SmartMedia, */
24 /* because the 256 byte devices have page depenent oob layout */
25 /* However it does preserve the bad block markers */
26 /* If you use smftl, it will bypass this and work correctly */
27 /* If you not, then you break SmartMedia compliance anyway */
29 static struct nand_ecclayout nand_oob_sm_small
= {
33 {.offset
= 3 , .length
= 2}, /* reserved */
34 {.offset
= 6 , .length
= 2}, /* LBA1 */
39 static int sm_block_markbad(struct mtd_info
*mtd
, loff_t ofs
)
41 struct mtd_oob_ops ops
;
45 memset(&oob
, -1, SM_OOB_SIZE
);
46 oob
.block_status
= 0x0F;
48 /* As long as this function is called on erase block boundaries
49 it will work correctly for 256 byte nand */
50 ops
.mode
= MTD_OOB_PLACE
;
52 ops
.ooblen
= mtd
->oobsize
;
53 ops
.oobbuf
= (void *)&oob
;
57 ret
= mtd
->write_oob(mtd
, ofs
, &ops
);
58 if (ret
< 0 || ops
.oobretlen
!= SM_OOB_SIZE
) {
60 "sm_common: can't mark sector at %i as bad\n",
64 mtd
->ecc_stats
.badblocks
++;
70 int sm_register_device(struct mtd_info
*mtd
)
72 struct nand_chip
*chip
= (struct nand_chip
*)mtd
->priv
;
75 chip
->options
|= NAND_SKIP_BBTSCAN
| NAND_SMARTMEDIA
;
77 /* Scan for card properties */
78 ret
= nand_scan_ident(mtd
, 1, NULL
);
83 /* Bad block marker postion */
84 chip
->badblockpos
= 0x05;
85 chip
->badblockbits
= 7;
86 chip
->block_markbad
= sm_block_markbad
;
89 if (mtd
->writesize
== SM_SECTOR_SIZE
)
90 chip
->ecc
.layout
= &nand_oob_sm
;
91 else if (mtd
->writesize
== SM_SMALL_PAGE
)
92 chip
->ecc
.layout
= &nand_oob_sm_small
;
96 ret
= nand_scan_tail(mtd
);
101 return add_mtd_device(mtd
);
103 EXPORT_SYMBOL_GPL(sm_register_device
);
105 MODULE_LICENSE("GPL");
106 MODULE_AUTHOR("Maxim Levitsky <maximlevitsky@gmail.com>");
107 MODULE_DESCRIPTION("Common SmartMedia/xD functions");