mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-27 07:55:15 +07:00
d4092d76a4
We are planning to share more code between different NAND based devices (SPI NAND, OneNAND and raw NANDs), but before doing that we need to move the existing include/linux/mtd/nand.h file into include/linux/mtd/rawnand.h so we can later create a nand.h header containing all common structure and function prototypes. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Peter Pan <peterpandong@micron.com> Acked-by: Vladimir Zapolskiy <vz@mleia.com> Acked-by: Alexander Sverdlin <alexander.sverdlin@gmail.com> Acked-by: Wenyou Yang <wenyou.yang@microchip.com> Acked-by: Krzysztof Kozlowski <krzk@kernel.org> Acked-by: Han Xu <han.xu@nxp.com> Acked-by: H Hartley Sweeten <hsweeten@visionengravers.com> Acked-by: Shawn Guo <shawnguo@kernel.org> Acked-by: Gregory CLEMENT <gregory.clement@free-electrons.com> Acked-by: Neil Armstrong <narmstrong@baylibre.com> Acked-by: Masahiro Yamada <yamada.masahiro@socionext.com> Acked-By: Harvey Hunt <harveyhuntnexus@gmail.com> Acked-by: Tony Lindgren <tony@atomide.com> Acked-by: Krzysztof Halasa <khalasa@piap.pl>
116 lines
2.7 KiB
C
116 lines
2.7 KiB
C
/*
|
|
* Copyright (C) 2017 Free Electrons
|
|
* Copyright (C) 2017 NextThing Co
|
|
*
|
|
* Author: Boris Brezillon <boris.brezillon@free-electrons.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#include <linux/mtd/rawnand.h>
|
|
|
|
static void samsung_nand_decode_id(struct nand_chip *chip)
|
|
{
|
|
struct mtd_info *mtd = nand_to_mtd(chip);
|
|
|
|
/* New Samsung (6 byte ID): Samsung K9GAG08U0F (p.44) */
|
|
if (chip->id.len == 6 && !nand_is_slc(chip) &&
|
|
chip->id.data[5] != 0x00) {
|
|
u8 extid = chip->id.data[3];
|
|
|
|
/* Get pagesize */
|
|
mtd->writesize = 2048 << (extid & 0x03);
|
|
|
|
extid >>= 2;
|
|
|
|
/* Get oobsize */
|
|
switch (((extid >> 2) & 0x4) | (extid & 0x3)) {
|
|
case 1:
|
|
mtd->oobsize = 128;
|
|
break;
|
|
case 2:
|
|
mtd->oobsize = 218;
|
|
break;
|
|
case 3:
|
|
mtd->oobsize = 400;
|
|
break;
|
|
case 4:
|
|
mtd->oobsize = 436;
|
|
break;
|
|
case 5:
|
|
mtd->oobsize = 512;
|
|
break;
|
|
case 6:
|
|
mtd->oobsize = 640;
|
|
break;
|
|
default:
|
|
/*
|
|
* We should never reach this case, but if that
|
|
* happens, this probably means Samsung decided to use
|
|
* a different extended ID format, and we should find
|
|
* a way to support it.
|
|
*/
|
|
WARN(1, "Invalid OOB size value");
|
|
break;
|
|
}
|
|
|
|
/* Get blocksize */
|
|
extid >>= 2;
|
|
mtd->erasesize = (128 * 1024) <<
|
|
(((extid >> 1) & 0x04) | (extid & 0x03));
|
|
|
|
/* Extract ECC requirements from 5th id byte*/
|
|
extid = (chip->id.data[4] >> 4) & 0x07;
|
|
if (extid < 5) {
|
|
chip->ecc_step_ds = 512;
|
|
chip->ecc_strength_ds = 1 << extid;
|
|
} else {
|
|
chip->ecc_step_ds = 1024;
|
|
switch (extid) {
|
|
case 5:
|
|
chip->ecc_strength_ds = 24;
|
|
break;
|
|
case 6:
|
|
chip->ecc_strength_ds = 40;
|
|
break;
|
|
case 7:
|
|
chip->ecc_strength_ds = 60;
|
|
break;
|
|
default:
|
|
WARN(1, "Could not decode ECC info");
|
|
chip->ecc_step_ds = 0;
|
|
}
|
|
}
|
|
} else {
|
|
nand_decode_ext_id(chip);
|
|
}
|
|
}
|
|
|
|
static int samsung_nand_init(struct nand_chip *chip)
|
|
{
|
|
struct mtd_info *mtd = nand_to_mtd(chip);
|
|
|
|
if (mtd->writesize > 512)
|
|
chip->options |= NAND_SAMSUNG_LP_OPTIONS;
|
|
|
|
if (!nand_is_slc(chip))
|
|
chip->bbt_options |= NAND_BBT_SCANLASTPAGE;
|
|
else
|
|
chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
|
|
|
|
return 0;
|
|
}
|
|
|
|
const struct nand_manufacturer_ops samsung_nand_manuf_ops = {
|
|
.detect = samsung_nand_decode_id,
|
|
.init = samsung_nand_init,
|
|
};
|