Commit cbe435a1 authored by Boris Brezillon's avatar Boris Brezillon

mtd: nand: Get rid of the mtd parameter in all auto-detection functions

Now that struct nand_chip embeds an mtd_info object we can get rid of the
mtd parameter and extract it from the chip parameter with the nand_to_mtd()
helper.
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: default avatarRichard Weinberger <richard@nod.at>
Reviewed-by: default avatarMarek Vasut <marek.vasut@gmail.com>
parent c1ae3cfa
...@@ -3464,9 +3464,10 @@ static u16 onfi_crc16(u16 crc, u8 const *p, size_t len) ...@@ -3464,9 +3464,10 @@ static u16 onfi_crc16(u16 crc, u8 const *p, size_t len)
} }
/* Parse the Extended Parameter Page. */ /* Parse the Extended Parameter Page. */
static int nand_flash_detect_ext_param_page(struct mtd_info *mtd, static int nand_flash_detect_ext_param_page(struct nand_chip *chip,
struct nand_chip *chip, struct nand_onfi_params *p) struct nand_onfi_params *p)
{ {
struct mtd_info *mtd = nand_to_mtd(chip);
struct onfi_ext_param_page *ep; struct onfi_ext_param_page *ep;
struct onfi_ext_section *s; struct onfi_ext_section *s;
struct onfi_ext_ecc_info *ecc; struct onfi_ext_ecc_info *ecc;
...@@ -3561,9 +3562,9 @@ static void nand_onfi_detect_micron(struct nand_chip *chip, ...@@ -3561,9 +3562,9 @@ static void nand_onfi_detect_micron(struct nand_chip *chip,
/* /*
* Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise. * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise.
*/ */
static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, static int nand_flash_detect_onfi(struct nand_chip *chip, int *busw)
int *busw)
{ {
struct mtd_info *mtd = nand_to_mtd(chip);
struct nand_onfi_params *p = &chip->onfi_params; struct nand_onfi_params *p = &chip->onfi_params;
int i, j; int i, j;
int val; int val;
...@@ -3653,7 +3654,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -3653,7 +3654,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
chip->cmdfunc = nand_command_lp; chip->cmdfunc = nand_command_lp;
/* The Extended Parameter Page is supported since ONFI 2.1. */ /* The Extended Parameter Page is supported since ONFI 2.1. */
if (nand_flash_detect_ext_param_page(mtd, chip, p)) if (nand_flash_detect_ext_param_page(chip, p))
pr_warn("Failed to detect ONFI extended param page\n"); pr_warn("Failed to detect ONFI extended param page\n");
} else { } else {
pr_warn("Could not retrieve ONFI ECC requirements\n"); pr_warn("Could not retrieve ONFI ECC requirements\n");
...@@ -3668,9 +3669,9 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -3668,9 +3669,9 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
/* /*
* Check if the NAND chip is JEDEC compliant, returns 1 if it is, 0 otherwise. * Check if the NAND chip is JEDEC compliant, returns 1 if it is, 0 otherwise.
*/ */
static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip, static int nand_flash_detect_jedec(struct nand_chip *chip, int *busw)
int *busw)
{ {
struct mtd_info *mtd = nand_to_mtd(chip);
struct nand_jedec_params *p = &chip->jedec_params; struct nand_jedec_params *p = &chip->jedec_params;
struct jedec_ecc_info *ecc; struct jedec_ecc_info *ecc;
int val; int val;
...@@ -3820,9 +3821,10 @@ static int nand_get_bits_per_cell(u8 cellinfo) ...@@ -3820,9 +3821,10 @@ static int nand_get_bits_per_cell(u8 cellinfo)
* chip. The rest of the parameters must be decoded according to generic or * chip. The rest of the parameters must be decoded according to generic or
* manufacturer-specific "extended ID" decoding patterns. * manufacturer-specific "extended ID" decoding patterns.
*/ */
static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, static void nand_decode_ext_id(struct nand_chip *chip, u8 id_data[8],
u8 id_data[8], int *busw) int *busw)
{ {
struct mtd_info *mtd = nand_to_mtd(chip);
int extid, id_len; int extid, id_len;
/* The 3rd id byte holds MLC / multichip data */ /* The 3rd id byte holds MLC / multichip data */
chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]); chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]);
...@@ -3953,10 +3955,10 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -3953,10 +3955,10 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip,
* decodes a matching ID table entry and assigns the MTD size parameters for * decodes a matching ID table entry and assigns the MTD size parameters for
* the chip. * the chip.
*/ */
static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, static void nand_decode_id(struct nand_chip *chip, struct nand_flash_dev *type,
struct nand_flash_dev *type, u8 id_data[8], u8 id_data[8], int *busw)
int *busw)
{ {
struct mtd_info *mtd = nand_to_mtd(chip);
int maf_id = id_data[0]; int maf_id = id_data[0];
mtd->erasesize = type->erasesize; mtd->erasesize = type->erasesize;
...@@ -3986,9 +3988,9 @@ static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -3986,9 +3988,9 @@ static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip,
* heuristic patterns using various detected parameters (e.g., manufacturer, * heuristic patterns using various detected parameters (e.g., manufacturer,
* page size, cell-type information). * page size, cell-type information).
*/ */
static void nand_decode_bbm_options(struct mtd_info *mtd, static void nand_decode_bbm_options(struct nand_chip *chip, u8 id_data[8])
struct nand_chip *chip, u8 id_data[8])
{ {
struct mtd_info *mtd = nand_to_mtd(chip);
int maf_id = id_data[0]; int maf_id = id_data[0];
/* Set the bad block position */ /* Set the bad block position */
...@@ -4023,9 +4025,12 @@ static inline bool is_full_id_nand(struct nand_flash_dev *type) ...@@ -4023,9 +4025,12 @@ static inline bool is_full_id_nand(struct nand_flash_dev *type)
return type->id_len; return type->id_len;
} }
static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, static bool find_full_id_nand(struct nand_chip *chip,
struct nand_flash_dev *type, u8 *id_data, int *busw) struct nand_flash_dev *type, u8 *id_data,
int *busw)
{ {
struct mtd_info *mtd = nand_to_mtd(chip);
if (!strncmp(type->id, id_data, type->id_len)) { if (!strncmp(type->id, id_data, type->id_len)) {
mtd->writesize = type->pagesize; mtd->writesize = type->pagesize;
mtd->erasesize = type->erasesize; mtd->erasesize = type->erasesize;
...@@ -4052,10 +4057,11 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -4052,10 +4057,11 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip,
/* /*
* Get the flash and manufacturer id and lookup if the type is supported. * Get the flash and manufacturer id and lookup if the type is supported.
*/ */
static int nand_get_flash_type(struct mtd_info *mtd, struct nand_chip *chip, static int nand_get_flash_type(struct nand_chip *chip,
int *maf_id, int *dev_id, int *maf_id, int *dev_id,
struct nand_flash_dev *type) struct nand_flash_dev *type)
{ {
struct mtd_info *mtd = nand_to_mtd(chip);
int busw; int busw;
int i, maf_idx; int i, maf_idx;
u8 id_data[8]; u8 id_data[8];
...@@ -4100,7 +4106,7 @@ static int nand_get_flash_type(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -4100,7 +4106,7 @@ static int nand_get_flash_type(struct mtd_info *mtd, struct nand_chip *chip,
for (; type->name != NULL; type++) { for (; type->name != NULL; type++) {
if (is_full_id_nand(type)) { if (is_full_id_nand(type)) {
if (find_full_id_nand(mtd, chip, type, id_data, &busw)) if (find_full_id_nand(chip, type, id_data, &busw))
goto ident_done; goto ident_done;
} else if (*dev_id == type->dev_id) { } else if (*dev_id == type->dev_id) {
break; break;
...@@ -4110,11 +4116,11 @@ static int nand_get_flash_type(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -4110,11 +4116,11 @@ static int nand_get_flash_type(struct mtd_info *mtd, struct nand_chip *chip,
chip->onfi_version = 0; chip->onfi_version = 0;
if (!type->name || !type->pagesize) { if (!type->name || !type->pagesize) {
/* Check if the chip is ONFI compliant */ /* Check if the chip is ONFI compliant */
if (nand_flash_detect_onfi(mtd, chip, &busw)) if (nand_flash_detect_onfi(chip, &busw))
goto ident_done; goto ident_done;
/* Check if the chip is JEDEC compliant */ /* Check if the chip is JEDEC compliant */
if (nand_flash_detect_jedec(mtd, chip, &busw)) if (nand_flash_detect_jedec(chip, &busw))
goto ident_done; goto ident_done;
} }
...@@ -4128,9 +4134,9 @@ static int nand_get_flash_type(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -4128,9 +4134,9 @@ static int nand_get_flash_type(struct mtd_info *mtd, struct nand_chip *chip,
if (!type->pagesize) { if (!type->pagesize) {
/* Decode parameters from extended ID */ /* Decode parameters from extended ID */
nand_decode_ext_id(mtd, chip, id_data, &busw); nand_decode_ext_id(chip, id_data, &busw);
} else { } else {
nand_decode_id(mtd, chip, type, id_data, &busw); nand_decode_id(chip, type, id_data, &busw);
} }
/* Get chip options */ /* Get chip options */
chip->options |= type->options; chip->options |= type->options;
...@@ -4167,7 +4173,7 @@ static int nand_get_flash_type(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -4167,7 +4173,7 @@ static int nand_get_flash_type(struct mtd_info *mtd, struct nand_chip *chip,
return -EINVAL; return -EINVAL;
} }
nand_decode_bbm_options(mtd, chip, id_data); nand_decode_bbm_options(chip, id_data);
/* Calculate the address shift from the page size */ /* Calculate the address shift from the page size */
chip->page_shift = ffs(mtd->writesize) - 1; chip->page_shift = ffs(mtd->writesize) - 1;
...@@ -4394,7 +4400,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips, ...@@ -4394,7 +4400,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16); nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16);
/* Read the flash type */ /* Read the flash type */
ret = nand_get_flash_type(mtd, chip, &nand_maf_id, &nand_dev_id, table); ret = nand_get_flash_type(chip, &nand_maf_id, &nand_dev_id, table);
if (ret) { if (ret) {
if (!(chip->options & NAND_SCAN_SILENT_NODEV)) if (!(chip->options & NAND_SCAN_SILENT_NODEV))
pr_warn("No NAND device found\n"); pr_warn("No NAND device found\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment