summaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-07-18 14:53:26 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-08-06 13:55:03 +0200
commitafc8ed054de6e8839a745fd5520828c50711629f (patch)
tree1249d28d31fdc36936f639fc0c914152f82b9c97 /drivers/mtd
parent61b0b210a81fef51eeca861b5886837beb2e7cd6 (diff)
downloadbarebox-afc8ed054de6e8839a745fd5520828c50711629f.tar.gz
barebox-afc8ed054de6e8839a745fd5520828c50711629f.tar.xz
mtd: nand-mxs: change API between NAND driver and fcb code
The imx-bbu-nand-fcb update handler code calls into the NAND driver to get the ecc strength and bad block marker position. Change the API so that only a single function is necessary and not three functions. Also in future the ecc strength will be configurable via device tree. This means static parameters like page size / oob size are no longer enough to calculate the ecc strength and so we store a pointer to our mtd_info struct in a static global variable. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/nand/nand_mxs.c62
1 files changed, 33 insertions, 29 deletions
diff --git a/drivers/mtd/nand/nand_mxs.c b/drivers/mtd/nand/nand_mxs.c
index 4317c30805..92d78db6c9 100644
--- a/drivers/mtd/nand/nand_mxs.c
+++ b/drivers/mtd/nand/nand_mxs.c
@@ -287,20 +287,6 @@ static uint32_t mxs_nand_aux_status_offset(void)
return (MXS_NAND_METADATA_SIZE + 0x3) & ~0x3;
}
-uint32_t mxs_nand_get_ecc_strength(uint32_t page_data_size,
- uint32_t page_oob_size)
-{
- int ecc_chunk_count = mxs_nand_ecc_chunk_cnt(page_data_size);
- int ecc_strength = 0;
- int gf_len = 13; /* length of Galois Field for non-DDR nand */
-
- ecc_strength = ((page_oob_size - MXS_NAND_METADATA_SIZE) * 8)
- / (gf_len * ecc_chunk_count);
-
- /* We need the minor even number. */
- return rounddown(ecc_strength, 2);
-}
-
static inline uint32_t mxs_nand_get_mark_offset(uint32_t page_data_size,
uint32_t ecc_strength)
{
@@ -350,20 +336,6 @@ static inline uint32_t mxs_nand_get_mark_offset(uint32_t page_data_size,
return block_mark_bit_offset;
}
-uint32_t mxs_nand_mark_byte_offset(struct mtd_info *mtd)
-{
- uint32_t ecc_strength;
- ecc_strength = mxs_nand_get_ecc_strength(mtd->writesize, mtd->oobsize);
- return mxs_nand_get_mark_offset(mtd->writesize, ecc_strength) >> 3;
-}
-
-uint32_t mxs_nand_mark_bit_offset(struct mtd_info *mtd)
-{
- uint32_t ecc_strength;
- ecc_strength = mxs_nand_get_ecc_strength(mtd->writesize, mtd->oobsize);
- return mxs_nand_get_mark_offset(mtd->writesize, ecc_strength) & 0x7;
-}
-
static int mxs_nand_calc_geo(struct mtd_info *mtd)
{
struct nand_chip *chip = mtd->priv;
@@ -387,6 +359,25 @@ static int mxs_nand_calc_geo(struct mtd_info *mtd)
return 0;
}
+static struct mtd_info *mxs_nand_mtd;
+
+int mxs_nand_get_geo(int *ecc_strength, int *bb_mark_bit_offset)
+{
+ struct nand_chip *chip;
+ struct mxs_nand_info *nand_info;
+
+ if (!mxs_nand_mtd)
+ return -ENODEV;
+
+ chip = mxs_nand_mtd->priv;
+ nand_info = chip->priv;
+
+ *ecc_strength = chip->ecc.strength;
+ *bb_mark_bit_offset = nand_info->bb_mark_bit_offset;
+
+ return 0;
+}
+
/*
* Wait for BCH complete IRQ and clear the IRQ
*/
@@ -2140,6 +2131,10 @@ static int mxs_nand_probe(struct device_d *dev)
enum gpmi_type type;
int err;
+ /* We expect only one */
+ if (mxs_nand_mtd)
+ return -EBUSY;
+
err = dev_get_drvdata(dev, (const void **)&type);
if (err)
type = GPMI_MXS;
@@ -2239,12 +2234,21 @@ static int mxs_nand_probe(struct device_d *dev)
if (err)
goto err2;
- return add_mtd_nand_device(mtd, "nand");
+ err = add_mtd_nand_device(mtd, "nand");
+ if (err)
+ goto err2;
+
+ mxs_nand_mtd = mtd;
+
+ return 0;
err2:
free(nand_info->data_buf);
free(nand_info->cmd_buf);
err1:
free(nand_info);
+
+ mxs_nand_mtd = NULL;
+
return err;
}