aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorBrian Norris <computersforpeace@gmail.com>2012-09-24 23:40:51 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2012-09-29 10:57:42 -0400
commitf23a481c4e0ccb006470b1c890cc7236ba634e67 (patch)
treee5fd455deb2d1e6d7484ced398bec45f4f3b7468 /drivers/mtd
parentfc09bbc04ccd7f069c1928a0156968b888393833 (diff)
mtd: nand: split simple ID decode into its own function
When detecting NAND parameters, the code gets a little ugly so that the logic is obscured. Try to remedy that by moving code to separate functions that have well-defined purposes. This patch splits out the simple ID decode functionality, where all the information regarding NAND size/blocksize/pagesize/oobsize/busw is encoded in the first two bytes of the ID string. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/nand/nand_base.c51
1 files changed, 31 insertions, 20 deletions
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index e017af02da1c..4e1ea7283a95 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -2971,6 +2971,36 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip,
2971} 2971}
2972 2972
2973/* 2973/*
2974 * Old devices have chip data hardcoded in the device ID table. nand_decode_id
2975 * decodes a matching ID table entry and assigns the MTD size parameters for
2976 * the chip.
2977 */
2978static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip,
2979 struct nand_flash_dev *type, u8 id_data[8],
2980 int *busw)
2981{
2982 int maf_id = id_data[0];
2983
2984 mtd->erasesize = type->erasesize;
2985 mtd->writesize = type->pagesize;
2986 mtd->oobsize = mtd->writesize / 32;
2987 *busw = type->options & NAND_BUSWIDTH_16;
2988
2989 /*
2990 * Check for Spansion/AMD ID + repeating 5th, 6th byte since
2991 * some Spansion chips have erasesize that conflicts with size
2992 * listed in nand_ids table.
2993 * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39)
2994 */
2995 if (maf_id == NAND_MFR_AMD && id_data[4] != 0x00 && id_data[5] == 0x00
2996 && id_data[6] == 0x00 && id_data[7] == 0x00
2997 && mtd->writesize == 512) {
2998 mtd->erasesize = 128 * 1024;
2999 mtd->erasesize <<= ((id_data[3] & 0x03) << 1);
3000 }
3001}
3002
3003/*
2974 * Set the bad block marker/indicator (BBM/BBI) patterns according to some 3004 * Set the bad block marker/indicator (BBM/BBI) patterns according to some
2975 * heuristic patterns using various detected parameters (e.g., manufacturer, 3005 * heuristic patterns using various detected parameters (e.g., manufacturer,
2976 * page size, cell-type information). 3006 * page size, cell-type information).
@@ -3084,26 +3114,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
3084 /* Decode parameters from extended ID */ 3114 /* Decode parameters from extended ID */
3085 nand_decode_ext_id(mtd, chip, id_data, &busw); 3115 nand_decode_ext_id(mtd, chip, id_data, &busw);
3086 } else { 3116 } else {
3087 /* 3117 nand_decode_id(mtd, chip, type, id_data, &busw);
3088 * Old devices have chip data hardcoded in the device id table.
3089 */
3090 mtd->erasesize = type->erasesize;
3091 mtd->writesize = type->pagesize;
3092 mtd->oobsize = mtd->writesize / 32;
3093 busw = type->options & NAND_BUSWIDTH_16;
3094
3095 /*
3096 * Check for Spansion/AMD ID + repeating 5th, 6th byte since
3097 * some Spansion chips have erasesize that conflicts with size
3098 * listed in nand_ids table.
3099 * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39)
3100 */
3101 if (*maf_id == NAND_MFR_AMD && id_data[4] != 0x00 &&
3102 id_data[5] == 0x00 && id_data[6] == 0x00 &&
3103 id_data[7] == 0x00 && mtd->writesize == 512) {
3104 mtd->erasesize = 128 * 1024;
3105 mtd->erasesize <<= ((id_data[3] & 0x03) << 1);
3106 }
3107 } 3118 }
3108 /* Get chip options */ 3119 /* Get chip options */
3109 chip->options |= type->options; 3120 chip->options |= type->options;