[U-Boot] [PATCH v6 19/31] dt-bindings: Add bindings for SPI NAND devices

2018-08-16 Thread Miquel Raynal
From: Boris Brezillon 

Add bindings for SPI NAND chips.

Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 doc/device-tree-bindings/mtd/spi-nand.txt | 5 +
 1 file changed, 5 insertions(+)
 create mode 100644 doc/device-tree-bindings/mtd/spi-nand.txt

diff --git a/doc/device-tree-bindings/mtd/spi-nand.txt 
b/doc/device-tree-bindings/mtd/spi-nand.txt
new file mode 100644
index 00..8b51f3b6d5
--- /dev/null
+++ b/doc/device-tree-bindings/mtd/spi-nand.txt
@@ -0,0 +1,5 @@
+SPI NAND flash
+
+Required properties:
+- compatible: should be "spi-nand"
+- reg: should encode the chip-select line used to access the NAND chip
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 21/31] mtd: mtdpart: balance debug messages

2018-08-16 Thread Miquel Raynal
Balance debug message in the partition allocation/removal process in
order to keep track of them more easily.

Signed-off-by: Miquel Raynal 
---
 drivers/mtd/mtdpart.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index ccbb1757ea..9ccb1b3361 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -362,6 +362,8 @@ int del_mtd_partitions(struct mtd_info *master)
struct mtd_part *slave, *next;
int ret, err = 0;
 
+   debug("Deleting MTD partitions on \"%s\":\n", master->name);
+
mutex_lock(_partitions_mutex);
list_for_each_entry_safe(slave, next, _partitions, list)
if (slave->master == master) {
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 23/31] cmd: mtdparts: add fallthrough in switch statement

2018-08-16 Thread Miquel Raynal
Switch blocks for deriving size naturally use fallthrough between
'case' statements. Make it explicit.

Signed-off-by: Miquel Raynal 
---
 cmd/mtdparts.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index 0da3afd75f..756fc6018f 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -177,13 +177,16 @@ static u64 memsize_parse (const char *const ptr, const 
char **retptr)
case 'G':
case 'g':
ret <<= 10;
+   /* Fallthrough */
case 'M':
case 'm':
ret <<= 10;
+   /* Fallthrough */
case 'K':
case 'k':
ret <<= 10;
(*retptr)++;
+   /* Fallthrough */
default:
break;
}
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 26/31] mtd: uclass: add probe function

2018-08-16 Thread 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.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 drivers/mtd/mtd-uclass.c | 9 +
 include/linux/mtd/mtd.h  | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/drivers/mtd/mtd-uclass.c b/drivers/mtd/mtd-uclass.c
index 9ca049c437..9a9470410c 100644
--- a/drivers/mtd/mtd-uclass.c
+++ b/drivers/mtd/mtd-uclass.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -13,6 +14,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",
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index b8c2c3fd59..755c785416 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -549,5 +549,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__ */
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 27/31] mtd: move mtdparts_init() declaration

2018-08-16 Thread Miquel Raynal
mtdparts_init() is called from various source files. It is declared in
include/jffs2/load_kernel.h while it has nothing to do with jffs2
anymore.

Move its declaration to include/linux/mtd/partitions.h which has way
more meaning.

Signed-off-by: Miquel Raynal 
---
 cmd/flash.c|  1 +
 cmd/jffs2.c|  1 +
 cmd/mtdparts.c | 35 +++---
 cmd/nand.c |  1 +
 common/fdt_support.c   |  1 +
 drivers/dfu/dfu_nand.c |  1 +
 drivers/fastboot/fb_nand.c |  1 +
 drivers/mtd/mtd_uboot.c|  1 +
 include/jffs2/load_kernel.h|  1 -
 include/linux/mtd/partitions.h |  3 +++
 10 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/cmd/flash.c b/cmd/flash.c
index cd1758d7e2..383c015b87 100644
--- a/cmd/flash.c
+++ b/cmd/flash.c
@@ -12,6 +12,7 @@
 
 #if defined(CONFIG_CMD_MTDPARTS)
 #include 
+#include 
 
 /* partition handling routines */
 int mtdparts_init(void);
diff --git a/cmd/jffs2.c b/cmd/jffs2.c
index 64621f2546..0ca2d30e2e 100644
--- a/cmd/jffs2.c
+++ b/cmd/jffs2.c
@@ -76,6 +76,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #if defined(CONFIG_CMD_NAND)
diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index 7fd9e5cbdb..33becb86e8 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -44,7 +44,7 @@
  *
  * 'mtdparts' - partition list
  *
- * mtdparts=mtdparts=[;...]
+ * mtdparts=[mtdparts=][;...]
  *
  *   := :[,...]
  *:= unique device tag used by linux kernel to find mtd device 
(mtd->name)
@@ -62,11 +62,11 @@
  *
  * 1 NOR Flash, with 1 single writable partition:
  * mtdids=nor0=edb7312-nor
- * mtdparts=mtdparts=edb7312-nor:-
+ * mtdparts=[mtdparts=]edb7312-nor:-
  *
  * 1 NOR Flash with 2 partitions, 1 NAND with one
  * mtdids=nor0=edb7312-nor,nand0=edb7312-nand
- * mtdparts=mtdparts=edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
+ * mtdparts=[mtdparts=]edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
  *
  */
 
@@ -1170,9 +1170,6 @@ static int generate_mtdparts(char *buf, u32 buflen)
return 0;
}
 
-   strcpy(p, "mtdparts=");
-   p += 9;
-
list_for_each(dentry, ) {
dev = list_entry(dentry, struct mtd_device, link);
 
@@ -1643,11 +1640,9 @@ static int parse_mtdparts(const char *const mtdparts)
if (!p)
p = mtdparts;
 
-   if (strncmp(p, "mtdparts=", 9) != 0) {
-   printf("mtdparts variable doesn't start with 'mtdparts='\n");
-   return err;
-   }
-   p += 9;
+   /* Skip the useless prefix, if any */
+   if (strncmp(p, "mtdparts=", 9) == 0)
+   p += 9;
 
while (*p != '\0') {
err = 1;
@@ -1786,6 +1781,24 @@ static int parse_mtdids(const char *const ids)
return 0;
 }
 
+int mtdids_search_alternate_name(const char *mtdname, char *altname,
+unsigned int max_len)
+{
+   struct list_head *entry;
+   struct mtdids *id;
+
+   list_for_each(entry, ) {
+   id = list_entry(entry, struct mtdids, link);
+   if (!strncmp(mtdname, id->mtd_id, max_len)) {
+   snprintf(altname, max_len, "%s%d",
+MTD_DEV_TYPE(id->type), id->num);
+
+   return 0;
+   }
+   }
+
+   return -EINVAL;
+}
 
 /**
  * Parse and initialize global mtdids mapping and create global
diff --git a/cmd/nand.c b/cmd/nand.c
index a22945d144..507966c513 100644
--- a/cmd/nand.c
+++ b/cmd/nand.c
@@ -21,6 +21,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 34d2bd59c4..3906b7446d 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/drivers/dfu/dfu_nand.c b/drivers/dfu/dfu_nand.c
index 0bfdbf9428..a3164491eb 100644
--- a/drivers/dfu/dfu_nand.c
+++ b/drivers/dfu/dfu_nand.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
diff --git a/drivers/fastboot/fb_nand.c b/drivers/fastboot/fb_nand.c
index 526bc12307..776f628712 100644
--- a/drivers/fastboot/fb_nand.c
+++ b/drivers/fastboot/fb_nand.c
@@ -11,6 +11,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 
diff --git a/drivers/mtd/mtd_uboot.c b/drivers/mtd/mtd_uboot.c
index 2b3b2eecca..55cdde284c 100644
--- a/drivers/mtd/mtd_uboot.c
+++ b/drivers/mtd/mtd_uboot.c
@@ -5,6 +5,7 @@
  */
 #include 
 #include 
+#include 
 #include 
 
 static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size,
diff --git a/include/jffs2/load_kernel.h b/include/jffs2/load_kernel.h
index 9346d7ee9f..3ef56ab0c5 100644
--- a/include/jffs2/load_kernel.h
+++ b/include/jffs2/load_kernel.h
@@ -62,7 +62,6 @@ struct mtdids {
 #define led_blink(x, 

[U-Boot] [PATCH v6 20/31] mtd: declare MTD_PARTITIONS symbol in Kconfig

2018-08-16 Thread Miquel Raynal
UBI selects MTD_PARTITIONS which is the symbol to compile
drivers/mtd/mtdpart.c. Unfortunately, the symbol was not defined in
Kconfig and this worked only with board files defining it. Fix this by
adding a boolean in Kconfig so boards defined by defconfig files only
will work as expected.

Signed-off-by: Miquel Raynal 
---
 drivers/mtd/Kconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 9341d518f3..d98457e223 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -1,5 +1,8 @@
 menu "MTD Support"
 
+config MTD_PARTITIONS
+   bool
+
 config MTD
bool "Enable Driver Model for MTD drivers"
depends on DM
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 24/31] cmd: mtdparts: accept spi-nand devices

2018-08-16 Thread Miquel Raynal
Let spi-nand devices be recognized by mtdparts. This is superfluous
but a full mtdparts rework would be very time-consuming.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 cmd/mtdparts.c  | 13 -
 include/jffs2/load_kernel.h |  7 +--
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index 756fc6018f..2e547894c6 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -37,7 +37,7 @@
  * mtdids=[,,...]
  *
  * := =
- *:= 'nand'|'nor'|'onenand'
+ *:= 'nand'|'nor'|'onenand'|'spi-nand'
  *   := mtd device number, 0...
  *:= unique device tag used by linux kernel to find mtd device 
(mtd->name)
  *
@@ -339,7 +339,7 @@ static int part_validate_eraseblock(struct mtdids *id, 
struct part_info *part)
 
if (!mtd->numeraseregions) {
/*
-* Only one eraseregion (NAND, OneNAND or uniform NOR),
+* Only one eraseregion (NAND, SPI-NAND, OneNAND or uniform 
NOR),
 * checking for alignment is easy here
 */
offset = part->offset;
@@ -1030,7 +1030,7 @@ static struct mtdids* id_find_by_mtd_id(const char 
*mtd_id, unsigned int mtd_id_
 }
 
 /**
- * Parse device id string  := 'nand'|'nor'|'onenand',
+ * Parse device id string  := 
'nand'|'nor'|'onenand'|'spi-nand',
  * return device type and number.
  *
  * @param id string describing device id
@@ -1054,6 +1054,9 @@ int mtd_id_parse(const char *id, const char **ret_id, u8 
*dev_type,
} else if (strncmp(p, "onenand", 7) == 0) {
*dev_type = MTD_DEV_TYPE_ONENAND;
p += 7;
+   } else if (strncmp(p, "spi-nand", 8) == 0) {
+   *dev_type = MTD_DEV_TYPE_SPINAND;
+   p += 8;
} else {
printf("incorrect device type in %s\n", id);
return 1;
@@ -1636,7 +1639,7 @@ static int parse_mtdids(const char *const ids)
while(p && (*p != '\0')) {
 
ret = 1;
-   /* parse 'nor'|'nand'|'onenand' */
+   /* parse 'nor'|'nand'|'onenand'|'spi-nand' */
if (mtd_id_parse(p, , , ) != 0)
break;
 
@@ -2112,7 +2115,7 @@ static char mtdparts_help_text[] =
"'mtdids' - linux kernel mtd device id <-> u-boot device id mapping\n\n"
"mtdids=[,,...]\n\n"
":= =\n"
-   "   := 'nand'|'nor'|'onenand'\n"
+   "   := 'nand'|'nor'|'onenand'|'spi-nand'\n"
"  := mtd device number, 0...\n"
"   := unique device tag used by linux kernel to find mtd 
device (mtd->name)\n\n"
"'mtdparts' - partition list\n\n"
diff --git a/include/jffs2/load_kernel.h b/include/jffs2/load_kernel.h
index 1ddff062ad..9346d7ee9f 100644
--- a/include/jffs2/load_kernel.h
+++ b/include/jffs2/load_kernel.h
@@ -15,9 +15,12 @@
 #define MTD_DEV_TYPE_NOR   0x0001
 #define MTD_DEV_TYPE_NAND  0x0002
 #define MTD_DEV_TYPE_ONENAND   0x0004
+#define MTD_DEV_TYPE_SPINAND   0x0008
 
-#define MTD_DEV_TYPE(type) ((type == MTD_DEV_TYPE_NAND) ? "nand" : \
-   (type == MTD_DEV_TYPE_ONENAND) ? "onenand" : "nor")
+#define MTD_DEV_TYPE(type) (type == MTD_DEV_TYPE_NAND ? "nand" :   \
+   (type == MTD_DEV_TYPE_NOR ? "nor" : \
+(type == MTD_DEV_TYPE_ONENAND ? "onenand" : \
+ "spi-nand"))) \
 
 struct mtd_device {
struct list_head link;
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 14/31] mtd: nand: Add core infrastructure to support SPI NANDs

2018-08-16 Thread Miquel Raynal
From: Peter Pan 

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

Signed-off-by: Peter Pan 
Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 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   | 1235 +
 include/linux/mtd/spinand.h   |  427 
 6 files changed, 1676 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

diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 1c1a1f487e..78ae04bdcb 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -2,3 +2,5 @@ config MTD_NAND_CORE
tristate
 
 source "drivers/mtd/nand/raw/Kconfig"
+
+source "drivers/mtd/nand/spi/Kconfig"
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index cd492dbc14..a358bc680e 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -2,3 +2,4 @@
 
 nandcore-objs := core.o bbt.o
 obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
+obj-$(CONFIG_MTD_SPI_NAND) += spi/
diff --git a/drivers/mtd/nand/spi/Kconfig b/drivers/mtd/nand/spi/Kconfig
new file mode 100644
index 00..2197cb531f
--- /dev/null
+++ b/drivers/mtd/nand/spi/Kconfig
@@ -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.
diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile
new file mode 100644
index 00..f0c6e69d2e
--- /dev/null
+++ b/drivers/mtd/nand/spi/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+
+spinand-objs := core.o
+obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
new file mode 100644
index 00..08f853ae11
--- /dev/null
+++ b/drivers/mtd/nand/spi/core.c
@@ -0,0 +1,1235 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2016-2017 Micron Technology, Inc.
+ *
+ * Authors:
+ * Peter Pan 
+ * Boris Brezillon 
+ */
+
+#define pr_fmt(fmt)"spi-nand: " fmt
+
+#ifndef __UBOOT__
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#else
+#include 
+#include 
+#include 
+#include 
+#include 
+#endif
+
+/* SPI NAND index visible in MTD names */
+static int spi_nand_idx;
+
+static void spinand_cache_op_adjust_colum(struct spinand_device *spinand,
+ const struct nand_page_io_req *req,
+ u16 *column)
+{
+   struct nand_device *nand = spinand_to_nand(spinand);
+   unsigned int shift;
+
+   if (nand->memorg.planes_per_lun < 2)
+   return;
+
+   /* The plane number is passed in MSB just above the column address */
+   shift = fls(nand->memorg.pagesize);
+   *column |= req->pos.plane << shift;
+}
+
+static int spinand_read_reg_op(struct spinand_device *spinand, u8 reg, u8 *val)
+{
+   struct spi_mem_op op = SPINAND_GET_FEATURE_OP(reg,
+ spinand->scratchbuf);
+   int ret;
+
+   ret = spi_mem_exec_op(spinand->slave, );
+   if (ret)
+   return ret;
+
+   *val = *spinand->scratchbuf;
+   return 0;
+}
+
+static int spinand_write_reg_op(struct spinand_device *spinand, u8 reg, u8 val)
+{
+   struct spi_mem_op op = SPINAND_SET_FEATURE_OP(reg,
+ spinand->scratchbuf);
+
+   *spinand->scratchbuf = val;
+   return spi_mem_exec_op(spinand->slave, );
+}
+
+static int spinand_read_status(struct spinand_device *spinand, u8 *status)
+{
+   return spinand_read_reg_op(spinand, REG_STATUS, status);
+}
+
+static int spinand_get_cfg(struct spinand_device *spinand, u8 *cfg)
+{
+   struct nand_device *nand = spinand_to_nand(spinand);
+
+   if (WARN_ON(spinand->cur_target < 0 ||
+   spinand->cur_target >= nand->memorg.ntargets))
+   return -EINVAL;
+
+   *cfg = spinand->cfg_cache[spinand->cur_target];
+   return 0;
+}
+
+static int spinand_set_cfg(struct spinand_device *spinand, u8 cfg)
+{
+   struct nand_device *nand = spinand_to_nand(spinand);
+   int ret;
+
+   if (WARN_ON(spinand->cur_target < 0 ||
+   spinand->cur_target >= nand->memorg.ntargets))
+   return -EINVAL;
+
+ 

[U-Boot] [PATCH v6 13/31] spi: Extend the core to ease integration of SPI memory controllers

2018-08-16 Thread Miquel Raynal
From: Boris Brezillon 

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).

Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 drivers/spi/Kconfig   |   7 +
 drivers/spi/Makefile  |   1 +
 drivers/spi/spi-mem.c | 501 ++
 include/spi-mem.h | 258 ++
 include/spi.h |  11 +
 5 files changed, 778 insertions(+)
 create mode 100644 drivers/spi/spi-mem.c
 create mode 100644 include/spi-mem.h

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index dcd719ff0a..9fbd26740d 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -18,6 +18,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
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 728e30c538..bdb5b5a02f 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -8,6 +8,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
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
new file mode 100644
index 00..af9aef009a
--- /dev/null
+++ b/drivers/spi/spi-mem.c
@@ -0,0 +1,501 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Exceet Electronics GmbH
+ * Copyright (C) 2018 Bootlin
+ *
+ * Author: Boris Brezillon 
+ */
+
+#ifndef __UBOOT__
+#include 
+#include 
+#include "internals.h"
+#else
+#include 
+#include 
+#endif
+
+#ifndef __UBOOT__
+/**
+ * spi_controller_dma_map_mem_op_data() - DMA-map the buffer attached to a
+ *   memory operation
+ * @ctlr: the SPI controller requesting this dma_map()
+ * @op: the memory operation containing the buffer to map
+ * @sgt: a pointer to a non-initialized sg_table that will be filled by this
+ *  function
+ *
+ * Some controllers might want to do DMA on the data buffer embedded in @op.
+ * This helper prepares everything for you and provides a ready-to-use
+ * sg_table. This function is not intended to be called from spi drivers.
+ * Only SPI controller drivers should use it.
+ * Note that the caller must ensure the memory region pointed by
+ * op->data.buf.{in,out} is DMA-able before calling this function.
+ *
+ * Return: 0 in case of success, a negative error code otherwise.
+ */
+int spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr,
+  const struct spi_mem_op *op,
+  struct sg_table *sgt)
+{
+   struct device *dmadev;
+
+   if (!op->data.nbytes)
+   return -EINVAL;
+
+   if (op->data.dir == SPI_MEM_DATA_OUT && ctlr->dma_tx)
+   dmadev = ctlr->dma_tx->device->dev;
+   else if (op->data.dir == SPI_MEM_DATA_IN && ctlr->dma_rx)
+   dmadev = ctlr->dma_rx->device->dev;
+   else
+   dmadev = ctlr->dev.parent;
+
+   if (!dmadev)
+   return -EINVAL;
+
+   return spi_map_buf(ctlr, dmadev, sgt, op->data.buf.in, op->data.nbytes,
+  op->data.dir == SPI_MEM_DATA_IN ?
+  DMA_FROM_DEVICE : DMA_TO_DEVICE);
+}
+EXPORT_SYMBOL_GPL(spi_controller_dma_map_mem_op_data);
+
+/**
+ * spi_controller_dma_unmap_mem_op_data() - DMA-unmap the buffer attached to a
+ * memory operation
+ * @ctlr: the SPI controller requesting this dma_unmap()
+ * @op: the memory operation containing the buffer to unmap
+ * @sgt: a pointer to an sg_table previously initialized by
+ *  spi_controller_dma_map_mem_op_data()
+ *
+ * Some controllers might want to do DMA on the data buffer embedded in @op.
+ * This helper prepares things so that the CPU can access the
+ * op->data.buf.{in,out} buffer again.
+ *
+ * This function is not intended to be called from SPI drivers. Only SPI
+ * controller drivers should use it.
+ *
+ * This function should be called after the DMA operation has finished and is
+ * only valid if the previous spi_controller_dma_map_mem_op_data() call
+ * returned 0.
+ *
+ * Return: 0 in case of success, a negative 

[U-Boot] [PATCH v6 15/31] mtd: spinand: Add initial support for Micron MT29F2G01ABAGD

2018-08-16 Thread Miquel Raynal
From: Peter Pan 

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.

Signed-off-by: Peter Pan 
Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 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

diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile
index f0c6e69d2e..4eb745abd4 100644
--- a/drivers/mtd/nand/spi/Makefile
+++ b/drivers/mtd/nand/spi/Makefile
@@ -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
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 08f853ae11..36b8b52bc2 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -829,8 +829,25 @@ static const struct nand_ops spinand_ops = {
.isbad = spinand_isbad,
 };
 
+static const struct spinand_manufacturer *spinand_manufacturers[] = {
+   _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;
 }
 
diff --git a/drivers/mtd/nand/spi/micron.c b/drivers/mtd/nand/spi/micron.c
new file mode 100644
index 00..83951c5d0f
--- /dev/null
+++ b/drivers/mtd/nand/spi/micron.c
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2016-2017 Micron Technology, Inc.
+ *
+ * Authors:
+ * Peter Pan 
+ */
+
+#ifndef __UBOOT__
+#include 
+#include 
+#endif
+#include 
+
+#define SPINAND_MFR_MICRON 0x2c
+
+#define MICRON_STATUS_ECC_MASK GENMASK(7, 4)
+#define MICRON_STATUS_ECC_NO_BITFLIPS  (0 << 4)
+#define MICRON_STATUS_ECC_1TO3_BITFLIPS(1 << 4)
+#define MICRON_STATUS_ECC_4TO6_BITFLIPS(3 << 4)
+#define MICRON_STATUS_ECC_7TO8_BITFLIPS(5 << 4)
+
+static SPINAND_OP_VARIANTS(read_cache_variants,
+   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
+
+static SPINAND_OP_VARIANTS(write_cache_variants,
+   SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
+   SPINAND_PROG_LOAD(true, 0, NULL, 0));
+
+static SPINAND_OP_VARIANTS(update_cache_variants,
+   SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
+   SPINAND_PROG_LOAD(false, 0, NULL, 0));
+
+static int mt29f2g01abagd_ooblayout_ecc(struct mtd_info *mtd, int section,
+   struct mtd_oob_region *region)
+{
+   if (section)
+   return -ERANGE;
+
+   region->offset = 64;
+   region->length = 64;
+
+   return 0;
+}
+
+static int mt29f2g01abagd_ooblayout_free(struct mtd_info *mtd, int section,
+struct mtd_oob_region *region)
+{
+   if (section)
+   return -ERANGE;
+
+   /* Reserve 2 bytes for the BBM. */
+   region->offset = 2;
+   region->length = 62;
+
+   return 0;
+}
+
+static const struct mtd_ooblayout_ops mt29f2g01abagd_ooblayout = {
+   .ecc = mt29f2g01abagd_ooblayout_ecc,
+   .free = mt29f2g01abagd_ooblayout_free,
+};
+
+static int mt29f2g01abagd_ecc_get_status(struct spinand_device *spinand,
+u8 status)
+{
+   switch (status & MICRON_STATUS_ECC_MASK) {
+   case STATUS_ECC_NO_BITFLIPS:
+   return 0;
+
+   case STATUS_ECC_UNCOR_ERROR:
+   return -EBADMSG;
+
+   case MICRON_STATUS_ECC_1TO3_BITFLIPS:
+   return 3;
+
+   case MICRON_STATUS_ECC_4TO6_BITFLIPS:
+   return 6;
+
+   case MICRON_STATUS_ECC_7TO8_BITFLIPS:
+   return 8;
+
+   default:
+   break;
+   }
+
+   return -EINVAL;
+}
+
+static const struct spinand_info micron_spinand_table[] = {
+   SPINAND_INFO("MT29F2G01ABAGD", 0x24,
+NAND_MEMORG(1, 20

[U-Boot] [PATCH v6 18/31] mtd: spinand: Add initial support for the MX35LF2GE4AB chip

2018-08-16 Thread Miquel Raynal
Add support for the MX35LF2GE4AB chip, which is similar to its cousin
MX35LF1GE4AB, with two planes instead of one.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 drivers/mtd/nand/spi/macronix.c | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c
index dd351dcb6c..662c561e50 100644
--- a/drivers/mtd/nand/spi/macronix.c
+++ b/drivers/mtd/nand/spi/macronix.c
@@ -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[] 
= {
  _cache_variants,
  _cache_variants),
 SPINAND_HAS_QE_BIT,
-SPINAND_ECCINFO(_ooblayout,
+SPINAND_ECCINFO(_ooblayout,
 mx35lf1ge4ab_ecc_get_status)),
+   SPINAND_INFO("MX35LF2GE4AB", 0x22,
+NAND_MEMORG(1, 2048, 64, 64, 2048, 2, 1, 1),
+NAND_ECCREQ(4, 512),
+SPINAND_INFO_OP_VARIANTS(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+SPINAND_HAS_QE_BIT,
+SPINAND_ECCINFO(_ooblayout, NULL)),
 };
 
 static int macronix_spinand_detect(struct spinand_device *spinand)
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 11/31] mtd: nand: Add core infrastructure to deal with NAND devices

2018-08-16 Thread Miquel Raynal
From: Boris Brezillon 

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

Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 drivers/mtd/nand/Kconfig  |   3 +
 drivers/mtd/nand/Makefile |   2 +
 drivers/mtd/nand/bbt.c| 132 +++
 drivers/mtd/nand/core.c   | 243 +
 include/linux/mtd/nand.h  | 731 ++
 5 files changed,  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

diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 6d53734718..1c1a1f487e 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -1 +1,4 @@
+config MTD_NAND_CORE
+   tristate
+
 source "drivers/mtd/nand/raw/Kconfig"
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index 69f40d1563..cd492dbc14 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -1,2 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0+
 
+nandcore-objs := core.o bbt.o
+obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
diff --git a/drivers/mtd/nand/bbt.c b/drivers/mtd/nand/bbt.c
new file mode 100644
index 00..7e0ad3190c
--- /dev/null
+++ b/drivers/mtd/nand/bbt.c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2017 Free Electrons
+ *
+ * Authors:
+ * Boris Brezillon 
+ * Peter Pan 
+ */
+
+#define pr_fmt(fmt)"nand-bbt: " fmt
+
+#include 
+#ifndef __UBOOT__
+#include 
+#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);
+   if (!nand->bbt.cache)
+   return -ENOMEM;
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_init);
+
+/**
+ * nanddev_bbt_cleanup() - Cleanup the BBT (Bad Block Table)
+ * @nand: NAND device
+ *
+ * Undoes what has been done in nanddev_bbt_init()
+ */
+void nanddev_bbt_cleanup(struct nand_device *nand)
+{
+   kfree(nand->bbt.cache);
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_cleanup);
+
+/**
+ * nanddev_bbt_update() - Update a BBT
+ * @nand: nand device
+ *
+ * Update the BBT. Currently a NOP function since on-flash bbt is not yet
+ * supported.
+ *
+ * Return: 0 in case of success, a negative error code otherwise.
+ */
+int nanddev_bbt_update(struct nand_device *nand)
+{
+   return 0;
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_update);
+
+/**
+ * nanddev_bbt_get_block_status() - Return the status of an eraseblock
+ * @nand: nand device
+ * @entry: the BBT entry
+ *
+ * Return: a positive number nand_bbt_block_status status or -%ERANGE if @entry
+ *is bigger than the BBT size.
+ */
+int nanddev_bbt_get_block_status(const struct nand_device *nand,
+unsigned int entry)
+{
+   unsigned int bits_per_block = fls(NAND_BBT_BLOCK_NUM_STATUS);
+   unsigned long *pos = nand->bbt.cache +
+((entry * bits_per_block) / BITS_PER_LONG);
+   unsigned int offs = (entry * bits_per_block) % BITS_PER_LONG;
+   unsigned long status;
+
+   if (entry >= nanddev_neraseblocks(nand))
+   return -ERANGE;
+
+   status = pos[0] >> offs;
+   if (bits_per_block + offs > BITS_PER_LONG)
+   status |= pos[1] << (BITS_PER_LONG - offs);
+
+   return status & GENMASK(bits_per_block - 1, 0);
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_get_block_status);
+
+/**
+ * nanddev_bbt_set_block_status() - Update the status of an eraseblock in the
+ * in-memory BBT
+ * @nand: nand device
+ * @entry: the BBT entry to update
+ * @status: the new status
+ *
+ * Update an entry of the in-memory BBT. If you want to push the updated BBT
+ * the NAND you should call nanddev_bbt_update().
+ *
+ * Return: 0 in case of success or -%ERANGE if @entry is bigger than the BBT
+ *size.
+ */
+int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,
+enum nand_bbt_block_status status)
+{
+   unsigned int bits_per_block = fls(NAND_BBT_BLOCK_NUM_STATUS);
+   unsigned long *pos = nand->bbt.cache +
+((entry * bits_per_block) / BITS_PER_LONG);
+   unsigned int offs = (entry * bits_per_block) % BITS_PER_LONG;
+   unsigned long val = status & GENMASK(bits_per_block - 1, 0);
+
+   if (entry 

[U-Boot] [PATCH v6 12/31] mtd: nand: Pass mode information to nand_page_io_req

2018-08-16 Thread Miquel Raynal
From: Boris Brezillon 

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.

Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
---
 include/linux/mtd/nand.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index ada7af4a41..13e8dd1103 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -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, >req.pos);
iter->req.ooboffs = req->ooboffs;
iter->oobbytes_per_page = mtd_oobavail(mtd, req);
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 10/31] mtd: rename nand into rawnand in Kconfig prompt

2018-08-16 Thread Miquel Raynal
Sync the Kconfig raw NAND entry title with the code architecture.

Signed-off-by: Miquel Raynal 
---
 drivers/mtd/nand/raw/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig
index 1e4ea7bdd4..008f7b4b4b 100644
--- a/drivers/mtd/nand/raw/Kconfig
+++ b/drivers/mtd/nand/raw/Kconfig
@@ -1,6 +1,6 @@
 
 menuconfig NAND
-   bool "NAND Device Support"
+   bool "Raw NAND Device Support"
 if NAND
 
 config SYS_NAND_SELF_INIT
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 17/31] mtd: spinand: Add initial support for the MX35LF1GE4AB chip

2018-08-16 Thread Miquel Raynal
From: Boris Brezillon 

Add minimal support for the MX35LF1GE4AB SPI NAND chip.

Signed-off-by: Boris Brezillon 
Acked-by: Jagan Teki 
---
 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

diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile
index 11ba5de68b..a66edd9199 100644
--- a/drivers/mtd/nand/spi/Makefile
+++ b/drivers/mtd/nand/spi/Makefile
@@ -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
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index ef3e6445d8..362d104846 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -830,6 +830,7 @@ static const struct nand_ops spinand_ops = {
 };
 
 static const struct spinand_manufacturer *spinand_manufacturers[] = {
+   _spinand_manufacturer,
_spinand_manufacturer,
_spinand_manufacturer,
 };
diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c
new file mode 100644
index 00..dd351dcb6c
--- /dev/null
+++ b/drivers/mtd/nand/spi/macronix.c
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018 Macronix
+ *
+ * Author: Boris Brezillon 
+ */
+
+#ifndef __UBOOT__
+#include 
+#include 
+#endif
+#include 
+
+#define SPINAND_MFR_MACRONIX   0xC2
+
+static SPINAND_OP_VARIANTS(read_cache_variants,
+   SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
+
+static SPINAND_OP_VARIANTS(write_cache_variants,
+   SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
+   SPINAND_PROG_LOAD(true, 0, NULL, 0));
+
+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,
+ struct mtd_oob_region *region)
+{
+   return -ERANGE;
+}
+
+static int mx35lf1ge4ab_ooblayout_free(struct mtd_info *mtd, int section,
+  struct mtd_oob_region *region)
+{
+   if (section)
+   return -ERANGE;
+
+   region->offset = 2;
+   region->length = mtd->oobsize - 2;
+
+   return 0;
+}
+
+static const struct mtd_ooblayout_ops mx35lf1ge4ab_ooblayout = {
+   .ecc = mx35lf1ge4ab_ooblayout_ecc,
+   .free = mx35lf1ge4ab_ooblayout_free,
+};
+
+static int mx35lf1ge4ab_get_eccsr(struct spinand_device *spinand, u8 *eccsr)
+{
+   struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(0x7c, 1),
+ SPI_MEM_OP_NO_ADDR,
+ SPI_MEM_OP_DUMMY(1, 1),
+ SPI_MEM_OP_DATA_IN(1, eccsr, 1));
+
+   return spi_mem_exec_op(spinand->slave, );
+}
+
+static int mx35lf1ge4ab_ecc_get_status(struct spinand_device *spinand,
+  u8 status)
+{
+   struct nand_device *nand = spinand_to_nand(spinand);
+   u8 eccsr;
+
+   switch (status & STATUS_ECC_MASK) {
+   case STATUS_ECC_NO_BITFLIPS:
+   return 0;
+
+   case STATUS_ECC_UNCOR_ERROR:
+   return -EBADMSG;
+
+   case STATUS_ECC_HAS_BITFLIPS:
+   /*
+* Let's try to retrieve the real maximum number of bitflips
+* in order to avoid forcing the wear-leveling layer to move
+* data around if it's not necessary.
+*/
+   if (mx35lf1ge4ab_get_eccsr(spinand, ))
+   return nand->eccreq.strength;
+
+   if (WARN_ON(eccsr > nand->eccreq.strength || !eccsr))
+   return nand->eccreq.strength;
+
+   return eccsr;
+
+   default:
+   break;
+   }
+
+   return -EINVAL;
+}
+
+static const struct spinand_info macronix_spinand_table[] = {
+   SPINAND_INFO("MX35LF1GE4AB", 0x12,
+NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
+NAND_ECCREQ(4, 512),
+SPINAND_INFO_OP_VARIANTS(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+SPINAND_HAS_QE_BIT,
+SPINAND_ECCINFO(_ooblayout,
+mx35lf1ge4ab_ecc_get_status)),
+};
+
+static int macronix_spinand_detect(struct spinand_device 

[U-Boot] [PATCH v6 05/31] mtd: add get/set of_node/flash_node helpers

2018-08-16 Thread Miquel Raynal
From: Brian Norris 

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.

Signed-off-by: Brian Norris 
Reviewed-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Reviewed-by: Jagan Teki 
---
 include/linux/mtd/mtd.h | 25 +
 1 file changed, 25 insertions(+)

diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index eb39f38887..73b19b57b1 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -306,6 +306,31 @@ struct mtd_info {
int usecount;
 };
 
+#if IS_ENABLED(CONFIG_DM)
+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;
+}
+#else
+struct device_node;
+
+static inline void mtd_set_of_node(struct mtd_info *mtd,
+  const struct device_node *np)
+{
+}
+
+static inline const struct device_node *mtd_get_of_node(struct mtd_info *mtd)
+{
+   return NULL;
+}
+#endif
+
 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,
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 16/31] mtd: spinand: Add initial support for Winbond W25M02GV

2018-08-16 Thread Miquel Raynal
From: Frieder Schrempf 

Add support for the W25M02GV chip.

Signed-off-by: Frieder Schrempf 
Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 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

diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile
index 4eb745abd4..11ba5de68b 100644
--- a/drivers/mtd/nand/spi/Makefile
+++ b/drivers/mtd/nand/spi/Makefile
@@ -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
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 36b8b52bc2..ef3e6445d8 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -831,6 +831,7 @@ static const struct nand_ops spinand_ops = {
 
 static const struct spinand_manufacturer *spinand_manufacturers[] = {
_spinand_manufacturer,
+   _spinand_manufacturer,
 };
 
 static int spinand_manufacturer_detect(struct spinand_device *spinand)
diff --git a/drivers/mtd/nand/spi/winbond.c b/drivers/mtd/nand/spi/winbond.c
new file mode 100644
index 00..eac811d97c
--- /dev/null
+++ b/drivers/mtd/nand/spi/winbond.c
@@ -0,0 +1,143 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2017 exceet electronics GmbH
+ *
+ * Authors:
+ * Frieder Schrempf 
+ * Boris Brezillon 
+ */
+
+#ifndef __UBOOT__
+#include 
+#include 
+#endif
+#include 
+
+#define SPINAND_MFR_WINBOND0xEF
+
+#define WINBOND_CFG_BUF_READ   BIT(3)
+
+static SPINAND_OP_VARIANTS(read_cache_variants,
+   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
+
+static SPINAND_OP_VARIANTS(write_cache_variants,
+   SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
+   SPINAND_PROG_LOAD(true, 0, NULL, 0));
+
+static SPINAND_OP_VARIANTS(update_cache_variants,
+   SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
+   SPINAND_PROG_LOAD(false, 0, NULL, 0));
+
+static int w25m02gv_ooblayout_ecc(struct mtd_info *mtd, int section,
+ struct mtd_oob_region *region)
+{
+   if (section > 3)
+   return -ERANGE;
+
+   region->offset = (16 * section) + 8;
+   region->length = 8;
+
+   return 0;
+}
+
+static int w25m02gv_ooblayout_free(struct mtd_info *mtd, int section,
+  struct mtd_oob_region *region)
+{
+   if (section > 3)
+   return -ERANGE;
+
+   region->offset = (16 * section) + 2;
+   region->length = 6;
+
+   return 0;
+}
+
+static const struct mtd_ooblayout_ops w25m02gv_ooblayout = {
+   .ecc = w25m02gv_ooblayout_ecc,
+   .free = w25m02gv_ooblayout_free,
+};
+
+static int w25m02gv_select_target(struct spinand_device *spinand,
+ unsigned int target)
+{
+   struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(0xc2, 1),
+ SPI_MEM_OP_NO_ADDR,
+ SPI_MEM_OP_NO_DUMMY,
+ SPI_MEM_OP_DATA_OUT(1,
+   spinand->scratchbuf,
+   1));
+
+   *spinand->scratchbuf = target;
+   return spi_mem_exec_op(spinand->slave, );
+}
+
+static const struct spinand_info winbond_spinand_table[] = {
+   SPINAND_INFO("W25M02GV", 0xAB,
+NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 2),
+NAND_ECCREQ(1, 512),
+SPINAND_INFO_OP_VARIANTS(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+0,
+SPINAND_ECCINFO(_ooblayout, NULL),
+SPINAND_SELECT_TARGET(w25m02gv_select_target)),
+};
+
+/**
+ * winbond_spinand_detect - initialize device related part in spinand_device
+ * struct if it is a Winbond device.
+ * @spinand: SPI NAND device structure
+ */
+static int winbond_spinand_detect(struct spinand_device *spinand)
+{
+   u8 *id = spinand->id.data;
+   int ret;
+
+   /*
+* Winbond SPI NAND read ID need a dummy byte,
+* so the first byte in raw_id is dummy.
+*/
+   if (id[1] != SPINA

[U-Boot] [PATCH v6 07/31] mtd: move definitions to enlarge their range

2018-08-16 Thread Miquel Raynal
Some helpers might be useful in a future 'mtd' U-Boot command to parse
MTD device list.

Signed-off-by: Miquel Raynal 
---
 drivers/mtd/mtdcore.h   | 6 --
 include/linux/mtd/mtd.h | 6 ++
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/mtdcore.h b/drivers/mtd/mtdcore.h
index 7b0353399a..1d181a1045 100644
--- a/drivers/mtd/mtdcore.h
+++ b/drivers/mtd/mtdcore.h
@@ -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))
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 272c646f9d..b8c2c3fd59 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -533,6 +533,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,
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 06/31] mtd: fix build issue with includes

2018-08-16 Thread Miquel Raynal
Fix build errors produced by mtd.h and dm/device.h if not included in
the right order.

Signed-off-by: Miquel Raynal 
Reviewed-by: Jagan Teki 
---
 include/linux/mtd/mtd.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 73b19b57b1..272c646f9d 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -21,6 +21,9 @@
 #include 
 #include 
 #include 
+#if IS_ENABLED(CONFIG_DM)
+#include 
+#endif
 
 #define MAX_MTD_DEVICES 32
 #endif
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 08/31] mtd: move all flash categories inside MTD submenu

2018-08-16 Thread Miquel Raynal
There is no reason to have NAND, SPI flashes and UBI sections outside of
the MTD submenu in Kconfig.

Signed-off-by: Miquel Raynal 
Reviewed-by: Jagan Teki 
---
 drivers/mtd/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 41f8883ec2..9341d518f3 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -59,10 +59,10 @@ config RENESAS_RPC_HF
  This enables access to Hyperflash memory through the Renesas
  RCar Gen3 RPC controller.
 
-endmenu
-
 source "drivers/mtd/nand/Kconfig"
 
 source "drivers/mtd/spi/Kconfig"
 
 source "drivers/mtd/ubi/Kconfig"
+
+endmenu
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 03/31] mtd: Add sanity checks in mtd_write/read_oob()

2018-08-16 Thread Miquel Raynal
From: Boris Brezillon 

Unlike what's done in mtd_read/write(), there are no checks to make sure
the parameters passed to mtd_read/write_oob() are consistent, which
forces implementers of ->_read/write_oob() to do it, which in turn leads
to code duplication and possibly errors in the logic.

Do general sanity checks, like ops fields consistency and range checking.

Signed-off-by: Boris Brezillon 
Cc: Peter Pan 
Signed-off-by: Richard Weinberger 
[Miquel: squashed the fix about the chip's size check]
Signed-off-by: Miquel Raynal 
---
 drivers/mtd/mtdcore.c | 45 +++
 1 file changed, 45 insertions(+)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index ad61406dac..9a3efe95df 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1010,12 +1010,50 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, 
size_t len, size_t *retlen,
 }
 EXPORT_SYMBOL_GPL(mtd_panic_write);
 
+static int mtd_check_oob_ops(struct mtd_info *mtd, loff_t offs,
+struct mtd_oob_ops *ops)
+{
+   /*
+* Some users are setting ->datbuf or ->oobbuf to NULL, but are leaving
+* ->len or ->ooblen uninitialized. Force ->len and ->ooblen to 0 in
+*  this case.
+*/
+   if (!ops->datbuf)
+   ops->len = 0;
+
+   if (!ops->oobbuf)
+   ops->ooblen = 0;
+
+   if (offs < 0 || offs + ops->len > mtd->size)
+   return -EINVAL;
+
+   if (ops->ooblen) {
+   u64 maxooblen;
+
+   if (ops->ooboffs >= mtd_oobavail(mtd, ops))
+   return -EINVAL;
+
+   maxooblen = ((mtd_div_by_ws(mtd->size, mtd) -
+ mtd_div_by_ws(offs, mtd)) *
+mtd_oobavail(mtd, ops)) - ops->ooboffs;
+   if (ops->ooblen > maxooblen)
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
 int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
 {
int ret_code;
ops->retlen = ops->oobretlen = 0;
if (!mtd->_read_oob)
return -EOPNOTSUPP;
+
+   ret_code = mtd_check_oob_ops(mtd, from, ops);
+   if (ret_code)
+   return ret_code;
+
/*
 * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics
 * similar to mtd->_read(), returning a non-negative integer
@@ -1034,11 +1072,18 @@ EXPORT_SYMBOL_GPL(mtd_read_oob);
 int mtd_write_oob(struct mtd_info *mtd, loff_t to,
struct mtd_oob_ops *ops)
 {
+   int ret;
+
ops->retlen = ops->oobretlen = 0;
if (!mtd->_write_oob)
return -EOPNOTSUPP;
if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS;
+
+   ret = mtd_check_oob_ops(mtd, to, ops);
+   if (ret)
+   return ret;
+
return mtd->_write_oob(mtd, to, ops);
 }
 EXPORT_SYMBOL_GPL(mtd_write_oob);
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 02/31] mtd: Uninline mtd_write_oob and move it to mtdcore.c

2018-08-16 Thread Miquel Raynal
From: Ezequiel Garcia 

There's no reason for having mtd_write_oob inlined in mtd.h header.
Move it to mtdcore.c where it belongs.

Signed-off-by: Ezequiel Garcia 
Acked-by: Boris Brezillon 
Signed-off-by: Jacek Anaszewski 
Signed-off-by: Miquel Raynal 
---
 drivers/mtd/mtdcore.c   | 12 
 include/linux/mtd/mtd.h | 12 +---
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 60ad28efd4..ad61406dac 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1031,6 +1031,18 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, 
struct mtd_oob_ops *ops)
 }
 EXPORT_SYMBOL_GPL(mtd_read_oob);
 
+int mtd_write_oob(struct mtd_info *mtd, loff_t to,
+   struct mtd_oob_ops *ops)
+{
+   ops->retlen = ops->oobretlen = 0;
+   if (!mtd->_write_oob)
+   return -EOPNOTSUPP;
+   if (!(mtd->flags & MTD_WRITEABLE))
+   return -EROFS;
+   return mtd->_write_oob(mtd, to, ops);
+}
+EXPORT_SYMBOL_GPL(mtd_write_oob);
+
 /**
  * mtd_ooblayout_ecc - Get the OOB region definition of a specific ECC section
  * @mtd: MTD device structure
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 823e535b82..eb39f38887 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -351,17 +351,7 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, 
size_t len, size_t *retlen,
const u_char *buf);
 
 int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops);
-
-static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to,
-   struct mtd_oob_ops *ops)
-{
-   ops->retlen = ops->oobretlen = 0;
-   if (!mtd->_write_oob)
-   return -EOPNOTSUPP;
-   if (!(mtd->flags & MTD_WRITEABLE))
-   return -EROFS;
-   return mtd->_write_oob(mtd, to, ops);
-}
+int mtd_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops);
 
 int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
   struct otp_info *buf);
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 01/31] mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing

2018-08-16 Thread Miquel Raynal
From: Boris Brezillon 

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.

Signed-off-by: Boris Brezillon 
Acked-by: Robert Jarzmik 
Acked-by: Brian Norris 
Reviewed-by: Miquel Raynal 
Tested-by: Ladislav Michl 
Signed-off-by: Miquel Raynal 
Reviewed-by: Jagan Teki 
---
 drivers/mtd/mtdcore.c  | 31 +++--
 drivers/mtd/mtdpart.c  |  6 ++--
 drivers/mtd/nand/nand_base.c   | 56 --
 drivers/mtd/onenand/onenand_base.c |  2 --
 4 files changed, 33 insertions(+), 62 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 6217be2352..60ad28efd4 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -937,7 +937,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, );
+   *retlen = ops.retlen;
+   } else {
+   return -ENOTSUPP;
+   }
+
if (unlikely(ret_code < 0))
return ret_code;
if (mtd->ecc_strength == 0)
@@ -952,10 +965,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, );
+   *retlen = ops.retlen;
+   return ret;
+   }
+
return mtd->_write(mtd, to, len, retlen, buf);
 }
 EXPORT_SYMBOL_GPL(mtd_write);
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index f87c962205..ccbb1757ea 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -417,8 +417,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 (master->_read)
+   slave->mtd._read = part_read;
+   if (master->_write)
+   slave->mtd._write = part_write;
 
if (master->_panic_write)
slave->mtd._panic_write = part_panic_write;
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 9094f857c1..92daebe120 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1863,33 +1863,6 @@ read_retry:
return max_bitflips;
 }
 
-/**
- * nand_read - [MTD Interface] MTD compatibility function for nand_do_read_ecc
- * @mtd: MTD device structure
- * @from: offset to read from
- * @len: number of bytes to read
- * @retlen: pointer to variable to store the number of read bytes
- * @buf: the databuffer to put data
- *
- * Get hold of the chip and call nand_do_read.
- */
-static int nand_read(struct mtd_info *mtd, loff_t from, size_t len,
-size_t *retlen, uint8_t *buf)
-{
-   struct mtd_oob_ops ops;
-   int ret;
-
-   nand_get_device(mtd, FL_READING);
-   memset(, 0, sizeof(ops));
-   ops.len = len;
-   ops.datbuf = buf;
-   ops.mode = MTD_OPS_PLACE_OOB;
-   ret = nand_do_read_ops(mtd, from, );
-   *retlen = ops.retlen;
-   nand_release_device(mtd);
-   return ret;
-}
-
 /**
  * nand_read_oob_std - [REPLACEABLE] the most common OOB data read function
  * @mtd: mtd info structure
@@ -2674,33 +2647,6 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t 
to, size_t len,
return ret;
 }
 
-/**
- * nand_write - [MTD Interface] NAND write with ECC
- * @mtd: MTD device structure
- * @to: offset to write to
- * @len: number of bytes to write
- * @retlen: pointer to variable to store the number of written bytes
- * @buf: the data to write
- *
- * NAND write with ECC.
- */
-static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
- size_t *retlen, const uint8_t *buf)
-{

[U-Boot] [PATCH v6 04/31] mtd: Fallback to ->_read/write() when ->_read/write_oob() is missing

2018-08-16 Thread Miquel Raynal
Some MTD sublayers/drivers are implementing ->_read/write() and
not ->_read/write_oob().

While for NAND devices both are usually valid, for NOR devices, using
the _oob variant has no real meaning. But, as the MTD layer is supposed
to hide as much as possible the flash complexity to the user, there is
no reason to error out while it is just a matter of rewritting things
internally.

Add a fallback on mtd->_read() (resp. mtd->_write()) when the user calls
mtd_read_oob() (resp. mtd_write_oob()) while mtd->_read_oob() (resp.
mtd->_write_oob) is not implemented. There is already a fallback on the
_oob variant if the former is used.

Signed-off-by: Miquel Raynal 
---
 drivers/mtd/mtdcore.c | 26 --
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 9a3efe95df..fb1d68d5e2 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1047,20 +1047,27 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, 
struct mtd_oob_ops *ops)
 {
int ret_code;
ops->retlen = ops->oobretlen = 0;
-   if (!mtd->_read_oob)
-   return -EOPNOTSUPP;
 
ret_code = mtd_check_oob_ops(mtd, from, ops);
if (ret_code)
return ret_code;
 
+   /* Check the validity of a potential fallback on mtd->_read */
+   if (!mtd->_read_oob && (!mtd->_read || ops->oobbuf))
+   return -EOPNOTSUPP;
+
+   if (mtd->_read_oob)
+   ret_code = mtd->_read_oob(mtd, from, ops);
+   else
+   ret_code = mtd->_read(mtd, from, ops->len, >retlen,
+ ops->datbuf);
+
/*
 * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics
 * similar to mtd->_read(), returning a non-negative integer
 * representing max bitflips. In other cases, mtd->_read_oob() may
 * return -EUCLEAN. In all cases, perform similar logic to mtd_read().
 */
-   ret_code = mtd->_read_oob(mtd, from, ops);
if (unlikely(ret_code < 0))
return ret_code;
if (mtd->ecc_strength == 0)
@@ -1075,8 +1082,7 @@ int mtd_write_oob(struct mtd_info *mtd, loff_t to,
int ret;
 
ops->retlen = ops->oobretlen = 0;
-   if (!mtd->_write_oob)
-   return -EOPNOTSUPP;
+
if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS;
 
@@ -1084,7 +1090,15 @@ int mtd_write_oob(struct mtd_info *mtd, loff_t to,
if (ret)
return ret;
 
-   return mtd->_write_oob(mtd, to, ops);
+   /* Check the validity of a potential fallback on mtd->_write */
+   if (!mtd->_write_oob && (!mtd->_write || ops->oobbuf))
+   return -EOPNOTSUPP;
+
+   if (mtd->_write_oob)
+   return mtd->_write_oob(mtd, to, ops);
+   else
+   return mtd->_write(mtd, to, ops->len, >retlen,
+  ops->datbuf);
 }
 EXPORT_SYMBOL_GPL(mtd_write_oob);
 
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 00/31] SPI-NAND support

2018-08-16 Thread Miquel Raynal
v1:
-
* Fixed the nand_memorg structure of the MX35LF2GE4AB chip.
* Added Reviewed-by tags from Jagan.
* Backported and squashed two patches fixing things in the SPI NAND core
  received on the Linux ML.
* Backported more changes in mtdcore.c from Linux.
* Added a patch to add a fallback on mtd->_read/_write() in mtdcore.c
  when mtd->_read/write_oob() is not supported.
* Removed the DT changes, useless as the DTs are not available in
  mainline yet.
* Addressed Boris/Stefan comments on the 'mtd' command.
* Added support for multi-pages OOB read/write.


Boris Brezillon (7):
  mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing
  mtd: Add sanity checks in mtd_write/read_oob()
  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

Ezequiel Garcia (1):
  mtd: Uninline mtd_write_oob and move it to mtdcore.c

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

Miquel Raynal (19):
  mtd: Fallback to ->_read/write() when ->_read/write_oob() is missing
  mtd: fix build issue with includes
  mtd: move definitions to enlarge their range
  mtd: move all flash categories inside MTD submenu
  mtd: move NAND files into a raw/ subdirectory
  mtd: rename nand into rawnand in Kconfig prompt
  mtd: spinand: Add initial support for the MX35LF2GE4AB chip
  mtd: declare MTD_PARTITIONS symbol in Kconfig
  mtd: mtdpart: balance debug messages
  cmd: ubi: delete useless and misleading definitions
  cmd: mtdparts: add fallthrough in switch statement
  cmd: mtdparts: accept spi-nand devices
  cmd: mtdparts: add a generic 'mtdparts' parser
  mtd: uclass: add probe function
  mtd: move mtdparts_init() declaration
  mtd: mtdpart: implement proper partition handling
  cmd: mtd: add 'mtd' command
  cmd: mtdparts: try to probe the MTD devices as a fallback
  cmd: ubi: clean the partition handling

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

 MAINTAINERS   |6 +-
 Makefile  |2 +-
 README|6 +-
 arch/arm/mach-uniphier/board_late_init.c  |2 +-
 cmd/Kconfig   |7 +
 cmd/Makefile  |1 +
 cmd/flash.c   |1 +
 cmd/jffs2.c   |1 +
 cmd/mtd.c |  513 +++
 cmd/mtdparts.c|  134 +-
 cmd/nand.c|1 +
 cmd/ubi.c |  100 +-
 common/fdt_support.c  |1 +
 common/spl/Kconfig|2 +-
 common/spl/spl_spi.c  |2 +-
 doc/README.SPL|4 +-
 doc/README.arm-relocation |2 +-
 doc/README.nand   |6 +-
 doc/README.zynq   |2 +-
 doc/device-tree-bindings/mtd/spi-nand.txt |5 +
 drivers/Makefile  |2 +-
 drivers/dfu/dfu_nand.c|1 +
 drivers/fastboot/fb_nand.c|1 +
 drivers/mtd/Kconfig   |7 +-
 drivers/mtd/Makefile  |4 +-
 drivers/mtd/mtd-uclass.c  |   20 +
 drivers/mtd/mtd_uboot.c   |1 +
 drivers/mtd/mtdcore.c |  106 +-
 drivers/mtd/mtdcore.h |6 -
 drivers/mtd/mtdpart.c |  389 +++--
 drivers/mtd/nand/Kconfig  |  299 +---
 drivers/mtd/nand/Makefile |   78 +-
 drivers/mtd/nand/bbt.c|  132 ++
 drivers/mtd/nand/core.c   |  243 
 drivers/mtd/nand/raw/Kconfig  |  297 
 drivers/mtd/nand/raw/Makefile |   77 +
 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 |2 +-
 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
 

Re: [U-Boot] [PATCH 1/4 v2] spi: spi-mem: Use 2 SPI messages instead of a single full-duplex one

2018-08-09 Thread Miquel Raynal
Hi Stefan,

Stefan Roese  wrote on Thu, 9 Aug 2018 11:10:15 +0200:

> Hi Miquel,
> 
> On 09.08.2018 10:13, Miquel Raynal wrote:
> > Stefan Roese  wrote on Thu, 9 Aug 2018 07:24:14 +0200:  
> > >> Hi Miquel,  
> >>
> >> On 08.08.2018 10:56, Miquel Raynal wrote:  
> >>> Boris Brezillon  wrote on Tue, 7 Aug 2018
> >>> 15:28:02 +0200:  
> >>>>> On Tue,  7 Aug 2018 14:16:52 +0200  
> >>>> Stefan Roese  wrote:  
> >>>>   >>>>> Some SPI controller do not support full-duplex SPI transfers. 
> >>>> This patch  
> >>>>> changes the SPI transfer into 2 separate transfers - or 1, if no data is
> >>>>> to transmitted.
> >>>>>
> >>>>> With this change, no buffers need to be allocated anymore. We use the
> >>>>> TX and RX buffers that are passed to spi_mem_exec_op() directly.
> >>>>>
> >>>>> Signed-off-by: Stefan Roese 
> >>>>> Suggested-by: Boris Brezillon 
> >>>>> Cc: Miquel Raynal 
> >>>>> Cc: Boris Brezillon 
> >>>>> Cc: Jagan Teki   
> >>>>
> >>>> Looks good overall, just a few comments (that you might chose to ignore
> >>>> if you disagree).
> >>>>
> >>>> Reviewed-by: Boris Brezillon 
> >>>>
> >>>> Sorry for being a bit late on the discussion, but while I do agree with  
> >>> the change, I'm not sure about its implementation : I think SPI
> >>> controllers are supposed to be abstracted by the SPI layer.
> >>> Addressing the controller's limitations in the SPI-mem layer would
> >>> not be appropriate.  
> >>>> Would it be possible to adapt spi_xfer() to handle such case?  
> >>
> >> No, I don't think so. Its impossible to guess in the SPI driver layer,
> >> which parts of the message are TX data and which are RX data. So this
> >> message can't be split up into a half-duplex one here. This can only
> >> be done in the driver which constructs the SPI messages.
> >>
> >> Or did I miss something here?
> > > Actually I'm fine with it as SPI-mem only uses half-duplex. It's not  
> > necessary to limit its use to SPI controllers (drivers) supporting
> > full-duplex.  
> > > Stefan, shall I fold your changes in my series and resend? Or do I  
> > resend only my original patches and Jagan/Tom will apply yours on top
> > of it?  
> 
> Do you need to re-send your original patches? If yes, then please do
> with my patches folded in. If a re-send is not necessary, then Jagan
> or Tom should be able to apply your latest patchset and mine on top
> of it.

I suppose Jagan prefers formal patches than a Github branch so
basically I have to pull Boris fixes, squash them, do the same with
yours and resend.

As we missed the merge window, maybe I'll also take the time to rework
mtdparts. I plan to do that next week.

Thanks for your help,
Miquèl
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 1/4 v2] spi: spi-mem: Use 2 SPI messages instead of a single full-duplex one

2018-08-09 Thread Miquel Raynal
Hi Stefan,

Stefan Roese  wrote on Thu, 9 Aug 2018 07:24:14 +0200:

> Hi Miquel,
> 
> On 08.08.2018 10:56, Miquel Raynal wrote:
> > Boris Brezillon  wrote on Tue, 7 Aug 2018
> > 15:28:02 +0200:  
> > >> On Tue,  7 Aug 2018 14:16:52 +0200  
> >> Stefan Roese  wrote:
> >>  
> >>> Some SPI controller do not support full-duplex SPI transfers. This patch
> >>> changes the SPI transfer into 2 separate transfers - or 1, if no data is
> >>> to transmitted.
> >>>
> >>> With this change, no buffers need to be allocated anymore. We use the
> >>> TX and RX buffers that are passed to spi_mem_exec_op() directly.
> >>>
> >>> Signed-off-by: Stefan Roese 
> >>> Suggested-by: Boris Brezillon 
> >>> Cc: Miquel Raynal 
> >>> Cc: Boris Brezillon 
> >>> Cc: Jagan Teki   
> >>
> >> Looks good overall, just a few comments (that you might chose to ignore
> >> if you disagree).
> >>
> >> Reviewed-by: Boris Brezillon 
> >>
> > > Sorry for being a bit late on the discussion, but while I do agree with  
> > the change, I'm not sure about its implementation : I think SPI
> > controllers are supposed to be abstracted by the SPI layer.
> > Addressing the controller's limitations in the SPI-mem layer would
> > not be appropriate.  
> > > Would it be possible to adapt spi_xfer() to handle such case?  
> 
> No, I don't think so. Its impossible to guess in the SPI driver layer,
> which parts of the message are TX data and which are RX data. So this
> message can't be split up into a half-duplex one here. This can only
> be done in the driver which constructs the SPI messages.
> 
> Or did I miss something here?

Actually I'm fine with it as SPI-mem only uses half-duplex. It's not
necessary to limit its use to SPI controllers (drivers) supporting
full-duplex.

Stefan, shall I fold your changes in my series and resend? Or do I
resend only my original patches and Jagan/Tom will apply yours on top
of it?

Thanks,
Miquèl
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v6 00/27] SPI-NAND support

2018-08-08 Thread Miquel Raynal
Hi Jagan,

Jagan Teki  wrote on Mon, 6 Aug 2018
23:20:19 +0530:

> Are you planning to send the next version?

I was not as we gave you a branch to pull patches from and test with
Travis if the warnings were gone [1].

Of course I can send the patches if you want them here also.

If Stefan sends a new iteration of his series I could fold the changes.

[1] https://github.com/bbrezillon/u-boot/commits/wip-spi


Thanks,
Miquèl
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 1/4 v2] spi: spi-mem: Use 2 SPI messages instead of a single full-duplex one

2018-08-08 Thread Miquel Raynal
Hi Stefan,

Minor typo if you decide to send a v3.

Boris Brezillon  wrote on Tue, 7 Aug 2018
15:28:02 +0200:

> On Tue,  7 Aug 2018 14:16:52 +0200
> Stefan Roese  wrote:
> 
> > Some SPI controller do not support full-duplex SPI transfers. This patch
> > changes the SPI transfer into 2 separate transfers - or 1, if no data is
> > to transmitted.

  ^ be ?

> > 
> > With this change, no buffers need to be allocated anymore. We use the
> > TX and RX buffers that are passed to spi_mem_exec_op() directly.
> > 
> > Signed-off-by: Stefan Roese 
> > Suggested-by: Boris Brezillon 
> > Cc: Miquel Raynal 
> > Cc: Boris Brezillon 
> > Cc: Jagan Teki   
> 

Thanks,
Miquèl
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v6 00/27] SPI-NAND support

2018-08-08 Thread Miquel Raynal
Hi Daniel,

Daniel Schwierzeck  wrote on Tue, 7 Aug
2018 16:39:34 +0200:

> 2018-08-04 9:23 GMT+02:00 Miquel Raynal :
> > Hi Jagan,
> >
> > Jagan Teki  wrote on Fri, 3 Aug 2018
> > 17:38:33 +0530:
> >  
> >> On Fri, Aug 3, 2018 at 3:20 PM, Jagan Teki  
> >> wrote:  
> >> > On Fri, Aug 3, 2018 at 1:57 PM, Miquel Raynal 
> >> >  wrote:  
> >> >> Hi Jagan, Tom,
> >> >>
> >> >> Miquel Raynal  wrote on Wed,  1 Aug 2018
> >> >> 10:18:21 +0200:
> >> >>  
> >> >>> 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:
> >> >>> - A few patches from Linux to resynchronize some areas of the MTD 
> >> >>> layer.
> >> >>> - 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.
> >> >>> - Support for spi-nand devices in mtdparts.
> >> >>>
> >> >>> To test your SPI-NAND device with U-Boot simply follow these lines:
> >> >>>  
> >> >>> > setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)
> >> >>> > setenv mtdids spi-nand0=spi-nand0
> >> >>> > mtdparts # show the spi-nand device partitions
> >> >>> > ubi part bar # create a static UBI volume in the bar 
> >> >>> > partition  
> >> >>>
> >> >>> Thanks,
> >> >>> Miquèl
> >> >>>
> >> >>> Changes since v5:
> >> >>> -
> >> >>> * Included Boris fixup about the build issues.
> >> >>> * Added Rb/Ab tags from Jagan on patchs 20/21.  
> >> >>
> >> >> I can't see a pull request flow on U-Boot ML, I suppose you use a
> >> >> different mean for that purpose.
> >> >>
> >> >> Jagan, is this version OK? Is it part of your PR?  
> >> >
> >> > Travis is going on [1], will send PR once all fine.
> >> >
> >> > [1] https://travis-ci.org/openedev/u-boot-amarula/builds/411596788  
> >>
> >> There are some build issues, not quite sure whether it relates. please
> >> look into it.  
> >
> > Thanks for the reports.
> >  
> >>
> >> [2] https://travis-ci.org/openedev/u-boot-amarula/jobs/411596814
> >> [3] https://travis-ci.org/openedev/u-boot-amarula/jobs/411596815  
> >
> > Boris supposedly fixed all the build issues related to my changes (I
> > don't think the "missing interrupt parent" in a DTS file is related),
> > please pull his branch [1].  
> 
> the DTS warnings are unrelated and can be ignored. Only the onenand_*
> stuff seems
> to be a regression.

OneNAND warnings should be gone with Boris fixups.

Thanks,
Miquèl
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 1/4 v2] spi: spi-mem: Use 2 SPI messages instead of a single full-duplex one

2018-08-08 Thread Miquel Raynal
Hi Stefan, Jagan,

Boris Brezillon  wrote on Tue, 7 Aug 2018
15:28:02 +0200:

> On Tue,  7 Aug 2018 14:16:52 +0200
> Stefan Roese  wrote:
> 
> > Some SPI controller do not support full-duplex SPI transfers. This patch
> > changes the SPI transfer into 2 separate transfers - or 1, if no data is
> > to transmitted.
> > 
> > With this change, no buffers need to be allocated anymore. We use the
> > TX and RX buffers that are passed to spi_mem_exec_op() directly.
> > 
> > Signed-off-by: Stefan Roese 
> > Suggested-by: Boris Brezillon 
> > Cc: Miquel Raynal 
> > Cc: Boris Brezillon 
> > Cc: Jagan Teki   
> 
> Looks good overall, just a few comments (that you might chose to ignore
> if you disagree).
> 
> Reviewed-by: Boris Brezillon 
> 

Sorry for being a bit late on the discussion, but while I do agree with
the change, I'm not sure about its implementation : I think SPI
controllers are supposed to be abstracted by the SPI layer.
Addressing the controller's limitations in the SPI-mem layer would
not be appropriate.

Would it be possible to adapt spi_xfer() to handle such case? 

Thanks,
Miquèl
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 2/2] tpm: sandbox: fix wrong assignment with a simplification

2018-08-05 Thread Miquel Raynal
The recv variable in sandbox_tpm2_fill_buf() is a pointer on a pointer
of a char array. It means accessing *recv is the char array pointer
itself while **recv is the first character of that array. There is no
need for such indirection here, so simplify the code.

Simplifying things will make the last assignment right: "*recv = NULL"
is now correct. The issue has been found by the following Coverity
Scan report:

CID 183371:  Incorrect expression  (UNUSED_VALUE)
Assigning value "4UL" to "*recv" here, but that stored value is overwritten 
before it can be used.
232 *recv += sizeof(rc);
233
234 /* Add trailing \0 */
235 *recv = NULL;

While at simplifying things, use '\0' instead of NULL when adding an
empty char at the end of the buffer.

Reported-by: Tom Rini 
Signed-off-by: Miquel Raynal 
---
 drivers/tpm/tpm2_tis_sandbox.c | 52 +-
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/tpm/tpm2_tis_sandbox.c b/drivers/tpm/tpm2_tis_sandbox.c
index b15ec732ad..f282ea6adf 100644
--- a/drivers/tpm/tpm2_tis_sandbox.c
+++ b/drivers/tpm/tpm2_tis_sandbox.c
@@ -215,24 +215,24 @@ static int sandbox_tpm2_check_readyness(struct udevice 
*dev, int command)
return 0;
 }
 
-static int sandbox_tpm2_fill_buf(u8 **recv, size_t *recv_len, u16 tag, u32 rc)
+static int sandbox_tpm2_fill_buf(u8 *recv, size_t *recv_len, u16 tag, u32 rc)
 {
*recv_len = sizeof(tag) + sizeof(u32) + sizeof(rc);
 
/* Write tag */
-   put_unaligned_be16(tag, *recv);
-   *recv += sizeof(tag);
+   put_unaligned_be16(tag, recv);
+   recv += sizeof(tag);
 
/* Write length */
-   put_unaligned_be32(*recv_len, *recv);
-   *recv += sizeof(u32);
+   put_unaligned_be32(*recv_len, recv);
+   recv += sizeof(u32);
 
/* Write return code */
-   put_unaligned_be32(rc, *recv);
-   *recv += sizeof(rc);
+   put_unaligned_be32(rc, recv);
+   recv += sizeof(rc);
 
/* Add trailing \0 */
-   *recv = NULL;
+   *recv = '\0';
 
return 0;
 }
@@ -287,7 +287,7 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 
*sendbuf,
printf("TPM2: Unmatching length, received: %ld, expected: %d\n",
   send_size, length);
rc = TPM2_RC_SIZE;
-   sandbox_tpm2_fill_buf(, recv_len, tag, rc);
+   sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
return 0;
}
 
@@ -295,13 +295,13 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const 
u8 *sendbuf,
sent += sizeof(command);
rc = sandbox_tpm2_check_readyness(dev, command);
if (rc) {
-   sandbox_tpm2_fill_buf(, recv_len, tag, rc);
+   sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
return 0;
}
 
rc = sandbox_tpm2_check_session(dev, command, tag, , );
if (rc) {
-   sandbox_tpm2_fill_buf(, recv_len, tag, rc);
+   sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
return 0;
}
 
@@ -319,7 +319,7 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 
*sendbuf,
 
tpm->startup_done = true;
 
-   sandbox_tpm2_fill_buf(, recv_len, tag, rc);
+   sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
break;
 
case TPM2_CC_SELF_TEST:
@@ -335,7 +335,7 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 
*sendbuf,
 
tpm->tests_done = true;
 
-   sandbox_tpm2_fill_buf(, recv_len, tag, rc);
+   sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
break;
 
case TPM2_CC_CLEAR:
@@ -358,7 +358,7 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 
*sendbuf,
tpm->pcr[i][j] = 0;
}
 
-   sandbox_tpm2_fill_buf(, recv_len, tag, rc);
+   sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
break;
 
case TPM2_CC_HIERCHANGEAUTH:
@@ -372,7 +372,7 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 
*sendbuf,
sent += new_pw_sz;
}
 
-   sandbox_tpm2_fill_buf(, recv_len, tag, rc);
+   sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
break;
 
case TPM2_CC_GET_CAPABILITY:
@@ -392,7 +392,7 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 
*sendbuf,
if (!property_count ||
property + property_count > TPM2_PROPERTY_NB) {
rc = TPM2_RC_HANDLE;
-   return sandbox_tpm2_fill_buf(, recv_len, tag, rc);
+   return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
}
 
/* Write tag */
@@ -445,7 +445,7 @@ static

[U-Boot] [PATCH 1/2] tpm: sandbox: fix wrong check on pcr_map

2018-08-05 Thread Miquel Raynal
The second check on pcr_map in sandbox_tpm2_xfer() is wrong. It should
check for pcr_map not being empty. Instead, it is a pure copy/paste of
the first check which is redundant.

This has been found thanks to a Coverity Scan report:

CID 183370:  Memory - illegal accesses  (UNINIT)
Using uninitialized value "pcr_index".
put_unaligned_be32(tpm->pcr_extensions[pcr_index], recv);

This is because pcr_index is initialized only if the user input is
correct, ie. at least one valid bit is set in pcr_map.

Fix the second check and also initialize pcr_index to 0 (which is
harmless in case of error) to make Coverity Scan happy.

Reported-by: Tom Rini 
Signed-off-by: Miquel Raynal 
---
 drivers/tpm/tpm2_tis_sandbox.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/tpm/tpm2_tis_sandbox.c b/drivers/tpm/tpm2_tis_sandbox.c
index 66f6c9ba82..b15ec732ad 100644
--- a/drivers/tpm/tpm2_tis_sandbox.c
+++ b/drivers/tpm/tpm2_tis_sandbox.c
@@ -272,7 +272,7 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 
*sendbuf,
u32 capability, property, property_count;
 
/* TPM2_PCR_Read/Extend variables */
-   int pcr_index;
+   int pcr_index = 0;
u64 pcr_map = 0;
u32 selections, pcr_nb;
u16 alg;
@@ -483,8 +483,8 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 
*sendbuf,
return sandbox_tpm2_fill_buf(, recv_len, tag, rc);
}
 
-   if (pcr_map >> SANDBOX_TPM_PCR_NB) {
-   printf("Wrong PCR map.\n");
+   if (!pcr_map) {
+   printf("Empty PCR map.\n");
rc = TPM2_RC_VALUE;
return sandbox_tpm2_fill_buf(, recv_len, tag, rc);
}
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v6 00/27] SPI-NAND support

2018-08-04 Thread Miquel Raynal
Hi Boris,

Boris Brezillon  wrote on Sat, 4 Aug 2018
10:34:55 +0200:

> On Sat, 4 Aug 2018 09:23:05 +0200
> Miquel Raynal  wrote:
> 
> > Hi Jagan,
> > 
> > Jagan Teki  wrote on Fri, 3 Aug 2018
> > 17:38:33 +0530:
> >   
> > > On Fri, Aug 3, 2018 at 3:20 PM, Jagan Teki  
> > > wrote:    
> > > > On Fri, Aug 3, 2018 at 1:57 PM, Miquel Raynal 
> > > >  wrote:  
> > > >> Hi Jagan, Tom,
> > > >>
> > > >> Miquel Raynal  wrote on Wed,  1 Aug 2018
> > > >> 10:18:21 +0200:
> > > >>  
> > > >>> 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:
> > > >>> - A few patches from Linux to resynchronize some areas of the MTD 
> > > >>> layer.
> > > >>> - 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.
> > > >>> - Support for spi-nand devices in mtdparts.
> > > >>>
> > > >>> To test your SPI-NAND device with U-Boot simply follow these lines:
> > > >>>  
> > > >>> > setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)
> > > >>> > setenv mtdids spi-nand0=spi-nand0
> > > >>> > mtdparts # show the spi-nand device partitions
> > > >>> > ubi part bar # create a static UBI volume in the bar 
> > > >>> > partition  
> > > >>>
> > > >>> Thanks,
> > > >>> Miquèl
> > > >>>
> > > >>> Changes since v5:
> > > >>> -
> > > >>> * Included Boris fixup about the build issues.
> > > >>> * Added Rb/Ab tags from Jagan on patchs 20/21.  
> > > >>
> > > >> I can't see a pull request flow on U-Boot ML, I suppose you use a
> > > >> different mean for that purpose.
> > > >>
> > > >> Jagan, is this version OK? Is it part of your PR?  
> > > >
> > > > Travis is going on [1], will send PR once all fine.
> > > >
> > > > [1] https://travis-ci.org/openedev/u-boot-amarula/builds/411596788  
> > > 
> > > There are some build issues, not quite sure whether it relates. please
> > > look into it.
> > 
> > Thanks for the reports.
> >   
> > > 
> > > [2] https://travis-ci.org/openedev/u-boot-amarula/jobs/411596814
> > > [3] https://travis-ci.org/openedev/u-boot-amarula/jobs/411596815
> > 
> > Boris supposedly fixed all the build issues related to my changes (I
> > don't think the "missing interrupt parent" in a DTS file is related),
> > please pull his branch [1].
> > 
> > The fixes are under the form of fixups if you wanna check them.
> > Otherwise you can just 'rebase -i --autosquash' to automatically squash
> > them with the commit introducing the regression.  
> 
> One more thing, if you want to make things bisectable patch 6 ("mtd: fix
> build issue with includes") and it's fixup should be squashed in patch 5
> ("mtd: add get/set of_node/flash_node helpers"), because the build
> failure you're fixing in patch 6 is introduced by patch 5.
> 
> > 
> > [1] https://travis-ci.org/openedev/u-boot-amarula/jobs/411596814  
> 
> You mean
> 
> [1]https://github.com/bbrezillon/u-boot/commits/wip-spi


Oops!

Thanks,
Miquèl
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v6 00/27] SPI-NAND support

2018-08-04 Thread Miquel Raynal
Hi Jagan,

Jagan Teki  wrote on Fri, 3 Aug 2018
17:38:33 +0530:

> On Fri, Aug 3, 2018 at 3:20 PM, Jagan Teki  wrote:
> > On Fri, Aug 3, 2018 at 1:57 PM, Miquel Raynal  
> > wrote:  
> >> Hi Jagan, Tom,
> >>
> >> Miquel Raynal  wrote on Wed,  1 Aug 2018
> >> 10:18:21 +0200:
> >>  
> >>> 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:
> >>> - A few patches from Linux to resynchronize some areas of the MTD layer.
> >>> - 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.
> >>> - Support for spi-nand devices in mtdparts.
> >>>
> >>> To test your SPI-NAND device with U-Boot simply follow these lines:
> >>>  
> >>> > setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)
> >>> > setenv mtdids spi-nand0=spi-nand0
> >>> > mtdparts # show the spi-nand device partitions
> >>> > ubi part bar # create a static UBI volume in the bar partition  
> >>>
> >>> Thanks,
> >>> Miquèl
> >>>
> >>> Changes since v5:
> >>> -
> >>> * Included Boris fixup about the build issues.
> >>> * Added Rb/Ab tags from Jagan on patchs 20/21.  
> >>
> >> I can't see a pull request flow on U-Boot ML, I suppose you use a
> >> different mean for that purpose.
> >>
> >> Jagan, is this version OK? Is it part of your PR?  
> >
> > Travis is going on [1], will send PR once all fine.
> >
> > [1] https://travis-ci.org/openedev/u-boot-amarula/builds/411596788  
> 
> There are some build issues, not quite sure whether it relates. please
> look into it.

Thanks for the reports.

> 
> [2] https://travis-ci.org/openedev/u-boot-amarula/jobs/411596814
> [3] https://travis-ci.org/openedev/u-boot-amarula/jobs/411596815

Boris supposedly fixed all the build issues related to my changes (I
don't think the "missing interrupt parent" in a DTS file is related),
please pull his branch [1].

The fixes are under the form of fixups if you wanna check them.
Otherwise you can just 'rebase -i --autosquash' to automatically squash
them with the commit introducing the regression.

[1] https://travis-ci.org/openedev/u-boot-amarula/jobs/411596814


Thanks,
Miquèl

-- 
Miquel Raynal, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v6 00/27] SPI-NAND support

2018-08-03 Thread Miquel Raynal
Hi Jagan, Tom,

Miquel Raynal  wrote on Wed,  1 Aug 2018
10:18:21 +0200:

> 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:
> - A few patches from Linux to resynchronize some areas of the MTD layer.
> - 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.
> - Support for spi-nand devices in mtdparts.
> 
> To test your SPI-NAND device with U-Boot simply follow these lines:
> 
> > setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)
> > setenv mtdids spi-nand0=spi-nand0
> > mtdparts # show the spi-nand device partitions
> > ubi part bar # create a static UBI volume in the bar partition  
> 
> Thanks,
> Miquèl
> 
> Changes since v5:
> -
> * Included Boris fixup about the build issues.
> * Added Rb/Ab tags from Jagan on patchs 20/21.

I can't see a pull request flow on U-Boot ML, I suppose you use a
different mean for that purpose.

Jagan, is this version OK? Is it part of your PR?

Thanks,
Miquèl
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 26/27] cmd: mtd: add 'mtd' command

2018-08-01 Thread 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.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 cmd/Kconfig |   7 +
 cmd/Makefile|   1 +
 cmd/mtd.c   | 392 
 drivers/mtd/Makefile|   2 +-
 include/linux/mtd/mtd.h |   1 +
 5 files changed, 402 insertions(+), 1 deletion(-)
 create mode 100644 cmd/mtd.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 0cf530d923..45ead0ffce 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -848,6 +848,13 @@ config CMD_MMC_SWRITE
  Enable support for the "mmc swrite" command to write Android sparse
  images to eMMC.
 
+config CMD_MTD
+   bool "mtd"
+   depends on CMD_MTDPARTS
+   select MTD_PARTITIONS
+   help
+ MTD commands support.
+
 config CMD_NAND
bool "nand"
default y if NAND_SUNXI
diff --git a/cmd/Makefile b/cmd/Makefile
index 323f1fd2c7..32fd102189 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -90,6 +90,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
diff --git a/cmd/mtd.c b/cmd/mtd.c
new file mode 100644
index 00..221b12500f
--- /dev/null
+++ b/cmd/mtd.c
@@ -0,0 +1,392 @@
+// 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 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static void mtd_dump_buf(u8 *buf, uint len, uint offset)
+{
+   int i, j;
+
+   for (i = 0; i < len; ) {
+   printf("0x%08x:\t", offset + 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)
+{
+   /* Device */
+   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");
+
+   /* MTD information */
+   printf("\t> type: ");
+   switch (mtd->type) {
+   case MTD_RAM:
+   printf("RAM\n");
+   break;
+   case MTD_ROM:
+   printf("ROM\n");
+   break;
+   case MTD_NORFLASH:
+   printf("NOR flash\n");
+   break;
+   case MTD_NANDFLASH:
+   printf("NAND flash\n");
+   break;
+   case MTD_DATAFLASH:
+   printf("Data flash\n");
+   break;
+   case MTD_UBIVOLUME:
+   printf("UBI volume\n");
+   break;
+   case MTD_MLCNANDFLASH:
+   printf("MLC NAND flash\n");
+   break;
+   case MTD_ABSENT:
+   default:
+   printf("Unknown\n");
+   break;
+   }
+
+   printf("\t> Size: 0x%llx bytes\n", mtd->size);
+   printf("\t> Block: 0x%x bytes\n", mtd->erasesize);
+   printf("\t> Min I/O: 0x%x bytes\n", mtd->writesize);
+
+   if (mtd->oobsize) {
+   printf("\t> OOB size: %u bytes\n", mtd->oobsize);
+   printf("\t> OOB available: %u bytes\n", mtd->oobavail);
+   }
+
+   if (mtd->ecc_strength) {
+   printf("\t> ECC strength: %u bits\n", mtd->ecc_strength);
+   printf("\t> ECC step size: %u bytes\n", mtd->ecc_step_size);
+   printf("\t> Bitflip threshold: %u bits\n",
+  mtd->bitflip_threshold);
+   }
+}
+
+int mtd_probe_devices(void)
+{
+   const char *mtdparts = env_get("mtdparts");
+   struct udevice *dev;
+   int idx = 0;
+
+   /* Probe devices with DM compliant drivers */
+   while (!uclass_find_device(UCLASS_MTD, idx, ) && dev) {
+   mtd_probe(dev);
+   idx++;
+   }
+
+   /* Create the partitions defined in mtdparts, here the fun begins */
+
+   /* Ignore the extra 'm

[U-Boot] [PATCH v6 27/27] cmd: mtdparts: try to probe the MTD devices as a fallback

2018-08-01 Thread Miquel Raynal
Current implementation of mtdparts command errors out if the desired MTD
device is not found. Fallback to the new probe function in this case
before erroring out.

This will the save the user the need to call something like 'mtd list'
before mtdparts.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 cmd/mtdparts.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index ef8588bd71..76f0138e4d 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -305,9 +305,15 @@ static int get_mtd_info(u8 type, u8 num, struct mtd_info 
**mtd)
 
sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(type), num);
*mtd = get_mtd_device_nm(mtd_dev);
-   if (IS_ERR(*mtd)) {
-   printf("Device %s not found!\n", mtd_dev);
-   return 1;
+   if (IS_ERR_OR_NULL(*mtd)) {
+#ifdef CONFIG_CMD_MTD
+   mtd_probe_devices();
+   *mtd = get_mtd_device_nm(mtd_dev);
+#endif
+   if (IS_ERR_OR_NULL(*mtd)) {
+   printf("Device %s not found!\n", mtd_dev);
+   return 1;
+   }
}
put_mtd_device(*mtd);
 
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 17/27] mtd: spinand: Add initial support for the MX35LF1GE4AB chip

2018-08-01 Thread Miquel Raynal
From: Boris Brezillon 

Add minimal support for the MX35LF1GE4AB SPI NAND chip.

Signed-off-by: Boris Brezillon 
Acked-by: Jagan Teki 
---
 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

diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile
index 11ba5de68b..a66edd9199 100644
--- a/drivers/mtd/nand/spi/Makefile
+++ b/drivers/mtd/nand/spi/Makefile
@@ -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
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index ef3e6445d8..362d104846 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -830,6 +830,7 @@ static const struct nand_ops spinand_ops = {
 };
 
 static const struct spinand_manufacturer *spinand_manufacturers[] = {
+   _spinand_manufacturer,
_spinand_manufacturer,
_spinand_manufacturer,
 };
diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c
new file mode 100644
index 00..dd351dcb6c
--- /dev/null
+++ b/drivers/mtd/nand/spi/macronix.c
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018 Macronix
+ *
+ * Author: Boris Brezillon 
+ */
+
+#ifndef __UBOOT__
+#include 
+#include 
+#endif
+#include 
+
+#define SPINAND_MFR_MACRONIX   0xC2
+
+static SPINAND_OP_VARIANTS(read_cache_variants,
+   SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
+
+static SPINAND_OP_VARIANTS(write_cache_variants,
+   SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
+   SPINAND_PROG_LOAD(true, 0, NULL, 0));
+
+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,
+ struct mtd_oob_region *region)
+{
+   return -ERANGE;
+}
+
+static int mx35lf1ge4ab_ooblayout_free(struct mtd_info *mtd, int section,
+  struct mtd_oob_region *region)
+{
+   if (section)
+   return -ERANGE;
+
+   region->offset = 2;
+   region->length = mtd->oobsize - 2;
+
+   return 0;
+}
+
+static const struct mtd_ooblayout_ops mx35lf1ge4ab_ooblayout = {
+   .ecc = mx35lf1ge4ab_ooblayout_ecc,
+   .free = mx35lf1ge4ab_ooblayout_free,
+};
+
+static int mx35lf1ge4ab_get_eccsr(struct spinand_device *spinand, u8 *eccsr)
+{
+   struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(0x7c, 1),
+ SPI_MEM_OP_NO_ADDR,
+ SPI_MEM_OP_DUMMY(1, 1),
+ SPI_MEM_OP_DATA_IN(1, eccsr, 1));
+
+   return spi_mem_exec_op(spinand->slave, );
+}
+
+static int mx35lf1ge4ab_ecc_get_status(struct spinand_device *spinand,
+  u8 status)
+{
+   struct nand_device *nand = spinand_to_nand(spinand);
+   u8 eccsr;
+
+   switch (status & STATUS_ECC_MASK) {
+   case STATUS_ECC_NO_BITFLIPS:
+   return 0;
+
+   case STATUS_ECC_UNCOR_ERROR:
+   return -EBADMSG;
+
+   case STATUS_ECC_HAS_BITFLIPS:
+   /*
+* Let's try to retrieve the real maximum number of bitflips
+* in order to avoid forcing the wear-leveling layer to move
+* data around if it's not necessary.
+*/
+   if (mx35lf1ge4ab_get_eccsr(spinand, ))
+   return nand->eccreq.strength;
+
+   if (WARN_ON(eccsr > nand->eccreq.strength || !eccsr))
+   return nand->eccreq.strength;
+
+   return eccsr;
+
+   default:
+   break;
+   }
+
+   return -EINVAL;
+}
+
+static const struct spinand_info macronix_spinand_table[] = {
+   SPINAND_INFO("MX35LF1GE4AB", 0x12,
+NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
+NAND_ECCREQ(4, 512),
+SPINAND_INFO_OP_VARIANTS(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+SPINAND_HAS_QE_BIT,
+SPINAND_ECCINFO(_ooblayout,
+mx35lf1ge4ab_ecc_get_status)),
+};
+
+static int macronix_spinand_detect(struct 

[U-Boot] [PATCH v6 22/27] cmd: mtdparts: accept spi-nand devices

2018-08-01 Thread Miquel Raynal
Let spi-nand devices be recognized by mtdparts. This is superfluous
but a full mtdparts rework would be very time-consuming.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 cmd/mtdparts.c  | 13 -
 include/jffs2/load_kernel.h |  7 +--
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index 0da3afd75f..f26a761c99 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -37,7 +37,7 @@
  * mtdids=[,,...]
  *
  * := =
- *:= 'nand'|'nor'|'onenand'
+ *:= 'nand'|'nor'|'onenand'|'spi-nand'
  *   := mtd device number, 0...
  *:= unique device tag used by linux kernel to find mtd device 
(mtd->name)
  *
@@ -336,7 +336,7 @@ static int part_validate_eraseblock(struct mtdids *id, 
struct part_info *part)
 
if (!mtd->numeraseregions) {
/*
-* Only one eraseregion (NAND, OneNAND or uniform NOR),
+* Only one eraseregion (NAND, SPI-NAND, OneNAND or uniform 
NOR),
 * checking for alignment is easy here
 */
offset = part->offset;
@@ -1027,7 +1027,7 @@ static struct mtdids* id_find_by_mtd_id(const char 
*mtd_id, unsigned int mtd_id_
 }
 
 /**
- * Parse device id string  := 'nand'|'nor'|'onenand',
+ * Parse device id string  := 
'nand'|'nor'|'onenand'|'spi-nand',
  * return device type and number.
  *
  * @param id string describing device id
@@ -1051,6 +1051,9 @@ int mtd_id_parse(const char *id, const char **ret_id, u8 
*dev_type,
} else if (strncmp(p, "onenand", 7) == 0) {
*dev_type = MTD_DEV_TYPE_ONENAND;
p += 7;
+   } else if (strncmp(p, "spi-nand", 8) == 0) {
+   *dev_type = MTD_DEV_TYPE_SPINAND;
+   p += 8;
} else {
printf("incorrect device type in %s\n", id);
return 1;
@@ -1633,7 +1636,7 @@ static int parse_mtdids(const char *const ids)
while(p && (*p != '\0')) {
 
ret = 1;
-   /* parse 'nor'|'nand'|'onenand' */
+   /* parse 'nor'|'nand'|'onenand'|'spi-nand' */
if (mtd_id_parse(p, , , ) != 0)
break;
 
@@ -2109,7 +2112,7 @@ static char mtdparts_help_text[] =
"'mtdids' - linux kernel mtd device id <-> u-boot device id mapping\n\n"
"mtdids=[,,...]\n\n"
":= =\n"
-   "   := 'nand'|'nor'|'onenand'\n"
+   "   := 'nand'|'nor'|'onenand'|'spi-nand'\n"
"  := mtd device number, 0...\n"
"   := unique device tag used by linux kernel to find mtd 
device (mtd->name)\n\n"
"'mtdparts' - partition list\n\n"
diff --git a/include/jffs2/load_kernel.h b/include/jffs2/load_kernel.h
index 1ddff062ad..9346d7ee9f 100644
--- a/include/jffs2/load_kernel.h
+++ b/include/jffs2/load_kernel.h
@@ -15,9 +15,12 @@
 #define MTD_DEV_TYPE_NOR   0x0001
 #define MTD_DEV_TYPE_NAND  0x0002
 #define MTD_DEV_TYPE_ONENAND   0x0004
+#define MTD_DEV_TYPE_SPINAND   0x0008
 
-#define MTD_DEV_TYPE(type) ((type == MTD_DEV_TYPE_NAND) ? "nand" : \
-   (type == MTD_DEV_TYPE_ONENAND) ? "onenand" : "nor")
+#define MTD_DEV_TYPE(type) (type == MTD_DEV_TYPE_NAND ? "nand" :   \
+   (type == MTD_DEV_TYPE_NOR ? "nor" : \
+(type == MTD_DEV_TYPE_ONENAND ? "onenand" : \
+ "spi-nand"))) \
 
 struct mtd_device {
struct list_head link;
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 23/27] cmd: mtdparts: add a generic 'mtdparts' parser

2018-08-01 Thread Miquel Raynal
The current parser is very specific to U-Boot mtdparts implementation.
It does not use MTD structures like mtd_info and mtd_partition. Write
some kind of a wrapper around the current implementation to allow other
commands to benefit from this parsing in a user-friendly way.

This new command will allocate an mtd_partition array for each
successful call. This array must be freed after use by the caller.
The given 'mtdparts' buffer pointer will be moved forward to the next
MTD device (if any, it will point towards a '\0' character otherwise).

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 cmd/mtdparts.c | 71 ++
 include/linux/mtd/partitions.h |  3 ++
 2 files changed, 74 insertions(+)

diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index f26a761c99..27e84db0e4 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -78,6 +78,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #if defined(CONFIG_CMD_NAND)
 #include 
@@ -705,6 +706,76 @@ static int part_parse(const char *const partdef, const 
char **ret, struct part_i
return 0;
 }
 
+int mtdparts_parse_part(struct mtd_info *parent, const char **_mtdparts,
+   struct mtd_partition **_parts, int *_nb_parts)
+{
+   const char *mtdparts = *_mtdparts;
+   struct part_info *part_legacy;
+   struct mtd_partition *parts;
+   int cur_off = 0, cur_sz = 0;
+   int nb_parts = 0;
+   char *names;
+   int ret, idx;
+
+   *_parts = NULL;
+   *_nb_parts = 0;
+
+   /* First, iterate over the partitions until we know their number */
+   while (mtdparts[0] != '\0' && mtdparts[0] != ';') {
+   ret = part_parse(mtdparts, , _legacy);
+   if (ret)
+   return ret;
+
+   nb_parts++;
+   free(part_legacy);
+   }
+
+   /* Allocate an array of partitions to give back to the caller */
+   parts = malloc((sizeof(*parts) + 20) * nb_parts);
+   names = (char *)[nb_parts];
+   if (!parts) {
+   printf("Could not allocate enough space to save partitions 
meta-data\n");
+   return -ENOMEM;
+   }
+
+   /* Iterate again over each partition to save the data in our array */
+   for (idx = 0; idx < nb_parts; idx++) {
+   char *name;
+
+   ret = part_parse(*_mtdparts, _mtdparts, _legacy);
+   if (ret)
+   return ret;
+
+   name = [idx * 20];
+   strncpy(name, part_legacy->name, 20);
+   parts[idx].name = name;
+
+   parts[idx].size = part_legacy->size;
+   if (parts[idx].size == SIZE_REMAINING)
+   parts[idx].size = parent->size - cur_sz;
+   cur_sz += parts[idx].size;
+
+   parts[idx].offset = part_legacy->offset;
+   if (parts[idx].offset == OFFSET_NOT_SPECIFIED)
+   parts[idx].offset = cur_off;
+   cur_off += parts[idx].size;
+
+   parts[idx].mask_flags = part_legacy->mask_flags;
+   parts[idx].ecclayout = parent->ecclayout;
+
+   free(part_legacy);
+   }
+
+   /* Offset by one mtdparts to point to the next device if needed */
+   if (*_mtdparts[0] == ';')
+   _mtdparts++;
+
+   *_parts = parts;
+   *_nb_parts = nb_parts;
+
+   return 0;
+}
+
 /**
  * Check device number to be within valid range for given device type.
  *
diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
index ce0e8dbee4..0cf26ca945 100644
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -87,4 +87,7 @@ int mtd_add_partition(struct mtd_info *master, const char 
*name,
 int mtd_del_partition(struct mtd_info *master, int partno);
 uint64_t mtd_get_device_size(const struct mtd_info *mtd);
 
+int mtdparts_parse_part(struct mtd_info *parent, const char **_mtdparts,
+   struct mtd_partition **_parts, int *_nb_parts);
+
 #endif
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 18/27] mtd: spinand: Add initial support for the MX35LF2GE4AB chip

2018-08-01 Thread Miquel Raynal
Add support for the MX35LF2GE4AB chip, which is similar to its cousin
MX35LF1GE4AB, with two planes instead of one.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 drivers/mtd/nand/spi/macronix.c | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c
index dd351dcb6c..662c561e50 100644
--- a/drivers/mtd/nand/spi/macronix.c
+++ b/drivers/mtd/nand/spi/macronix.c
@@ -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[] 
= {
  _cache_variants,
  _cache_variants),
 SPINAND_HAS_QE_BIT,
-SPINAND_ECCINFO(_ooblayout,
+SPINAND_ECCINFO(_ooblayout,
 mx35lf1ge4ab_ecc_get_status)),
+   SPINAND_INFO("MX35LF2GE4AB", 0x22,
+NAND_MEMORG(1, 2048, 64, 64, 2048, 2, 1, 1),
+NAND_ECCREQ(4, 512),
+SPINAND_INFO_OP_VARIANTS(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+SPINAND_HAS_QE_BIT,
+SPINAND_ECCINFO(_ooblayout, NULL)),
 };
 
 static int macronix_spinand_detect(struct spinand_device *spinand)
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 24/27] cmd: mtdparts: remove useless 'mtdparts=' prefix

2018-08-01 Thread Miquel Raynal
All U-Boot users must define the mtdparts environment variable with:
setenv mtdparts mtdparts=...

This is a pure software limitation and is a complete non-sense. Remove
this limitation but keep the backward compatibility.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 cmd/mtdparts.c | 17 ++---
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index 27e84db0e4..ef8588bd71 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -44,7 +44,7 @@
  *
  * 'mtdparts' - partition list
  *
- * mtdparts=mtdparts=[;...]
+ * mtdparts=[mtdparts=][;...]
  *
  *   := :[,...]
  *:= unique device tag used by linux kernel to find mtd device 
(mtd->name)
@@ -62,11 +62,11 @@
  *
  * 1 NOR Flash, with 1 single writable partition:
  * mtdids=nor0=edb7312-nor
- * mtdparts=mtdparts=edb7312-nor:-
+ * mtdparts=[mtdparts=]edb7312-nor:-
  *
  * 1 NOR Flash with 2 partitions, 1 NAND with one
  * mtdids=nor0=edb7312-nor,nand0=edb7312-nand
- * mtdparts=mtdparts=edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
+ * mtdparts=[mtdparts=]edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
  *
  */
 
@@ -1167,9 +1167,6 @@ static int generate_mtdparts(char *buf, u32 buflen)
return 0;
}
 
-   strcpy(p, "mtdparts=");
-   p += 9;
-
list_for_each(dentry, ) {
dev = list_entry(dentry, struct mtd_device, link);
 
@@ -1640,11 +1637,9 @@ static int parse_mtdparts(const char *const mtdparts)
if (!p)
p = mtdparts;
 
-   if (strncmp(p, "mtdparts=", 9) != 0) {
-   printf("mtdparts variable doesn't start with 'mtdparts='\n");
-   return err;
-   }
-   p += 9;
+   /* Skip the useless prefix, if any */
+   if (strncmp(p, "mtdparts=", 9) == 0)
+   p += 9;
 
while (*p != '\0') {
err = 1;
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 21/27] cmd: ubi: delete useless and misleading definitions

2018-08-01 Thread Miquel Raynal
These definitions are simply not used and are misleading because similar
definitions exist in jffs2/load_kernel.h and are used widely to define
MTD device types (which is, by the way, totally redundant with what the
MTD core does). Remove these definitions.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 cmd/ubi.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/cmd/ubi.c b/cmd/ubi.c
index 913f0f71fd..0a3405a3b1 100644
--- a/cmd/ubi.c
+++ b/cmd/ubi.c
@@ -27,11 +27,6 @@
 #undef ubi_msg
 #define ubi_msg(fmt, ...) printf("UBI: " fmt "\n", ##__VA_ARGS__)
 
-#define DEV_TYPE_NONE  0
-#define DEV_TYPE_NAND  1
-#define DEV_TYPE_ONENAND   2
-#define DEV_TYPE_NOR   3
-
 /* Private own data */
 static struct ubi_device *ubi;
 static char buffer[80];
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 19/27] dt-bindings: Add bindings for SPI NAND devices

2018-08-01 Thread Miquel Raynal
From: Boris Brezillon 

Add bindings for SPI NAND chips.

Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 doc/device-tree-bindings/mtd/spi-nand.txt | 5 +
 1 file changed, 5 insertions(+)
 create mode 100644 doc/device-tree-bindings/mtd/spi-nand.txt

diff --git a/doc/device-tree-bindings/mtd/spi-nand.txt 
b/doc/device-tree-bindings/mtd/spi-nand.txt
new file mode 100644
index 00..8b51f3b6d5
--- /dev/null
+++ b/doc/device-tree-bindings/mtd/spi-nand.txt
@@ -0,0 +1,5 @@
+SPI NAND flash
+
+Required properties:
+- compatible: should be "spi-nand"
+- reg: should encode the chip-select line used to access the NAND chip
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 15/27] mtd: spinand: Add initial support for Micron MT29F2G01ABAGD

2018-08-01 Thread Miquel Raynal
From: Peter Pan 

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.

Signed-off-by: Peter Pan 
Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 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

diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile
index f0c6e69d2e..4eb745abd4 100644
--- a/drivers/mtd/nand/spi/Makefile
+++ b/drivers/mtd/nand/spi/Makefile
@@ -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
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 08f853ae11..36b8b52bc2 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -829,8 +829,25 @@ static const struct nand_ops spinand_ops = {
.isbad = spinand_isbad,
 };
 
+static const struct spinand_manufacturer *spinand_manufacturers[] = {
+   _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;
 }
 
diff --git a/drivers/mtd/nand/spi/micron.c b/drivers/mtd/nand/spi/micron.c
new file mode 100644
index 00..83951c5d0f
--- /dev/null
+++ b/drivers/mtd/nand/spi/micron.c
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2016-2017 Micron Technology, Inc.
+ *
+ * Authors:
+ * Peter Pan 
+ */
+
+#ifndef __UBOOT__
+#include 
+#include 
+#endif
+#include 
+
+#define SPINAND_MFR_MICRON 0x2c
+
+#define MICRON_STATUS_ECC_MASK GENMASK(7, 4)
+#define MICRON_STATUS_ECC_NO_BITFLIPS  (0 << 4)
+#define MICRON_STATUS_ECC_1TO3_BITFLIPS(1 << 4)
+#define MICRON_STATUS_ECC_4TO6_BITFLIPS(3 << 4)
+#define MICRON_STATUS_ECC_7TO8_BITFLIPS(5 << 4)
+
+static SPINAND_OP_VARIANTS(read_cache_variants,
+   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
+
+static SPINAND_OP_VARIANTS(write_cache_variants,
+   SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
+   SPINAND_PROG_LOAD(true, 0, NULL, 0));
+
+static SPINAND_OP_VARIANTS(update_cache_variants,
+   SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
+   SPINAND_PROG_LOAD(false, 0, NULL, 0));
+
+static int mt29f2g01abagd_ooblayout_ecc(struct mtd_info *mtd, int section,
+   struct mtd_oob_region *region)
+{
+   if (section)
+   return -ERANGE;
+
+   region->offset = 64;
+   region->length = 64;
+
+   return 0;
+}
+
+static int mt29f2g01abagd_ooblayout_free(struct mtd_info *mtd, int section,
+struct mtd_oob_region *region)
+{
+   if (section)
+   return -ERANGE;
+
+   /* Reserve 2 bytes for the BBM. */
+   region->offset = 2;
+   region->length = 62;
+
+   return 0;
+}
+
+static const struct mtd_ooblayout_ops mt29f2g01abagd_ooblayout = {
+   .ecc = mt29f2g01abagd_ooblayout_ecc,
+   .free = mt29f2g01abagd_ooblayout_free,
+};
+
+static int mt29f2g01abagd_ecc_get_status(struct spinand_device *spinand,
+u8 status)
+{
+   switch (status & MICRON_STATUS_ECC_MASK) {
+   case STATUS_ECC_NO_BITFLIPS:
+   return 0;
+
+   case STATUS_ECC_UNCOR_ERROR:
+   return -EBADMSG;
+
+   case MICRON_STATUS_ECC_1TO3_BITFLIPS:
+   return 3;
+
+   case MICRON_STATUS_ECC_4TO6_BITFLIPS:
+   return 6;
+
+   case MICRON_STATUS_ECC_7TO8_BITFLIPS:
+   return 8;
+
+   default:
+   break;
+   }
+
+   return -EINVAL;
+}
+
+static const struct spinand_info micron_spinand_table[] = {
+   SPINAND_INFO("MT29F2G01ABAGD", 0x24,
+NAND_MEMORG(1, 20

[U-Boot] [PATCH v6 11/27] mtd: nand: Add core infrastructure to deal with NAND devices

2018-08-01 Thread Miquel Raynal
From: Boris Brezillon 

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

Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 drivers/mtd/nand/Kconfig  |   3 +
 drivers/mtd/nand/Makefile |   2 +
 drivers/mtd/nand/bbt.c| 132 +
 drivers/mtd/nand/core.c   | 243 +++
 include/linux/mtd/nand.h  | 731 ++
 5 files changed,  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

diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 6d53734718..1c1a1f487e 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -1 +1,4 @@
+config MTD_NAND_CORE
+   tristate
+
 source "drivers/mtd/nand/raw/Kconfig"
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index 69f40d1563..cd492dbc14 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -1,2 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0+
 
+nandcore-objs := core.o bbt.o
+obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
diff --git a/drivers/mtd/nand/bbt.c b/drivers/mtd/nand/bbt.c
new file mode 100644
index 00..7e0ad3190c
--- /dev/null
+++ b/drivers/mtd/nand/bbt.c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2017 Free Electrons
+ *
+ * Authors:
+ * Boris Brezillon 
+ * Peter Pan 
+ */
+
+#define pr_fmt(fmt)"nand-bbt: " fmt
+
+#include 
+#ifndef __UBOOT__
+#include 
+#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);
+   if (!nand->bbt.cache)
+   return -ENOMEM;
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_init);
+
+/**
+ * nanddev_bbt_cleanup() - Cleanup the BBT (Bad Block Table)
+ * @nand: NAND device
+ *
+ * Undoes what has been done in nanddev_bbt_init()
+ */
+void nanddev_bbt_cleanup(struct nand_device *nand)
+{
+   kfree(nand->bbt.cache);
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_cleanup);
+
+/**
+ * nanddev_bbt_update() - Update a BBT
+ * @nand: nand device
+ *
+ * Update the BBT. Currently a NOP function since on-flash bbt is not yet
+ * supported.
+ *
+ * Return: 0 in case of success, a negative error code otherwise.
+ */
+int nanddev_bbt_update(struct nand_device *nand)
+{
+   return 0;
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_update);
+
+/**
+ * nanddev_bbt_get_block_status() - Return the status of an eraseblock
+ * @nand: nand device
+ * @entry: the BBT entry
+ *
+ * Return: a positive number nand_bbt_block_status status or -%ERANGE if @entry
+ *is bigger than the BBT size.
+ */
+int nanddev_bbt_get_block_status(const struct nand_device *nand,
+unsigned int entry)
+{
+   unsigned int bits_per_block = fls(NAND_BBT_BLOCK_NUM_STATUS);
+   unsigned long *pos = nand->bbt.cache +
+((entry * bits_per_block) / BITS_PER_LONG);
+   unsigned int offs = (entry * bits_per_block) % BITS_PER_LONG;
+   unsigned long status;
+
+   if (entry >= nanddev_neraseblocks(nand))
+   return -ERANGE;
+
+   status = pos[0] >> offs;
+   if (bits_per_block + offs > BITS_PER_LONG)
+   status |= pos[1] << (BITS_PER_LONG - offs);
+
+   return status & GENMASK(bits_per_block - 1, 0);
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_get_block_status);
+
+/**
+ * nanddev_bbt_set_block_status() - Update the status of an eraseblock in the
+ * in-memory BBT
+ * @nand: nand device
+ * @entry: the BBT entry to update
+ * @status: the new status
+ *
+ * Update an entry of the in-memory BBT. If you want to push the updated BBT
+ * the NAND you should call nanddev_bbt_update().
+ *
+ * Return: 0 in case of success or -%ERANGE if @entry is bigger than the BBT
+ *size.
+ */
+int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,
+enum nand_bbt_block_status status)
+{
+   unsigned int bits_per_block = fls(NAND_BBT_BLOCK_NUM_STATUS);
+   unsigned long *pos = nand->bbt.cache +
+((entry * bits_per_block) / BITS_PER_LONG);
+   unsigned int offs = (entry * bits_per_block) % BITS_PER_LONG;
+   unsigned long val = status & GENMASK(bits_per_block - 1, 0);
+
+   if (entry 

[U-Boot] [PATCH v6 20/27] mtd: declare MTD_PARTITIONS symbol in Kconfig

2018-08-01 Thread Miquel Raynal
UBI selects MTD_PARTITIONS which is the symbol to compile
drivers/mtd/mtdpart.c. Unfortunately, the symbol was not defined in
Kconfig and this worked only with board files defining it. Fix this by
adding a boolean in Kconfig so boards defined by defconfig files only
will work as expected.

Signed-off-by: Miquel Raynal 
Reviewed-by: Jagan Teki 
---
 drivers/mtd/Kconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 9341d518f3..d98457e223 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -1,5 +1,8 @@
 menu "MTD Support"
 
+config MTD_PARTITIONS
+   bool
+
 config MTD
bool "Enable Driver Model for MTD drivers"
depends on DM
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 14/27] mtd: nand: Add core infrastructure to support SPI NANDs

2018-08-01 Thread Miquel Raynal
From: Peter Pan 

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

Signed-off-by: Peter Pan 
Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 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   | 1235 +
 include/linux/mtd/spinand.h   |  427 ++
 6 files changed, 1676 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

diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 1c1a1f487e..78ae04bdcb 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -2,3 +2,5 @@ config MTD_NAND_CORE
tristate
 
 source "drivers/mtd/nand/raw/Kconfig"
+
+source "drivers/mtd/nand/spi/Kconfig"
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index cd492dbc14..a358bc680e 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -2,3 +2,4 @@
 
 nandcore-objs := core.o bbt.o
 obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
+obj-$(CONFIG_MTD_SPI_NAND) += spi/
diff --git a/drivers/mtd/nand/spi/Kconfig b/drivers/mtd/nand/spi/Kconfig
new file mode 100644
index 00..2197cb531f
--- /dev/null
+++ b/drivers/mtd/nand/spi/Kconfig
@@ -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.
diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile
new file mode 100644
index 00..f0c6e69d2e
--- /dev/null
+++ b/drivers/mtd/nand/spi/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+
+spinand-objs := core.o
+obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
new file mode 100644
index 00..08f853ae11
--- /dev/null
+++ b/drivers/mtd/nand/spi/core.c
@@ -0,0 +1,1235 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2016-2017 Micron Technology, Inc.
+ *
+ * Authors:
+ * Peter Pan 
+ * Boris Brezillon 
+ */
+
+#define pr_fmt(fmt)"spi-nand: " fmt
+
+#ifndef __UBOOT__
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#else
+#include 
+#include 
+#include 
+#include 
+#include 
+#endif
+
+/* SPI NAND index visible in MTD names */
+static int spi_nand_idx;
+
+static void spinand_cache_op_adjust_colum(struct spinand_device *spinand,
+ const struct nand_page_io_req *req,
+ u16 *column)
+{
+   struct nand_device *nand = spinand_to_nand(spinand);
+   unsigned int shift;
+
+   if (nand->memorg.planes_per_lun < 2)
+   return;
+
+   /* The plane number is passed in MSB just above the column address */
+   shift = fls(nand->memorg.pagesize);
+   *column |= req->pos.plane << shift;
+}
+
+static int spinand_read_reg_op(struct spinand_device *spinand, u8 reg, u8 *val)
+{
+   struct spi_mem_op op = SPINAND_GET_FEATURE_OP(reg,
+ spinand->scratchbuf);
+   int ret;
+
+   ret = spi_mem_exec_op(spinand->slave, );
+   if (ret)
+   return ret;
+
+   *val = *spinand->scratchbuf;
+   return 0;
+}
+
+static int spinand_write_reg_op(struct spinand_device *spinand, u8 reg, u8 val)
+{
+   struct spi_mem_op op = SPINAND_SET_FEATURE_OP(reg,
+ spinand->scratchbuf);
+
+   *spinand->scratchbuf = val;
+   return spi_mem_exec_op(spinand->slave, );
+}
+
+static int spinand_read_status(struct spinand_device *spinand, u8 *status)
+{
+   return spinand_read_reg_op(spinand, REG_STATUS, status);
+}
+
+static int spinand_get_cfg(struct spinand_device *spinand, u8 *cfg)
+{
+   struct nand_device *nand = spinand_to_nand(spinand);
+
+   if (WARN_ON(spinand->cur_target < 0 ||
+   spinand->cur_target >= nand->memorg.ntargets))
+   return -EINVAL;
+
+   *cfg = spinand->cfg_cache[spinand->cur_target];
+   return 0;
+}
+
+static int spinand_set_cfg(struct spinand_device *spinand, u8 cfg)
+{
+   struct nand_device *nand = spinand_to_nand(spinand);
+   int ret;
+
+   if (WARN_ON(spinand->cur_target < 0 ||
+   spinand->cur_target >= nand->memorg.ntargets))
+

[U-Boot] [PATCH v6 13/27] spi: Extend the core to ease integration of SPI memory controllers

2018-08-01 Thread Miquel Raynal
From: Boris Brezillon 

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).

Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 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

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index b85fca5628..6286b2e234 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -18,6 +18,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
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 95b03a29dc..7971adeb6f 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -8,6 +8,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
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
new file mode 100644
index 00..07ce799170
--- /dev/null
+++ b/drivers/spi/spi-mem.c
@@ -0,0 +1,500 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Exceet Electronics GmbH
+ * Copyright (C) 2018 Bootlin
+ *
+ * Author: Boris Brezillon 
+ */
+
+#ifndef __UBOOT__
+#include 
+#include 
+#include "internals.h"
+#else
+#include 
+#include 
+#endif
+
+#ifndef __UBOOT__
+/**
+ * spi_controller_dma_map_mem_op_data() - DMA-map the buffer attached to a
+ *   memory operation
+ * @ctlr: the SPI controller requesting this dma_map()
+ * @op: the memory operation containing the buffer to map
+ * @sgt: a pointer to a non-initialized sg_table that will be filled by this
+ *  function
+ *
+ * Some controllers might want to do DMA on the data buffer embedded in @op.
+ * This helper prepares everything for you and provides a ready-to-use
+ * sg_table. This function is not intended to be called from spi drivers.
+ * Only SPI controller drivers should use it.
+ * Note that the caller must ensure the memory region pointed by
+ * op->data.buf.{in,out} is DMA-able before calling this function.
+ *
+ * Return: 0 in case of success, a negative error code otherwise.
+ */
+int spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr,
+  const struct spi_mem_op *op,
+  struct sg_table *sgt)
+{
+   struct device *dmadev;
+
+   if (!op->data.nbytes)
+   return -EINVAL;
+
+   if (op->data.dir == SPI_MEM_DATA_OUT && ctlr->dma_tx)
+   dmadev = ctlr->dma_tx->device->dev;
+   else if (op->data.dir == SPI_MEM_DATA_IN && ctlr->dma_rx)
+   dmadev = ctlr->dma_rx->device->dev;
+   else
+   dmadev = ctlr->dev.parent;
+
+   if (!dmadev)
+   return -EINVAL;
+
+   return spi_map_buf(ctlr, dmadev, sgt, op->data.buf.in, op->data.nbytes,
+  op->data.dir == SPI_MEM_DATA_IN ?
+  DMA_FROM_DEVICE : DMA_TO_DEVICE);
+}
+EXPORT_SYMBOL_GPL(spi_controller_dma_map_mem_op_data);
+
+/**
+ * spi_controller_dma_unmap_mem_op_data() - DMA-unmap the buffer attached to a
+ * memory operation
+ * @ctlr: the SPI controller requesting this dma_unmap()
+ * @op: the memory operation containing the buffer to unmap
+ * @sgt: a pointer to an sg_table previously initialized by
+ *  spi_controller_dma_map_mem_op_data()
+ *
+ * Some controllers might want to do DMA on the data buffer embedded in @op.
+ * This helper prepares things so that the CPU can access the
+ * op->data.buf.{in,out} buffer again.
+ *
+ * This function is not intended to be called from SPI drivers. Only SPI
+ * controller drivers should use it.
+ *
+ * This function should be called after the DMA operation has finished and is
+ * only valid if the previous spi_controller_dma_map_mem_op_data() call
+ * returned 0.
+ *
+ * Return: 0 in case of success, a negative 

[U-Boot] [PATCH v6 25/27] mtd: uclass: add probe function

2018-08-01 Thread 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.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 drivers/mtd/mtd-uclass.c | 9 +
 include/linux/mtd/mtd.h  | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/drivers/mtd/mtd-uclass.c b/drivers/mtd/mtd-uclass.c
index 9ca049c437..9a9470410c 100644
--- a/drivers/mtd/mtd-uclass.c
+++ b/drivers/mtd/mtd-uclass.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -13,6 +14,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",
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 6771ee2586..7dd45bde65 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -533,5 +533,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__ */
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 16/27] mtd: spinand: Add initial support for Winbond W25M02GV

2018-08-01 Thread Miquel Raynal
From: Frieder Schrempf 

Add support for the W25M02GV chip.

Signed-off-by: Frieder Schrempf 
Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 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

diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile
index 4eb745abd4..11ba5de68b 100644
--- a/drivers/mtd/nand/spi/Makefile
+++ b/drivers/mtd/nand/spi/Makefile
@@ -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
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 36b8b52bc2..ef3e6445d8 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -831,6 +831,7 @@ static const struct nand_ops spinand_ops = {
 
 static const struct spinand_manufacturer *spinand_manufacturers[] = {
_spinand_manufacturer,
+   _spinand_manufacturer,
 };
 
 static int spinand_manufacturer_detect(struct spinand_device *spinand)
diff --git a/drivers/mtd/nand/spi/winbond.c b/drivers/mtd/nand/spi/winbond.c
new file mode 100644
index 00..eac811d97c
--- /dev/null
+++ b/drivers/mtd/nand/spi/winbond.c
@@ -0,0 +1,143 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2017 exceet electronics GmbH
+ *
+ * Authors:
+ * Frieder Schrempf 
+ * Boris Brezillon 
+ */
+
+#ifndef __UBOOT__
+#include 
+#include 
+#endif
+#include 
+
+#define SPINAND_MFR_WINBOND0xEF
+
+#define WINBOND_CFG_BUF_READ   BIT(3)
+
+static SPINAND_OP_VARIANTS(read_cache_variants,
+   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
+
+static SPINAND_OP_VARIANTS(write_cache_variants,
+   SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
+   SPINAND_PROG_LOAD(true, 0, NULL, 0));
+
+static SPINAND_OP_VARIANTS(update_cache_variants,
+   SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
+   SPINAND_PROG_LOAD(false, 0, NULL, 0));
+
+static int w25m02gv_ooblayout_ecc(struct mtd_info *mtd, int section,
+ struct mtd_oob_region *region)
+{
+   if (section > 3)
+   return -ERANGE;
+
+   region->offset = (16 * section) + 8;
+   region->length = 8;
+
+   return 0;
+}
+
+static int w25m02gv_ooblayout_free(struct mtd_info *mtd, int section,
+  struct mtd_oob_region *region)
+{
+   if (section > 3)
+   return -ERANGE;
+
+   region->offset = (16 * section) + 2;
+   region->length = 6;
+
+   return 0;
+}
+
+static const struct mtd_ooblayout_ops w25m02gv_ooblayout = {
+   .ecc = w25m02gv_ooblayout_ecc,
+   .free = w25m02gv_ooblayout_free,
+};
+
+static int w25m02gv_select_target(struct spinand_device *spinand,
+ unsigned int target)
+{
+   struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(0xc2, 1),
+ SPI_MEM_OP_NO_ADDR,
+ SPI_MEM_OP_NO_DUMMY,
+ SPI_MEM_OP_DATA_OUT(1,
+   spinand->scratchbuf,
+   1));
+
+   *spinand->scratchbuf = target;
+   return spi_mem_exec_op(spinand->slave, );
+}
+
+static const struct spinand_info winbond_spinand_table[] = {
+   SPINAND_INFO("W25M02GV", 0xAB,
+NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 2),
+NAND_ECCREQ(1, 512),
+SPINAND_INFO_OP_VARIANTS(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+0,
+SPINAND_ECCINFO(_ooblayout, NULL),
+SPINAND_SELECT_TARGET(w25m02gv_select_target)),
+};
+
+/**
+ * winbond_spinand_detect - initialize device related part in spinand_device
+ * struct if it is a Winbond device.
+ * @spinand: SPI NAND device structure
+ */
+static int winbond_spinand_detect(struct spinand_device *spinand)
+{
+   u8 *id = spinand->id.data;
+   int ret;
+
+   /*
+* Winbond SPI NAND read ID need a dummy byte,
+* so the first byte in raw_id is dummy.
+*/
+   if (id[1] != SPI

[U-Boot] [PATCH v6 09/27] mtd: move NAND files into a raw/ subdirectory

2018-08-01 Thread 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.

Documentation, README*, and MAINTAINERS files are updated accordingly.

Signed-off-by: Miquel Raynal 
---
 MAINTAINERS   |   6 +-
 Makefile  |   2 +-
 README|   6 +-
 arch/arm/mach-uniphier/board_late_init.c  |   2 +-
 common/spl/Kconfig|   2 +-
 common/spl/spl_spi.c  |   2 +-
 doc/README.SPL|   4 +-
 doc/README.arm-relocation |   2 +-
 doc/README.nand   |   6 +-
 doc/README.zynq   |   2 +-
 drivers/Makefile  |   2 +-
 drivers/mtd/Makefile  |   2 +
 drivers/mtd/nand/Kconfig  | 298 +-
 drivers/mtd/nand/Makefile |  75 ---
 drivers/mtd/nand/raw/Kconfig  | 297 +
 drivers/mtd/nand/raw/Makefile |  77 +++
 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 |   2 +-
 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.h |   0
 drivers/mtd/nand/{ => raw}/mxs_nand_dt.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 |   2 +-
 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|   2 +-
 drivers/mtd/nand/{ => raw}/omap_elm.c |   0
 drivers/mtd/nand/{ => raw}/omap_gpmc.c|   0
 drivers/mtd/nand/{ => raw}/pxa3xx_nand.c  |   2 +-
 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
 include/configs/MPC8313ERDB.h |   2 +-
 66 files changed, 400 insertions(+), 395 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 (99%)
 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 (

[U-Boot] [PATCH v6 08/27] mtd: move all flash categories inside MTD submenu

2018-08-01 Thread Miquel Raynal
There is no reason to have NAND, SPI flashes and UBI sections outside of
the MTD submenu in Kconfig.

Signed-off-by: Miquel Raynal 
Reviewed-by: Jagan Teki 
---
 drivers/mtd/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 41f8883ec2..9341d518f3 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -59,10 +59,10 @@ config RENESAS_RPC_HF
  This enables access to Hyperflash memory through the Renesas
  RCar Gen3 RPC controller.
 
-endmenu
-
 source "drivers/mtd/nand/Kconfig"
 
 source "drivers/mtd/spi/Kconfig"
 
 source "drivers/mtd/ubi/Kconfig"
+
+endmenu
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 10/27] mtd: rename nand into rawnand in Kconfig prompt

2018-08-01 Thread Miquel Raynal
Sync the Kconfig raw NAND entry title with the code architecture.

Signed-off-by: Miquel Raynal 
---
 drivers/mtd/nand/raw/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig
index 1e4ea7bdd4..008f7b4b4b 100644
--- a/drivers/mtd/nand/raw/Kconfig
+++ b/drivers/mtd/nand/raw/Kconfig
@@ -1,6 +1,6 @@
 
 menuconfig NAND
-   bool "NAND Device Support"
+   bool "Raw NAND Device Support"
 if NAND
 
 config SYS_NAND_SELF_INIT
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 05/27] mtd: add get/set of_node/flash_node helpers

2018-08-01 Thread Miquel Raynal
From: Brian Norris 

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.

Signed-off-by: Brian Norris 
Reviewed-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Reviewed-by: Jagan Teki 
---
 include/linux/mtd/mtd.h | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index eb39f38887..ea659c354b 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -306,6 +306,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,
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 12/27] mtd: nand: Pass mode information to nand_page_io_req

2018-08-01 Thread Miquel Raynal
From: Boris Brezillon 

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.

Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
---
 include/linux/mtd/nand.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index ada7af4a41..13e8dd1103 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -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, >req.pos);
iter->req.ooboffs = req->ooboffs;
iter->oobbytes_per_page = mtd_oobavail(mtd, req);
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 03/27] mtd: Add sanity checks in mtd_write/read_oob()

2018-08-01 Thread Miquel Raynal
From: Boris Brezillon 

Unlike what's done in mtd_read/write(), there are no checks to make sure
the parameters passed to mtd_read/write_oob() are consistent, which
forces implementers of ->_read/write_oob() to do it, which in turn leads
to code duplication and possibly errors in the logic.

Do general sanity checks, like ops fields consistency and range checking.

Signed-off-by: Boris Brezillon 
Cc: Peter Pan 
Signed-off-by: Richard Weinberger 
[Miquel: squashed the fix about the chip's size check]
Signed-off-by: Miquel Raynal 
---
 drivers/mtd/mtdcore.c | 45 +
 1 file changed, 45 insertions(+)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index ad61406dac..9a3efe95df 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1010,12 +1010,50 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, 
size_t len, size_t *retlen,
 }
 EXPORT_SYMBOL_GPL(mtd_panic_write);
 
+static int mtd_check_oob_ops(struct mtd_info *mtd, loff_t offs,
+struct mtd_oob_ops *ops)
+{
+   /*
+* Some users are setting ->datbuf or ->oobbuf to NULL, but are leaving
+* ->len or ->ooblen uninitialized. Force ->len and ->ooblen to 0 in
+*  this case.
+*/
+   if (!ops->datbuf)
+   ops->len = 0;
+
+   if (!ops->oobbuf)
+   ops->ooblen = 0;
+
+   if (offs < 0 || offs + ops->len > mtd->size)
+   return -EINVAL;
+
+   if (ops->ooblen) {
+   u64 maxooblen;
+
+   if (ops->ooboffs >= mtd_oobavail(mtd, ops))
+   return -EINVAL;
+
+   maxooblen = ((mtd_div_by_ws(mtd->size, mtd) -
+ mtd_div_by_ws(offs, mtd)) *
+mtd_oobavail(mtd, ops)) - ops->ooboffs;
+   if (ops->ooblen > maxooblen)
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
 int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
 {
int ret_code;
ops->retlen = ops->oobretlen = 0;
if (!mtd->_read_oob)
return -EOPNOTSUPP;
+
+   ret_code = mtd_check_oob_ops(mtd, from, ops);
+   if (ret_code)
+   return ret_code;
+
/*
 * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics
 * similar to mtd->_read(), returning a non-negative integer
@@ -1034,11 +1072,18 @@ EXPORT_SYMBOL_GPL(mtd_read_oob);
 int mtd_write_oob(struct mtd_info *mtd, loff_t to,
struct mtd_oob_ops *ops)
 {
+   int ret;
+
ops->retlen = ops->oobretlen = 0;
if (!mtd->_write_oob)
return -EOPNOTSUPP;
if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS;
+
+   ret = mtd_check_oob_ops(mtd, to, ops);
+   if (ret)
+   return ret;
+
return mtd->_write_oob(mtd, to, ops);
 }
 EXPORT_SYMBOL_GPL(mtd_write_oob);
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 06/27] mtd: fix build issue with includes

2018-08-01 Thread Miquel Raynal
Fix build errors produced by mtd.h and dm/device.h if not included in
the right order.

Signed-off-by: Miquel Raynal 
Reviewed-by: Jagan Teki 
---
 include/linux/mtd/mtd.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index ea659c354b..8def104627 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define MAX_MTD_DEVICES 32
 #endif
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 07/27] mtd: move definitions to enlarge their range

2018-08-01 Thread Miquel Raynal
Some helpers might be useful in a future 'mtd' U-Boot command to parse
MTD device list.

Signed-off-by: Miquel Raynal 
---
 drivers/mtd/mtdcore.h   | 6 --
 include/linux/mtd/mtd.h | 6 ++
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/mtdcore.h b/drivers/mtd/mtdcore.h
index 7b0353399a..1d181a1045 100644
--- a/drivers/mtd/mtdcore.h
+++ b/drivers/mtd/mtdcore.h
@@ -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))
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 8def104627..6771ee2586 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -517,6 +517,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,
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 04/27] mtd: Fallback to ->_read/write() when ->_read/write_oob() is missing

2018-08-01 Thread Miquel Raynal
Some MTD sublayers/drivers are implementing ->_read/write() and
not ->_read/write_oob().

While for NAND devices both are usually valid, for NOR devices, using
the _oob variant has no real meaning. But, as the MTD layer is supposed
to hide as much as possible the flash complexity to the user, there is
no reason to error out while it is just a matter of rewritting things
internally.

Add a fallback on mtd->_read() (resp. mtd->_write()) when the user calls
mtd_read_oob() (resp. mtd_write_oob()) while mtd->_read_oob() (resp.
mtd->_write_oob) is not implemented. There is already a fallback on the
_oob variant if the former is used.

Signed-off-by: Miquel Raynal 
---
 drivers/mtd/mtdcore.c | 26 --
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 9a3efe95df..fb1d68d5e2 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1047,20 +1047,27 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, 
struct mtd_oob_ops *ops)
 {
int ret_code;
ops->retlen = ops->oobretlen = 0;
-   if (!mtd->_read_oob)
-   return -EOPNOTSUPP;
 
ret_code = mtd_check_oob_ops(mtd, from, ops);
if (ret_code)
return ret_code;
 
+   /* Check the validity of a potential fallback on mtd->_read */
+   if (!mtd->_read_oob && (!mtd->_read || ops->oobbuf))
+   return -EOPNOTSUPP;
+
+   if (mtd->_read_oob)
+   ret_code = mtd->_read_oob(mtd, from, ops);
+   else
+   ret_code = mtd->_read(mtd, from, ops->len, >retlen,
+ ops->datbuf);
+
/*
 * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics
 * similar to mtd->_read(), returning a non-negative integer
 * representing max bitflips. In other cases, mtd->_read_oob() may
 * return -EUCLEAN. In all cases, perform similar logic to mtd_read().
 */
-   ret_code = mtd->_read_oob(mtd, from, ops);
if (unlikely(ret_code < 0))
return ret_code;
if (mtd->ecc_strength == 0)
@@ -1075,8 +1082,7 @@ int mtd_write_oob(struct mtd_info *mtd, loff_t to,
int ret;
 
ops->retlen = ops->oobretlen = 0;
-   if (!mtd->_write_oob)
-   return -EOPNOTSUPP;
+
if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS;
 
@@ -1084,7 +1090,15 @@ int mtd_write_oob(struct mtd_info *mtd, loff_t to,
if (ret)
return ret;
 
-   return mtd->_write_oob(mtd, to, ops);
+   /* Check the validity of a potential fallback on mtd->_write */
+   if (!mtd->_write_oob && (!mtd->_write || ops->oobbuf))
+   return -EOPNOTSUPP;
+
+   if (mtd->_write_oob)
+   return mtd->_write_oob(mtd, to, ops);
+   else
+   return mtd->_write(mtd, to, ops->len, >retlen,
+  ops->datbuf);
 }
 EXPORT_SYMBOL_GPL(mtd_write_oob);
 
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 01/27] mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing

2018-08-01 Thread Miquel Raynal
From: Boris Brezillon 

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.

Signed-off-by: Boris Brezillon 
Acked-by: Robert Jarzmik 
Acked-by: Brian Norris 
Reviewed-by: Miquel Raynal 
Tested-by: Ladislav Michl 
Signed-off-by: Miquel Raynal 
Reviewed-by: Jagan Teki 
---
 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(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 6217be2352..60ad28efd4 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -937,7 +937,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, );
+   *retlen = ops.retlen;
+   } else {
+   return -ENOTSUPP;
+   }
+
if (unlikely(ret_code < 0))
return ret_code;
if (mtd->ecc_strength == 0)
@@ -952,10 +965,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, );
+   *retlen = ops.retlen;
+   return ret;
+   }
+
return mtd->_write(mtd, to, len, retlen, buf);
 }
 EXPORT_SYMBOL_GPL(mtd_write);
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index f87c962205..ccbb1757ea 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -417,8 +417,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 (master->_read)
+   slave->mtd._read = part_read;
+   if (master->_write)
+   slave->mtd._write = part_write;
 
if (master->_panic_write)
slave->mtd._panic_write = part_panic_write;
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 64e4621aaa..0b58e15b03 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1863,33 +1863,6 @@ read_retry:
return max_bitflips;
 }
 
-/**
- * nand_read - [MTD Interface] MTD compatibility function for nand_do_read_ecc
- * @mtd: MTD device structure
- * @from: offset to read from
- * @len: number of bytes to read
- * @retlen: pointer to variable to store the number of read bytes
- * @buf: the databuffer to put data
- *
- * Get hold of the chip and call nand_do_read.
- */
-static int nand_read(struct mtd_info *mtd, loff_t from, size_t len,
-size_t *retlen, uint8_t *buf)
-{
-   struct mtd_oob_ops ops;
-   int ret;
-
-   nand_get_device(mtd, FL_READING);
-   memset(, 0, sizeof(ops));
-   ops.len = len;
-   ops.datbuf = buf;
-   ops.mode = MTD_OPS_PLACE_OOB;
-   ret = nand_do_read_ops(mtd, from, );
-   *retlen = ops.retlen;
-   nand_release_device(mtd);
-   return ret;
-}
-
 /**
  * nand_read_oob_std - [REPLACEABLE] the most common OOB data read function
  * @mtd: mtd info structure
@@ -2674,33 +2647,6 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t 
to, size_t len,
return ret;
 }
 
-/**
- * nand_write - [MTD Interface] NAND write with ECC
- * @mtd: MTD device structure
- * @to: offset to write to
- * @len: number of bytes to write
- * @retlen: pointer to variable to store the number of written bytes
- * @buf: the data to write
- *
- * NAND write with ECC.
- */
-static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,

[U-Boot] [PATCH v6 00/27] SPI-NAND support

2018-08-01 Thread 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:
- A few patches from Linux to resynchronize some areas of the MTD layer.
- 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.
- Support for spi-nand devices in mtdparts.

To test your SPI-NAND device with U-Boot simply follow these lines:

> setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)
> setenv mtdids spi-nand0=spi-nand0
> mtdparts # show the spi-nand device partitions
> ubi part bar # create a static UBI volume in the bar partition

Thanks,
Miquèl

Changes since v5:
-
* Included Boris fixup about the build issues.
* Added Rb/Ab tags from Jagan on patchs 20/21.

Changes since v4:
-
* Added Jagan's Acked-by tags to every patch related to the
  SPI-mem/SPI-NAND addition.
* Rebased on top of master.

Changes since v3:
-
* Fixed the debug messages in spi-mem to print either Rx or Tx data.
* Fixed a Kconfig error that prevented to build mtdparts with plain
  defconfig.
* Fixed a compilation error due to the above error that prevented one
  file to be compiled.
* Adapted the mtd command to probe MTD partitions also.
* Declared mtd_probe_devices() in a header so mtdparts or UBI could
  use it too (to probe all devices and MTD partitions in a clean way).
* As I worked on mtdparts, I found annoying and completely useless the
  fact that we need to prefix the environment variable with
  "mtdparts=". Canceled this obligation.
* Added one patch to allow spi-nand devices to be recognized by mtdparts
  (this is purely useless but needed to be done in order to use this
  command).
* Removed useless definitions of MTD device types in UBI code.
* Wrote a generic mtdparts environment variable parser, used by the mtd
  command.
* Used the mtd_probe_devices() function from get_mtd_info() in
  cmd/mtdparts.c to be sure the desired partition really does not exist
  (otherwise it will be probed and then found).

Changes since v2:
-
* Rebased on u-boot master branch.
* Removed extra-parenthesis in
  "mtd: Fallback to ->_read/write() when ->_read/write_oob() is missing"
* s/fiels/files/ in "mtd: move NAND fiels into a raw/ subdirectory"
* Do not describe generic SPI device properties in SPI NAND bindings.
* Changes in the mtd command:
  * Printing more information in 'mtd list' (device type, device
characteristics)
  * Switch to do_div() instead of '(u32)value64b % value32b' which only
worked because value32b was a power of 2.
  * Removed erase.chip option.
  * By default, erase/read/write happen on the full MTD device while a
dump will only work on a single page.

Changes since v1:
-
* Fixed the nand_memorg structure of the MX35LF2GE4AB chip.
* Added Reviewed-by tags from Jagan.
* Backported and squashed two patches fixing things in the SPI NAND core
  received on the Linux ML.
* Backported more changes in mtdcore.c from Linux.
* Added a patch to add a fallback on mtd->_read/_write() in mtdcore.c
  when mtd->_read/write_oob() is not supported.
* Removed the DT changes, useless as the DTs are not available in
  mainline yet.
* Addressed Boris/Stefan comments on the 'mtd' command.
* Added support for multi-pages OOB read/write.


Boris Brezillon (7):
  mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing
  mtd: Add sanity checks in mtd_write/read_oob()
  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

Ezequiel Garcia (1):
  mtd: Uninline mtd_write_oob and move it to mtdcore.c

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

Miquel Raynal (15):
  mtd: Fallback to ->_read/write() when ->_read/write_oob() is missing
  mtd

[U-Boot] [PATCH v6 02/27] mtd: Uninline mtd_write_oob and move it to mtdcore.c

2018-08-01 Thread Miquel Raynal
From: Ezequiel Garcia 

There's no reason for having mtd_write_oob inlined in mtd.h header.
Move it to mtdcore.c where it belongs.

Signed-off-by: Ezequiel Garcia 
Acked-by: Boris Brezillon 
Signed-off-by: Jacek Anaszewski 
Signed-off-by: Miquel Raynal 
---
 drivers/mtd/mtdcore.c   | 12 
 include/linux/mtd/mtd.h | 12 +---
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 60ad28efd4..ad61406dac 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1031,6 +1031,18 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, 
struct mtd_oob_ops *ops)
 }
 EXPORT_SYMBOL_GPL(mtd_read_oob);
 
+int mtd_write_oob(struct mtd_info *mtd, loff_t to,
+   struct mtd_oob_ops *ops)
+{
+   ops->retlen = ops->oobretlen = 0;
+   if (!mtd->_write_oob)
+   return -EOPNOTSUPP;
+   if (!(mtd->flags & MTD_WRITEABLE))
+   return -EROFS;
+   return mtd->_write_oob(mtd, to, ops);
+}
+EXPORT_SYMBOL_GPL(mtd_write_oob);
+
 /**
  * mtd_ooblayout_ecc - Get the OOB region definition of a specific ECC section
  * @mtd: MTD device structure
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 823e535b82..eb39f38887 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -351,17 +351,7 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, 
size_t len, size_t *retlen,
const u_char *buf);
 
 int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops);
-
-static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to,
-   struct mtd_oob_ops *ops)
-{
-   ops->retlen = ops->oobretlen = 0;
-   if (!mtd->_write_oob)
-   return -EOPNOTSUPP;
-   if (!(mtd->flags & MTD_WRITEABLE))
-   return -EROFS;
-   return mtd->_write_oob(mtd, to, ops);
-}
+int mtd_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops);
 
 int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
   struct otp_info *buf);
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v5 00/27] SPI-NAND support

2018-08-01 Thread Miquel Raynal
Hi Jagan,

Jagan Teki  wrote on Wed, 1 Aug 2018
11:55:19 +0530:

> On Wed, Aug 1, 2018 at 12:55 AM, Boris Brezillon
>  wrote:
> > Hi Jagan,
> >
> > On Tue, 31 Jul 2018 20:03:47 +0530
> > Jagan Teki  wrote:
> >  
> >> > Applied to u-boot-spi/master  
> >>
> >> Look like we have some build issues [1]?  
> >
> > Yep, I reproduced the issue. Looks like u-boot Makefile hierarchy is a
> > bit different from Linux one, and patch is breaking raw/parallel NAND
> > build. I fixed it up (see below diff). This diff should be merged in
> > patch 9, and you'll have to fix a few conflicts when rebasing. Here is
> > a branch [1] containing this fixup commit (placed just after the
> > offending one) in case you want to check the end result.  
> 
> Thanks, better send a patch v5.1 and point me where we need to apply
> with in the series so-that it can't break individual commits.

Thanks Boris for fixing the build, while I actually forgot some changes
in MAINTAINERS, doc, README...

The current way of compiling the NAND subsystem from the root Makefile
is clearly something to fix.

I'll send a v6 with Boris fixup included, you'll just have to apply.

Thanks,
Miquèl

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 00/27] SPI-NAND support

2018-07-31 Thread Miquel Raynal
Hi Jagan,

Stefan Roese  wrote on Tue, 31 Jul 2018 07:50:54 +0200:

> Hi Jagan,
> 
> On 31.07.2018 07:36, Jagan Teki wrote:
> 
> 
> 
>  Acked--by: Jagan Teki 
>   
> >>>
> >>> Thanks!
> >>>  
>  Can you rebase on master and send the needed patches or whole? Look
>  like some changes been added in drivers/mtd/nand/Kconfig  
> >>>
> >>>
> >>> I'll wait a bit for Stefan review also and I think I missed something
> >>> in mtdparts: old partitions are not freed when creating new ones.  
> > > Is this resolved with v5?  

Absolutely not, but I will fix it in a next series during the
stabilization cycle. Maybe I will rework a bit mtdparts too, to trash
the thin layer that handles the partitions to use in a much more
consistent way the MTD core.

> > >>  
> >> I'm back from vacation and am starting to work on this SPI NAND
> >> support again. Right now, I'm facing a problem with 32 Bytes
> >> missing when written to NAND and read back. Most likely a problem
> >> with my SPI driver which supports a maximum of 32 Bytes per SPI
> >> message (I'm using adjust_op_size() to adjust the max xfer size).
> > > Is it with kirkwood?  
> 
> No. Its with a new platform I'm currently working on (MediaTek
> MT7688 MIPS) - custom board. The platform and board port will be
> posted in a few days / weeks (once its ready).
> 
> >> As for waiting for my review comments, I would suggest to pull
> >> this patchset (once updated onto TOT) soon, as the merge window
> >> closes just today. We can fix issues later in this release cycle.
> >> Otherwise we need to postpone this series to the next release, which
> >> is of course also on option.
> > > If the issue is generic and it changed the current behavior on mtd or  
> > any other related areas, it's better to hold.  
> 
> AFAICT its not generic. The SPI NAND seems to be working for Miquel
> and its a new infrastructure. So chances for breaking an existing
> board / platform are pretty low.

I totally agree on this.

> By pulling this patchset now, we
> enable the possibility for implementing and testing it on other
> platforms sooner. Tom also seems to be willing to do so.

Jagan, I just saw your answer to the cover letter of the v5,
thanks for applying it.

Regards,
Miquèl
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 22/27] cmd: mtdparts: accept spi-nand devices

2018-07-30 Thread Miquel Raynal
Let spi-nand devices be recognized by mtdparts. This is superfluous
but a full mtdparts rework would be very time-consuming.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 cmd/mtdparts.c  | 13 -
 include/jffs2/load_kernel.h |  7 +--
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index 0da3afd75f..f26a761c99 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -37,7 +37,7 @@
  * mtdids=[,,...]
  *
  * := =
- *:= 'nand'|'nor'|'onenand'
+ *:= 'nand'|'nor'|'onenand'|'spi-nand'
  *   := mtd device number, 0...
  *:= unique device tag used by linux kernel to find mtd device 
(mtd->name)
  *
@@ -336,7 +336,7 @@ static int part_validate_eraseblock(struct mtdids *id, 
struct part_info *part)
 
if (!mtd->numeraseregions) {
/*
-* Only one eraseregion (NAND, OneNAND or uniform NOR),
+* Only one eraseregion (NAND, SPI-NAND, OneNAND or uniform 
NOR),
 * checking for alignment is easy here
 */
offset = part->offset;
@@ -1027,7 +1027,7 @@ static struct mtdids* id_find_by_mtd_id(const char 
*mtd_id, unsigned int mtd_id_
 }
 
 /**
- * Parse device id string  := 'nand'|'nor'|'onenand',
+ * Parse device id string  := 
'nand'|'nor'|'onenand'|'spi-nand',
  * return device type and number.
  *
  * @param id string describing device id
@@ -1051,6 +1051,9 @@ int mtd_id_parse(const char *id, const char **ret_id, u8 
*dev_type,
} else if (strncmp(p, "onenand", 7) == 0) {
*dev_type = MTD_DEV_TYPE_ONENAND;
p += 7;
+   } else if (strncmp(p, "spi-nand", 8) == 0) {
+   *dev_type = MTD_DEV_TYPE_SPINAND;
+   p += 8;
} else {
printf("incorrect device type in %s\n", id);
return 1;
@@ -1633,7 +1636,7 @@ static int parse_mtdids(const char *const ids)
while(p && (*p != '\0')) {
 
ret = 1;
-   /* parse 'nor'|'nand'|'onenand' */
+   /* parse 'nor'|'nand'|'onenand'|'spi-nand' */
if (mtd_id_parse(p, , , ) != 0)
break;
 
@@ -2109,7 +2112,7 @@ static char mtdparts_help_text[] =
"'mtdids' - linux kernel mtd device id <-> u-boot device id mapping\n\n"
"mtdids=[,,...]\n\n"
":= =\n"
-   "   := 'nand'|'nor'|'onenand'\n"
+   "   := 'nand'|'nor'|'onenand'|'spi-nand'\n"
"  := mtd device number, 0...\n"
"   := unique device tag used by linux kernel to find mtd 
device (mtd->name)\n\n"
"'mtdparts' - partition list\n\n"
diff --git a/include/jffs2/load_kernel.h b/include/jffs2/load_kernel.h
index 1ddff062ad..9346d7ee9f 100644
--- a/include/jffs2/load_kernel.h
+++ b/include/jffs2/load_kernel.h
@@ -15,9 +15,12 @@
 #define MTD_DEV_TYPE_NOR   0x0001
 #define MTD_DEV_TYPE_NAND  0x0002
 #define MTD_DEV_TYPE_ONENAND   0x0004
+#define MTD_DEV_TYPE_SPINAND   0x0008
 
-#define MTD_DEV_TYPE(type) ((type == MTD_DEV_TYPE_NAND) ? "nand" : \
-   (type == MTD_DEV_TYPE_ONENAND) ? "onenand" : "nor")
+#define MTD_DEV_TYPE(type) (type == MTD_DEV_TYPE_NAND ? "nand" :   \
+   (type == MTD_DEV_TYPE_NOR ? "nor" : \
+(type == MTD_DEV_TYPE_ONENAND ? "onenand" : \
+ "spi-nand"))) \
 
 struct mtd_device {
struct list_head link;
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 21/27] cmd: ubi: delete useless and misleading definitions

2018-07-30 Thread Miquel Raynal
These definitions are simply not used and are misleading because similar
definitions exist in jffs2/load_kernel.h and are used widely to define
MTD device types (which is, by the way, totally redundant with what the
MTD core does). Remove these definitions.

Signed-off-by: Miquel Raynal 
---
 cmd/ubi.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/cmd/ubi.c b/cmd/ubi.c
index 913f0f71fd..0a3405a3b1 100644
--- a/cmd/ubi.c
+++ b/cmd/ubi.c
@@ -27,11 +27,6 @@
 #undef ubi_msg
 #define ubi_msg(fmt, ...) printf("UBI: " fmt "\n", ##__VA_ARGS__)
 
-#define DEV_TYPE_NONE  0
-#define DEV_TYPE_NAND  1
-#define DEV_TYPE_ONENAND   2
-#define DEV_TYPE_NOR   3
-
 /* Private own data */
 static struct ubi_device *ubi;
 static char buffer[80];
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 25/27] mtd: uclass: add probe function

2018-07-30 Thread 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.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 drivers/mtd/mtd-uclass.c | 9 +
 include/linux/mtd/mtd.h  | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/drivers/mtd/mtd-uclass.c b/drivers/mtd/mtd-uclass.c
index 9ca049c437..9a9470410c 100644
--- a/drivers/mtd/mtd-uclass.c
+++ b/drivers/mtd/mtd-uclass.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -13,6 +14,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",
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 6771ee2586..7dd45bde65 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -533,5 +533,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__ */
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 18/27] mtd: spinand: Add initial support for the MX35LF2GE4AB chip

2018-07-30 Thread Miquel Raynal
Add support for the MX35LF2GE4AB chip, which is similar to its cousin
MX35LF1GE4AB, with two planes instead of one.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 drivers/mtd/nand/spi/macronix.c | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c
index dd351dcb6c..662c561e50 100644
--- a/drivers/mtd/nand/spi/macronix.c
+++ b/drivers/mtd/nand/spi/macronix.c
@@ -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[] 
= {
  _cache_variants,
  _cache_variants),
 SPINAND_HAS_QE_BIT,
-SPINAND_ECCINFO(_ooblayout,
+SPINAND_ECCINFO(_ooblayout,
 mx35lf1ge4ab_ecc_get_status)),
+   SPINAND_INFO("MX35LF2GE4AB", 0x22,
+NAND_MEMORG(1, 2048, 64, 64, 2048, 2, 1, 1),
+NAND_ECCREQ(4, 512),
+SPINAND_INFO_OP_VARIANTS(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+SPINAND_HAS_QE_BIT,
+SPINAND_ECCINFO(_ooblayout, NULL)),
 };
 
 static int macronix_spinand_detect(struct spinand_device *spinand)
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 27/27] cmd: mtdparts: try to probe the MTD devices as a fallback

2018-07-30 Thread Miquel Raynal
Current implementation of mtdparts command errors out if the desired MTD
device is not found. Fallback to the new probe function in this case
before erroring out.

This will the save the user the need to call something like 'mtd list'
before mtdparts.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 cmd/mtdparts.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index ef8588bd71..76f0138e4d 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -305,9 +305,15 @@ static int get_mtd_info(u8 type, u8 num, struct mtd_info 
**mtd)
 
sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(type), num);
*mtd = get_mtd_device_nm(mtd_dev);
-   if (IS_ERR(*mtd)) {
-   printf("Device %s not found!\n", mtd_dev);
-   return 1;
+   if (IS_ERR_OR_NULL(*mtd)) {
+#ifdef CONFIG_CMD_MTD
+   mtd_probe_devices();
+   *mtd = get_mtd_device_nm(mtd_dev);
+#endif
+   if (IS_ERR_OR_NULL(*mtd)) {
+   printf("Device %s not found!\n", mtd_dev);
+   return 1;
+   }
}
put_mtd_device(*mtd);
 
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 23/27] cmd: mtdparts: add a generic 'mtdparts' parser

2018-07-30 Thread Miquel Raynal
The current parser is very specific to U-Boot mtdparts implementation.
It does not use MTD structures like mtd_info and mtd_partition. Write
some kind of a wrapper around the current implementation to allow other
commands to benefit from this parsing in a user-friendly way.

This new command will allocate an mtd_partition array for each
successful call. This array must be freed after use by the caller.
The given 'mtdparts' buffer pointer will be moved forward to the next
MTD device (if any, it will point towards a '\0' character otherwise).

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 cmd/mtdparts.c | 71 ++
 include/linux/mtd/partitions.h |  3 ++
 2 files changed, 74 insertions(+)

diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index f26a761c99..27e84db0e4 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -78,6 +78,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #if defined(CONFIG_CMD_NAND)
 #include 
@@ -705,6 +706,76 @@ static int part_parse(const char *const partdef, const 
char **ret, struct part_i
return 0;
 }
 
+int mtdparts_parse_part(struct mtd_info *parent, const char **_mtdparts,
+   struct mtd_partition **_parts, int *_nb_parts)
+{
+   const char *mtdparts = *_mtdparts;
+   struct part_info *part_legacy;
+   struct mtd_partition *parts;
+   int cur_off = 0, cur_sz = 0;
+   int nb_parts = 0;
+   char *names;
+   int ret, idx;
+
+   *_parts = NULL;
+   *_nb_parts = 0;
+
+   /* First, iterate over the partitions until we know their number */
+   while (mtdparts[0] != '\0' && mtdparts[0] != ';') {
+   ret = part_parse(mtdparts, , _legacy);
+   if (ret)
+   return ret;
+
+   nb_parts++;
+   free(part_legacy);
+   }
+
+   /* Allocate an array of partitions to give back to the caller */
+   parts = malloc((sizeof(*parts) + 20) * nb_parts);
+   names = (char *)[nb_parts];
+   if (!parts) {
+   printf("Could not allocate enough space to save partitions 
meta-data\n");
+   return -ENOMEM;
+   }
+
+   /* Iterate again over each partition to save the data in our array */
+   for (idx = 0; idx < nb_parts; idx++) {
+   char *name;
+
+   ret = part_parse(*_mtdparts, _mtdparts, _legacy);
+   if (ret)
+   return ret;
+
+   name = [idx * 20];
+   strncpy(name, part_legacy->name, 20);
+   parts[idx].name = name;
+
+   parts[idx].size = part_legacy->size;
+   if (parts[idx].size == SIZE_REMAINING)
+   parts[idx].size = parent->size - cur_sz;
+   cur_sz += parts[idx].size;
+
+   parts[idx].offset = part_legacy->offset;
+   if (parts[idx].offset == OFFSET_NOT_SPECIFIED)
+   parts[idx].offset = cur_off;
+   cur_off += parts[idx].size;
+
+   parts[idx].mask_flags = part_legacy->mask_flags;
+   parts[idx].ecclayout = parent->ecclayout;
+
+   free(part_legacy);
+   }
+
+   /* Offset by one mtdparts to point to the next device if needed */
+   if (*_mtdparts[0] == ';')
+   _mtdparts++;
+
+   *_parts = parts;
+   *_nb_parts = nb_parts;
+
+   return 0;
+}
+
 /**
  * Check device number to be within valid range for given device type.
  *
diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
index ce0e8dbee4..0cf26ca945 100644
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -87,4 +87,7 @@ int mtd_add_partition(struct mtd_info *master, const char 
*name,
 int mtd_del_partition(struct mtd_info *master, int partno);
 uint64_t mtd_get_device_size(const struct mtd_info *mtd);
 
+int mtdparts_parse_part(struct mtd_info *parent, const char **_mtdparts,
+   struct mtd_partition **_parts, int *_nb_parts);
+
 #endif
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 24/27] cmd: mtdparts: remove useless 'mtdparts=' prefix

2018-07-30 Thread Miquel Raynal
All U-Boot users must define the mtdparts environment variable with:
setenv mtdparts mtdparts=...

This is a pure software limitation and is a complete non-sense. Remove
this limitation but keep the backward compatibility.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 cmd/mtdparts.c | 17 ++---
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index 27e84db0e4..ef8588bd71 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -44,7 +44,7 @@
  *
  * 'mtdparts' - partition list
  *
- * mtdparts=mtdparts=[;...]
+ * mtdparts=[mtdparts=][;...]
  *
  *   := :[,...]
  *:= unique device tag used by linux kernel to find mtd device 
(mtd->name)
@@ -62,11 +62,11 @@
  *
  * 1 NOR Flash, with 1 single writable partition:
  * mtdids=nor0=edb7312-nor
- * mtdparts=mtdparts=edb7312-nor:-
+ * mtdparts=[mtdparts=]edb7312-nor:-
  *
  * 1 NOR Flash with 2 partitions, 1 NAND with one
  * mtdids=nor0=edb7312-nor,nand0=edb7312-nand
- * mtdparts=mtdparts=edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
+ * mtdparts=[mtdparts=]edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
  *
  */
 
@@ -1167,9 +1167,6 @@ static int generate_mtdparts(char *buf, u32 buflen)
return 0;
}
 
-   strcpy(p, "mtdparts=");
-   p += 9;
-
list_for_each(dentry, ) {
dev = list_entry(dentry, struct mtd_device, link);
 
@@ -1640,11 +1637,9 @@ static int parse_mtdparts(const char *const mtdparts)
if (!p)
p = mtdparts;
 
-   if (strncmp(p, "mtdparts=", 9) != 0) {
-   printf("mtdparts variable doesn't start with 'mtdparts='\n");
-   return err;
-   }
-   p += 9;
+   /* Skip the useless prefix, if any */
+   if (strncmp(p, "mtdparts=", 9) == 0)
+   p += 9;
 
while (*p != '\0') {
err = 1;
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 26/27] cmd: mtd: add 'mtd' command

2018-07-30 Thread 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.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 cmd/Kconfig |   7 +
 cmd/Makefile|   1 +
 cmd/mtd.c   | 392 
 drivers/mtd/Makefile|   2 +-
 include/linux/mtd/mtd.h |   1 +
 5 files changed, 402 insertions(+), 1 deletion(-)
 create mode 100644 cmd/mtd.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 0cf530d923..45ead0ffce 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -848,6 +848,13 @@ config CMD_MMC_SWRITE
  Enable support for the "mmc swrite" command to write Android sparse
  images to eMMC.
 
+config CMD_MTD
+   bool "mtd"
+   depends on CMD_MTDPARTS
+   select MTD_PARTITIONS
+   help
+ MTD commands support.
+
 config CMD_NAND
bool "nand"
default y if NAND_SUNXI
diff --git a/cmd/Makefile b/cmd/Makefile
index 323f1fd2c7..32fd102189 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -90,6 +90,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
diff --git a/cmd/mtd.c b/cmd/mtd.c
new file mode 100644
index 00..221b12500f
--- /dev/null
+++ b/cmd/mtd.c
@@ -0,0 +1,392 @@
+// 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 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static void mtd_dump_buf(u8 *buf, uint len, uint offset)
+{
+   int i, j;
+
+   for (i = 0; i < len; ) {
+   printf("0x%08x:\t", offset + 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)
+{
+   /* Device */
+   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");
+
+   /* MTD information */
+   printf("\t> type: ");
+   switch (mtd->type) {
+   case MTD_RAM:
+   printf("RAM\n");
+   break;
+   case MTD_ROM:
+   printf("ROM\n");
+   break;
+   case MTD_NORFLASH:
+   printf("NOR flash\n");
+   break;
+   case MTD_NANDFLASH:
+   printf("NAND flash\n");
+   break;
+   case MTD_DATAFLASH:
+   printf("Data flash\n");
+   break;
+   case MTD_UBIVOLUME:
+   printf("UBI volume\n");
+   break;
+   case MTD_MLCNANDFLASH:
+   printf("MLC NAND flash\n");
+   break;
+   case MTD_ABSENT:
+   default:
+   printf("Unknown\n");
+   break;
+   }
+
+   printf("\t> Size: 0x%llx bytes\n", mtd->size);
+   printf("\t> Block: 0x%x bytes\n", mtd->erasesize);
+   printf("\t> Min I/O: 0x%x bytes\n", mtd->writesize);
+
+   if (mtd->oobsize) {
+   printf("\t> OOB size: %u bytes\n", mtd->oobsize);
+   printf("\t> OOB available: %u bytes\n", mtd->oobavail);
+   }
+
+   if (mtd->ecc_strength) {
+   printf("\t> ECC strength: %u bits\n", mtd->ecc_strength);
+   printf("\t> ECC step size: %u bytes\n", mtd->ecc_step_size);
+   printf("\t> Bitflip threshold: %u bits\n",
+  mtd->bitflip_threshold);
+   }
+}
+
+int mtd_probe_devices(void)
+{
+   const char *mtdparts = env_get("mtdparts");
+   struct udevice *dev;
+   int idx = 0;
+
+   /* Probe devices with DM compliant drivers */
+   while (!uclass_find_device(UCLASS_MTD, idx, ) && dev) {
+   mtd_probe(dev);
+   idx++;
+   }
+
+   /* Create the partitions defined in mtdparts, here the fun begins */
+
+   /* Ignore the extra 'm

[U-Boot] [PATCH v5 13/27] spi: Extend the core to ease integration of SPI memory controllers

2018-07-30 Thread Miquel Raynal
From: Boris Brezillon 

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).

Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 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

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index b85fca5628..6286b2e234 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -18,6 +18,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
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 95b03a29dc..7971adeb6f 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -8,6 +8,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
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
new file mode 100644
index 00..07ce799170
--- /dev/null
+++ b/drivers/spi/spi-mem.c
@@ -0,0 +1,500 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Exceet Electronics GmbH
+ * Copyright (C) 2018 Bootlin
+ *
+ * Author: Boris Brezillon 
+ */
+
+#ifndef __UBOOT__
+#include 
+#include 
+#include "internals.h"
+#else
+#include 
+#include 
+#endif
+
+#ifndef __UBOOT__
+/**
+ * spi_controller_dma_map_mem_op_data() - DMA-map the buffer attached to a
+ *   memory operation
+ * @ctlr: the SPI controller requesting this dma_map()
+ * @op: the memory operation containing the buffer to map
+ * @sgt: a pointer to a non-initialized sg_table that will be filled by this
+ *  function
+ *
+ * Some controllers might want to do DMA on the data buffer embedded in @op.
+ * This helper prepares everything for you and provides a ready-to-use
+ * sg_table. This function is not intended to be called from spi drivers.
+ * Only SPI controller drivers should use it.
+ * Note that the caller must ensure the memory region pointed by
+ * op->data.buf.{in,out} is DMA-able before calling this function.
+ *
+ * Return: 0 in case of success, a negative error code otherwise.
+ */
+int spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr,
+  const struct spi_mem_op *op,
+  struct sg_table *sgt)
+{
+   struct device *dmadev;
+
+   if (!op->data.nbytes)
+   return -EINVAL;
+
+   if (op->data.dir == SPI_MEM_DATA_OUT && ctlr->dma_tx)
+   dmadev = ctlr->dma_tx->device->dev;
+   else if (op->data.dir == SPI_MEM_DATA_IN && ctlr->dma_rx)
+   dmadev = ctlr->dma_rx->device->dev;
+   else
+   dmadev = ctlr->dev.parent;
+
+   if (!dmadev)
+   return -EINVAL;
+
+   return spi_map_buf(ctlr, dmadev, sgt, op->data.buf.in, op->data.nbytes,
+  op->data.dir == SPI_MEM_DATA_IN ?
+  DMA_FROM_DEVICE : DMA_TO_DEVICE);
+}
+EXPORT_SYMBOL_GPL(spi_controller_dma_map_mem_op_data);
+
+/**
+ * spi_controller_dma_unmap_mem_op_data() - DMA-unmap the buffer attached to a
+ * memory operation
+ * @ctlr: the SPI controller requesting this dma_unmap()
+ * @op: the memory operation containing the buffer to unmap
+ * @sgt: a pointer to an sg_table previously initialized by
+ *  spi_controller_dma_map_mem_op_data()
+ *
+ * Some controllers might want to do DMA on the data buffer embedded in @op.
+ * This helper prepares things so that the CPU can access the
+ * op->data.buf.{in,out} buffer again.
+ *
+ * This function is not intended to be called from SPI drivers. Only SPI
+ * controller drivers should use it.
+ *
+ * This function should be called after the DMA operation has finished and is
+ * only valid if the previous spi_controller_dma_map_mem_op_data() call
+ * returned 0.
+ *
+ * Return: 0 in case of success, a negative 

[U-Boot] [PATCH v5 12/27] mtd: nand: Pass mode information to nand_page_io_req

2018-07-30 Thread Miquel Raynal
From: Boris Brezillon 

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.

Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
---
 include/linux/mtd/nand.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index ada7af4a41..13e8dd1103 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -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, >req.pos);
iter->req.ooboffs = req->ooboffs;
iter->oobbytes_per_page = mtd_oobavail(mtd, req);
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 15/27] mtd: spinand: Add initial support for Micron MT29F2G01ABAGD

2018-07-30 Thread Miquel Raynal
From: Peter Pan 

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.

Signed-off-by: Peter Pan 
Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 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

diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile
index f0c6e69d2e..4eb745abd4 100644
--- a/drivers/mtd/nand/spi/Makefile
+++ b/drivers/mtd/nand/spi/Makefile
@@ -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
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 08f853ae11..36b8b52bc2 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -829,8 +829,25 @@ static const struct nand_ops spinand_ops = {
.isbad = spinand_isbad,
 };
 
+static const struct spinand_manufacturer *spinand_manufacturers[] = {
+   _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;
 }
 
diff --git a/drivers/mtd/nand/spi/micron.c b/drivers/mtd/nand/spi/micron.c
new file mode 100644
index 00..83951c5d0f
--- /dev/null
+++ b/drivers/mtd/nand/spi/micron.c
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2016-2017 Micron Technology, Inc.
+ *
+ * Authors:
+ * Peter Pan 
+ */
+
+#ifndef __UBOOT__
+#include 
+#include 
+#endif
+#include 
+
+#define SPINAND_MFR_MICRON 0x2c
+
+#define MICRON_STATUS_ECC_MASK GENMASK(7, 4)
+#define MICRON_STATUS_ECC_NO_BITFLIPS  (0 << 4)
+#define MICRON_STATUS_ECC_1TO3_BITFLIPS(1 << 4)
+#define MICRON_STATUS_ECC_4TO6_BITFLIPS(3 << 4)
+#define MICRON_STATUS_ECC_7TO8_BITFLIPS(5 << 4)
+
+static SPINAND_OP_VARIANTS(read_cache_variants,
+   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
+
+static SPINAND_OP_VARIANTS(write_cache_variants,
+   SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
+   SPINAND_PROG_LOAD(true, 0, NULL, 0));
+
+static SPINAND_OP_VARIANTS(update_cache_variants,
+   SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
+   SPINAND_PROG_LOAD(false, 0, NULL, 0));
+
+static int mt29f2g01abagd_ooblayout_ecc(struct mtd_info *mtd, int section,
+   struct mtd_oob_region *region)
+{
+   if (section)
+   return -ERANGE;
+
+   region->offset = 64;
+   region->length = 64;
+
+   return 0;
+}
+
+static int mt29f2g01abagd_ooblayout_free(struct mtd_info *mtd, int section,
+struct mtd_oob_region *region)
+{
+   if (section)
+   return -ERANGE;
+
+   /* Reserve 2 bytes for the BBM. */
+   region->offset = 2;
+   region->length = 62;
+
+   return 0;
+}
+
+static const struct mtd_ooblayout_ops mt29f2g01abagd_ooblayout = {
+   .ecc = mt29f2g01abagd_ooblayout_ecc,
+   .free = mt29f2g01abagd_ooblayout_free,
+};
+
+static int mt29f2g01abagd_ecc_get_status(struct spinand_device *spinand,
+u8 status)
+{
+   switch (status & MICRON_STATUS_ECC_MASK) {
+   case STATUS_ECC_NO_BITFLIPS:
+   return 0;
+
+   case STATUS_ECC_UNCOR_ERROR:
+   return -EBADMSG;
+
+   case MICRON_STATUS_ECC_1TO3_BITFLIPS:
+   return 3;
+
+   case MICRON_STATUS_ECC_4TO6_BITFLIPS:
+   return 6;
+
+   case MICRON_STATUS_ECC_7TO8_BITFLIPS:
+   return 8;
+
+   default:
+   break;
+   }
+
+   return -EINVAL;
+}
+
+static const struct spinand_info micron_spinand_table[] = {
+   SPINAND_INFO("MT29F2G01ABAGD", 0x24,
+NAND_MEMORG(1, 20

[U-Boot] [PATCH v5 20/27] mtd: declare MTD_PARTITIONS symbol in Kconfig

2018-07-30 Thread Miquel Raynal
UBI selects MTD_PARTITIONS which is the symbol to compile
drivers/mtd/mtdpart.c. Unfortunately, the symbol was not defined in
Kconfig and this worked only with board files defining it. Fix this by
adding a boolean in Kconfig so boards defined by defconfig files only
will work as expected.

Signed-off-by: Miquel Raynal 
---
 drivers/mtd/Kconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 9341d518f3..d98457e223 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -1,5 +1,8 @@
 menu "MTD Support"
 
+config MTD_PARTITIONS
+   bool
+
 config MTD
bool "Enable Driver Model for MTD drivers"
depends on DM
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 17/27] mtd: spinand: Add initial support for the MX35LF1GE4AB chip

2018-07-30 Thread Miquel Raynal
From: Boris Brezillon 

Add minimal support for the MX35LF1GE4AB SPI NAND chip.

Signed-off-by: Boris Brezillon 
Acked-by: Jagan Teki 
---
 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

diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile
index 11ba5de68b..a66edd9199 100644
--- a/drivers/mtd/nand/spi/Makefile
+++ b/drivers/mtd/nand/spi/Makefile
@@ -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
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index ef3e6445d8..362d104846 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -830,6 +830,7 @@ static const struct nand_ops spinand_ops = {
 };
 
 static const struct spinand_manufacturer *spinand_manufacturers[] = {
+   _spinand_manufacturer,
_spinand_manufacturer,
_spinand_manufacturer,
 };
diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c
new file mode 100644
index 00..dd351dcb6c
--- /dev/null
+++ b/drivers/mtd/nand/spi/macronix.c
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018 Macronix
+ *
+ * Author: Boris Brezillon 
+ */
+
+#ifndef __UBOOT__
+#include 
+#include 
+#endif
+#include 
+
+#define SPINAND_MFR_MACRONIX   0xC2
+
+static SPINAND_OP_VARIANTS(read_cache_variants,
+   SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
+
+static SPINAND_OP_VARIANTS(write_cache_variants,
+   SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
+   SPINAND_PROG_LOAD(true, 0, NULL, 0));
+
+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,
+ struct mtd_oob_region *region)
+{
+   return -ERANGE;
+}
+
+static int mx35lf1ge4ab_ooblayout_free(struct mtd_info *mtd, int section,
+  struct mtd_oob_region *region)
+{
+   if (section)
+   return -ERANGE;
+
+   region->offset = 2;
+   region->length = mtd->oobsize - 2;
+
+   return 0;
+}
+
+static const struct mtd_ooblayout_ops mx35lf1ge4ab_ooblayout = {
+   .ecc = mx35lf1ge4ab_ooblayout_ecc,
+   .free = mx35lf1ge4ab_ooblayout_free,
+};
+
+static int mx35lf1ge4ab_get_eccsr(struct spinand_device *spinand, u8 *eccsr)
+{
+   struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(0x7c, 1),
+ SPI_MEM_OP_NO_ADDR,
+ SPI_MEM_OP_DUMMY(1, 1),
+ SPI_MEM_OP_DATA_IN(1, eccsr, 1));
+
+   return spi_mem_exec_op(spinand->slave, );
+}
+
+static int mx35lf1ge4ab_ecc_get_status(struct spinand_device *spinand,
+  u8 status)
+{
+   struct nand_device *nand = spinand_to_nand(spinand);
+   u8 eccsr;
+
+   switch (status & STATUS_ECC_MASK) {
+   case STATUS_ECC_NO_BITFLIPS:
+   return 0;
+
+   case STATUS_ECC_UNCOR_ERROR:
+   return -EBADMSG;
+
+   case STATUS_ECC_HAS_BITFLIPS:
+   /*
+* Let's try to retrieve the real maximum number of bitflips
+* in order to avoid forcing the wear-leveling layer to move
+* data around if it's not necessary.
+*/
+   if (mx35lf1ge4ab_get_eccsr(spinand, ))
+   return nand->eccreq.strength;
+
+   if (WARN_ON(eccsr > nand->eccreq.strength || !eccsr))
+   return nand->eccreq.strength;
+
+   return eccsr;
+
+   default:
+   break;
+   }
+
+   return -EINVAL;
+}
+
+static const struct spinand_info macronix_spinand_table[] = {
+   SPINAND_INFO("MX35LF1GE4AB", 0x12,
+NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
+NAND_ECCREQ(4, 512),
+SPINAND_INFO_OP_VARIANTS(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+SPINAND_HAS_QE_BIT,
+SPINAND_ECCINFO(_ooblayout,
+mx35lf1ge4ab_ecc_get_status)),
+};
+
+static int macronix_spinand_detect(struct 

[U-Boot] [PATCH v5 19/27] dt-bindings: Add bindings for SPI NAND devices

2018-07-30 Thread Miquel Raynal
From: Boris Brezillon 

Add bindings for SPI NAND chips.

Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 doc/device-tree-bindings/mtd/spi-nand.txt | 5 +
 1 file changed, 5 insertions(+)
 create mode 100644 doc/device-tree-bindings/mtd/spi-nand.txt

diff --git a/doc/device-tree-bindings/mtd/spi-nand.txt 
b/doc/device-tree-bindings/mtd/spi-nand.txt
new file mode 100644
index 00..8b51f3b6d5
--- /dev/null
+++ b/doc/device-tree-bindings/mtd/spi-nand.txt
@@ -0,0 +1,5 @@
+SPI NAND flash
+
+Required properties:
+- compatible: should be "spi-nand"
+- reg: should encode the chip-select line used to access the NAND chip
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 14/27] mtd: nand: Add core infrastructure to support SPI NANDs

2018-07-30 Thread Miquel Raynal
From: Peter Pan 

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

Signed-off-by: Peter Pan 
Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 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   | 1235 +
 include/linux/mtd/spinand.h   |  427 ++
 6 files changed, 1676 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

diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 1c1a1f487e..78ae04bdcb 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -2,3 +2,5 @@ config MTD_NAND_CORE
tristate
 
 source "drivers/mtd/nand/raw/Kconfig"
+
+source "drivers/mtd/nand/spi/Kconfig"
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index e07d0da46a..583e8880f3 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -3,3 +3,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/
diff --git a/drivers/mtd/nand/spi/Kconfig b/drivers/mtd/nand/spi/Kconfig
new file mode 100644
index 00..2197cb531f
--- /dev/null
+++ b/drivers/mtd/nand/spi/Kconfig
@@ -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.
diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile
new file mode 100644
index 00..f0c6e69d2e
--- /dev/null
+++ b/drivers/mtd/nand/spi/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+
+spinand-objs := core.o
+obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
new file mode 100644
index 00..08f853ae11
--- /dev/null
+++ b/drivers/mtd/nand/spi/core.c
@@ -0,0 +1,1235 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2016-2017 Micron Technology, Inc.
+ *
+ * Authors:
+ * Peter Pan 
+ * Boris Brezillon 
+ */
+
+#define pr_fmt(fmt)"spi-nand: " fmt
+
+#ifndef __UBOOT__
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#else
+#include 
+#include 
+#include 
+#include 
+#include 
+#endif
+
+/* SPI NAND index visible in MTD names */
+static int spi_nand_idx;
+
+static void spinand_cache_op_adjust_colum(struct spinand_device *spinand,
+ const struct nand_page_io_req *req,
+ u16 *column)
+{
+   struct nand_device *nand = spinand_to_nand(spinand);
+   unsigned int shift;
+
+   if (nand->memorg.planes_per_lun < 2)
+   return;
+
+   /* The plane number is passed in MSB just above the column address */
+   shift = fls(nand->memorg.pagesize);
+   *column |= req->pos.plane << shift;
+}
+
+static int spinand_read_reg_op(struct spinand_device *spinand, u8 reg, u8 *val)
+{
+   struct spi_mem_op op = SPINAND_GET_FEATURE_OP(reg,
+ spinand->scratchbuf);
+   int ret;
+
+   ret = spi_mem_exec_op(spinand->slave, );
+   if (ret)
+   return ret;
+
+   *val = *spinand->scratchbuf;
+   return 0;
+}
+
+static int spinand_write_reg_op(struct spinand_device *spinand, u8 reg, u8 val)
+{
+   struct spi_mem_op op = SPINAND_SET_FEATURE_OP(reg,
+ spinand->scratchbuf);
+
+   *spinand->scratchbuf = val;
+   return spi_mem_exec_op(spinand->slave, );
+}
+
+static int spinand_read_status(struct spinand_device *spinand, u8 *status)
+{
+   return spinand_read_reg_op(spinand, REG_STATUS, status);
+}
+
+static int spinand_get_cfg(struct spinand_device *spinand, u8 *cfg)
+{
+   struct nand_device *nand = spinand_to_nand(spinand);
+
+   if (WARN_ON(spinand->cur_target < 0 ||
+   spinand->cur_target >= nand->memorg.ntargets))
+   return -EINVAL;
+
+   *cfg = spinand->cfg_cache[spinand->cur_target];
+   return 0;
+}
+
+static int spinand_set_cfg(struct spinand_device *spinand, u8 cfg)
+{
+   struct nand_device *nand = spinand_to_nand(spinand);
+   int ret;
+
+   if (WARN_ON(spinand->cur_target < 0 ||
+   spinand->cur_target >= nand->memorg.ntargets)

[U-Boot] [PATCH v5 09/27] mtd: move NAND files into a raw/ subdirectory

2018-07-30 Thread 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.

Signed-off-by: Miquel Raynal 
---
 drivers/mtd/Makefile  |   2 +
 drivers/mtd/nand/Kconfig  | 298 +-
 drivers/mtd/nand/Makefile |  76 +--
 drivers/mtd/nand/raw/Kconfig  | 297 +
 drivers/mtd/nand/raw/Makefile |  77 +++
 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.h |   0
 drivers/mtd/nand/{ => raw}/mxs_nand_dt.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}/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
 54 files changed, 378 insertions(+), 372 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_

[U-Boot] [PATCH v5 10/27] mtd: rename nand into rawnand in Kconfig prompt

2018-07-30 Thread Miquel Raynal
Sync the Kconfig raw NAND entry title with the code architecture.

Signed-off-by: Miquel Raynal 
---
 drivers/mtd/nand/raw/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig
index 1e4ea7bdd4..008f7b4b4b 100644
--- a/drivers/mtd/nand/raw/Kconfig
+++ b/drivers/mtd/nand/raw/Kconfig
@@ -1,6 +1,6 @@
 
 menuconfig NAND
-   bool "NAND Device Support"
+   bool "Raw NAND Device Support"
 if NAND
 
 config SYS_NAND_SELF_INIT
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 11/27] mtd: nand: Add core infrastructure to deal with NAND devices

2018-07-30 Thread Miquel Raynal
From: Boris Brezillon 

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

Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 drivers/mtd/nand/Kconfig  |   3 +
 drivers/mtd/nand/Makefile |   2 +
 drivers/mtd/nand/bbt.c| 132 +
 drivers/mtd/nand/core.c   | 243 +++
 include/linux/mtd/nand.h  | 731 ++
 5 files changed,  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

diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 6d53734718..1c1a1f487e 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -1 +1,4 @@
+config MTD_NAND_CORE
+   tristate
+
 source "drivers/mtd/nand/raw/Kconfig"
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index 8b2d0e118d..e07d0da46a 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -1,3 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0+
 
+nandcore-objs := core.o bbt.o
+obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
 obj-$(CONFIG_MTD_NAND) += raw/
diff --git a/drivers/mtd/nand/bbt.c b/drivers/mtd/nand/bbt.c
new file mode 100644
index 00..7e0ad3190c
--- /dev/null
+++ b/drivers/mtd/nand/bbt.c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2017 Free Electrons
+ *
+ * Authors:
+ * Boris Brezillon 
+ * Peter Pan 
+ */
+
+#define pr_fmt(fmt)"nand-bbt: " fmt
+
+#include 
+#ifndef __UBOOT__
+#include 
+#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);
+   if (!nand->bbt.cache)
+   return -ENOMEM;
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_init);
+
+/**
+ * nanddev_bbt_cleanup() - Cleanup the BBT (Bad Block Table)
+ * @nand: NAND device
+ *
+ * Undoes what has been done in nanddev_bbt_init()
+ */
+void nanddev_bbt_cleanup(struct nand_device *nand)
+{
+   kfree(nand->bbt.cache);
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_cleanup);
+
+/**
+ * nanddev_bbt_update() - Update a BBT
+ * @nand: nand device
+ *
+ * Update the BBT. Currently a NOP function since on-flash bbt is not yet
+ * supported.
+ *
+ * Return: 0 in case of success, a negative error code otherwise.
+ */
+int nanddev_bbt_update(struct nand_device *nand)
+{
+   return 0;
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_update);
+
+/**
+ * nanddev_bbt_get_block_status() - Return the status of an eraseblock
+ * @nand: nand device
+ * @entry: the BBT entry
+ *
+ * Return: a positive number nand_bbt_block_status status or -%ERANGE if @entry
+ *is bigger than the BBT size.
+ */
+int nanddev_bbt_get_block_status(const struct nand_device *nand,
+unsigned int entry)
+{
+   unsigned int bits_per_block = fls(NAND_BBT_BLOCK_NUM_STATUS);
+   unsigned long *pos = nand->bbt.cache +
+((entry * bits_per_block) / BITS_PER_LONG);
+   unsigned int offs = (entry * bits_per_block) % BITS_PER_LONG;
+   unsigned long status;
+
+   if (entry >= nanddev_neraseblocks(nand))
+   return -ERANGE;
+
+   status = pos[0] >> offs;
+   if (bits_per_block + offs > BITS_PER_LONG)
+   status |= pos[1] << (BITS_PER_LONG - offs);
+
+   return status & GENMASK(bits_per_block - 1, 0);
+}
+EXPORT_SYMBOL_GPL(nanddev_bbt_get_block_status);
+
+/**
+ * nanddev_bbt_set_block_status() - Update the status of an eraseblock in the
+ * in-memory BBT
+ * @nand: nand device
+ * @entry: the BBT entry to update
+ * @status: the new status
+ *
+ * Update an entry of the in-memory BBT. If you want to push the updated BBT
+ * the NAND you should call nanddev_bbt_update().
+ *
+ * Return: 0 in case of success or -%ERANGE if @entry is bigger than the BBT
+ *size.
+ */
+int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,
+enum nand_bbt_block_status status)
+{
+   unsigned int bits_per_block = fls(NAND_BBT_BLOCK_NUM_STATUS);
+   unsigned long *pos = nand->bbt.cache +
+((entry * bits_per_block) / BITS_PER_LONG);
+   unsigned int offs = (entry * bits_per_block) % BITS_PER_LONG;
+   unsigned long val = status & GENMASK(bits_per_bl

[U-Boot] [PATCH v5 16/27] mtd: spinand: Add initial support for Winbond W25M02GV

2018-07-30 Thread Miquel Raynal
From: Frieder Schrempf 

Add support for the W25M02GV chip.

Signed-off-by: Frieder Schrempf 
Signed-off-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 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

diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile
index 4eb745abd4..11ba5de68b 100644
--- a/drivers/mtd/nand/spi/Makefile
+++ b/drivers/mtd/nand/spi/Makefile
@@ -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
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 36b8b52bc2..ef3e6445d8 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -831,6 +831,7 @@ static const struct nand_ops spinand_ops = {
 
 static const struct spinand_manufacturer *spinand_manufacturers[] = {
_spinand_manufacturer,
+   _spinand_manufacturer,
 };
 
 static int spinand_manufacturer_detect(struct spinand_device *spinand)
diff --git a/drivers/mtd/nand/spi/winbond.c b/drivers/mtd/nand/spi/winbond.c
new file mode 100644
index 00..eac811d97c
--- /dev/null
+++ b/drivers/mtd/nand/spi/winbond.c
@@ -0,0 +1,143 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2017 exceet electronics GmbH
+ *
+ * Authors:
+ * Frieder Schrempf 
+ * Boris Brezillon 
+ */
+
+#ifndef __UBOOT__
+#include 
+#include 
+#endif
+#include 
+
+#define SPINAND_MFR_WINBOND0xEF
+
+#define WINBOND_CFG_BUF_READ   BIT(3)
+
+static SPINAND_OP_VARIANTS(read_cache_variants,
+   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
+
+static SPINAND_OP_VARIANTS(write_cache_variants,
+   SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
+   SPINAND_PROG_LOAD(true, 0, NULL, 0));
+
+static SPINAND_OP_VARIANTS(update_cache_variants,
+   SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
+   SPINAND_PROG_LOAD(false, 0, NULL, 0));
+
+static int w25m02gv_ooblayout_ecc(struct mtd_info *mtd, int section,
+ struct mtd_oob_region *region)
+{
+   if (section > 3)
+   return -ERANGE;
+
+   region->offset = (16 * section) + 8;
+   region->length = 8;
+
+   return 0;
+}
+
+static int w25m02gv_ooblayout_free(struct mtd_info *mtd, int section,
+  struct mtd_oob_region *region)
+{
+   if (section > 3)
+   return -ERANGE;
+
+   region->offset = (16 * section) + 2;
+   region->length = 6;
+
+   return 0;
+}
+
+static const struct mtd_ooblayout_ops w25m02gv_ooblayout = {
+   .ecc = w25m02gv_ooblayout_ecc,
+   .free = w25m02gv_ooblayout_free,
+};
+
+static int w25m02gv_select_target(struct spinand_device *spinand,
+ unsigned int target)
+{
+   struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(0xc2, 1),
+ SPI_MEM_OP_NO_ADDR,
+ SPI_MEM_OP_NO_DUMMY,
+ SPI_MEM_OP_DATA_OUT(1,
+   spinand->scratchbuf,
+   1));
+
+   *spinand->scratchbuf = target;
+   return spi_mem_exec_op(spinand->slave, );
+}
+
+static const struct spinand_info winbond_spinand_table[] = {
+   SPINAND_INFO("W25M02GV", 0xAB,
+NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 2),
+NAND_ECCREQ(1, 512),
+SPINAND_INFO_OP_VARIANTS(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+0,
+SPINAND_ECCINFO(_ooblayout, NULL),
+SPINAND_SELECT_TARGET(w25m02gv_select_target)),
+};
+
+/**
+ * winbond_spinand_detect - initialize device related part in spinand_device
+ * struct if it is a Winbond device.
+ * @spinand: SPI NAND device structure
+ */
+static int winbond_spinand_detect(struct spinand_device *spinand)
+{
+   u8 *id = spinand->id.data;
+   int ret;
+
+   /*
+* Winbond SPI NAND read ID need a dummy byte,
+* so the first byte in raw_id is dummy.
+*/
+   if (id[1] != SPI

[U-Boot] [PATCH v5 04/27] mtd: Fallback to ->_read/write() when ->_read/write_oob() is missing

2018-07-30 Thread Miquel Raynal
Some MTD sublayers/drivers are implementing ->_read/write() and
not ->_read/write_oob().

While for NAND devices both are usually valid, for NOR devices, using
the _oob variant has no real meaning. But, as the MTD layer is supposed
to hide as much as possible the flash complexity to the user, there is
no reason to error out while it is just a matter of rewritting things
internally.

Add a fallback on mtd->_read() (resp. mtd->_write()) when the user calls
mtd_read_oob() (resp. mtd_write_oob()) while mtd->_read_oob() (resp.
mtd->_write_oob) is not implemented. There is already a fallback on the
_oob variant if the former is used.

Signed-off-by: Miquel Raynal 
---
 drivers/mtd/mtdcore.c | 26 --
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 9a3efe95df..fb1d68d5e2 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1047,20 +1047,27 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, 
struct mtd_oob_ops *ops)
 {
int ret_code;
ops->retlen = ops->oobretlen = 0;
-   if (!mtd->_read_oob)
-   return -EOPNOTSUPP;
 
ret_code = mtd_check_oob_ops(mtd, from, ops);
if (ret_code)
return ret_code;
 
+   /* Check the validity of a potential fallback on mtd->_read */
+   if (!mtd->_read_oob && (!mtd->_read || ops->oobbuf))
+   return -EOPNOTSUPP;
+
+   if (mtd->_read_oob)
+   ret_code = mtd->_read_oob(mtd, from, ops);
+   else
+   ret_code = mtd->_read(mtd, from, ops->len, >retlen,
+ ops->datbuf);
+
/*
 * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics
 * similar to mtd->_read(), returning a non-negative integer
 * representing max bitflips. In other cases, mtd->_read_oob() may
 * return -EUCLEAN. In all cases, perform similar logic to mtd_read().
 */
-   ret_code = mtd->_read_oob(mtd, from, ops);
if (unlikely(ret_code < 0))
return ret_code;
if (mtd->ecc_strength == 0)
@@ -1075,8 +1082,7 @@ int mtd_write_oob(struct mtd_info *mtd, loff_t to,
int ret;
 
ops->retlen = ops->oobretlen = 0;
-   if (!mtd->_write_oob)
-   return -EOPNOTSUPP;
+
if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS;
 
@@ -1084,7 +1090,15 @@ int mtd_write_oob(struct mtd_info *mtd, loff_t to,
if (ret)
return ret;
 
-   return mtd->_write_oob(mtd, to, ops);
+   /* Check the validity of a potential fallback on mtd->_write */
+   if (!mtd->_write_oob && (!mtd->_write || ops->oobbuf))
+   return -EOPNOTSUPP;
+
+   if (mtd->_write_oob)
+   return mtd->_write_oob(mtd, to, ops);
+   else
+   return mtd->_write(mtd, to, ops->len, >retlen,
+  ops->datbuf);
 }
 EXPORT_SYMBOL_GPL(mtd_write_oob);
 
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 08/27] mtd: move all flash categories inside MTD submenu

2018-07-30 Thread Miquel Raynal
There is no reason to have NAND, SPI flashes and UBI sections outside of
the MTD submenu in Kconfig.

Signed-off-by: Miquel Raynal 
Reviewed-by: Jagan Teki 
---
 drivers/mtd/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 41f8883ec2..9341d518f3 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -59,10 +59,10 @@ config RENESAS_RPC_HF
  This enables access to Hyperflash memory through the Renesas
  RCar Gen3 RPC controller.
 
-endmenu
-
 source "drivers/mtd/nand/Kconfig"
 
 source "drivers/mtd/spi/Kconfig"
 
 source "drivers/mtd/ubi/Kconfig"
+
+endmenu
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 05/27] mtd: add get/set of_node/flash_node helpers

2018-07-30 Thread Miquel Raynal
From: Brian Norris 

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.

Signed-off-by: Brian Norris 
Reviewed-by: Boris Brezillon 
Signed-off-by: Miquel Raynal 
Reviewed-by: Jagan Teki 
---
 include/linux/mtd/mtd.h | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index eb39f38887..ea659c354b 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -306,6 +306,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,
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 07/27] mtd: move definitions to enlarge their range

2018-07-30 Thread Miquel Raynal
Some helpers might be useful in a future 'mtd' U-Boot command to parse
MTD device list.

Signed-off-by: Miquel Raynal 
---
 drivers/mtd/mtdcore.h   | 6 --
 include/linux/mtd/mtd.h | 6 ++
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/mtdcore.h b/drivers/mtd/mtdcore.h
index 7b0353399a..1d181a1045 100644
--- a/drivers/mtd/mtdcore.h
+++ b/drivers/mtd/mtdcore.h
@@ -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))
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 8def104627..6771ee2586 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -517,6 +517,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,
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 06/27] mtd: fix build issue with includes

2018-07-30 Thread Miquel Raynal
Fix build errors produced by mtd.h and dm/device.h if not included in
the right order.

Signed-off-by: Miquel Raynal 
Reviewed-by: Jagan Teki 
---
 include/linux/mtd/mtd.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index ea659c354b..8def104627 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define MAX_MTD_DEVICES 32
 #endif
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 01/27] mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing

2018-07-30 Thread Miquel Raynal
From: Boris Brezillon 

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.

Signed-off-by: Boris Brezillon 
Acked-by: Robert Jarzmik 
Acked-by: Brian Norris 
Reviewed-by: Miquel Raynal 
Tested-by: Ladislav Michl 
Signed-off-by: Miquel Raynal 
Reviewed-by: Jagan Teki 
---
 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(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 6217be2352..60ad28efd4 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -937,7 +937,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, );
+   *retlen = ops.retlen;
+   } else {
+   return -ENOTSUPP;
+   }
+
if (unlikely(ret_code < 0))
return ret_code;
if (mtd->ecc_strength == 0)
@@ -952,10 +965,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, );
+   *retlen = ops.retlen;
+   return ret;
+   }
+
return mtd->_write(mtd, to, len, retlen, buf);
 }
 EXPORT_SYMBOL_GPL(mtd_write);
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index f87c962205..ccbb1757ea 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -417,8 +417,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 (master->_read)
+   slave->mtd._read = part_read;
+   if (master->_write)
+   slave->mtd._write = part_write;
 
if (master->_panic_write)
slave->mtd._panic_write = part_panic_write;
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 64e4621aaa..0b58e15b03 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1863,33 +1863,6 @@ read_retry:
return max_bitflips;
 }
 
-/**
- * nand_read - [MTD Interface] MTD compatibility function for nand_do_read_ecc
- * @mtd: MTD device structure
- * @from: offset to read from
- * @len: number of bytes to read
- * @retlen: pointer to variable to store the number of read bytes
- * @buf: the databuffer to put data
- *
- * Get hold of the chip and call nand_do_read.
- */
-static int nand_read(struct mtd_info *mtd, loff_t from, size_t len,
-size_t *retlen, uint8_t *buf)
-{
-   struct mtd_oob_ops ops;
-   int ret;
-
-   nand_get_device(mtd, FL_READING);
-   memset(, 0, sizeof(ops));
-   ops.len = len;
-   ops.datbuf = buf;
-   ops.mode = MTD_OPS_PLACE_OOB;
-   ret = nand_do_read_ops(mtd, from, );
-   *retlen = ops.retlen;
-   nand_release_device(mtd);
-   return ret;
-}
-
 /**
  * nand_read_oob_std - [REPLACEABLE] the most common OOB data read function
  * @mtd: mtd info structure
@@ -2674,33 +2647,6 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t 
to, size_t len,
return ret;
 }
 
-/**
- * nand_write - [MTD Interface] NAND write with ECC
- * @mtd: MTD device structure
- * @to: offset to write to
- * @len: number of bytes to write
- * @retlen: pointer to variable to store the number of written bytes
- * @buf: the data to write
- *
- * NAND write with ECC.
- */
-static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,

[U-Boot] [PATCH v5 03/27] mtd: Add sanity checks in mtd_write/read_oob()

2018-07-30 Thread Miquel Raynal
From: Boris Brezillon 

Unlike what's done in mtd_read/write(), there are no checks to make sure
the parameters passed to mtd_read/write_oob() are consistent, which
forces implementers of ->_read/write_oob() to do it, which in turn leads
to code duplication and possibly errors in the logic.

Do general sanity checks, like ops fields consistency and range checking.

Signed-off-by: Boris Brezillon 
Cc: Peter Pan 
Signed-off-by: Richard Weinberger 
[Miquel: squashed the fix about the chip's size check]
Signed-off-by: Miquel Raynal 
---
 drivers/mtd/mtdcore.c | 45 +
 1 file changed, 45 insertions(+)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index ad61406dac..9a3efe95df 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1010,12 +1010,50 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, 
size_t len, size_t *retlen,
 }
 EXPORT_SYMBOL_GPL(mtd_panic_write);
 
+static int mtd_check_oob_ops(struct mtd_info *mtd, loff_t offs,
+struct mtd_oob_ops *ops)
+{
+   /*
+* Some users are setting ->datbuf or ->oobbuf to NULL, but are leaving
+* ->len or ->ooblen uninitialized. Force ->len and ->ooblen to 0 in
+*  this case.
+*/
+   if (!ops->datbuf)
+   ops->len = 0;
+
+   if (!ops->oobbuf)
+   ops->ooblen = 0;
+
+   if (offs < 0 || offs + ops->len > mtd->size)
+   return -EINVAL;
+
+   if (ops->ooblen) {
+   u64 maxooblen;
+
+   if (ops->ooboffs >= mtd_oobavail(mtd, ops))
+   return -EINVAL;
+
+   maxooblen = ((mtd_div_by_ws(mtd->size, mtd) -
+ mtd_div_by_ws(offs, mtd)) *
+mtd_oobavail(mtd, ops)) - ops->ooboffs;
+   if (ops->ooblen > maxooblen)
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
 int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
 {
int ret_code;
ops->retlen = ops->oobretlen = 0;
if (!mtd->_read_oob)
return -EOPNOTSUPP;
+
+   ret_code = mtd_check_oob_ops(mtd, from, ops);
+   if (ret_code)
+   return ret_code;
+
/*
 * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics
 * similar to mtd->_read(), returning a non-negative integer
@@ -1034,11 +1072,18 @@ EXPORT_SYMBOL_GPL(mtd_read_oob);
 int mtd_write_oob(struct mtd_info *mtd, loff_t to,
struct mtd_oob_ops *ops)
 {
+   int ret;
+
ops->retlen = ops->oobretlen = 0;
if (!mtd->_write_oob)
return -EOPNOTSUPP;
if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS;
+
+   ret = mtd_check_oob_ops(mtd, to, ops);
+   if (ret)
+   return ret;
+
return mtd->_write_oob(mtd, to, ops);
 }
 EXPORT_SYMBOL_GPL(mtd_write_oob);
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 02/27] mtd: Uninline mtd_write_oob and move it to mtdcore.c

2018-07-30 Thread Miquel Raynal
From: Ezequiel Garcia 

There's no reason for having mtd_write_oob inlined in mtd.h header.
Move it to mtdcore.c where it belongs.

Signed-off-by: Ezequiel Garcia 
Acked-by: Boris Brezillon 
Signed-off-by: Jacek Anaszewski 
Signed-off-by: Miquel Raynal 
---
 drivers/mtd/mtdcore.c   | 12 
 include/linux/mtd/mtd.h | 12 +---
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 60ad28efd4..ad61406dac 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1031,6 +1031,18 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, 
struct mtd_oob_ops *ops)
 }
 EXPORT_SYMBOL_GPL(mtd_read_oob);
 
+int mtd_write_oob(struct mtd_info *mtd, loff_t to,
+   struct mtd_oob_ops *ops)
+{
+   ops->retlen = ops->oobretlen = 0;
+   if (!mtd->_write_oob)
+   return -EOPNOTSUPP;
+   if (!(mtd->flags & MTD_WRITEABLE))
+   return -EROFS;
+   return mtd->_write_oob(mtd, to, ops);
+}
+EXPORT_SYMBOL_GPL(mtd_write_oob);
+
 /**
  * mtd_ooblayout_ecc - Get the OOB region definition of a specific ECC section
  * @mtd: MTD device structure
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 823e535b82..eb39f38887 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -351,17 +351,7 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, 
size_t len, size_t *retlen,
const u_char *buf);
 
 int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops);
-
-static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to,
-   struct mtd_oob_ops *ops)
-{
-   ops->retlen = ops->oobretlen = 0;
-   if (!mtd->_write_oob)
-   return -EOPNOTSUPP;
-   if (!(mtd->flags & MTD_WRITEABLE))
-   return -EROFS;
-   return mtd->_write_oob(mtd, to, ops);
-}
+int mtd_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops);
 
 int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
   struct otp_info *buf);
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 00/27] SPI-NAND support

2018-07-30 Thread 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:
- A few patches from Linux to resynchronize some areas of the MTD layer.
- 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.
- Support for spi-nand devices in mtdparts.

To test your SPI-NAND device with U-Boot simply follow these lines:

> setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)
> setenv mtdids spi-nand0=spi-nand0
> mtdparts # show the spi-nand device partitions
> ubi part bar # create a static UBI volume in the bar partition

Thanks,
Miquèl

Changes since v4:
-
* Added Jagan's Acked-by tags to every patch related to the
  SPI-mem/SPI-NAND addition.
* Rebased on top of master.

Changes since v3:
-
* Fixed the debug messages in spi-mem to print either Rx or Tx data.
* Fixed a Kconfig error that prevented to build mtdparts with plain
  defconfig.
* Fixed a compilation error due to the above error that prevented one
  file to be compiled.
* Adapted the mtd command to probe MTD partitions also.
* Declared mtd_probe_devices() in a header so mtdparts or UBI could
  use it too (to probe all devices and MTD partitions in a clean way).
* As I worked on mtdparts, I found annoying and completely useless the
  fact that we need to prefix the environment variable with
  "mtdparts=". Canceled this obligation.
* Added one patch to allow spi-nand devices to be recognized by mtdparts
  (this is purely useless but needed to be done in order to use this
  command).
* Removed useless definitions of MTD device types in UBI code.
* Wrote a generic mtdparts environment variable parser, used by the mtd
  command.
* Used the mtd_probe_devices() function from get_mtd_info() in
  cmd/mtdparts.c to be sure the desired partition really does not exist
  (otherwise it will be probed and then found).

Changes since v2:
-
* Rebased on u-boot master branch.
* Removed extra-parenthesis in
  "mtd: Fallback to ->_read/write() when ->_read/write_oob() is missing"
* s/fiels/files/ in "mtd: move NAND fiels into a raw/ subdirectory"
* Do not describe generic SPI device properties in SPI NAND bindings.
* Changes in the mtd command:
  * Printing more information in 'mtd list' (device type, device
characteristics)
  * Switch to do_div() instead of '(u32)value64b % value32b' which only
worked because value32b was a power of 2.
  * Removed erase.chip option.
  * By default, erase/read/write happen on the full MTD device while a
dump will only work on a single page.

Changes since v1:
-
* Fixed the nand_memorg structure of the MX35LF2GE4AB chip.
* Added Reviewed-by tags from Jagan.
* Backported and squashed two patches fixing things in the SPI NAND core
  received on the Linux ML.
* Backported more changes in mtdcore.c from Linux.
* Added a patch to add a fallback on mtd->_read/_write() in mtdcore.c
  when mtd->_read/write_oob() is not supported.
* Removed the DT changes, useless as the DTs are not available in
  mainline yet.
* Addressed Boris/Stefan comments on the 'mtd' command.
* Added support for multi-pages OOB read/write.


Boris Brezillon (7):
  mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing
  mtd: Add sanity checks in mtd_write/read_oob()
  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

Ezequiel Garcia (1):
  mtd: Uninline mtd_write_oob and move it to mtdcore.c

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

Miquel Raynal (15):
  mtd: Fallback to ->_read/write() when ->_read/write_oob() is missing
  mtd: fix build issue with includes
  mtd: move definitions to enlarge their range
  mtd: move all flash categories inside MTD submenu

Re: [U-Boot] [PATCH v4 00/27] SPI-NAND support

2018-07-30 Thread Miquel Raynal
Hi Stefan, Tom,

Stefan Roese  wrote on Mon, 30 Jul 2018 17:11:49 +0200:

> Hi Miquel,
> Hi Jagan,
> 
> On 26.07.2018 09:29, Miquel Raynal wrote:
> > Hi Jagan,  
> > > Jagan Teki  wrote on Thu, 26 Jul 2018  
> > 11:00:56 +0530:  
> > >> On Fri, Jul 13, 2018 at 6:01 PM, Miquel Raynal  
> >>  wrote:  
> >>> 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:
> >>> - A few patches from Linux to resynchronize some areas of the MTD layer.
> >>> - 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.
> >>> - Support for spi-nand devices in mtdparts.
> >>>
> >>> To test your SPI-NAND device with U-Boot simply follow these lines:  
> >>>   >>>> setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)  
> >>>> setenv mtdids spi-nand0=spi-nand0
> >>>> mtdparts # show the spi-nand device partitions
> >>>> ubi part bar # create a static UBI volume in the bar partition  
> >>>
> >>> Thanks,
> >>> Miquèl
> >>>
> >>> Changes since v3:
> >>> -
> >>> * Fixed the debug messages in spi-mem to print either Rx or Tx data.
> >>> * Fixed a Kconfig error that prevented to build mtdparts with plain
> >>>defconfig.
> >>> * Fixed a compilation error due to the above error that prevented one
> >>>file to be compiled.
> >>> * Adapted the mtd command to probe MTD partitions also.
> >>> * Declared mtd_probe_devices() in a header so mtdparts or UBI could
> >>>use it too (to probe all devices and MTD partitions in a clean way).
> >>> * As I worked on mtdparts, I found annoying and completely useless the
> >>>fact that we need to prefix the environment variable with
> >>>"mtdparts=". Canceled this obligation.
> >>> * Added one patch to allow spi-nand devices to be recognized by mtdparts
> >>>(this is purely useless but needed to be done in order to use this
> >>>command).
> >>> * Removed useless definitions of MTD device types in UBI code.
> >>> * Wrote a generic mtdparts environment variable parser, used by the mtd
> >>>command.
> >>> * Used the mtd_probe_devices() function from get_mtd_info() in
> >>>cmd/mtdparts.c to be sure the desired partition really does not exist
> >>>(otherwise it will be probed and then found).
> >>>
> >>> Changes since v2:
> >>> -
> >>> * Rebased on u-boot master branch.
> >>> * Removed extra-parenthesis in
> >>>"mtd: Fallback to ->_read/write() when ->_read/write_oob() is missing"
> >>> * s/fiels/files/ in "mtd: move NAND fiels into a raw/ subdirectory"
> >>> * Do not describe generic SPI device properties in SPI NAND bindings.
> >>> * Changes in the mtd command:
> >>>* Printing more information in 'mtd list' (device type, device
> >>>  characteristics)
> >>>* Switch to do_div() instead of '(u32)value64b % value32b' which only
> >>>  worked because value32b was a power of 2.
> >>>* Removed erase.chip option.
> >>>* By default, erase/read/write happen on the full MTD device while a
> >>>  dump will only work on 

Re: [U-Boot] [PATCH v4 00/27] SPI-NAND support

2018-07-26 Thread Miquel Raynal
Hi Jagan,

Jagan Teki  wrote on Thu, 26 Jul 2018
11:00:56 +0530:

> On Fri, Jul 13, 2018 at 6:01 PM, Miquel Raynal
>  wrote:
> > 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:
> > - A few patches from Linux to resynchronize some areas of the MTD layer.
> > - 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.
> > - Support for spi-nand devices in mtdparts.
> >
> > To test your SPI-NAND device with U-Boot simply follow these lines:
> >  
> >> setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)
> >> setenv mtdids spi-nand0=spi-nand0
> >> mtdparts # show the spi-nand device partitions
> >> ubi part bar # create a static UBI volume in the bar partition  
> >
> > Thanks,
> > Miquèl
> >
> > Changes since v3:
> > -
> > * Fixed the debug messages in spi-mem to print either Rx or Tx data.
> > * Fixed a Kconfig error that prevented to build mtdparts with plain
> >   defconfig.
> > * Fixed a compilation error due to the above error that prevented one
> >   file to be compiled.
> > * Adapted the mtd command to probe MTD partitions also.
> > * Declared mtd_probe_devices() in a header so mtdparts or UBI could
> >   use it too (to probe all devices and MTD partitions in a clean way).
> > * As I worked on mtdparts, I found annoying and completely useless the
> >   fact that we need to prefix the environment variable with
> >   "mtdparts=". Canceled this obligation.
> > * Added one patch to allow spi-nand devices to be recognized by mtdparts
> >   (this is purely useless but needed to be done in order to use this
> >   command).
> > * Removed useless definitions of MTD device types in UBI code.
> > * Wrote a generic mtdparts environment variable parser, used by the mtd
> >   command.
> > * Used the mtd_probe_devices() function from get_mtd_info() in
> >   cmd/mtdparts.c to be sure the desired partition really does not exist
> >   (otherwise it will be probed and then found).
> >
> > Changes since v2:
> > -
> > * Rebased on u-boot master branch.
> > * Removed extra-parenthesis in
> >   "mtd: Fallback to ->_read/write() when ->_read/write_oob() is missing"
> > * s/fiels/files/ in "mtd: move NAND fiels into a raw/ subdirectory"
> > * Do not describe generic SPI device properties in SPI NAND bindings.
> > * Changes in the mtd command:
> >   * Printing more information in 'mtd list' (device type, device
> > characteristics)
> >   * Switch to do_div() instead of '(u32)value64b % value32b' which only
> > worked because value32b was a power of 2.
> >   * Removed erase.chip option.
> >   * By default, erase/read/write happen on the full MTD device while a
> > dump will only work on a single page.
> >
> > Changes since v1:
> > -
> > * Fixed the nand_memorg structure of the MX35LF2GE4AB chip.
> > * Added Reviewed-by tags from Jagan.
> > * Backported and squashed two patches fixing things in the SPI NAND core
> >   received on the Linux ML.
> > * Backported more changes in mtdcore.c from Linux.
> > * Added a patch to add a fallback on mtd->_read/_write() in mtdcore.c
> >   when mtd->_read/write_oob() is not supported.
> > * Removed the DT changes, useless as the DTs are not available in
> >   mainline yet.
> > * Addressed Boris/Stefan comments on the 'mtd' command.
> > * Added support for multi-pages OOB read/write.
> >
> >
> > Boris Brezillon (7):
> >   mtd

[U-Boot] [PATCH v2 6/7] tpm: make TPM_V2 be compiled by default

2018-07-19 Thread Miquel Raynal
TPM_V1 was already compiled by default. Now that both can be compiled
at the same time, compiled them both by default.

Signed-off-by: Miquel Raynal 
Reviewed-by: Simon Glass 
---
 drivers/tpm/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index 782a620f91..94629dffd2 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -120,6 +120,7 @@ endif # TPM_V1
 config TPM_V2
bool "TPMv2.x support"
depends on TPM
+   default y
help
  Major TPM versions are not compatible at all, choose either
  one or the other. This option enables TPMv2.x drivers/commands.
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 5/7] test/py: tpm2: switch from 'tpm' to 'tpm2' command

2018-07-19 Thread Miquel Raynal
While using the 'tpm' command should work on most cases, this test suite
only works with TPMv2 and since the work to make both versions build at
the same time, we might end up having both 'tpm' (TPMv1) and 'tpm2'
(TPMv2) commands available at the same time. Ensure this test suite
always use the right one.

Signed-off-by: Miquel Raynal 
Reviewed-by: Simon Glass 
---
 test/py/tests/test_tpm2.py | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/test/py/tests/test_tpm2.py b/test/py/tests/test_tpm2.py
index 01ffb3178d..3e1f42d83e 100644
--- a/test/py/tests/test_tpm2.py
+++ b/test/py/tests/test_tpm2.py
@@ -29,22 +29,22 @@ def force_init(u_boot_console, force=False):
 twice will spawn an error used to detect that the TPM was not reset and no
 initialization code should be run.
 """
-output = u_boot_console.run_command('tpm init')
+output = u_boot_console.run_command('tpm2 init')
 if force or not 'Error' in output:
 u_boot_console.run_command('echo --- start of init ---')
-u_boot_console.run_command('tpm startup TPM2_SU_CLEAR')
-u_boot_console.run_command('tpm self_test full')
-u_boot_console.run_command('tpm clear TPM2_RH_LOCKOUT')
+u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
+u_boot_console.run_command('tpm2 self_test full')
+u_boot_console.run_command('tpm2 clear TPM2_RH_LOCKOUT')
 output = u_boot_console.run_command('echo $?')
 if not output.endswith('0'):
-u_boot_console.run_command('tpm clear TPM2_RH_PLATFORM')
+u_boot_console.run_command('tpm2 clear TPM2_RH_PLATFORM')
 u_boot_console.run_command('echo --- end of init ---')
 
 @pytest.mark.buildconfigspec('cmd_tpm_v2')
 def test_tpm2_init(u_boot_console):
 """Init the software stack to use TPMv2 commands."""
 
-u_boot_console.run_command('tpm init')
+u_boot_console.run_command('tpm2 init')
 output = u_boot_console.run_command('echo $?')
 assert output.endswith('0')
 
@@ -55,7 +55,7 @@ def test_tpm2_startup(u_boot_console):
 Initiate the TPM internal state machine.
 """
 
-u_boot_console.run_command('tpm startup TPM2_SU_CLEAR')
+u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
 output = u_boot_console.run_command('echo $?')
 assert output.endswith('0')
 
@@ -66,7 +66,7 @@ def test_tpm2_self_test_full(u_boot_console):
 Ask the TPM to perform all self tests to also enable full capabilities.
 """
 
-u_boot_console.run_command('tpm self_test full')
+u_boot_console.run_command('tpm2 self_test full')
 output = u_boot_console.run_command('echo $?')
 assert output.endswith('0')
 
@@ -78,7 +78,7 @@ def test_tpm2_continue_self_test(u_boot_console):
 to enter a fully operational state.
 """
 
-u_boot_console.run_command('tpm self_test continue')
+u_boot_console.run_command('tpm2 self_test continue')
 output = u_boot_console.run_command('echo $?')
 assert output.endswith('0')
 
@@ -95,11 +95,11 @@ def test_tpm2_clear(u_boot_console):
 PLATFORM hierarchies are also available.
 """
 
-u_boot_console.run_command('tpm clear TPM2_RH_LOCKOUT')
+u_boot_console.run_command('tpm2 clear TPM2_RH_LOCKOUT')
 output = u_boot_console.run_command('echo $?')
 assert output.endswith('0')
 
-u_boot_console.run_command('tpm clear TPM2_RH_PLATFORM')
+u_boot_console.run_command('tpm2 clear TPM2_RH_PLATFORM')
 output = u_boot_console.run_command('echo $?')
 assert output.endswith('0')
 
@@ -115,13 +115,13 @@ def test_tpm2_change_auth(u_boot_console):
 
 force_init(u_boot_console)
 
-u_boot_console.run_command('tpm change_auth TPM2_RH_LOCKOUT unicorn')
+u_boot_console.run_command('tpm2 change_auth TPM2_RH_LOCKOUT unicorn')
 output = u_boot_console.run_command('echo $?')
 assert output.endswith('0')
 
-u_boot_console.run_command('tpm clear TPM2_RH_LOCKOUT unicorn')
+u_boot_console.run_command('tpm2 clear TPM2_RH_LOCKOUT unicorn')
 output = u_boot_console.run_command('echo $?')
-u_boot_console.run_command('tpm clear TPM2_RH_PLATFORM')
+u_boot_console.run_command('tpm2 clear TPM2_RH_PLATFORM')
 assert output.endswith('0')
 
 @pytest.mark.buildconfigspec('cmd_tpm_v2')
@@ -140,7 +140,7 @@ def test_tpm2_get_capability(u_boot_console):
 force_init(u_boot_console)
 ram = u_boot_utils.find_ram_base(u_boot_console)
 
-read_cap = u_boot_console.run_command('tpm get_capability 0x6 0x20e 0x200 
1') #0x%x 1' % ram)
+read_cap = u_boot_console.run_command('tpm2 get_capability 0x6 0x20e 0x200 
1') #0x%x 1' % ram)
 output = u_boot_console.run_command('echo $?')
 assert output.endswith('0')
 assert 'Property 0x020e: 0x' in read_cap
@@ -163,12 +163,12 @@ def test_tpm2_dam_parameters(u_boot

[U-Boot] [PATCH v2 4/7] tpm: allow TPM v1 and v2 to be compiled at the same time

2018-07-19 Thread Miquel Raynal
While there is probably no reason to do so in a real life situation, it
will allow to compile test both stacks with the same sandbox defconfig.

As we cannot define two 'tpm' commands at the same time, the command for
TPM v1 is still called 'tpm' and the one for TPM v2 'tpm2'. While this
is the exact command name that must be written into eg. test files, any
user already using the TPM v2 stack can continue to do so by just writing
'tpm' because as long as TPM v1 support is not compiled, U-Boot prompt
will search for the closest command named after 'tpm'.

The command set can also be changed at runtime (not supported yet, but
ready to be), but as one can compile only either one stack or the other,
there is still one spot in the code where conditionals are used: to
retrieve the v1 or v2 command set.

Signed-off-by: Miquel Raynal 
---
 cmd/tpm-common.c   | 24 +++-
 cmd/tpm-v1.c   |  2 +-
 cmd/tpm-v2.c   |  4 ++--
 drivers/tpm/Kconfig|  7 ++-
 drivers/tpm/tpm-uclass.c   |  3 ---
 drivers/tpm/tpm2_tis_sandbox.c |  3 +++
 drivers/tpm/tpm2_tis_spi.c |  4 
 include/tpm-common.h   | 40 ++--
 8 files changed, 69 insertions(+), 18 deletions(-)

diff --git a/cmd/tpm-common.c b/cmd/tpm-common.c
index 6cf9fcc9ac..56443862c2 100644
--- a/cmd/tpm-common.c
+++ b/cmd/tpm-common.c
@@ -273,12 +273,34 @@ int do_tpm_init(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
 int do_tpm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
cmd_tbl_t *tpm_commands, *cmd;
+   struct tpm_chip_priv *priv;
+   struct udevice *dev;
unsigned int size;
+   int ret;
 
if (argc < 2)
return CMD_RET_USAGE;
 
-   tpm_commands = get_tpm_commands();
+   ret = get_tpm();
+   if (ret)
+   return ret;
+
+   priv = dev_get_uclass_priv(dev);
+
+   /* Below getters return NULL if the desired stack is not built */
+   switch (priv->version) {
+   case TPM_V1:
+   tpm_commands = get_tpm1_commands();
+   break;
+   case TPM_V2:
+   tpm_commands = get_tpm2_commands();
+   break;
+   default:
+   tpm_commands = NULL;
+   }
+
+   if (!tpm_commands)
+   return CMD_RET_USAGE;
 
cmd = find_cmd_tbl(argv[1], tpm_commands, size);
if (!cmd)
diff --git a/cmd/tpm-v1.c b/cmd/tpm-v1.c
index 0874c4d7ba..69870002d4 100644
--- a/cmd/tpm-v1.c
+++ b/cmd/tpm-v1.c
@@ -608,7 +608,7 @@ static cmd_tbl_t tpm1_commands[] = {
 #endif /* CONFIG_TPM_LIST_RESOURCES */
 };
 
-cmd_tbl_t *get_tpm_commands(unsigned int *size)
+cmd_tbl_t *get_tpm1_commands(unsigned int *size)
 {
*size = ARRAY_SIZE(tpm1_commands);
 
diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c
index 38add4f462..ffbf35a75c 100644
--- a/cmd/tpm-v2.c
+++ b/cmd/tpm-v2.c
@@ -319,14 +319,14 @@ static cmd_tbl_t tpm2_commands[] = {
 do_tpm_pcr_setauthvalue, "", ""),
 };
 
-cmd_tbl_t *get_tpm_commands(unsigned int *size)
+cmd_tbl_t *get_tpm2_commands(unsigned int *size)
 {
*size = ARRAY_SIZE(tpm2_commands);
 
return tpm2_commands;
 }
 
-U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
+U_BOOT_CMD(tpm2, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
 " []\n"
 "\n"
 "info\n"
diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index da1ed8fd87..782a620f91 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -4,9 +4,6 @@
 
 menu "TPM support"
 
-comment "Please select only one TPM revision"
-   depends on TPM_V1 && TPM_V2
-
 config TPM_V1
bool "TPMv1.x support"
depends on TPM
@@ -15,7 +12,7 @@ config TPM_V1
  Major TPM versions are not compatible at all, choose either
  one or the other. This option enables TPMv1.x drivers/commands.
 
-if TPM_V1 && !TPM_V2
+if TPM_V1
 
 config TPM_TIS_SANDBOX
bool "Enable sandbox TPM driver"
@@ -127,7 +124,7 @@ config TPM_V2
  Major TPM versions are not compatible at all, choose either
  one or the other. This option enables TPMv2.x drivers/commands.
 
-if TPM_V2 && !TPM_V1
+if TPM_V2
 
 config TPM2_TIS_SANDBOX
bool "Enable sandbox TPMv2.x driver"
diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
index 412697eedc..c83f53ab86 100644
--- a/drivers/tpm/tpm-uclass.c
+++ b/drivers/tpm/tpm-uclass.c
@@ -7,11 +7,8 @@
 #include 
 #include 
 #include 
-#if defined(CONFIG_TPM_V1)
 #include 
-#elif defined(CONFIG_TPM_V2)
 #include 
-#endif
 #include "tpm_internal.h"
 
 int tpm_open(struct udevice *dev)
diff --git a/drivers/tpm/tpm2_tis_sandbox.c b/drivers/tpm/tpm2_tis_sandbox.c
index 3240cc5dba..532d27ddd9 100644
--- a/drivers/tpm

[U-Boot] [PATCH v2 7/7] sandbox: compile both TPM stack versions and drivers

2018-07-19 Thread Miquel Raynal
Now that TPMv1 and TPMv2 can be compiled at the same time, let's compile
them both with Sandbox as well as both drivers (and, it is already
implied in Kconfig: both commands).

Signed-off-by: Miquel Raynal 
Reviewed-by: Simon Glass 
---
 configs/sandbox_defconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 2fc84a16c9..d5756d1173 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -176,6 +176,7 @@ CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
 CONFIG_SANDBOX_TIMER=y
 CONFIG_TPM_TIS_SANDBOX=y
+CONFIG_TPM2_TIS_SANDBOX=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_USB_EMUL=y
@@ -192,6 +193,8 @@ CONFIG_FS_CBFS=y
 CONFIG_FS_CRAMFS=y
 CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
+CONFIG_TPM_V1=y
+CONFIG_TPM_V2=y
 CONFIG_LZ4=y
 CONFIG_ERRNO_STR=y
 CONFIG_OF_LIBFDT_OVERLAY=y
-- 
2.14.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


<    1   2   3   4   5   6   7   8   9   10   >