diff mbox series

[RFC,22/27] mtd: spinand: Let the SPI-NAND core flag a SPI-NAND chip

Message ID 20190221125806.28875-10-miquel.raynal@bootlin.com
State RFC
Headers show
Series None | expand

Commit Message

Miquel Raynal Feb. 21, 2019, 12:58 p.m. UTC
As of today there is no way to make the distinction between a raw NAND
chip and a SPI-NAND chip. The ABI is stable and we cannot add a
"SPI-NAND" tag to the MTD type, but we can add a special SPINAND
capability to the flags instead. A helper is also provided to retrieve
if whether or not the chip is working over SPI or not.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/nand/core.c    | 2 +-
 include/linux/mtd/mtd.h    | 5 +++++
 include/uapi/mtd/mtd-abi.h | 1 +
 3 files changed, 7 insertions(+), 1 deletion(-)

Comments

Boris Brezillon Feb. 22, 2019, 2:33 p.m. UTC | #1
On Thu, 21 Feb 2019 13:58:01 +0100
Miquel Raynal <miquel.raynal@bootlin.com> wrote:

> As of today there is no way to make the distinction between a raw NAND
> chip and a SPI-NAND chip. The ABI is stable and we cannot add a
> "SPI-NAND" tag to the MTD type, but we can add a special SPINAND
> capability to the flags instead. A helper is also provided to retrieve
> if whether or not the chip is working over SPI or not.

Why would we need a new cap or a new type? The user should only care
about the class of device (NAND, NOR, SRAM, ...) and not the
bus/protocol used to communicate with this device.

> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  drivers/mtd/nand/core.c    | 2 +-
>  include/linux/mtd/mtd.h    | 5 +++++
>  include/uapi/mtd/mtd-abi.h | 1 +
>  3 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c
> index a76d206d233a..872d46b5fc0f 100644
> --- a/drivers/mtd/nand/core.c
> +++ b/drivers/mtd/nand/core.c
> @@ -245,7 +245,7 @@ int nanddev_init(struct nand_device *nand, const struct nand_ops *ops,
>  
>  	mtd->type = memorg->bits_per_cell == 1 ?
>  		    MTD_NANDFLASH : MTD_MLCNANDFLASH;
> -	mtd->flags = MTD_CAP_NANDFLASH;
> +	mtd->flags = MTD_SPINAND | MTD_CAP_NANDFLASH;
>  	mtd->erasesize = memorg->pagesize * memorg->pages_per_eraseblock;
>  	mtd->writesize = memorg->pagesize;
>  	mtd->writebufsize = memorg->pagesize;
> diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
> index 677768b21a1d..7c245d109524 100644
> --- a/include/linux/mtd/mtd.h
> +++ b/include/linux/mtd/mtd.h
> @@ -551,6 +551,11 @@ static inline int mtd_type_is_nand(const struct mtd_info *mtd)
>  	return mtd->type == MTD_NANDFLASH || mtd->type == MTD_MLCNANDFLASH;
>  }
>  
> +static inline int mtd_type_is_spinand(const struct mtd_info *mtd)
> +{
> +	return mtd_type_is_nand(mtd) && (mtd->flags & MTD_SPINAND);
> +}
> +
>  static inline int mtd_can_have_bb(const struct mtd_info *mtd)
>  {
>  	return !!mtd->_block_isbad;
> diff --git a/include/uapi/mtd/mtd-abi.h b/include/uapi/mtd/mtd-abi.h
> index aff5b5e59845..7c7124c88fe0 100644
> --- a/include/uapi/mtd/mtd-abi.h
> +++ b/include/uapi/mtd/mtd-abi.h
> @@ -104,6 +104,7 @@ struct mtd_write_req {
>  #define MTD_BIT_WRITEABLE	0x800	/* Single bits can be flipped */
>  #define MTD_NO_ERASE		0x1000	/* No erase necessary */
>  #define MTD_POWERUP_LOCK	0x2000	/* Always locked after reset */
> +#define MTD_SPINAND		0x4000	/* Device works over SPI */
>  
>  /* Some common devices / combinations of capabilities */
>  #define MTD_CAP_ROM		0
diff mbox series

Patch

diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c
index a76d206d233a..872d46b5fc0f 100644
--- a/drivers/mtd/nand/core.c
+++ b/drivers/mtd/nand/core.c
@@ -245,7 +245,7 @@  int nanddev_init(struct nand_device *nand, const struct nand_ops *ops,
 
 	mtd->type = memorg->bits_per_cell == 1 ?
 		    MTD_NANDFLASH : MTD_MLCNANDFLASH;
-	mtd->flags = MTD_CAP_NANDFLASH;
+	mtd->flags = MTD_SPINAND | MTD_CAP_NANDFLASH;
 	mtd->erasesize = memorg->pagesize * memorg->pages_per_eraseblock;
 	mtd->writesize = memorg->pagesize;
 	mtd->writebufsize = memorg->pagesize;
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 677768b21a1d..7c245d109524 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -551,6 +551,11 @@  static inline int mtd_type_is_nand(const struct mtd_info *mtd)
 	return mtd->type == MTD_NANDFLASH || mtd->type == MTD_MLCNANDFLASH;
 }
 
+static inline int mtd_type_is_spinand(const struct mtd_info *mtd)
+{
+	return mtd_type_is_nand(mtd) && (mtd->flags & MTD_SPINAND);
+}
+
 static inline int mtd_can_have_bb(const struct mtd_info *mtd)
 {
 	return !!mtd->_block_isbad;
diff --git a/include/uapi/mtd/mtd-abi.h b/include/uapi/mtd/mtd-abi.h
index aff5b5e59845..7c7124c88fe0 100644
--- a/include/uapi/mtd/mtd-abi.h
+++ b/include/uapi/mtd/mtd-abi.h
@@ -104,6 +104,7 @@  struct mtd_write_req {
 #define MTD_BIT_WRITEABLE	0x800	/* Single bits can be flipped */
 #define MTD_NO_ERASE		0x1000	/* No erase necessary */
 #define MTD_POWERUP_LOCK	0x2000	/* Always locked after reset */
+#define MTD_SPINAND		0x4000	/* Device works over SPI */
 
 /* Some common devices / combinations of capabilities */
 #define MTD_CAP_ROM		0