Commit | Line | Data |
---|---|---|
9fc51a37 ML |
1 | /* |
2 | * Copyright © 2009 - Maxim Levitsky | |
3 | * Common routines & support for xD format | |
4 | * | |
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. | |
8 | */ | |
9 | #include <linux/kernel.h> | |
10 | #include <linux/mtd/nand.h> | |
a0e5cc58 | 11 | #include <linux/module.h> |
9fc51a37 ML |
12 | #include "sm_common.h" |
13 | ||
14 | static struct nand_ecclayout nand_oob_sm = { | |
15 | .eccbytes = 6, | |
16 | .eccpos = {8, 9, 10, 13, 14, 15}, | |
17 | .oobfree = { | |
18 | {.offset = 0 , .length = 4}, /* reserved */ | |
19 | {.offset = 6 , .length = 2}, /* LBA1 */ | |
20 | {.offset = 11, .length = 2} /* LBA2 */ | |
21 | } | |
22 | }; | |
23 | ||
24 | /* NOTE: This layout is is not compatabable with SmartMedia, */ | |
25 | /* because the 256 byte devices have page depenent oob layout */ | |
26 | /* However it does preserve the bad block markers */ | |
27 | /* If you use smftl, it will bypass this and work correctly */ | |
28 | /* If you not, then you break SmartMedia compliance anyway */ | |
29 | ||
30 | static struct nand_ecclayout nand_oob_sm_small = { | |
31 | .eccbytes = 3, | |
32 | .eccpos = {0, 1, 2}, | |
33 | .oobfree = { | |
34 | {.offset = 3 , .length = 2}, /* reserved */ | |
35 | {.offset = 6 , .length = 2}, /* LBA1 */ | |
36 | } | |
37 | }; | |
38 | ||
39 | ||
40 | static int sm_block_markbad(struct mtd_info *mtd, loff_t ofs) | |
41 | { | |
42 | struct mtd_oob_ops ops; | |
43 | struct sm_oob oob; | |
44 | int ret, error = 0; | |
45 | ||
46 | memset(&oob, -1, SM_OOB_SIZE); | |
47 | oob.block_status = 0x0F; | |
48 | ||
49 | /* As long as this function is called on erase block boundaries | |
50 | it will work correctly for 256 byte nand */ | |
0612b9dd | 51 | ops.mode = MTD_OPS_PLACE_OOB; |
9fc51a37 ML |
52 | ops.ooboffs = 0; |
53 | ops.ooblen = mtd->oobsize; | |
54 | ops.oobbuf = (void *)&oob; | |
55 | ops.datbuf = NULL; | |
56 | ||
57 | ||
a2cc5ba0 | 58 | ret = mtd_write_oob(mtd, ofs, &ops); |
9fc51a37 ML |
59 | if (ret < 0 || ops.oobretlen != SM_OOB_SIZE) { |
60 | printk(KERN_NOTICE | |
61 | "sm_common: can't mark sector at %i as bad\n", | |
62 | (int)ofs); | |
63 | error = -EIO; | |
64 | } else | |
65 | mtd->ecc_stats.badblocks++; | |
66 | ||
67 | return error; | |
68 | } | |
69 | ||
2764fb42 | 70 | static struct nand_flash_dev nand_smartmedia_flash_ids[] = { |
5bfa9b71 AB |
71 | LEGACY_ID_NAND("SmartMedia 2MiB 3,3V ROM", 0x5d, 2, 0x2000, NAND_ROM), |
72 | LEGACY_ID_NAND("SmartMedia 4MiB 3,3V", 0xe3, 4, 0x2000, 0), | |
73 | LEGACY_ID_NAND("SmartMedia 4MiB 3,3/5V", 0xe5, 4, 0x2000, 0), | |
74 | LEGACY_ID_NAND("SmartMedia 4MiB 5V", 0x6b, 4, 0x2000, 0), | |
75 | LEGACY_ID_NAND("SmartMedia 4MiB 3,3V ROM", 0xd5, 4, 0x2000, NAND_ROM), | |
76 | LEGACY_ID_NAND("SmartMedia 8MiB 3,3V", 0xe6, 8, 0x2000, 0), | |
77 | LEGACY_ID_NAND("SmartMedia 8MiB 3,3V ROM", 0xd6, 8, 0x2000, NAND_ROM), | |
78 | LEGACY_ID_NAND("SmartMedia 16MiB 3,3V", 0x73, 16, 0x4000, 0), | |
79 | LEGACY_ID_NAND("SmartMedia 16MiB 3,3V ROM", 0x57, 16, 0x4000, NAND_ROM), | |
80 | LEGACY_ID_NAND("SmartMedia 32MiB 3,3V", 0x75, 32, 0x4000, 0), | |
81 | LEGACY_ID_NAND("SmartMedia 32MiB 3,3V ROM", 0x58, 32, 0x4000, NAND_ROM), | |
82 | LEGACY_ID_NAND("SmartMedia 64MiB 3,3V", 0x76, 64, 0x4000, 0), | |
83 | LEGACY_ID_NAND("SmartMedia 64MiB 3,3V ROM", 0xd9, 64, 0x4000, NAND_ROM), | |
84 | LEGACY_ID_NAND("SmartMedia 128MiB 3,3V", 0x79, 128, 0x4000, 0), | |
85 | LEGACY_ID_NAND("SmartMedia 128MiB 3,3V ROM", 0xda, 128, 0x4000, NAND_ROM), | |
86 | LEGACY_ID_NAND("SmartMedia 256MiB 3, 3V", 0x71, 256, 0x4000, 0), | |
87 | LEGACY_ID_NAND("SmartMedia 256MiB 3,3V ROM", 0x5b, 256, 0x4000, NAND_ROM), | |
8dbfae1e | 88 | {NULL} |
c3611570 | 89 | }; |
2764fb42 | 90 | |
c3611570 | 91 | static struct nand_flash_dev nand_xd_flash_ids[] = { |
5bfa9b71 AB |
92 | LEGACY_ID_NAND("xD 16MiB 3,3V", 0x73, 16, 0x4000, 0), |
93 | LEGACY_ID_NAND("xD 32MiB 3,3V", 0x75, 32, 0x4000, 0), | |
94 | LEGACY_ID_NAND("xD 64MiB 3,3V", 0x76, 64, 0x4000, 0), | |
95 | LEGACY_ID_NAND("xD 128MiB 3,3V", 0x79, 128, 0x4000, 0), | |
96 | LEGACY_ID_NAND("xD 256MiB 3,3V", 0x71, 256, 0x4000, NAND_BROKEN_XD), | |
97 | LEGACY_ID_NAND("xD 512MiB 3,3V", 0xdc, 512, 0x4000, NAND_BROKEN_XD), | |
98 | LEGACY_ID_NAND("xD 1GiB 3,3V", 0xd3, 1024, 0x4000, NAND_BROKEN_XD), | |
99 | LEGACY_ID_NAND("xD 2GiB 3,3V", 0xd5, 2048, 0x4000, NAND_BROKEN_XD), | |
8dbfae1e | 100 | {NULL} |
2764fb42 DW |
101 | }; |
102 | ||
c3611570 | 103 | int sm_register_device(struct mtd_info *mtd, int smartmedia) |
9fc51a37 | 104 | { |
ece0ac98 | 105 | struct nand_chip *chip = mtd->priv; |
9fc51a37 ML |
106 | int ret; |
107 | ||
2764fb42 | 108 | chip->options |= NAND_SKIP_BBTSCAN; |
9fc51a37 ML |
109 | |
110 | /* Scan for card properties */ | |
c3611570 ML |
111 | ret = nand_scan_ident(mtd, 1, smartmedia ? |
112 | nand_smartmedia_flash_ids : nand_xd_flash_ids); | |
9fc51a37 ML |
113 | |
114 | if (ret) | |
115 | return ret; | |
116 | ||
25985edc | 117 | /* Bad block marker position */ |
9fc51a37 ML |
118 | chip->badblockpos = 0x05; |
119 | chip->badblockbits = 7; | |
120 | chip->block_markbad = sm_block_markbad; | |
121 | ||
122 | /* ECC layout */ | |
123 | if (mtd->writesize == SM_SECTOR_SIZE) | |
124 | chip->ecc.layout = &nand_oob_sm; | |
125 | else if (mtd->writesize == SM_SMALL_PAGE) | |
126 | chip->ecc.layout = &nand_oob_sm_small; | |
127 | else | |
128 | return -ENODEV; | |
129 | ||
130 | ret = nand_scan_tail(mtd); | |
131 | ||
132 | if (ret) | |
133 | return ret; | |
134 | ||
ee0e87b1 | 135 | return mtd_device_register(mtd, NULL, 0); |
9fc51a37 ML |
136 | } |
137 | EXPORT_SYMBOL_GPL(sm_register_device); | |
138 | ||
139 | MODULE_LICENSE("GPL"); | |
140 | MODULE_AUTHOR("Maxim Levitsky <maximlevitsky@gmail.com>"); | |
141 | MODULE_DESCRIPTION("Common SmartMedia/xD functions"); |