cascardo/linux.git
8 years agomtd: partitions: kill unused ecclayout struct
Brian Norris [Thu, 12 Nov 2015 01:05:56 +0000 (17:05 -0800)]
mtd: partitions: kill unused ecclayout struct

This field is not used.

Reported here:

http://lists.infradead.org/pipermail/linux-mtd/2015-October/062417.html

Reported-by: Brian Foster <brian.foster@maximintegrated.com>
Cc: Brian Foster <brian.foster@maximintegrated.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agomtd: zero out mtd_partition struct before using it
Brian Norris [Thu, 12 Nov 2015 00:47:52 +0000 (16:47 -0800)]
mtd: zero out mtd_partition struct before using it

It's easier to guarantee we've cleared out all unused fields with
memset() than by manually initializing each field.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agomtd: grab a reference to the MTD of_node before registering it
Brian Norris [Thu, 12 Nov 2015 00:26:04 +0000 (16:26 -0800)]
mtd: grab a reference to the MTD of_node before registering it

We now stick the device node representing the current MTD (if any) into
sysfs, so let's make sure we have a reference to it before doing that.

Suggested-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agomtd: nand: convert to nand_get_flash_node()
Boris BREZILLON [Sun, 1 Nov 2015 23:03:38 +0000 (00:03 +0100)]
mtd: nand: convert to nand_get_flash_node()

Used semantic patch with 'make coccicheck MODE=patch COCCI=script.cocci':

---8<----
virtual patch

@@
struct nand_chip c;
struct nand_chip *cp;
@@
(
-(cp)->flash_node
+nand_get_flash_node(cp)
|
-(c).flash_node
+nand_get_flash_node(&c)
)
---8<----

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: physmap_of: assign parent for the concatenated MTD
Brian Norris [Sat, 31 Oct 2015 03:33:30 +0000 (20:33 -0700)]
mtd: physmap_of: assign parent for the concatenated MTD

If there is more than one map region for this device, then the
concatenated MTD will not have a parent device assigned to it -- only
the sub-devices (which are not actually registered with the framework)
will have their parents assigned. Let's assign the concatenated device
correctly.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agomtd: ofpart: drop 'of_node' partition parser data
Brian Norris [Sat, 31 Oct 2015 03:33:29 +0000 (20:33 -0700)]
mtd: ofpart: drop 'of_node' partition parser data

This field is no longer used anywhere, as it is superseded by
mtd->dev.of_node.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agomtd: drop unnecessary partition parser data
Brian Norris [Sat, 31 Oct 2015 03:33:28 +0000 (20:33 -0700)]
mtd: drop unnecessary partition parser data

We should assign the MTD dev.of_node instead of the parser data field.
This gets us the equivalent partition parser behavior with fewer special
fields and parameter passing.

Also convert several of these to mtd_device_register(), since we don't
need the 2nd and 3rd parameters anymore.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Marek Vasut <marex@denx.de>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agomtd: spi-nor: drop flash_node field
Brian Norris [Sat, 31 Oct 2015 03:33:27 +0000 (20:33 -0700)]
mtd: spi-nor: drop flash_node field

We can just alias to the MTD of_node.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agomtd: spi-nor: drop unnecessary partition parser data
Brian Norris [Sat, 31 Oct 2015 03:33:26 +0000 (20:33 -0700)]
mtd: spi-nor: drop unnecessary partition parser data

Now that the SPI-NOR/MTD framework pass the 'flash_node' through to the
partition parsing code, we don't have to do it ourselves.

Also convert to mtd_device_register(), since we don't need the 2nd and
3rd parameters anymore.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agomtd: nand: drop unnecessary partition parser data
Brian Norris [Sat, 31 Oct 2015 03:33:25 +0000 (20:33 -0700)]
mtd: nand: drop unnecessary partition parser data

All of these drivers set up a parser data struct just to communicate DT
partition data. This field has been deprecated and is instead supported
by telling nand_scan_ident() about the 'flash_node'.

This patch:
 * sets chip->flash_node for those drivers that didn't already (but used
   OF partitioning)
 * drops the parser data
 * switches to the simpler mtd_device_register() where possible, now
   that we've eliminated one of the auxiliary parameters

Now that we've assigned chip->flash_node for these drivers, we can
probably rely on nand_dt_init() to do more of the DT parsing for us, but
for now, I don't want to fiddle with each of these drivers. The parsing
is done in duplicate for now on some drivers. I don't think this should
break things. (Famous last words.)

(Rolled in some changes by Boris Brezillon)

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agomtd: spi-nor: convert to spi_nor_{get, set}_flash_node()
Brian Norris [Sat, 31 Oct 2015 03:33:24 +0000 (20:33 -0700)]
mtd: spi-nor: convert to spi_nor_{get, set}_flash_node()

Used semantic patch with 'make coccicheck MODE=patch COCCI=script.cocci':

---8<----
virtual patch

@@
struct spi_nor b;
struct spi_nor *c;
expression d;
@@
(
-(b).flash_node = (d)
+spi_nor_set_flash_node(&b, d)
|
-(c)->flash_node = (d)
+spi_nor_set_flash_node(c, d)
)
---8<----

And a manual conversion for the one use of spi_nor_get_flash_node().

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agomtd: nand: convert to nand_set_flash_node()
Brian Norris [Sat, 31 Oct 2015 03:33:23 +0000 (20:33 -0700)]
mtd: nand: convert to nand_set_flash_node()

Used semantic patch with 'make coccicheck MODE=patch COCCI=script.cocci':

---8<----
virtual patch

@@
struct nand_chip *c;
struct device_node *d;
@@
-(c)->flash_node = (d)
+nand_set_flash_node(c, d)
---8<----

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Marek Vasut <marex@denx.de>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agomtd: {nand,spi-nor}: assign MTD of_node
Brian Norris [Sat, 31 Oct 2015 03:33:22 +0000 (20:33 -0700)]
mtd: {nand,spi-nor}: assign MTD of_node

We should pass along our flash DT node to the MTD layer, so it can set
up ofpart for us.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agomtd: ofpart: grab device tree node directly from master device node
Brian Norris [Sat, 31 Oct 2015 03:33:21 +0000 (20:33 -0700)]
mtd: ofpart: grab device tree node directly from master device node

It seems more logical to use a device node directly associated with the
MTD master device (i.e., mtd->dev.of_node field) rather than requiring
auxiliary partition parser information to be passed in by the driver in
a separate struct.

This patch supports the mtd->dev.of_node field and deprecates the parser
data 'of_node' field

Driver conversions may now follow.

Additional side benefit to assigning mtd->dev.of_node rather than using
parser data: the driver core will automatically create a device -> node
symlink for us.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agomtd: add get/set of_node/flash_node helpers
Brian Norris [Sat, 31 Oct 2015 03:33:20 +0000 (20:33 -0700)]
mtd: add get/set of_node/flash_node helpers

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 <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agodoc: dt: mtd: add documentation for Mediatek spi-nor controller
Bayi Cheng [Fri, 6 Nov 2015 15:48:07 +0000 (23:48 +0800)]
doc: dt: mtd: add documentation for Mediatek spi-nor controller

Add device tree binding documentation for serial flash with
Mediatek serial flash controller

Signed-off-by: Bayi Cheng <bayi.cheng@mediatek.com>
Acked-by: Rob Herring <robh@kernel.org>
[Brian: fixed up language]
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: afs: refactor v1 partition parsing
Linus Walleij [Thu, 15 Oct 2015 13:08:47 +0000 (15:08 +0200)]
mtd: afs: refactor v1 partition parsing

Return immediately if we are not finding a valid v1 partition
in afs_read_footer_v1(), invert scanning logic so we continue
to read image information on v1 if we found a footer. This is
needed for the logic we introduce to parse v2 footers.

Cc: Ryan Harkin <ryan.harkin@linaro.org>
Cc: Liviu Dudau <liviu.dudau@arm.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: afs: break out v1 footer magic to a define
Linus Walleij [Thu, 15 Oct 2015 13:08:46 +0000 (15:08 +0200)]
mtd: afs: break out v1 footer magic to a define

Break out the magic number to a #defined constant.

Cc: Ryan Harkin <ryan.harkin@linaro.org>
Cc: Liviu Dudau <liviu.dudau@arm.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: enable AFS selection for ARM64
Linus Walleij [Thu, 15 Oct 2015 13:08:45 +0000 (15:08 +0200)]
mtd: enable AFS selection for ARM64

ARM use their special partitions also on the ARM64 architecture
reference designs, so enable this for ARM64.

Cc: Ryan Harkin <ryan.harkin@linaro.org>
Cc: Liviu Dudau <liviu.dudau@arm.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: afs: rename structs and functions for v1
Linus Walleij [Thu, 15 Oct 2015 13:08:44 +0000 (15:08 +0200)]
mtd: afs: rename structs and functions for v1

Since we're gonna add the v2 version of flash information
structure and we want to avoid confusion, rename the old
functions to *v1. Cut the word "structure" from the struct
name, it is pretty obvious that it is a struct already from
the keyword.

Cc: Ryan Harkin <ryan.harkin@linaro.org>
Cc: Liviu Dudau <liviu.dudau@arm.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: ofpart: document the lock flag.
Michal Suchanek [Fri, 30 Oct 2015 20:34:00 +0000 (13:34 -0700)]
mtd: ofpart: document the lock flag.

The lock flag of ofpart is undocumented. Add to binding doc.

Signed-off-by: Michal Suchanek <hramrach@gmail.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: don't WARN about overloaded users of mtd->reboot_notifier.notifier_call
Brian Norris [Wed, 4 Nov 2015 01:01:53 +0000 (17:01 -0800)]
mtd: don't WARN about overloaded users of mtd->reboot_notifier.notifier_call

There are multiple types of users of mtd->reboot_notifier.notifier_call:

(1) A while back, the cfi_cmdset_000{1,2} chip drivers implemented a
reboot notifier to (on a best effort basis) attempt to reset their flash
chips before rebooting.

(2) More recently, we implemented a common _reboot() hook so that MTD
drivers (particularly, NAND flash) could better halt I/O operations
without having to reimplement the same notifier boilerplate.

Currently, the WARN_ONCE() condition here was written to handle (2), but
at the same time it mis-diagnosed case (1) as an already-registered MTD.
Let's fix this by having the WARN_ONCE() condition better imitate the
condition that immediately follows it. (Wow, I don't know how I missed
that one.)

(Side note: Unfortunately, we can't yet combine the reboot notifier code
for (1) and (2) with a patch like [1], because some users of (1) also
use mtdconcat, and so the mtd_info struct from cfi_cmdset_000{1,2} won't
actually get registered with mtdcore, and therefore their reboot
notifier won't get registered.)

[1] http://patchwork.ozlabs.org/patch/417981/

Suggested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Cc: Jesper Nilsson <jespern@axis.com>
Cc: linux-cris-kernel@axis.com
Tested-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: sunxi: avoid retrieving data before ECC pass
Boris BREZILLON [Tue, 20 Oct 2015 20:16:01 +0000 (22:16 +0200)]
mtd: nand: sunxi: avoid retrieving data before ECC pass

The in-band data are copied twice: before ECC correction and after the
ECC engine has fixed all the fixable bitflips.
Drop the useless memcpy_fromio operation by passing a NULL pointer when
calling sunxi_nfc_read_buf().

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: sunxi: fix sunxi_nfc_hw_ecc_read/write_chunk()
Boris BREZILLON [Tue, 20 Oct 2015 20:16:00 +0000 (22:16 +0200)]
mtd: nand: sunxi: fix sunxi_nfc_hw_ecc_read/write_chunk()

The sunxi_nfc_hw_ecc_read/write_chunk() functions try to avoid changing
the column address if unnecessary, but the logic to determine whether it's
necessary or not is currently wrong: it adds the ecc->bytes value to the
current offset where it should actually add ecc->size.

Fixes: 913821bdd211 ("mtd: nand: sunxi: introduce sunxi_nfc_hw_ecc_read/write_chunk()")
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: blkdevs: fix potential deadlock + lockdep warnings
Brian Norris [Mon, 26 Oct 2015 17:20:23 +0000 (10:20 -0700)]
mtd: blkdevs: fix potential deadlock + lockdep warnings

Commit 073db4a51ee4 ("mtd: fix: avoid race condition when accessing
mtd->usecount") fixed a race condition but due to poor ordering of the
mutex acquisition, introduced a potential deadlock.

The deadlock can occur, for example, when rmmod'ing the m25p80 module, which
will delete one or more MTDs, along with any corresponding mtdblock
devices. This could potentially race with an acquisition of the block
device as follows.

 -> blktrans_open()
    ->  mutex_lock(&dev->lock);
    ->  mutex_lock(&mtd_table_mutex);

 -> del_mtd_device()
    ->  mutex_lock(&mtd_table_mutex);
    ->  blktrans_notify_remove() -> del_mtd_blktrans_dev()
       ->  mutex_lock(&dev->lock);

This is a classic (potential) ABBA deadlock, which can be fixed by
making the A->B ordering consistent everywhere. There was no real
purpose to the ordering in the original patch, AFAIR, so this shouldn't
be a problem. This ordering was actually already present in
del_mtd_blktrans_dev(), for one, where the function tried to ensure that
its caller already held mtd_table_mutex before it acquired &dev->lock:

        if (mutex_trylock(&mtd_table_mutex)) {
                mutex_unlock(&mtd_table_mutex);
                BUG();
        }

So, reverse the ordering of acquisition of &dev->lock and &mtd_table_mutex so
we always acquire mtd_table_mutex first.

Snippets of the lockdep output follow:

  # modprobe -r m25p80
  [   53.419251]
  [   53.420838] ======================================================
  [   53.427300] [ INFO: possible circular locking dependency detected ]
  [   53.433865] 4.3.0-rc6 #96 Not tainted
  [   53.437686] -------------------------------------------------------
  [   53.444220] modprobe/372 is trying to acquire lock:
  [   53.449320]  (&new->lock){+.+...}, at: [<c043fe4c>] del_mtd_blktrans_dev+0x80/0xdc
  [   53.457271]
  [   53.457271] but task is already holding lock:
  [   53.463372]  (mtd_table_mutex){+.+.+.}, at: [<c0439994>] del_mtd_device+0x18/0x100
  [   53.471321]
  [   53.471321] which lock already depends on the new lock.
  [   53.471321]
  [   53.479856]
  [   53.479856] the existing dependency chain (in reverse order) is:
  [   53.487660]
  -> #1 (mtd_table_mutex){+.+.+.}:
  [   53.492331]        [<c043fc5c>] blktrans_open+0x34/0x1a4
  [   53.497879]        [<c01afce0>] __blkdev_get+0xc4/0x3b0
  [   53.503364]        [<c01b0bb8>] blkdev_get+0x108/0x320
  [   53.508743]        [<c01713c0>] do_dentry_open+0x218/0x314
  [   53.514496]        [<c0180454>] path_openat+0x4c0/0xf9c
  [   53.519959]        [<c0182044>] do_filp_open+0x5c/0xc0
  [   53.525336]        [<c0172758>] do_sys_open+0xfc/0x1cc
  [   53.530716]        [<c000f740>] ret_fast_syscall+0x0/0x1c
  [   53.536375]
  -> #0 (&new->lock){+.+...}:
  [   53.540587]        [<c063f124>] mutex_lock_nested+0x38/0x3cc
  [   53.546504]        [<c043fe4c>] del_mtd_blktrans_dev+0x80/0xdc
  [   53.552606]        [<c043f164>] blktrans_notify_remove+0x7c/0x84
  [   53.558891]        [<c04399f0>] del_mtd_device+0x74/0x100
  [   53.564544]        [<c043c670>] del_mtd_partitions+0x80/0xc8
  [   53.570451]        [<c0439aa0>] mtd_device_unregister+0x24/0x48
  [   53.576637]        [<c046ce6c>] spi_drv_remove+0x1c/0x34
  [   53.582207]        [<c03de0f0>] __device_release_driver+0x88/0x114
  [   53.588663]        [<c03de19c>] device_release_driver+0x20/0x2c
  [   53.594843]        [<c03dd9e8>] bus_remove_device+0xd8/0x108
  [   53.600748]        [<c03dacc0>] device_del+0x10c/0x210
  [   53.606127]        [<c03dadd0>] device_unregister+0xc/0x20
  [   53.611849]        [<c046d878>] __unregister+0x10/0x20
  [   53.617211]        [<c03da868>] device_for_each_child+0x50/0x7c
  [   53.623387]        [<c046eae8>] spi_unregister_master+0x58/0x8c
  [   53.629578]        [<c03e12f0>] release_nodes+0x15c/0x1c8
  [   53.635223]        [<c03de0f8>] __device_release_driver+0x90/0x114
  [   53.641689]        [<c03de900>] driver_detach+0xb4/0xb8
  [   53.647147]        [<c03ddc78>] bus_remove_driver+0x4c/0xa0
  [   53.652970]        [<c00cab50>] SyS_delete_module+0x11c/0x1e4
  [   53.658976]        [<c000f740>] ret_fast_syscall+0x0/0x1c
  [   53.664621]
  [   53.664621] other info that might help us debug this:
  [   53.664621]
  [   53.672979]  Possible unsafe locking scenario:
  [   53.672979]
  [   53.679169]        CPU0                    CPU1
  [   53.683900]        ----                    ----
  [   53.688633]   lock(mtd_table_mutex);
  [   53.692383]                                lock(&new->lock);
  [   53.698306]                                lock(mtd_table_mutex);
  [   53.704658]   lock(&new->lock);
  [   53.707946]
  [   53.707946]  *** DEADLOCK ***

Fixes: 073db4a51ee4 ("mtd: fix: avoid race condition when accessing mtd->usecount")
Reported-by: Felipe Balbi <balbi@ti.com>
Tested-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Cc: <stable@vger.kernel.org>
8 years agomtd: ofpart: move ofpart partitions to a dedicated dt node
Michal Suchanek [Tue, 18 Aug 2015 15:34:09 +0000 (15:34 +0000)]
mtd: ofpart: move ofpart partitions to a dedicated dt node

Parsing direct subnodes of a mtd device as partitions is unreliable
since the mtd device is also part of its bus subsystem and can contain
bus data in subnodes.

Move ofpart data to a subnode of its own so it is clear which data is
part of the partition layout.

Signed-off-by: Michal Suchanek <hramrach@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agodoc: dt: mtd: support partitions in a special 'partitions' subnode
Michal Suchanek [Wed, 28 Oct 2015 22:48:06 +0000 (15:48 -0700)]
doc: dt: mtd: support partitions in a special 'partitions' subnode

To avoid conflict with other drivers using subnodes of the mtd device
create only one ofpart-specific node rather than any number of
arbitrary partition subnodes.

Signed-off-by: Michal Suchanek <hramrach@gmail.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: brcmnand: Force 8bit mode before doing nand_scan_ident()
Anup Patel [Fri, 30 Oct 2015 06:59:20 +0000 (12:29 +0530)]
mtd: brcmnand: Force 8bit mode before doing nand_scan_ident()

Just like other NAND controllers, the NAND READID command only works
in 8bit mode for all versions of BRCMNAND controller.

This patch forces 8bit mode for each NAND CS in brcmnand_init_cs()
before doing nand_scan_ident() to ensure that BRCMNAND controller
is in 8bit mode when NAND READID command is issued.

Signed-off-by: Anup Patel <anup.patel@broadcom.com>
Reviewed-by: Ray Jui <rjui@broadcom.com>
Reviewed-by: Scott Branden <sbranden@broadcom.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: brcmnand: factor out CFG and CFG_EXT bitfields
Brian Norris [Fri, 30 Oct 2015 06:59:19 +0000 (12:29 +0530)]
mtd: brcmnand: factor out CFG and CFG_EXT bitfields

Use enum instead of magic numbers for CFG and CFG_EXT bitfields.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Tested-by: Anup Patel <anup.patel@broadcom.com>
8 years agomtd: mtdpart: Do not fail mtd probe when parsing partitions fails
Brian Norris [Sun, 11 Oct 2015 20:03:47 +0000 (13:03 -0700)]
mtd: mtdpart: Do not fail mtd probe when parsing partitions fails

Due to wrong assumption in ofpart ofpart fails on Exynos on SPI chips
with no partitions because the subnode containing controller data
confuses the ofpart parser.

Thus compiling in ofpart support automatically fails probing any SPI NOR
flash without partitions on Exynos.

Compiling in a partitioning scheme should not cause probe of otherwise
valid device to fail.

Instead, let's do the following:
 * try parsers until one succeeds
 * if no parser succeeds, report the first error we saw
 * even in the failure case, allow MTD to probe, with fallback
   partitions or no partitions at all -- the master device will still be
   registered

Issue report and comments initially by Michal Suchanek.

Reported-by: Michal Suchanek <hramrach@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: fsl-quadspi: fix macro collision problems with READ/WRITE
Han Xu [Fri, 23 Oct 2015 18:18:28 +0000 (13:18 -0500)]
mtd: fsl-quadspi: fix macro collision problems with READ/WRITE

Change the READ/WRITE to FSL_READ/FSL_WRITE to resolve any possible
namespace collisions with READ/WRITE macros (e.g., from <linux/fs.h>).

Problems have been seen, for example, on mips:

>> drivers/mtd/spi-nor/fsl-quadspi.c:186:5: error: 'LUT_0' undeclared (first use in this function)
      ((LUT_##ins) << INSTR0_SHIFT))
        ^
>> drivers/mtd/spi-nor/fsl-quadspi.c:188:30: note: in expansion of macro 'LUT0'

On SPARC:

drivers/mtd/spi-nor/fsl-quadspi.c: In function 'fsl_qspi_init_lut':
drivers/mtd/spi-nor/fsl-quadspi.c:369:1: error: 'LUT_0' undeclared (first use in this function)
drivers/mtd/spi-nor/fsl-quadspi.c:418:1: error: pasting "LUT_" and "(" does not give a valid preprocessing token
drivers/mtd/spi-nor/fsl-quadspi.c:418:2: error: implicit declaration of function 'LUT_'

And surely on others.

Fixes: d26a22d06708 ("mtd: fsl-quadspi: allow building for other ARCHes with COMPILE_TEST")
Reported-by: Guenter Roeck <linux@roeck-us.net>
Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Han Xu <b45815@freescale.com>
[Brian: rewrote commit description]
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: warn when registering the same master many times
Brian Norris [Mon, 1 Jun 2015 23:17:20 +0000 (16:17 -0700)]
mtd: warn when registering the same master many times

When CONFIG_MTD_PARTITIONED_MASTER=y, it is fatal to call
mtd_device_parse_register() twice on the same MTD, as we try to register
the same device/kobject multipile times.

When CONFIG_MTD_PARTITIONED_MASTER=n, calling
mtd_device_parse_register() is more of just a nuisance, as we can mostly
navigate around any conflicting actions.

But anyway, doing so is a Bad Thing (TM), and we should complain loudly
for any drivers that try to do this.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Richard Weinberger <richard@nod.at>
8 years agomtd: fixup corner case error handling in mtd_device_parse_register()
Brian Norris [Mon, 1 Jun 2015 23:17:19 +0000 (16:17 -0700)]
mtd: fixup corner case error handling in mtd_device_parse_register()

Since commit 3efe41be224c ("mtd: implement common reboot notifier
boilerplate"), we might try to register a reboot notifier for an MTD
that failed to register. Let's avoid this by making the error path
clearer.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Richard Weinberger <richard@nod.at>
8 years agomtd: tests: Replace timeval with ktime_t
Shraddha Barke [Thu, 22 Oct 2015 14:59:54 +0000 (20:29 +0530)]
mtd: tests: Replace timeval with ktime_t

Changes the 32-bit time type timeval to the 64-bit time type
ktime_t, since 32-bit systems using struct timeval will break in the
year 2038. Correspondingly change do_gettimeofday() to ktime_get()
since ktime_get returns a ktime_t, but do_gettimeofday returns a
struct timeval.Here, ktime_get() is used instead of ktime_get_real()
since ktime_get() uses monotonic clock.

Signed-off-by: Shraddha Barke <shraddha.6596@gmail.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: fsmc_nand: Add BCH4 SW ECC support for SPEAr600
Stefan Roese [Mon, 19 Oct 2015 06:40:13 +0000 (08:40 +0200)]
mtd: fsmc_nand: Add BCH4 SW ECC support for SPEAr600

This patch adds support for 4-bit ECC BCH4 for the SPEAr600 SoC. This can
be used by boards equipped with a NAND chip that requires 4-bit ECC
strength. The SPEAr600 HW ECC only supports 1-bit ECC strength.

To enable SW BCH4, you need to specify this in your nand controller
DT node:

nand-ecc-mode = "soft_bch";
nand-ecc-strength = <4>;
nand-ecc-step-size = <512>;

Tested on a custom SPEAr600 board.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
[Brian: tweaked the comments a bit]
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: vf610_nfc: use nand_check_erased_ecc_chunk() helper
Brian Norris [Tue, 29 Sep 2015 21:11:56 +0000 (14:11 -0700)]
mtd: nand: vf610_nfc: use nand_check_erased_ecc_chunk() helper

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
8 years agomtd: nand: increase ready wait timeout and report timeouts
Alex Smith [Tue, 6 Oct 2015 13:52:07 +0000 (14:52 +0100)]
mtd: nand: increase ready wait timeout and report timeouts

If nand_wait_ready() times out, this is silently ignored, and its
caller will then proceed to read from/write to the chip before it is
ready. This can potentially result in corruption with no indication as
to why.

While a 20ms timeout seems like it should be plenty enough, certain
behaviour can cause it to timeout much earlier than expected. The
situation which prompted this change was that CPU 0, which is
responsible for updating jiffies, was holding interrupts disabled
for a fairly long time while writing to the console during a printk,
causing several jiffies updates to be delayed. If CPU 1 happens to
enter the timeout loop in nand_wait_ready() just before CPU 0 re-
enables interrupts and updates jiffies, CPU 1 will immediately time
out when the delayed jiffies updates are made. The result of this is
that nand_wait_ready() actually waits less time than the NAND chip
would normally take to be ready, and then read_page() proceeds to
read out bad data from the chip.

The situation described above may seem unlikely, but in fact it can be
reproduced almost every boot on the MIPS Creator Ci20.

Therefore, this patch increases the timeout to 400ms. This should be
enough to cover cases where jiffies updates get delayed. In nand_wait()
the timeout was previously chosen based on whether erasing or
programming. This is changed to be 400ms unconditionally as well to
avoid similar problems there. nand_wait() is also slightly refactored
to be consistent with nand_wait{,_status}_ready(). These changes should
have no effect during normal operation.

Debugging this was made more difficult by the misleading comment above
nand_wait_ready() stating "The timeout is caught later" - no timeout was
ever reported, leading me away from the real source of the problem.
Therefore, a pr_warn() is added when a timeout does occur so that it is
easier to pinpoint similar problems in future.

Signed-off-by: Alex Smith <alex.smith@imgtec.com>
Signed-off-by: Harvey Hunt <harvey.hunt@imgtec.com>
Reviewed-by: Niklas Cassel <niklas.cassel@axis.com>
Cc: Alex Smith <alex@alex-smith.me.uk>
Cc: Zubair Lutfullah Kakakhel <Zubair.Kakakhel@imgtec.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Niklas Cassel <niklas.cassel@axis.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: docg3: off by one in doc_register_sysfs()
Dan Carpenter [Mon, 19 Oct 2015 10:20:05 +0000 (13:20 +0300)]
mtd: docg3: off by one in doc_register_sysfs()

Smatch found a bug in the error handling:

drivers/mtd/devices/docg3.c:1634 doc_register_sysfs()
error: buffer overflow 'doc_sys_attrs' 4 <= 4

The problem is that if the very last device_create_file() fails, then we
are beyond the end of the array.  Actually, any time i == 3 then there
is a problem.  We can fix this an simplify the code at the same time by
moving the !ret conditions out of the for loops and using a goto
instead.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: pxa3xx_nand: clean up the pxa3xx timings
Antoine Ténart [Wed, 21 Oct 2015 08:29:04 +0000 (10:29 +0200)]
mtd: pxa3xx_nand: clean up the pxa3xx timings

With the previous modifications, lots of pxa3xx specific definitions can
be removed.

Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
Acked-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: pxa3xx_nand: rework flash detection and timing setup
Antoine Ténart [Wed, 21 Oct 2015 08:29:03 +0000 (10:29 +0200)]
mtd: pxa3xx_nand: rework flash detection and timing setup

Rework the pxa3xx_nand driver to allow using functions exported by the
nand framework to detect the flash and the timings. Then setup the
timings using the helpers previously added.

Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
Acked-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: pxa3xx_nand: add helpers to setup the timings
Antoine Ténart [Wed, 21 Oct 2015 08:29:02 +0000 (10:29 +0200)]
mtd: pxa3xx_nand: add helpers to setup the timings

Add helpers to setup the timings in the pxa3xx driver. These helpers
allow to either make use of the nand framework nand_sdr_timings or the
pxa3xx specific pxa3xx_nand_host, for compatibility reasons.

Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
Acked-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: pxa3xx_nand: fix some compile issues on non-ARM arches
Antoine Ténart [Wed, 21 Oct 2015 08:29:00 +0000 (10:29 +0200)]
mtd: pxa3xx_nand: fix some compile issues on non-ARM arches

Using readsl() result in a build error on i386. Fix this by using
ioread32_rep() instead, to allow compile testing the pxa3xx nand driver
on other architectures later.

Suggested-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
Acked-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: lpc32xx_mlc: fix warnings caused by enabling unprepared clock
Vladimir Zapolskiy [Sat, 17 Oct 2015 18:09:30 +0000 (21:09 +0300)]
mtd: lpc32xx_mlc: fix warnings caused by enabling unprepared clock

If common clock framework is configured, the driver generates a warning,
which is fixed by this change:

    WARNING: CPU: 0 PID: 1 at drivers/clk/clk.c:727 clk_core_enable+0x2c/0xa4()
    Modules linked in:
    CPU: 0 PID: 1 Comm: swapper Not tainted 4.3.0-rc2+ #206
    Hardware name: LPC32XX SoC (Flattened Device Tree)
    Backtrace:
    [<>] (dump_backtrace) from [<>] (show_stack+0x18/0x1c)
    [<>] (show_stack) from [<>] (dump_stack+0x20/0x28)
    [<>] (dump_stack) from [<>] (warn_slowpath_common+0x90/0xb8)
    [<>] (warn_slowpath_common) from [<>] (warn_slowpath_null+0x24/0x2c)
    [<>] (warn_slowpath_null) from [<>] (clk_core_enable+0x2c/0xa4)
    [<>] (clk_core_enable) from [<>] (clk_enable+0x24/0x38)
    [<>] (clk_enable) from [<>] (lpc32xx_nand_probe+0x208/0x248)
    [<>] (lpc32xx_nand_probe) from [<>] (platform_drv_probe+0x50/0xa0)
    [<>] (platform_drv_probe) from [<>] (driver_probe_device+0x18c/0x408)
    [<>] (driver_probe_device) from [<>] (__driver_attach+0x70/0x94)
    [<>] (__driver_attach) from [<>] (bus_for_each_dev+0x74/0x98)
    [<>] (bus_for_each_dev) from [<>] (driver_attach+0x20/0x28)
    [<>] (driver_attach) from [<>] (bus_add_driver+0x11c/0x248)
    [<>] (bus_add_driver) from [<>] (driver_register+0xa4/0xe8)
    [<>] (driver_register) from [<>] (__platform_driver_register+0x50/0x64)
    [<>] (__platform_driver_register) from [<>] (lpc32xx_nand_driver_init+0x18/0x20)
    [<>] (lpc32xx_nand_driver_init) from [<>] (do_one_initcall+0x11c/0x1dc)
    [<>] (do_one_initcall) from [<>] (kernel_init_freeable+0x10c/0x1d4)
    [<>] (kernel_init_freeable) from [<>] (kernel_init+0x10/0xec)
    [<>] (kernel_init) from [<>] (ret_from_fork+0x14/0x24)

Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: lpc32xx_slc: fix warnings caused by enabling unprepared clock
Vladimir Zapolskiy [Sat, 17 Oct 2015 18:09:29 +0000 (21:09 +0300)]
mtd: lpc32xx_slc: fix warnings caused by enabling unprepared clock

If common clock framework is configured, the driver generates a warning,
which is fixed by this change:

    WARNING: CPU: 0 PID: 1 at drivers/clk/clk.c:727 clk_core_enable+0x2c/0xa4()
    Modules linked in:
    CPU: 0 PID: 1 Comm: swapper Not tainted 4.3.0-rc2+ #201
    Hardware name: LPC32XX SoC (Flattened Device Tree)
    Backtrace:
    [<>] (dump_backtrace) from [<>] (show_stack+0x18/0x1c)
    [<>] (show_stack) from [<>] (dump_stack+0x20/0x28)
    [<>] (dump_stack) from [<>] (warn_slowpath_common+0x90/0xb8)
    [<>] (warn_slowpath_common) from [<>] (warn_slowpath_null+0x24/0x2c)
    [<>] (warn_slowpath_null) from [<>] (clk_core_enable+0x2c/0xa4)
    [<>] (clk_core_enable) from [<>] (clk_enable+0x24/0x38)
    [<>] (clk_enable) from [<>] (lpc32xx_nand_probe+0x290/0x568)
    [<>] (lpc32xx_nand_probe) from [<>] (platform_drv_probe+0x50/0xa0)
    [<>] (platform_drv_probe) from [<>] (driver_probe_device+0x18c/0x408)
    [<>] (driver_probe_device) from [<>] (__driver_attach+0x70/0x94)
    [<>] (__driver_attach) from [<>] (bus_for_each_dev+0x74/0x98)
    [<>] (bus_for_each_dev) from [<>] (driver_attach+0x20/0x28)
    [<>] (driver_attach) from [<>] (bus_add_driver+0x11c/0x248)
    [<>] (bus_add_driver) from [<>] (driver_register+0xa4/0xe8)
    [<>] (driver_register) from [<>] (__platform_driver_register+0x50/0x64)
    [<>] (__platform_driver_register) from [<>] (lpc32xx_nand_driver_init+0x18/0x20)
    [<>] (lpc32xx_nand_driver_init) from [<>] (do_one_initcall+0x11c/0x1dc)
    [<>] (do_one_initcall) from [<>] (kernel_init_freeable+0x10c/0x1d4)
    [<>] (kernel_init_freeable) from [<>] (kernel_init+0x10/0xec)
    [<>] (kernel_init) from [<>] (ret_from_fork+0x14/0x24)

Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: maps: rbtx4939-flash: fix compile error
Brian Norris [Mon, 19 Oct 2015 19:22:57 +0000 (12:22 -0700)]
mtd: maps: rbtx4939-flash: fix compile error

We got the syntax wrong here. Compile tested this time!

Error:

   drivers/mtd/maps/rbtx4939-flash.c: In function 'rbtx4939_flash_probe':
>> drivers/mtd/maps/rbtx4939-flash.c:99:11: error: request for member 'dev' in something not a structure or union
     info->mtd.dev.parent = &dev->dev;
              ^

Fixes: 9aa7e50276c1 ("mtd: maps: rbtx4939-flash: show parent device in sysfs")
Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Cc: Frans Klaver <fransklaver@gmail.com>
8 years agomtd: mtd-user: remove stdint.h include
Mikko Rapeli [Thu, 15 Oct 2015 05:56:48 +0000 (07:56 +0200)]
mtd: mtd-user: remove stdint.h include

Kernel headers should use linux/types.h instead.

Signed-off-by: Mikko Rapeli <mikko.rapeli@iki.fi>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: mtdram: check offs and len in mtdram->erase
Dongsheng Yang [Wed, 30 Sep 2015 01:01:19 +0000 (09:01 +0800)]
mtd: mtdram: check offs and len in mtdram->erase

We should prevent user to erasing mtd device with
an unaligned offset or length.

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: pxa3xx_nand: switch to device PM
Brian Norris [Mon, 12 Oct 2015 21:07:41 +0000 (14:07 -0700)]
mtd: pxa3xx_nand: switch to device PM

The old PM model is deprecated. This is equivalent.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Tested-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Acked-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
8 years agomtd: pxa3xx_nand: don't duplicate MTD suspend/resume
Brian Norris [Mon, 12 Oct 2015 20:33:11 +0000 (13:33 -0700)]
mtd: pxa3xx_nand: don't duplicate MTD suspend/resume

mtd_{suspend,resume}() get called from mtdcore in a class suspend/resume
callback. We don't need to call them again here. In practice, this would
actually work OK, as nand_base actually handles nesting OK -- it just
might print warnings.

Untested, but there are few (no?) users of PM for this driver AFAIK.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Tested-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Acked-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
8 years agomtd: fsl-quadspi: Include <linux/sizes.h> to avoid build error
Fabio Estevam [Wed, 14 Oct 2015 03:39:44 +0000 (00:39 -0300)]
mtd: fsl-quadspi: Include <linux/sizes.h> to avoid build error

Building for x86 results in the following build errors:

   drivers/mtd/spi-nor/fsl-quadspi.c: In function 'fsl_qspi_init_lut':
>> drivers/mtd/spi-nor/fsl-quadspi.c:355:21: error: 'SZ_16M' undeclared (first use in this function)
     if (q->nor_size <= SZ_16M) {
                        ^
   drivers/mtd/spi-nor/fsl-quadspi.c:355:21: note: each undeclared identifier is reported only once for each function it appears in
   drivers/mtd/spi-nor/fsl-quadspi.c: In function 'fsl_qspi_read':
>> drivers/mtd/spi-nor/fsl-quadspi.c:208:27: error: 'SZ_4M' undeclared (first use in this function)
    #define QUADSPI_MIN_IOMAP SZ_4M
                              ^
>> drivers/mtd/spi-nor/fsl-quadspi.c:845:25: note: in expansion of macro 'QUADSPI_MIN_IOMAP'
      q->memmap_len = len > QUADSPI_MIN_IOMAP ? len : QUADSPI_MIN_IOMAP;

Explicitly include <linux/sizes.h> to fix the problem.

Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: fsl-quadspi: allow building for other ARCHes with COMPILE_TEST
Brian Norris [Mon, 12 Oct 2015 20:35:16 +0000 (13:35 -0700)]
mtd: fsl-quadspi: allow building for other ARCHes with COMPILE_TEST

This driver doesn't actually need ARCH_MXC to compile. Relax the
constraints.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Acked-by: Han xu <han.xu@freescale.com>
8 years agomtd: fsl-quadspi: fix printk() format warning for size_t
Brian Norris [Mon, 12 Oct 2015 20:35:15 +0000 (13:35 -0700)]
mtd: fsl-quadspi: fix printk() format warning for size_t

Seen when compile-testing on non-32-bit arch:

    CC      drivers/mtd/spi-nor/fsl-quadspi.o
  drivers/mtd/spi-nor/fsl-quadspi.c: In function 'fsl_qspi_read':
  drivers/mtd/spi-nor/fsl-quadspi.c:873:2: warning: format '%d' expects argument of type 'int', but argument 6 has type 'size_t' [-Wformat=]
    dev_dbg(q->dev, "cmd [%x],read from 0x%p, len:%d\n",
    ^

Also drop the '0x' prefixing to the '%p' formatter, since %p already
knows how to format pointers appropriately.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Acked-by: Han xu <han.xu@freescale.com>
8 years agomtd: spi-nor: add DUAL_READ for w25q{32,64}dw
Brian Norris [Tue, 1 Sep 2015 19:57:13 +0000 (12:57 -0700)]
mtd: spi-nor: add DUAL_READ for w25q{32,64}dw

These flash support dual and quad read. Tested dual read on the 32 Mbit
version.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: spi-nor: disable protection for Winbond flash at startup
Brian Norris [Tue, 1 Sep 2015 19:57:15 +0000 (12:57 -0700)]
mtd: spi-nor: disable protection for Winbond flash at startup

In case the flash was locked at boot time.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: spi-nor: support lock/unlock/is_locked for Winbond
Brian Norris [Tue, 1 Sep 2015 19:57:14 +0000 (12:57 -0700)]
mtd: spi-nor: support lock/unlock/is_locked for Winbond

Many other flash share the same features as ST Micro. I've tested some
Winbond flash, so add them.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: spi-nor: add mtd_is_locked() support
Brian Norris [Tue, 1 Sep 2015 19:57:12 +0000 (12:57 -0700)]
mtd: spi-nor: add mtd_is_locked() support

This enables ioctl(MEMISLOCKED). Status can now be reported in the
mtdinfo or flash_lock utilities found in mtd-utils.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: spi-nor: refactor block protection functions
Brian Norris [Tue, 1 Sep 2015 19:57:11 +0000 (12:57 -0700)]
mtd: spi-nor: refactor block protection functions

This code was a bit sloppy, would produce a lot of copy-and-paste, and
did not always provide a sensible interface:

 * It didn't validate the length for LOCK and the offset for UNLOCK, so
   we were essentially discarding half of the user-supplied data and
   assuming what they wanted to lock/unlock
 * It didn't do very good error checking
 * It didn't make use of the fact that this operation works on
   power-of-two dimensions

So, rewrite this to do proper bit arithmetic rather than a bunch of
hard-coded condition tables. Now we have:

 * More comments on how this was derived
 * Notes on what is (and isn't) supported
 * A more exendible function, so we could add support for other
   protection ranges
 * More accurate locking - e.g., suppose the top quadrant is locked (75%
   to 100%); then in the following cases, case (a) will succeed but (b)
   will not (return -EINVAL):
     (a) user requests lock 3rd quadrant (50% to 75%)
     (b) user requests lock 3rd quadrant, minus a few blocks (e.g., 50%
         to 73%)
   Case (b) *should* fail, since we'd have to lock blocks that weren't
   requested. But the old implementation didn't know the difference and
   would lock the entire second half (50% to 100%)

This refactoring work will also help enable the addition of
mtd_is_locked() support and potentially the support of bottom boot
protection (TB=1).

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: spi-nor: fixup kernel-doc for flash lock/unlock function pointers
Brian Norris [Tue, 1 Sep 2015 19:57:10 +0000 (12:57 -0700)]
mtd: spi-nor: fixup kernel-doc for flash lock/unlock function pointers

I got the names of these fields wrong.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: spi-nor: use SNOR_MFR_* instead of CFI_MFR_*
Brian Norris [Tue, 1 Sep 2015 19:57:09 +0000 (12:57 -0700)]
mtd: spi-nor: use SNOR_MFR_* instead of CFI_MFR_*

No functional change, just cosmetic.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: spi-nor: add SPI NOR manufacturer IDs
Brian Norris [Tue, 1 Sep 2015 19:57:08 +0000 (12:57 -0700)]
mtd: spi-nor: add SPI NOR manufacturer IDs

These are often similar for CFI (parallel NOR) and for SPI NOR, but they
aren't always the same, for various reasons (different namespaces,
company acquisitions and renames, etc.). And some don't have CFI_MFR_*
entries at all.

So let's make a proper place to list the SPI NOR IDs, with all the SPI
NOR specific assumptions and comments.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: spi-nor: make bitfield constants more consistent
Brian Norris [Tue, 1 Sep 2015 19:57:07 +0000 (12:57 -0700)]
mtd: spi-nor: make bitfield constants more consistent

These status bits use different ways of representing similar integer
constants -- some are decimal, some are hex. Make them more consistent.

At the same time, impose my own preference, since IMO it's clearer what
these are when using the BIT() macro.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: spi-nor: make implicit <linux/bitops.h> dependency explicit
Brian Norris [Tue, 1 Sep 2015 19:57:06 +0000 (12:57 -0700)]
mtd: spi-nor: make implicit <linux/bitops.h> dependency explicit

We use BIT() in the header. No real problem for now, but it's better to
be accurate.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: spi-nor: Add support for s25fl004k
Sean Nyekjaer [Tue, 13 Oct 2015 06:50:30 +0000 (08:50 +0200)]
mtd: spi-nor: Add support for s25fl004k

Signed-off-by: Sean Nyekjaer <sean.nyekjaer@prevas.dk>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: spi-nor: s25fl204k supports dual I/0
Sean Nyekjaer [Tue, 13 Oct 2015 06:51:14 +0000 (08:51 +0200)]
mtd: spi-nor: s25fl204k supports dual I/0

Signed-off-by: Sean Nyekjaer <sean.nyekjaer@prevas.dk>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: pass page number to ecc->write_xxx() methods
Boris BREZILLON [Tue, 13 Oct 2015 09:22:18 +0000 (11:22 +0200)]
mtd: nand: pass page number to ecc->write_xxx() methods

The ->read_xxx() methods are all passed the page number the NAND controller
is supposed to read, but ->write_xxx() do not have such a parameter.

This is a problem if we want to properly implement data
scrambling/randomization in order to mitigate MLC sensibility to repeated
pattern: to prevent bitflips in adjacent pages in the same block we need
to avoid repeating the same pattern at the same offset in those pages,
hence the randomizer/scrambler engine need to be passed the page value
in order to adapt its seed accordingly.

Moreover, adding the page parameter to the ->write_xxx() methods add some
consistency to the current API.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
CC: Josh Wu <josh.wu@atmel.com>
CC: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
CC: Maxime Ripard <maxime.ripard@free-electrons.com>
CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CC: Huang Shijie <shijie.huang@arm.com>
CC: Stefan Agner <stefan@agner.ch>
CC: devel@driverdev.osuosl.org
CC: linux-arm-kernel@lists.infradead.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: txx9ndfmc: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:39:09 +0000 (22:39 +0200)]
mtd: nand: txx9ndfmc: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner value set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: jz4740_nand: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:51 +0000 (22:38 +0200)]
mtd: nand: jz4740_nand: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner value set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: fsl_upm: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:46 +0000 (22:38 +0200)]
mtd: nand: fsl_upm: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: socrates_nand: drop owner assignment
Frans Klaver [Wed, 10 Jun 2015 20:39:06 +0000 (22:39 +0200)]
mtd: nand: socrates_nand: drop owner assignment

Owner is automatically set by mtdcore. Make use of that.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: fsl_elbc_nand: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:44 +0000 (22:38 +0200)]
mtd: nand: fsl_elbc_nand: show parent device in sysfs

Fix a bug where mtd parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner value set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: pxa3xx_nand: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:39:01 +0000 (22:39 +0200)]
mtd: nand: pxa3xx_nand: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner value set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: gpio: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:48 +0000 (22:38 +0200)]
mtd: nand: gpio: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner value set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agostaging: mt29f_spinand: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:39:14 +0000 (22:39 +0200)]
staging: mt29f_spinand: show parent device in sysfs

Fix a bug where mtd parent device symlinks aren't shown in sysfs.

While at it, take advantage of the default owner and name values set by
mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: onenand: omap2: drop owner and name assignment
Frans Klaver [Wed, 10 Jun 2015 20:39:11 +0000 (22:39 +0200)]
mtd: onenand: omap2: drop owner and name assignment

Owner and name are automatically set by mtdcore. Make use of that.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: s3c2410: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:39:03 +0000 (22:39 +0200)]
mtd: nand: s3c2410: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: sharpsl: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:39:05 +0000 (22:39 +0200)]
mtd: nand: sharpsl: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner value set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: omap2: show parent device structure in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:57 +0000 (22:38 +0200)]
mtd: nand: omap2: show parent device structure in sysfs

Make sure the device structure is properly shown in sysfs by properly
filling in dev.parent.

While at it, make use of the default owner and name values set by
mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: onenand: samsung: drop owner assignment
Frans Klaver [Wed, 10 Jun 2015 20:39:12 +0000 (22:39 +0200)]
mtd: onenand: samsung: drop owner assignment

Owner is automatically set by mtdcore. Make use of that.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: lpc32xx_mlc: drop owner assignment
Frans Klaver [Wed, 10 Jun 2015 20:38:52 +0000 (22:38 +0200)]
mtd: nand: lpc32xx_mlc: drop owner assignment

Owner is automatically set by mtdcore. Make use of that.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: ndfc: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:55 +0000 (22:38 +0200)]
mtd: nand: ndfc: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: pasemi_nand: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:59 +0000 (22:38 +0200)]
mtd: nand: pasemi_nand: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner value set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: mxc_nand: drop owner assignment
Frans Klaver [Wed, 10 Jun 2015 20:38:54 +0000 (22:38 +0200)]
mtd: nand: mxc_nand: drop owner assignment

Owner is automatically set by mtdcore. Make use of that.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: onenand: generic: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:39:10 +0000 (22:39 +0200)]
mtd: onenand: generic: show parent device in sysfs

Fix a bug where mtd parent device symlinks aren't shown in sysfs.

While at it, take advantage of the default owner and name values set by
mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: tmio_nand: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:39:08 +0000 (22:39 +0200)]
mtd: nand: tmio_nand: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: sunxi_nand: drop owner assignment
Frans Klaver [Wed, 10 Jun 2015 20:39:07 +0000 (22:39 +0200)]
mtd: nand: sunxi_nand: drop owner assignment

Owner is automatically set by mtdcore. Make use of that.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: sh_flctl: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:39:04 +0000 (22:39 +0200)]
mtd: nand: sh_flctl: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: r852: drop owner assignment
Frans Klaver [Wed, 10 Jun 2015 20:39:02 +0000 (22:39 +0200)]
mtd: nand: r852: drop owner assignment

Owner is automatically set by mtdcore. Make use of that.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: plat_nand: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:39:00 +0000 (22:39 +0200)]
mtd: nand: plat_nand: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner and name set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: orion_nand: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:58 +0000 (22:38 +0200)]
mtd: nand: orion_nand: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner value set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: nuc900_nand: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:56 +0000 (22:38 +0200)]
mtd: nand: nuc900_nand: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner value set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: mpc5121_nfc: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:53 +0000 (22:38 +0200)]
mtd: nand: mpc5121_nfc: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: hisi504_nand: drop owner assignment
Frans Klaver [Wed, 10 Jun 2015 20:38:50 +0000 (22:38 +0200)]
mtd: nand: hisi504_nand: drop owner assignment

Owner is automatically set by mtdcore. Make use of that.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: gpmi-nand: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:49 +0000 (22:38 +0200)]
mtd: nand: gpmi-nand: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: fsmc_nand: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:47 +0000 (22:38 +0200)]
mtd: nand: fsmc_nand: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner value set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: fsl_ifc_nand: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:45 +0000 (22:38 +0200)]
mtd: nand: fsl_ifc_nand: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: docg4: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:43 +0000 (22:38 +0200)]
mtd: nand: docg4: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner value set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: denali: drop owner assignment
Frans Klaver [Wed, 10 Jun 2015 20:38:42 +0000 (22:38 +0200)]
mtd: nand: denali: drop owner assignment

Owner is automatically set by mtdcore. Make use of that.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: davinci_nand: drop owner and name assignment
Frans Klaver [Wed, 10 Jun 2015 20:38:41 +0000 (22:38 +0200)]
mtd: nand: davinci_nand: drop owner and name assignment

Owner and name are automatically set by mtdcore. Make use of that.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: cafe_nand: drop owner assignment
Frans Klaver [Wed, 10 Jun 2015 20:38:40 +0000 (22:38 +0200)]
mtd: nand: cafe_nand: drop owner assignment

Owner is automatically set by mtdcore. Make use of that.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
8 years agomtd: nand: bf5xx_nand: show parent device in sysfs
Frans Klaver [Wed, 10 Jun 2015 20:38:39 +0000 (22:38 +0200)]
mtd: nand: bf5xx_nand: show parent device in sysfs

Fix a bug where parent device symlinks aren't shown in sysfs.

While at it, make use of the default owner value set by mtdcore.

Signed-off-by: Frans Klaver <fransklaver@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>