Commit dacd1a12 authored by Miquel Raynal's avatar Miquel Raynal

mtd: rawnand: onfi: Define the number of parameter pages

Use a macro to define the number of parameter page instead of
hardcoding it everywhere.
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: default avatarBoris Brezillon <boris.brezillon@collabora.com>
Link: https://lore.kernel.org/linux-mtd/20200428094302.14624-6-miquel.raynal@bootlin.com
parent 543e34f2
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "internals.h" #include "internals.h"
#define ONFI_PARAM_PAGES 3
u16 onfi_crc16(u16 crc, u8 const *p, size_t len) u16 onfi_crc16(u16 crc, u8 const *p, size_t len)
{ {
int i; int i;
...@@ -156,7 +158,7 @@ int nand_onfi_detect(struct nand_chip *chip) ...@@ -156,7 +158,7 @@ int nand_onfi_detect(struct nand_chip *chip)
return 0; return 0;
/* ONFI chip: allocate a buffer to hold its parameter page */ /* ONFI chip: allocate a buffer to hold its parameter page */
p = kzalloc((sizeof(*p) * 3), GFP_KERNEL); p = kzalloc((sizeof(*p) * ONFI_PARAM_PAGES), GFP_KERNEL);
if (!p) if (!p)
return -ENOMEM; return -ENOMEM;
...@@ -166,7 +168,7 @@ int nand_onfi_detect(struct nand_chip *chip) ...@@ -166,7 +168,7 @@ int nand_onfi_detect(struct nand_chip *chip)
goto free_onfi_param_page; goto free_onfi_param_page;
} }
for (i = 0; i < 3; i++) { for (i = 0; i < ONFI_PARAM_PAGES; i++) {
ret = nand_read_data_op(chip, &p[i], sizeof(*p), true); ret = nand_read_data_op(chip, &p[i], sizeof(*p), true);
if (ret) { if (ret) {
ret = 0; ret = 0;
...@@ -181,11 +183,15 @@ int nand_onfi_detect(struct nand_chip *chip) ...@@ -181,11 +183,15 @@ int nand_onfi_detect(struct nand_chip *chip)
} }
} }
if (i == 3) { if (i == ONFI_PARAM_PAGES) {
const void *srcbufs[3] = {p, p + 1, p + 2}; const void *srcbufs[ONFI_PARAM_PAGES];
unsigned int j;
for (j = 0; j < ONFI_PARAM_PAGES; j++)
srcbufs[j] = p + j;
pr_warn("Could not find a valid ONFI parameter page, trying bit-wise majority to recover it\n"); pr_warn("Could not find a valid ONFI parameter page, trying bit-wise majority to recover it\n");
nand_bit_wise_majority(srcbufs, ARRAY_SIZE(srcbufs), p, nand_bit_wise_majority(srcbufs, ONFI_PARAM_PAGES, p,
sizeof(*p)); sizeof(*p));
crc = onfi_crc16(ONFI_CRC_BASE, (u8 *)p, 254); crc = onfi_crc16(ONFI_CRC_BASE, (u8 *)p, 254);
......
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