1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2017 Free Electrons
4 * Copyright (C) 2017 NextThing Co
6 * Author: Boris Brezillon <boris.brezillon@free-electrons.com>
11 static void samsung_nand_decode_id(struct nand_chip *chip)
13 struct mtd_info *mtd = nand_to_mtd(chip);
14 struct nand_memory_organization *memorg;
16 memorg = nanddev_get_memorg(&chip->base);
18 /* New Samsung (6 byte ID): Samsung K9GAG08U0F (p.44) */
19 if (chip->id.len == 6 && !nand_is_slc(chip) &&
20 chip->id.data[5] != 0x00) {
21 u8 extid = chip->id.data[3];
24 memorg->pagesize = 2048 << (extid & 0x03);
25 mtd->writesize = memorg->pagesize;
30 switch (((extid >> 2) & 0x4) | (extid & 0x3)) {
32 memorg->oobsize = 128;
35 memorg->oobsize = 218;
38 memorg->oobsize = 400;
41 memorg->oobsize = 436;
44 memorg->oobsize = 512;
47 memorg->oobsize = 640;
51 * We should never reach this case, but if that
52 * happens, this probably means Samsung decided to use
53 * a different extended ID format, and we should find
54 * a way to support it.
56 WARN(1, "Invalid OOB size value");
60 mtd->oobsize = memorg->oobsize;
64 memorg->pages_per_eraseblock = (128 * 1024) <<
65 (((extid >> 1) & 0x04) |
68 mtd->erasesize = (128 * 1024) <<
69 (((extid >> 1) & 0x04) | (extid & 0x03));
71 /* Extract ECC requirements from 5th id byte*/
72 extid = (chip->id.data[4] >> 4) & 0x07;
74 chip->base.eccreq.step_size = 512;
75 chip->base.eccreq.strength = 1 << extid;
77 chip->base.eccreq.step_size = 1024;
80 chip->base.eccreq.strength = 24;
83 chip->base.eccreq.strength = 40;
86 chip->base.eccreq.strength = 60;
89 WARN(1, "Could not decode ECC info");
90 chip->base.eccreq.step_size = 0;
94 nand_decode_ext_id(chip);
96 if (nand_is_slc(chip)) {
97 switch (chip->id.data[1]) {
98 /* K9F4G08U0D-S[I|C]B0(T00) */
100 chip->base.eccreq.step_size = 512;
101 chip->base.eccreq.strength = 1;
104 /* K9F1G08U0E 21nm chips do not support subpage write */
106 if (chip->id.len > 4 &&
107 (chip->id.data[4] & GENMASK(1, 0)) == 0x1)
108 chip->options |= NAND_NO_SUBPAGE_WRITE;
117 static int samsung_nand_init(struct nand_chip *chip)
119 struct mtd_info *mtd = nand_to_mtd(chip);
121 if (mtd->writesize > 512)
122 chip->options |= NAND_SAMSUNG_LP_OPTIONS;
124 if (!nand_is_slc(chip))
125 chip->options |= NAND_BBM_LASTPAGE;
127 chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE;
132 const struct nand_manufacturer_ops samsung_nand_manuf_ops = {
133 .detect = samsung_nand_decode_id,
134 .init = samsung_nand_init,