mtd: nand: fix NAND_BUSWIDTH_AUTO for x16 devices

The code for NAND_BUSWIDTH_AUTO is broken. According to Alexander:

  "I have a problem with attach NAND UBI in 16 bit mode.
   NAND works fine if I specify NAND_BUSWIDTH_16 option, but not
   working with NAND_BUSWIDTH_AUTO option. In second case NAND
   chip is identifyed with ONFI."

See his report for the rest of the details:

  http://lists.infradead.org/pipermail/linux-mtd/2013-July/047515.html

Anyway, the problem is that nand_set_defaults() is called twice, we
intend it to reset the chip functions to their x16 buswidth verions
if the buswidth changed from x8 to x16; however, nand_set_defaults()
does exactly nothing if called a second time.

Fix this by hacking nand_set_defaults() to reset the buswidth-dependent
functions if they were set to the x8 version the first time. Note that
this does not do anything to reset from x16 to x8, but that's not the
supported use case for NAND_BUSWIDTH_AUTO anyway.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reported-by: Alexander Shiyan <shc_work@mail.ru>
Tested-by: Alexander Shiyan <shc_work@mail.ru>
Cc: Matthieu Castet <matthieu.castet@parrot.com>
Cc: <stable@vger.kernel.org> # v3.8+
mtd: cafe_nand: use devres functions for easier cleanup

There are several little bits of memory that need to be removed properly
on error paths and on device removal. Just use the devres versions of
the allocation functions, and they will be cleaned up automatically on
device removal.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
mtd: nand: kill NAND_OWN_BUFFERS

We can allocate our NAND buffers with devres. That way, they can be
automatically freed when the device is released, and we don't have to
track them with the NAND_OWN_BUFFERS flag.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
mtd: nand: kill NAND_BBT_DYNAMICSTRUCT

We can allocate bad block patterns with devres. That way, they can be
automatically freed when the device is released, and we don't have to
track them with the NAND_BBT_DYNAMICSTRUCT flag.

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