[08/15] mtd: rawnand: Initialize the nand_device object
diff mbox series

Message ID 20190221091527.20497-9-miquel.raynal@bootlin.com
State New, archived
Headers show
Series
  • mtd: rawnand: 5th batch of cleanups
Related show

Commit Message

Miquel Raynal Feb. 21, 2019, 9:15 a.m. UTC
From: Boris Brezillon <bbrezillon@kernel.org>

In order to use some of the nanddev_xxx() helpers, we need to
initialize the nand_device object embedded in nand_chip using
nanddev_init(). This requires implementing nand_ops.

We also drop useless mtd->xxx initialization when they're already taken
case of by nanddev_init().

Signed-off-by: Boris Brezillon <bbrezillon@kernel.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/nand/raw/Kconfig     |  1 +
 drivers/mtd/nand/raw/nand_base.c | 65 ++++++++++++++++++++++++++++----
 2 files changed, 59 insertions(+), 7 deletions(-)

Comments

Frieder Schrempf Feb. 23, 2019, 1:20 p.m. UTC | #1
On 21.02.19 10:15, Miquel Raynal wrote:
> From: Boris Brezillon <bbrezillon@kernel.org>
> 
> In order to use some of the nanddev_xxx() helpers, we need to
> initialize the nand_device object embedded in nand_chip using
> nanddev_init(). This requires implementing nand_ops.
> 
> We also drop useless mtd->xxx initialization when they're already taken
> case of by nanddev_init().
> 
> Signed-off-by: Boris Brezillon <bbrezillon@kernel.org>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>

> ---
>   drivers/mtd/nand/raw/Kconfig     |  1 +
>   drivers/mtd/nand/raw/nand_base.c | 65 ++++++++++++++++++++++++++++----
>   2 files changed, 59 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig
> index 1a55d3e3d4c5..8c38f2c116a2 100644
> --- a/drivers/mtd/nand/raw/Kconfig
> +++ b/drivers/mtd/nand/raw/Kconfig
> @@ -14,6 +14,7 @@ menuconfig MTD_NAND
>   	tristate "Raw/Parallel NAND Device Support"
>   	depends on MTD
>   	select MTD_NAND_ECC
> +	select MTD_NAND_CORE
>   	help
>   	  This enables support for accessing all type of raw/parallel
>   	  NAND flash devices. For further information see
> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> index cb03877c775c..e8c1ad17f3c6 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -5519,6 +5519,50 @@ static bool nand_ecc_strength_good(struct nand_chip *chip)
>   	return corr >= ds_corr && ecc->strength >= chip->ecc_strength_ds;
>   }
>   
> +static int rawnand_erase(struct nand_device *nand, const struct nand_pos *pos)
> +{
> +	struct nand_chip *chip = container_of(nand, struct nand_chip,
> +					      base);
> +	unsigned int eb = nanddev_pos_to_row(nand, pos);
> +	int ret;
> +
> +	eb >>= nand->rowconv.eraseblock_addr_shift;
> +
> +	nand_select_target(chip, pos->target);
> +	ret = nand_erase_op(chip, eb);
> +	nand_deselect_target(chip);
> +
> +	return ret;
> +}
> +
> +static int rawnand_markbad(struct nand_device *nand,
> +			   const struct nand_pos *pos)
> +{
> +	struct nand_chip *chip = container_of(nand, struct nand_chip,
> +					      base);
> +
> +	return nand_markbad_bbm(chip, nanddev_pos_to_offs(nand, pos));
> +}
> +
> +static bool rawnand_isbad(struct nand_device *nand, const struct nand_pos *pos)
> +{
> +	struct nand_chip *chip = container_of(nand, struct nand_chip,
> +					      base);
> +	int ret;
> +
> +	nand_select_target(chip, pos->target);
> +	ret = nand_isbad_bbm(chip, nanddev_pos_to_offs(nand, pos));
> +	nand_deselect_target(chip);
> +
> +	return ret;
> +}
> +
> +static const struct nand_ops rawnand_ops = {
> +	.erase = rawnand_erase,
> +	.markbad = rawnand_markbad,
> +	.isbad = rawnand_isbad,
> +};
> +
>   /**
>    * nand_scan_tail - Scan for the NAND device
>    * @chip: NAND chip object
> @@ -5787,10 +5831,15 @@ static int nand_scan_tail(struct nand_chip *chip)
>   		break;
>   	}
>   
> +	ret = nanddev_init(&chip->base, &rawnand_ops, mtd->owner);
> +	if (ret)
> +		goto err_nand_manuf_cleanup;
> +
> +	/* Adjust the MTD_CAP_ flags when NAND_ROM is set. */
> +	if (chip->options & NAND_ROM)
> +		mtd->flags = MTD_CAP_ROM;
> +
>   	/* Fill in remaining MTD driver data */
> -	mtd->type = nand_is_slc(chip) ? MTD_NANDFLASH : MTD_MLCNANDFLASH;
> -	mtd->flags = (chip->options & NAND_ROM) ? MTD_CAP_ROM :
> -						MTD_CAP_NANDFLASH;
>   	mtd->_erase = nand_erase;
>   	mtd->_point = NULL;
>   	mtd->_unpoint = NULL;
> @@ -5807,7 +5856,6 @@ static int nand_scan_tail(struct nand_chip *chip)
>   	mtd->_block_isbad = nand_block_isbad;
>   	mtd->_block_markbad = nand_block_markbad;
>   	mtd->_max_bad_blocks = nand_max_bad_blocks;
> -	mtd->writebufsize = mtd->writesize;
>   
>   	/*
>   	 * Initialize bitflip_threshold to its default prior scan_bbt() call.
> @@ -5820,13 +5868,13 @@ static int nand_scan_tail(struct nand_chip *chip)
>   	/* Initialize the ->data_interface field. */
>   	ret = nand_init_data_interface(chip);
>   	if (ret)
> -		goto err_nand_manuf_cleanup;
> +		goto err_nanddev_cleanup;
>   
>   	/* Enter fastest possible mode on all dies. */
>   	for (i = 0; i < chip->numchips; i++) {
>   		ret = nand_setup_data_interface(chip, i);
>   		if (ret)
> -			goto err_nand_manuf_cleanup;
> +			goto err_nanddev_cleanup;
>   	}
>   
>   	/* Check, if we should skip the bad block table scan */
> @@ -5836,11 +5884,14 @@ static int nand_scan_tail(struct nand_chip *chip)
>   	/* Build bad block table */
>   	ret = nand_create_bbt(chip);
>   	if (ret)
> -		goto err_nand_manuf_cleanup;
> +		goto err_nanddev_cleanup;
>   
>   	return 0;
>   
>   
> +err_nanddev_cleanup:
> +	nanddev_cleanup(&chip->base);
> +
>   err_nand_manuf_cleanup:
>   	nand_manufacturer_cleanup(chip);
>   
>

Patch
diff mbox series

diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig
index 1a55d3e3d4c5..8c38f2c116a2 100644
--- a/drivers/mtd/nand/raw/Kconfig
+++ b/drivers/mtd/nand/raw/Kconfig
@@ -14,6 +14,7 @@  menuconfig MTD_NAND
 	tristate "Raw/Parallel NAND Device Support"
 	depends on MTD
 	select MTD_NAND_ECC
+	select MTD_NAND_CORE
 	help
 	  This enables support for accessing all type of raw/parallel
 	  NAND flash devices. For further information see
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index cb03877c775c..e8c1ad17f3c6 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -5519,6 +5519,50 @@  static bool nand_ecc_strength_good(struct nand_chip *chip)
 	return corr >= ds_corr && ecc->strength >= chip->ecc_strength_ds;
 }
 
+static int rawnand_erase(struct nand_device *nand, const struct nand_pos *pos)
+{
+	struct nand_chip *chip = container_of(nand, struct nand_chip,
+					      base);
+	unsigned int eb = nanddev_pos_to_row(nand, pos);
+	int ret;
+
+	eb >>= nand->rowconv.eraseblock_addr_shift;
+
+	nand_select_target(chip, pos->target);
+	ret = nand_erase_op(chip, eb);
+	nand_deselect_target(chip);
+
+	return ret;
+}
+
+static int rawnand_markbad(struct nand_device *nand,
+			   const struct nand_pos *pos)
+{
+	struct nand_chip *chip = container_of(nand, struct nand_chip,
+					      base);
+
+	return nand_markbad_bbm(chip, nanddev_pos_to_offs(nand, pos));
+}
+
+static bool rawnand_isbad(struct nand_device *nand, const struct nand_pos *pos)
+{
+	struct nand_chip *chip = container_of(nand, struct nand_chip,
+					      base);
+	int ret;
+
+	nand_select_target(chip, pos->target);
+	ret = nand_isbad_bbm(chip, nanddev_pos_to_offs(nand, pos));
+	nand_deselect_target(chip);
+
+	return ret;
+}
+
+static const struct nand_ops rawnand_ops = {
+	.erase = rawnand_erase,
+	.markbad = rawnand_markbad,
+	.isbad = rawnand_isbad,
+};
+
 /**
  * nand_scan_tail - Scan for the NAND device
  * @chip: NAND chip object
@@ -5787,10 +5831,15 @@  static int nand_scan_tail(struct nand_chip *chip)
 		break;
 	}
 
+	ret = nanddev_init(&chip->base, &rawnand_ops, mtd->owner);
+	if (ret)
+		goto err_nand_manuf_cleanup;
+
+	/* Adjust the MTD_CAP_ flags when NAND_ROM is set. */
+	if (chip->options & NAND_ROM)
+		mtd->flags = MTD_CAP_ROM;
+
 	/* Fill in remaining MTD driver data */
-	mtd->type = nand_is_slc(chip) ? MTD_NANDFLASH : MTD_MLCNANDFLASH;
-	mtd->flags = (chip->options & NAND_ROM) ? MTD_CAP_ROM :
-						MTD_CAP_NANDFLASH;
 	mtd->_erase = nand_erase;
 	mtd->_point = NULL;
 	mtd->_unpoint = NULL;
@@ -5807,7 +5856,6 @@  static int nand_scan_tail(struct nand_chip *chip)
 	mtd->_block_isbad = nand_block_isbad;
 	mtd->_block_markbad = nand_block_markbad;
 	mtd->_max_bad_blocks = nand_max_bad_blocks;
-	mtd->writebufsize = mtd->writesize;
 
 	/*
 	 * Initialize bitflip_threshold to its default prior scan_bbt() call.
@@ -5820,13 +5868,13 @@  static int nand_scan_tail(struct nand_chip *chip)
 	/* Initialize the ->data_interface field. */
 	ret = nand_init_data_interface(chip);
 	if (ret)
-		goto err_nand_manuf_cleanup;
+		goto err_nanddev_cleanup;
 
 	/* Enter fastest possible mode on all dies. */
 	for (i = 0; i < chip->numchips; i++) {
 		ret = nand_setup_data_interface(chip, i);
 		if (ret)
-			goto err_nand_manuf_cleanup;
+			goto err_nanddev_cleanup;
 	}
 
 	/* Check, if we should skip the bad block table scan */
@@ -5836,11 +5884,14 @@  static int nand_scan_tail(struct nand_chip *chip)
 	/* Build bad block table */
 	ret = nand_create_bbt(chip);
 	if (ret)
-		goto err_nand_manuf_cleanup;
+		goto err_nanddev_cleanup;
 
 	return 0;
 
 
+err_nanddev_cleanup:
+	nanddev_cleanup(&chip->base);
+
 err_nand_manuf_cleanup:
 	nand_manufacturer_cleanup(chip);