Skip to contentSkip to conversation

SPI-NAND support

RFC PATCH New Miquel Raynal 7 participants 65 messages Jun 6, 2018 – Jul 11, 2018

Subsystems (13)
lore
Share & tools
lore

Miquel Raynal

author maintainer
#0 lore raw

cover SPI-NAND support

During the last months, Boris Brezillon shared his work to support serial flashes within Linux. First, he delivered (and merged) a new layer called spi-mem. He also initiated in Linux MTD subsystem the move of all 'raw' NAND related code to a raw/ subdirectory, adding at the same time a NAND core that would be shared with all NAND devices. Then, he contributed a generic SPI-NAND driver, making use of this NAND core, as well as some vendor code to drive a few chips.

On top of this work, I added an 'mtd' U-Boot command to handle all sort of MTD devices. This should become the default command instead of having one per flash flavor ('sf', 'nand', 'spi-nand' ?).

The series has been tested on an Ocelot board PCB123 (VSC7514), featuring a Macronix SPI NAND chip.

TL;DR: the series contains:
- Various fixes and re-organization of the MTD subsystem.
- The introduction of the SPI-mem interface.
- The addition of the generic SPI-NAND driver (and its bindings).
- Several SPI NAND chip drivers (Macronix, Micron, Winbond).
- A new 'mtd' command.
- DT changes to make use of a SPI NAND on the Ocelot board.

Any comments on the code, the organization and the respect of U-Boot driver model will be welcome.

Thanks,
Miquèl

Boris Brezillon (6):
mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing
mtd: nand: Add core infrastructure to deal with NAND devices
mtd: nand: Pass mode information to nand_page_io_req
spi: Extend the core to ease integration of SPI memory controllers
mtd: spinand: Add initial support for the MX35LF1GE4AB chip
dt-bindings: Add bindings for SPI NAND devices

Brian Norris (1):
mtd: add get/set of_node/flash_node helpers

Frieder Schrempf (1):
mtd: spinand: Add initial support for Winbond W25M02GV

Miquel Raynal (10):
mtd: fix build issue with includes
mtd: move definitions to enlarge their range
mtd: move all flash categories inside MTD submenu
mtd: move NAND fiels into a raw/ subdirectory
mtd: rename nand into rawnand in Kconfig prompt
mtd: spinand: Add initial support for the MX35LF2GE4AB chip
mtd: uclass: add probe function
cmd: mtd: add 'mtd' command
mips: dts: ocelot: describe SPI CS pins
mips: dts: ocelot: add the SPI NAND node

Peter Pan (2):
mtd: nand: Add core infrastructure to support SPI NANDs
mtd: spinand: Add initial support for Micron MT29F2G01ABAGD

 arch/mips/dts/mscc,ocelot.dtsi                |   20 +
 arch/mips/dts/mscc,ocelot_pcb.dtsi            |    9 +
 cmd/Kconfig                                   |    5 +
 cmd/Makefile                                  |    1 +
 cmd/mtd.c                                     |  280 ++++++
 doc/device-tree-bindings/mtd/spi-nand.txt     |   27 +
 drivers/mtd/Kconfig                           |    4 +-
 drivers/mtd/Makefile                          |    4 +-
 drivers/mtd/mtd-uclass.c                      |    9 +
 drivers/mtd/mtdcore.c                         |   31 +-
 drivers/mtd/mtdcore.h                         |    6 -
 drivers/mtd/mtdpart.c                         |    6 +-
 drivers/mtd/nand/Kconfig                      |  241 +----
 drivers/mtd/nand/Makefile                     |   81 +-
 drivers/mtd/nand/bbt.c                        |  132 +++
 drivers/mtd/nand/core.c                       |  243 +++++
 drivers/mtd/nand/raw/Kconfig                  |  239 +++++
 drivers/mtd/nand/raw/Makefile                 |   78 ++
 drivers/mtd/nand/{ => raw}/am335x_spl_bch.c   |    0
 drivers/mtd/nand/{ => raw}/arasan_nfc.c       |    0
 drivers/mtd/nand/{ => raw}/atmel_nand.c       |    0
 drivers/mtd/nand/{ => raw}/atmel_nand_ecc.h   |    0
 drivers/mtd/nand/{ => raw}/davinci_nand.c     |    0
 drivers/mtd/nand/{ => raw}/denali.c           |    0
 drivers/mtd/nand/{ => raw}/denali.h           |    0
 drivers/mtd/nand/{ => raw}/denali_dt.c        |    0
 drivers/mtd/nand/{ => raw}/denali_spl.c       |    0
 drivers/mtd/nand/{ => raw}/fsl_elbc_nand.c    |    0
 drivers/mtd/nand/{ => raw}/fsl_elbc_spl.c     |    0
 drivers/mtd/nand/{ => raw}/fsl_ifc_nand.c     |    0
 drivers/mtd/nand/{ => raw}/fsl_ifc_spl.c      |    0
 drivers/mtd/nand/{ => raw}/fsl_upm.c          |    0
 drivers/mtd/nand/{ => raw}/fsmc_nand.c        |    0
 drivers/mtd/nand/{ => raw}/kb9202_nand.c      |    0
 drivers/mtd/nand/{ => raw}/kirkwood_nand.c    |    0
 drivers/mtd/nand/{ => raw}/kmeter1_nand.c     |    0
 drivers/mtd/nand/{ => raw}/lpc32xx_nand_mlc.c |    0
 drivers/mtd/nand/{ => raw}/lpc32xx_nand_slc.c |    0
 drivers/mtd/nand/{ => raw}/mxc_nand.c         |    0
 drivers/mtd/nand/{ => raw}/mxc_nand.h         |    0
 drivers/mtd/nand/{ => raw}/mxc_nand_spl.c     |    0
 drivers/mtd/nand/{ => raw}/mxs_nand.c         |    0
 drivers/mtd/nand/{ => raw}/mxs_nand_spl.c     |    0
 drivers/mtd/nand/{ => raw}/nand.c             |    0
 drivers/mtd/nand/{ => raw}/nand_base.c        |   56 --
 drivers/mtd/nand/{ => raw}/nand_bbt.c         |    0
 drivers/mtd/nand/{ => raw}/nand_bch.c         |    0
 drivers/mtd/nand/{ => raw}/nand_ecc.c         |    0
 drivers/mtd/nand/{ => raw}/nand_ids.c         |    0
 drivers/mtd/nand/{ => raw}/nand_plat.c        |    0
 drivers/mtd/nand/{ => raw}/nand_spl_load.c    |    0
 drivers/mtd/nand/{ => raw}/nand_spl_loaders.c |    0
 drivers/mtd/nand/{ => raw}/nand_spl_simple.c  |    0
 drivers/mtd/nand/{ => raw}/nand_timings.c     |    0
 drivers/mtd/nand/{ => raw}/nand_util.c        |    0
 drivers/mtd/nand/{ => raw}/ndfc.c             |    0
 drivers/mtd/nand/{ => raw}/omap_elm.c         |    0
 drivers/mtd/nand/{ => raw}/omap_gpmc.c        |    0
 drivers/mtd/nand/{ => raw}/pxa3xx_nand.c      |    0
 drivers/mtd/nand/{ => raw}/pxa3xx_nand.h      |    0
 drivers/mtd/nand/{ => raw}/sunxi_nand.c       |    0
 drivers/mtd/nand/{ => raw}/sunxi_nand_spl.c   |    0
 drivers/mtd/nand/{ => raw}/tegra_nand.c       |    0
 drivers/mtd/nand/{ => raw}/tegra_nand.h       |    0
 drivers/mtd/nand/{ => raw}/vf610_nfc.c        |    0
 drivers/mtd/nand/{ => raw}/zynq_nand.c        |    0
 drivers/mtd/nand/spi/Kconfig                  |    7 +
 drivers/mtd/nand/spi/Makefile                 |    4 +
 drivers/mtd/nand/spi/core.c                   | 1252 +++++++++++++++++++++++++
 drivers/mtd/nand/spi/macronix.c               |  146 +++
 drivers/mtd/nand/spi/micron.c                 |  135 +++
 drivers/mtd/nand/spi/winbond.c                |  143 +++
 drivers/mtd/onenand/onenand_base.c            |   60 --
 drivers/spi/Kconfig                           |    7 +
 drivers/spi/Makefile                          |    1 +
 drivers/spi/spi-mem.c                         |  500 ++++++++++
 include/linux/mtd/mtd.h                       |   21 +
 include/linux/mtd/nand.h                      |  734 +++++++++++++++
 include/linux/mtd/spinand.h                   |  432 +++++++++
 include/spi-mem.h                             |  258 +++++
 include/spi.h                                 |   11 +
 81 files changed, 4741 insertions(+), 442 deletions(-)
 create mode 100644 cmd/mtd.c
 create mode 100644 doc/device-tree-bindings/mtd/spi-nand.txt
 create mode 100644 drivers/mtd/nand/bbt.c
 create mode 100644 drivers/mtd/nand/core.c
 create mode 100644 drivers/mtd/nand/raw/Kconfig
 create mode 100644 drivers/mtd/nand/raw/Makefile
 rename drivers/mtd/nand/{ => raw}/am335x_spl_bch.c (100%)
 rename drivers/mtd/nand/{ => raw}/arasan_nfc.c (100%)
 rename drivers/mtd/nand/{ => raw}/atmel_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/atmel_nand_ecc.h (100%)
 rename drivers/mtd/nand/{ => raw}/davinci_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/denali.c (100%)
 rename drivers/mtd/nand/{ => raw}/denali.h (100%)
 rename drivers/mtd/nand/{ => raw}/denali_dt.c (100%)
 rename drivers/mtd/nand/{ => raw}/denali_spl.c (100%)
 rename drivers/mtd/nand/{ => raw}/fsl_elbc_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/fsl_elbc_spl.c (100%)
 rename drivers/mtd/nand/{ => raw}/fsl_ifc_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/fsl_ifc_spl.c (100%)
 rename drivers/mtd/nand/{ => raw}/fsl_upm.c (100%)
 rename drivers/mtd/nand/{ => raw}/fsmc_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/kb9202_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/kirkwood_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/kmeter1_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/lpc32xx_nand_mlc.c (100%)
 rename drivers/mtd/nand/{ => raw}/lpc32xx_nand_slc.c (100%)
 rename drivers/mtd/nand/{ => raw}/mxc_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/mxc_nand.h (100%)
 rename drivers/mtd/nand/{ => raw}/mxc_nand_spl.c (100%)
 rename drivers/mtd/nand/{ => raw}/mxs_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/mxs_nand_spl.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_base.c (98%)
 rename drivers/mtd/nand/{ => raw}/nand_bbt.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_bch.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_ecc.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_ids.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_plat.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_spl_load.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_spl_loaders.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_spl_simple.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_timings.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_util.c (100%)
 rename drivers/mtd/nand/{ => raw}/ndfc.c (100%)
 rename drivers/mtd/nand/{ => raw}/omap_elm.c (100%)
 rename drivers/mtd/nand/{ => raw}/omap_gpmc.c (100%)
 rename drivers/mtd/nand/{ => raw}/pxa3xx_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/pxa3xx_nand.h (100%)
 rename drivers/mtd/nand/{ => raw}/sunxi_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/sunxi_nand_spl.c (100%)
 rename drivers/mtd/nand/{ => raw}/tegra_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/tegra_nand.h (100%)
 rename drivers/mtd/nand/{ => raw}/vf610_nfc.c (100%)
 rename drivers/mtd/nand/{ => raw}/zynq_nand.c (100%)
 create mode 100644 drivers/mtd/nand/spi/Kconfig
 create mode 100644 drivers/mtd/nand/spi/Makefile
 create mode 100644 drivers/mtd/nand/spi/core.c
 create mode 100644 drivers/mtd/nand/spi/macronix.c
 create mode 100644 drivers/mtd/nand/spi/micron.c
 create mode 100644 drivers/mtd/nand/spi/winbond.c
 create mode 100644 drivers/spi/spi-mem.c
 create mode 100644 include/linux/mtd/nand.h
 create mode 100644 include/linux/mtd/spinand.h
 create mode 100644 include/spi-mem.h
Signature · 1 line
2.14.1
author maintainer
#1 lore raw

RFC PATCH 1/20 mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing

From: Boris Brezillon <[email protected]>

Some MTD sublayers/drivers are implementing ->_read/write_oob() and provide dummy wrappers for their ->_read/write() implementations. Let the core handle this case instead of duplicating the logic.

---
 drivers/mtd/mtdcore.c              | 31 ++++++++++++++++++--
 drivers/mtd/mtdpart.c              |  6 ++--
 drivers/mtd/nand/nand_base.c       | 56 -----------------------------------
 drivers/mtd/onenand/onenand_base.c | 60 --------------------------------------
 4 files changed, 33 insertions(+), 120 deletions(-)
drivers/mtd/mtdcore.c +29 -2
index 2cda0511e8..15e0ac2f3e 100644
@@ -938,7 +938,20 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
 	 * representing the maximum number of bitflips that were corrected on
 	 * any one ecc region (if applicable; zero otherwise).
 	 */
-	ret_code = mtd->_read(mtd, from, len, retlen, buf);
+	if (mtd->_read) {
+		ret_code = mtd->_read(mtd, from, len, retlen, buf);
+	} else if (mtd->_read_oob) {
+		struct mtd_oob_ops ops = {
+			.len = len,
+			.datbuf = buf,
+		};
+
+		ret_code = mtd->_read_oob(mtd, from, &ops);
+		*retlen = ops.retlen;
+	} else {
+		return -ENOTSUPP;
+	}
+
 	if (unlikely(ret_code < 0))
 		return ret_code;
 	if (mtd->ecc_strength == 0)
@@ -953,10 +966,24 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
 	*retlen = 0;
 	if (to < 0 || to > mtd->size || len > mtd->size - to)
 		return -EINVAL;
-	if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE))
+	if ((!mtd->_write && !mtd->_write_oob) ||
+	    !(mtd->flags & MTD_WRITEABLE))
 		return -EROFS;
 	if (!len)
 		return 0;
+
+	if (!mtd->_write) {
+		struct mtd_oob_ops ops = {
+			.len = len,
+			.datbuf = (u8 *)buf,
+		};
+		int ret;
+
+		ret = mtd->_write_oob(mtd, to, &ops);
+		*retlen = ops.retlen;
+		return ret;
+	}
+
 	return mtd->_write(mtd, to, len, retlen, buf);
 }
 EXPORT_SYMBOL_GPL(mtd_write);
drivers/mtd/mtdpart.c +4 -2
index 5e42c4b833..3a3f2a1717 100644
@@ -418,8 +418,10 @@ static struct mtd_part *allocate_partition(struct mtd_info *master,
 	slave->mtd.dev.parent = master->dev.parent;
 #endif
 
-	slave->mtd._read = part_read;
-	slave->mtd._write = part_write;
+	if (parent->_read)
+		slave->mtd._read = part_read;
+	if (parent->_write)
+		slave->mtd._write = part_write;
 
 	if (master->_panic_write)
 		slave->mtd._panic_write = part_panic_write;
drivers/mtd/nand/nand_base.c +0 -56

74 lines not on this page · raw message

drivers/mtd/onenand/onenand_base.c +0 -60

78 lines not on this page · raw message

Signature · 1 line
2.14.1
#2 lore raw

RFC PATCH 1/20 mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing

Quoted 6 lines · Miquel Raynal

From: Boris Brezillon <[email protected]>

Some MTD sublayers/drivers are implementing ->_read/write_oob() and provide dummy wrappers for their ->_read/write() implementations. Let the core handle this case instead of duplicating the logic.

Quoted 7 lines

---

author maintainer
#3 lore raw

RFC PATCH 2/20 mtd: add get/set of_node/flash_node helpers

In reply to Miquel Raynal

From: Brian Norris <[email protected]>

We are going to begin using the mtd->dev.of_node field for MTD device nodes, so let's add helpers for it. Also, we'll be making some conversions on spi_nor (and nand_chip eventually) too, so get that ready with their own helpers.

---
 include/linux/mtd/mtd.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/mtd/mtd.h +11 -0
index ba4cbba949..777a926623 100644
@@ -311,6 +311,17 @@ struct mtd_info {
 	int usecount;
 };
 
+static inline void mtd_set_of_node(struct mtd_info *mtd,
+				   const struct device_node *np)
+{
+	mtd->dev->node.np = np;
+}
+
+static inline const struct device_node *mtd_get_of_node(struct mtd_info *mtd)
+{
+	return mtd->dev->node.np;
+}
+
 int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
 		      struct mtd_oob_region *oobecc);
 int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte,
Signature · 1 line
2.14.1
#4 lore raw

RFC PATCH 2/20 mtd: add get/set of_node/flash_node helpers

Quoted 11 lines · Miquel Raynal

From: Brian Norris <[email protected]>

We are going to begin using the mtd->dev.of_node field for MTD device nodes, so let's add helpers for it. Also, we'll be making some conversions on spi_nor (and nand_chip eventually) too, so get that ready with their own helpers.

---

author maintainer
#5 lore raw

RFC PATCH 3/20 mtd: fix build issue with includes

In reply to Miquel Raynal

Fix build errors produced by mtd.h and dm/device.h if not included in the right order.

---
 include/linux/mtd/mtd.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/mtd/mtd.h +1 -0
index 777a926623..52d1afb5b8 100644
@@ -22,6 +22,7 @@
 #include <mtd/mtd-abi.h>
 #include <linux/errno.h>
 #include <div64.h>
+#include <dm/device.h>
 
 #define MAX_MTD_DEVICES 32
 #endif
Signature · 1 line
2.14.1
author maintainer
#7 lore raw

RFC PATCH 4/20 mtd: move definitions to enlarge their range

In reply to Miquel Raynal

Some helpers might be useful in a future 'mtd' U-Boot command to parse MTD device list.

---
 drivers/mtd/mtdcore.h   | 6 ------
 include/linux/mtd/mtd.h | 6 ++++++
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/mtd/mtdcore.h +0 -6
index 7b0353399a..1d181a1045 100644
@@ -5,7 +5,6 @@
 
 extern struct mutex mtd_table_mutex;
 
-struct mtd_info *__mtd_next_device(int i);
 int add_mtd_device(struct mtd_info *mtd);
 int del_mtd_device(struct mtd_info *mtd);
 int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
@@ -16,8 +15,3 @@ int parse_mtd_partitions(struct mtd_info *master, const char * const *types,
 
 int __init init_mtdchar(void);
 void __exit cleanup_mtdchar(void);
-
-#define mtd_for_each_device(mtd)			\
-	for ((mtd) = __mtd_next_device(0);		\
-	     (mtd) != NULL;				\
-	     (mtd) = __mtd_next_device(mtd->index + 1))
include/linux/mtd/mtd.h +6 -0
index 52d1afb5b8..b5f9151a70 100644
@@ -532,6 +532,12 @@ int del_mtd_device(struct mtd_info *mtd);
 int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
 int del_mtd_partitions(struct mtd_info *);
 
+struct mtd_info *__mtd_next_device(int i);
+#define mtd_for_each_device(mtd)			\
+	for ((mtd) = __mtd_next_device(0);		\
+	     (mtd) != NULL;				\
+	     (mtd) = __mtd_next_device(mtd->index + 1))
+
 int mtd_arg_off(const char *arg, int *idx, loff_t *off, loff_t *size,
 		loff_t *maxsize, int devtype, uint64_t chipsize);
 int mtd_arg_off_size(int argc, char *const argv[], int *idx, loff_t *off,
Signature · 1 line
2.14.1
author maintainer
#8 lore raw

RFC PATCH 5/20 mtd: move all flash categories inside MTD submenu

In reply to Miquel Raynal

There is no reason to have NAND, SPI flashes and UBI sections outside of the MTD submenu in Kconfig.

---
 drivers/mtd/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/Kconfig +2 -2
index 19579801d2..d21b0920dc 100644
@@ -40,10 +40,10 @@ config FLASH_PIC32
 	  This enables access to Microchip PIC32 internal non-CFI flash
 	  chips through PIC32 Non-Volatile-Memory Controller.
 
-endmenu
-
 source "drivers/mtd/nand/Kconfig"
 
 source "drivers/mtd/spi/Kconfig"
 
 source "drivers/mtd/ubi/Kconfig"
+
+endmenu
Signature · 1 line
2.14.1
author maintainer
#10 lore raw

RFC PATCH 6/20 mtd: move NAND fiels into a raw/ subdirectory

In reply to Miquel Raynal

NAND flavors, like serial and parallel, have a lot in common and would benefit to share code. Let's move raw (parallel) NAND specific code in a raw/ subdirectory, to ease the addition of a core file in nand/ and the introduction of a spi/ subdirectory specific to SPI NANDs.

---
 drivers/mtd/Makefile                          |   2 +
 drivers/mtd/nand/Kconfig                      | 240 +-------------------------
 drivers/mtd/nand/Makefile                     |  79 +--------
 drivers/mtd/nand/raw/Kconfig                  | 239 +++++++++++++++++++++++++
 drivers/mtd/nand/raw/Makefile                 |  78 +++++++++
 drivers/mtd/nand/{ => raw}/am335x_spl_bch.c   |   0
 drivers/mtd/nand/{ => raw}/arasan_nfc.c       |   0
 drivers/mtd/nand/{ => raw}/atmel_nand.c       |   0
 drivers/mtd/nand/{ => raw}/atmel_nand_ecc.h   |   0
 drivers/mtd/nand/{ => raw}/davinci_nand.c     |   0
 drivers/mtd/nand/{ => raw}/denali.c           |   0
 drivers/mtd/nand/{ => raw}/denali.h           |   0
 drivers/mtd/nand/{ => raw}/denali_dt.c        |   0
 drivers/mtd/nand/{ => raw}/denali_spl.c       |   0
 drivers/mtd/nand/{ => raw}/fsl_elbc_nand.c    |   0
 drivers/mtd/nand/{ => raw}/fsl_elbc_spl.c     |   0
 drivers/mtd/nand/{ => raw}/fsl_ifc_nand.c     |   0
 drivers/mtd/nand/{ => raw}/fsl_ifc_spl.c      |   0
 drivers/mtd/nand/{ => raw}/fsl_upm.c          |   0
 drivers/mtd/nand/{ => raw}/fsmc_nand.c        |   0
 drivers/mtd/nand/{ => raw}/kb9202_nand.c      |   0
 drivers/mtd/nand/{ => raw}/kirkwood_nand.c    |   0
 drivers/mtd/nand/{ => raw}/kmeter1_nand.c     |   0
 drivers/mtd/nand/{ => raw}/lpc32xx_nand_mlc.c |   0
 drivers/mtd/nand/{ => raw}/lpc32xx_nand_slc.c |   0
 drivers/mtd/nand/{ => raw}/mxc_nand.c         |   0
 drivers/mtd/nand/{ => raw}/mxc_nand.h         |   0
 drivers/mtd/nand/{ => raw}/mxc_nand_spl.c     |   0
 drivers/mtd/nand/{ => raw}/mxs_nand.c         |   0
 drivers/mtd/nand/{ => raw}/mxs_nand_spl.c     |   0
 drivers/mtd/nand/{ => raw}/nand.c             |   0
 drivers/mtd/nand/{ => raw}/nand_base.c        |   0
 drivers/mtd/nand/{ => raw}/nand_bbt.c         |   0
 drivers/mtd/nand/{ => raw}/nand_bch.c         |   0
 drivers/mtd/nand/{ => raw}/nand_ecc.c         |   0
 drivers/mtd/nand/{ => raw}/nand_ids.c         |   0
 drivers/mtd/nand/{ => raw}/nand_plat.c        |   0
 drivers/mtd/nand/{ => raw}/nand_spl_load.c    |   0
 drivers/mtd/nand/{ => raw}/nand_spl_loaders.c |   0
 drivers/mtd/nand/{ => raw}/nand_spl_simple.c  |   0
 drivers/mtd/nand/{ => raw}/nand_timings.c     |   0
 drivers/mtd/nand/{ => raw}/nand_util.c        |   0
 drivers/mtd/nand/{ => raw}/ndfc.c             |   0
 drivers/mtd/nand/{ => raw}/omap_elm.c         |   0
 drivers/mtd/nand/{ => raw}/omap_gpmc.c        |   0
 drivers/mtd/nand/{ => raw}/pxa3xx_nand.c      |   0
 drivers/mtd/nand/{ => raw}/pxa3xx_nand.h      |   0
 drivers/mtd/nand/{ => raw}/sunxi_nand.c       |   0
 drivers/mtd/nand/{ => raw}/sunxi_nand_spl.c   |   0
 drivers/mtd/nand/{ => raw}/tegra_nand.c       |   0
 drivers/mtd/nand/{ => raw}/tegra_nand.h       |   0
 drivers/mtd/nand/{ => raw}/vf610_nfc.c        |   0
 drivers/mtd/nand/{ => raw}/zynq_nand.c        |   0
 53 files changed, 322 insertions(+), 316 deletions(-)
 create mode 100644 drivers/mtd/nand/raw/Kconfig
 create mode 100644 drivers/mtd/nand/raw/Makefile
 rename drivers/mtd/nand/{ => raw}/am335x_spl_bch.c (100%)
 rename drivers/mtd/nand/{ => raw}/arasan_nfc.c (100%)
 rename drivers/mtd/nand/{ => raw}/atmel_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/atmel_nand_ecc.h (100%)
 rename drivers/mtd/nand/{ => raw}/davinci_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/denali.c (100%)
 rename drivers/mtd/nand/{ => raw}/denali.h (100%)
 rename drivers/mtd/nand/{ => raw}/denali_dt.c (100%)
 rename drivers/mtd/nand/{ => raw}/denali_spl.c (100%)
 rename drivers/mtd/nand/{ => raw}/fsl_elbc_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/fsl_elbc_spl.c (100%)
 rename drivers/mtd/nand/{ => raw}/fsl_ifc_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/fsl_ifc_spl.c (100%)
 rename drivers/mtd/nand/{ => raw}/fsl_upm.c (100%)
 rename drivers/mtd/nand/{ => raw}/fsmc_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/kb9202_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/kirkwood_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/kmeter1_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/lpc32xx_nand_mlc.c (100%)
 rename drivers/mtd/nand/{ => raw}/lpc32xx_nand_slc.c (100%)
 rename drivers/mtd/nand/{ => raw}/mxc_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/mxc_nand.h (100%)
 rename drivers/mtd/nand/{ => raw}/mxc_nand_spl.c (100%)
 rename drivers/mtd/nand/{ => raw}/mxs_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/mxs_nand_spl.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_base.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_bbt.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_bch.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_ecc.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_ids.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_plat.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_spl_load.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_spl_loaders.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_spl_simple.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_timings.c (100%)
 rename drivers/mtd/nand/{ => raw}/nand_util.c (100%)
 rename drivers/mtd/nand/{ => raw}/ndfc.c (100%)
 rename drivers/mtd/nand/{ => raw}/omap_elm.c (100%)
 rename drivers/mtd/nand/{ => raw}/omap_gpmc.c (100%)
 rename drivers/mtd/nand/{ => raw}/pxa3xx_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/pxa3xx_nand.h (100%)
 rename drivers/mtd/nand/{ => raw}/sunxi_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/sunxi_nand_spl.c (100%)
 rename drivers/mtd/nand/{ => raw}/tegra_nand.c (100%)
 rename drivers/mtd/nand/{ => raw}/tegra_nand.h (100%)
 rename drivers/mtd/nand/{ => raw}/vf610_nfc.c (100%)
 rename drivers/mtd/nand/{ => raw}/zynq_nand.c (100%)
drivers/mtd/Makefile +2 -0
index 20c0d0af44..eb0e7264ab 100644
@@ -20,3 +20,5 @@ obj-$(CONFIG_MW_EEPROM) += mw_eeprom.o
 obj-$(CONFIG_FLASH_PIC32) += pic32_flash.o
 obj-$(CONFIG_ST_SMI) += st_smi.o
 obj-$(CONFIG_STM32_FLASH) += stm32_flash.o
+
+obj-y += nand/
drivers/mtd/nand/Kconfig +1 -239

240 lines not on this page · raw message

drivers/mtd/nand/Makefile +2 -77

80 lines not on this page · raw message

drivers/mtd/nand/raw/Kconfig new file +239 -0

239 lines not on this page · raw message

drivers/mtd/nand/raw/Makefile new file +78 -0

78 lines not on this page · raw message

drivers/mtd/nand/raw/am335x_spl_bch.c renamed from drivers/mtd/nand/am335x_spl_bch.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/am335x_spl_bch.c
rename to drivers/mtd/nand/raw/am335x_spl_bch.c
drivers/mtd/nand/raw/arasan_nfc.c renamed from drivers/mtd/nand/arasan_nfc.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/arasan_nfc.c
rename to drivers/mtd/nand/raw/arasan_nfc.c
drivers/mtd/nand/raw/atmel_nand.c renamed from drivers/mtd/nand/atmel_nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/atmel_nand.c
rename to drivers/mtd/nand/raw/atmel_nand.c
drivers/mtd/nand/raw/atmel_nand_ecc.h renamed from drivers/mtd/nand/atmel_nand_ecc.h +0 -0
similarity index 100%
rename from drivers/mtd/nand/atmel_nand_ecc.h
rename to drivers/mtd/nand/raw/atmel_nand_ecc.h
drivers/mtd/nand/raw/davinci_nand.c renamed from drivers/mtd/nand/davinci_nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/davinci_nand.c
rename to drivers/mtd/nand/raw/davinci_nand.c
drivers/mtd/nand/raw/denali.c renamed from drivers/mtd/nand/denali.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/denali.c
rename to drivers/mtd/nand/raw/denali.c
drivers/mtd/nand/raw/denali.h renamed from drivers/mtd/nand/denali.h +0 -0
similarity index 100%
rename from drivers/mtd/nand/denali.h
rename to drivers/mtd/nand/raw/denali.h
drivers/mtd/nand/raw/denali_dt.c renamed from drivers/mtd/nand/denali_dt.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/denali_dt.c
rename to drivers/mtd/nand/raw/denali_dt.c
drivers/mtd/nand/raw/denali_spl.c renamed from drivers/mtd/nand/denali_spl.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/denali_spl.c
rename to drivers/mtd/nand/raw/denali_spl.c
drivers/mtd/nand/raw/fsl_elbc_nand.c renamed from drivers/mtd/nand/fsl_elbc_nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/fsl_elbc_nand.c
rename to drivers/mtd/nand/raw/fsl_elbc_nand.c
drivers/mtd/nand/raw/fsl_elbc_spl.c renamed from drivers/mtd/nand/fsl_elbc_spl.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/fsl_elbc_spl.c
rename to drivers/mtd/nand/raw/fsl_elbc_spl.c
drivers/mtd/nand/raw/fsl_ifc_nand.c renamed from drivers/mtd/nand/fsl_ifc_nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/fsl_ifc_nand.c
rename to drivers/mtd/nand/raw/fsl_ifc_nand.c
drivers/mtd/nand/raw/fsl_ifc_spl.c renamed from drivers/mtd/nand/fsl_ifc_spl.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/fsl_ifc_spl.c
rename to drivers/mtd/nand/raw/fsl_ifc_spl.c
drivers/mtd/nand/raw/fsl_upm.c renamed from drivers/mtd/nand/fsl_upm.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/fsl_upm.c
rename to drivers/mtd/nand/raw/fsl_upm.c
drivers/mtd/nand/raw/fsmc_nand.c renamed from drivers/mtd/nand/fsmc_nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/fsmc_nand.c
rename to drivers/mtd/nand/raw/fsmc_nand.c
drivers/mtd/nand/raw/kb9202_nand.c renamed from drivers/mtd/nand/kb9202_nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/kb9202_nand.c
rename to drivers/mtd/nand/raw/kb9202_nand.c
drivers/mtd/nand/raw/kirkwood_nand.c renamed from drivers/mtd/nand/kirkwood_nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/kirkwood_nand.c
rename to drivers/mtd/nand/raw/kirkwood_nand.c
drivers/mtd/nand/raw/kmeter1_nand.c renamed from drivers/mtd/nand/kmeter1_nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/kmeter1_nand.c
rename to drivers/mtd/nand/raw/kmeter1_nand.c
drivers/mtd/nand/raw/lpc32xx_nand_mlc.c renamed from drivers/mtd/nand/lpc32xx_nand_mlc.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/lpc32xx_nand_mlc.c
rename to drivers/mtd/nand/raw/lpc32xx_nand_mlc.c
drivers/mtd/nand/raw/lpc32xx_nand_slc.c renamed from drivers/mtd/nand/lpc32xx_nand_slc.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/lpc32xx_nand_slc.c
rename to drivers/mtd/nand/raw/lpc32xx_nand_slc.c
drivers/mtd/nand/raw/mxc_nand.c renamed from drivers/mtd/nand/mxc_nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/mxc_nand.c
rename to drivers/mtd/nand/raw/mxc_nand.c
drivers/mtd/nand/raw/mxc_nand.h renamed from drivers/mtd/nand/mxc_nand.h +0 -0
similarity index 100%
rename from drivers/mtd/nand/mxc_nand.h
rename to drivers/mtd/nand/raw/mxc_nand.h
drivers/mtd/nand/raw/mxc_nand_spl.c renamed from drivers/mtd/nand/mxc_nand_spl.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/mxc_nand_spl.c
rename to drivers/mtd/nand/raw/mxc_nand_spl.c
drivers/mtd/nand/raw/mxs_nand.c renamed from drivers/mtd/nand/mxs_nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/mxs_nand.c
rename to drivers/mtd/nand/raw/mxs_nand.c
drivers/mtd/nand/raw/mxs_nand_spl.c renamed from drivers/mtd/nand/mxs_nand_spl.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/mxs_nand_spl.c
rename to drivers/mtd/nand/raw/mxs_nand_spl.c
drivers/mtd/nand/raw/nand.c renamed from drivers/mtd/nand/nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/nand.c
rename to drivers/mtd/nand/raw/nand.c
drivers/mtd/nand/raw/nand_base.c renamed from drivers/mtd/nand/nand_base.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/nand_base.c
rename to drivers/mtd/nand/raw/nand_base.c
drivers/mtd/nand/raw/nand_bbt.c renamed from drivers/mtd/nand/nand_bbt.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/nand_bbt.c
rename to drivers/mtd/nand/raw/nand_bbt.c
drivers/mtd/nand/raw/nand_bch.c renamed from drivers/mtd/nand/nand_bch.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/nand_bch.c
rename to drivers/mtd/nand/raw/nand_bch.c
drivers/mtd/nand/raw/nand_ecc.c renamed from drivers/mtd/nand/nand_ecc.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/nand_ecc.c
rename to drivers/mtd/nand/raw/nand_ecc.c
drivers/mtd/nand/raw/nand_ids.c renamed from drivers/mtd/nand/nand_ids.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/nand_ids.c
rename to drivers/mtd/nand/raw/nand_ids.c
drivers/mtd/nand/raw/nand_plat.c renamed from drivers/mtd/nand/nand_plat.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/nand_plat.c
rename to drivers/mtd/nand/raw/nand_plat.c
drivers/mtd/nand/raw/nand_spl_load.c renamed from drivers/mtd/nand/nand_spl_load.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/nand_spl_load.c
rename to drivers/mtd/nand/raw/nand_spl_load.c
drivers/mtd/nand/raw/nand_spl_loaders.c renamed from drivers/mtd/nand/nand_spl_loaders.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/nand_spl_loaders.c
rename to drivers/mtd/nand/raw/nand_spl_loaders.c
drivers/mtd/nand/raw/nand_spl_simple.c renamed from drivers/mtd/nand/nand_spl_simple.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/nand_spl_simple.c
rename to drivers/mtd/nand/raw/nand_spl_simple.c
drivers/mtd/nand/raw/nand_timings.c renamed from drivers/mtd/nand/nand_timings.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/nand_timings.c
rename to drivers/mtd/nand/raw/nand_timings.c
drivers/mtd/nand/raw/nand_util.c renamed from drivers/mtd/nand/nand_util.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/nand_util.c
rename to drivers/mtd/nand/raw/nand_util.c
drivers/mtd/nand/raw/ndfc.c renamed from drivers/mtd/nand/ndfc.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/ndfc.c
rename to drivers/mtd/nand/raw/ndfc.c
drivers/mtd/nand/raw/omap_elm.c renamed from drivers/mtd/nand/omap_elm.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/omap_elm.c
rename to drivers/mtd/nand/raw/omap_elm.c
drivers/mtd/nand/raw/omap_gpmc.c renamed from drivers/mtd/nand/omap_gpmc.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/omap_gpmc.c
rename to drivers/mtd/nand/raw/omap_gpmc.c
drivers/mtd/nand/raw/pxa3xx_nand.c renamed from drivers/mtd/nand/pxa3xx_nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/pxa3xx_nand.c
rename to drivers/mtd/nand/raw/pxa3xx_nand.c
drivers/mtd/nand/raw/pxa3xx_nand.h renamed from drivers/mtd/nand/pxa3xx_nand.h +0 -0
similarity index 100%
rename from drivers/mtd/nand/pxa3xx_nand.h
rename to drivers/mtd/nand/raw/pxa3xx_nand.h
drivers/mtd/nand/raw/sunxi_nand.c renamed from drivers/mtd/nand/sunxi_nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/sunxi_nand.c
rename to drivers/mtd/nand/raw/sunxi_nand.c
drivers/mtd/nand/raw/sunxi_nand_spl.c renamed from drivers/mtd/nand/sunxi_nand_spl.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/sunxi_nand_spl.c
rename to drivers/mtd/nand/raw/sunxi_nand_spl.c
drivers/mtd/nand/raw/tegra_nand.c renamed from drivers/mtd/nand/tegra_nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/tegra_nand.c
rename to drivers/mtd/nand/raw/tegra_nand.c
drivers/mtd/nand/raw/tegra_nand.h renamed from drivers/mtd/nand/tegra_nand.h +0 -0
similarity index 100%
rename from drivers/mtd/nand/tegra_nand.h
rename to drivers/mtd/nand/raw/tegra_nand.h
drivers/mtd/nand/raw/vf610_nfc.c renamed from drivers/mtd/nand/vf610_nfc.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/vf610_nfc.c
rename to drivers/mtd/nand/raw/vf610_nfc.c
drivers/mtd/nand/raw/zynq_nand.c renamed from drivers/mtd/nand/zynq_nand.c +0 -0
similarity index 100%
rename from drivers/mtd/nand/zynq_nand.c
rename to drivers/mtd/nand/raw/zynq_nand.c
Signature · 1 line
2.14.1
author maintainer
#11 lore raw

RFC PATCH 7/20 mtd: rename nand into rawnand in Kconfig prompt

In reply to Miquel Raynal

Sync the Kconfig raw NAND entry title with the code architecture.

---
 drivers/mtd/nand/raw/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/Kconfig +1 -1
index a820af61ce..6ef82cab88 100644
@@ -1,6 +1,6 @@
 
 menuconfig NAND
-	bool "NAND Device Support"
+	bool "Raw NAND Device Support"
 if NAND
 
 config SYS_NAND_SELF_INIT
Signature · 1 line
2.14.1
author maintainer
#12 lore raw

RFC PATCH 8/20 mtd: nand: Add core infrastructure to deal with NAND devices

In reply to Miquel Raynal

From: Boris Brezillon <[email protected]>

Add an intermediate layer to abstract NAND device interface so that some logic can be shared between SPI NANDs, parallel/raw NANDs, OneNANDs, ...

---
 drivers/mtd/nand/Kconfig  |   3 +
 drivers/mtd/nand/Makefile |   3 +
 drivers/mtd/nand/bbt.c    | 132 +++++++++
 drivers/mtd/nand/core.c   | 243 +++++++++++++++
 include/linux/mtd/nand.h  | 731 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1112 insertions(+)
 create mode 100644 drivers/mtd/nand/bbt.c
 create mode 100644 drivers/mtd/nand/core.c
 create mode 100644 include/linux/mtd/nand.h
drivers/mtd/nand/Kconfig +3 -0
index 6d53734718..1c1a1f487e 100644
@@ -1 +1,4 @@
+config MTD_NAND_CORE
+	tristate
+
 source "drivers/mtd/nand/raw/Kconfig"
drivers/mtd/nand/Makefile +3 -0
index d1c3f93047..69c80ea252 100644
@@ -1,3 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
+nandcore-objs := core.o bbt.o
+obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
+
 obj-$(CONFIG_MTD_NAND) += raw/
drivers/mtd/nand/bbt.c new file +132 -0

132 lines not on this page · raw message

drivers/mtd/nand/core.c new file +243 -0

243 lines not on this page · raw message

include/linux/mtd/nand.h new file +731 -0

731 lines not on this page · raw message

Signature · 1 line
2.14.1
#13 lore raw

RFC PATCH 8/20 mtd: nand: Add core infrastructure to deal with NAND devices

Quoted 73 lines · Miquel Raynal

From: Boris Brezillon <[email protected]>

Add an intermediate layer to abstract NAND device interface so that some logic can be shared between SPI NANDs, parallel/raw NANDs, OneNANDs, ...

---
 drivers/mtd/nand/Kconfig  |   3 +
 drivers/mtd/nand/Makefile |   3 +
 drivers/mtd/nand/bbt.c    | 132 +++++++++
 drivers/mtd/nand/core.c   | 243 +++++++++++++++
 include/linux/mtd/nand.h  | 731 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1112 insertions(+)
 create mode 100644 drivers/mtd/nand/bbt.c
 create mode 100644 drivers/mtd/nand/core.c
 create mode 100644 include/linux/mtd/nand.h
drivers/mtd/nand/Kconfig +3 -0
index 6d53734718..1c1a1f487e 100644
@@ -1 +1,4 @@
+config MTD_NAND_CORE
+       tristate
+
 source "drivers/mtd/nand/raw/Kconfig"
drivers/mtd/nand/Makefile +3 -0
index d1c3f93047..69c80ea252 100644
@@ -1,3 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
+nandcore-objs := core.o bbt.o
+obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
+
 obj-$(CONFIG_MTD_NAND) += raw/
drivers/mtd/nand/bbt.c new file +28 -0
new file mode 100644
index 0000000000..7e0ad3190c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2017 Free Electrons
+ *
+ * Authors:
+ *     Boris Brezillon <[email protected]>
+ *     Peter Pan <[email protected]>
+ */
+
+#define pr_fmt(fmt)    "nand-bbt: " fmt
+
+#include <linux/mtd/nand.h>
+#ifndef __UBOOT__
+#include <linux/slab.h>
+#endif
+
+/**
+ * nanddev_bbt_init() - Initialize the BBT (Bad Block Table)
+ * @nand: NAND device
+ *
+ * Initialize the in-memory BBT.
+ *
+ * Return: 0 in case of success, a negative error code otherwise.
+ */
+int nanddev_bbt_init(struct nand_device *nand)
+{
+       unsigned int bits_per_block = fls(NAND_BBT_BLOCK_NUM_STATUS);
+       unsigned int nblocks = nanddev_neraseblocks(nand);

drivers/mtd/nand/bbt.c line 38

Quoted 10 lines
drivers/mtd/nand/bbt.c new file +10 -0
+       unsigned int nwords = DIV_ROUND_UP(nblocks * bits_per_block,
+                                          BITS_PER_LONG);
+
+       nand->bbt.cache = kzalloc(nwords, GFP_KERNEL);
+       if (!nand->bbt.cache)
+               return -ENOMEM;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_init);

Can't we skip __UBOOT__ and EXPORT_SYMBOL_GPL ?

author maintainer
#14 lore raw

RFC PATCH 8/20 mtd: nand: Add core infrastructure to deal with NAND devices

Hi Jagan,

Quoted 78 lines · Jagan Teki
Quoted 77 lines · Miquel Raynal

From: Boris Brezillon <[email protected]>

Add an intermediate layer to abstract NAND device interface so that some logic can be shared between SPI NANDs, parallel/raw NANDs, OneNANDs, ...

---
 drivers/mtd/nand/Kconfig  |   3 +
 drivers/mtd/nand/Makefile |   3 +
 drivers/mtd/nand/bbt.c    | 132 +++++++++
 drivers/mtd/nand/core.c   | 243 +++++++++++++++
 include/linux/mtd/nand.h  | 731 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1112 insertions(+)
 create mode 100644 drivers/mtd/nand/bbt.c
 create mode 100644 drivers/mtd/nand/core.c
 create mode 100644 include/linux/mtd/nand.h
drivers/mtd/nand/Kconfig +3 -0
index 6d53734718..1c1a1f487e 100644
@@ -1 +1,4 @@
+config MTD_NAND_CORE
+       tristate
+
 source "drivers/mtd/nand/raw/Kconfig"
drivers/mtd/nand/Makefile +3 -0
index d1c3f93047..69c80ea252 100644
@@ -1,3 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
+nandcore-objs := core.o bbt.o
+obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
+
 obj-$(CONFIG_MTD_NAND) += raw/
drivers/mtd/nand/bbt.c new file +32 -0
new file mode 100644
index 0000000000..7e0ad3190c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2017 Free Electrons
+ *
+ * Authors:
+ *     Boris Brezillon <[email protected]>
+ *     Peter Pan <[email protected]>
+ */
+
+#define pr_fmt(fmt)    "nand-bbt: " fmt
+
+#include <linux/mtd/nand.h>
+#ifndef __UBOOT__
+#include <linux/slab.h>
+#endif
+
+/**
+ * nanddev_bbt_init() - Initialize the BBT (Bad Block Table)
+ * @nand: NAND device
+ *
+ * Initialize the in-memory BBT.
+ *
+ * Return: 0 in case of success, a negative error code otherwise.
+ */
+int nanddev_bbt_init(struct nand_device *nand)
+{
+       unsigned int bits_per_block = fls(NAND_BBT_BLOCK_NUM_STATUS);
+       unsigned int nblocks = nanddev_neraseblocks(nand);
+       unsigned int nwords = DIV_ROUND_UP(nblocks * bits_per_block,
+                                          BITS_PER_LONG);
+
+       nand->bbt.cache = kzalloc(nwords, GFP_KERNEL);
Quoted 8 lines

drivers/mtd/nand/bbt.c line 38

Quoted 6 lines
drivers/mtd/nand/bbt.c new file +6 -0
+       if (!nand->bbt.cache)
+               return -ENOMEM;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_init);  

Can't we skip __UBOOT__ and EXPORT_SYMBOL_GPL ?

Do you mean that you want me to delete all the #ifndef __UBOOT__/#endif sections?

They are present only to ease the patch backporting process from Linux. It was very useful during the development, I don't have a strong opinion on whether we should keep them or not, yet.

Thanks for reviewing!
Miquèl

#15 lore raw

RFC PATCH 8/20 mtd: nand: Add core infrastructure to deal with NAND devices

Quoted 92 lines · Miquel Raynal

Hi Jagan,

Quoted 78 lines · Jagan Teki
Quoted 77 lines · Miquel Raynal

From: Boris Brezillon <[email protected]>

Add an intermediate layer to abstract NAND device interface so that some logic can be shared between SPI NANDs, parallel/raw NANDs, OneNANDs, ...

---
 drivers/mtd/nand/Kconfig  |   3 +
 drivers/mtd/nand/Makefile |   3 +
 drivers/mtd/nand/bbt.c    | 132 +++++++++
 drivers/mtd/nand/core.c   | 243 +++++++++++++++
 include/linux/mtd/nand.h  | 731 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1112 insertions(+)
 create mode 100644 drivers/mtd/nand/bbt.c
 create mode 100644 drivers/mtd/nand/core.c
 create mode 100644 include/linux/mtd/nand.h
drivers/mtd/nand/Kconfig +3 -0
index 6d53734718..1c1a1f487e 100644
@@ -1 +1,4 @@
+config MTD_NAND_CORE
+       tristate
+
 source "drivers/mtd/nand/raw/Kconfig"
drivers/mtd/nand/Makefile +3 -0
index d1c3f93047..69c80ea252 100644
@@ -1,3 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
+nandcore-objs := core.o bbt.o
+obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
+
 obj-$(CONFIG_MTD_NAND) += raw/
drivers/mtd/nand/bbt.c new file +32 -0
new file mode 100644
index 0000000000..7e0ad3190c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2017 Free Electrons
+ *
+ * Authors:
+ *     Boris Brezillon <[email protected]>
+ *     Peter Pan <[email protected]>
+ */
+
+#define pr_fmt(fmt)    "nand-bbt: " fmt
+
+#include <linux/mtd/nand.h>
+#ifndef __UBOOT__
+#include <linux/slab.h>
+#endif
+
+/**
+ * nanddev_bbt_init() - Initialize the BBT (Bad Block Table)
+ * @nand: NAND device
+ *
+ * Initialize the in-memory BBT.
+ *
+ * Return: 0 in case of success, a negative error code otherwise.
+ */
+int nanddev_bbt_init(struct nand_device *nand)
+{
+       unsigned int bits_per_block = fls(NAND_BBT_BLOCK_NUM_STATUS);
+       unsigned int nblocks = nanddev_neraseblocks(nand);
+       unsigned int nwords = DIV_ROUND_UP(nblocks * bits_per_block,
+                                          BITS_PER_LONG);
+
+       nand->bbt.cache = kzalloc(nwords, GFP_KERNEL);
Quoted 8 lines

drivers/mtd/nand/bbt.c line 38

Quoted 6 lines
drivers/mtd/nand/bbt.c new file +6 -0
+       if (!nand->bbt.cache)
+               return -ENOMEM;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_init);  

Can't we skip __UBOOT__ and EXPORT_SYMBOL_GPL ?

Quoted 6 lines

Do you mean that you want me to delete all the #ifndef __UBOOT__/#endif sections?

They are present only to ease the patch backporting process from Linux. It was very useful during the development, I don't have a strong opinion on whether we should keep them or not, yet.

The general rule here is we do whatever makes life easiest on the people that are doing the periodic re-syncs. Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180627/06c706c8/attachment.sig>
author maintainer
#16 lore raw

RFC PATCH 9/20 mtd: nand: Pass mode information to nand_page_io_req

In reply to Miquel Raynal

From: Boris Brezillon <[email protected]>

The NAND sub-layers are likely to need the MTD_OPS_XXX mode information in order to decide if they should enable/disable ECC or how they should place the OOB bytes in the provided OOB buffer.

Add a field to nand_page_io_req to pass this information.

---
 include/linux/mtd/nand.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/mtd/nand.h +3 -0
index ada7af4a41..13e8dd1103 100644
@@ -86,6 +86,7 @@ struct nand_pos {
  * @ooboffs: the OOB offset within the page
  * @ooblen: the number of OOB bytes to read from/write to this page
  * @oobbuf: buffer to store OOB data in or get OOB data from
+ * @mode: one of the %MTD_OPS_XXX mode
  *
  * This object is used to pass per-page I/O requests to NAND sub-layers. This
  * way all useful information are already formatted in a useful way and
@@ -106,6 +107,7 @@ struct nand_page_io_req {
 		const void *out;
 		void *in;
 	} oobbuf;
+	int mode;
 };
 
 /**
@@ -599,6 +601,7 @@ static inline void nanddev_io_iter_init(struct nand_device *nand,
 {
 	struct mtd_info *mtd = nanddev_to_mtd(nand);
 
+	iter->req.mode = req->mode;
 	iter->req.dataoffs = nanddev_offs_to_pos(nand, offs, &iter->req.pos);
 	iter->req.ooboffs = req->ooboffs;
 	iter->oobbytes_per_page = mtd_oobavail(mtd, req);
Signature · 1 line
2.14.1
author maintainer
#17 lore raw

RFC PATCH 10/20 spi: Extend the core to ease integration of SPI memory controllers

In reply to Miquel Raynal

From: Boris Brezillon <[email protected]>

Some controllers are exposing high-level interfaces to access various kind of SPI memories. Unfortunately they do not fit in the current spi_controller model and usually have drivers placed in drivers/mtd/spi-nor which are only supporting SPI NORs and not SPI memories in general.

This is an attempt at defining a SPI memory interface which works for all kinds of SPI memories (NORs, NANDs, SRAMs).

---
 drivers/spi/Kconfig   |   7 +
 drivers/spi/Makefile  |   1 +
 drivers/spi/spi-mem.c | 500 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/spi-mem.h     | 258 ++++++++++++++++++++++++++
 include/spi.h         |  11 ++
 5 files changed, 777 insertions(+)
 create mode 100644 drivers/spi/spi-mem.c
 create mode 100644 include/spi-mem.h
drivers/spi/Kconfig +7 -0
index 235a8c7d73..0ee371b2d9 100644
@@ -15,6 +15,13 @@ config DM_SPI
 
 if DM_SPI
 
+config SPI_MEM
+	bool "SPI memory extension"
+	help
+	  Enable this option if you want to enable the SPI memory extension.
+	  This extension is meant to simplify interaction with SPI memories
+	  by providing an high-level interface to send memory-like commands.
+
 config ALTERA_SPI
 	bool "Altera SPI driver"
 	help
drivers/spi/Makefile +1 -0
index 4b6000fd9a..982529a0e6 100644
@@ -10,6 +10,7 @@ ifdef CONFIG_DM_SPI
 obj-y += spi-uclass.o
 obj-$(CONFIG_SANDBOX) += spi-emul-uclass.o
 obj-$(CONFIG_SOFT_SPI) += soft_spi.o
+obj-$(CONFIG_SPI_MEM) += spi-mem.o
 else
 obj-y += spi.o
 obj-$(CONFIG_SOFT_SPI) += soft_spi_legacy.o
drivers/spi/spi-mem.c new file +500 -0

500 lines not on this page · raw message

include/spi-mem.h new file +258 -0

258 lines not on this page · raw message

include/spi.h +11 -0
index f5bac8d002..12587ffeb0 100644
@@ -10,6 +10,8 @@
 #ifndef _SPI_H_
 #define _SPI_H_
 
+#include <common.h>
+
 /* SPI mode flags */
 #define SPI_CPHA	BIT(0)			/* clock phase */
 #define SPI_CPOL	BIT(1)			/* clock polarity */
@@ -403,6 +405,15 @@ struct dm_spi_ops {
 	int (*xfer)(struct udevice *dev, unsigned int bitlen, const void *dout,
 		    void *din, unsigned long flags);
 
+	/**
+	 * Optimized handlers for SPI memory-like operations.
+	 *
+	 * Optimized/dedicated operations for interactions with SPI memory. This
+	 * field is optional and should only be implemented if the controller
+	 * has native support for memory like operations.
+	 */
+	const struct spi_controller_mem_ops *mem_ops;
+
 	/**
 	 * Set transfer speed.
 	 * This sets a new speed to be applied for next spi_xfer().
Signature · 1 line
2.14.1
#18 lore raw

RFC PATCH 10/20 spi: Extend the core to ease integration of SPI memory controllers

Quoted 67 lines · Miquel Raynal

From: Boris Brezillon <[email protected]>

Some controllers are exposing high-level interfaces to access various kind of SPI memories. Unfortunately they do not fit in the current spi_controller model and usually have drivers placed in drivers/mtd/spi-nor which are only supporting SPI NORs and not SPI memories in general.

This is an attempt at defining a SPI memory interface which works for all kinds of SPI memories (NORs, NANDs, SRAMs).

---
 drivers/spi/Kconfig   |   7 +
 drivers/spi/Makefile  |   1 +
 drivers/spi/spi-mem.c | 500 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/spi-mem.h     | 258 ++++++++++++++++++++++++++
 include/spi.h         |  11 ++
 5 files changed, 777 insertions(+)
 create mode 100644 drivers/spi/spi-mem.c
 create mode 100644 include/spi-mem.h
drivers/spi/Kconfig +7 -0
index 235a8c7d73..0ee371b2d9 100644
@@ -15,6 +15,13 @@ config DM_SPI
 
 if DM_SPI
 
+config SPI_MEM
+       bool "SPI memory extension"
+       help
+         Enable this option if you want to enable the SPI memory extension.
+         This extension is meant to simplify interaction with SPI memories
+         by providing an high-level interface to send memory-like commands.
+
 config ALTERA_SPI
        bool "Altera SPI driver"
        help
drivers/spi/Makefile +1 -0
index 4b6000fd9a..982529a0e6 100644
@@ -10,6 +10,7 @@ ifdef CONFIG_DM_SPI
 obj-y += spi-uclass.o
 obj-$(CONFIG_SANDBOX) += spi-emul-uclass.o
 obj-$(CONFIG_SOFT_SPI) += soft_spi.o
+obj-$(CONFIG_SPI_MEM) += spi-mem.o
 else
 obj-y += spi.o
 obj-$(CONFIG_SOFT_SPI) += soft_spi_legacy.o
drivers/spi/spi-mem.c new file +8 -0
new file mode 100644
index 0000000000..1aabe56819
@@ -0,0 +1,500 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Exceet Electronics GmbH
+ * Copyright (C) 2018 Bootlin
+ *
+ * Author: Boris Brezillon <[email protected]>
+ */
+

drivers/spi/spi-mem.c line 18

Quoted 10 lines
drivers/spi/spi-mem.c new file +10 -0
+#ifndef __UBOOT__
+#include <linux/dmaengine.h>
+#include <linux/pm_runtime.h>
+#include "internals.h"
+#else
+#include <spi.h>
+#include <spi-mem.h>
+#endif
+
+#ifndef __UBOOT__

I would like remove Linux stuff atleast on this file becuase it's difficult for me to read or review the code and also driver/spi have fully u-boot dm stuff. I know it's easy for Linux sync but for this we can do manual sync what ever need. I'm on something what from Linux.

author maintainer
#19 lore raw

RFC PATCH 10/20 spi: Extend the core to ease integration of SPI memory controllers

Hi Jagan,

Jagan Teki <[email protected]> wrote on Fri, 6 Jul 2018 17:02:22 +0530:

Quoted 75 lines · Miquel Raynal
Quoted 74 lines

From: Boris Brezillon <[email protected]>

Some controllers are exposing high-level interfaces to access various kind of SPI memories. Unfortunately they do not fit in the current spi_controller model and usually have drivers placed in drivers/mtd/spi-nor which are only supporting SPI NORs and not SPI memories in general.

This is an attempt at defining a SPI memory interface which works for all kinds of SPI memories (NORs, NANDs, SRAMs).

---
 drivers/spi/Kconfig   |   7 +
 drivers/spi/Makefile  |   1 +
 drivers/spi/spi-mem.c | 500 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/spi-mem.h     | 258 ++++++++++++++++++++++++++
 include/spi.h         |  11 ++
 5 files changed, 777 insertions(+)
 create mode 100644 drivers/spi/spi-mem.c
 create mode 100644 include/spi-mem.h
drivers/spi/Kconfig +7 -0
index 235a8c7d73..0ee371b2d9 100644
@@ -15,6 +15,13 @@ config DM_SPI
 
 if DM_SPI
 
+config SPI_MEM
+       bool "SPI memory extension"
+       help
+         Enable this option if you want to enable the SPI memory extension.
+         This extension is meant to simplify interaction with SPI memories
+         by providing an high-level interface to send memory-like commands.
+
 config ALTERA_SPI
        bool "Altera SPI driver"
        help
drivers/spi/Makefile +1 -0
index 4b6000fd9a..982529a0e6 100644
@@ -10,6 +10,7 @@ ifdef CONFIG_DM_SPI
 obj-y += spi-uclass.o
 obj-$(CONFIG_SANDBOX) += spi-emul-uclass.o
 obj-$(CONFIG_SOFT_SPI) += soft_spi.o
+obj-$(CONFIG_SPI_MEM) += spi-mem.o
 else
 obj-y += spi.o
 obj-$(CONFIG_SOFT_SPI) += soft_spi_legacy.o
drivers/spi/spi-mem.c new file +15 -0
new file mode 100644
index 0000000000..1aabe56819
@@ -0,0 +1,500 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Exceet Electronics GmbH
+ * Copyright (C) 2018 Bootlin
+ *
+ * Author: Boris Brezillon <[email protected]>
+ */
+
+#ifndef __UBOOT__
+#include <linux/dmaengine.h>
+#include <linux/pm_runtime.h>
+#include "internals.h"
+#else
+#include <spi.h>
+#include <spi-mem.h>
Quoted 8 lines

drivers/spi/spi-mem.c line 18

Quoted 3 lines
drivers/spi/spi-mem.c new file +3 -0
+#endif
+
+#ifndef __UBOOT__  

I would like remove Linux stuff atleast on this file becuase it's difficult for me to read or review the code and also driver/spi have fully u-boot dm stuff. I know it's easy for Linux sync but for this we can do manual sync what ever need. I'm on something what from Linux.

I'm not sure this is a wise idea.

And I don't understand how "driver/spi have fully u-boot dm stuff" is related in any manner to this request.

But okay, if you commit to backport the changes/fixes on spi-mem from Linux yourself, let's remove them.

Thanks,
Miquèl

#20 lore raw

RFC PATCH 10/20 spi: Extend the core to ease integration of SPI memory controllers

Quoted 89 lines · Miquel Raynal

Hi Jagan,

Jagan Teki <[email protected]> wrote on Fri, 6 Jul 2018 17:02:22 +0530:

Quoted 75 lines · Miquel Raynal
Quoted 74 lines

From: Boris Brezillon <[email protected]>

Some controllers are exposing high-level interfaces to access various kind of SPI memories. Unfortunately they do not fit in the current spi_controller model and usually have drivers placed in drivers/mtd/spi-nor which are only supporting SPI NORs and not SPI memories in general.

This is an attempt at defining a SPI memory interface which works for all kinds of SPI memories (NORs, NANDs, SRAMs).

---
 drivers/spi/Kconfig   |   7 +
 drivers/spi/Makefile  |   1 +
 drivers/spi/spi-mem.c | 500 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/spi-mem.h     | 258 ++++++++++++++++++++++++++
 include/spi.h         |  11 ++
 5 files changed, 777 insertions(+)
 create mode 100644 drivers/spi/spi-mem.c
 create mode 100644 include/spi-mem.h
drivers/spi/Kconfig +7 -0
index 235a8c7d73..0ee371b2d9 100644
@@ -15,6 +15,13 @@ config DM_SPI
 
 if DM_SPI
 
+config SPI_MEM
+       bool "SPI memory extension"
+       help
+         Enable this option if you want to enable the SPI memory extension.
+         This extension is meant to simplify interaction with SPI memories
+         by providing an high-level interface to send memory-like commands.
+
 config ALTERA_SPI
        bool "Altera SPI driver"
        help
drivers/spi/Makefile +1 -0
index 4b6000fd9a..982529a0e6 100644
@@ -10,6 +10,7 @@ ifdef CONFIG_DM_SPI
 obj-y += spi-uclass.o
 obj-$(CONFIG_SANDBOX) += spi-emul-uclass.o
 obj-$(CONFIG_SOFT_SPI) += soft_spi.o
+obj-$(CONFIG_SPI_MEM) += spi-mem.o
 else
 obj-y += spi.o
 obj-$(CONFIG_SOFT_SPI) += soft_spi_legacy.o
drivers/spi/spi-mem.c new file +15 -0
new file mode 100644
index 0000000000..1aabe56819
@@ -0,0 +1,500 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Exceet Electronics GmbH
+ * Copyright (C) 2018 Bootlin
+ *
+ * Author: Boris Brezillon <[email protected]>
+ */
+
+#ifndef __UBOOT__
+#include <linux/dmaengine.h>
+#include <linux/pm_runtime.h>
+#include "internals.h"
+#else
+#include <spi.h>
+#include <spi-mem.h>
Quoted 8 lines

drivers/spi/spi-mem.c line 18

Quoted 3 lines
drivers/spi/spi-mem.c new file +3 -0
+#endif
+
+#ifndef __UBOOT__

I would like remove Linux stuff atleast on this file becuase it's difficult for me to read or review the code and also driver/spi have fully u-boot dm stuff. I know it's easy for Linux sync but for this we can do manual sync what ever need. I'm on something what from Linux.

Quoted 4 lines

I'm not sure this is a wise idea.

And I don't understand how "driver/spi have fully u-boot dm stuff" is related in any manner to this request.

The code in driver/spi is more or less u-boot code it doesn't have Linux sync. ie reason I want to maintain the similar integrity here, but on the other-side spi-mem depend more on Linux like MTD. OK let's move as-it-is like what you added, may be we can simulate if require in future need.

author maintainer
#21 lore raw

RFC PATCH 10/20 spi: Extend the core to ease integration of SPI memory controllers

Hi Jagan,

Jagan Teki <[email protected]> wrote on Wed, 11 Jul 2018 20:07:19 +0530:

Quoted 93 lines
Quoted 91 lines · Miquel Raynal

Hi Jagan,

Jagan Teki <[email protected]> wrote on Fri, 6 Jul 2018 17:02:22 +0530:

Quoted 75 lines · Miquel Raynal
Quoted 74 lines

From: Boris Brezillon <[email protected]>

Some controllers are exposing high-level interfaces to access various kind of SPI memories. Unfortunately they do not fit in the current spi_controller model and usually have drivers placed in drivers/mtd/spi-nor which are only supporting SPI NORs and not SPI memories in general.

This is an attempt at defining a SPI memory interface which works for all kinds of SPI memories (NORs, NANDs, SRAMs).

---
 drivers/spi/Kconfig   |   7 +
 drivers/spi/Makefile  |   1 +
 drivers/spi/spi-mem.c | 500 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/spi-mem.h     | 258 ++++++++++++++++++++++++++
 include/spi.h         |  11 ++
 5 files changed, 777 insertions(+)
 create mode 100644 drivers/spi/spi-mem.c
 create mode 100644 include/spi-mem.h
drivers/spi/Kconfig +7 -0
index 235a8c7d73..0ee371b2d9 100644
@@ -15,6 +15,13 @@ config DM_SPI
 
 if DM_SPI
 
+config SPI_MEM
+       bool "SPI memory extension"
+       help
+         Enable this option if you want to enable the SPI memory extension.
+         This extension is meant to simplify interaction with SPI memories
+         by providing an high-level interface to send memory-like commands.
+
 config ALTERA_SPI
        bool "Altera SPI driver"
        help
drivers/spi/Makefile +1 -0
index 4b6000fd9a..982529a0e6 100644
@@ -10,6 +10,7 @@ ifdef CONFIG_DM_SPI
 obj-y += spi-uclass.o
 obj-$(CONFIG_SANDBOX) += spi-emul-uclass.o
 obj-$(CONFIG_SOFT_SPI) += soft_spi.o
+obj-$(CONFIG_SPI_MEM) += spi-mem.o
 else
 obj-y += spi.o
 obj-$(CONFIG_SOFT_SPI) += soft_spi_legacy.o
drivers/spi/spi-mem.c new file +15 -0
new file mode 100644
index 0000000000..1aabe56819
@@ -0,0 +1,500 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Exceet Electronics GmbH
+ * Copyright (C) 2018 Bootlin
+ *
+ * Author: Boris Brezillon <[email protected]>
+ */
+
+#ifndef __UBOOT__
+#include <linux/dmaengine.h>
+#include <linux/pm_runtime.h>
+#include "internals.h"
+#else
+#include <spi.h>
+#include <spi-mem.h>
Quoted 8 lines

drivers/spi/spi-mem.c line 18

Quoted 3 lines
drivers/spi/spi-mem.c new file +3 -0
+#endif
+
+#ifndef __UBOOT__  

I would like remove Linux stuff atleast on this file becuase it's difficult for me to read or review the code and also driver/spi have fully u-boot dm stuff. I know it's easy for Linux sync but for this we can do manual sync what ever need. I'm on something what from Linux.

I'm not sure this is a wise idea.

Quoted 8 lines
Quoted 2 lines

And I don't understand how "driver/spi have fully u-boot dm stuff" is related in any manner to this request.

The code in driver/spi is more or less u-boot code it doesn't have Linux sync. ie reason I want to maintain the similar integrity here, but on the other-side spi-mem depend more on Linux like MTD. OK let's move as-it-is like what you added, may be we can simulate if require in future need.

I understand better your POV, OK then, let met re-add these portions.

Thanks,
Miquèl

author maintainer
#22 lore raw

RFC PATCH 11/20 mtd: nand: Add core infrastructure to support SPI NANDs

In reply to Miquel Raynal

From: Peter Pan <[email protected]>

Add a SPI NAND framework based on the generic NAND framework and the spi-mem infrastructure.

In its current state, this framework supports the following features:

- single/dual/quad IO modes
- on-die ECC

---
 drivers/mtd/nand/Kconfig      |    2 +
 drivers/mtd/nand/Makefile     |    1 +
 drivers/mtd/nand/spi/Kconfig  |    7 +
 drivers/mtd/nand/spi/Makefile |    4 +
 drivers/mtd/nand/spi/core.c   | 1233 +++++++++++++++++++++++++++++++++++++++++
 include/linux/mtd/spinand.h   |  427 ++++++++++++++
 6 files changed, 1674 insertions(+)
 create mode 100644 drivers/mtd/nand/spi/Kconfig
 create mode 100644 drivers/mtd/nand/spi/Makefile
 create mode 100644 drivers/mtd/nand/spi/core.c
 create mode 100644 include/linux/mtd/spinand.h
drivers/mtd/nand/Kconfig +2 -0
index 1c1a1f487e..78ae04bdcb 100644
@@ -2,3 +2,5 @@ config MTD_NAND_CORE
 	tristate
 
 source "drivers/mtd/nand/raw/Kconfig"
+
+source "drivers/mtd/nand/spi/Kconfig"
drivers/mtd/nand/Makefile +1 -0
index 69c80ea252..cbac19b38a 100644
@@ -4,3 +4,4 @@ nandcore-objs := core.o bbt.o
 obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
 
 obj-$(CONFIG_MTD_NAND) += raw/
+obj-$(CONFIG_MTD_SPI_NAND) += spi/
drivers/mtd/nand/spi/Kconfig new file +7 -0
new file mode 100644
index 0000000000..2197cb531f
@@ -0,0 +1,7 @@
+menuconfig MTD_SPI_NAND
+	bool "SPI NAND device Support"
+	depends on MTD && DM_SPI
+	select MTD_NAND_CORE
+	select SPI_MEM
+	help
+	  This is the framework for the SPI NAND device drivers.
drivers/mtd/nand/spi/Makefile new file +4 -0
new file mode 100644
index 0000000000..f0c6e69d2e
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+
+spinand-objs := core.o
+obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
drivers/mtd/nand/spi/core.c new file +1233 -0

1,233 lines not on this page · raw message

include/linux/mtd/spinand.h new file +427 -0

427 lines not on this page · raw message

Signature · 1 line
2.14.1
author maintainer
#23 lore raw

RFC PATCH 12/20 mtd: spinand: Add initial support for Micron MT29F2G01ABAGD

In reply to Miquel Raynal

From: Peter Pan <[email protected]>

Add a basic driver for Micron SPI NANDs. Only one device is supported right now, but the driver will be extended to support more devices afterwards.

---
 drivers/mtd/nand/spi/Makefile |   2 +-
 drivers/mtd/nand/spi/core.c   |  17 ++++++
 drivers/mtd/nand/spi/micron.c | 135 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/mtd/spinand.h   |   3 +
 4 files changed, 156 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mtd/nand/spi/micron.c
drivers/mtd/nand/spi/Makefile +1 -1
index f0c6e69d2e..4eb745abd4 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
-spinand-objs := core.o
+spinand-objs := core.o micron.o
 obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
drivers/mtd/nand/spi/core.c +17 -0
index d2e912aeb5..8b01aeb7e7 100644
@@ -829,8 +829,25 @@ static const struct nand_ops spinand_ops = {
 	.isbad = spinand_isbad,
 };
 
+static const struct spinand_manufacturer *spinand_manufacturers[] = {
+	&micron_spinand_manufacturer,
+};
+
 static int spinand_manufacturer_detect(struct spinand_device *spinand)
 {
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < ARRAY_SIZE(spinand_manufacturers); i++) {
+		ret = spinand_manufacturers[i]->ops->detect(spinand);
+		if (ret > 0) {
+			spinand->manufacturer = spinand_manufacturers[i];
+			return 0;
+		} else if (ret < 0) {
+			return ret;
+		}
+	}
+
 	return -ENOTSUPP;
 }
 
drivers/mtd/nand/spi/micron.c new file +135 -0

135 lines not on this page · raw message

include/linux/mtd/spinand.h +3 -0
index ad59fc01ef..5302d38de8 100644
@@ -200,6 +200,9 @@ struct spinand_manufacturer {
 	const struct spinand_manufacturer_ops *ops;
 };
 
+/* SPI NAND manufacturers */
+extern const struct spinand_manufacturer micron_spinand_manufacturer;
+
 /**
  * struct spinand_op_variants - SPI NAND operation variants
  * @ops: the list of variants for a given operation
Signature · 1 line
2.14.1
author maintainer
#24 lore raw

RFC PATCH 13/20 mtd: spinand: Add initial support for Winbond W25M02GV

In reply to Miquel Raynal

From: Frieder Schrempf <[email protected]>

Add support for the W25M02GV chip.

---
 drivers/mtd/nand/spi/Makefile  |   2 +-
 drivers/mtd/nand/spi/core.c    |   1 +
 drivers/mtd/nand/spi/winbond.c | 143 +++++++++++++++++++++++++++++++++++++++++
 include/linux/mtd/spinand.h    |   1 +
 4 files changed, 146 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mtd/nand/spi/winbond.c
drivers/mtd/nand/spi/Makefile +1 -1
index 4eb745abd4..11ba5de68b 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
-spinand-objs := core.o micron.o
+spinand-objs := core.o micron.o winbond.o
 obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
drivers/mtd/nand/spi/core.c +1 -0
index 8b01aeb7e7..f151f671fa 100644
@@ -831,6 +831,7 @@ static const struct nand_ops spinand_ops = {
 
 static const struct spinand_manufacturer *spinand_manufacturers[] = {
 	&micron_spinand_manufacturer,
+	&winbond_spinand_manufacturer,
 };
 
 static int spinand_manufacturer_detect(struct spinand_device *spinand)
drivers/mtd/nand/spi/winbond.c new file +143 -0

143 lines not on this page · raw message

include/linux/mtd/spinand.h +1 -0
index 5302d38de8..d40a7c8f4e 100644
@@ -202,6 +202,7 @@ struct spinand_manufacturer {
 
 /* SPI NAND manufacturers */
 extern const struct spinand_manufacturer micron_spinand_manufacturer;
+extern const struct spinand_manufacturer winbond_spinand_manufacturer;
 
 /**
  * struct spinand_op_variants - SPI NAND operation variants
Signature · 1 line
2.14.1
author maintainer
#25 lore raw

RFC PATCH 14/20 mtd: spinand: Add initial support for the MX35LF1GE4AB chip

In reply to Miquel Raynal

From: Boris Brezillon <[email protected]>

Add minimal support for the MX35LF1GE4AB SPI NAND chip.

---
 drivers/mtd/nand/spi/Makefile   |   2 +-
 drivers/mtd/nand/spi/core.c     |   1 +
 drivers/mtd/nand/spi/macronix.c | 138 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mtd/spinand.h     |   1 +
 4 files changed, 141 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mtd/nand/spi/macronix.c
drivers/mtd/nand/spi/Makefile +1 -1
index 11ba5de68b..a66edd9199 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
-spinand-objs := core.o micron.o winbond.o
+spinand-objs := core.o macronix.o micron.o winbond.o
 obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
drivers/mtd/nand/spi/core.c +1 -0
index f151f671fa..6f383852d9 100644
@@ -830,6 +830,7 @@ static const struct nand_ops spinand_ops = {
 };
 
 static const struct spinand_manufacturer *spinand_manufacturers[] = {
+	&macronix_spinand_manufacturer,
 	&micron_spinand_manufacturer,
 	&winbond_spinand_manufacturer,
 };
drivers/mtd/nand/spi/macronix.c new file +138 -0

138 lines not on this page · raw message

include/linux/mtd/spinand.h +1 -0
index d40a7c8f4e..8c9c756179 100644
@@ -201,6 +201,7 @@ struct spinand_manufacturer {
 };
 
 /* SPI NAND manufacturers */
+extern const struct spinand_manufacturer macronix_spinand_manufacturer;
 extern const struct spinand_manufacturer micron_spinand_manufacturer;
 extern const struct spinand_manufacturer winbond_spinand_manufacturer;
 
Signature · 1 line
2.14.1
author maintainer
#26 lore raw

RFC PATCH 15/20 mtd: spinand: Add initial support for the MX35LF2GE4AB chip

In reply to Miquel Raynal

Add support for the MX35LF2GE4AB chip, which is similar to its cousin MX35LF1GE4AB, with two planes instead of one.

---
 drivers/mtd/nand/spi/macronix.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/mtd/nand/spi/macronix.c +14 -6
index dd351dcb6c..d761b99d26 100644
@@ -27,13 +27,13 @@ static SPINAND_OP_VARIANTS(update_cache_variants,
 		SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
 		SPINAND_PROG_LOAD(false, 0, NULL, 0));
 
-static int mx35lf1ge4ab_ooblayout_ecc(struct mtd_info *mtd, int section,
+static int mx35lfxge4ab_ooblayout_ecc(struct mtd_info *mtd, int section,
 				      struct mtd_oob_region *region)
 {
 	return -ERANGE;
 }
 
-static int mx35lf1ge4ab_ooblayout_free(struct mtd_info *mtd, int section,
+static int mx35lfxge4ab_ooblayout_free(struct mtd_info *mtd, int section,
 				       struct mtd_oob_region *region)
 {
 	if (section)
@@ -45,9 +45,9 @@ static int mx35lf1ge4ab_ooblayout_free(struct mtd_info *mtd, int section,
 	return 0;
 }
 
-static const struct mtd_ooblayout_ops mx35lf1ge4ab_ooblayout = {
-	.ecc = mx35lf1ge4ab_ooblayout_ecc,
-	.free = mx35lf1ge4ab_ooblayout_free,
+static const struct mtd_ooblayout_ops mx35lfxge4ab_ooblayout = {
+	.ecc = mx35lfxge4ab_ooblayout_ecc,
+	.free = mx35lfxge4ab_ooblayout_free,
 };
 
 static int mx35lf1ge4ab_get_eccsr(struct spinand_device *spinand, u8 *eccsr)
@@ -102,8 +102,16 @@ static const struct spinand_info macronix_spinand_table[] = {
 					      &write_cache_variants,
 					      &update_cache_variants),
 		     SPINAND_HAS_QE_BIT,
-		     SPINAND_ECCINFO(&mx35lf1ge4ab_ooblayout,
+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
 				     mx35lf1ge4ab_ecc_get_status)),
+	SPINAND_INFO("MX35LF2GE4AB", 0x22,
+		     NAND_MEMORG(1, 2048, 64, 64, 1024, 2, 1, 1),
+		     NAND_ECCREQ(4, 512),
+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+					      &write_cache_variants,
+					      &update_cache_variants),
+		     SPINAND_HAS_QE_BIT,
+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
 };
 
 static int macronix_spinand_detect(struct spinand_device *spinand)
Signature · 1 line
2.14.1
#27 lore raw

RFC PATCH 15/20 mtd: spinand: Add initial support for the MX35LF2GE4AB chip

Quoted 42 lines · On Wed, 6 Jun 2018 17:30:35 +0200 Miquel Raynal <[email protected]>…

Add support for the MX35LF2GE4AB chip, which is similar to its cousin MX35LF1GE4AB, with two planes instead of one.

---
 drivers/mtd/nand/spi/macronix.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/mtd/nand/spi/macronix.c +5 -5
index dd351dcb6c..d761b99d26 100644
@@ -27,13 +27,13 @@ static SPINAND_OP_VARIANTS(update_cache_variants,
 		SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
 		SPINAND_PROG_LOAD(false, 0, NULL, 0));
 
-static int mx35lf1ge4ab_ooblayout_ecc(struct mtd_info *mtd, int section,
+static int mx35lfxge4ab_ooblayout_ecc(struct mtd_info *mtd, int section,
 				      struct mtd_oob_region *region)
 {
 	return -ERANGE;
 }
 
-static int mx35lf1ge4ab_ooblayout_free(struct mtd_info *mtd, int section,
+static int mx35lfxge4ab_ooblayout_free(struct mtd_info *mtd, int section,
 				       struct mtd_oob_region *region)
 {
 	if (section)
@@ -45,9 +45,9 @@ static int mx35lf1ge4ab_ooblayout_free(struct mtd_info *mtd, int section,
 	return 0;
 }
 
-static const struct mtd_ooblayout_ops mx35lf1ge4ab_ooblayout = {
-	.ecc = mx35lf1ge4ab_ooblayout_ecc,
-	.free = mx35lf1ge4ab_ooblayout_free,
+static const struct mtd_ooblayout_ops mx35lfxge4ab_ooblayout = {
+	.ecc = mx35lfxge4ab_ooblayout_ecc,
+	.free = mx35lfxge4ab_ooblayout_free,
 };
 
 static int mx35lf1ge4ab_get_eccsr(struct spinand_device *spinand, u8 *eccsr)

drivers/mtd/nand/spi/macronix.c static const struct spinand_info macronix_spinand_table[] = { · line 108

Quoted 8 lines
drivers/mtd/nand/spi/macronix.c +3 -1
@@ -102,8 +102,16 @@ static const struct spinand_info macronix_spinand_table[] = {
 					      &write_cache_variants,
 					      &update_cache_variants),
 		     SPINAND_HAS_QE_BIT,
-		     SPINAND_ECCINFO(&mx35lf1ge4ab_ooblayout,
+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
 				     mx35lf1ge4ab_ecc_get_status)),
+	SPINAND_INFO("MX35LF2GE4AB", 0x22,
+		     NAND_MEMORG(1, 2048, 64, 64, 1024, 2, 1, 1),

I think it should be 2048 here ^.

Quoted 9 lines
drivers/mtd/nand/spi/macronix.c +6 -0
+		     NAND_ECCREQ(4, 512),
+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+					      &write_cache_variants,
+					      &update_cache_variants),
+		     SPINAND_HAS_QE_BIT,
+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
 };
 
 static int macronix_spinand_detect(struct spinand_device *spinand)
author maintainer
#28 lore raw

RFC PATCH 15/20 mtd: spinand: Add initial support for the MX35LF2GE4AB chip

Hi Boris,

Quoted 43 lines · Boris Brezillon
Quoted 40 lines · On Wed, 6 Jun 2018 17:30:35 +0200 Miquel Raynal <[email protected]>…

Add support for the MX35LF2GE4AB chip, which is similar to its cousin MX35LF1GE4AB, with two planes instead of one.

---
 drivers/mtd/nand/spi/macronix.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/mtd/nand/spi/macronix.c +5 -5
index dd351dcb6c..d761b99d26 100644
@@ -27,13 +27,13 @@ static SPINAND_OP_VARIANTS(update_cache_variants,
 		SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
 		SPINAND_PROG_LOAD(false, 0, NULL, 0));
 
-static int mx35lf1ge4ab_ooblayout_ecc(struct mtd_info *mtd, int section,
+static int mx35lfxge4ab_ooblayout_ecc(struct mtd_info *mtd, int section,
 				      struct mtd_oob_region *region)
 {
 	return -ERANGE;
 }
 
-static int mx35lf1ge4ab_ooblayout_free(struct mtd_info *mtd, int section,
+static int mx35lfxge4ab_ooblayout_free(struct mtd_info *mtd, int section,
 				       struct mtd_oob_region *region)
 {
 	if (section)
@@ -45,9 +45,9 @@ static int mx35lf1ge4ab_ooblayout_free(struct mtd_info *mtd, int section,
 	return 0;
 }
 
-static const struct mtd_ooblayout_ops mx35lf1ge4ab_ooblayout = {
-	.ecc = mx35lf1ge4ab_ooblayout_ecc,
-	.free = mx35lf1ge4ab_ooblayout_free,
+static const struct mtd_ooblayout_ops mx35lfxge4ab_ooblayout = {
+	.ecc = mx35lfxge4ab_ooblayout_ecc,
+	.free = mx35lfxge4ab_ooblayout_free,
 };
 
Quoted 12 lines

drivers/mtd/nand/spi/macronix.c static const struct spinand_info macronix_spinand_table[] = { · line 108

Quoted 10 lines
drivers/mtd/nand/spi/macronix.c +3 -1
 static int mx35lf1ge4ab_get_eccsr(struct spinand_device *spinand, u8 *eccsr)
@@ -102,8 +102,16 @@ static const struct spinand_info macronix_spinand_table[] = {
 					      &write_cache_variants,
 					      &update_cache_variants),
 		     SPINAND_HAS_QE_BIT,
-		     SPINAND_ECCINFO(&mx35lf1ge4ab_ooblayout,
+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
 				     mx35lf1ge4ab_ecc_get_status)),
+	SPINAND_INFO("MX35LF2GE4AB", 0x22,
+		     NAND_MEMORG(1, 2048, 64, 64, 1024, 2, 1, 1),  

I think it should be 2048 here ^.

I just checked, I think you are right. I'll edit this for the next version.

Thanks,
Miquèl

author maintainer
#29 lore raw

RFC PATCH 16/20 mtd: uclass: add probe function

In reply to Miquel Raynal

The user might want to trigger the probe of any MTD device, export these functions so they can be called from a command source file.

---
 drivers/mtd/mtd-uclass.c | 9 +++++++++
 include/linux/mtd/mtd.h  | 3 +++
 2 files changed, 12 insertions(+)
drivers/mtd/mtd-uclass.c +9 -0
index 7b7c48ec5a..1b6533829c 100644
@@ -6,6 +6,7 @@
 
 #include <common.h>
 #include <dm.h>
+#include <dm/device-internal.h>
 #include <errno.h>
 #include <mtd.h>
 
@@ -14,6 +15,14 @@
  * The uclass private is pointed to mtd_info.
  */
 
+int mtd_probe(struct udevice *dev)
+{
+	if (device_active(dev))
+		return 0;
+
+	return device_probe(dev);
+}
+
 UCLASS_DRIVER(mtd) = {
 	.id		= UCLASS_MTD,
 	.name		= "mtd",
include/linux/mtd/mtd.h +3 -0
index b5f9151a70..f89a32ae36 100644
@@ -548,5 +548,8 @@ int mtd_arg_off_size(int argc, char *const argv[], int *idx, loff_t *off,
 void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset,
 			  const uint64_t length, uint64_t *len_incl_bad,
 			  int *truncated);
+
+int mtd_probe(struct udevice *dev);
+
 #endif
 #endif /* __MTD_MTD_H__ */
Signature · 1 line
2.14.1
author maintainer
#30 lore raw

RFC PATCH 17/20 cmd: mtd: add 'mtd' command

In reply to Miquel Raynal

There should not be a 'nand' command, a 'sf' command and certainly not another 'spi-nand'. Write a 'mtd' command instead to manage all MTD devices at once. This should be the preferred way to access any MTD device.

---
 cmd/Kconfig          |   5 +
 cmd/Makefile         |   1 +
 cmd/mtd.c            | 280 +++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/Makefile |   2 +-
 4 files changed, 287 insertions(+), 1 deletion(-)
 create mode 100644 cmd/mtd.c
cmd/Kconfig +5 -0
index 136836d146..6e9b629e1c 100644
@@ -797,6 +797,11 @@ config CMD_MMC
 	help
 	  MMC memory mapped support.
 
+config CMD_MTD
+	bool "mtd"
+	help
+	  MTD commands support.
+
 config CMD_NAND
 	bool "nand"
 	default y if NAND_SUNXI
cmd/Makefile +1 -0
index 9a358e4801..e42db12e1d 100644
@@ -88,6 +88,7 @@ obj-$(CONFIG_CMD_MISC) += misc.o
 obj-$(CONFIG_CMD_MMC) += mmc.o
 obj-$(CONFIG_CMD_MMC_SPI) += mmc_spi.o
 obj-$(CONFIG_MP) += mp.o
+obj-$(CONFIG_CMD_MTD) += mtd.o
 obj-$(CONFIG_CMD_MTDPARTS) += mtdparts.o
 obj-$(CONFIG_CMD_NAND) += nand.o
 obj-$(CONFIG_CMD_NET) += net.o
cmd/mtd.c new file +280 -0

280 lines not on this page · raw message

drivers/mtd/Makefile +1 -1
index eb0e7264ab..95b5f25fef 100644
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
-ifneq (,$(findstring y,$(CONFIG_MTD_DEVICE)$(CONFIG_CMD_NAND)$(CONFIG_CMD_ONENAND)$(CONFIG_CMD_SF)))
+ifneq (,$(findstring y,$(CONFIG_MTD_DEVICE)$(CONFIG_CMD_NAND)$(CONFIG_CMD_ONENAND)$(CONFIG_CMD_SF)$(CONFIG_CMD_MTD)))
 obj-y += mtdcore.o mtd_uboot.o
 endif
 obj-$(CONFIG_MTD) += mtd-uclass.o
Signature · 1 line
2.14.1
#31 lore raw

RFC PATCH 17/20 cmd: mtd: add 'mtd' command

Hi Miquel,

Quoted 4 lines · On Wed, 6 Jun 2018 17:30:37 +0200 Miquel Raynal <[email protected]>…

There should not be a 'nand' command, a 'sf' command and certainly not another 'spi-nand'. Write a 'mtd' command instead to manage all MTD devices at once. This should be the preferred way to access any MTD device.

Just a few comments below, but overall, I'm really happy with this new set of commands and the fact that we'll soon be able to replace custom MTD accessors (nand, onenand, sf, cp.b+erase, ...) by these ones.

Quoted 95 lines
---
 cmd/Kconfig          |   5 +
 cmd/Makefile         |   1 +
 cmd/mtd.c            | 280 +++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/Makefile |   2 +-
 4 files changed, 287 insertions(+), 1 deletion(-)
 create mode 100644 cmd/mtd.c
cmd/Kconfig +5 -0
index 136836d146..6e9b629e1c 100644
@@ -797,6 +797,11 @@ config CMD_MMC
 	help
 	  MMC memory mapped support.
 
+config CMD_MTD
+	bool "mtd"
+	help
+	  MTD commands support.
+
 config CMD_NAND
 	bool "nand"
 	default y if NAND_SUNXI
cmd/Makefile +1 -0
index 9a358e4801..e42db12e1d 100644
@@ -88,6 +88,7 @@ obj-$(CONFIG_CMD_MISC) += misc.o
 obj-$(CONFIG_CMD_MMC) += mmc.o
 obj-$(CONFIG_CMD_MMC_SPI) += mmc_spi.o
 obj-$(CONFIG_MP) += mp.o
+obj-$(CONFIG_CMD_MTD) += mtd.o
 obj-$(CONFIG_CMD_MTDPARTS) += mtdparts.o
 obj-$(CONFIG_CMD_NAND) += nand.o
 obj-$(CONFIG_CMD_NET) += net.o
cmd/mtd.c new file +51 -0
new file mode 100644
index 0000000000..fe48378bd0
@@ -0,0 +1,280 @@
+// SPDX-License-Identifier:  GPL-2.0+
+/*
+ * mtd.c
+ *
+ * Generic command to handle basic operations on any memory device.
+ *
+ * Copyright: Bootlin, 2018
+ * Author: Miquèl Raynal <[email protected]>
+ */
+
+#include <common.h>
+#include <linux/mtd/mtd.h>
+#include <command.h>
+#include <console.h>
+#include <malloc.h>
+#include <mtd.h>
+#include <mapmem.h>
+#include <dm/device.h>
+#include <dm/uclass-internal.h>
+
+static void mtd_dump_buf(u8 *buf, uint len)
+{
+	int i, j;
+
+	for (i = 0; i < len; ) {
+		printf("0x%08x:\t", i);
+		for (j = 0; j < 8; j++)
+			printf("%02x ", buf[i + j]);
+		printf(" ");
+		i += 8;
+		for (j = 0; j < 8; j++)
+			printf("%02x ", buf[i + j]);
+		printf("\n");
+		i += 8;
+	}
+}
+
+static void mtd_show_device(struct mtd_info *mtd)
+{
+	printf("* %s", mtd->name);
+	if (mtd->dev)
+		printf(" [device: %s] [parent: %s] [driver: %s]",
+		       mtd->dev->name, mtd->dev->parent->name,
+		       mtd->dev->driver->name);
+
+	printf("\n");
+}
+
+static int do_mtd_list(void)
+{
+	struct mtd_info *mtd;

cmd/mtd.c line 61

Quoted 10 lines
cmd/mtd.c new file +10 -0
+	struct udevice *dev;
+	int dm_idx = 0, idx = 0;
+
+	/* Ensure all devices compliants with U-Boot driver model are probed */
+	while (!uclass_find_device(UCLASS_MTD, dm_idx, &dev) && dev) {
+		mtd_probe(dev);
+		dm_idx++;
+	}
+
+	printf("MTD devices list (%d DM compliant):\n", dm_idx);

Do we really want to say how many of them are exported by DM compliant drivers? I mean, the user doesn't care about that. If you want to force people to convert their drivers, we should probably complain at MTD device registration time when the mtd_info struct is not backed by an udevice.

Quoted 4 lines
cmd/mtd.c new file +4 -0
+
+	mtd_for_each_device(mtd) {
+		mtd_show_device(mtd);
+		idx++;

cmd/mtd.c line 75

Quoted 10 lines
cmd/mtd.c new file +10 -0
+	}
+
+	if (!idx)
+		printf("No MTD device found\n");
+
+	return 0;
+}
+
+static int do_mtd_read_write(struct mtd_info *mtd, bool read, uint *waddr,
+			     bool raw, bool woob, u64 from, u64 len)

s/do_mtd_read_write/do_mtd_io/ ? And why not passing an mtd_oob_ops object directly? That would reduce the number of parameters you pass to this function.

cmd/mtd.c line 79

Quoted 4 lines
cmd/mtd.c new file +4 -0
+{
+	u32 buf_len = woob ? mtd->writesize + mtd->oobsize :
+			     ROUND(len, mtd->writesize);
+	u8 *buf = malloc(buf_len);

It's probably worth a comment explaining why you allocate a bounce buffer here (i.e. to make sure len not aligned on a page size are padded with 0xff).

Maybe a simpler solution would be to simply refuse such unaligned accesses.

Quoted 20 lines
cmd/mtd.c new file +20 -0
+	struct mtd_oob_ops ops = {
+		.mode = raw ? MTD_OPS_RAW : 0,
+		.len = len,
+		.ooblen = woob ? mtd->oobsize : 0,
+		.datbuf = buf,
+		.oobbuf = woob ? &buf[mtd->writesize] : NULL,
+	};
+	int ret;
+
+	if (!buf)
+		return -ENOMEM;
+
+	memset(buf, 0xFF, buf_len);
+
+	if (read) {
+		ret = mtd_read_oob(mtd, from, &ops);
+	} else {
+		memcpy(buf, waddr, ops.len + ops.ooblen);
+		ret = mtd_write_oob(mtd, from, &ops);
+	}

cmd/mtd.c line 109

Quoted 10 lines
cmd/mtd.c new file +10 -0
+
+	if (ret) {
+		printf("Could not handle %lldB from 0x%08llx on %s, ret %d\n",
+		       len, from, mtd->name, ret);
+		return ret;
+	}
+
+	if (read) {
+		printf("Dump %lld data bytes from 0x%08llx:\n", len, from);
+		mtd_dump_buf(buf, len);

Read and dump are 2 different things: one might want to read an MTD device and store the result in RAM without dumping it on the console.

cmd/mtd.c line 115

Quoted 6 lines
cmd/mtd.c new file +6 -0
+
+		if (woob) {
+			printf("\nDump %d OOB bytes from 0x%08llx:\n",
+			       mtd->oobsize, from);
+			mtd_dump_buf(&buf[len], mtd->oobsize);
+		}

Looks like you're never copying the data back to waddr.

Quoted 36 lines
cmd/mtd.c new file +36 -0
+	}
+
+	kfree(buf);
+
+	return 0;
+}
+
+static int do_mtd_erase(struct mtd_info *mtd, bool scrub, u64 from, u64 len)
+{
+	struct erase_info erase_infos = {
+		.mtd = mtd,
+		.addr = from,
+		.len = len,
+		.scrub = scrub,
+	};
+
+	return mtd_erase(mtd, &erase_infos);
+}
+
+static int do_mtd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	struct mtd_info *mtd;
+	struct udevice *dev;
+	const char *cmd;
+	char *part;
+	int ret;
+
+	/* All MTD commands need at least two arguments */
+	if (argc < 2)
+		return CMD_RET_USAGE;
+
+	/* Parse the command name and its optional suffixes */
+	cmd = argv[1];
+
+	/* List the MTD devices if that is what the user wants */
+	if (strcmp(cmd, "list") == 0)

cmd/mtd.c line 161

Quoted 10 lines
cmd/mtd.c new file +10 -0
+		return do_mtd_list();
+
+	/*
+	 * The remaining commands require also at least a device ID.
+	 * Check the selected device is valid. Ensure it is probed.
+	 */
+	if (argc < 3)
+		return CMD_RET_USAGE;
+
+	part = argv[2];

Why part. The MTD object can be a partition or the device itself. How about renaming it mtdname?

Quoted 6 lines
cmd/mtd.c new file +6 -0
+	ret = uclass_find_device_by_name(UCLASS_MTD, part, &dev);
+	if (!ret && dev) {
+		mtd_probe(dev);
+		mtd = (struct mtd_info *)dev_get_uclass_priv(dev);
+		if (!mtd) {
+			printf("Could not retrieve MTD data\n");

cmd/mtd.c line 177

Quoted 10 lines
cmd/mtd.c new file +10 -0
+			return -ENODEV;
+		}
+	} else {
+		mtd = get_mtd_device_nm(part);
+		if (IS_ERR_OR_NULL(mtd)) {
+			printf("MTD device %s not found, ret %ld\n", part,
+			       PTR_ERR(mtd));
+			return 1;
+		}
+	}

Hm, I'd do it the other way around: first call get_mtd_device_nm() and if you don't find the device trigger the probe of all UCLASS_MTD devs, and then search again with get_mtd_device_nm(). Note that mtd->dev->name and mtd->name are 2 different things, and they won't match most of the time.

Quoted 28 lines
cmd/mtd.c new file +28 -0
+
+	argc -= 3;
+	argv += 3;
+
+	/* Do the parsing */
+	if (!strncmp(cmd, "read", 4) || !strncmp(cmd, "write", 5)) {
+		bool read, raw, woob;
+		uint *waddr = NULL;
+		u64 off, len;
+
+		read = !strncmp(cmd, "read", 4);
+		raw = strstr(cmd, ".raw");
+		woob = strstr(cmd, ".oob");
+
+		if (!read) {
+			if (argc < 1)
+				return CMD_RET_USAGE;
+
+			waddr = map_sysmem(simple_strtoul(argv[0], NULL, 10),
+					   0);
+			argc--;
+			argv++;
+		}
+
+		off = argc > 0 ? simple_strtoul(argv[0], NULL, 10) : 0;
+		len = argc > 1 ? simple_strtoul(argv[1], NULL, 10) :
+				 mtd->writesize + (woob ? mtd->oobsize : 0);
+

cmd/mtd.c line 215

Quoted 10 lines
cmd/mtd.c new file +10 -0
+		if ((u32)off % mtd->writesize) {
+			printf("Section not page-aligned (0x%x)\n",
+			       mtd->writesize);
+			return -EINVAL;
+		}
+
+		if (woob && (len != (mtd->writesize + mtd->oobsize))) {
+			printf("OOB operations are limited to single pages\n");
+			return -EINVAL;
+		}

Is this a uboot limitation? I don't think you have such a limitation in Linux.

cmd/mtd.c line 217

Quoted 2 lines
cmd/mtd.c new file +2 -0
+
+		if ((off + len) >= mtd->size) {

That doesn't work when reading the last page of the MTD device with woob = true. See how Linux handle that here [1]. BTW, why don't you let mtdcore.c do these checks for you (that's also true for unaligned accesses)?

Quoted 46 lines
cmd/mtd.c new file +46 -0
+			printf("Access location beyond the end of the chip\n");
+			return -EINVAL;
+		}
+
+		printf("%s (from %p) %lldB at 0x%08llx [%s %s]\n",
+		       read ? "read" : "write", read ? 0 : waddr, len, off,
+		       raw ? "raw" : "", woob ? "oob" : "");
+
+		ret = do_mtd_read_write(mtd, read, waddr, raw, woob, off, len);
+
+		if (!read)
+			unmap_sysmem(waddr);
+
+	} else if (!strcmp(cmd, "erase") || !strcmp(cmd, "scrub")) {
+		bool scrub = !strcmp(cmd, "scrub");
+		bool full_erase = !strncmp(&cmd[5], ".chip", 4);
+		u64 off, len;
+
+		off = argc > 0 ? simple_strtoul(argv[0], NULL, 10) : 0;
+		len = argc > 1 ? simple_strtoul(argv[1], NULL, 10) :
+				 mtd->erasesize;
+		if (full_erase) {
+			off = 0;
+			len = mtd->size;
+		}
+
+		if ((u32)off % mtd->erasesize) {
+			printf("Section not erase-block-aligned (0x%x)\n",
+			       mtd->erasesize);
+			return -EINVAL;
+		}
+
+		if ((u32)len % mtd->erasesize) {
+			printf("Size not aligned with an erase block (%dB)\n",
+			       mtd->erasesize);
+			return -EINVAL;
+		}
+
+		if ((off + len) >= mtd->size) {
+			printf("Cannot read beyond end of chip\n");
+			return -EINVAL;
+		}
+
+		ret = do_mtd_erase(mtd, scrub, off, len);
+	} else {
+		return CMD_RET_USAGE;

cmd/mtd.c line 273

Quoted 10 lines
cmd/mtd.c new file +10 -0
+	}
+
+	return ret;
+}
+
+static char mtd_help_text[] =
+#ifdef CONFIG_SYS_LONGHELP
+	"- generic operations on memory technology devices\n\n"
+	"mtd list\n"
+	"mtd read[.raw][.oob] <name> [<off> [<size>]]\n"

I guess this one should be

	"mtd read[.raw][.oob] <name> <addr> [<off> [<size>]]\n"

and then, you should have

	"mtd dump[.raw][.oob] <name> [<off> [<size>]]\n"

cmd/mtd.c line 276

Quoted 3 lines
cmd/mtd.c new file +3 -0
+	"mtd write[.raw][.oob] <name> <addr> [<off> [<size>]]\n"
+	"mtd erase[.chip] <name> [<off> [<size>]]\n"
+	"mtd scrub[.chip] <name> [<off> [<size>]]\n"

Hm, maybe it's time to simplify that. mtd.scrub is just an option of mtd erase, so maybe we should just have:

mtd erase[.force] or erase[.dontskipbad]

Also, [.chip] can be extracted from the number of parameters. If you just have <name> passed, that means the callers wants to erase the whole chip.

Regards,

Boris

cmd/mtd.c line 280

Quoted 4 lines
cmd/mtd.c new file +4 -0
+#endif
+	"";
+
+U_BOOT_CMD(mtd, 10, 1, do_mtd, "MTD utils", mtd_help_text);

[1]https://elixir.bootlin.com/linux/latest/source/drivers/mtd/mtdcore.c#L1117

author maintainer
#32 lore raw

RFC PATCH 17/20 cmd: mtd: add 'mtd' command

Hi Boris,

Boris Brezillon <[email protected]> wrote on Wed, 6 Jun 2018 21:45:24 +0200:

Quoted 117 lines

Hi Miquel,

Quoted 4 lines · On Wed, 6 Jun 2018 17:30:37 +0200 Miquel Raynal <[email protected]>…

There should not be a 'nand' command, a 'sf' command and certainly not another 'spi-nand'. Write a 'mtd' command instead to manage all MTD devices at once. This should be the preferred way to access any MTD device.

Just a few comments below, but overall, I'm really happy with this new set of commands and the fact that we'll soon be able to replace custom MTD accessors (nand, onenand, sf, cp.b+erase, ...) by these ones.

Quoted 103 lines
---
 cmd/Kconfig          |   5 +
 cmd/Makefile         |   1 +
 cmd/mtd.c            | 280 +++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/Makefile |   2 +-
 4 files changed, 287 insertions(+), 1 deletion(-)
 create mode 100644 cmd/mtd.c
cmd/Kconfig +5 -0
index 136836d146..6e9b629e1c 100644
@@ -797,6 +797,11 @@ config CMD_MMC
 	help
 	  MMC memory mapped support.
 
+config CMD_MTD
+	bool "mtd"
+	help
+	  MTD commands support.
+
 config CMD_NAND
 	bool "nand"
 	default y if NAND_SUNXI
cmd/Makefile +1 -0
index 9a358e4801..e42db12e1d 100644
@@ -88,6 +88,7 @@ obj-$(CONFIG_CMD_MISC) += misc.o
 obj-$(CONFIG_CMD_MMC) += mmc.o
 obj-$(CONFIG_CMD_MMC_SPI) += mmc_spi.o
 obj-$(CONFIG_MP) += mp.o
+obj-$(CONFIG_CMD_MTD) += mtd.o
 obj-$(CONFIG_CMD_MTDPARTS) += mtdparts.o
 obj-$(CONFIG_CMD_NAND) += nand.o
 obj-$(CONFIG_CMD_NET) += net.o
cmd/mtd.c new file +59 -0
new file mode 100644
index 0000000000..fe48378bd0
@@ -0,0 +1,280 @@
+// SPDX-License-Identifier:  GPL-2.0+
+/*
+ * mtd.c
+ *
+ * Generic command to handle basic operations on any memory device.
+ *
+ * Copyright: Bootlin, 2018
+ * Author: Miquèl Raynal <[email protected]>
+ */
+
+#include <common.h>
+#include <linux/mtd/mtd.h>
+#include <command.h>
+#include <console.h>
+#include <malloc.h>
+#include <mtd.h>
+#include <mapmem.h>
+#include <dm/device.h>
+#include <dm/uclass-internal.h>
+
+static void mtd_dump_buf(u8 *buf, uint len)
+{
+	int i, j;
+
+	for (i = 0; i < len; ) {
+		printf("0x%08x:\t", i);
+		for (j = 0; j < 8; j++)
+			printf("%02x ", buf[i + j]);
+		printf(" ");
+		i += 8;
+		for (j = 0; j < 8; j++)
+			printf("%02x ", buf[i + j]);
+		printf("\n");
+		i += 8;
+	}
+}
+
+static void mtd_show_device(struct mtd_info *mtd)
+{
+	printf("* %s", mtd->name);
+	if (mtd->dev)
+		printf(" [device: %s] [parent: %s] [driver: %s]",
+		       mtd->dev->name, mtd->dev->parent->name,
+		       mtd->dev->driver->name);
+
+	printf("\n");
+}
+
+static int do_mtd_list(void)
+{
+	struct mtd_info *mtd;
+	struct udevice *dev;
+	int dm_idx = 0, idx = 0;
+
+	/* Ensure all devices compliants with U-Boot driver model are probed */
+	while (!uclass_find_device(UCLASS_MTD, dm_idx, &dev) && dev) {
+		mtd_probe(dev);
+		dm_idx++;
+	}
Quoted 8 lines

cmd/mtd.c line 61

Quoted 2 lines
cmd/mtd.c new file +2 -0
+
+	printf("MTD devices list (%d DM compliant):\n", dm_idx);  

Do we really want to say how many of them are exported by DM compliant drivers? I mean, the user doesn't care about that. If you want to force people to convert their drivers, we should probably complain at MTD device registration time when the mtd_info struct is not backed by an udevice.

It was more like a small debug value but I don't really care about it.

Parenthesis removed.

Quoted 17 lines
Quoted 5 lines
cmd/mtd.c new file +4 -0
+
+	mtd_for_each_device(mtd) {
+		mtd_show_device(mtd);
+		idx++;

cmd/mtd.c line 75

Quoted 10 lines
cmd/mtd.c new file +10 -0
+	}
+
+	if (!idx)
+		printf("No MTD device found\n");
+
+	return 0;
+}
+
+static int do_mtd_read_write(struct mtd_info *mtd, bool read, uint *waddr,
+			     bool raw, bool woob, u64 from, u64 len)  

s/do_mtd_read_write/do_mtd_io/ ?

+1 for the artistic name :) -> renamed

Quoted 3 lines

And why not passing an mtd_oob_ops
object directly? That would reduce the number of parameters you pass to this function.

Good point actually. While rewriting the function I figured out there was no "reusable code" nor any "logicial split" with this do_mtd_io() helper so I just moved the code from it into the main do_mtd(). If you find it unclear please tell me where

Quoted 10 lines

cmd/mtd.c line 79

Quoted 5 lines
cmd/mtd.c new file +4 -0
+{
+	u32 buf_len = woob ? mtd->writesize + mtd->oobsize :
+			     ROUND(len, mtd->writesize);
+	u8 *buf = malloc(buf_len);  

It's probably worth a comment explaining why you allocate a bounce buffer here (i.e. to make sure len not aligned on a page size are padded with 0xff).

Quoted 2 lines

Maybe a simpler solution would be to simply refuse such unaligned accesses.

Agreed.

Quoted 26 lines
Quoted 26 lines
cmd/mtd.c new file +25 -0
+	struct mtd_oob_ops ops = {
+		.mode = raw ? MTD_OPS_RAW : 0,
+		.len = len,
+		.ooblen = woob ? mtd->oobsize : 0,
+		.datbuf = buf,
+		.oobbuf = woob ? &buf[mtd->writesize] : NULL,
+	};
+	int ret;
+
+	if (!buf)
+		return -ENOMEM;
+
+	memset(buf, 0xFF, buf_len);
+
+	if (read) {
+		ret = mtd_read_oob(mtd, from, &ops);
+	} else {
+		memcpy(buf, waddr, ops.len + ops.ooblen);
+		ret = mtd_write_oob(mtd, from, &ops);
+	}
+
+	if (ret) {
+		printf("Could not handle %lldB from 0x%08llx on %s, ret %d\n",
+		       len, from, mtd->name, ret);
+		return ret;
Quoted 8 lines

cmd/mtd.c line 109

Quoted 5 lines
cmd/mtd.c new file +5 -0
+	}
+
+	if (read) {
+		printf("Dump %lld data bytes from 0x%08llx:\n", len, from);
+		mtd_dump_buf(buf, len);  

Read and dump are 2 different things: one might want to read an MTD device and store the result in RAM without dumping it on the console.

Sure. Made a difference between read and dump.

Quoted 9 lines

cmd/mtd.c line 115

Quoted 7 lines
cmd/mtd.c new file +6 -0
+
+		if (woob) {
+			printf("\nDump %d OOB bytes from 0x%08llx:\n",
+			       mtd->oobsize, from);
+			mtd_dump_buf(&buf[len], mtd->oobsize);
+		}  

Looks like you're never copying the data back to waddr.

Fixed as there is no more bounce buffer.

Quoted 42 lines
Quoted 42 lines
cmd/mtd.c new file +41 -0
+	}
+
+	kfree(buf);
+
+	return 0;
+}
+
+static int do_mtd_erase(struct mtd_info *mtd, bool scrub, u64 from, u64 len)
+{
+	struct erase_info erase_infos = {
+		.mtd = mtd,
+		.addr = from,
+		.len = len,
+		.scrub = scrub,
+	};
+
+	return mtd_erase(mtd, &erase_infos);
+}
+
+static int do_mtd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	struct mtd_info *mtd;
+	struct udevice *dev;
+	const char *cmd;
+	char *part;
+	int ret;
+
+	/* All MTD commands need at least two arguments */
+	if (argc < 2)
+		return CMD_RET_USAGE;
+
+	/* Parse the command name and its optional suffixes */
+	cmd = argv[1];
+
+	/* List the MTD devices if that is what the user wants */
+	if (strcmp(cmd, "list") == 0)
+		return do_mtd_list();
+
+	/*
+	 * The remaining commands require also at least a device ID.
+	 * Check the selected device is valid. Ensure it is probed.
Quoted 8 lines

cmd/mtd.c line 161

Quoted 5 lines
cmd/mtd.c new file +5 -0
+	 */
+	if (argc < 3)
+		return CMD_RET_USAGE;
+
+	part = argv[2];  

Why part. The MTD object can be a partition or the device itself. How about renaming it mtdname?

Ok.

Quoted 15 lines
Quoted 15 lines
cmd/mtd.c new file +14 -0
+	ret = uclass_find_device_by_name(UCLASS_MTD, part, &dev);
+	if (!ret && dev) {
+		mtd_probe(dev);
+		mtd = (struct mtd_info *)dev_get_uclass_priv(dev);
+		if (!mtd) {
+			printf("Could not retrieve MTD data\n");
+			return -ENODEV;
+		}
+	} else {
+		mtd = get_mtd_device_nm(part);
+		if (IS_ERR_OR_NULL(mtd)) {
+			printf("MTD device %s not found, ret %ld\n", part,
+			       PTR_ERR(mtd));
+			return 1;
Quoted 8 lines

cmd/mtd.c line 177

Quoted 2 lines
cmd/mtd.c new file +2 -0
+		}
+	}  

Hm, I'd do it the other way around: first call get_mtd_device_nm() and if you don't find the device trigger the probe of all UCLASS_MTD devs, and then search again with get_mtd_device_nm(). Note that mtd->dev->name and mtd->name are 2 different things, and they won't match most of the time.

Actually the logic above was broken in the sense that an 'mtd list' was necessary prior to using any DM-compliant driven device.

Edited.

Quoted 34 lines
Quoted 34 lines
cmd/mtd.c new file +33 -0
+
+	argc -= 3;
+	argv += 3;
+
+	/* Do the parsing */
+	if (!strncmp(cmd, "read", 4) || !strncmp(cmd, "write", 5)) {
+		bool read, raw, woob;
+		uint *waddr = NULL;
+		u64 off, len;
+
+		read = !strncmp(cmd, "read", 4);
+		raw = strstr(cmd, ".raw");
+		woob = strstr(cmd, ".oob");
+
+		if (!read) {
+			if (argc < 1)
+				return CMD_RET_USAGE;
+
+			waddr = map_sysmem(simple_strtoul(argv[0], NULL, 10),
+					   0);
+			argc--;
+			argv++;
+		}
+
+		off = argc > 0 ? simple_strtoul(argv[0], NULL, 10) : 0;
+		len = argc > 1 ? simple_strtoul(argv[1], NULL, 10) :
+				 mtd->writesize + (woob ? mtd->oobsize : 0);
+
+		if ((u32)off % mtd->writesize) {
+			printf("Section not page-aligned (0x%x)\n",
+			       mtd->writesize);
+			return -EINVAL;
+		}
Quoted 8 lines

cmd/mtd.c line 215

Quoted 5 lines
cmd/mtd.c new file +5 -0
+
+		if (woob && (len != (mtd->writesize + mtd->oobsize))) {
+			printf("OOB operations are limited to single pages\n");
+			return -EINVAL;
+		}  

Is this a uboot limitation? I don't think you have such a limitation in Linux.

Kind of, only one single page write with OOB at a time is possible says a comment on mtd_oob_ops in mtd.h in Linux. Reads are actually not limited. But I really prefer to keep this limitation that simplifies _a lot_ the logic and is not really useful to a u-boot user I suppose.

Quoted 8 lines

cmd/mtd.c line 217

Quoted 3 lines
cmd/mtd.c new file +2 -0
+
+		if ((off + len) >= mtd->size) {  

That doesn't work when reading the last page of the MTD device with woob = true. See how Linux handle that here [1]. BTW, why don't you let mtdcore.c do these checks for you (that's also true for unaligned accesses)?

Because the relevant patch (and its fix :) ) has not been backported yet.

And now I understand your voice in my ears "do it".

Okay.

Quoted 73 lines
Quoted 47 lines
cmd/mtd.c new file +46 -0
+			printf("Access location beyond the end of the chip\n");
+			return -EINVAL;
+		}
+
+		printf("%s (from %p) %lldB at 0x%08llx [%s %s]\n",
+		       read ? "read" : "write", read ? 0 : waddr, len, off,
+		       raw ? "raw" : "", woob ? "oob" : "");
+
+		ret = do_mtd_read_write(mtd, read, waddr, raw, woob, off, len);
+
+		if (!read)
+			unmap_sysmem(waddr);
+
+	} else if (!strcmp(cmd, "erase") || !strcmp(cmd, "scrub")) {
+		bool scrub = !strcmp(cmd, "scrub");
+		bool full_erase = !strncmp(&cmd[5], ".chip", 4);
+		u64 off, len;
+
+		off = argc > 0 ? simple_strtoul(argv[0], NULL, 10) : 0;
+		len = argc > 1 ? simple_strtoul(argv[1], NULL, 10) :
+				 mtd->erasesize;
+		if (full_erase) {
+			off = 0;
+			len = mtd->size;
+		}
+
+		if ((u32)off % mtd->erasesize) {
+			printf("Section not erase-block-aligned (0x%x)\n",
+			       mtd->erasesize);
+			return -EINVAL;
+		}
+
+		if ((u32)len % mtd->erasesize) {
+			printf("Size not aligned with an erase block (%dB)\n",
+			       mtd->erasesize);
+			return -EINVAL;
+		}
+
+		if ((off + len) >= mtd->size) {
+			printf("Cannot read beyond end of chip\n");
+			return -EINVAL;
+		}
+
+		ret = do_mtd_erase(mtd, scrub, off, len);
+	} else {
+		return CMD_RET_USAGE;

cmd/mtd.c line 273

Quoted 10 lines
cmd/mtd.c new file +10 -0
+	}
+
+	return ret;
+}
+
+static char mtd_help_text[] =
+#ifdef CONFIG_SYS_LONGHELP
+	"- generic operations on memory technology devices\n\n"
+	"mtd list\n"
+	"mtd read[.raw][.oob] <name> [<off> [<size>]]\n"  

I guess this one should be

	"mtd read[.raw][.oob] <name> <addr> [<off> [<size>]]\n"

and then, you should have

	"mtd dump[.raw][.oob] <name> [<off> [<size>]]\n"

cmd/mtd.c line 276

Quoted 3 lines
cmd/mtd.c new file +3 -0
+	"mtd write[.raw][.oob] <name> <addr> [<off> [<size>]]\n"
+	"mtd erase[.chip] <name> [<off> [<size>]]\n"
+	"mtd scrub[.chip] <name> [<off> [<size>]]\n"  

Hm, maybe it's time to simplify that. mtd.scrub is just an option of mtd erase, so maybe we should just have:

Quoted 5 lines

mtd erase[.force] or erase[.dontskipbad]

Also, [.chip] can be extracted from the number of parameters. If you just have <name> passed, that means the callers wants to erase the whole chip.

I prefer .dontskipbad for the sake of clarity. Updated accordingly.

Also updated the code following Stefan comments: all the numbers (addresses, lengths) are hexadecimal + creation of a dump command.

Thanks for the review!
Miquèl

Quoted 11 lines

Regards,

Boris

cmd/mtd.c line 280

Quoted 4 lines
cmd/mtd.c new file +4 -0
+#endif
+	"";
+
+U_BOOT_CMD(mtd, 10, 1, do_mtd, "MTD utils", mtd_help_text);  

[1]https://elixir.bootlin.com/linux/latest/source/drivers/mtd/mtdcore.c#L1117

Signature · 3 lines
Miquel Raynal, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
#33 lore raw

RFC PATCH 17/20 cmd: mtd: add 'mtd' command

Quoted 42 lines · On Wed, 11 Jul 2018 15:51:39 +0200 Miquel Raynal <[email protected]>…
Quoted 33 lines
Quoted 33 lines
cmd/mtd.c new file +33 -0
+
+	argc -= 3;
+	argv += 3;
+
+	/* Do the parsing */
+	if (!strncmp(cmd, "read", 4) || !strncmp(cmd, "write", 5)) {
+		bool read, raw, woob;
+		uint *waddr = NULL;
+		u64 off, len;
+
+		read = !strncmp(cmd, "read", 4);
+		raw = strstr(cmd, ".raw");
+		woob = strstr(cmd, ".oob");
+
+		if (!read) {
+			if (argc < 1)
+				return CMD_RET_USAGE;
+
+			waddr = map_sysmem(simple_strtoul(argv[0], NULL, 10),
+					   0);
+			argc--;
+			argv++;
+		}
+
+		off = argc > 0 ? simple_strtoul(argv[0], NULL, 10) : 0;
+		len = argc > 1 ? simple_strtoul(argv[1], NULL, 10) :
+				 mtd->writesize + (woob ? mtd->oobsize : 0);
+
+		if ((u32)off % mtd->writesize) {
+			printf("Section not page-aligned (0x%x)\n",
+			       mtd->writesize);
+			return -EINVAL;
+		}
Quoted 8 lines

cmd/mtd.c line 215

Quoted 5 lines
cmd/mtd.c new file +5 -0
+
+		if (woob && (len != (mtd->writesize + mtd->oobsize))) {
+			printf("OOB operations are limited to single pages\n");
+			return -EINVAL;
+		}    

Is this a uboot limitation? I don't think you have such a limitation in Linux.

Quoted 4 lines

Kind of, only one single page write with OOB at a time is possible says a comment on mtd_oob_ops in mtd.h in Linux. Reads are actually not limited. But I really prefer to keep this limitation that simplifies _a lot_ the logic and is not really useful to a u-boot user I suppose.

It is useful when you write things in raw mode and the image you write contains OOB (which in turn contains pre-generated ECC bytes). I know we do such things on sunxi when writing the SPL.

Quoted 10 lines
Quoted 9 lines

Review

Quoted 4 lines
(quoted diff) +2 -0
+
+		if ((off + len) >= mtd->size) {    

That doesn't work when reading the last page of the MTD device with woob = true. See how Linux handle that here [1]. BTW, why don't you let mtdcore.c do these checks for you (that's also true for unaligned accesses)?

Quoted 4 lines

Because the relevant patch (and its fix :) ) has not been backported yet.

And now I understand your voice in my ears "do it".

Hehe. So I guess I'll see this patch in your v2 :-).

author maintainer
#34 lore raw

RFC PATCH 17/20 cmd: mtd: add 'mtd' command

Hi Boris,

Boris Brezillon <[email protected]> wrote on Wed, 11 Jul 2018 16:01:09 +0200:

Quoted 45 lines
Quoted 42 lines · On Wed, 11 Jul 2018 15:51:39 +0200 Miquel Raynal <[email protected]>…
Quoted 41 lines
Quoted 28 lines
cmd/mtd.c new file +28 -0
+
+	argc -= 3;
+	argv += 3;
+
+	/* Do the parsing */
+	if (!strncmp(cmd, "read", 4) || !strncmp(cmd, "write", 5)) {
+		bool read, raw, woob;
+		uint *waddr = NULL;
+		u64 off, len;
+
+		read = !strncmp(cmd, "read", 4);
+		raw = strstr(cmd, ".raw");
+		woob = strstr(cmd, ".oob");
+
+		if (!read) {
+			if (argc < 1)
+				return CMD_RET_USAGE;
+
+			waddr = map_sysmem(simple_strtoul(argv[0], NULL, 10),
+					   0);
+			argc--;
+			argv++;
+		}
+
+		off = argc > 0 ? simple_strtoul(argv[0], NULL, 10) : 0;
+		len = argc > 1 ? simple_strtoul(argv[1], NULL, 10) :
+				 mtd->writesize + (woob ? mtd->oobsize : 0);
+

cmd/mtd.c line 215

Quoted 10 lines
cmd/mtd.c new file +10 -0
+		if ((u32)off % mtd->writesize) {
+			printf("Section not page-aligned (0x%x)\n",
+			       mtd->writesize);
+			return -EINVAL;
+		}
+
+		if (woob && (len != (mtd->writesize + mtd->oobsize))) {
+			printf("OOB operations are limited to single pages\n");
+			return -EINVAL;
+		}      

Is this a uboot limitation? I don't think you have such a limitation in Linux.

Quoted 8 lines
Quoted 4 lines

Kind of, only one single page write with OOB at a time is possible says a comment on mtd_oob_ops in mtd.h in Linux. Reads are actually not limited. But I really prefer to keep this limitation that simplifies _a lot_ the logic and is not really useful to a u-boot user I suppose.

It is useful when you write things in raw mode and the image you write contains OOB (which in turn contains pre-generated ECC bytes). I know we do such things on sunxi when writing the SPL.

:'(

Ok.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

Review

Quoted 5 lines
(quoted diff) +2 -0
+
+		if ((off + len) >= mtd->size) {      

That doesn't work when reading the last page of the MTD device with woob = true. See how Linux handle that here [1]. BTW, why don't you let mtdcore.c do these checks for you (that's also true for unaligned accesses)?

Quoted 6 lines
Quoted 4 lines

Because the relevant patch (and its fix :) ) has not been backported yet.

And now I understand your voice in my ears "do it".

Hehe. So I guess I'll see this patch in your v2 :-).

Indeed ;)

Cheers,
Miquèl

#35 lore raw

RFC PATCH 17/20 cmd: mtd: add 'mtd' command

In reply to Miquel Raynal
Quoted 4 lines · Miquel Raynal

There should not be a 'nand' command, a 'sf' command and certainly not another 'spi-nand'. Write a 'mtd' command instead to manage all MTD devices at once. This should be the preferred way to access any MTD device.

So are you planning to integrate sf, nand command in future, adding them dm conversion of many stuff. I would like to reommend to go with spinand command. I have been through this and finally added spinor command, which I will going to in soon. once all are converted to dm, it would be easy and meaningfull to have common command.

author maintainer
#36 lore raw

RFC PATCH 17/20 cmd: mtd: add 'mtd' command

Hi Jagan,

Jagan Teki <[email protected]> wrote on Fri, 6 Jul 2018 17:08:57 +0530:

Quoted 11 lines · Miquel Raynal
Quoted 4 lines

There should not be a 'nand' command, a 'sf' command and certainly not another 'spi-nand'. Write a 'mtd' command instead to manage all MTD devices at once. This should be the preferred way to access any MTD device.

So are you planning to integrate sf, nand command in future, adding them dm conversion of many stuff. I would like to reommend to go with spinand command. I have been through this and finally added spinor command, which I will going to in soon. once all are converted to dm, it would be easy and meaningfull to have common command.

I'm not sure we are in sync about this. The whole point of the previous discussion was to decide whether or not we should make full use of the MTD stack or not. I think it was pretty clear on the fact that people prefer to be close to Linux's architecture on this regard.

MTD being an abstraction of the type of memory, I don't get the point in creating yet another command each time a new type of device is supported. The fact that all the drivers of these devices register to the MTD layer makes it trivial to interact with. So why should we wait?

Thanks,
Miquèl

#37 lore raw

RFC PATCH 17/20 cmd: mtd: add 'mtd' command

Hi Miquel,

Quoted 20 lines · Miquel Raynal

Jagan Teki <[email protected]> wrote on Fri, 6 Jul 2018 17:08:57 +0530:

Quoted 11 lines · Miquel Raynal
Quoted 4 lines

There should not be a 'nand' command, a 'sf' command and certainly not another 'spi-nand'. Write a 'mtd' command instead to manage all MTD devices at once. This should be the preferred way to access any MTD device.

So are you planning to integrate sf, nand command in future, adding them dm conversion of many stuff. I would like to reommend to go with spinand command. I have been through this and finally added spinor command, which I will going to in soon. once all are converted to dm, it would be easy and meaningfull to have common command.

I'm not sure we are in sync about this. The whole point of the previous discussion was to decide whether or not we should make full use of the MTD stack or not. I think it was pretty clear on the fact that people prefer to be close to Linux's architecture on this regard.

Quoted 5 lines

MTD being an abstraction of the type of memory, I don't get the point in creating yet another command each time a new type of device is supported. The fact that all the drivers of these devices register to the MTD layer makes it trivial to interact with. So why should we wait?

Yes, please don't add new commands for each subsystem / device-type. I like the idea of adding one new command-set (your mtd command) and extending this one to all other device-types over the time.

BTW: I'm testing your SPI NAND patches right now (still struggling with some Gigadevice SPI NAND) and found that the "mtd" command is not really in-line with the usual U-Boot commands. Here some comments:

- Use hex values per default (addresses, sizes and soffset)
- "mtd read" just prints the read values. It makes more sense to read into memory instead (similar to the "mtd write")

I have some patches to address these issues in the queue (still need some massaging), which you can fold into your patchset, once we agree on this.

Thanks,
Stefan

author maintainer
#38 lore raw

RFC PATCH 17/20 cmd: mtd: add 'mtd' command

Hi Stefan,

Stefan Roese <[email protected]> wrote on Fri, 6 Jul 2018 15:21:20 +0200:

Quoted 30 lines

Hi Miquel,

Quoted 14 lines · Miquel Raynal

Jagan Teki <[email protected]> wrote on Fri, 6 Jul 2018 17:08:57 +0530:

Quoted 6 lines
Quoted 5 lines · Miquel Raynal

There should not be a 'nand' command, a 'sf' command and certainly not another 'spi-nand'. Write a 'mtd' command instead to manage all MTD devices at once. This should be the preferred way to access any MTD device.

Quoted 6 lines

So are you planning to integrate sf, nand command in future, adding them dm conversion of many stuff. I would like to reommend to go with spinand command. I have been through this and finally added spinor command, which I will going to in soon. once all are converted to dm, it would be easy and meaningfull to have common command.
I'm not sure we are in sync about this. The whole point of the previous

Quoted 8 lines

discussion was to decide whether or not we should make full use of the MTD stack or not. I think it was pretty clear on the fact that people prefer to be close to Linux's architecture on this regard.

Quoted 1 line

MTD being an abstraction of the type of memory, I don't get the

point in creating yet another command each time a new type of device is supported. The fact that all the drivers of these devices register to the MTD layer makes it trivial to interact with. So why should we wait?

Yes, please don't add new commands for each subsystem / device-type. I like the idea of adding one new command-set (your mtd command) and extending this one to all other device-types over the time.

Quoted 8 lines

BTW: I'm testing your SPI NAND patches right now (still struggling with some Gigadevice SPI NAND) and found that the "mtd" command is not really in-line with the usual U-Boot commands. Here some comments:

- Use hex values per default (addresses, sizes and soffset)
- "mtd read" just prints the read values. It makes more sense to read into memory instead (similar to the "mtd write")

I absolutely agree with this! I sent this series to show people what I planned to contribute but this mtd command is still a WIP and there are plenty of things to address.

Quoted 4 lines

I have some patches to address these issues in the queue (still need some massaging), which you can fold into your patchset, once we agree on this.

I am currently working on a new iteration of this series in which the mtd.c file will change quite a bit. I plan to send a new version early next week. I suppose this one will be much more stable to base your fixes/enhancements on.

Thanks,
Miquèl

#39 lore raw

RFC PATCH 17/20 cmd: mtd: add 'mtd' command

Hi Miquel,

Quoted 48 lines · Miquel Raynal

Hi Stefan,

Stefan Roese <[email protected]> wrote on Fri, 6 Jul 2018 15:21:20 +0200:

Quoted 30 lines

Hi Miquel,

Quoted 14 lines · Miquel Raynal

Jagan Teki <[email protected]> wrote on Fri, 6 Jul 2018 17:08:57 +0530:

Quoted 6 lines
Quoted 5 lines · Miquel Raynal

There should not be a 'nand' command, a 'sf' command and certainly not another 'spi-nand'. Write a 'mtd' command instead to manage all MTD devices at once. This should be the preferred way to access any MTD device.

Quoted 6 lines

So are you planning to integrate sf, nand command in future, adding them dm conversion of many stuff. I would like to reommend to go with spinand command. I have been through this and finally added spinor command, which I will going to in soon. once all are converted to dm, it would be easy and meaningfull to have common command.
I'm not sure we are in sync about this. The whole point of the previous

Quoted 8 lines

discussion was to decide whether or not we should make full use of the MTD stack or not. I think it was pretty clear on the fact that people prefer to be close to Linux's architecture on this regard.

Quoted 1 line

MTD being an abstraction of the type of memory, I don't get the

point in creating yet another command each time a new type of device is supported. The fact that all the drivers of these devices register to the MTD layer makes it trivial to interact with. So why should we wait?

Yes, please don't add new commands for each subsystem / device-type. I like the idea of adding one new command-set (your mtd command) and extending this one to all other device-types over the time.

Quoted 8 lines

BTW: I'm testing your SPI NAND patches right now (still struggling with some Gigadevice SPI NAND) and found that the "mtd" command is not really in-line with the usual U-Boot commands. Here some comments:

- Use hex values per default (addresses, sizes and soffset)
- "mtd read" just prints the read values. It makes more sense to read into memory instead (similar to the "mtd write")

I absolutely agree with this! I sent this series to show people what I planned to contribute but this mtd command is still a WIP and there are plenty of things to address.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

I have some patches to address these issues in the queue (still need some massaging), which you can fold into your patchset, once we agree on this.

I am currently working on a new iteration of this series in which the mtd.c file will change quite a bit. I plan to send a new version early next week. I suppose this one will be much more stable to base your fixes/enhancements on.

That sound really great. Looking forward to seeing the new version next week. :)

Thanks,
Stefan

author maintainer
#40 lore raw

RFC PATCH 18/20 dt-bindings: Add bindings for SPI NAND devices

In reply to Miquel Raynal

From: Boris Brezillon <[email protected]>

Add bindings for SPI NAND chips.

---
 doc/device-tree-bindings/mtd/spi-nand.txt | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 doc/device-tree-bindings/mtd/spi-nand.txt
doc/device-tree-bindings/mtd/spi-nand.txt new file +27 -0
new file mode 100644
index 0000000000..d55f80196c
@@ -0,0 +1,27 @@
+SPI NAND flash
+
+Required properties:
+- compatible: should be "spi-nand"
+- reg: should encode the chip-select line used to access the NAND chip
+
+Optional properties
+- spi-max-frequency: maximum frequency of the SPI bus the chip can operate at.
+		     This should encode board limitations (i.e. max freq can't
+		     be achieved due to crosstalk on IO lines).
+		     When unspecified, the driver assumes the chip can run at
+		     the max frequency defined in the spec (information
+		     extracted chip detection time).
+- spi-tx-bus-width: The bus width (number of data wires) that is used for MOSI.
+		    Only encodes the board constraints (i.e. when not all IO
+		    signals are routed on the board). Device constraints are
+		    extracted when detecting the chip, and controller
+		    constraints are exposed by the SPI mem controller. If this
+		    property is missing that means no constraint at the board
+		    level.
+- spi-rx-bus-width: The bus width (number of data wires) that is used for MISO.
+		    Only encodes the board constraints (i.e. when not all IO
+		    signals are routed on the board). Device constraints are
+		    extracted when detecting the chip, and controller
+		    constraints are exposed by the SPI mem controller. If this
+		    property is missing that means no constraint at the board
+		    level.
Signature · 1 line
2.14.1
author maintainer
#41 lore raw

RFC PATCH 19/20 mips: dts: ocelot: describe SPI CS pins

In reply to Miquel Raynal

Describe all SPI CS pins that are not part of the SoC. CS0 can only be used as SPI CS, while CS1, CS2 and CS3 defaults as GPIOs.

---
 arch/mips/dts/mscc,ocelot.dtsi | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
arch/mips/dts/mscc,ocelot.dtsi +20 -0
index d1b8868194..8b04f76ed4 100644
@@ -135,6 +135,26 @@
 				pins = "GPIO_12", "GPIO_13";
 				function = "uart2";
 			};
+
+			spi_cs1_pin: spi-cs1-pin {
+				pins = "GPIO_8";
+				function = "si";
+			};
+
+			spi_cs2_pin: spi-cs2-pin {
+				pins = "GPIO_9";
+				function = "si";
+			};
+
+			spi_cs3_pin: spi-cs3-pin {
+				pins = "GPIO_16";
+				function = "si";
+			};
+
+			spi_cs4_pin: spi-cs4-pin {
+				pins = "GPIO_17";
+				function = "si";
+			};
 		};
 	};
 };
Signature · 1 line
2.14.1
author maintainer
#42 lore raw

RFC PATCH 20/20 mips: dts: ocelot: add the SPI NAND node

In reply to Miquel Raynal

Declare the SPI NAND device accessible on the SPI bus with CS1.

---
 arch/mips/dts/mscc,ocelot_pcb.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/mips/dts/mscc,ocelot_pcb.dtsi +9 -0
index 4e532363c3..2f37ef92f9 100644
@@ -25,11 +25,20 @@
 
 &spi0 {
 	status = "okay";
+	pinctrl-0 = <&spi_cs1_pin>;
+	pinctrl-names = "default";
+
 	spi-flash at 0 {
 		compatible = "spi-flash";
                 spi-max-frequency = <18000000>; /* input clock */
                 reg = <0>; /* CS0 */
 	};
+
+	spi-nand at 1 {
+		compatible = "spi-nand";
+		spi-max-frequency = <18000000>; /* input clock */
+		reg = <1>; /* CS1 */
+	};
 };
 
 &ethernet {
Signature · 1 line
2.14.1
#43 lore raw

cover SPI-NAND support

In reply to Miquel Raynal

+ Boris
+ Suneel (who helped in DM MTD)
+ Siva, Michal (zynq qspi)

Quoted 7 lines · Miquel Raynal

During the last months, Boris Brezillon shared his work to support serial flashes within Linux. First, he delivered (and merged) a new layer called spi-mem. He also initiated in Linux MTD subsystem the move of all 'raw' NAND related code to a raw/ subdirectory, adding at the same time a NAND core that would be shared with all NAND devices. Then, he contributed a generic SPI-NAND driver, making use of this NAND core, as well as some vendor code to drive a few chips.

1) Can you pointed us the Linux changes along with discussion thread about spi-mem, and spi-nand.

2) If my understanding was correct, spi-mem is replacement for spi-nor controller drivers from driver/mtd/spi-nor in Linux.

3) If so is fsl_qspi spi-nor driver moves to drivers/spi area? yes then how does flash changes handled by spi-mem.

4) we have zynq qspi controller which has extensive features like dual flash(stacked and parallel) does spi-mem support these flash specific changes?

5) Better to send spi-mem and spi-nand changes separately, for better reviewing.

6) We have DM MTD layer in ML, better to send the changes on-top [1]

[1] https://patchwork.ozlabs.org/project/uboot/list/?series=20450

Jagan.

Signature · 4 lines
Jagan Teki
Free Software Engineer | www.openedev.com
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.
author maintainer
#44 lore raw

cover SPI-NAND support

Hi Jagan,

Quoted 13 lines · Jagan Teki

+ Boris
+ Suneel (who helped in DM MTD)
+ Siva, Michal (zynq qspi)

Quoted 7 lines · Miquel Raynal

During the last months, Boris Brezillon shared his work to support serial flashes within Linux. First, he delivered (and merged) a new layer called spi-mem. He also initiated in Linux MTD subsystem the move of all 'raw' NAND related code to a raw/ subdirectory, adding at the same time a NAND core that would be shared with all NAND devices. Then, he contributed a generic SPI-NAND driver, making use of this NAND core, as well as some vendor code to drive a few chips.

Quoted 2 lines

1) Can you pointed us the Linux changes along with discussion thread about spi-mem, and spi-nand.

Sure, you can have a look there:

SPI-mem:
http://lists.infradead.org/pipermail/linux-mtd/2018-April/080225.html

SPI-NAND:
http://lists.infradead.org/pipermail/linux-mtd/2018-May/081005.html

Quoted 3 lines

2) If my understanding was correct, spi-mem is replacement for spi-nor controller drivers from driver/mtd/spi-nor in Linux.

It is not 'exactly' a replacement for spi-nor controller drivers but that's the idea. I suggest you to have a look at Boris' blog post about it:
https://bootlin.com/blog/spi-mem-bringing-some-consistency-to-the-spi-memory-ecosystem/

Quoted 3 lines

3) If so is fsl_qspi spi-nor driver moves to drivers/spi area? yes then how does flash changes handled by spi-mem.

This series does not migrate the SPI-NOR stack to spi-mem. It focuses on SPI-NAND for now. And I don't understand the second sentence.

Quoted 4 lines

4) we have zynq qspi controller which has extensive features like dual flash(stacked and parallel) does spi-mem support these flash specific changes?

This controller is very specific and such support has not yet been added.

Quoted 2 lines

5) Better to send spi-mem and spi-nand changes separately, for better reviewing.

It would mean sending 3 or 4 distinct series, I thought better to give the whole picture but that's your choice.

Quoted 4 lines

6) We have DM MTD layer in ML, better to send the changes on-top [1]

[1] https://patchwork.ozlabs.org/project/uboot/list/?series=20450

This is great to see such effort being made to develop U-Boot driver-model but is there a real need for yet another layer on top of the MTD stack?

I'm looking at mtd-uclass.c for instance, I don't get the need for a mtd_dread() function, all the operations in the mtd_d*() helpers are already handled by mtd/mtdcore.c, no?

And the mtd_ops structure does not bring a lot. Should not we keep it simple and avoid such intermediate layer?

Also, there is the introduction of a spinor command (what about the existing 'sf'?), which is exactly the opposite of what the MTD abstraction would told us to do (thus, the 'mtd' generic command).

Regards,
Miquèl

#45 lore raw

cover SPI-NAND support

Hi Jagan,

Quoted 72 lines · On Thu, 7 Jun 2018 10:41:35 +0200 Miquel Raynal <[email protected]>…

Hi Jagan,

Quoted 13 lines · Jagan Teki

+ Boris
+ Suneel (who helped in DM MTD)
+ Siva, Michal (zynq qspi)

Quoted 7 lines · Miquel Raynal

During the last months, Boris Brezillon shared his work to support serial flashes within Linux. First, he delivered (and merged) a new layer called spi-mem. He also initiated in Linux MTD subsystem the move of all 'raw' NAND related code to a raw/ subdirectory, adding at the same time a NAND core that would be shared with all NAND devices. Then, he contributed a generic SPI-NAND driver, making use of this NAND core, as well as some vendor code to drive a few chips.

Quoted 2 lines

1) Can you pointed us the Linux changes along with discussion thread about spi-mem, and spi-nand.

Sure, you can have a look there:

SPI-mem:
http://lists.infradead.org/pipermail/linux-mtd/2018-April/080225.html

SPI-NAND:
http://lists.infradead.org/pipermail/linux-mtd/2018-May/081005.html

Quoted 3 lines

2) If my understanding was correct, spi-mem is replacement for spi-nor controller drivers from driver/mtd/spi-nor in Linux.

It is not 'exactly' a replacement for spi-nor controller drivers but that's the idea. I suggest you to have a look at Boris' blog post about it:
https://bootlin.com/blog/spi-mem-bringing-some-consistency-to-the-spi-memory-ecosystem/

Quoted 3 lines

3) If so is fsl_qspi spi-nor driver moves to drivers/spi area? yes then how does flash changes handled by spi-mem.

This series does not migrate the SPI-NOR stack to spi-mem. It focuses on SPI-NAND for now. And I don't understand the second sentence.

Quoted 4 lines

4) we have zynq qspi controller which has extensive features like dual flash(stacked and parallel) does spi-mem support these flash specific changes?

This controller is very specific and such support has not yet been added.

Quoted 2 lines

5) Better to send spi-mem and spi-nand changes separately, for better reviewing.

It would mean sending 3 or 4 distinct series, I thought better to give the whole picture but that's your choice.

Quoted 4 lines

6) We have DM MTD layer in ML, better to send the changes on-top [1]

[1] https://patchwork.ozlabs.org/project/uboot/list/?series=20450

This is great to see such effort being made to develop U-Boot driver-model but is there a real need for yet another layer on top of the MTD stack?

I'm looking at mtd-uclass.c for instance, I don't get the need for a mtd_dread() function, all the operations in the mtd_d*() helpers are already handled by mtd/mtdcore.c, no?

Quoted 6 lines

And the mtd_ops structure does not bring a lot. Should not we keep it simple and avoid such intermediate layer?

Also, there is the introduction of a spinor command (what about the existing 'sf'?), which is exactly the opposite of what the MTD abstraction would told us to do (thus, the 'mtd' generic command).

Any chance you can comment on Miquel's reply?

That's really important to have your feedback on these questions since your answers might heavily impact the work we'll have to do to get things merged (especially question #6).

Thanks,

Boris

#46 lore raw

cover SPI-NAND support

In reply to Miquel Raynal

Miquel and Brois, thanks for working on this.

Quoted 21 lines · Miquel Raynal

Hi Jagan,

Quoted 13 lines · Jagan Teki

+ Boris
+ Suneel (who helped in DM MTD)
+ Siva, Michal (zynq qspi)

Quoted 7 lines · Miquel Raynal

During the last months, Boris Brezillon shared his work to support serial flashes within Linux. First, he delivered (and merged) a new layer called spi-mem. He also initiated in Linux MTD subsystem the move of all 'raw' NAND related code to a raw/ subdirectory, adding at the same time a NAND core that would be shared with all NAND devices. Then, he contributed a generic SPI-NAND driver, making use of this NAND core, as well as some vendor code to drive a few chips.

Quoted 2 lines

1) Can you pointed us the Linux changes along with discussion thread about spi-mem, and spi-nand.

Quoted 7 lines

Sure, you can have a look there:

SPI-mem:
http://lists.infradead.org/pipermail/linux-mtd/2018-April/080225.html

SPI-NAND:
http://lists.infradead.org/pipermail/linux-mtd/2018-May/081005.html

This is really nice, look like this design handling any kind of controller features by abstracting spi core so-that controller hacks shouldn't touch the common core code. unfortunately I missed Linux ML during submission.

Quoted 44 lines
Quoted 4 lines

2) If my understanding was correct, spi-mem is replacement for spi-nor controller drivers from driver/mtd/spi-nor in Linux.

It is not 'exactly' a replacement for spi-nor controller drivers but that's the idea. I suggest you to have a look at Boris' blog post about it:
https://bootlin.com/blog/spi-mem-bringing-some-consistency-to-the-spi-memory-ecosystem/

Quoted 3 lines

3) If so is fsl_qspi spi-nor driver moves to drivers/spi area? yes then how does flash changes handled by spi-mem.

This series does not migrate the SPI-NOR stack to spi-mem. It focuses on SPI-NAND for now. And I don't understand the second sentence.

Quoted 4 lines

4) we have zynq qspi controller which has extensive features like dual flash(stacked and parallel) does spi-mem support these flash specific changes?

This controller is very specific and such support has not yet been added.

Quoted 2 lines

5) Better to send spi-mem and spi-nand changes separately, for better reviewing.

It would mean sending 3 or 4 distinct series, I thought better to give the whole picture but that's your choice.

Quoted 4 lines

6) We have DM MTD layer in ML, better to send the changes on-top [1]

[1] https://patchwork.ozlabs.org/project/uboot/list/?series=20450

This is great to see such effort being made to develop U-Boot driver-model but is there a real need for yet another layer on top of the MTD stack?

I'm looking at mtd-uclass.c for instance, I don't get the need for a mtd_dread() function, all the operations in the mtd_d*() helpers are already handled by mtd/mtdcore.c, no?

Quoted 6 lines

And the mtd_ops structure does not bring a lot. Should not we keep it simple and avoid such intermediate layer?

Also, there is the introduction of a spinor command (what about the existing 'sf'?), which is exactly the opposite of what the MTD abstraction would told us to do (thus, the 'mtd' generic command).

I've looked the code on the respective patches, look like most of the code copy from Linux by adding __UBOOT__. I have no issue with Linux copy but we need to structure the code according to U-Boot in the form of driver-model (this series lack with that).

Here are my suggestions, based the MTD work so-far

First we need to design MTD driver-model which can capable to drive one driver from each interface. (not converting all interface drivers at once, that is taking more time and other issues)

Like Linux MTD, U-Boot should have MTD dm for underlying flash devices like nand, parallel nor, spinor etc. So to drive this theory with driver model(with an example of block layer) mtd is common device interaction for most of memory technology flashes like nand, parallel nor, spinor etc, these are treated as interface types wrt u-boot driver model.

Once the respective interface driver bind happen, the uclass driver will pass an 'interface type' to mtd layer to create device for it, for example once spinor ULASS_SPI_NOR driver bind happen, the uclass driver of spinor will pass MTD_IF_TYPE_SPI_NOR
interface type to create mtd device for spinor devices.

So If we add this design to SPI-NAND changes, we need to implement
- MTD dm core that can driver all interfaces
- one driver for raw nand
- one driver for spinand
- spi-mem
- convert fsl-qspi to spi-mem
- implement command to handle

For spi-nor interface design, we have an example code here[2]

I've paused this [2] series because of dm conversion of spi-drivers otherwise I need add legacy code like mmc-legacy.c, so if we really move to spi-mem design and okay with above design. I will try to move the current spi flash to add MTD driver-model so-that we can add spi-mem, spi-nand on top of it or we can work together to convert them all.

[2] https://patchwork.ozlabs.org/project/uboot/list/?series=20450

Jagan.

#47 lore raw

cover SPI-NAND support

+Richard to comment on the MTD abstraction stuff and how uboot port of UBI might be impacted by some changes requested here.

Hi Jagan,

Quoted 19 lines · On Mon, 25 Jun 2018 13:59:37 +0530 Jagan Teki <[email protected]> wrote:

I've looked the code on the respective patches, look like most of the code copy from Linux by adding __UBOOT__. I have no issue with Linux copy but we need to structure the code according to U-Boot in the form of driver-model (this series lack with that).

Here are my suggestions, based the MTD work so-far

First we need to design MTD driver-model which can capable to drive one driver from each interface. (not converting all interface drivers at once, that is taking more time and other issues)

Like Linux MTD, U-Boot should have MTD dm for underlying flash devices like nand, parallel nor, spinor etc. So to drive this theory with driver model(with an example of block layer) mtd is common device interaction for most of memory technology flashes like nand, parallel nor, spinor etc, these are treated as interface types wrt u-boot driver model.

Quoted 8 lines

Once the respective interface driver bind happen, the uclass driver will pass an 'interface type' to mtd layer to create device for it, for example once spinor ULASS_SPI_NOR driver bind happen, the uclass driver of spinor will pass MTD_IF_TYPE_SPI_NOR
interface type to create mtd device for spinor devices.

So If we add this design to SPI-NAND changes, we need to implement
- MTD dm core that can driver all interfaces

That's already what the MTD framework provides, and Miquel even added some stuff to integrate the MTD layer even further in the DM. It's probably not perfect yet, but the changes are, IMHO, going in the right direction.

Now, if you're talking about the new MTD API that creates helper functions prefixed with dm_, sorry, but I don't see the point. We already have plenty of MTD users in u-boot, they all manipulate MTD objects and go through the standard MTD API to do that. What you suggest would make things messier for several reasons:

1/ we won't be able to easily port Linux code to u-boot. Look at the
JFFS2 UBI support. They all use mtd_info objects. What's the point of changing that except making things harder to port.

2/ Not all MTD providers will be converted to the device model at once,
so how do you plan to deal with that?

3/ What's the benefit of exposing yet another way to manipulate MTD
devices?

Quoted 1 line

- one driver for raw nand

Unfortunately, that's not how it works right now, and clearly, we don't have time to work on this raw NAND rework right now.

Quoted 1 line

- one driver for spinand

I think that's already the case.

Quoted 1 line

- spi-mem

It's also what Miquel is doing in this series.

Quoted 1 line

- convert fsl-qspi to spi-mem

We're not targeting the fsl-qspi controller here but a simple SPI controller that is already upstreamed. But yes, the fsl-qspi driver will have to be patched to support the spi-mem interface at some point.

Quoted 1 line

- implement command to handle

This I don't get. What do you mean by "implement command to handle"? Are we talking about cmd/mtd.c? I think the work Miquel has done is already a good start, what's missing in there?

Quoted 9 lines

For spi-nor interface design, we have an example code here[2]

I've paused this [2] series because of dm conversion of spi-drivers otherwise I need add legacy code like mmc-legacy.c, so if we really move to spi-mem design and okay with above design. I will try to move the current spi flash to add MTD driver-model so-that we can add spi-mem, spi-nand on top of it or we can work together to convert them all.

Why can't we do things iteratively. I mean, if the long term goal is to convert everything to the driver model, then this patchset is going in the right direction:
- addition of DM helpers to the MTD_UCLASS
- addition of the spi-mem interface properly integrated in the DM model of the SPI framework
- addition of a SPI NAND driver, again properly integrated in the DM
- integration of DM-ready MTD drivers and old MTD drivers in a single view exposed by the cmd/mtd.c command set

I'd really like to limit the scope of this development to these topics, which doesn't prevent you from converting other part of u-boot to the spi-mem approach (SPI NOR is one example).

I hope you understand our concerns and the fact that what you're asking us to do as a dependency of getting SPI NAND support + cmd/mtd.c merged is way more than we can actually provide.

Regards,

Boris

#48 lore raw

cover SPI-NAND support

Am Montag, 25. Juni 2018, 11:09:41 CEST schrieb Boris Brezillon:

Quoted 102 lines

+Richard to comment on the MTD abstraction stuff and how uboot port of UBI might be impacted by some changes requested here.

Hi Jagan,

Quoted 19 lines · On Mon, 25 Jun 2018 13:59:37 +0530 Jagan Teki <[email protected]> wrote:

I've looked the code on the respective patches, look like most of the code copy from Linux by adding __UBOOT__. I have no issue with Linux copy but we need to structure the code according to U-Boot in the form of driver-model (this series lack with that).

Here are my suggestions, based the MTD work so-far

First we need to design MTD driver-model which can capable to drive one driver from each interface. (not converting all interface drivers at once, that is taking more time and other issues)

Like Linux MTD, U-Boot should have MTD dm for underlying flash devices like nand, parallel nor, spinor etc. So to drive this theory with driver model(with an example of block layer) mtd is common device interaction for most of memory technology flashes like nand, parallel nor, spinor etc, these are treated as interface types wrt u-boot driver model.

Quoted 8 lines

Once the respective interface driver bind happen, the uclass driver will pass an 'interface type' to mtd layer to create device for it, for example once spinor ULASS_SPI_NOR driver bind happen, the uclass driver of spinor will pass MTD_IF_TYPE_SPI_NOR
interface type to create mtd device for spinor devices.

So If we add this design to SPI-NAND changes, we need to implement
- MTD dm core that can driver all interfaces

That's already what the MTD framework provides, and Miquel even added some stuff to integrate the MTD layer even further in the DM. It's probably not perfect yet, but the changes are, IMHO, going in the right direction.

Now, if you're talking about the new MTD API that creates helper functions prefixed with dm_, sorry, but I don't see the point. We already have plenty of MTD users in u-boot, they all manipulate MTD objects and go through the standard MTD API to do that. What you suggest would make things messier for several reasons:

1/ we won't be able to easily port Linux code to u-boot. Look at the
JFFS2 UBI support. They all use mtd_info objects. What's the point of changing that except making things harder to port.

2/ Not all MTD providers will be converted to the device model at once,
so how do you plan to deal with that?

3/ What's the benefit of exposing yet another way to manipulate MTD
devices?

Quoted 1 line

- one driver for raw nand

Unfortunately, that's not how it works right now, and clearly, we don't have time to work on this raw NAND rework right now.

Quoted 1 line

- one driver for spinand

I think that's already the case.

Quoted 1 line

- spi-mem

It's also what Miquel is doing in this series.

Quoted 1 line

- convert fsl-qspi to spi-mem

We're not targeting the fsl-qspi controller here but a simple SPI controller that is already upstreamed. But yes, the fsl-qspi driver will have to be patched to support the spi-mem interface at some point.

Quoted 1 line

- implement command to handle

This I don't get. What do you mean by "implement command to handle"? Are we talking about cmd/mtd.c? I think the work Miquel has done is already a good start, what's missing in there?

Quoted 9 lines

For spi-nor interface design, we have an example code here[2]

I've paused this [2] series because of dm conversion of spi-drivers otherwise I need add legacy code like mmc-legacy.c, so if we really move to spi-mem design and okay with above design. I will try to move the current spi flash to add MTD driver-model so-that we can add spi-mem, spi-nand on top of it or we can work together to convert them all.

Why can't we do things iteratively. I mean, if the long term goal is to convert everything to the driver model, then this patchset is going in the right direction:
- addition of DM helpers to the MTD_UCLASS
- addition of the spi-mem interface properly integrated in the DM model of the SPI framework
- addition of a SPI NAND driver, again properly integrated in the DM
- integration of DM-ready MTD drivers and old MTD drivers in a single view exposed by the cmd/mtd.c command set

Quoted 7 lines

I'd really like to limit the scope of this development to these topics, which doesn't prevent you from converting other part of u-boot to the spi-mem approach (SPI NOR is one example).

I hope you understand our concerns and the fact that what you're asking us to do as a dependency of getting SPI NAND support + cmd/mtd.c merged is way more than we can actually provide.

+1

As someone who is concerned that UBI and UBIFS are sane within u-boot I'm not at all in favor of adding such a layer. The current MTD framework does not need another abstraction level.
It will make keeping u-boot in sync with Linux more complicated that it is already.

Thanks,
//richard

#49 lore raw

cover SPI-NAND support

In reply to Boris Brezillon

+ Simon
+ Tom
(suggesting MTD driver model abstraction layer)

Quoted 68 lines · Boris Brezillon

+Richard to comment on the MTD abstraction stuff and how uboot port of UBI might be impacted by some changes requested here.

Hi Jagan,

Quoted 19 lines · On Mon, 25 Jun 2018 13:59:37 +0530 Jagan Teki <[email protected]> wrote:

I've looked the code on the respective patches, look like most of the code copy from Linux by adding __UBOOT__. I have no issue with Linux copy but we need to structure the code according to U-Boot in the form of driver-model (this series lack with that).

Here are my suggestions, based the MTD work so-far

First we need to design MTD driver-model which can capable to drive one driver from each interface. (not converting all interface drivers at once, that is taking more time and other issues)

Like Linux MTD, U-Boot should have MTD dm for underlying flash devices like nand, parallel nor, spinor etc. So to drive this theory with driver model(with an example of block layer) mtd is common device interaction for most of memory technology flashes like nand, parallel nor, spinor etc, these are treated as interface types wrt u-boot driver model.

Quoted 8 lines

Once the respective interface driver bind happen, the uclass driver will pass an 'interface type' to mtd layer to create device for it, for example once spinor ULASS_SPI_NOR driver bind happen, the uclass driver of spinor will pass MTD_IF_TYPE_SPI_NOR
interface type to create mtd device for spinor devices.

So If we add this design to SPI-NAND changes, we need to implement
- MTD dm core that can driver all interfaces

That's already what the MTD framework provides, and Miquel even added some stuff to integrate the MTD layer even further in the DM. It's probably not perfect yet, but the changes are, IMHO, going in the right direction.

Now, if you're talking about the new MTD API that creates helper functions prefixed with dm_, sorry, but I don't see the point. We already have plenty of MTD users in u-boot, they all manipulate MTD objects and go through the standard MTD API to do that. What you suggest would make things messier for several reasons:

1/ we won't be able to easily port Linux code to u-boot. Look at the
JFFS2 UBI support. They all use mtd_info objects. What's the point of changing that except making things harder to port.

2/ Not all MTD providers will be converted to the device model at once,
so how do you plan to deal with that?

3/ What's the benefit of exposing yet another way to manipulate MTD
devices?

Quoted 1 line

- one driver for raw nand

Unfortunately, that's not how it works right now, and clearly, we don't have time to work on this raw NAND rework right now.

Quoted 1 line

- one driver for spinand

I think that's already the case.

Quoted 1 line

- spi-mem

Quoted 7 lines

It's also what Miquel is doing in this series.

Quoted 1 line

- convert fsl-qspi to spi-mem

We're not targeting the fsl-qspi controller here but a simple SPI controller that is already upstreamed. But yes, the fsl-qspi driver will have to be patched to support the spi-mem interface at some point.

Can you point me that simple spi-mem controller driver?

Quoted 27 lines
Quoted 2 lines

- implement command to handle

This I don't get. What do you mean by "implement command to handle"? Are we talking about cmd/mtd.c? I think the work Miquel has done is already a good start, what's missing in there?

Quoted 9 lines

For spi-nor interface design, we have an example code here[2]

I've paused this [2] series because of dm conversion of spi-drivers otherwise I need add legacy code like mmc-legacy.c, so if we really move to spi-mem design and okay with above design. I will try to move the current spi flash to add MTD driver-model so-that we can add spi-mem, spi-nand on top of it or we can work together to convert them all.

Why can't we do things iteratively. I mean, if the long term goal is to convert everything to the driver model, then this patchset is going in the right direction:
- addition of DM helpers to the MTD_UCLASS
- addition of the spi-mem interface properly integrated in the DM model of the SPI framework
- addition of a SPI NAND driver, again properly integrated in the DM
- integration of DM-ready MTD drivers and old MTD drivers in a single view exposed by the cmd/mtd.c command set

Quoted 7 lines

I'd really like to limit the scope of this development to these topics, which doesn't prevent you from converting other part of u-boot to the spi-mem approach (SPI NOR is one example).

I hope you understand our concerns and the fact that what you're asking us to do as a dependency of getting SPI NAND support + cmd/mtd.c merged is way more than we can actually provide.

To answer all these questions, I think we need to decide whether we go for MTD dm abstraction or existing MTD layer.

When I say MTD dm abstraction, all mtd operation prototypes are in the form of udevice unlike existing MTD has mtd_info. when I initially supporting spi-nor (during Linux early spi-nor) I've reused existing MTD and written something like what Miquel did using mtd_info ops [3]. but then developers on ML, proposed the new drivers should be form of driver-model abstraction, so I've added mtd driver model ops [4].

I understand the new MTD dm abstraction in U-Boot is not possible for direct syncing from Linux, but we really want the u-boot way of handling drivers and trying to copy code from Linux by removing __UBOOT__ or any Linux specific macros. Since this is pretty much big task, ie the reason I'm asking for single driver from each MTD device so-that once the clear stack is ready other drivers can convert one-by-one.

[3] http://git.denx.de/?p=u-boot-spi.git;a=commitdiff;h=d297949cd3f44278f109dff42fb88a879722121c
[4] https://patchwork.ozlabs.org/patch/853337/

#50 lore raw

cover SPI-NAND support

+ Simon
+ Tom

Quoted 139 lines · Jagan Teki

+ Simon
+ Tom
(suggesting MTD driver model abstraction layer)

Quoted 68 lines · Boris Brezillon

+Richard to comment on the MTD abstraction stuff and how uboot port of UBI might be impacted by some changes requested here.

Hi Jagan,

Quoted 19 lines · On Mon, 25 Jun 2018 13:59:37 +0530 Jagan Teki <[email protected]> wrote:

I've looked the code on the respective patches, look like most of the code copy from Linux by adding __UBOOT__. I have no issue with Linux copy but we need to structure the code according to U-Boot in the form of driver-model (this series lack with that).

Here are my suggestions, based the MTD work so-far

First we need to design MTD driver-model which can capable to drive one driver from each interface. (not converting all interface drivers at once, that is taking more time and other issues)

Like Linux MTD, U-Boot should have MTD dm for underlying flash devices like nand, parallel nor, spinor etc. So to drive this theory with driver model(with an example of block layer) mtd is common device interaction for most of memory technology flashes like nand, parallel nor, spinor etc, these are treated as interface types wrt u-boot driver model.

Quoted 8 lines

Once the respective interface driver bind happen, the uclass driver will pass an 'interface type' to mtd layer to create device for it, for example once spinor ULASS_SPI_NOR driver bind happen, the uclass driver of spinor will pass MTD_IF_TYPE_SPI_NOR
interface type to create mtd device for spinor devices.

So If we add this design to SPI-NAND changes, we need to implement
- MTD dm core that can driver all interfaces

That's already what the MTD framework provides, and Miquel even added some stuff to integrate the MTD layer even further in the DM. It's probably not perfect yet, but the changes are, IMHO, going in the right direction.

Now, if you're talking about the new MTD API that creates helper functions prefixed with dm_, sorry, but I don't see the point. We already have plenty of MTD users in u-boot, they all manipulate MTD objects and go through the standard MTD API to do that. What you suggest would make things messier for several reasons:

1/ we won't be able to easily port Linux code to u-boot. Look at the
JFFS2 UBI support. They all use mtd_info objects. What's the point of changing that except making things harder to port.

2/ Not all MTD providers will be converted to the device model at once,
so how do you plan to deal with that?

3/ What's the benefit of exposing yet another way to manipulate MTD
devices?

Quoted 1 line

- one driver for raw nand

Unfortunately, that's not how it works right now, and clearly, we don't have time to work on this raw NAND rework right now.

Quoted 1 line

- one driver for spinand

I think that's already the case.

Quoted 1 line

- spi-mem

Quoted 7 lines

It's also what Miquel is doing in this series.

Quoted 1 line

- convert fsl-qspi to spi-mem

We're not targeting the fsl-qspi controller here but a simple SPI controller that is already upstreamed. But yes, the fsl-qspi driver will have to be patched to support the spi-mem interface at some point.

Can you point me that simple spi-mem controller driver?

Quoted 27 lines
Quoted 2 lines

- implement command to handle

This I don't get. What do you mean by "implement command to handle"? Are we talking about cmd/mtd.c? I think the work Miquel has done is already a good start, what's missing in there?

Quoted 9 lines

For spi-nor interface design, we have an example code here[2]

I've paused this [2] series because of dm conversion of spi-drivers otherwise I need add legacy code like mmc-legacy.c, so if we really move to spi-mem design and okay with above design. I will try to move the current spi flash to add MTD driver-model so-that we can add spi-mem, spi-nand on top of it or we can work together to convert them all.

Why can't we do things iteratively. I mean, if the long term goal is to convert everything to the driver model, then this patchset is going in the right direction:
- addition of DM helpers to the MTD_UCLASS
- addition of the spi-mem interface properly integrated in the DM model of the SPI framework
- addition of a SPI NAND driver, again properly integrated in the DM
- integration of DM-ready MTD drivers and old MTD drivers in a single view exposed by the cmd/mtd.c command set

Quoted 7 lines

I'd really like to limit the scope of this development to these topics, which doesn't prevent you from converting other part of u-boot to the spi-mem approach (SPI NOR is one example).

I hope you understand our concerns and the fact that what you're asking us to do as a dependency of getting SPI NAND support + cmd/mtd.c merged is way more than we can actually provide.

To answer all these questions, I think we need to decide whether we go for MTD dm abstraction or existing MTD layer.

When I say MTD dm abstraction, all mtd operation prototypes are in the form of udevice unlike existing MTD has mtd_info. when I initially supporting spi-nor (during Linux early spi-nor) I've reused existing MTD and written something like what Miquel did using mtd_info ops [3]. but then developers on ML, proposed the new drivers should be form of driver-model abstraction, so I've added mtd driver model ops [4].

I understand the new MTD dm abstraction in U-Boot is not possible for direct syncing from Linux, but we really want the u-boot way of handling drivers and trying to copy code from Linux by removing __UBOOT__ or any Linux specific macros. Since this is pretty much big task, ie the reason I'm asking for single driver from each MTD device so-that once the clear stack is ready other drivers can convert one-by-one.

[3] http://git.denx.de/?p=u-boot-spi.git;a=commitdiff;h=d297949cd3f44278f109dff42fb88a879722121c
[4] https://patchwork.ozlabs.org/patch/853337/

Signature · 4 lines
Jagan Teki
Senior Linux Kernel Engineer | Amarula Solutions
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.
#51 lore raw

cover SPI-NAND support

Quoted 7 lines · On Mon, 25 Jun 2018 19:58:37 +0530 Jagan Teki <[email protected]>…
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

- convert fsl-qspi to spi-mem

We're not targeting the fsl-qspi controller here but a simple SPI controller that is already upstreamed. But yes, the fsl-qspi driver will have to be patched to support the spi-mem interface at some point.

Can you point me that simple spi-mem controller driver?

It's not a controller that implements spi-mem operations but a simple SPI controller (one that knows how to do regular SPI transfers and nothing more). But the spi-mem layer knows how to send spi_mem_op using regular transfer and that's why it works without any modification at the driver level.

Quoted 38 lines
Quoted 38 lines
Quoted 20 lines
Quoted 9 lines

For spi-nor interface design, we have an example code here[2]

I've paused this [2] series because of dm conversion of spi-drivers otherwise I need add legacy code like mmc-legacy.c, so if we really move to spi-mem design and okay with above design. I will try to move the current spi flash to add MTD driver-model so-that we can add spi-mem, spi-nand on top of it or we can work together to convert them all.

Why can't we do things iteratively. I mean, if the long term goal is to convert everything to the driver model, then this patchset is going in the right direction:
- addition of DM helpers to the MTD_UCLASS
- addition of the spi-mem interface properly integrated in the DM model of the SPI framework
- addition of a SPI NAND driver, again properly integrated in the DM
- integration of DM-ready MTD drivers and old MTD drivers in a single view exposed by the cmd/mtd.c command set

Quoted 7 lines

I'd really like to limit the scope of this development to these topics, which doesn't prevent you from converting other part of u-boot to the spi-mem approach (SPI NOR is one example).

I hope you understand our concerns and the fact that what you're asking us to do as a dependency of getting SPI NAND support + cmd/mtd.c merged is way more than we can actually provide.

To answer all these questions, I think we need to decide whether we go for MTD dm abstraction or existing MTD layer.

When I say MTD dm abstraction, all mtd operation prototypes are in the form of udevice unlike existing MTD has mtd_info. when I initially supporting spi-nor (during Linux early spi-nor) I've reused existing MTD and written something like what Miquel did using mtd_info ops [3]. but then developers on ML, proposed the new drivers should be form of driver-model abstraction, so I've added mtd driver model ops [4].

Quoted 7 lines
Quoted 7 lines

I understand the new MTD dm abstraction in U-Boot is not possible for direct syncing from Linux, but we really want the u-boot way of handling drivers and trying to copy code from Linux by removing __UBOOT__ or any Linux specific macros. Since this is pretty much big task, ie the reason I'm asking for single driver from each MTD device so-that once the clear stack is ready other drivers can convert one-by-one.

I think I have to repeat my previous statement here. It would be very unfortunate if u-boot decides to take this direction (see Richard's reply), especially since I see absolutely no benefit in doing what you suggest. Having MTD devices registered to the uboot DM is something I can understand, deciding to no longer support the standard MTD API is something I don't.

#52 lore raw

cover SPI-NAND support

Quoted 64 lines · Boris Brezillon
Quoted 7 lines · On Mon, 25 Jun 2018 19:58:37 +0530 Jagan Teki <[email protected]>…
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

- convert fsl-qspi to spi-mem

We're not targeting the fsl-qspi controller here but a simple SPI controller that is already upstreamed. But yes, the fsl-qspi driver will have to be patched to support the spi-mem interface at some point.

Can you point me that simple spi-mem controller driver?

It's not a controller that implements spi-mem operations but a simple SPI controller (one that knows how to do regular SPI transfers and nothing more). But the spi-mem layer knows how to send spi_mem_op using regular transfer and that's why it works without any modification at the driver level.

Quoted 38 lines
Quoted 38 lines
Quoted 20 lines
Quoted 9 lines

For spi-nor interface design, we have an example code here[2]

I've paused this [2] series because of dm conversion of spi-drivers otherwise I need add legacy code like mmc-legacy.c, so if we really move to spi-mem design and okay with above design. I will try to move the current spi flash to add MTD driver-model so-that we can add spi-mem, spi-nand on top of it or we can work together to convert them all.

Why can't we do things iteratively. I mean, if the long term goal is to convert everything to the driver model, then this patchset is going in the right direction:
- addition of DM helpers to the MTD_UCLASS
- addition of the spi-mem interface properly integrated in the DM model of the SPI framework
- addition of a SPI NAND driver, again properly integrated in the DM
- integration of DM-ready MTD drivers and old MTD drivers in a single view exposed by the cmd/mtd.c command set

Quoted 7 lines

I'd really like to limit the scope of this development to these topics, which doesn't prevent you from converting other part of u-boot to the spi-mem approach (SPI NOR is one example).

I hope you understand our concerns and the fact that what you're asking us to do as a dependency of getting SPI NAND support + cmd/mtd.c merged is way more than we can actually provide.

To answer all these questions, I think we need to decide whether we go for MTD dm abstraction or existing MTD layer.

When I say MTD dm abstraction, all mtd operation prototypes are in the form of udevice unlike existing MTD has mtd_info. when I initially supporting spi-nor (during Linux early spi-nor) I've reused existing MTD and written something like what Miquel did using mtd_info ops [3]. but then developers on ML, proposed the new drivers should be form of driver-model abstraction, so I've added mtd driver model ops [4].

Quoted 7 lines
Quoted 7 lines

I understand the new MTD dm abstraction in U-Boot is not possible for direct syncing from Linux, but we really want the u-boot way of handling drivers and trying to copy code from Linux by removing __UBOOT__ or any Linux specific macros. Since this is pretty much big task, ie the reason I'm asking for single driver from each MTD device so-that once the clear stack is ready other drivers can convert one-by-one.

Quoted 6 lines

I think I have to repeat my previous statement here. It would be very unfortunate if u-boot decides to take this direction (see Richard's reply), especially since I see absolutely no benefit in doing what you suggest. Having MTD devices registered to the uboot DM is something I can understand, deciding to no longer support the standard MTD API is something I don't.

I agree. We want U-Boot to be able to leverage as much as possible from the Linux kernel with as little re-working as possible.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180625/aa2bbc35/attachment.sig>
#53 lore raw

cover SPI-NAND support

Quoted 72 lines · Tom Rini
Quoted 64 lines · Boris Brezillon
Quoted 7 lines · On Mon, 25 Jun 2018 19:58:37 +0530 Jagan Teki <[email protected]>…
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

- convert fsl-qspi to spi-mem

We're not targeting the fsl-qspi controller here but a simple SPI controller that is already upstreamed. But yes, the fsl-qspi driver will have to be patched to support the spi-mem interface at some point.

Can you point me that simple spi-mem controller driver?

It's not a controller that implements spi-mem operations but a simple SPI controller (one that knows how to do regular SPI transfers and nothing more). But the spi-mem layer knows how to send spi_mem_op using regular transfer and that's why it works without any modification at the driver level.

Quoted 38 lines
Quoted 38 lines
Quoted 20 lines
Quoted 9 lines

For spi-nor interface design, we have an example code here[2]

I've paused this [2] series because of dm conversion of spi-drivers otherwise I need add legacy code like mmc-legacy.c, so if we really move to spi-mem design and okay with above design. I will try to move the current spi flash to add MTD driver-model so-that we can add spi-mem, spi-nand on top of it or we can work together to convert them all.

Why can't we do things iteratively. I mean, if the long term goal is to convert everything to the driver model, then this patchset is going in the right direction:
- addition of DM helpers to the MTD_UCLASS
- addition of the spi-mem interface properly integrated in the DM model of the SPI framework
- addition of a SPI NAND driver, again properly integrated in the DM
- integration of DM-ready MTD drivers and old MTD drivers in a single view exposed by the cmd/mtd.c command set

Quoted 7 lines

I'd really like to limit the scope of this development to these topics, which doesn't prevent you from converting other part of u-boot to the spi-mem approach (SPI NOR is one example).

I hope you understand our concerns and the fact that what you're asking us to do as a dependency of getting SPI NAND support + cmd/mtd.c merged is way more than we can actually provide.

To answer all these questions, I think we need to decide whether we go for MTD dm abstraction or existing MTD layer.

When I say MTD dm abstraction, all mtd operation prototypes are in the form of udevice unlike existing MTD has mtd_info. when I initially supporting spi-nor (during Linux early spi-nor) I've reused existing MTD and written something like what Miquel did using mtd_info ops [3]. but then developers on ML, proposed the new drivers should be form of driver-model abstraction, so I've added mtd driver model ops [4].

Quoted 7 lines
Quoted 7 lines

I understand the new MTD dm abstraction in U-Boot is not possible for direct syncing from Linux, but we really want the u-boot way of handling drivers and trying to copy code from Linux by removing __UBOOT__ or any Linux specific macros. Since this is pretty much big task, ie the reason I'm asking for single driver from each MTD device so-that once the clear stack is ready other drivers can convert one-by-one.

Quoted 6 lines

I think I have to repeat my previous statement here. It would be very unfortunate if u-boot decides to take this direction (see Richard's reply), especially since I see absolutely no benefit in doing what you suggest. Having MTD devices registered to the uboot DM is something I can understand, deciding to no longer support the standard MTD API is something I don't.

Quoted 2 lines

I agree. We want U-Boot to be able to leverage as much as possible from the Linux kernel with as little re-working as possible.

I wholeheartedly agree on this.

Thanks,
Stefan

#54 lore raw

cover SPI-NAND support

In reply to Tom Rini
Quoted 72 lines · Tom Rini
Quoted 64 lines · Boris Brezillon
Quoted 7 lines · On Mon, 25 Jun 2018 19:58:37 +0530 Jagan Teki <[email protected]>…
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

- convert fsl-qspi to spi-mem

We're not targeting the fsl-qspi controller here but a simple SPI controller that is already upstreamed. But yes, the fsl-qspi driver will have to be patched to support the spi-mem interface at some point.

Can you point me that simple spi-mem controller driver?

It's not a controller that implements spi-mem operations but a simple SPI controller (one that knows how to do regular SPI transfers and nothing more). But the spi-mem layer knows how to send spi_mem_op using regular transfer and that's why it works without any modification at the driver level.

Quoted 38 lines
Quoted 38 lines
Quoted 20 lines
Quoted 9 lines

For spi-nor interface design, we have an example code here[2]

I've paused this [2] series because of dm conversion of spi-drivers otherwise I need add legacy code like mmc-legacy.c, so if we really move to spi-mem design and okay with above design. I will try to move the current spi flash to add MTD driver-model so-that we can add spi-mem, spi-nand on top of it or we can work together to convert them all.

Why can't we do things iteratively. I mean, if the long term goal is to convert everything to the driver model, then this patchset is going in the right direction:
- addition of DM helpers to the MTD_UCLASS
- addition of the spi-mem interface properly integrated in the DM model of the SPI framework
- addition of a SPI NAND driver, again properly integrated in the DM
- integration of DM-ready MTD drivers and old MTD drivers in a single view exposed by the cmd/mtd.c command set

Quoted 7 lines

I'd really like to limit the scope of this development to these topics, which doesn't prevent you from converting other part of u-boot to the spi-mem approach (SPI NOR is one example).

I hope you understand our concerns and the fact that what you're asking us to do as a dependency of getting SPI NAND support + cmd/mtd.c merged is way more than we can actually provide.

To answer all these questions, I think we need to decide whether we go for MTD dm abstraction or existing MTD layer.

When I say MTD dm abstraction, all mtd operation prototypes are in the form of udevice unlike existing MTD has mtd_info. when I initially supporting spi-nor (during Linux early spi-nor) I've reused existing MTD and written something like what Miquel did using mtd_info ops [3]. but then developers on ML, proposed the new drivers should be form of driver-model abstraction, so I've added mtd driver model ops [4].

Quoted 7 lines
Quoted 7 lines

I understand the new MTD dm abstraction in U-Boot is not possible for direct syncing from Linux, but we really want the u-boot way of handling drivers and trying to copy code from Linux by removing __UBOOT__ or any Linux specific macros. Since this is pretty much big task, ie the reason I'm asking for single driver from each MTD device so-that once the clear stack is ready other drivers can convert one-by-one.

Quoted 6 lines

I think I have to repeat my previous statement here. It would be very unfortunate if u-boot decides to take this direction (see Richard's reply), especially since I see absolutely no benefit in doing what you suggest. Having MTD devices registered to the uboot DM is something I can understand, deciding to no longer support the standard MTD API is something I don't.

Quoted 2 lines

I agree. We want U-Boot to be able to leverage as much as possible from the Linux kernel with as little re-working as possible.

I'm not denying that, but the basic design flow must follow u-boot driver model. this is what everyone told from the beginning when I started spi-nor work. Initially I did the design like this and leverage with existing MTD, everyone NAK and suggested to use driver-model on each stage with MTD dm abstraction.
So
- After 2 years of work
- With nearly 10 versions [4]
- Adding MIGRATION expire date for spi drivers dm conversion
- Simon Reviewed-by and
- Planning to apply after v2018.09.

but now all want the existing MTD, I don't understand what I can do further on this?

[4] https://patchwork.ozlabs.org/user/todo/uboot/?series=20450

#55 lore raw

cover SPI-NAND support

Quoted 22 lines · On Tue, 26 Jun 2018 00:07:10 +0530 Jagan Teki <[email protected]>…
Quoted 9 lines
Quoted 6 lines

I think I have to repeat my previous statement here. It would be very unfortunate if u-boot decides to take this direction (see Richard's reply), especially since I see absolutely no benefit in doing what you suggest. Having MTD devices registered to the uboot DM is something I can understand, deciding to no longer support the standard MTD API is something I don't.

I agree. We want U-Boot to be able to leverage as much as possible from the Linux kernel with as little re-working as possible.

I'm not denying that, but the basic design flow must follow u-boot driver model. this is what everyone told from the beginning when I started spi-nor work. Initially I did the design like this and leverage with existing MTD, everyone NAK and suggested to use driver-model on each stage with MTD dm abstraction.
So
- After 2 years of work
- With nearly 10 versions [4]
- Adding MIGRATION expire date for spi drivers dm conversion
- Simon Reviewed-by and
- Planning to apply after v2018.09.

Quoted 2 lines

but now all want the existing MTD, I don't understand what I can do further on this?

I didn't follow the initial discussion, but I can understand your frustration. Still, I think there's a misunderstanding here. I recommend that you have a second look at the different patches in this series. You'll see that everything Miquel did complies with the DM, and that the thing you're complaining about (MTD API not using udevice and not prefixed with dm_) is just a tiny detail compared to the rest.

Keeping the MTD API is not incompatible with the conversion of all MTD provider drivers to the DM. I think we all agree on that MTD providers should be converted to the DM progressively, and the work Miquel did allows such a smooth transition because both non-DM drivers and DM-compliant drivers can co-exist without impacting MTD users.

Sorry to say that, but your approach based on full-conversion is just an utopia. There's no way we can do that in a single step.

So the question here is more, should we block all developments until we have a perfect solution (I don't think perfection can be achieved without trying things and making mistake), or should we move forward, one step after the other and keep the "conversion of all MTD drivers to the DM" as a long term goal?

#56 lore raw

cover SPI-NAND support

Quoted 41 lines · Boris Brezillon
Quoted 22 lines · On Tue, 26 Jun 2018 00:07:10 +0530 Jagan Teki <[email protected]>…
Quoted 9 lines
Quoted 6 lines

I think I have to repeat my previous statement here. It would be very unfortunate if u-boot decides to take this direction (see Richard's reply), especially since I see absolutely no benefit in doing what you suggest. Having MTD devices registered to the uboot DM is something I can understand, deciding to no longer support the standard MTD API is something I don't.

I agree. We want U-Boot to be able to leverage as much as possible from the Linux kernel with as little re-working as possible.

I'm not denying that, but the basic design flow must follow u-boot driver model. this is what everyone told from the beginning when I started spi-nor work. Initially I did the design like this and leverage with existing MTD, everyone NAK and suggested to use driver-model on each stage with MTD dm abstraction.
So
- After 2 years of work
- With nearly 10 versions [4]
- Adding MIGRATION expire date for spi drivers dm conversion
- Simon Reviewed-by and
- Planning to apply after v2018.09.

Quoted 2 lines

but now all want the existing MTD, I don't understand what I can do further on this?

I didn't follow the initial discussion, but I can understand your frustration. Still, I think there's a misunderstanding here. I recommend that you have a second look at the different patches in this series. You'll see that everything Miquel did complies with the DM, and that the thing you're complaining about (MTD API not using udevice and not prefixed with dm_) is just a tiny detail compared to the rest.

Keeping the MTD API is not incompatible with the conversion of all MTD provider drivers to the DM. I think we all agree on that MTD providers should be converted to the DM progressively, and the work Miquel did allows such a smooth transition because both non-DM drivers and DM-compliant drivers can co-exist without impacting MTD users.

Quoted 8 lines

Sorry to say that, but your approach based on full-conversion is just an utopia. There's no way we can do that in a single step.

So the question here is more, should we block all developments until we have a perfect solution (I don't think perfection can be achieved without trying things and making mistake), or should we move forward, one step after the other and keep the "conversion of all MTD drivers to the DM" as a long term goal?

And furthermore, we _really_ need to get this area un-blocked. I feel bad that Jagan's series went on for so long, but I think it also highlights the problem with a convert-everything-at-once-try-and-be-perfect approach.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180625/58f2d972/attachment.sig>
#57 lore raw

cover SPI-NAND support

In reply to Boris Brezillon
Quoted 41 lines · Boris Brezillon
Quoted 22 lines · On Tue, 26 Jun 2018 00:07:10 +0530 Jagan Teki <[email protected]>…
Quoted 9 lines
Quoted 6 lines

I think I have to repeat my previous statement here. It would be very unfortunate if u-boot decides to take this direction (see Richard's reply), especially since I see absolutely no benefit in doing what you suggest. Having MTD devices registered to the uboot DM is something I can understand, deciding to no longer support the standard MTD API is something I don't.

I agree. We want U-Boot to be able to leverage as much as possible from the Linux kernel with as little re-working as possible.

I'm not denying that, but the basic design flow must follow u-boot driver model. this is what everyone told from the beginning when I started spi-nor work. Initially I did the design like this and leverage with existing MTD, everyone NAK and suggested to use driver-model on each stage with MTD dm abstraction.
So
- After 2 years of work
- With nearly 10 versions [4]
- Adding MIGRATION expire date for spi drivers dm conversion
- Simon Reviewed-by and
- Planning to apply after v2018.09.

Quoted 2 lines

but now all want the existing MTD, I don't understand what I can do further on this?

I didn't follow the initial discussion, but I can understand your frustration. Still, I think there's a misunderstanding here. I recommend that you have a second look at the different patches in this series. You'll see that everything Miquel did complies with the DM, and that the thing you're complaining about (MTD API not using udevice and not prefixed with dm_) is just a tiny detail compared to the rest.

Keeping the MTD API is not incompatible with the conversion of all MTD provider drivers to the DM. I think we all agree on that MTD providers should be converted to the DM progressively, and the work Miquel did allows such a smooth transition because both non-DM drivers and DM-compliant drivers can co-exist without impacting MTD users.

Quoted 8 lines

Sorry to say that, but your approach based on full-conversion is just an utopia. There's no way we can do that in a single step.

So the question here is more, should we block all developments until we have a perfect solution (I don't think perfection can be achieved without trying things and making mistake), or should we move forward, one step after the other and keep the "conversion of all MTD drivers to the DM" as a long term goal?

Thanks for explaining all these Boris.

I agree on the context of "not to block the development" for the sake of new improvement solution. Yes I will start reviewing these stuff, even thought these are not compatible with MTD DM providers. Mean while I will keep moving spi-nor development with MTD DM providers along with Linux changes and it should be a starting point for full DM conversion for MTD layer.

Jagan.

Signature · 4 lines
Jagan Teki
Senior Linux Kernel Engineer | Amarula Solutions
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.
#58 lore raw

cover SPI-NAND support

In reply to Jagan Teki

Am Montag, 25. Juni 2018, 16:27:45 CEST schrieb Jagan Teki:

Quoted 7 lines

I understand the new MTD dm abstraction in U-Boot is not possible for direct syncing from Linux, but we really want the u-boot way of handling drivers and trying to copy code from Linux by removing __UBOOT__ or any Linux specific macros. Since this is pretty much big task, ie the reason I'm asking for single driver from each MTD device so-that once the clear stack is ready other drivers can convert one-by-one.

Do you have the man power to massage/backport all Linux changes/fixes to u-boot?

Thanks,
//richard

#59 lore raw

cover SPI-NAND support

In reply to Miquel Raynal

Hi Miquèl,

Quoted 11 lines · Miquel Raynal

During the last months, Boris Brezillon shared his work to support serial flashes within Linux. First, he delivered (and merged) a new layer called spi-mem. He also initiated in Linux MTD subsystem the move of all 'raw' NAND related code to a raw/ subdirectory, adding at the same time a NAND core that would be shared with all NAND devices. Then, he contributed a generic SPI-NAND driver, making use of this NAND core, as well as some vendor code to drive a few chips.

On top of this work, I added an 'mtd' U-Boot command to handle all sort of MTD devices. This should become the default command instead of having one per flash flavor ('sf', 'nand', 'spi-nand' ?).

Interesting. I like this idea.

BTW: I also would like to see the ubifs commands being supported by the common file commands, like "ls" and "load". But this just came to my mind right now (again) and definitely has nothing to do with your current work on SPI NAND.

Quoted 11 lines

The series has been tested on an Ocelot board PCB123 (VSC7514), featuring a Macronix SPI NAND chip.

TL;DR: the series contains:
- Various fixes and re-organization of the MTD subsystem.
- The introduction of the SPI-mem interface.
- The addition of the generic SPI-NAND driver (and its bindings).
- Several SPI NAND chip drivers (Macronix, Micron, Winbond).
- A new 'mtd' command.
- DT changes to make use of a SPI NAND on the Ocelot board.

Quoted 2 lines

Any comments on the code, the organization and the respect of U-Boot driver model will be welcome.

Many thanks for working on this. I might get access to a new platform in a few days, requiring SPI NAND support. So I tried to apply your patches on top of current mainline, which unfortunately fails with some patches.

Would it be possible for you to rebase your patches on top of current mainline U-Boot? Best would be to also push a git branch with your patches / changes. This way you don't need to re-send all those patches to the list, without any real changes done.

Thanks,
Stefan

author maintainer
#60 lore raw

cover SPI-NAND support

Hi Stefan,

Quoted 30 lines · Stefan Roese

Hi Miquèl,

Quoted 10 lines · Miquel Raynal

During the last months, Boris Brezillon shared his work to support serial flashes within Linux. First, he delivered (and merged) a new layer called spi-mem. He also initiated in Linux MTD subsystem the move of all 'raw' NAND related code to a raw/ subdirectory, adding at the same time a NAND core that would be shared with all NAND devices. Then, he contributed a generic SPI-NAND driver, making use of this NAND core, as well as some vendor code to drive a few chips.

Quoted 1 line

On top of this work, I added an 'mtd' U-Boot command to handle all sort

of MTD devices. This should become the default command instead of having one per flash flavor ('sf', 'nand', 'spi-nand' ?).

Interesting. I like this idea.

BTW: I also would like to see the ubifs commands being supported by the common file commands, like "ls" and "load". But this just came to my mind right now (again) and definitely has nothing to do with your current work on SPI NAND.

Quoted 9 lines

The series has been tested on an Ocelot board PCB123 (VSC7514), featuring a Macronix SPI NAND chip.

Quoted 1 line

TL;DR: the series contains:

- Various fixes and re-organization of the MTD subsystem.
- The introduction of the SPI-mem interface.
- The addition of the generic SPI-NAND driver (and its bindings).
- Several SPI NAND chip drivers (Macronix, Micron, Winbond).
- A new 'mtd' command.
- DT changes to make use of a SPI NAND on the Ocelot board.

Quoted 5 lines
Quoted 2 lines
Quoted 1 line

Any comments on the code, the organization and the respect of U-Boot

driver model will be welcome.

Many thanks for working on this. I might get access to a new platform in a few days, requiring SPI NAND support. So I tried to

Thanks, testing will be appreciated!

Quoted 8 lines

apply your patches on top of current mainline, which unfortunately fails with some patches.

Would it be possible for you to rebase your patches on top of current mainline U-Boot? Best would be to also push a git branch with your patches / changes. This way you don't need to re-send all those patches to the list, without any real changes done.

Mmmh. Sorry for that. Please have a look at this branch, the work is based on top of v2018.03:

https://github.com/miquelraynal/u-boot/commits/public/spi-nand

Quoted 3 lines

Thanks,
Stefan

Thanks,
Miquèl

#61 lore raw

cover SPI-NAND support

In reply to Miquel Raynal
Quoted 56 lines · Miquel Raynal

During the last months, Boris Brezillon shared his work to support serial flashes within Linux. First, he delivered (and merged) a new layer called spi-mem. He also initiated in Linux MTD subsystem the move of all 'raw' NAND related code to a raw/ subdirectory, adding at the same time a NAND core that would be shared with all NAND devices. Then, he contributed a generic SPI-NAND driver, making use of this NAND core, as well as some vendor code to drive a few chips.

On top of this work, I added an 'mtd' U-Boot command to handle all sort of MTD devices. This should become the default command instead of having one per flash flavor ('sf', 'nand', 'spi-nand' ?).

The series has been tested on an Ocelot board PCB123 (VSC7514), featuring a Macronix SPI NAND chip.

TL;DR: the series contains:
- Various fixes and re-organization of the MTD subsystem.
- The introduction of the SPI-mem interface.
- The addition of the generic SPI-NAND driver (and its bindings).
- Several SPI NAND chip drivers (Macronix, Micron, Winbond).
- A new 'mtd' command.
- DT changes to make use of a SPI NAND on the Ocelot board.

Any comments on the code, the organization and the respect of U-Boot driver model will be welcome.

Thanks,
Miquèl

Boris Brezillon (6):
mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing
mtd: nand: Add core infrastructure to deal with NAND devices
mtd: nand: Pass mode information to nand_page_io_req
spi: Extend the core to ease integration of SPI memory controllers
mtd: spinand: Add initial support for the MX35LF1GE4AB chip
dt-bindings: Add bindings for SPI NAND devices

Brian Norris (1):
mtd: add get/set of_node/flash_node helpers

Frieder Schrempf (1):
mtd: spinand: Add initial support for Winbond W25M02GV

Miquel Raynal (10):
mtd: fix build issue with includes
mtd: move definitions to enlarge their range
mtd: move all flash categories inside MTD submenu
mtd: move NAND fiels into a raw/ subdirectory
mtd: rename nand into rawnand in Kconfig prompt
mtd: spinand: Add initial support for the MX35LF2GE4AB chip
mtd: uclass: add probe function
cmd: mtd: add 'mtd' command
mips: dts: ocelot: describe SPI CS pins
mips: dts: ocelot: add the SPI NAND node

Quoted 3 lines

Peter Pan (2):
mtd: nand: Add core infrastructure to support SPI NANDs
mtd: spinand: Add initial support for Micron MT29F2G01ABAGD

I have reviewed and commented most of the stuff that are in my control, except few spi-nand code, which I would like to give a try to other people in the list. Hope to seen the fine-tuning patches on next version.

Jagan.

author maintainer
#62 lore raw

cover SPI-NAND support

Hi Jagan,

Jagan Teki <[email protected]> wrote on Fri, 6 Jul 2018 17:13:21 +0530:

Quoted 57 lines · Miquel Raynal
Quoted 56 lines

During the last months, Boris Brezillon shared his work to support serial flashes within Linux. First, he delivered (and merged) a new layer called spi-mem. He also initiated in Linux MTD subsystem the move of all 'raw' NAND related code to a raw/ subdirectory, adding at the same time a NAND core that would be shared with all NAND devices. Then, he contributed a generic SPI-NAND driver, making use of this NAND core, as well as some vendor code to drive a few chips.

On top of this work, I added an 'mtd' U-Boot command to handle all sort of MTD devices. This should become the default command instead of having one per flash flavor ('sf', 'nand', 'spi-nand' ?).

The series has been tested on an Ocelot board PCB123 (VSC7514), featuring a Macronix SPI NAND chip.

TL;DR: the series contains:
- Various fixes and re-organization of the MTD subsystem.
- The introduction of the SPI-mem interface.
- The addition of the generic SPI-NAND driver (and its bindings).
- Several SPI NAND chip drivers (Macronix, Micron, Winbond).
- A new 'mtd' command.
- DT changes to make use of a SPI NAND on the Ocelot board.

Any comments on the code, the organization and the respect of U-Boot driver model will be welcome.

Thanks,
Miquèl

Boris Brezillon (6):
mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing
mtd: nand: Add core infrastructure to deal with NAND devices
mtd: nand: Pass mode information to nand_page_io_req
spi: Extend the core to ease integration of SPI memory controllers
mtd: spinand: Add initial support for the MX35LF1GE4AB chip
dt-bindings: Add bindings for SPI NAND devices

Brian Norris (1):
mtd: add get/set of_node/flash_node helpers

Frieder Schrempf (1):
mtd: spinand: Add initial support for Winbond W25M02GV

Miquel Raynal (10):
mtd: fix build issue with includes
mtd: move definitions to enlarge their range
mtd: move all flash categories inside MTD submenu
mtd: move NAND fiels into a raw/ subdirectory
mtd: rename nand into rawnand in Kconfig prompt
mtd: spinand: Add initial support for the MX35LF2GE4AB chip
mtd: uclass: add probe function
cmd: mtd: add 'mtd' command
mips: dts: ocelot: describe SPI CS pins
mips: dts: ocelot: add the SPI NAND node

Quoted 8 lines
Quoted 3 lines

Peter Pan (2):
mtd: nand: Add core infrastructure to support SPI NANDs
mtd: spinand: Add initial support for Micron MT29F2G01ABAGD

I have reviewed and commented most of the stuff that are in my control, except few spi-nand code, which I would like to give a try to other people in the list. Hope to seen the fine-tuning patches on next version.

Thanks for taking the time to review all this; I'm on it.

About spi-nand, reviews from other contributors are welcome, but it's mostly a copy from Linux framework that I just applied to nand/next. There have been 9 versions of it before that so I think it's pretty well reviewed.

Thanks,
Miquèl

#63 lore raw

cover SPI-NAND support

Quoted 71 lines · Miquel Raynal

Hi Jagan,

Jagan Teki <[email protected]> wrote on Fri, 6 Jul 2018 17:13:21 +0530:

Quoted 57 lines · Miquel Raynal
Quoted 56 lines

During the last months, Boris Brezillon shared his work to support serial flashes within Linux. First, he delivered (and merged) a new layer called spi-mem. He also initiated in Linux MTD subsystem the move of all 'raw' NAND related code to a raw/ subdirectory, adding at the same time a NAND core that would be shared with all NAND devices. Then, he contributed a generic SPI-NAND driver, making use of this NAND core, as well as some vendor code to drive a few chips.

On top of this work, I added an 'mtd' U-Boot command to handle all sort of MTD devices. This should become the default command instead of having one per flash flavor ('sf', 'nand', 'spi-nand' ?).

The series has been tested on an Ocelot board PCB123 (VSC7514), featuring a Macronix SPI NAND chip.

TL;DR: the series contains:
- Various fixes and re-organization of the MTD subsystem.
- The introduction of the SPI-mem interface.
- The addition of the generic SPI-NAND driver (and its bindings).
- Several SPI NAND chip drivers (Macronix, Micron, Winbond).
- A new 'mtd' command.
- DT changes to make use of a SPI NAND on the Ocelot board.

Any comments on the code, the organization and the respect of U-Boot driver model will be welcome.

Thanks,
Miquèl

Boris Brezillon (6):
mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing
mtd: nand: Add core infrastructure to deal with NAND devices
mtd: nand: Pass mode information to nand_page_io_req
spi: Extend the core to ease integration of SPI memory controllers
mtd: spinand: Add initial support for the MX35LF1GE4AB chip
dt-bindings: Add bindings for SPI NAND devices

Brian Norris (1):
mtd: add get/set of_node/flash_node helpers

Frieder Schrempf (1):
mtd: spinand: Add initial support for Winbond W25M02GV

Miquel Raynal (10):
mtd: fix build issue with includes
mtd: move definitions to enlarge their range
mtd: move all flash categories inside MTD submenu
mtd: move NAND fiels into a raw/ subdirectory
mtd: rename nand into rawnand in Kconfig prompt
mtd: spinand: Add initial support for the MX35LF2GE4AB chip
mtd: uclass: add probe function
cmd: mtd: add 'mtd' command
mips: dts: ocelot: describe SPI CS pins
mips: dts: ocelot: add the SPI NAND node

Quoted 8 lines
Quoted 3 lines

Peter Pan (2):
mtd: nand: Add core infrastructure to support SPI NANDs
mtd: spinand: Add initial support for Micron MT29F2G01ABAGD

I have reviewed and commented most of the stuff that are in my control, except few spi-nand code, which I would like to give a try to other people in the list. Hope to seen the fine-tuning patches on next version.

Quoted 6 lines

Thanks for taking the time to review all this; I'm on it.

About spi-nand, reviews from other contributors are welcome, but it's mostly a copy from Linux framework that I just applied to nand/next. There have been 9 versions of it before that so I think it's pretty well reviewed.

OK, that's fine then.

#64 lore raw

cover SPI-NAND support

Quoted 72 lines · Jagan Teki
Quoted 71 lines · Miquel Raynal

Hi Jagan,

Jagan Teki <[email protected]> wrote on Fri, 6 Jul 2018 17:13:21 +0530:

Quoted 65 lines · Miquel Raynal
Quoted 56 lines

During the last months, Boris Brezillon shared his work to support serial flashes within Linux. First, he delivered (and merged) a new layer called spi-mem. He also initiated in Linux MTD subsystem the move of all 'raw' NAND related code to a raw/ subdirectory, adding at the same time a NAND core that would be shared with all NAND devices. Then, he contributed a generic SPI-NAND driver, making use of this NAND core, as well as some vendor code to drive a few chips.

On top of this work, I added an 'mtd' U-Boot command to handle all sort of MTD devices. This should become the default command instead of having one per flash flavor ('sf', 'nand', 'spi-nand' ?).

The series has been tested on an Ocelot board PCB123 (VSC7514), featuring a Macronix SPI NAND chip.

TL;DR: the series contains:
- Various fixes and re-organization of the MTD subsystem.
- The introduction of the SPI-mem interface.
- The addition of the generic SPI-NAND driver (and its bindings).
- Several SPI NAND chip drivers (Macronix, Micron, Winbond).
- A new 'mtd' command.
- DT changes to make use of a SPI NAND on the Ocelot board.

Any comments on the code, the organization and the respect of U-Boot driver model will be welcome.

Thanks,
Miquèl

Boris Brezillon (6):
mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing
mtd: nand: Add core infrastructure to deal with NAND devices
mtd: nand: Pass mode information to nand_page_io_req
spi: Extend the core to ease integration of SPI memory controllers
mtd: spinand: Add initial support for the MX35LF1GE4AB chip
dt-bindings: Add bindings for SPI NAND devices

Brian Norris (1):
mtd: add get/set of_node/flash_node helpers

Frieder Schrempf (1):
mtd: spinand: Add initial support for Winbond W25M02GV

Miquel Raynal (10):
mtd: fix build issue with includes
mtd: move definitions to enlarge their range
mtd: move all flash categories inside MTD submenu
mtd: move NAND fiels into a raw/ subdirectory
mtd: rename nand into rawnand in Kconfig prompt
mtd: spinand: Add initial support for the MX35LF2GE4AB chip
mtd: uclass: add probe function
cmd: mtd: add 'mtd' command
mips: dts: ocelot: describe SPI CS pins
mips: dts: ocelot: add the SPI NAND node

Quoted 3 lines

Peter Pan (2):
mtd: nand: Add core infrastructure to support SPI NANDs
mtd: spinand: Add initial support for Micron MT29F2G01ABAGD

I have reviewed and commented most of the stuff that are in my control, except few spi-nand code, which I would like to give a try to other people in the list. Hope to seen the fine-tuning patches on next version.

Quoted 8 lines
Quoted 6 lines

Thanks for taking the time to review all this; I'm on it.

About spi-nand, reviews from other contributors are welcome, but it's mostly a copy from Linux framework that I just applied to nand/next. There have been 9 versions of it before that so I think it's pretty well reviewed.

OK, that's fine then.

If everyone is agreeable I would like to see this in the v2018.09 release. Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180706/8daf333b/attachment.sig>