[PATCH v5 41/58] mtd: nand: socrates: use the mtd instance embedded in struct nand_chip

2015-12-11 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes since v4:
- fix build error

---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/socrates_nand.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/socrates_nand.c b/drivers/mtd/nand/socrates_nand.c
index 2dfb1e0..925761c 100644
--- a/drivers/mtd/nand/socrates_nand.c
+++ b/drivers/mtd/nand/socrates_nand.c
@@ -30,7 +30,6 @@
 
 struct socrates_nand_host {
struct nand_chipnand_chip;
-   struct mtd_info mtd;
void __iomem*io_base;
struct device   *dev;
 };
@@ -159,8 +158,8 @@ static int socrates_nand_probe(struct platform_device 
*ofdev)
return -EIO;
}
 
-   mtd = >mtd;
nand_chip = >nand_chip;
+   mtd = nand_to_mtd(nand_chip);
host->dev = >dev;
 
nand_chip->priv = host; /* link the private data structures */
@@ -216,7 +215,7 @@ out:
 static int socrates_nand_remove(struct platform_device *ofdev)
 {
struct socrates_nand_host *host = dev_get_drvdata(>dev);
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand_chip);
 
nand_release(mtd);
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 01/58] mtd: nand: denali: add missing nand_release() call in denali_remove()

2015-12-11 Thread Boris Brezillon
Unregister the NAND device from the NAND subsystem when removing a denali
NAND controller, otherwise the MTD attached to the NAND device is still
exposed by the MTD layer, and accesses to this device will likely crash
the system.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes since v4:
- remove Cc stable and fixes tags
- calculate the dma buffer size before calling nand_release()

 drivers/mtd/nand/denali.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 67eb2be..fdfea05 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -1622,9 +1622,11 @@ EXPORT_SYMBOL(denali_init);
 /* driver exit point */
 void denali_remove(struct denali_nand_info *denali)
 {
+   int bufsize = denali->mtd.writesize + denali->mtd.oobsize;
+
+   nand_release(>mtd);
denali_irq_cleanup(denali->irq, denali);
-   dma_unmap_single(denali->dev, denali->buf.dma_buf,
-denali->mtd.writesize + denali->mtd.oobsize,
+   dma_unmap_single(denali->dev, denali->buf.dma_buf, bufsize,
 DMA_BIDIRECTIONAL);
 }
 EXPORT_SYMBOL(denali_remove);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 15/58] mtd: nand: denali: use the mtd instance embedded in struct nand_chip

2015-12-11 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes since v4:
- fix conflict after changes brought in v5 of patch 1

---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---

Conflicts:
drivers/mtd/nand/denali.c
---
 drivers/mtd/nand/denali.c | 69 ++-
 drivers/mtd/nand/denali.h |  1 -
 2 files changed, 38 insertions(+), 32 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index fdfea05..ccab8bc 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -75,7 +75,10 @@ MODULE_PARM_DESC(onfi_timing_mode,
  * this macro allows us to convert from an MTD structure to our own
  * device context (denali) structure.
  */
-#define mtd_to_denali(m) container_of(m, struct denali_nand_info, mtd)
+static inline struct denali_nand_info *mtd_to_denali(struct mtd_info *mtd)
+{
+   return container_of(mtd_to_nand(mtd), struct denali_nand_info, nand);
+}
 
 /*
  * These constants are defined by the driver to enable common driver
@@ -986,6 +989,8 @@ static bool handle_ecc(struct denali_nand_info *denali, 
uint8_t *buf,
 * than one NAND connected.
 */
if (err_byte < ECC_SECTOR_SIZE) {
+   struct mtd_info *mtd =
+   nand_to_mtd(>nand);
int offset;
 
offset = (err_sector *
@@ -995,7 +1000,7 @@ static bool handle_ecc(struct denali_nand_info *denali, 
uint8_t *buf,
err_device;
/* correct the ECC error */
buf[offset] ^= err_correction_value;
-   denali->mtd.ecc_stats.corrected++;
+   mtd->ecc_stats.corrected++;
bitflips++;
}
} else {
@@ -1062,7 +1067,7 @@ static int write_page(struct mtd_info *mtd, struct 
nand_chip *chip,
 {
struct denali_nand_info *denali = mtd_to_denali(mtd);
dma_addr_t addr = denali->buf.dma_buf;
-   size_t size = denali->mtd.writesize + denali->mtd.oobsize;
+   size_t size = mtd->writesize + mtd->oobsize;
uint32_t irq_status;
uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP |
INTR_STATUS__PROGRAM_FAIL;
@@ -1160,7 +1165,7 @@ static int denali_read_page(struct mtd_info *mtd, struct 
nand_chip *chip,
struct denali_nand_info *denali = mtd_to_denali(mtd);
 
dma_addr_t addr = denali->buf.dma_buf;
-   size_t size = denali->mtd.writesize + denali->mtd.oobsize;
+   size_t size = mtd->writesize + mtd->oobsize;
 
uint32_t irq_status;
uint32_t irq_mask = INTR_STATUS__ECC_TRANSACTION_DONE |
@@ -1193,14 +1198,14 @@ static int denali_read_page(struct mtd_info *mtd, 
struct nand_chip *chip,
denali_enable_dma(denali, false);
 
if (check_erased_page) {
-   read_oob_data(>mtd, chip->oob_poi, denali->page);
+   read_oob_data(mtd, chip->oob_poi, denali->page);
 
/* check ECC failures that may have occurred on erased pages */
if (check_erased_page) {
-   if (!is_erased(buf, denali->mtd.writesize))
-   denali->mtd.ecc_stats.failed++;
-   if (!is_erased(buf, denali->mtd.oobsize))
-   denali->mtd.ecc_stats.failed++;
+   if (!is_erased(buf, mtd->writesize))
+   mtd->ecc_stats.failed++;
+   if (!is_erased(buf, mtd->oobsize))
+   mtd->ecc_stats.failed++;
}
}
return max_bitflips;
@@ -1211,7 +1216,7 @@ s

Re: [PATCH v5 01/58] mtd: nand: denali: add missing nand_release() call in denali_remove()

2015-12-11 Thread Boris Brezillon
Hi Dinh,

On Fri, 11 Dec 2015 10:50:21 -0600
Dinh Nguyen <dinh.li...@gmail.com> wrote:

> Hi Boris,
> 
> On Fri, Dec 11, 2015 at 9:10 AM, Boris Brezillon
> <boris.brezil...@free-electrons.com> wrote:
> > + Dinh (who made commit 2a0a288ec258)
> >
> > Also added back the Fixes tag.
> >
> > On Fri, 11 Dec 2015 15:02:34 +0100
> > Boris Brezillon <boris.brezil...@free-electrons.com> wrote:
> >
> >> Unregister the NAND device from the NAND subsystem when removing a denali
> >> NAND controller, otherwise the MTD attached to the NAND device is still
> >> exposed by the MTD layer, and accesses to this device will likely crash
> >> the system.
> >>
> >> Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
> >
> > Fixes: 2a0a288ec258 ("mtd: denali: split the generic driver and PCI layer")
> >
> >> ---
> >> Changes since v4:
> >> - remove Cc stable and fixes tags
> >> - calculate the dma buffer size before calling nand_release()
> >>
> >>  drivers/mtd/nand/denali.c | 6 --
> >>  1 file changed, 4 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
> >> index 67eb2be..fdfea05 100644
> >> --- a/drivers/mtd/nand/denali.c
> >> +++ b/drivers/mtd/nand/denali.c
> >> @@ -1622,9 +1622,11 @@ EXPORT_SYMBOL(denali_init);
> >>  /* driver exit point */
> >>  void denali_remove(struct denali_nand_info *denali)
> >>  {
> >> + int bufsize = denali->mtd.writesize + denali->mtd.oobsize;
> >> +
> >> + nand_release(>mtd);
> >>   denali_irq_cleanup(denali->irq, denali);
> >> - dma_unmap_single(denali->dev, denali->buf.dma_buf,
> >> -  denali->mtd.writesize + denali->mtd.oobsize,
> >> + dma_unmap_single(denali->dev, denali->buf.dma_buf, bufsize,
> >>DMA_BIDIRECTIONAL);
> 
> Not sure what is the need to add bufsize here, but the commit message
> doesn't reflect the change.

You were not in Cc of the first version (my fault), but Brian pointed
that the mtd fields could be in an unknown state after the
nand_release() call (this is currently not the case, but it change in
the future). The idea is to pre-compute the DMA buffer size before
releasing the mtd/nand device to prevent any future issues.

I don't think it is worth mentioning this in the commit message,
because these are just implementation details, but I can add the
following comment before the bufsize declaration:

/*
 * Pre-compute DMA buffer size to avoid any problems in case
 * nand_release() ever changes in a way that mtd->writesize and
 * mtd->oobsize are not reliable after this call.
 */

What do you think?

Best Regards,

Boris

> 
> Dinh



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 01/58] mtd: nand: denali: add missing nand_release() call in denali_remove()

2015-12-11 Thread Boris Brezillon
+ Dinh (who made commit 2a0a288ec258)

Also added back the Fixes tag.

On Fri, 11 Dec 2015 15:02:34 +0100
Boris Brezillon <boris.brezil...@free-electrons.com> wrote:

> Unregister the NAND device from the NAND subsystem when removing a denali
> NAND controller, otherwise the MTD attached to the NAND device is still
> exposed by the MTD layer, and accesses to this device will likely crash
> the system.
> 
> Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>

Fixes: 2a0a288ec258 ("mtd: denali: split the generic driver and PCI layer")

> ---
> Changes since v4:
> - remove Cc stable and fixes tags
> - calculate the dma buffer size before calling nand_release()
> 
>  drivers/mtd/nand/denali.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
> index 67eb2be..fdfea05 100644
> --- a/drivers/mtd/nand/denali.c
> +++ b/drivers/mtd/nand/denali.c
> @@ -1622,9 +1622,11 @@ EXPORT_SYMBOL(denali_init);
>  /* driver exit point */
>  void denali_remove(struct denali_nand_info *denali)
>  {
> + int bufsize = denali->mtd.writesize + denali->mtd.oobsize;
> +
> + nand_release(>mtd);
>   denali_irq_cleanup(denali->irq, denali);
> - dma_unmap_single(denali->dev, denali->buf.dma_buf,
> -  denali->mtd.writesize + denali->mtd.oobsize,
> + dma_unmap_single(denali->dev, denali->buf.dma_buf, bufsize,
>DMA_BIDIRECTIONAL);
>  }
>  EXPORT_SYMBOL(denali_remove);



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 01/58] mtd: nand: denali: add missing nand_release() call in denali_remove()

2015-12-11 Thread Boris Brezillon
Hi Dan,

On Fri, 11 Dec 2015 17:39:47 +0300
Dan Carpenter <dan.carpen...@oracle.com> wrote:

> On Fri, Dec 11, 2015 at 02:53:20PM +0100, Boris Brezillon wrote:
> > Hi Brian,
> > 
> > On Thu, 10 Dec 2015 16:40:08 -0800
> > Brian Norris <computersforpe...@gmail.com> wrote:
> > 
> > > On Thu, Dec 10, 2015 at 08:59:45AM +0100, Boris Brezillon wrote:
> > > > Unregister the NAND device from the NAND subsystem when removing a 
> > > > denali
> > > > NAND controller, otherwise the MTD attached to the NAND device is still
> > > > exposed by the MTD layer, and accesses to this device will likely crash
> > > > the system.
> > > > 
> > > > Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
> > > > Cc: <sta...@vger.kernel.org> #3.8+
> > > 
> > > Does this follow these rules, from
> > > Documentation/stable_kernel_rules.txt?
> > > 
> > >  - It must be obviously correct and tested.
> > > 
> > >  - It must fix a real bug that bothers people (not a, "This could be a
> > >problem..." type thing).
> > 
> > As you wish, I'll remove those Cc and Fixes tags, or just drop the
> > patch if you think it's useless...
> 
> The fixes tag is a separate thing from CCing stable.  It's useful on by
> itself.  I always put the person who wrote the original patch in the To:
> header so they can review and comment if I have made a mistake.

Noted. I added back the Fixes tag and added Dinh Nguyen (the commit
author) in the loop.

Thanks,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 01/58] mtd: nand: denali: add missing nand_release() call in denali_remove()

2015-12-11 Thread Boris Brezillon
Hi Brian,

On Thu, 10 Dec 2015 16:40:08 -0800
Brian Norris <computersforpe...@gmail.com> wrote:

> On Thu, Dec 10, 2015 at 08:59:45AM +0100, Boris Brezillon wrote:
> > Unregister the NAND device from the NAND subsystem when removing a denali
> > NAND controller, otherwise the MTD attached to the NAND device is still
> > exposed by the MTD layer, and accesses to this device will likely crash
> > the system.
> > 
> > Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
> > Cc: <sta...@vger.kernel.org> #3.8+
> 
> Does this follow these rules, from
> Documentation/stable_kernel_rules.txt?
> 
>  - It must be obviously correct and tested.
> 
>  - It must fix a real bug that bothers people (not a, "This could be a
>problem..." type thing).

Sorry to bring the "stable or not stable (that is the question :-))"
debate back, but after thinking a bit more about the implications of
this missing nand_release() call, I think it is worth backporting the
fix to all stable kernels.
The reason is, it can potentially introduce a security hole, because if
the mtd device is not unregister but the underlying mtd object is freed
and the kernel reuses the same memory region for a different object,
the MTD layer will possibly call one of the mtd->_method() function,
and this field might point to another completely different function.

You'll say that denali devices are probably never removed and this is
the reason why people have never seen this problem before, which would
be a good reason to not bother backporting the patch.
But, given that the driver can be compiled as a module (the user can
possibly load/unload it, which will in turn create/destroy the
NAND/MTD device), and that the denali controller can be exposed through
a PCI bus (which, AFAIK is hotpluggable), I really think this fix
should be sent to stable.

Best Regards,

Boris

> 
> > Fixes: 2a0a288ec258 ("mtd: denali: split the generic driver and PCI layer")
> > ---
> >  drivers/mtd/nand/denali.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
> > index 67eb2be..8feece3 100644
> > --- a/drivers/mtd/nand/denali.c
> > +++ b/drivers/mtd/nand/denali.c
> > @@ -1622,6 +1622,7 @@ EXPORT_SYMBOL(denali_init);
> >  /* driver exit point */
> >  void denali_remove(struct denali_nand_info *denali)
> >  {
> > +   nand_release(>mtd);
> > denali_irq_cleanup(denali->irq, denali);
> > dma_unmap_single(denali->dev, denali->buf.dma_buf,
> >  denali->mtd.writesize + denali->mtd.oobsize,
> 
> It feels a bit odd to allow usage of MTD fields after it has been
> unregistered. Maybe precompute this before the nand_release()?
> 
> Brian



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 01/58] mtd: nand: denali: add missing nand_release() call in denali_remove()

2015-12-11 Thread Boris Brezillon
Hi Brian,

On Thu, 10 Dec 2015 16:40:08 -0800
Brian Norris <computersforpe...@gmail.com> wrote:

> On Thu, Dec 10, 2015 at 08:59:45AM +0100, Boris Brezillon wrote:
> > Unregister the NAND device from the NAND subsystem when removing a denali
> > NAND controller, otherwise the MTD attached to the NAND device is still
> > exposed by the MTD layer, and accesses to this device will likely crash
> > the system.
> > 
> > Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
> > Cc: <sta...@vger.kernel.org> #3.8+
> 
> Does this follow these rules, from
> Documentation/stable_kernel_rules.txt?
> 
>  - It must be obviously correct and tested.
> 
>  - It must fix a real bug that bothers people (not a, "This could be a
>problem..." type thing).

As you wish, I'll remove those Cc and Fixes tags, or just drop the
patch if you think it's useless...
I just noticed the bug while reworking this series, and thought it
would be useful to fix it, but I honestly don't care if it's applied
or not (I don't use this platform).

> 
> > Fixes: 2a0a288ec258 ("mtd: denali: split the generic driver and PCI layer")
> > ---
> >  drivers/mtd/nand/denali.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
> > index 67eb2be..8feece3 100644
> > --- a/drivers/mtd/nand/denali.c
> > +++ b/drivers/mtd/nand/denali.c
> > @@ -1622,6 +1622,7 @@ EXPORT_SYMBOL(denali_init);
> >  /* driver exit point */
> >  void denali_remove(struct denali_nand_info *denali)
> >  {
> > +   nand_release(>mtd);
> > denali_irq_cleanup(denali->irq, denali);
> > dma_unmap_single(denali->dev, denali->buf.dma_buf,
> >  denali->mtd.writesize + denali->mtd.oobsize,
> 
> It feels a bit odd to allow usage of MTD fields after it has been
> unregistered. Maybe precompute this before the nand_release()?

nand_realease() is not releasing the mtd instance or re-initialazing
its field, so it should be safe, but I agree that pre-computing the DMA
buffer size is more future-proof.

I'll fix that, send a v5 and let you decide whether it's needed or not.

Best Regards,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 28/58] mtd: nand: mxc: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/mxc_nand.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index b291258..9dd71af 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -173,7 +173,6 @@ struct mxc_nand_devtype_data {
 };
 
 struct mxc_nand_host {
-   struct mtd_info mtd;
struct nand_chipnand;
struct device   *dev;
 
@@ -1514,7 +1513,7 @@ static int mxcnd_probe(struct platform_device *pdev)
host->dev = >dev;
/* structures must be linked */
this = >nand;
-   mtd = >mtd;
+   mtd = nand_to_mtd(this);
mtd->priv = this;
mtd->dev.parent = >dev;
mtd->name = DRIVER_NAME;
@@ -1702,7 +1701,7 @@ static int mxcnd_remove(struct platform_device *pdev)
 {
struct mxc_nand_host *host = platform_get_drvdata(pdev);
 
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>nand));
if (host->clk_act)
clk_disable_unprepare(host->clk);
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 29/58] mtd: nand: nandsim: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/nandsim.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index eb2a567..442eeaf 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -2236,13 +2236,13 @@ static int __init ns_init_module(void)
}
 
/* Allocate and initialize mtd_info, nand_chip and nandsim structures */
-   nsmtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip)
-   + sizeof(struct nandsim), GFP_KERNEL);
-   if (!nsmtd) {
+   chip = kzalloc(sizeof(struct nand_chip) + sizeof(struct nandsim),
+  GFP_KERNEL);
+   if (!chip) {
NS_ERR("unable to allocate core structures.\n");
return -ENOMEM;
}
-   chip= (struct nand_chip *)(nsmtd + 1);
+   nsmtd   = nand_to_mtd(chip);
 nsmtd->priv = (void *)chip;
nand= (struct nandsim *)(chip + 1);
chip->priv  = (void *)nand;
@@ -2392,7 +2392,7 @@ err_exit:
for (i = 0;i < ARRAY_SIZE(nand->partitions); ++i)
kfree(nand->partitions[i].name);
 error:
-   kfree(nsmtd);
+   kfree(chip);
free_lists();
 
return retval;
@@ -2413,7 +2413,7 @@ static void __exit ns_cleanup_module(void)
nand_release(nsmtd); /* Unregister driver */
for (i = 0;i < ARRAY_SIZE(ns->partitions); ++i)
kfree(ns->partitions[i].name);
-   kfree(nsmtd);/* Free other structures */
+   kfree(mtd_to_nand(nsmtd));/* Free other structures */
free_lists();
 }
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 26/58] mtd: nand: lpc32xx: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/lpc32xx_mlc.c | 7 +++
 drivers/mtd/nand/lpc32xx_slc.c | 7 +++
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/lpc32xx_mlc.c b/drivers/mtd/nand/lpc32xx_mlc.c
index 3738856..3400b3f 100644
--- a/drivers/mtd/nand/lpc32xx_mlc.c
+++ b/drivers/mtd/nand/lpc32xx_mlc.c
@@ -173,7 +173,6 @@ struct lpc32xx_nand_host {
struct nand_chipnand_chip;
struct lpc32xx_mlc_platform_data *pdata;
struct clk  *clk;
-   struct mtd_info mtd;
void __iomem*io_base;
int irq;
struct lpc32xx_nand_cfg_mlc *ncfg;
@@ -566,7 +565,7 @@ static void lpc32xx_ecc_enable(struct mtd_info *mtd, int 
mode)
 
 static int lpc32xx_dma_setup(struct lpc32xx_nand_host *host)
 {
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand_chip);
dma_cap_mask_t mask;
 
if (!host->pdata || !host->pdata->dma_filter) {
@@ -660,8 +659,8 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)

host->io_base_phy = rc->start;
 
-   mtd = >mtd;
nand_chip = >nand_chip;
+   mtd = nand_to_mtd(nand_chip);
if (pdev->dev.of_node)
host->ncfg = lpc32xx_parse_dt(>dev);
if (!host->ncfg) {
@@ -814,7 +813,7 @@ err_exit1:
 static int lpc32xx_nand_remove(struct platform_device *pdev)
 {
struct lpc32xx_nand_host *host = platform_get_drvdata(pdev);
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand_chip);
 
nand_release(mtd);
free_irq(host->irq, host);
diff --git a/drivers/mtd/nand/lpc32xx_slc.c b/drivers/mtd/nand/lpc32xx_slc.c
index fcd9fac..61b2961 100644
--- a/drivers/mtd/nand/lpc32xx_slc.c
+++ b/drivers/mtd/nand/lpc32xx_slc.c
@@ -204,7 +204,6 @@ struct lpc32xx_nand_host {
struct nand_chipnand_chip;
struct lpc32xx_slc_platform_data *pdata;
struct clk  *clk;
-   struct mtd_info mtd;
void __iomem*io_base;
struct lpc32xx_nand_cfg_slc *ncfg;
 
@@ -703,7 +702,7 @@ static int lpc32xx_nand_write_page_raw_syndrome(struct 
mtd_info *mtd,
 
 static int lpc32xx_nand_dma_setup(struct lpc32xx_nand_host *host)
 {
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand_chip);
dma_cap_mask_t mask;
 
if (!host->pdata || !host->pdata->dma_filter) {
@@ -799,8 +798,8 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 
host->pdata = dev_get_platdata(>dev);
 
-   mtd = >mtd;
chip = >nand_chip;
+   mtd = nand_to_mtd(chip);
chip->priv = host;
nand_set_flash_node(chip, pdev->dev.of_node);
mtd->priv = chip;
@@ -932,7 +931,7 @@ static int lpc32xx_nand_remove(struct platform_device *pdev)
 {
uint32_t tmp;
struct lpc32xx_nand_host *host = platform_get_drvdata(pdev);
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand_chip);
 
nand_release(mtd);
dma_release_channel(host->dma_chan);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 25/58] mtd: nand: jz4740: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/jz4740_nand.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/jz4740_nand.c b/drivers/mtd/nand/jz4740_nand.c
index 5a06fba..03239a5 100644
--- a/drivers/mtd/nand/jz4740_nand.c
+++ b/drivers/mtd/nand/jz4740_nand.c
@@ -59,7 +59,6 @@
 #define JZ_NAND_MEM_ADDR_OFFSET 0x1
 
 struct jz_nand {
-   struct mtd_info mtd;
struct nand_chip chip;
void __iomem *base;
struct resource *mem;
@@ -76,7 +75,7 @@ struct jz_nand {
 
 static inline struct jz_nand *mtd_to_jz_nand(struct mtd_info *mtd)
 {
-   return container_of(mtd, struct jz_nand, mtd);
+   return container_of(mtd_to_nand(mtd), struct jz_nand, chip);
 }
 
 static void jz_nand_select_chip(struct mtd_info *mtd, int chipnr)
@@ -334,8 +333,8 @@ static int jz_nand_detect_bank(struct platform_device *pdev,
char gpio_name[9];
char res_name[6];
uint32_t ctrl;
-   struct mtd_info *mtd = >mtd;
struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(chip);
 
/* Request GPIO port. */
gpio = JZ_GPIO_MEM_CS0 + bank - 1;
@@ -432,8 +431,8 @@ static int jz_nand_probe(struct platform_device *pdev)
goto err_iounmap_mmio;
}
 
-   mtd = >mtd;
chip= >chip;
+   mtd = nand_to_mtd(chip);
mtd->priv   = chip;
mtd->dev.parent = >dev;
mtd->name   = "jz4740-nand";
@@ -543,7 +542,7 @@ static int jz_nand_remove(struct platform_device *pdev)
struct jz_nand *nand = platform_get_drvdata(pdev);
size_t i;
 
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
 
/* Deassert and disable all chips */
writel(0, nand->base + JZ_REG_NAND_CTRL);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 35/58] mtd: nand: plat: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/plat_nand.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index 06ac6c6..796eb7d 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -20,7 +20,6 @@
 
 struct plat_nand_data {
struct nand_chipchip;
-   struct mtd_info mtd;
void __iomem*io_base;
 };
 
@@ -31,6 +30,7 @@ static int plat_nand_probe(struct platform_device *pdev)
 {
struct platform_nand_data *pdata = dev_get_platdata(>dev);
struct plat_nand_data *data;
+   struct mtd_info *mtd;
struct resource *res;
const char **part_types;
int err = 0;
@@ -58,8 +58,9 @@ static int plat_nand_probe(struct platform_device *pdev)
 
data->chip.priv = 
nand_set_flash_node(>chip, pdev->dev.of_node);
-   data->mtd.priv = >chip;
-   data->mtd.dev.parent = >dev;
+   mtd = nand_to_mtd(>chip);
+   mtd->priv = >chip;
+   mtd->dev.parent = >dev;
 
data->chip.IO_ADDR_R = data->io_base;
data->chip.IO_ADDR_W = data->io_base;
@@ -87,21 +88,21 @@ static int plat_nand_probe(struct platform_device *pdev)
}
 
/* Scan to find existence of the device */
-   if (nand_scan(>mtd, pdata->chip.nr_chips)) {
+   if (nand_scan(mtd, pdata->chip.nr_chips)) {
err = -ENXIO;
goto out;
}
 
part_types = pdata->chip.part_probe_types;
 
-   err = mtd_device_parse_register(>mtd, part_types, NULL,
+   err = mtd_device_parse_register(mtd, part_types, NULL,
pdata->chip.partitions,
pdata->chip.nr_partitions);
 
if (!err)
return err;
 
-   nand_release(>mtd);
+   nand_release(mtd);
 out:
if (pdata->ctrl.remove)
pdata->ctrl.remove(pdev);
@@ -116,7 +117,7 @@ static int plat_nand_remove(struct platform_device *pdev)
struct plat_nand_data *data = platform_get_drvdata(pdev);
struct platform_nand_data *pdata = dev_get_platdata(>dev);
 
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
if (pdata->ctrl.remove)
pdata->ctrl.remove(pdev);
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 34/58] mtd: nand: pasemi: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/pasemi_nand.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/pasemi_nand.c b/drivers/mtd/nand/pasemi_nand.c
index 0ececac..4dd2985 100644
--- a/drivers/mtd/nand/pasemi_nand.c
+++ b/drivers/mtd/nand/pasemi_nand.c
@@ -110,17 +110,15 @@ static int pasemi_nand_probe(struct platform_device 
*ofdev)
pr_debug("pasemi_nand at %pR\n", );
 
/* Allocate memory for MTD device structure and private data */
-   pasemi_nand_mtd = kzalloc(sizeof(struct mtd_info) +
- sizeof(struct nand_chip), GFP_KERNEL);
-   if (!pasemi_nand_mtd) {
+   chip = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
+   if (!chip) {
printk(KERN_WARNING
   "Unable to allocate PASEMI NAND MTD device structure\n");
err = -ENOMEM;
goto out;
}
 
-   /* Get pointer to private data */
-   chip = (struct nand_chip *)_nand_mtd[1];
+   pasemi_nand_mtd = nand_to_mtd(chip);
 
/* Link the private data with the MTD structure */
pasemi_nand_mtd->priv = chip;
@@ -180,7 +178,7 @@ static int pasemi_nand_probe(struct platform_device *ofdev)
  out_ior:
iounmap(chip->IO_ADDR_R);
  out_mtd:
-   kfree(pasemi_nand_mtd);
+   kfree(chip);
  out:
return err;
 }
@@ -202,7 +200,7 @@ static int pasemi_nand_remove(struct platform_device *ofdev)
iounmap(chip->IO_ADDR_R);
 
/* Free the MTD device structure */
-   kfree(pasemi_nand_mtd);
+   kfree(chip);
 
pasemi_nand_mtd = NULL;
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 36/58] mtd: nand: pxa3xx: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/pxa3xx_nand.c | 33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index dc39a98..c4d5788 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -167,7 +167,6 @@ enum pxa3xx_nand_variant {
 
 struct pxa3xx_nand_host {
struct nand_chipchip;
-   struct mtd_info *mtd;
void*info_data;
 
/* page size of attached chip */
@@ -450,14 +449,15 @@ static int pxa3xx_nand_init_timings_compat(struct 
pxa3xx_nand_host *host,
struct nand_chip *chip = >chip;
struct pxa3xx_nand_info *info = host->info_data;
const struct pxa3xx_nand_flash *f = NULL;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
int i, id, ntypes;
 
ntypes = ARRAY_SIZE(builtin_flash_types);
 
-   chip->cmdfunc(host->mtd, NAND_CMD_READID, 0x00, -1);
+   chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
 
-   id = chip->read_byte(host->mtd);
-   id |= chip->read_byte(host->mtd) << 0x8;
+   id = chip->read_byte(mtd);
+   id |= chip->read_byte(mtd) << 0x8;
 
for (i = 0; i < ntypes; i++) {
f = _flash_types[i];
@@ -890,7 +890,7 @@ static void set_command_address(struct pxa3xx_nand_info 
*info,
 static void prepare_start_command(struct pxa3xx_nand_info *info, int command)
 {
struct pxa3xx_nand_host *host = info->host[info->cs];
-   struct mtd_info *mtd = host->mtd;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
 
/* reset data and oob column point to handle data */
info->buf_start = 0;
@@ -943,7 +943,7 @@ static int prepare_set_command(struct pxa3xx_nand_info 
*info, int command,
struct mtd_info *mtd;
 
host = info->host[info->cs];
-   mtd = host->mtd;
+   mtd = nand_to_mtd(>chip);
addr_cycle = 0;
exec_cmd = 1;
 
@@ -1415,8 +1415,8 @@ static int pxa3xx_nand_config_ident(struct 
pxa3xx_nand_info *info)
 static void pxa3xx_nand_config_tail(struct pxa3xx_nand_info *info)
 {
struct pxa3xx_nand_host *host = info->host[info->cs];
-   struct mtd_info *mtd = host->mtd;
-   struct nand_chip *chip = mtd_to_nand(mtd);
+   struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(chip);
 
info->reg_ndcr |= (host->col_addr_cycles == 2) ? NDCR_RA_START : 0;
info->reg_ndcr |= (chip->page_shift == 6) ? NDCR_PG_PER_BLK : 0;
@@ -1693,19 +1693,20 @@ static int alloc_nand_resource(struct platform_device 
*pdev)
pdata = dev_get_platdata(>dev);
if (pdata->num_cs <= 0)
return -ENODEV;
-   info = devm_kzalloc(>dev, sizeof(*info) + (sizeof(*mtd) +
-   sizeof(*host)) * pdata->num_cs, GFP_KERNEL);
+   info = devm_kzalloc(>dev,
+   sizeof(*info) + sizeof(*host) * pdata->num_cs,
+   GFP_KERNEL);
if (!info)
return -ENOMEM;
 
info->pdev = pdev;
info->variant = pxa3xx_nand_get_variant(pdev);
for (cs = 0; cs < pdata->num_cs; cs++) {
-   mtd = (void *)[1] + (sizeof(*mtd) + sizeof(*host)) * cs;
-   chip = (struct nand_chip *)([1]);
-   host = (struct pxa3xx_nand_host *)chip;
+   host = (void *)[1] + sizeof(*host) * cs;
+   chip = >chip;
+   chip->priv = host;
+   mtd = nand_to_mtd(chip);
info->host[cs] = host;
-   host->mtd = mtd;
host->cs = cs;
host->info_data = info;
mtd->priv = chip;
@@ -1833,7 +1834,7 @@ static int pxa3xx_nand_remove(struct platform_device 
*pdev)
clk_disable_unprepare(info->clk);
 
for (cs = 0; cs < pdata->num_cs; cs++)
-   nand_release(info->host[cs]->mtd);
+   nand_release(nand_to_mtd(>host[cs]->chip));
return 0;
 }
 
@@ -1904,7 +1905,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
info = platform_get_drvdata(pdev);
probe_success = 0;
for (cs = 0; cs < pdata->num_cs; cs++) {
-   struct mtd_info *mtd = info->host[cs]->mtd;
+   struct mtd_info *mtd = nand_to_mtd(>host[cs]->chip);
 
/*
 * The mtd name matches the one used in 'mtdparts' kernel
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 33/58] mtd: nand: orion: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/orion_nand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index 4ed4f67..087a040 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -85,11 +85,11 @@ static int __init orion_nand_probe(struct platform_device 
*pdev)
u32 val = 0;
 
nc = devm_kzalloc(>dev,
-   sizeof(struct nand_chip) + sizeof(struct mtd_info),
+   sizeof(struct nand_chip),
GFP_KERNEL);
if (!nc)
return -ENOMEM;
-   mtd = (struct mtd_info *)(nc + 1);
+   mtd = nand_to_mtd(nc);
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
io_base = devm_ioremap_resource(>dev, res);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 16/58] mtd: nand: diskonchip: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/diskonchip.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index 5f7bcc8..fff7a4a 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -1556,15 +1556,15 @@ static int __init doc_probe(unsigned long physadr)
 
printk(KERN_NOTICE "DiskOnChip found at 0x%lx\n", physadr);
 
-   len = sizeof(struct mtd_info) +
-   sizeof(struct nand_chip) + sizeof(struct doc_priv) + (2 * 
sizeof(struct nand_bbt_descr));
-   mtd = kzalloc(len, GFP_KERNEL);
-   if (!mtd) {
+   len = sizeof(struct nand_chip) + sizeof(struct doc_priv) +
+ (2 * sizeof(struct nand_bbt_descr));
+   nand = kzalloc(len, GFP_KERNEL);
+   if (!nand) {
ret = -ENOMEM;
goto fail;
}
 
-   nand= (struct nand_chip *) (mtd + 1);
+   mtd = nand_to_mtd(nand);
doc = (struct doc_priv *) (nand + 1);
nand->bbt_td= (struct nand_bbt_descr *) (doc + 1);
nand->bbt_md= nand->bbt_td + 1;
@@ -1615,7 +1615,7 @@ static int __init doc_probe(unsigned long physadr)
   haven't yet added it.  This is handled without incident by
   mtd_device_unregister, as far as I can tell. */
nand_release(mtd);
-   kfree(mtd);
+   kfree(nand);
goto fail;
}
 
@@ -1650,7 +1650,7 @@ static void release_nanddoc(void)
nand_release(mtd);
iounmap(doc->virtadr);
release_mem_region(doc->physadr, DOC_IOREMAP_LEN);
-   kfree(mtd);
+   kfree(nand);
}
 }
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 18/58] mtd: nand: fsl_elbc: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/fsl_elbc_nand.c | 26 +++---
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
index ad6d5da..7bde76a 100644
--- a/drivers/mtd/nand/fsl_elbc_nand.c
+++ b/drivers/mtd/nand/fsl_elbc_nand.c
@@ -48,7 +48,6 @@
 /* mtd information per set */
 
 struct fsl_elbc_mtd {
-   struct mtd_info mtd;
struct nand_chip chip;
struct fsl_lbc_ctrl *ctrl;
 
@@ -742,12 +741,13 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
struct fsl_lbc_regs __iomem *lbc = ctrl->regs;
struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = ctrl->nand;
struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(chip);
 
dev_dbg(priv->dev, "eLBC Set Information for bank %d\n", priv->bank);
 
/* Fill in fsl_elbc_mtd structure */
-   priv->mtd.priv = chip;
-   priv->mtd.dev.parent = priv->dev;
+   mtd->priv = chip;
+   mtd->dev.parent = priv->dev;
nand_set_flash_node(chip, priv->dev->of_node);
 
/* set timeout to maximum */
@@ -798,9 +798,11 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
 static int fsl_elbc_chip_remove(struct fsl_elbc_mtd *priv)
 {
struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = priv->ctrl->nand;
-   nand_release(>mtd);
+   struct mtd_info *mtd = nand_to_mtd(>chip);
 
-   kfree(priv->mtd.name);
+   nand_release(mtd);
+
+   kfree(mtd->name);
 
if (priv->vbase)
iounmap(priv->vbase);
@@ -824,6 +826,7 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev)
int bank;
struct device *dev;
struct device_node *node = pdev->dev.of_node;
+   struct mtd_info *mtd;
 
if (!fsl_lbc_ctrl_dev || !fsl_lbc_ctrl_dev->regs)
return -ENODEV;
@@ -886,8 +889,9 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev)
goto err;
}
 
-   priv->mtd.name = kasprintf(GFP_KERNEL, "%llx.flash", (u64)res.start);
-   if (!priv->mtd.name) {
+   mtd = nand_to_mtd(>chip);
+   mtd->name = kasprintf(GFP_KERNEL, "%llx.flash", (u64)res.start);
+   if (!nand_to_mtd(>chip)->name) {
ret = -ENOMEM;
goto err;
}
@@ -896,21 +900,21 @@ static int fsl_elbc_nand_probe(struct platform_device 
*pdev)
if (ret)
goto err;
 
-   ret = nand_scan_ident(>mtd, 1, NULL);
+   ret = nand_scan_ident(mtd, 1, NULL);
if (ret)
goto err;
 
-   ret = fsl_elbc_chip_init_tail(>mtd);
+   ret = fsl_elbc_chip_init_tail(mtd);
if (ret)
goto err;
 
-   ret = nand_scan_tail(>mtd);
+   ret = nand_scan_tail(mtd);
if (ret)
goto err;
 
/* First look for RedBoot table or partitions on the command
 * line, these take precedence over device tree information */
-   mtd_device_parse_register(>mtd, part_probe_types, NULL,
+   mtd_device_parse_register(mtd, part_probe_types, NULL,
  NULL, 0);
 
printk(KERN_INFO "eLBC NAND device at 0x%llx, bank %d\n",
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 13/58] mtd: nand: cs553x: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/cs553x_nand.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/cs553x_nand.c b/drivers/mtd/nand/cs553x_nand.c
index 8904d68..386ae83 100644
--- a/drivers/mtd/nand/cs553x_nand.c
+++ b/drivers/mtd/nand/cs553x_nand.c
@@ -197,14 +197,13 @@ static int __init cs553x_init_one(int cs, int mmio, 
unsigned long adr)
}
 
/* Allocate memory for MTD device structure and private data */
-   new_mtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), 
GFP_KERNEL);
-   if (!new_mtd) {
+   this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
+   if (!this) {
err = -ENOMEM;
goto out;
}
 
-   /* Get pointer to private data */
-   this = (struct nand_chip *)(_mtd[1]);
+   new_mtd = nand_to_mtd(this);
 
/* Link the private data with the MTD structure */
new_mtd->priv = this;
@@ -257,7 +256,7 @@ out_free:
 out_ior:
iounmap(this->IO_ADDR_R);
 out_mtd:
-   kfree(new_mtd);
+   kfree(this);
 out:
return err;
 }
@@ -337,19 +336,19 @@ static void __exit cs553x_cleanup(void)
if (!mtd)
continue;
 
-   this = mtd_to_nand(cs553x_mtd[i]);
+   this = mtd_to_nand(mtd);
mmio_base = this->IO_ADDR_R;
 
/* Release resources, unregister device */
-   nand_release(cs553x_mtd[i]);
-   kfree(cs553x_mtd[i]->name);
+   nand_release(mtd);
+   kfree(mtd->name);
cs553x_mtd[i] = NULL;
 
/* unmap physical address */
iounmap(mmio_base);
 
/* Free the MTD device structure */
-   kfree(mtd);
+   kfree(this);
}
 }
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 14/58] mtd: nand: davinci: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/davinci_nand.c | 30 --
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c
index b5978d5..b1f69f9 100644
--- a/drivers/mtd/nand/davinci_nand.c
+++ b/drivers/mtd/nand/davinci_nand.c
@@ -53,7 +53,6 @@
  * outputs in a "wire-AND" configuration, with no per-chip signals.
  */
 struct davinci_nand_info {
-   struct mtd_info mtd;
struct nand_chipchip;
struct nand_ecclayout   ecclayout;
 
@@ -80,8 +79,10 @@ struct davinci_nand_info {
 static DEFINE_SPINLOCK(davinci_nand_lock);
 static bool ecc4_busy;
 
-#define to_davinci_nand(m) container_of(m, struct davinci_nand_info, mtd)
-
+static inline struct davinci_nand_info *to_davinci_nand(struct mtd_info *mtd)
+{
+   return container_of(mtd_to_nand(mtd), struct davinci_nand_info, chip);
+}
 
 static inline unsigned int davinci_nand_readl(struct davinci_nand_info *info,
int offset)
@@ -636,6 +637,7 @@ static int nand_davinci_probe(struct platform_device *pdev)
int ret;
uint32_tval;
nand_ecc_modes_tecc_mode;
+   struct mtd_info *mtd;
 
pdata = nand_davinci_get_pdata(pdev);
if (IS_ERR(pdata))
@@ -682,8 +684,9 @@ static int nand_davinci_probe(struct platform_device *pdev)
info->base  = base;
info->vaddr = vaddr;
 
-   info->mtd.priv  = >chip;
-   info->mtd.dev.parent= >dev;
+   mtd = nand_to_mtd(>chip);
+   mtd->priv   = >chip;
+   mtd->dev.parent = >dev;
nand_set_flash_node(>chip, pdev->dev.of_node);
 
info->chip.IO_ADDR_R= vaddr;
@@ -785,7 +788,7 @@ static int nand_davinci_probe(struct platform_device *pdev)
spin_unlock_irq(_nand_lock);
 
/* Scan to find existence of the device(s) */
-   ret = nand_scan_ident(>mtd, pdata->mask_chipsel ? 2 : 1, NULL);
+   ret = nand_scan_ident(mtd, pdata->mask_chipsel ? 2 : 1, NULL);
if (ret < 0) {
dev_dbg(>dev, "no NAND chip(s) found\n");
goto err;
@@ -797,9 +800,9 @@ static int nand_davinci_probe(struct platform_device *pdev)
 * usable:  10 bytes are needed, not 6.
 */
if (pdata->ecc_bits == 4) {
-   int chunks = info->mtd.writesize / 512;
+   int chunks = mtd->writesize / 512;
 
-   if (!chunks || info->mtd.oobsize < 16) {
+   if (!chunks || mtd->oobsize < 16) {
dev_dbg(>dev, "too small\n");
ret = -EINVAL;
goto err;
@@ -811,8 +814,7 @@ static int nand_davinci_probe(struct platform_device *pdev)
 */
if (chunks == 1) {
info->ecclayout = hwecc4_small;
-   info->ecclayout.oobfree[1].length =
-   info->mtd.oobsize - 16;
+   info->ecclayout.oobfree[1].length = mtd->oobsize - 16;
goto syndrome_done;
}
if (chunks == 4) {
@@ -833,15 +835,15 @@ syndrome_done:
info->chip.ecc.layout = >ecclayout;
}
 
-   ret = nand_scan_tail(>mtd);
+   ret = nand_scan_tail(mtd);
if (ret < 0)
goto err;
 
if (pdata->parts)
-   ret = mtd_device_parse_register(>mtd, NULL, NULL,
+   ret = mtd_device_parse_register(mtd, NULL, NULL,
pdata->parts, pdata->nr_parts);
else
-   ret = mtd_device_register(>mtd, NULL, 0);
+   ret = mtd_device_register(mtd, NULL, 

[PATCH v4 45/58] mtd: nand: vf610: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/vf610_nfc.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index 1c86c6b..1bbb93a 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -156,7 +156,6 @@ enum vf610_nfc_variant {
 };
 
 struct vf610_nfc {
-   struct mtd_info mtd;
struct nand_chip chip;
struct device *dev;
void __iomem *regs;
@@ -171,7 +170,10 @@ struct vf610_nfc {
u32 ecc_mode;
 };
 
-#define mtd_to_nfc(_mtd) container_of(_mtd, struct vf610_nfc, mtd)
+static inline struct vf610_nfc *mtd_to_nfc(struct mtd_info *mtd)
+{
+   return container_of(mtd_to_nand(mtd), struct vf610_nfc, chip);
+}
 
 static struct nand_ecclayout vf610_nfc_ecc45 = {
.eccbytes = 45,
@@ -674,8 +676,8 @@ static int vf610_nfc_probe(struct platform_device *pdev)
return -ENOMEM;
 
nfc->dev = >dev;
-   mtd = >mtd;
chip = >chip;
+   mtd = nand_to_mtd(chip);
 
mtd->priv = chip;
mtd->owner = THIS_MODULE;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 27/58] mtd: nand: mpc5121: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/mpc5121_nfc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/mpc5121_nfc.c b/drivers/mtd/nand/mpc5121_nfc.c
index 642c486..8b4cd82 100644
--- a/drivers/mtd/nand/mpc5121_nfc.c
+++ b/drivers/mtd/nand/mpc5121_nfc.c
@@ -118,7 +118,6 @@
 #define NFC_TIMEOUT(HZ / 10)   /* 1/10 s */
 
 struct mpc5121_nfc_prv {
-   struct mtd_info mtd;
struct nand_chipchip;
int irq;
void __iomem*regs;
@@ -654,8 +653,8 @@ static int mpc5121_nfc_probe(struct platform_device *op)
if (!prv)
return -ENOMEM;
 
-   mtd = >mtd;
chip = >chip;
+   mtd = nand_to_mtd(chip);
 
mtd->priv = chip;
mtd->dev.parent = dev;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 10/58] mtd: nand: brcm: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/brcmnand/brcmnand.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c 
b/drivers/mtd/nand/brcmnand/brcmnand.c
index 190a99a..26b64bc 100644
--- a/drivers/mtd/nand/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/brcmnand/brcmnand.c
@@ -178,7 +178,6 @@ struct brcmnand_host {
struct list_headnode;
 
struct nand_chipchip;
-   struct mtd_info mtd;
struct platform_device  *pdev;
int cs;
 
@@ -1074,7 +1073,7 @@ static int brcmnand_low_level_op(struct brcmnand_host 
*host,
 enum brcmnand_llop_type type, u32 data,
 bool last_op)
 {
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
struct nand_chip *chip = >chip;
struct brcmnand_controller *ctrl = host->ctrl;
u32 tmp;
@@ -1802,7 +1801,7 @@ static inline int get_blk_adr_bytes(u64 size, u32 
writesize)
 
 static int brcmnand_setup_dev(struct brcmnand_host *host)
 {
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
struct nand_chip *chip = >chip;
struct brcmnand_controller *ctrl = host->ctrl;
struct brcmnand_cfg *cfg = >hwcfg;
@@ -1916,7 +1915,7 @@ static int brcmnand_init_cs(struct brcmnand_host *host, 
struct device_node *dn)
return -ENXIO;
}
 
-   mtd = >mtd;
+   mtd = nand_to_mtd(>chip);
chip = >chip;
 
nand_set_flash_node(chip, dn);
@@ -2060,8 +2059,8 @@ static int brcmnand_resume(struct device *dev)
}
 
list_for_each_entry(host, >host_list, node) {
-   struct mtd_info *mtd = >mtd;
-   struct nand_chip *chip = mtd_to_nand(mtd);
+   struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(chip);
 
brcmnand_save_restore_cs_config(host, 1);
 
@@ -2262,7 +2261,7 @@ int brcmnand_remove(struct platform_device *pdev)
struct brcmnand_host *host;
 
list_for_each_entry(host, >host_list, node)
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
 
dev_set_drvdata(>dev, NULL);
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 08/58] mtd: nand: bcm47xx: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h | 1 -
 drivers/mtd/nand/bcm47xxnflash/main.c  | 8 +---
 drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c   | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h 
b/drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h
index c005a62..8ea7571 100644
--- a/drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h
+++ b/drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h
@@ -12,7 +12,6 @@ struct bcm47xxnflash {
struct bcma_drv_cc *cc;
 
struct nand_chip nand_chip;
-   struct mtd_info mtd;
 
unsigned curr_command;
int curr_page_addr;
diff --git a/drivers/mtd/nand/bcm47xxnflash/main.c 
b/drivers/mtd/nand/bcm47xxnflash/main.c
index 9ba0c0f..4711ca2b 100644
--- a/drivers/mtd/nand/bcm47xxnflash/main.c
+++ b/drivers/mtd/nand/bcm47xxnflash/main.c
@@ -27,6 +27,7 @@ static int bcm47xxnflash_probe(struct platform_device *pdev)
 {
struct bcma_nflash *nflash = dev_get_platdata(>dev);
struct bcm47xxnflash *b47n;
+   struct mtd_info *mtd;
int err = 0;
 
b47n = devm_kzalloc(>dev, sizeof(*b47n), GFP_KERNEL);
@@ -34,8 +35,9 @@ static int bcm47xxnflash_probe(struct platform_device *pdev)
return -ENOMEM;
 
b47n->nand_chip.priv = b47n;
-   b47n->mtd.dev.parent = >dev;
-   b47n->mtd.priv = >nand_chip; /* Required */
+   mtd = nand_to_mtd(>nand_chip);
+   mtd->dev.parent = >dev;
+   mtd->priv = >nand_chip; /* Required */
b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash);
 
if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
@@ -49,7 +51,7 @@ static int bcm47xxnflash_probe(struct platform_device *pdev)
return err;
}
 
-   err = mtd_device_parse_register(>mtd, probes, NULL, NULL, 0);
+   err = mtd_device_parse_register(mtd, probes, NULL, NULL, 0);
if (err) {
pr_err("Failed to register MTD device: %d\n", err);
return err;
diff --git a/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c 
b/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c
index e5b2e48..6524780 100644
--- a/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c
+++ b/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c
@@ -421,7 +421,7 @@ int bcm47xxnflash_ops_bcm4706_init(struct bcm47xxnflash 
*b47n)
(w4 << 24 | w3 << 18 | w2 << 12 | w1 << 6 | w0));
 
/* Scan NAND */
-   err = nand_scan(>mtd, 1);
+   err = nand_scan(nand_to_mtd(>nand_chip), 1);
if (err) {
pr_err("Could not scan NAND flash: %d\n", err);
goto exit;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 12/58] mtd: nand: cmx270: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/cmx270_nand.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/cmx270_nand.c b/drivers/mtd/nand/cmx270_nand.c
index 43bded6..6b26e0c 100644
--- a/drivers/mtd/nand/cmx270_nand.c
+++ b/drivers/mtd/nand/cmx270_nand.c
@@ -160,10 +160,8 @@ static int __init cmx270_init(void)
gpio_direction_input(GPIO_NAND_RB);
 
/* Allocate memory for MTD device structure and private data */
-   cmx270_nand_mtd = kzalloc(sizeof(struct mtd_info) +
- sizeof(struct nand_chip),
- GFP_KERNEL);
-   if (!cmx270_nand_mtd) {
+   this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
+   if (!this) {
ret = -ENOMEM;
goto err_kzalloc;
}
@@ -175,8 +173,7 @@ static int __init cmx270_init(void)
goto err_ioremap;
}
 
-   /* Get pointer to private data */
-   this = (struct nand_chip *)(_nand_mtd[1]);
+   cmx270_nand_mtd = nand_to_mtd(this);
 
/* Link the private data with the MTD structure */
cmx270_nand_mtd->owner = THIS_MODULE;
@@ -216,7 +213,7 @@ static int __init cmx270_init(void)
 err_scan:
iounmap(cmx270_nand_io);
 err_ioremap:
-   kfree(cmx270_nand_mtd);
+   kfree(this);
 err_kzalloc:
gpio_free(GPIO_NAND_RB);
 err_gpio_request:
@@ -241,7 +238,7 @@ static void __exit cmx270_cleanup(void)
iounmap(cmx270_nand_io);
 
/* Free the MTD device structure */
-   kfree (cmx270_nand_mtd);
+   kfree(mtd_to_nand(cmx270_nand_mtd));
 }
 module_exit(cmx270_cleanup);
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 11/58] mtd: nand: cafe: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/cafe_nand.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
index 77c92f1..7d6a142 100644
--- a/drivers/mtd/nand/cafe_nand.c
+++ b/drivers/mtd/nand/cafe_nand.c
@@ -605,11 +605,11 @@ static int cafe_nand_probe(struct pci_dev *pdev,
 
pci_set_master(pdev);
 
-   mtd = kzalloc(sizeof(*mtd) + sizeof(struct cafe_priv), GFP_KERNEL);
-   if (!mtd)
+   cafe = kzalloc(sizeof(*cafe), GFP_KERNEL);
+   if (!cafe)
return  -ENOMEM;
-   cafe = (void *)([1]);
 
+   mtd = nand_to_mtd(>nand);
mtd->dev.parent = >dev;
mtd->priv = >nand;
cafe->nand.priv = cafe;
@@ -792,7 +792,7 @@ static int cafe_nand_probe(struct pci_dev *pdev,
  out_ior:
pci_iounmap(pdev, cafe->mmio);
  out_free_mtd:
-   kfree(mtd);
+   kfree(cafe);
  out:
return err;
 }
@@ -813,7 +813,7 @@ static void cafe_nand_remove(struct pci_dev *pdev)
2112 + sizeof(struct nand_buffers) +
mtd->writesize + mtd->oobsize,
cafe->dmabuf, cafe->dmaaddr);
-   kfree(mtd);
+   kfree(cafe);
 }
 
 static const struct pci_device_id cafe_nand_tbl[] = {
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 09/58] mtd: nand: bf5xx: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/bf5xx_nand.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/bf5xx_nand.c b/drivers/mtd/nand/bf5xx_nand.c
index d9da5ed..928d599 100644
--- a/drivers/mtd/nand/bf5xx_nand.c
+++ b/drivers/mtd/nand/bf5xx_nand.c
@@ -142,7 +142,6 @@ static struct nand_ecclayout bootrom_ecclayout = {
 struct bf5xx_nand_info {
/* mtd info */
struct nand_hw_control  controller;
-   struct mtd_info mtd;
struct nand_chipchip;
 
/* platform info */
@@ -160,7 +159,8 @@ struct bf5xx_nand_info {
  */
 static struct bf5xx_nand_info *mtd_to_nand_info(struct mtd_info *mtd)
 {
-   return container_of(mtd, struct bf5xx_nand_info, mtd);
+   return container_of(mtd_to_nand(mtd), struct bf5xx_nand_info,
+   chip);
 }
 
 static struct bf5xx_nand_info *to_nand_info(struct platform_device *pdev)
@@ -660,7 +660,7 @@ static int bf5xx_nand_hw_init(struct bf5xx_nand_info *info)
  */
 static int bf5xx_nand_add_partition(struct bf5xx_nand_info *info)
 {
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
struct mtd_partition *parts = info->platform->partitions;
int nr = info->platform->nr_partitions;
 
@@ -675,7 +675,7 @@ static int bf5xx_nand_remove(struct platform_device *pdev)
 * and their partitions, then go through freeing the
 * resources used
 */
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
 
peripheral_free_list(bfin_nfc_pin_req);
bf5xx_nand_dma_remove(info);
@@ -756,6 +756,7 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
 
/* initialise chip data struct */
chip = >chip;
+   mtd = nand_to_mtd(>chip);
 
if (plat->data_width)
chip->options |= NAND_BUSWIDTH_16;
@@ -772,7 +773,7 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
chip->cmd_ctrl = bf5xx_nand_hwcontrol;
chip->dev_ready= bf5xx_nand_devready;
 
-   chip->priv = >mtd;
+   chip->priv = mtd;
chip->controller   = >controller;
 
chip->IO_ADDR_R= (void __iomem *) NFC_READ;
@@ -781,7 +782,6 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
chip->chip_delay   = 0;
 
/* initialise mtd info data struct */
-   mtd = >mtd;
mtd->priv   = chip;
mtd->dev.parent = >dev;
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 05/58] mtd: nand: ams-delta: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance
instead of allocating our own.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/ams-delta.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c
index b2b49c4..0f638c6 100644
--- a/drivers/mtd/nand/ams-delta.c
+++ b/drivers/mtd/nand/ams-delta.c
@@ -183,19 +183,16 @@ static int ams_delta_init(struct platform_device *pdev)
return -ENXIO;
 
/* Allocate memory for MTD device structure and private data */
-   ams_delta_mtd = kzalloc(sizeof(struct mtd_info) +
-   sizeof(struct nand_chip), GFP_KERNEL);
-   if (!ams_delta_mtd) {
+   this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
+   if (!this) {
printk (KERN_WARNING "Unable to allocate E3 NAND MTD device 
structure.\n");
err = -ENOMEM;
goto out;
}
 
+   ams_delta_mtd = nand_to_mtd(this);
ams_delta_mtd->owner = THIS_MODULE;
 
-   /* Get pointer to private data */
-   this = (struct nand_chip *) (_delta_mtd[1]);
-
/* Link the private data with the MTD structure */
ams_delta_mtd->priv = this;
 
@@ -256,7 +253,7 @@ out_gpio:
gpio_free(AMS_DELTA_GPIO_PIN_NAND_RB);
iounmap(io_base);
 out_free:
-   kfree(ams_delta_mtd);
+   kfree(this);
  out:
return err;
 }
@@ -276,7 +273,7 @@ static int ams_delta_cleanup(struct platform_device *pdev)
iounmap(io_base);
 
/* Free the MTD device structure */
-   kfree(ams_delta_mtd);
+   kfree(mtd_to_nand(ams_delta_mtd));
 
return 0;
 }
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 30/58] mtd: nand: ndfc: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/ndfc.c | 24 +---
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c
index d8a23b0..3a7168e 100644
--- a/drivers/mtd/nand/ndfc.c
+++ b/drivers/mtd/nand/ndfc.c
@@ -37,7 +37,6 @@
 struct ndfc_controller {
struct platform_device *ofdev;
void __iomem *ndfcbase;
-   struct mtd_info mtd;
struct nand_chip chip;
int chip_select;
struct nand_hw_control ndfc_control;
@@ -147,6 +146,7 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
 {
struct device_node *flash_np;
struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(chip);
int ret;
 
chip->IO_ADDR_R = ndfc->ndfcbase + NDFC_DATA;
@@ -167,31 +167,32 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
chip->ecc.strength = 1;
chip->priv = ndfc;
 
-   ndfc->mtd.priv = chip;
-   ndfc->mtd.dev.parent = >ofdev->dev;
+   mtd->priv = chip;
+   mtd->dev.parent = >ofdev->dev;
 
flash_np = of_get_next_child(node, NULL);
if (!flash_np)
return -ENODEV;
nand_set_flash_node(chip, flash_np);
 
-   ndfc->mtd.name = kasprintf(GFP_KERNEL, "%s.%s",
-   dev_name(>ofdev->dev), flash_np->name);
-   if (!ndfc->mtd.name) {
+   ppdata.of_node = flash_np;
+   mtd->name = kasprintf(GFP_KERNEL, "%s.%s", dev_name(>ofdev->dev),
+ flash_np->name);
+   if (!mtd->name) {
ret = -ENOMEM;
goto err;
}
 
-   ret = nand_scan(>mtd, 1);
+   ret = nand_scan(mtd, 1);
if (ret)
goto err;
 
-   ret = mtd_device_register(>mtd, NULL, 0);
+   ret = mtd_device_register(mtd, NULL, 0);
 
 err:
of_node_put(flash_np);
if (ret)
-   kfree(ndfc->mtd.name);
+   kfree(mtd->name);
return ret;
 }
 
@@ -258,9 +259,10 @@ static int ndfc_probe(struct platform_device *ofdev)
 static int ndfc_remove(struct platform_device *ofdev)
 {
struct ndfc_controller *ndfc = dev_get_drvdata(>dev);
+   struct mtd_info *mtd = nand_to_mtd(>chip);
 
-   nand_release(>mtd);
-   kfree(ndfc->mtd.name);
+   nand_release(mtd);
+   kfree(mtd->name);
 
return 0;
 }
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 44/58] mtd: nand: txx9ndfmc: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/txx9ndfmc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/txx9ndfmc.c b/drivers/mtd/nand/txx9ndfmc.c
index ff9afb1..da7fcbd 100644
--- a/drivers/mtd/nand/txx9ndfmc.c
+++ b/drivers/mtd/nand/txx9ndfmc.c
@@ -63,7 +63,6 @@
 struct txx9ndfmc_priv {
struct platform_device *dev;
struct nand_chip chip;
-   struct mtd_info mtd;
int cs;
const char *mtdname;
 };
@@ -322,7 +321,7 @@ static int __init txx9ndfmc_probe(struct platform_device 
*dev)
if (!txx9_priv)
continue;
chip = _priv->chip;
-   mtd = _priv->mtd;
+   mtd = nand_to_mtd(chip);
mtd->dev.parent = >dev;
 
mtd->priv = chip;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 50/58] mtd: nand: remove useless mtd->priv = chip assignments

2015-12-10 Thread Boris Brezillon
mtd_to_nand() now uses the container_of() approach to transform an
mtd_info pointer into a nand_chip one. Drop useless mtd->priv
assignments from NAND controller drivers.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Patch generated with the following coccinelle script:

---8<
virtual patch

@@
struct mtd_info m;
struct mtd_info *mp;
struct nand_chip *c;
@@
(
-(m).priv = c;
|
-(mp)->priv = c;
|
-(mp)->priv = (void *)c;
)
---8<
---
 drivers/mtd/nand/ams-delta.c   | 3 ---
 drivers/mtd/nand/atmel_nand.c  | 1 -
 drivers/mtd/nand/au1550nd.c| 1 -
 drivers/mtd/nand/bcm47xxnflash/main.c  | 1 -
 drivers/mtd/nand/bf5xx_nand.c  | 1 -
 drivers/mtd/nand/brcmnand/brcmnand.c   | 1 -
 drivers/mtd/nand/cafe_nand.c   | 1 -
 drivers/mtd/nand/cmx270_nand.c | 1 -
 drivers/mtd/nand/cs553x_nand.c | 1 -
 drivers/mtd/nand/davinci_nand.c| 1 -
 drivers/mtd/nand/denali.c  | 1 -
 drivers/mtd/nand/diskonchip.c  | 1 -
 drivers/mtd/nand/docg4.c   | 1 -
 drivers/mtd/nand/fsl_elbc_nand.c   | 1 -
 drivers/mtd/nand/fsl_ifc_nand.c| 1 -
 drivers/mtd/nand/fsl_upm.c | 1 -
 drivers/mtd/nand/fsmc_nand.c   | 1 -
 drivers/mtd/nand/gpio.c| 1 -
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 1 -
 drivers/mtd/nand/hisi504_nand.c| 1 -
 drivers/mtd/nand/jz4740_nand.c | 1 -
 drivers/mtd/nand/lpc32xx_mlc.c | 1 -
 drivers/mtd/nand/lpc32xx_slc.c | 1 -
 drivers/mtd/nand/mpc5121_nfc.c | 1 -
 drivers/mtd/nand/mxc_nand.c| 1 -
 drivers/mtd/nand/nandsim.c | 1 -
 drivers/mtd/nand/ndfc.c| 1 -
 drivers/mtd/nand/nuc900_nand.c | 1 -
 drivers/mtd/nand/omap2.c   | 1 -
 drivers/mtd/nand/orion_nand.c  | 1 -
 drivers/mtd/nand/pasemi_nand.c | 1 -
 drivers/mtd/nand/plat_nand.c   | 1 -
 drivers/mtd/nand/pxa3xx_nand.c | 1 -
 drivers/mtd/nand/r852.c| 1 -
 drivers/mtd/nand/s3c2410.c | 2 --
 drivers/mtd/nand/sh_flctl.c| 1 -
 drivers/mtd/nand/sharpsl.c | 1 -
 drivers/mtd/nand/socrates_nand.c   | 1 -
 drivers/mtd/nand/sunxi_nand.c  | 1 -
 drivers/mtd/nand/tmio_nand.c   | 1 -
 drivers/mtd/nand/txx9ndfmc.c   | 2 --
 drivers/mtd/nand/vf610_nfc.c   | 1 -
 42 files changed, 46 deletions(-)

diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c
index 0f638c6..1a18938 100644
--- a/drivers/mtd/nand/ams-delta.c
+++ b/drivers/mtd/nand/ams-delta.c
@@ -193,9 +193,6 @@ static int ams_delta_init(struct platform_device *pdev)
ams_delta_mtd = nand_to_mtd(this);
ams_delta_mtd->owner = THIS_MODULE;
 
-   /* Link the private data with the MTD structure */
-   ams_delta_mtd->priv = this;
-
/*
 * Don't try to request the memory region from here,
 * it should have been already requested from the
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 9ba2831..18c4e14 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -2128,7 +2128,6 @@ static int atmel_nand_probe(struct platform_device *pdev)
}
 
nand_chip->priv = host; /* link the private data structures */
-   mtd->priv = nand_chip;
mtd->dev.parent = >dev;
 
/* Set address of NAND IO lines */
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index 280e5b6..341ea49 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -441,7 +441,6 @@ static int au1550nd_probe(struct platform_device *pdev)
 
this = >chip;
mtd = nand_to_mtd(this);
-   mtd->priv = this;
mtd->dev.parent = >dev;
 
/* figure out which CS# r->start belongs to */
diff --git a/drivers/mtd/nand/bcm47xxnflash/main.c 
b/drivers/mtd/nand/bcm47xxnflash/main.c
index 4711ca2b..0f0a798 100644
--- a/drivers/mtd/nand/bcm47xxnflash/main.c
+++ b/drivers/mtd/nand/bcm47xxnflash/main.c
@@ -37,7 +37,6 @@ static int bcm47xxnflash_probe(struct platform_device *pdev)
b47n->nand_chip.priv = b47n;
mtd = nand_to_mtd(>nand_chip);
mtd->dev.parent = >dev;
-   mtd->priv = >nand_chip; /* Required */
b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash);
 
if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
diff --git a/drivers/mtd/nand/bf5xx_nand.c b/drivers/mtd/nand/bf5xx_nand.c
index 928d599..9514e13 100644
--- a/drivers/mtd/nand/bf5xx_nand.c
+++ b/drivers/mtd/nand/bf5xx_nand.c
@@ -782,7 +782,6 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
chip->chip_delay   = 0;
 
/* initialise mtd info data struct */
-   mtd->priv   = chip;
mtd->dev.parent = >dev;
 
/* initialise the ha

[PATCH v4 49/58] mtd: nand: update mtd_to_nand()

2015-12-10 Thread Boris Brezillon
Now that all drivers are using the mtd instance embedded in the nand_chip
struct we can safely update the mtd_to_nand() implementation to use
the container_of macro instead of returning the content of mtd->priv.
This will allow us to remove mtd->priv = chip assignments done in all
NAND controller drivers.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 include/linux/mtd/nand.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index b614ed2..9cb7ace 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -734,7 +734,7 @@ static inline struct device_node 
*nand_get_flash_node(struct nand_chip *chip)
 
 static inline struct nand_chip *mtd_to_nand(struct mtd_info *mtd)
 {
-   return mtd->priv;
+   return container_of(mtd, struct nand_chip, mtd);
 }
 
 static inline struct mtd_info *nand_to_mtd(struct nand_chip *chip)
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 43/58] mtd: nand: tmio: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/tmio_nand.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/tmio_nand.c b/drivers/mtd/nand/tmio_nand.c
index 6d0cbe9..e7b82e1 100644
--- a/drivers/mtd/nand/tmio_nand.c
+++ b/drivers/mtd/nand/tmio_nand.c
@@ -103,7 +103,6 @@
 /*--*/
 
 struct tmio_nand {
-   struct mtd_info mtd;
struct nand_chip chip;
 
struct platform_device *dev;
@@ -119,7 +118,10 @@ struct tmio_nand {
unsigned read_good:1;
 };
 
-#define mtd_to_tmio(m) container_of(m, struct tmio_nand, mtd)
+static inline struct tmio_nand *mtd_to_tmio(struct mtd_info *mtd)
+{
+   return container_of(mtd_to_nand(mtd), struct tmio_nand, chip);
+}
 
 
 /*--*/
@@ -378,8 +380,8 @@ static int tmio_probe(struct platform_device *dev)
tmio->dev = dev;
 
platform_set_drvdata(dev, tmio);
-   mtd = >mtd;
nand_chip = >chip;
+   mtd = nand_to_mtd(nand_chip);
mtd->priv = nand_chip;
mtd->name = "tmio-nand";
mtd->dev.parent = >dev;
@@ -456,7 +458,7 @@ static int tmio_remove(struct platform_device *dev)
 {
struct tmio_nand *tmio = platform_get_drvdata(dev);
 
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
tmio_hw_stop(dev, tmio);
return 0;
 }
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 47/58] staging: mt29f_spinand: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device, use it instead of allocating
a new one.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/staging/mt29f_spinand/mt29f_spinand.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.c 
b/drivers/staging/mt29f_spinand/mt29f_spinand.c
index 8924a96..8171b74 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
@@ -903,9 +903,7 @@ static int spinand_probe(struct spi_device *spi_nand)
chip->options   |= NAND_CACHEPRG;
chip->select_chip = spinand_select_chip;
 
-   mtd = devm_kzalloc(_nand->dev, sizeof(struct mtd_info), GFP_KERNEL);
-   if (!mtd)
-   return -ENOMEM;
+   mtd = nand_to_mtd(chip);
 
dev_set_drvdata(_nand->dev, mtd);
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 46/58] mtd: nand: update the documentation to reflect framework changes

2015-12-10 Thread Boris Brezillon
The MTD device is now directly embedded in the nand_chip struct. Update the
mtdnand documentation to mention this aspect and fix the different
examples.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 Documentation/DocBook/mtdnand.tmpl | 31 +++
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/Documentation/DocBook/mtdnand.tmpl 
b/Documentation/DocBook/mtdnand.tmpl
index 403a7ab..b442921 100644
--- a/Documentation/DocBook/mtdnand.tmpl
+++ b/Documentation/DocBook/mtdnand.tmpl
@@ -162,12 +162,15 @@

Basic defines

-   At least you have to provide a mtd structure and
-   a storage for the ioremap'ed chip address.
-   You can allocate the mtd structure using kmalloc
-   or you can allocate it statically.
-   In case of static allocation you have to allocate
-   a nand_chip structure too.
+   At least you have to provide a nand_chip structure
+   and a storage for the ioremap'ed chip address.
+   You can allocate the nand_chip structure using
+   kmalloc or you can allocate it statically.
+   The NAND chip structure embeds an mtd structure
+   which will be registered to the MTD subsystem.
+   You can extract a pointer to the mtd structure
+   from a nand_chip pointer using the nand_to_mtd()
+   helper.


Kmalloc based example
@@ -180,7 +183,6 @@ static void __iomem *baseaddr;
Static example


-static struct mtd_info board_mtd;
 static struct nand_chip board_chip;
 static void __iomem *baseaddr;

@@ -274,13 +276,15 @@ static int __init board_init (void)
int err = 0;
 
/* Allocate memory for MTD device structure and private data */
-   board_mtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), 
GFP_KERNEL);
-   if (!board_mtd) {
+   this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
+   if (!this) {
printk ("Unable to allocate NAND MTD device structure.\n");
err = -ENOMEM;
goto out;
}
 
+   board_mtd = nand_to_mtd(this);
+
/* map physical address */
baseaddr = ioremap(CHIP_PHYSICAL_ADDRESS, 1024);
if (!baseaddr) {
@@ -289,11 +293,6 @@ static int __init board_init (void)
goto out_mtd;
}
 
-   /* Get pointer to private data */
-   this = (struct nand_chip *) ();
-   /* Link the private data with the MTD structure */
-   board_mtd->priv = this;
-
/* Set address of NAND IO lines */
this->IO_ADDR_R = baseaddr;
this->IO_ADDR_W = baseaddr;
@@ -317,7 +316,7 @@ static int __init board_init (void)
 out_ior:
iounmap(baseaddr);
 out_mtd:
-   kfree (board_mtd);
+   kfree (this);
 out:
return err;
 }
@@ -343,7 +342,7 @@ static void __exit board_cleanup (void)
iounmap(baseaddr);

/* Free the MTD device structure */
-   kfree (board_mtd);
+   kfree (mtd_to_nand(board_mtd));
 }
 module_exit(board_cleanup);
 #endif
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 52/58] staging: mt29f_spinand: remove useless mtd->priv = chip assignment

2015-12-10 Thread Boris Brezillon
mtd_to_nand() now uses the container_of() approach to transform an
mtd_info pointer into a nand_chip one. Drop useless mtd->priv
assignments from NAND controller drivers.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Patch generated with the following coccinelle script:

---8<
virtual patch

@@
struct mtd_info m;
struct mtd_info *mp;
struct nand_chip *c;
@@
(
-(m).priv = c;
|
-(mp)->priv = c;
|
-(mp)->priv = (void *)c;
)
---8<
---
 drivers/staging/mt29f_spinand/mt29f_spinand.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.c 
b/drivers/staging/mt29f_spinand/mt29f_spinand.c
index 8171b74..b7d429d 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
@@ -907,7 +907,6 @@ static int spinand_probe(struct spi_device *spi_nand)
 
dev_set_drvdata(_nand->dev, mtd);
 
-   mtd->priv = chip;
mtd->dev.parent = _nand->dev;
mtd->oobsize = 64;
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 04/58] mtd: nand: omap2: create and use mtd_to_omap()

2015-12-10 Thread Boris Brezillon
Define and use mtd_to_omap() instead of container_of();

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/omap2.c | 55 ++--
 1 file changed, 21 insertions(+), 34 deletions(-)

diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index 944a74e..1fb40db 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -177,6 +177,10 @@ struct omap_nand_info {
struct device_node  *of_node;
 };
 
+static inline struct omap_nand_info *mtd_to_omap(struct mtd_info *mtd)
+{
+   return container_of(mtd, struct omap_nand_info, mtd);
+}
 /**
  * omap_prefetch_enable - configures and starts prefetch transfer
  * @cs: cs (chip select) number
@@ -247,8 +251,7 @@ static int omap_prefetch_reset(int cs, struct 
omap_nand_info *info)
  */
 static void omap_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
 
if (cmd != NAND_CMD_NONE) {
if (ctrl & NAND_CLE)
@@ -283,8 +286,7 @@ static void omap_read_buf8(struct mtd_info *mtd, u_char 
*buf, int len)
  */
 static void omap_write_buf8(struct mtd_info *mtd, const u_char *buf, int len)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
u_char *p = (u_char *)buf;
u32 status = 0;
 
@@ -319,8 +321,7 @@ static void omap_read_buf16(struct mtd_info *mtd, u_char 
*buf, int len)
  */
 static void omap_write_buf16(struct mtd_info *mtd, const u_char * buf, int len)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
u16 *p = (u16 *) buf;
u32 status = 0;
/* FIXME try bursts of writesw() or DMA ... */
@@ -344,8 +345,7 @@ static void omap_write_buf16(struct mtd_info *mtd, const 
u_char * buf, int len)
  */
 static void omap_read_buf_pref(struct mtd_info *mtd, u_char *buf, int len)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
uint32_t r_count = 0;
int ret = 0;
u32 *p = (u32 *)buf;
@@ -392,8 +392,7 @@ static void omap_read_buf_pref(struct mtd_info *mtd, u_char 
*buf, int len)
 static void omap_write_buf_pref(struct mtd_info *mtd,
const u_char *buf, int len)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
uint32_t w_count = 0;
int i = 0, ret = 0;
u16 *p = (u16 *)buf;
@@ -458,8 +457,7 @@ static void omap_nand_dma_callback(void *data)
 static inline int omap_nand_dma_transfer(struct mtd_info *mtd, void *addr,
unsigned int len, int is_write)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
struct dma_async_tx_descriptor *tx;
enum dma_data_direction dir = is_write ? DMA_TO_DEVICE :
DMA_FROM_DEVICE;
@@ -623,8 +621,7 @@ done:
  */
 static void omap_read_buf_irq_pref(struct mtd_info *mtd, u_char *buf, int len)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
int ret = 0;
 
if (len <= mtd->oobsize) {
@@ -671,8 +668,7 @@ out_copy:
 static void omap_write_buf_irq_pref(struct mtd_info *mtd,
const u_char *buf, int len)
 {
-   struct omap_nand_info *info = container_of(mtd,
-   struct omap_nand_info, mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
int ret = 0;
unsigned long tim, limit;
u32 val;
@@ -886,8 +882,7 @@ static int omap_compare_ecc(u8 *ecc_data1,  /* read from 
NAND memory */
 static int omap_correct_data(struct mtd_info *mtd, u_char *dat,
u_char *read_ecc, u_char *calc_ecc)
 {
-   struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
-   mtd);
+   struct omap_nand_info *info = mtd_to_omap(mtd);
int blockCnt = 0, i = 0, ret = 0;
int stat = 0;
 
@@ -928,8 +923,7 @@ static int omap_correct_data(struct mtd_i

[PATCH v4 06/58] mtd: nand: atmel: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/atmel_nand.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index edd191a..9ba2831 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -116,7 +116,6 @@ static struct atmel_nfc nand_nfc;
 
 struct atmel_nand_host {
struct nand_chipnand_chip;
-   struct mtd_info mtd;
void __iomem*io_base;
dma_addr_t  io_phys;
struct atmel_nand_data  board;
@@ -317,8 +316,10 @@ static int nfc_set_sram_bank(struct atmel_nand_host *host, 
unsigned int bank)
return -EINVAL;
 
if (bank) {
+   struct mtd_info *mtd = nand_to_mtd(>nand_chip);
+
/* Only for a 2k-page or lower flash, NFC can handle 2 banks */
-   if (host->mtd.writesize > 2048)
+   if (mtd->writesize > 2048)
return -EINVAL;
nfc_writel(host->nfc->hsmc_regs, BANK, ATMEL_HSMC_NFC_BANK1);
} else {
@@ -1159,8 +1160,8 @@ static uint16_t *create_lookup_table(struct device *dev, 
int sector_size)
 static int atmel_pmecc_nand_init_params(struct platform_device *pdev,
 struct atmel_nand_host *host)
 {
-   struct mtd_info *mtd = >mtd;
struct nand_chip *nand_chip = >nand_chip;
+   struct mtd_info *mtd = nand_to_mtd(nand_chip);
struct resource *regs, *regs_pmerr, *regs_rom;
uint16_t *galois_table;
int cap, sector_size, err_no;
@@ -1586,8 +1587,8 @@ static int atmel_of_init_port(struct atmel_nand_host 
*host,
 static int atmel_hw_nand_init_params(struct platform_device *pdev,
 struct atmel_nand_host *host)
 {
-   struct mtd_info *mtd = >mtd;
struct nand_chip *nand_chip = >nand_chip;
+   struct mtd_info *mtd = nand_to_mtd(nand_chip);
struct resource *regs;
 
regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
@@ -2112,8 +2113,8 @@ static int atmel_nand_probe(struct platform_device *pdev)
}
host->io_phys = (dma_addr_t)mem->start;
 
-   mtd = >mtd;
nand_chip = >nand_chip;
+   mtd = nand_to_mtd(nand_chip);
host->dev = >dev;
if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
nand_set_flash_node(nand_chip, pdev->dev.of_node);
@@ -2283,7 +2284,7 @@ err_nand_ioremap:
 static int atmel_nand_remove(struct platform_device *pdev)
 {
struct atmel_nand_host *host = platform_get_drvdata(pdev);
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand_chip);
 
nand_release(mtd);
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 00/58] mtd: nand: refactor the NAND subsystem (part 1)

2015-12-10 Thread Boris Brezillon
Hello,

This huge series aims at clarifying the relationship between the mtd and
nand_chip structures and hiding NAND framework internals to NAND
controller drivers.

The first part of the series (patch 1 to 4) is a set of fixes/simple
reworks easing the migration to mtd_to_nand().

The second part of the series embeds the mtd structure into the nand_chip
one so that NAND controller drivers don't have to bother allocating the
MTD device and linking it with the NAND chip.

The last part of the series hides accesses to the chip->priv field behind
two helper functions.

This allows removal of some of the boilerplate code done in all NAND
controller drivers, but most importantly, it unifies a bit the way NAND
chip structures are instantiated (even though we still have two different
kinds of drivers: those embedding the nand_chip struct into their private
nand chip representation, and those allocating two different structures
and linking them together with the chip->priv field).

As said in the title, this refactoring is only the first step. I plan to
rework the NAND controller / NAND chip separation for pretty much the same
reasons: clarifying the separation between the two concepts, and getting
rid of more boilerplate code in NAND controller drivers.

Stay tuned ;-).

Best Regards,

Boris

Changes since v3:
- fix some bugs introduced when migrating to nand_to_mtd()
- split the huge commit switching all drivers to nand_to_mtd() into several
  commits (one per driver) to ease review and integration
- add a simple fixes/reworks at the beginning of the series (mainly to
  ease migration to nand_to_mtd())
- drop already applied patches.

Changes since v2:
- fix some build warnings/erros

Changes since v1:
- dropped already applied patches
- fixed some typos
- manually fixed some modifications omitted by the coccinelle scripts
- manually reworked modifactions done by coccinelle scripts to improve
  readability and fix coding style issues

*** BLURB HERE ***

Boris Brezillon (58):
  mtd: nand: denali: add missing nand_release() call in denali_remove()
  mtd: nand: fsmc: create and use mtd_to_fsmc()
  mtd: nand: nuc900: create and use mtd_to_nuc900()
  mtd: nand: omap2: create and use mtd_to_omap()
  mtd: nand: ams-delta: use the mtd instance embedded in struct
nand_chip
  mtd: nand: atmel: use the mtd instance embedded in struct nand_chip
  mtd: nand: au1550nd: use the mtd instance embedded in struct nand_chip
  mtd: nand: bcm47xx: use the mtd instance embedded in struct nand_chip
  mtd: nand: bf5xx: use the mtd instance embedded in struct nand_chip
  mtd: nand: brcm: use the mtd instance embedded in struct nand_chip
  mtd: nand: cafe: use the mtd instance embedded in struct nand_chip
  mtd: nand: cmx270: use the mtd instance embedded in struct nand_chip
  mtd: nand: cs553x: use the mtd instance embedded in struct nand_chip
  mtd: nand: davinci: use the mtd instance embedded in struct nand_chip
  mtd: nand: denali: use the mtd instance embedded in struct nand_chip
  mtd: nand: diskonchip: use the mtd instance embedded in struct
nand_chip
  mtd: nand: docg4: use the mtd instance embedded in struct nand_chip
  mtd: nand: fsl_elbc: use the mtd instance embedded in struct nand_chip
  mtd: nand: fsl_ifc: use the mtd instance embedded in struct nand_chip
  mtd: nand: fsl_upm: use the mtd instance embedded in struct nand_chip
  mtd: nand: fsmc: use the mtd instance embedded in struct nand_chip
  mtd: nand: gpio: use the mtd instance embedded in struct nand_chip
  mtd: nand: gpmi: use the mtd instance embedded in struct nand_chip
  mtd: nand: hisi504: use the mtd instance embedded in struct nand_chip
  mtd: nand: jz4740: use the mtd instance embedded in struct nand_chip
  mtd: nand: lpc32xx: use the mtd instance embedded in struct nand_chip
  mtd: nand: mpc5121: use the mtd instance embedded in struct nand_chip
  mtd: nand: mxc: use the mtd instance embedded in struct nand_chip
  mtd: nand: nandsim: use the mtd instance embedded in struct nand_chip
  mtd: nand: ndfc: use the mtd instance embedded in struct nand_chip
  mtd: nand: nuc900: use the mtd instance embedded in struct nand_chip
  mtd: nand: omap2: use the mtd instance embedded in struct nand_chip
  mtd: nand: orion: use the mtd instance embedded in struct nand_chip
  mtd: nand: pasemi: use the mtd instance embedded in struct nand_chip
  mtd: nand: plat: use the mtd instance embedded in struct nand_chip
  mtd: nand: pxa3xx: use the mtd instance embedded in struct nand_chip
  mtd: nand: r852: use the mtd instance embedded in struct nand_chip
  mtd: nand: s3c2410: use the mtd instance embedded in struct nand_chip
  mtd: nand: sh_flctl: use the mtd instance embedded in struct nand_chip
  mtd: nand: sharpsl: use the mtd instance embedded in struct nand_chip
  mtd: nand: socrates: use the mtd instance embedded in struct nand_chip
  mtd: nand: sunxi: use the mtd instance embedded in struct nand_chip
  mtd: nand: tmio: use the mtd instance embedded in 

[PATCH v4 02/58] mtd: nand: fsmc: create and use mtd_to_fsmc()

2015-12-10 Thread Boris Brezillon
Create and use mtd_to_fsmc() to avoid duplication of
container_of(mtd, struct fsmc_nand_data, mtd) calls.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/fsmc_nand.c | 31 ++-
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c
index 1c6c399..499fc59 100644
--- a/drivers/mtd/nand/fsmc_nand.c
+++ b/drivers/mtd/nand/fsmc_nand.c
@@ -326,13 +326,18 @@ struct fsmc_nand_data {
void(*select_chip)(uint32_t bank, uint32_t busw);
 };
 
+static inline struct fsmc_nand_data *mtd_to_fsmc(struct mtd_info *mtd)
+{
+   return container_of(mtd, struct fsmc_nand_data, mtd);
+}
+
 /* Assert CS signal based on chipnr */
 static void fsmc_select_chip(struct mtd_info *mtd, int chipnr)
 {
struct nand_chip *chip = mtd_to_nand(mtd);
struct fsmc_nand_data *host;
 
-   host = container_of(mtd, struct fsmc_nand_data, mtd);
+   host = mtd_to_fsmc(mtd);
 
switch (chipnr) {
case -1:
@@ -359,8 +364,7 @@ static void fsmc_select_chip(struct mtd_info *mtd, int 
chipnr)
 static void fsmc_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
struct nand_chip *this = mtd_to_nand(mtd);
-   struct fsmc_nand_data *host = container_of(mtd,
-   struct fsmc_nand_data, mtd);
+   struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
void __iomem *regs = host->regs_va;
unsigned int bank = host->bank;
 
@@ -445,8 +449,7 @@ static void fsmc_nand_setup(void __iomem *regs, uint32_t 
bank,
  */
 static void fsmc_enable_hwecc(struct mtd_info *mtd, int mode)
 {
-   struct fsmc_nand_data *host = container_of(mtd,
-   struct fsmc_nand_data, mtd);
+   struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
void __iomem *regs = host->regs_va;
uint32_t bank = host->bank;
 
@@ -466,8 +469,7 @@ static void fsmc_enable_hwecc(struct mtd_info *mtd, int 
mode)
 static int fsmc_read_hwecc_ecc4(struct mtd_info *mtd, const uint8_t *data,
uint8_t *ecc)
 {
-   struct fsmc_nand_data *host = container_of(mtd,
-   struct fsmc_nand_data, mtd);
+   struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
void __iomem *regs = host->regs_va;
uint32_t bank = host->bank;
uint32_t ecc_tmp;
@@ -517,8 +519,7 @@ static int fsmc_read_hwecc_ecc4(struct mtd_info *mtd, const 
uint8_t *data,
 static int fsmc_read_hwecc_ecc1(struct mtd_info *mtd, const uint8_t *data,
uint8_t *ecc)
 {
-   struct fsmc_nand_data *host = container_of(mtd,
-   struct fsmc_nand_data, mtd);
+   struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
void __iomem *regs = host->regs_va;
uint32_t bank = host->bank;
uint32_t ecc_tmp;
@@ -674,9 +675,8 @@ static void fsmc_read_buf(struct mtd_info *mtd, uint8_t 
*buf, int len)
  */
 static void fsmc_read_buf_dma(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-   struct fsmc_nand_data *host;
+   struct fsmc_nand_data *host  = mtd_to_fsmc(mtd);
 
-   host = container_of(mtd, struct fsmc_nand_data, mtd);
dma_xfer(host, buf, len, DMA_FROM_DEVICE);
 }
 
@@ -689,9 +689,8 @@ static void fsmc_read_buf_dma(struct mtd_info *mtd, uint8_t 
*buf, int len)
 static void fsmc_write_buf_dma(struct mtd_info *mtd, const uint8_t *buf,
int len)
 {
-   struct fsmc_nand_data *host;
+   struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
 
-   host = container_of(mtd, struct fsmc_nand_data, mtd);
dma_xfer(host, (void *)buf, len, DMA_TO_DEVICE);
 }
 
@@ -712,8 +711,7 @@ static void fsmc_write_buf_dma(struct mtd_info *mtd, const 
uint8_t *buf,
 static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
 uint8_t *buf, int oob_required, int page)
 {
-   struct fsmc_nand_data *host = container_of(mtd,
-   struct fsmc_nand_data, mtd);
+   struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
struct fsmc_eccplace *ecc_place = host->ecc_place;
int i, j, s, stat, eccsize = chip->ecc.size;
int eccbytes = chip->ecc.bytes;
@@ -782,9 +780,8 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, 
struct nand_chip *chip,
 static int fsmc_bch8_correct_data(struct mtd_info *mtd, uint8_t *dat,
 uint8_t *read_ecc, uint8_t *calc_ecc)
 {
-   struct fsmc_nand_data *host = container_of(mtd,
-   struct fsmc_nand_data, mtd);
struct nand_chip *chip = mtd_to_nand(mtd);
+   struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
void __iomem *regs = host->regs_va;
unsigned int bank = host->bank;
uint32_t 

[PATCH v4 01/58] mtd: nand: denali: add missing nand_release() call in denali_remove()

2015-12-10 Thread Boris Brezillon
Unregister the NAND device from the NAND subsystem when removing a denali
NAND controller, otherwise the MTD attached to the NAND device is still
exposed by the MTD layer, and accesses to this device will likely crash
the system.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
Cc: <sta...@vger.kernel.org> #3.8+
Fixes: 2a0a288ec258 ("mtd: denali: split the generic driver and PCI layer")
---
 drivers/mtd/nand/denali.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 67eb2be..8feece3 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -1622,6 +1622,7 @@ EXPORT_SYMBOL(denali_init);
 /* driver exit point */
 void denali_remove(struct denali_nand_info *denali)
 {
+   nand_release(>mtd);
denali_irq_cleanup(denali->irq, denali);
dma_unmap_single(denali->dev, denali->buf.dma_buf,
 denali->mtd.writesize + denali->mtd.oobsize,
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 03/58] mtd: nand: nuc900: create and use mtd_to_nuc900()

2015-12-10 Thread Boris Brezillon
Create and use mtd_to_nuc900() instead of direct container_of() calls.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/nuc900_nand.c | 25 ++---
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/mtd/nand/nuc900_nand.c b/drivers/mtd/nand/nuc900_nand.c
index 8148cd6..65908c0 100644
--- a/drivers/mtd/nand/nuc900_nand.c
+++ b/drivers/mtd/nand/nuc900_nand.c
@@ -62,6 +62,11 @@ struct nuc900_nand {
spinlock_t lock;
 };
 
+static inline struct nuc900_nand *mtd_to_nuc900(struct mtd_info *mtd)
+{
+   return container_of(mtd, struct nuc900_nand, mtd);
+}
+
 static const struct mtd_partition partitions[] = {
{
 .name = "NAND FS 0",
@@ -78,9 +83,7 @@ static const struct mtd_partition partitions[] = {
 static unsigned char nuc900_nand_read_byte(struct mtd_info *mtd)
 {
unsigned char ret;
-   struct nuc900_nand *nand;
-
-   nand = container_of(mtd, struct nuc900_nand, mtd);
+   struct nuc900_nand *nand = mtd_to_nuc900(mtd);
 
ret = (unsigned char)read_data_reg(nand);
 
@@ -91,9 +94,7 @@ static void nuc900_nand_read_buf(struct mtd_info *mtd,
 unsigned char *buf, int len)
 {
int i;
-   struct nuc900_nand *nand;
-
-   nand = container_of(mtd, struct nuc900_nand, mtd);
+   struct nuc900_nand *nand = mtd_to_nuc900(mtd);
 
for (i = 0; i < len; i++)
buf[i] = (unsigned char)read_data_reg(nand);
@@ -103,9 +104,7 @@ static void nuc900_nand_write_buf(struct mtd_info *mtd,
  const unsigned char *buf, int len)
 {
int i;
-   struct nuc900_nand *nand;
-
-   nand = container_of(mtd, struct nuc900_nand, mtd);
+   struct nuc900_nand *nand = mtd_to_nuc900(mtd);
 
for (i = 0; i < len; i++)
write_data_reg(nand, buf[i]);
@@ -124,11 +123,9 @@ static int nuc900_check_rb(struct nuc900_nand *nand)
 
 static int nuc900_nand_devready(struct mtd_info *mtd)
 {
-   struct nuc900_nand *nand;
+   struct nuc900_nand *nand = mtd_to_nuc900(mtd);
int ready;
 
-   nand = container_of(mtd, struct nuc900_nand, mtd);
-
ready = (nuc900_check_rb(nand)) ? 1 : 0;
return ready;
 }
@@ -137,9 +134,7 @@ static void nuc900_nand_command_lp(struct mtd_info *mtd, 
unsigned int command,
   int column, int page_addr)
 {
register struct nand_chip *chip = mtd_to_nand(mtd);
-   struct nuc900_nand *nand;
-
-   nand = container_of(mtd, struct nuc900_nand, mtd);
+   struct nuc900_nand *nand = mtd_to_nuc900(mtd);
 
if (command == NAND_CMD_READOOB) {
column += mtd->writesize;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 07/58] mtd: nand: au1550nd: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/au1550nd.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index 73fceb8..280e5b6 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -23,7 +23,6 @@
 
 
 struct au1550nd_ctx {
-   struct mtd_info info;
struct nand_chip chip;
 
int cs;
@@ -197,8 +196,9 @@ static void au_read_buf16(struct mtd_info *mtd, u_char 
*buf, int len)
 
 static void au1550_hwcontrol(struct mtd_info *mtd, int cmd)
 {
-   struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info);
struct nand_chip *this = mtd_to_nand(mtd);
+   struct au1550nd_ctx *ctx = container_of(this, struct au1550nd_ctx,
+   chip);
 
switch (cmd) {
 
@@ -267,8 +267,9 @@ static void au1550_select_chip(struct mtd_info *mtd, int 
chip)
  */
 static void au1550_command(struct mtd_info *mtd, unsigned command, int column, 
int page_addr)
 {
-   struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info);
struct nand_chip *this = mtd_to_nand(mtd);
+   struct au1550nd_ctx *ctx = container_of(this, struct au1550nd_ctx,
+   chip);
int ce_override = 0, i;
unsigned long flags = 0;
 
@@ -405,6 +406,7 @@ static int au1550nd_probe(struct platform_device *pdev)
struct au1550nd_platdata *pd;
struct au1550nd_ctx *ctx;
struct nand_chip *this;
+   struct mtd_info *mtd;
struct resource *r;
int ret, cs;
 
@@ -438,8 +440,9 @@ static int au1550nd_probe(struct platform_device *pdev)
}
 
this = >chip;
-   ctx->info.priv = this;
-   ctx->info.dev.parent = >dev;
+   mtd = nand_to_mtd(this);
+   mtd->priv = this;
+   mtd->dev.parent = >dev;
 
/* figure out which CS# r->start belongs to */
cs = find_nand_cs(r->start);
@@ -467,13 +470,13 @@ static int au1550nd_probe(struct platform_device *pdev)
this->write_buf = (pd->devwidth) ? au_write_buf16 : au_write_buf;
this->read_buf = (pd->devwidth) ? au_read_buf16 : au_read_buf;
 
-   ret = nand_scan(>info, 1);
+   ret = nand_scan(mtd, 1);
if (ret) {
dev_err(>dev, "NAND scan failed with %d\n", ret);
goto out3;
}
 
-   mtd_device_register(>info, pd->parts, pd->num_parts);
+   mtd_device_register(mtd, pd->parts, pd->num_parts);
 
platform_set_drvdata(pdev, ctx);
 
@@ -493,7 +496,7 @@ static int au1550nd_remove(struct platform_device *pdev)
struct au1550nd_ctx *ctx = platform_get_drvdata(pdev);
struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
-   nand_release(>info);
+   nand_release(nand_to_mtd(>chip));
iounmap(ctx->base);
release_mem_region(r->start, 0x1000);
kfree(ctx);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 20/58] mtd: nand: fsl_upm: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/fsl_upm.c | 29 -
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c
index 68ec128..0379adc 100644
--- a/drivers/mtd/nand/fsl_upm.c
+++ b/drivers/mtd/nand/fsl_upm.c
@@ -31,7 +31,6 @@
 
 struct fsl_upm_nand {
struct device *dev;
-   struct mtd_info mtd;
struct nand_chip chip;
int last_ctrl;
struct mtd_partition *parts;
@@ -49,7 +48,8 @@ struct fsl_upm_nand {
 
 static inline struct fsl_upm_nand *to_fsl_upm_nand(struct mtd_info *mtdinfo)
 {
-   return container_of(mtdinfo, struct fsl_upm_nand, mtd);
+   return container_of(mtd_to_nand(mtdinfo), struct fsl_upm_nand,
+   chip);
 }
 
 static int fun_chip_ready(struct mtd_info *mtd)
@@ -66,9 +66,10 @@ static int fun_chip_ready(struct mtd_info *mtd)
 static void fun_wait_rnb(struct fsl_upm_nand *fun)
 {
if (fun->rnb_gpio[fun->mchip_number] >= 0) {
+   struct mtd_info *mtd = nand_to_mtd(>chip);
int cnt = 100;
 
-   while (--cnt && !fun_chip_ready(>mtd))
+   while (--cnt && !fun_chip_ready(mtd))
cpu_relax();
if (!cnt)
dev_err(fun->dev, "tired waiting for RNB\n");
@@ -157,6 +158,7 @@ static int fun_chip_init(struct fsl_upm_nand *fun,
 const struct device_node *upm_np,
 const struct resource *io_res)
 {
+   struct mtd_info *mtd = nand_to_mtd(>chip);
int ret;
struct device_node *flash_np;
 
@@ -174,30 +176,30 @@ static int fun_chip_init(struct fsl_upm_nand *fun,
if (fun->rnb_gpio[0] >= 0)
fun->chip.dev_ready = fun_chip_ready;
 
-   fun->mtd.priv = >chip;
-   fun->mtd.dev.parent = fun->dev;
+   mtd->priv = >chip;
+   mtd->dev.parent = fun->dev;
 
flash_np = of_get_next_child(upm_np, NULL);
if (!flash_np)
return -ENODEV;
 
nand_set_flash_node(>chip, flash_np);
-   fun->mtd.name = kasprintf(GFP_KERNEL, "0x%llx.%s", (u64)io_res->start,
- flash_np->name);
-   if (!fun->mtd.name) {
+   mtd->name = kasprintf(GFP_KERNEL, "0x%llx.%s", (u64)io_res->start,
+ flash_np->name);
+   if (!mtd->name) {
ret = -ENOMEM;
goto err;
}
 
-   ret = nand_scan(>mtd, fun->mchip_count);
+   ret = nand_scan(mtd, fun->mchip_count);
if (ret)
goto err;
 
-   ret = mtd_device_register(>mtd, NULL, 0);
+   ret = mtd_device_register(mtd, NULL, 0);
 err:
of_node_put(flash_np);
if (ret)
-   kfree(fun->mtd.name);
+   kfree(mtd->name);
return ret;
 }
 
@@ -321,10 +323,11 @@ err1:
 static int fun_remove(struct platform_device *ofdev)
 {
struct fsl_upm_nand *fun = dev_get_drvdata(>dev);
+   struct mtd_info *mtd = nand_to_mtd(>chip);
int i;
 
-   nand_release(>mtd);
-   kfree(fun->mtd.name);
+   nand_release(mtd);
+   kfree(mtd->name);
 
for (i = 0; i < fun->mchip_count; i++) {
if (fun->rnb_gpio[i] < 0)
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 56/58] ARM: make use of nand_set/get_controller_data() helpers

2015-12-10 Thread Boris Brezillon
New helpers have been added to avoid directly accessing chip->field. Use
them where appropriate.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 arch/arm/mach-ixp4xx/ixdp425-setup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-ixp4xx/ixdp425-setup.c 
b/arch/arm/mach-ixp4xx/ixdp425-setup.c
index 333b0f9..508c2d7 100644
--- a/arch/arm/mach-ixp4xx/ixdp425-setup.c
+++ b/arch/arm/mach-ixp4xx/ixdp425-setup.c
@@ -77,7 +77,7 @@ static void
 ixdp425_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
struct nand_chip *this = mtd_to_nand(mtd);
-   int offset = (int)this->priv;
+   int offset = (int)nand_get_controller_data(this);
 
if (ctrl & NAND_CTRL_CHANGE) {
if (ctrl & NAND_NCE) {
@@ -88,7 +88,7 @@ ixdp425_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 
unsigned int ctrl)
 
offset = (ctrl & NAND_CLE) ? IXDP425_NAND_CMD_BYTE : 0;
offset |= (ctrl & NAND_ALE) ? IXDP425_NAND_ADDR_BYTE : 0;
-   this->priv = (void *)offset;
+   nand_set_controller_data(this, (void *)offset);
}
 
if (cmd != NAND_CMD_NONE)
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 58/58] staging: mt29f_spinand: make use of nand_set/get_controller_data() helpers

2015-12-10 Thread Boris Brezillon
New helpers have been added to avoid directly accessing chip->field. Use
them where appropriate.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/staging/mt29f_spinand/mt29f_spinand.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.c 
b/drivers/staging/mt29f_spinand/mt29f_spinand.c
index b7d429d..197d112 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
@@ -32,7 +32,7 @@
 static inline struct spinand_state *mtd_to_state(struct mtd_info *mtd)
 {
struct nand_chip *chip = mtd_to_nand(mtd);
-   struct spinand_info *info = (struct spinand_info *)chip->priv;
+   struct spinand_info *info = nand_get_controller_data(chip);
struct spinand_state *state = (struct spinand_state *)info->priv;
 
return state;
@@ -633,7 +633,7 @@ static int spinand_read_page_hwecc(struct mtd_info *mtd, 
struct nand_chip *chip,
u8 *p = buf;
int eccsize = chip->ecc.size;
int eccsteps = chip->ecc.steps;
-   struct spinand_info *info = (struct spinand_info *)chip->priv;
+   struct spinand_info *info = nand_get_controller_data(chip);
 
enable_read_hw_ecc = 1;
 
@@ -679,7 +679,7 @@ static u8 spinand_read_byte(struct mtd_info *mtd)
 
 static int spinand_wait(struct mtd_info *mtd, struct nand_chip *chip)
 {
-   struct spinand_info *info = (struct spinand_info *)chip->priv;
+   struct spinand_info *info = nand_get_controller_data(chip);
 
unsigned long timeo = jiffies;
int retval, state = chip->state;
@@ -745,7 +745,7 @@ static void spinand_cmdfunc(struct mtd_info *mtd, unsigned 
int command,
int column, int page)
 {
struct nand_chip *chip = mtd_to_nand(mtd);
-   struct spinand_info *info = (struct spinand_info *)chip->priv;
+   struct spinand_info *info = nand_get_controller_data(chip);
struct spinand_state *state = (struct spinand_state *)info->priv;
 
switch (command) {
@@ -894,7 +894,7 @@ static int spinand_probe(struct spi_device *spi_nand)
 #endif
 
nand_set_flash_node(chip, spi_nand->dev.of_node);
-   chip->priv  = info;
+   nand_set_controller_data(chip, info);
chip->read_buf  = spinand_read_buf;
chip->write_buf = spinand_write_buf;
chip->read_byte = spinand_read_byte;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 51/58] cris: nand: remove useless mtd->priv = chip assignments

2015-12-10 Thread Boris Brezillon
mtd_to_nand() now uses the container_of() approach to transform an
mtd_info pointer into a nand_chip one. Drop useless mtd->priv
assignments from NAND controller drivers.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Patch generated with the following coccinelle script:

---8<
virtual patch

@@
struct mtd_info m;
struct mtd_info *mp;
struct nand_chip *c;
@@
(
-(m).priv = c;
|
-(mp)->priv = c;
|
-(mp)->priv = (void *)c;
)
---8<
---
 arch/cris/arch-v32/drivers/mach-a3/nandflash.c | 3 ---
 arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 3 ---
 2 files changed, 6 deletions(-)

diff --git a/arch/cris/arch-v32/drivers/mach-a3/nandflash.c 
b/arch/cris/arch-v32/drivers/mach-a3/nandflash.c
index ee74e45..5aa3f51 100644
--- a/arch/cris/arch-v32/drivers/mach-a3/nandflash.c
+++ b/arch/cris/arch-v32/drivers/mach-a3/nandflash.c
@@ -149,9 +149,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)
this = >chip;
crisv32_mtd = nand_to_mtd(this);
 
-   /* Link the private data with the MTD structure */
-   crisv32_mtd->priv = this;
-
/* Set address of NAND IO lines */
this->IO_ADDR_R = read_cs;
this->IO_ADDR_W = write_cs;
diff --git a/arch/cris/arch-v32/drivers/mach-fs/nandflash.c 
b/arch/cris/arch-v32/drivers/mach-fs/nandflash.c
index 5626297..a7c17b0 100644
--- a/arch/cris/arch-v32/drivers/mach-fs/nandflash.c
+++ b/arch/cris/arch-v32/drivers/mach-fs/nandflash.c
@@ -140,9 +140,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)
bif_cfg.gated_csp1 = regk_bif_core_wr;
REG_WR(bif_core, regi_bif_core, rw_grp3_cfg, bif_cfg);
 
-   /* Link the private data with the MTD structure */
-   crisv32_mtd->priv = this;
-
/* Set address of NAND IO lines */
this->IO_ADDR_R = read_cs;
this->IO_ADDR_W = write_cs;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 54/58] mtd: nand: kill the chip->flash_node field

2015-12-10 Thread Boris Brezillon
Now that the nand_chip struct directly embeds an mtd_info struct we can
get rid of the ->flash_node field and forward set/get_flash_node requests
to the MTD layer.

As a side effect, we no longer need the mtd_set_of_node() call done in
nand_dt_init().

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/nand_base.c | 3 ---
 include/linux/mtd/nand.h | 7 ++-
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index ae3fd2a..8bb8ebd6 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3945,9 +3945,6 @@ static int nand_dt_init(struct nand_chip *chip)
if (!dn)
return 0;
 
-   /* MTD can automatically handle DT partitions, etc. */
-   mtd_set_of_node(nand_to_mtd(chip), dn);
-
if (of_get_nand_bus_width(dn) == 16)
chip->options |= NAND_BUSWIDTH_16;
 
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 9cb7ace..2bee2e4 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -545,7 +545,6 @@ struct nand_buffers {
  * flash device
  * @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the
  * flash device.
- * @flash_node:[BOARDSPECIFIC] device node describing this 
instance
  * @read_byte: [REPLACEABLE] read one byte from the chip
  * @read_word: [REPLACEABLE] read one word from the chip
  * @write_byte:[REPLACEABLE] write a single byte to the chip 
on the
@@ -645,8 +644,6 @@ struct nand_chip {
void __iomem *IO_ADDR_R;
void __iomem *IO_ADDR_W;
 
-   struct device_node *flash_node;
-
uint8_t (*read_byte)(struct mtd_info *mtd);
u16 (*read_word)(struct mtd_info *mtd);
void (*write_byte)(struct mtd_info *mtd, uint8_t byte);
@@ -724,12 +721,12 @@ struct nand_chip {
 static inline void nand_set_flash_node(struct nand_chip *chip,
   struct device_node *np)
 {
-   chip->flash_node = np;
+   mtd_set_of_node(>mtd, np);
 }
 
 static inline struct device_node *nand_get_flash_node(struct nand_chip *chip)
 {
-   return chip->flash_node;
+   return mtd_get_of_node(>mtd);
 }
 
 static inline struct nand_chip *mtd_to_nand(struct mtd_info *mtd)
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 53/58] mtd: nand: simplify nand_dt_init() usage

2015-12-10 Thread Boris Brezillon
nand_dt_init() function requires 3 arguments where it actually needs one
(dn and mtd can both be retrieved from chip). Drop these parameters.

Testing for dn != NULL inside nand_dt_init() also helps simplifying the
caller code.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/nand_base.c | 21 +++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 5aec154..ae3fd2a 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3937,11 +3937,17 @@ ident_done:
return type;
 }
 
-static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip,
-   struct device_node *dn)
+static int nand_dt_init(struct nand_chip *chip)
 {
+   struct device_node *dn = nand_get_flash_node(chip);
int ecc_mode, ecc_strength, ecc_step;
 
+   if (!dn)
+   return 0;
+
+   /* MTD can automatically handle DT partitions, etc. */
+   mtd_set_of_node(nand_to_mtd(chip), dn);
+
if (of_get_nand_bus_width(dn) == 16)
chip->options |= NAND_BUSWIDTH_16;
 
@@ -3989,14 +3995,9 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
struct nand_flash_dev *type;
int ret;
 
-   if (nand_get_flash_node(chip)) {
-   /* MTD can automatically handle DT partitions, etc. */
-   mtd_set_of_node(mtd, nand_get_flash_node(chip));
-
-   ret = nand_dt_init(mtd, chip, nand_get_flash_node(chip));
-   if (ret)
-   return ret;
-   }
+   ret = nand_dt_init(chip);
+   if (ret)
+   return ret;
 
/* Set the default functions */
nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 24/58] mtd: nand: hisi504: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/hisi504_nand.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/hisi504_nand.c b/drivers/mtd/nand/hisi504_nand.c
index 6358d4a..6e6e482 100644
--- a/drivers/mtd/nand/hisi504_nand.c
+++ b/drivers/mtd/nand/hisi504_nand.c
@@ -134,7 +134,6 @@
 
 struct hinfc_host {
struct nand_chipchip;
-   struct mtd_info mtd;
struct device   *dev;
void __iomem*iobase;
void __iomem*mmio;
@@ -189,8 +188,8 @@ static void wait_controller_finished(struct hinfc_host 
*host)
 
 static void hisi_nfc_dma_transfer(struct hinfc_host *host, int todev)
 {
-   struct mtd_info *mtd = >mtd;
-   struct nand_chip *chip = mtd_to_nand(mtd);
+   struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(chip);
unsigned long val;
int ret;
 
@@ -262,7 +261,7 @@ static int hisi_nfc_send_cmd_pageprog(struct hinfc_host 
*host)
 
 static int hisi_nfc_send_cmd_readstart(struct hinfc_host *host)
 {
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
 
if ((host->addr_value[0] == host->cache_addr_value[0]) &&
(host->addr_value[1] == host->cache_addr_value[1]))
@@ -643,7 +642,7 @@ static int hisi_nfc_ecc_probe(struct hinfc_host *host)
int size, strength, ecc_bits;
struct device *dev = host->dev;
struct nand_chip *chip = >chip;
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(chip);
struct device_node *np = host->dev->of_node;
 
size = of_get_nand_ecc_step_size(np);
@@ -712,7 +711,7 @@ static int hisi_nfc_probe(struct platform_device *pdev)
 
platform_set_drvdata(pdev, host);
chip = >chip;
-   mtd  = >mtd;
+   mtd  = nand_to_mtd(chip);
 
irq = platform_get_irq(pdev, 0);
if (irq < 0) {
@@ -822,7 +821,7 @@ err_res:
 static int hisi_nfc_remove(struct platform_device *pdev)
 {
struct hinfc_host *host = platform_get_drvdata(pdev);
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
 
nand_release(mtd);
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 19/58] mtd: nand: fsl_ifc: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/fsl_ifc_nand.c | 28 
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/nand/fsl_ifc_nand.c b/drivers/mtd/nand/fsl_ifc_nand.c
index 3136842..3f5654f 100644
--- a/drivers/mtd/nand/fsl_ifc_nand.c
+++ b/drivers/mtd/nand/fsl_ifc_nand.c
@@ -40,7 +40,6 @@ struct fsl_ifc_ctrl;
 
 /* mtd information per set */
 struct fsl_ifc_mtd {
-   struct mtd_info mtd;
struct nand_chip chip;
struct fsl_ifc_ctrl *ctrl;
 
@@ -877,12 +876,13 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
struct fsl_ifc_ctrl *ctrl = priv->ctrl;
struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(>chip);
struct nand_ecclayout *layout;
u32 csor;
 
/* Fill in fsl_ifc_mtd structure */
-   priv->mtd.priv = chip;
-   priv->mtd.dev.parent = priv->dev;
+   mtd->priv = chip;
+   mtd->dev.parent = priv->dev;
nand_set_flash_node(chip, priv->dev->of_node);
 
/* fill in nand_chip structure */
@@ -994,9 +994,11 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
 
 static int fsl_ifc_chip_remove(struct fsl_ifc_mtd *priv)
 {
-   nand_release(>mtd);
+   struct mtd_info *mtd = nand_to_mtd(>chip);
 
-   kfree(priv->mtd.name);
+   nand_release(mtd);
+
+   kfree(mtd->name);
 
if (priv->vbase)
iounmap(priv->vbase);
@@ -1031,6 +1033,7 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)
int ret;
int bank;
struct device_node *node = dev->dev.of_node;
+   struct mtd_info *mtd;
 
if (!fsl_ifc_ctrl_dev || !fsl_ifc_ctrl_dev->regs)
return -ENODEV;
@@ -1103,8 +1106,10 @@ static int fsl_ifc_nand_probe(struct platform_device 
*dev)
  IFC_NAND_EVTER_INTR_FTOERIR_EN |
  IFC_NAND_EVTER_INTR_WPERIR_EN,
  >ifc_nand.nand_evter_intr_en);
-   priv->mtd.name = kasprintf(GFP_KERNEL, "%llx.flash", (u64)res.start);
-   if (!priv->mtd.name) {
+
+   mtd = nand_to_mtd(>chip);
+   mtd->name = kasprintf(GFP_KERNEL, "%llx.flash", (u64)res.start);
+   if (!mtd->name) {
ret = -ENOMEM;
goto err;
}
@@ -1113,22 +1118,21 @@ static int fsl_ifc_nand_probe(struct platform_device 
*dev)
if (ret)
goto err;
 
-   ret = nand_scan_ident(>mtd, 1, NULL);
+   ret = nand_scan_ident(mtd, 1, NULL);
if (ret)
goto err;
 
-   ret = fsl_ifc_chip_init_tail(>mtd);
+   ret = fsl_ifc_chip_init_tail(mtd);
if (ret)
goto err;
 
-   ret = nand_scan_tail(>mtd);
+   ret = nand_scan_tail(mtd);
if (ret)
goto err;
 
/* First look for RedBoot table or partitions on the command
 * line, these take precedence over device tree information */
-   mtd_device_parse_register(>mtd, part_probe_types, NULL,
-   NULL, 0);
+   mtd_device_parse_register(mtd, part_probe_types, NULL, NULL, 0);
 
dev_info(priv->dev, "IFC NAND device at 0x%llx, bank %d\n",
 (unsigned long long)res.start, priv->bank);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 55/58] mtd: nand: add helpers to access ->priv

2015-12-10 Thread Boris Brezillon
Add two helpers to access the field reserved for private controller data.
This makes it clearer what this field is reserved for and ease future
refactoring.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 include/linux/mtd/nand.h | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 2bee2e4..4aed4b2 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -739,6 +739,16 @@ static inline struct mtd_info *nand_to_mtd(struct 
nand_chip *chip)
return >mtd;
 }
 
+static inline void *nand_get_controller_data(struct nand_chip *chip)
+{
+   return chip->priv;
+}
+
+static inline void nand_set_controller_data(struct nand_chip *chip, void *priv)
+{
+   chip->priv = priv;
+}
+
 /*
  * NAND Flash Manufacturer ID Codes
  */
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 40/58] mtd: nand: sharpsl: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/sharpsl.c | 22 +-
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/sharpsl.c b/drivers/mtd/nand/sharpsl.c
index 84129e5..4b649fb 100644
--- a/drivers/mtd/nand/sharpsl.c
+++ b/drivers/mtd/nand/sharpsl.c
@@ -29,13 +29,15 @@
 #include 
 
 struct sharpsl_nand {
-   struct mtd_info mtd;
struct nand_chipchip;
 
void __iomem*io;
 };
 
-#define mtd_to_sharpsl(_mtd)   container_of(_mtd, struct sharpsl_nand, mtd)
+static inline struct sharpsl_nand *mtd_to_sharpsl(struct mtd_info *mtd)
+{
+   return container_of(mtd_to_nand(mtd), struct sharpsl_nand, chip);
+}
 
 /* register offset */
 #define ECCLPLB0x00/* line parity 7 - 0 bit */
@@ -109,6 +111,7 @@ static int sharpsl_nand_calculate_ecc(struct mtd_info *mtd, 
const u_char * dat,
 static int sharpsl_nand_probe(struct platform_device *pdev)
 {
struct nand_chip *this;
+   struct mtd_info *mtd;
struct resource *r;
int err = 0;
struct sharpsl_nand *sharpsl;
@@ -143,8 +146,9 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
this = (struct nand_chip *)(>chip);
 
/* Link the private data with the MTD structure */
-   sharpsl->mtd.priv = this;
-   sharpsl->mtd.dev.parent = >dev;
+   mtd = nand_to_mtd(this);
+   mtd->priv = this;
+   mtd->dev.parent = >dev;
 
platform_set_drvdata(pdev, sharpsl);
 
@@ -173,14 +177,14 @@ static int sharpsl_nand_probe(struct platform_device 
*pdev)
this->ecc.correct = nand_correct_data;
 
/* Scan to find existence of the device */
-   err = nand_scan(>mtd, 1);
+   err = nand_scan(mtd, 1);
if (err)
goto err_scan;
 
/* Register the partitions */
-   sharpsl->mtd.name = "sharpsl-nand";
+   mtd->name = "sharpsl-nand";
 
-   err = mtd_device_parse_register(>mtd, NULL, NULL,
+   err = mtd_device_parse_register(mtd, NULL, NULL,
data->partitions, data->nr_partitions);
if (err)
goto err_add;
@@ -189,7 +193,7 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
return 0;
 
 err_add:
-   nand_release(>mtd);
+   nand_release(mtd);
 
 err_scan:
iounmap(sharpsl->io);
@@ -207,7 +211,7 @@ static int sharpsl_nand_remove(struct platform_device *pdev)
struct sharpsl_nand *sharpsl = platform_get_drvdata(pdev);
 
/* Release resources, unregister device */
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
 
iounmap(sharpsl->io);
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 38/58] mtd: nand: s3c2410: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/s3c2410.c | 23 ++-
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index e658b29..c074a49 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -104,7 +104,6 @@ struct s3c2410_nand_info;
  * @scan_res: The result from calling nand_scan_ident().
 */
 struct s3c2410_nand_mtd {
-   struct mtd_info mtd;
struct nand_chipchip;
struct s3c2410_nand_set *set;
struct s3c2410_nand_info*info;
@@ -168,7 +167,8 @@ struct s3c2410_nand_info {
 
 static struct s3c2410_nand_mtd *s3c2410_nand_mtd_toours(struct mtd_info *mtd)
 {
-   return container_of(mtd, struct s3c2410_nand_mtd, mtd);
+   return container_of(mtd_to_nand(mtd), struct s3c2410_nand_mtd,
+   chip);
 }
 
 static struct s3c2410_nand_info *s3c2410_nand_mtd_toinfo(struct mtd_info *mtd)
@@ -745,7 +745,7 @@ static int s3c24xx_nand_remove(struct platform_device *pdev)
 
for (mtdno = 0; mtdno < info->mtd_count; mtdno++, ptr++) {
pr_debug("releasing mtd %d (%p)\n", mtdno, ptr);
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>chip));
}
}
 
@@ -762,9 +762,11 @@ static int s3c2410_nand_add_partition(struct 
s3c2410_nand_info *info,
  struct s3c2410_nand_set *set)
 {
if (set) {
-   mtd->mtd.name = set->name;
+   struct mtd_info *mtdinfo = nand_to_mtd(>chip);
 
-   return mtd_device_parse_register(>mtd, NULL, NULL,
+   mtdinfo->name = set->name;
+
+   return mtd_device_parse_register(mtdinfo, NULL, NULL,
 set->partitions, set->nr_partitions);
}
 
@@ -786,6 +788,7 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info 
*info,
   struct s3c2410_nand_set *set)
 {
struct nand_chip *chip = >chip;
+   struct mtd_info *mtd = nand_to_mtd(chip);
void __iomem *regs = info->regs;
 
chip->write_buf= s3c2410_nand_write_buf;
@@ -831,7 +834,7 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info 
*info,
chip->IO_ADDR_R = chip->IO_ADDR_W;
 
nmtd->info = info;
-   nmtd->mtd.priv = chip;
+   mtd->priv  = chip;
nmtd->set  = set;
 
 #ifdef CONFIG_MTD_NAND_S3C2410_HWECC
@@ -1012,19 +1015,21 @@ static int s3c24xx_nand_probe(struct platform_device 
*pdev)
nmtd = info->mtds;
 
for (setno = 0; setno < nr_sets; setno++, nmtd++) {
+   struct mtd_info *mtd = nand_to_mtd(>chip);
+
pr_debug("initialising set %d (%p, info %p)\n",
 setno, nmtd, info);
 
-   nmtd->mtd.dev.parent = >dev;
+   mtd->dev.parent = >dev;
s3c2410_nand_init_chip(info, nmtd, sets);
 
-   nmtd->scan_res = nand_scan_ident(>mtd,
+   nmtd->scan_res = nand_scan_ident(mtd,
 (sets) ? sets->nr_chips : 1,
 NULL);
 
if (nmtd->scan_res == 0) {
s3c2410_nand_update_chip(info, nmtd);
-   nand_scan_tail(>mtd);
+   nand_scan_tail(mtd);
s3c2410_nand_add_partition(info, nmtd, sets);
}
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 32/58] mtd: nand: omap2: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/omap2.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index 1fb40db..f9d0b58 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -152,7 +152,6 @@ static struct nand_hw_control omap_gpmc_controller = {
 
 struct omap_nand_info {
struct omap_nand_platform_data  *pdata;
-   struct mtd_info mtd;
struct nand_chipnand;
struct platform_device  *pdev;
 
@@ -179,8 +178,9 @@ struct omap_nand_info {
 
 static inline struct omap_nand_info *mtd_to_omap(struct mtd_info *mtd)
 {
-   return container_of(mtd, struct omap_nand_info, mtd);
+   return container_of(mtd_to_nand(mtd), struct omap_nand_info, nand);
 }
+
 /**
  * omap_prefetch_enable - configures and starts prefetch transfer
  * @cs: cs (chip select) number
@@ -1670,10 +1670,10 @@ static int omap_nand_probe(struct platform_device *pdev)
info->reg   = pdata->reg;
info->of_node   = pdata->of_node;
info->ecc_opt   = pdata->ecc_opt;
-   mtd = >mtd;
+   nand_chip   = >nand;
+   mtd = nand_to_mtd(nand_chip);
mtd->priv   = >nand;
mtd->dev.parent = >dev;
-   nand_chip   = >nand;
nand_chip->ecc.priv = NULL;
nand_set_flash_node(nand_chip, pdata->of_node);
 
@@ -1897,7 +1897,7 @@ static int omap_nand_probe(struct platform_device *pdev)
ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
 
err = elm_config(info->elm_dev, BCH4_ECC,
-info->mtd.writesize / nand_chip->ecc.size,
+mtd->writesize / nand_chip->ecc.size,
 nand_chip->ecc.size, nand_chip->ecc.bytes);
if (err < 0)
goto return_error;
@@ -1951,7 +1951,7 @@ static int omap_nand_probe(struct platform_device *pdev)
nand_chip->ecc.write_page   = omap_write_page_bch;
 
err = elm_config(info->elm_dev, BCH8_ECC,
-info->mtd.writesize / nand_chip->ecc.size,
+mtd->writesize / nand_chip->ecc.size,
 nand_chip->ecc.size, nand_chip->ecc.bytes);
if (err < 0)
goto return_error;
@@ -1981,7 +1981,7 @@ static int omap_nand_probe(struct platform_device *pdev)
nand_chip->ecc.write_page   = omap_write_page_bch;
 
err = elm_config(info->elm_dev, BCH16_ECC,
-info->mtd.writesize / nand_chip->ecc.size,
+mtd->writesize / nand_chip->ecc.size,
 nand_chip->ecc.size, nand_chip->ecc.bytes);
if (err < 0)
goto return_error;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 31/58] mtd: nand: nuc900: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/nuc900_nand.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/nuc900_nand.c b/drivers/mtd/nand/nuc900_nand.c
index 65908c0..4dad170 100644
--- a/drivers/mtd/nand/nuc900_nand.c
+++ b/drivers/mtd/nand/nuc900_nand.c
@@ -55,7 +55,6 @@
__raw_writel((val), (dev)->reg + REG_SMADDR)
 
 struct nuc900_nand {
-   struct mtd_info mtd;
struct nand_chip chip;
void __iomem *reg;
struct clk *clk;
@@ -64,7 +63,7 @@ struct nuc900_nand {
 
 static inline struct nuc900_nand *mtd_to_nuc900(struct mtd_info *mtd)
 {
-   return container_of(mtd, struct nuc900_nand, mtd);
+   return container_of(mtd_to_nand(mtd), struct nuc900_nand, chip);
 }
 
 static const struct mtd_partition partitions[] = {
@@ -236,6 +235,7 @@ static int nuc900_nand_probe(struct platform_device *pdev)
 {
struct nuc900_nand *nuc900_nand;
struct nand_chip *chip;
+   struct mtd_info *mtd;
struct resource *res;
 
nuc900_nand = devm_kzalloc(>dev, sizeof(struct nuc900_nand),
@@ -243,9 +243,10 @@ static int nuc900_nand_probe(struct platform_device *pdev)
if (!nuc900_nand)
return -ENOMEM;
chip = &(nuc900_nand->chip);
+   mtd = nand_to_mtd(chip);
 
-   nuc900_nand->mtd.priv   = chip;
-   nuc900_nand->mtd.dev.parent = >dev;
+   mtd->priv   = chip;
+   mtd->dev.parent = >dev;
spin_lock_init(_nand->lock);
 
nuc900_nand->clk = devm_clk_get(>dev, NULL);
@@ -269,11 +270,10 @@ static int nuc900_nand_probe(struct platform_device *pdev)
 
nuc900_nand_enable(nuc900_nand);
 
-   if (nand_scan(&(nuc900_nand->mtd), 1))
+   if (nand_scan(mtd, 1))
return -ENXIO;
 
-   mtd_device_register(&(nuc900_nand->mtd), partitions,
-   ARRAY_SIZE(partitions));
+   mtd_device_register(mtd, partitions, ARRAY_SIZE(partitions));
 
platform_set_drvdata(pdev, nuc900_nand);
 
@@ -284,7 +284,7 @@ static int nuc900_nand_remove(struct platform_device *pdev)
 {
struct nuc900_nand *nuc900_nand = platform_get_drvdata(pdev);
 
-   nand_release(_nand->mtd);
+   nand_release(nand_to_mtd(_nand->chip));
clk_disable(nuc900_nand->clk);
 
return 0;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 21/58] mtd: nand: fsmc: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/fsmc_nand.c | 22 ++
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c
index 499fc59..4c68e7a 100644
--- a/drivers/mtd/nand/fsmc_nand.c
+++ b/drivers/mtd/nand/fsmc_nand.c
@@ -299,7 +299,6 @@ static struct fsmc_eccplace fsmc_ecc4_sp_place = {
  */
 struct fsmc_nand_data {
u32 pid;
-   struct mtd_info mtd;
struct nand_chipnand;
struct mtd_partition*partitions;
unsigned intnr_partitions;
@@ -328,7 +327,7 @@ struct fsmc_nand_data {
 
 static inline struct fsmc_nand_data *mtd_to_fsmc(struct mtd_info *mtd)
 {
-   return container_of(mtd, struct fsmc_nand_data, mtd);
+   return container_of(mtd_to_nand(mtd), struct fsmc_nand_data, nand);
 }
 
 /* Assert CS signal based on chipnr */
@@ -1008,13 +1007,13 @@ static int __init fsmc_nand_probe(struct 
platform_device *pdev)
init_completion(>dma_access_complete);
 
/* Link all private pointers */
-   mtd = >mtd;
+   mtd = nand_to_mtd(>nand);
nand = >nand;
mtd->priv = nand;
nand->priv = host;
nand_set_flash_node(nand, np);
 
-   host->mtd.dev.parent = >dev;
+   mtd->dev.parent = >dev;
nand->IO_ADDR_R = host->data_va;
nand->IO_ADDR_W = host->data_va;
nand->cmd_ctrl = fsmc_cmd_ctrl;
@@ -1077,14 +1076,14 @@ static int __init fsmc_nand_probe(struct 
platform_device *pdev)
/*
 * Scan to find existence of the device
 */
-   if (nand_scan_ident(>mtd, 1, NULL)) {
+   if (nand_scan_ident(mtd, 1, NULL)) {
ret = -ENXIO;
dev_err(>dev, "No NAND Device found!\n");
goto err_scan_ident;
}
 
if (AMBA_REV_BITS(host->pid) >= 8) {
-   switch (host->mtd.oobsize) {
+   switch (mtd->oobsize) {
case 16:
nand->ecc.layout = _ecc4_16_layout;
host->ecc_place = _ecc4_sp_place;
@@ -1135,7 +1134,7 @@ static int __init fsmc_nand_probe(struct platform_device 
*pdev)
 * generated later in nand_bch_init() later.
 */
if (nand->ecc.mode != NAND_ECC_SOFT_BCH) {
-   switch (host->mtd.oobsize) {
+   switch (mtd->oobsize) {
case 16:
nand->ecc.layout = _ecc1_16_layout;
break;
@@ -1156,7 +1155,7 @@ static int __init fsmc_nand_probe(struct platform_device 
*pdev)
}
 
/* Second stage of scan to fill MTD data-structures */
-   if (nand_scan_tail(>mtd)) {
+   if (nand_scan_tail(mtd)) {
ret = -ENXIO;
goto err_probe;
}
@@ -1171,9 +1170,8 @@ static int __init fsmc_nand_probe(struct platform_device 
*pdev)
/*
 * Check for partition info passed
 */
-   host->mtd.name = "nand";
-   ret = mtd_device_register(>mtd, host->partitions,
- host->nr_partitions);
+   mtd->name = "nand";
+   ret = mtd_device_register(mtd, host->partitions, host->nr_partitions);
if (ret)
goto err_probe;
 
@@ -1203,7 +1201,7 @@ static int fsmc_nand_remove(struct platform_device *pdev)
struct fsmc_nand_data *host = platform_get_drvdata(pdev);
 
if (host) {
-   nand_release(>mtd);
+   nand_release(nand_to_mtd(>nand));
 
if (host->mode == USE_DMA_ACCESS) {
dma_release_channel(host->write_dma_chan);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 23/58] mtd: nand: gpmi: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/gpmi-nand/gpmi-lib.c  |  2 +-
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 23 +++
 drivers/mtd/nand/gpmi-nand/gpmi-nand.h |  1 -
 3 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c 
b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
index 43fa16b..0f68a99 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
@@ -919,7 +919,7 @@ static int enable_edo_mode(struct gpmi_nand_data *this, int 
mode)
 {
struct resources  *r = >resources;
struct nand_chip *nand = >nand;
-   struct mtd_info  *mtd = >mtd;
+   struct mtd_info  *mtd = nand_to_mtd(nand);
uint8_t *feature;
unsigned long rate;
int ret;
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c 
b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
index 802adb0..38b07c7 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
@@ -107,7 +107,7 @@ static irqreturn_t bch_irq(int irq, void *cookie)
 static inline int get_ecc_strength(struct gpmi_nand_data *this)
 {
struct bch_geometry *geo = >bch_geometry;
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand);
int ecc_strength;
 
ecc_strength = ((mtd->oobsize - geo->metadata_size) * 8)
@@ -139,8 +139,8 @@ static inline bool gpmi_check_ecc(struct gpmi_nand_data 
*this)
 static bool set_geometry_by_ecc_info(struct gpmi_nand_data *this)
 {
struct bch_geometry *geo = >bch_geometry;
-   struct mtd_info *mtd = >mtd;
-   struct nand_chip *chip = mtd_to_nand(mtd);
+   struct nand_chip *chip = >nand;
+   struct mtd_info *mtd = nand_to_mtd(chip);
struct nand_oobfree *of = gpmi_hw_ecclayout.oobfree;
unsigned int block_mark_bit_offset;
 
@@ -257,7 +257,7 @@ static bool set_geometry_by_ecc_info(struct gpmi_nand_data 
*this)
 static int legacy_set_geometry(struct gpmi_nand_data *this)
 {
struct bch_geometry *geo = >bch_geometry;
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand);
unsigned int metadata_size;
unsigned int status_size;
unsigned int block_mark_bit_offset;
@@ -804,7 +804,7 @@ static int gpmi_alloc_dma_buffer(struct gpmi_nand_data 
*this)
 {
struct bch_geometry *geo = >bch_geometry;
struct device *dev = this->dev;
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(>nand);
 
/* [1] Allocate a command buffer. PAGE_SIZE is enough. */
this->cmd_buffer = kzalloc(PAGE_SIZE, GFP_DMA | GFP_KERNEL);
@@ -1600,8 +1600,8 @@ static int mx23_check_transcription_stamp(struct 
gpmi_nand_data *this)
 {
struct boot_rom_geometry *rom_geo = >rom_geometry;
struct device *dev = this->dev;
-   struct mtd_info *mtd = >mtd;
struct nand_chip *chip = >nand;
+   struct mtd_info *mtd = nand_to_mtd(chip);
unsigned int search_area_size_in_strides;
unsigned int stride;
unsigned int page;
@@ -1655,8 +1655,8 @@ static int mx23_write_transcription_stamp(struct 
gpmi_nand_data *this)
 {
struct device *dev = this->dev;
struct boot_rom_geometry *rom_geo = >rom_geometry;
-   struct mtd_info *mtd = >mtd;
struct nand_chip *chip = >nand;
+   struct mtd_info *mtd = nand_to_mtd(chip);
unsigned int block_size_in_pages;
unsigned int search_area_size_in_strides;
unsigned int search_area_size_in_pages;
@@ -1735,7 +1735,7 @@ static int mx23_boot_init(struct gpmi_nand_data  *this)
 {
struct device *dev = this->dev;
struct nand_chip *chip = >nand;
-   struct mtd_info *mtd = >mtd;
+   struct mtd_info *mtd = nand_to_mtd(chip);
unsigned int block_count;
unsigned int block;
int chipnr;
@@ -1831,14 +1831,13 @@ static int gpmi_s

[PATCH v4 15/58] mtd: nand: denali: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---

Conflicts:
drivers/mtd/nand/denali.c
---
 drivers/mtd/nand/denali.c | 70 ++-
 drivers/mtd/nand/denali.h |  1 -
 2 files changed, 39 insertions(+), 32 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 8feece3..2b66cee 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -75,7 +75,10 @@ MODULE_PARM_DESC(onfi_timing_mode,
  * this macro allows us to convert from an MTD structure to our own
  * device context (denali) structure.
  */
-#define mtd_to_denali(m) container_of(m, struct denali_nand_info, mtd)
+static inline struct denali_nand_info *mtd_to_denali(struct mtd_info *mtd)
+{
+   return container_of(mtd_to_nand(mtd), struct denali_nand_info, nand);
+}
 
 /*
  * These constants are defined by the driver to enable common driver
@@ -986,6 +989,8 @@ static bool handle_ecc(struct denali_nand_info *denali, 
uint8_t *buf,
 * than one NAND connected.
 */
if (err_byte < ECC_SECTOR_SIZE) {
+   struct mtd_info *mtd =
+   nand_to_mtd(>nand);
int offset;
 
offset = (err_sector *
@@ -995,7 +1000,7 @@ static bool handle_ecc(struct denali_nand_info *denali, 
uint8_t *buf,
err_device;
/* correct the ECC error */
buf[offset] ^= err_correction_value;
-   denali->mtd.ecc_stats.corrected++;
+   mtd->ecc_stats.corrected++;
bitflips++;
}
} else {
@@ -1062,7 +1067,7 @@ static int write_page(struct mtd_info *mtd, struct 
nand_chip *chip,
 {
struct denali_nand_info *denali = mtd_to_denali(mtd);
dma_addr_t addr = denali->buf.dma_buf;
-   size_t size = denali->mtd.writesize + denali->mtd.oobsize;
+   size_t size = mtd->writesize + mtd->oobsize;
uint32_t irq_status;
uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP |
INTR_STATUS__PROGRAM_FAIL;
@@ -1160,7 +1165,7 @@ static int denali_read_page(struct mtd_info *mtd, struct 
nand_chip *chip,
struct denali_nand_info *denali = mtd_to_denali(mtd);
 
dma_addr_t addr = denali->buf.dma_buf;
-   size_t size = denali->mtd.writesize + denali->mtd.oobsize;
+   size_t size = mtd->writesize + mtd->oobsize;
 
uint32_t irq_status;
uint32_t irq_mask = INTR_STATUS__ECC_TRANSACTION_DONE |
@@ -1193,14 +1198,14 @@ static int denali_read_page(struct mtd_info *mtd, 
struct nand_chip *chip,
denali_enable_dma(denali, false);
 
if (check_erased_page) {
-   read_oob_data(>mtd, chip->oob_poi, denali->page);
+   read_oob_data(mtd, chip->oob_poi, denali->page);
 
/* check ECC failures that may have occurred on erased pages */
if (check_erased_page) {
-   if (!is_erased(buf, denali->mtd.writesize))
-   denali->mtd.ecc_stats.failed++;
-   if (!is_erased(buf, denali->mtd.oobsize))
-   denali->mtd.ecc_stats.failed++;
+   if (!is_erased(buf, mtd->writesize))
+   mtd->ecc_stats.failed++;
+   if (!is_erased(buf, mtd->oobsize))
+   mtd->ecc_stats.failed++;
}
}
return max_bitflips;
@@ -1211,7 +1216,7 @@ static int denali_read_page_raw(struct mtd_info *mtd, 
struct nand_chip *chip,
 {
   

[PATCH v4 22/58] mtd: nand: gpio: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Changes generated with the following coccinelle script

--->8---
virtual patch

@fix1@
identifier __chipfield, __mtdfield;
type __type;
@@
(
__type {
...
struct nand_chip __chipfield;
...
-   struct mtd_info __mtdfield;
...
};
|
__type {
...
-   struct mtd_info __mtdfield;
...
struct nand_chip __chipfield;
...
};
)

@fix2 depends on fix1@
identifier fix1.__chipfield, fix1.__mtdfield;
identifier __subfield;
type fix1.__type;
__type *__priv;
@@
(
-   __priv->__mtdfield.__subfield
+   nand_to_mtd(&__priv->__chipfield)->__subfield
|
-   &(__priv->__mtdfield)
+   nand_to_mtd(&__priv->__chipfield)
)
--->8---
---
 drivers/mtd/nand/gpio.c | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/gpio.c b/drivers/mtd/nand/gpio.c
index d57a07a..99dd74c 100644
--- a/drivers/mtd/nand/gpio.c
+++ b/drivers/mtd/nand/gpio.c
@@ -35,12 +35,14 @@
 
 struct gpiomtd {
void __iomem*io_sync;
-   struct mtd_info mtd_info;
struct nand_chipnand_chip;
struct gpio_nand_platdata plat;
 };
 
-#define gpio_nand_getpriv(x) container_of(x, struct gpiomtd, mtd_info)
+static inline struct gpiomtd *gpio_nand_getpriv(struct mtd_info *mtd)
+{
+   return container_of(mtd_to_nand(mtd), struct gpiomtd, nand_chip);
+}
 
 
 #ifdef CONFIG_ARM
@@ -195,7 +197,7 @@ static int gpio_nand_remove(struct platform_device *pdev)
 {
struct gpiomtd *gpiomtd = platform_get_drvdata(pdev);
 
-   nand_release(>mtd_info);
+   nand_release(nand_to_mtd(>nand_chip));
 
if (gpio_is_valid(gpiomtd->plat.gpio_nwp))
gpio_set_value(gpiomtd->plat.gpio_nwp, 0);
@@ -208,6 +210,7 @@ static int gpio_nand_probe(struct platform_device *pdev)
 {
struct gpiomtd *gpiomtd;
struct nand_chip *chip;
+   struct mtd_info *mtd;
struct resource *res;
int ret = 0;
 
@@ -274,24 +277,24 @@ static int gpio_nand_probe(struct platform_device *pdev)
chip->chip_delay= gpiomtd->plat.chip_delay;
chip->cmd_ctrl  = gpio_nand_cmd_ctrl;
 
-   gpiomtd->mtd_info.priv  = chip;
-   gpiomtd->mtd_info.dev.parent = >dev;
+   mtd = nand_to_mtd(chip);
+   mtd->priv   = chip;
+   mtd->dev.parent = >dev;
 
platform_set_drvdata(pdev, gpiomtd);
 
if (gpio_is_valid(gpiomtd->plat.gpio_nwp))
gpio_direction_output(gpiomtd->plat.gpio_nwp, 1);
 
-   if (nand_scan(>mtd_info, 1)) {
+   if (nand_scan(mtd, 1)) {
ret = -ENXIO;
goto err_wp;
}
 
if (gpiomtd->plat.adjust_parts)
-   gpiomtd->plat.adjust_parts(>plat,
-  gpiomtd->mtd_info.size);
+   gpiomtd->plat.adjust_parts(>plat, mtd->size);
 
-   ret = mtd_device_register(>mtd_info, gpiomtd->plat.parts,
+   ret = mtd_device_register(mtd, gpiomtd->plat.parts,
  gpiomtd->plat.num_parts);
if (!ret)
return 0;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 17/58] mtd: nand: docg4: use the mtd instance embedded in struct nand_chip

2015-12-10 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Make use of this mtd instance.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/docg4.c | 23 ---
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/nand/docg4.c b/drivers/mtd/nand/docg4.c
index da93d7f..cb6efad 100644
--- a/drivers/mtd/nand/docg4.c
+++ b/drivers/mtd/nand/docg4.c
@@ -1305,14 +1305,14 @@ static int __init probe_docg4(struct platform_device 
*pdev)
return -EIO;
}
 
-   len = sizeof(struct mtd_info) + sizeof(struct nand_chip) +
-   sizeof(struct docg4_priv);
-   mtd = kzalloc(len, GFP_KERNEL);
-   if (mtd == NULL) {
+   len = sizeof(struct nand_chip) + sizeof(struct docg4_priv);
+   nand = kzalloc(len, GFP_KERNEL);
+   if (nand == NULL) {
retval = -ENOMEM;
-   goto fail;
+   goto fail_unmap;
}
-   nand = (struct nand_chip *) (mtd + 1);
+
+   mtd = nand_to_mtd(nand);
doc = (struct docg4_priv *) (nand + 1);
mtd->priv = nand;
nand->priv = doc;
@@ -1354,16 +1354,17 @@ static int __init probe_docg4(struct platform_device 
*pdev)
return 0;
 
  fail:
-   iounmap(virtadr);
-   if (mtd) {
+   if (nand) {
/* re-declarations avoid compiler warning */
-   struct nand_chip *nand = mtd_to_nand(mtd);
struct docg4_priv *doc = nand->priv;
nand_release(mtd); /* deletes partitions and mtd devices */
free_bch(doc->bch);
-   kfree(mtd);
+   kfree(nand);
}
 
+fail_unmap:
+   iounmap(virtadr);
+
return retval;
 }
 
@@ -1372,7 +1373,7 @@ static int __exit cleanup_docg4(struct platform_device 
*pdev)
struct docg4_priv *doc = platform_get_drvdata(pdev);
nand_release(doc->mtd);
free_bch(doc->bch);
-   kfree(doc->mtd);
+   kfree(mtd_to_nand(doc->mtd));
iounmap(doc->virtadr);
return 0;
 }
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 00/25] mtd: nand: refactor the NAND subsystem (part 1)

2015-12-09 Thread Boris Brezillon
Hi Brian,

On Tue, 8 Dec 2015 16:36:24 -0800
Brian Norris <computersforpe...@gmail.com> wrote:

> Hi,
> 
> On Tue, Dec 01, 2015 at 12:02:57PM +0100, Boris Brezillon wrote:
> > Hello,
> > 
> > This huge series aims at clarifying the relationship between the mtd and
> > nand_chip structures and hiding NAND framework internals to NAND
> > controller drivers.
> > 
> > The first part of the series provide an mtd_to_nand() helper to hide the
> > way mtd and nand_chip are linked together.
> > 
> > The second part of the series embeds the mtd structure into the nand_chip
> > one so that NAND controller drivers don't have to bother allocating the
> > MTD device and linking it with the NAND chip.
> > 
> > The last part of the series hides accesses to the chip->priv field behind
> > two helper functions.
> > 
> > This allows removal of some of the boilerplate code done in all NAND
> > controller drivers, but most importantly, it unifies a bit the way NAND
> > chip structures are instantiated (even though we still have two different
> > kinds of drivers: those embedding the nand_chip struct into their private
> > nand chip representation, and those allocating two different structures
> > and linking them together with the chip->priv field).
> > 
> > As said in the title, this refactoring is only the first step. I plan to
> > rework the NAND controller / NAND chip separation for pretty much the same
> > reasons: clarifying the separation between the two concepts, and getting
> > rid of more boilerplate code in NAND controller drivers.
> > 
> > Stay tuned ;-).
> > 
> > Best Regards,
> > 
> > Boris
> > 
> > Changes since v1:
> > - dropped already applied patches
> > - fixed some typos
> > - manually fixed some modifications omitted by the coccinelle scripts
> > - manually reworked modifactions done by coccinelle scripts to improve
> >   readability and fix coding style issues
> > 
> > Boris Brezillon (25):
> >   ARM: nand: make use of mtd_to_nand() where appropriate
> 
> I've sent this (+ the introduction of mtd_to_nand()) in a pull request
> to arm-soc, as well as to l2-mtd.git.
> 
> >   blackfin: nand: make use of mtd_to_nand() where appropriate
> >   cris: nand: make use of mtd_to_nand() where appropriate
> >   mips: nand: make use of mtd_to_nand() where appropriate
> 
> I've based these on v4.4-rc1 and brought them into l2-mtd.git, in case
> any arch/{blackfin,cris,mips}/ people want to pull them in too.
> 
> >   sh: nand: make use of mtd_to_nand() where appropriate
> >   mtd: nand: make use of mtd_to_nand() in NAND core code
> >   mtd: nand: make use of mtd_to_nand() in NAND drivers
> >   staging: mt29f_spinand: make use of mtd_to_nand()
> >   mtd: nand: embed an mtd_info structure into nand_chip
> >   mtd: nand: add nand_to_mtd() helper
> 
> Pulled the rest up to here into l2-mtd.git.

Okay, thanks.

> 
> >   coccinelle: nand: detect and correct drivers embedding an mtd_info
> > object
> 
> I believe Julia had comments on this. That probably would go through the
> kbuild tree in the end anyway (?).

Julia proposed to generate this script using sgen, so I guess this will
come later through a different tree.

> 
> >   mtd: nand: use the mtd instance embedded in struct nand_chip
> 
> There's still at least one problem in this patch (commented on the
> patch). It touches a lot of drivers, so any extra review would be great.

Yep, I think I'll resend the series and split the modification so that
you can pick changes independently (as you suggested a few days ago).

Anyway, reviews from other people would be much appreciated. As I said,
most of changes have been automated with coccinelle, but some of them
have been made manually done, and this is the case for all drivers using
the following pattern:

var = kzalloc(sizeof(struct mtd_info) +
  sizeof(struct nand_chip) + ... ,...);

because I failed to find a pattern common enough to match the cases I
had, and manually fixing them was easier for me...

> 
> >   mtd: nand: update the documentation to reflect framework changes
> >   staging: mt29f_spinand: use the mtd instance embedded in struct
> > nand_chip
> >   cris: nand: use the mtd instance embedded in struct nand_chip
> >   mtd: nand: update mtd_to_nand()
> >   mtd: nand: remove useless mtd->priv = chip assignments
> >   cris: nand: remove useless mtd->priv = chip assignments
> >   staging: mt29f_spinand: remove useless mtd->priv = chip assignment
> >   mtd: nand: simplify nand_dt_init() usage
> >   mtd: nand: kill the

Re: [PATCH v3 bis 12/25] mtd: nand: use the mtd instance embedded in struct nand_chip

2015-12-09 Thread Boris Brezillon
Hi Brian,

On Tue, 8 Dec 2015 16:17:41 -0800
Brian Norris <computersforpe...@gmail.com> wrote:

> 
> > diff --git a/drivers/mtd/nand/cmx270_nand.c b/drivers/mtd/nand/cmx270_nand.c
> > index 43bded6..84d027e 100644
> > --- a/drivers/mtd/nand/cmx270_nand.c
> > +++ b/drivers/mtd/nand/cmx270_nand.c
> > @@ -160,10 +160,8 @@ static int __init cmx270_init(void)
> > gpio_direction_input(GPIO_NAND_RB);
> >  
> > /* Allocate memory for MTD device structure and private data */
> > -   cmx270_nand_mtd = kzalloc(sizeof(struct mtd_info) +
> > - sizeof(struct nand_chip),
> > - GFP_KERNEL);
> > -   if (!cmx270_nand_mtd) {
> > +   this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
> > +   if (!this) {
> > ret = -ENOMEM;
> > goto err_kzalloc;
> > }
> > @@ -175,8 +173,7 @@ static int __init cmx270_init(void)
> > goto err_ioremap;
> > }
> >  
> > -   /* Get pointer to private data */
> > -   this = (struct nand_chip *)(_nand_mtd[1]);
> > +   cmx270_nand_mtd = nand_to_mtd(this);
> 
> So, you make cmx270_nand_mtd no longer kzalloc()'d, but I still see the
> cmx270_init() function end with:
> 
> err_scan:
> iounmap(cmx270_nand_io);
> err_ioremap:
> kfree(cmx270_nand_mtd);  <- *** this! ***

Oh, crap.

> err_kzalloc:
> gpio_free(GPIO_NAND_RB);
> err_gpio_request:
>   gpio_free(GPIO_NAND_CS);
> 
>   return ret;
> 
> }
> 
> I have a feeling there's a failing in your coccinelle script somewhere.

These changes are not automated, because it's kind of hard to address
all the different cases where the following pattern is employed;

var = kzalloc(sizeof(struct mtd_info) +
  sizeof(struct nand_chip) + ..., ...);

Sometime var is an mtd_info pointer, sometime it's a nand_chip pointer
or directly a pointer to the private struct.

I'm pretty sure we could come up with a valid coccinelle script, but
given the number of drivers using this approach I'm not sure it is
worth it...

> 
> Given that I was only through 10 of 49 files changes, I think you might
> need to take a comb over your patch better.

I'll go over those changes one more time, but from my experience, these
kind of bugs are spotted more easily by people who didn't write the
code, so other reviews are more than welcome.

Also, as you suggested, I'll split the changes in several commits (one
per driver) so that you can pick them independently.

Thanks,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [linux-sunxi] [PATCH 01/23] mtd: kill the ecclayout->oobavail field

2015-12-08 Thread Boris Brezillon
Hi Priit,

On Tue, 08 Dec 2015 08:43:05 +0200
Priit Laes <pl...@plaes.org> wrote:

> On Mon, 2015-12-07 at 23:25 +0100, Boris Brezillon wrote:
> > ecclayout->oobavail is just redundant with the mtd->oobavail field.
> > Moreover, it prevents static const definition of ecc layouts since
> > the
> > NAND framework is calculating this value based on the ecclayout-
> > >oobfree
> > field.
> > 
> > Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
> > ---
> >  drivers/mtd/devices/docg3.c   |  5 ++-
> >  drivers/mtd/mtdswap.c | 16 -
> >  drivers/mtd/nand/brcmnand/brcmnand.c  |  3 --
> >  drivers/mtd/nand/docg4.c  |  1 -
> >  drivers/mtd/nand/hisi504_nand.c   |  1 -
> >  drivers/mtd/nand/nand_base.c  | 12 +++
> >  drivers/mtd/onenand/onenand_base.c| 16 -
> >  drivers/mtd/tests/oobtest.c   | 49 +--
> > 
> >  drivers/staging/mt29f_spinand/mt29f_spinand.c |  1 -
> >  fs/jffs2/wbuf.c   |  6 ++--
> >  include/linux/mtd/mtd.h   |  1 -
> >  11 files changed, 48 insertions(+), 63 deletions(-)
> > 
> [..]
> >  
> > diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c
> > b/drivers/mtd/nand/brcmnand/brcmnand.c
> > index 35d78f7..a906ec2 100644
> > --- a/drivers/mtd/nand/brcmnand/brcmnand.c
> > +++ b/drivers/mtd/nand/brcmnand/brcmnand.c
> > @@ -845,9 +845,6 @@ static struct nand_ecclayout 
> > *brcmnand_create_layout(int ecc_level,
> >     break;
> >     }
> >  out:
> > -   /* Sum available OOB */
> > -   for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES_LARGE; i++)
> > -   layout->oobavail += layout->oobfree[i].length;
> >     return layout;
> >  }
> 
> You can get rid of the 'out' label and replace the single goto in this
> function with 'return layout'.

Yep, I'll fix that.

> 
> [...]
> >  
> > diff --git a/drivers/mtd/nand/nand_base.c
> > b/drivers/mtd/nand/nand_base.c
> > index 0748a13..1107f5c1 100644
> > --- a/drivers/mtd/nand/nand_base.c
> > +++ b/drivers/mtd/nand/nand_base.c
> > @@ -2037,7 +2037,7 @@ static int nand_do_read_oob(struct mtd_info
> > *mtd, loff_t from,
> >     stats = mtd->ecc_stats;
> >  
> >     if (ops->mode == MTD_OPS_AUTO_OOB)
> > -   len = chip->ecc.layout->oobavail;
> > +   len = mtd->oobavail;
> >     else
> >     len = mtd->oobsize;
> >  
> > @@ -2728,7 +2728,7 @@ static int nand_do_write_oob(struct mtd_info
> > *mtd, loff_t to,
> >      __func__, (unsigned int)to, (int)ops-
> > >ooblen);
> >  
> >     if (ops->mode == MTD_OPS_AUTO_OOB)
> > -   len = chip->ecc.layout->oobavail;
> > +   len = mtd->oobavail;
> >     else
> >     len = mtd->oobsize;
> >  
> [...]
> > diff --git a/drivers/mtd/onenand/onenand_base.c
> > b/drivers/mtd/onenand/onenand_base.c
> > index 43b3392..d70bbfd 100644
> > --- a/drivers/mtd/onenand/onenand_base.c
> > +++ b/drivers/mtd/onenand/onenand_base.c
> > @@ -1125,7 +1125,7 @@ static int onenand_mlc_read_ops_nolock(struct
> > mtd_info *mtd, loff_t from,
> >     (int)len);
> >  
> >     if (ops->mode == MTD_OPS_AUTO_OOB)
> > -   oobsize = this->ecclayout->oobavail;
> > +   oobsize = mtd->oobavail;
> >     else
> >     oobsize = mtd->oobsize;
> >  
> > @@ -1230,7 +1230,7 @@ static int onenand_read_ops_nolock(struct
> > mtd_info *mtd, loff_t from,
> >     (int)len);
> >  
> >     if (ops->mode == MTD_OPS_AUTO_OOB)
> > -   oobsize = this->ecclayout->oobavail;
> > +   oobsize = mtd->oobavail;
> >     else
> >     oobsize = mtd->oobsize;
> >  
> > @@ -1365,7 +1365,7 @@ static int onenand_read_oob_nolock(struct
> > mtd_info *mtd, loff_t from,
> >     ops->oobretlen = 0;
> >  
> >     if (mode == MTD_OPS_AUTO_OOB)
> > -   oobsize = this->ecclayout->oobavail;
> > +   oobsize = mtd->oobavail;
> >     else
> >     oobsize = mtd->oobsize;
> >  
> > @@ -1887,7 +1887,7 @@ static int onenand_write_ops_nolock(struct
> > mtd_info *mtd, loff_t to,
> >     return 0;
> >  
> >     if (ops->mode == MTD_OPS_AUTO

Re: [linux-sunxi] [PATCH 21/23] staging: mt29f_spinand: switch to mtd_ooblayout_ops

2015-12-08 Thread Boris Brezillon
Hi Julian,

On Tue, 8 Dec 2015 10:59:53 +1100
Julian Calaby <julian.cal...@gmail.com> wrote:

> Hi Boris,
> 
> On Tue, Dec 8, 2015 at 9:26 AM, Boris Brezillon
> <boris.brezil...@free-electrons.com> wrote:
> > Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
> > ---
> >  drivers/staging/mt29f_spinand/mt29f_spinand.c | 44 
> > ---
> >  1 file changed, 26 insertions(+), 18 deletions(-)
> >
> > diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.c 
> > b/drivers/staging/mt29f_spinand/mt29f_spinand.c
> > index cb9d5ab..967d50a 100644
> > --- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
> > +++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
> > @@ -42,23 +42,29 @@ static inline struct spinand_state *mtd_to_state(struct 
> > mtd_info *mtd)
> >  static int enable_hw_ecc;
> >  static int enable_read_hw_ecc;
> >
> > -static struct nand_ecclayout spinand_oob_64 = {
> > -   .eccbytes = 24,
> > -   .eccpos = {
> > -   1, 2, 3, 4, 5, 6,
> > -   17, 18, 19, 20, 21, 22,
> > -   33, 34, 35, 36, 37, 38,
> > -   49, 50, 51, 52, 53, 54, },
> > -   .oobfree = {
> > -   {.offset = 8,
> > -   .length = 8},
> > -   {.offset = 24,
> > -   .length = 8},
> > -   {.offset = 40,
> > -   .length = 8},
> > -   {.offset = 56,
> > -   .length = 8},
> > -   }
> > +static int spinand_oob_64_eccpos(struct mtd_info *mtd, int eccbyte)
> > +{
> > +   if (eccbyte > 23)
> > +   return -ERANGE;
> > +
> > +   return ((eccbyte / 6) * 16) + 1;
> 
> Are you sure this is correct? My reading of this is that we'd get 1
> for eccbytes 0 through 5.
> 
> Would
> 
> ((eccbyte / 6) * 16) + (eccbyte % 6) + 1
> 
> be more correct?

Absolutely. I'll fix that.

Thanks,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 05/23] mtd: nand: jz4770: kill the ->ecc_layout field

2015-12-08 Thread Boris Brezillon
On Tue, 8 Dec 2015 10:30:40 +
Harvey Hunt <harvey.h...@imgtec.com> wrote:

> Hi Boris,
> 
> On 07/12/15 22:26, Boris Brezillon wrote:
> > ->ecc_layout is not used by any board file. Kill this field to avoid any
> > confusion. New boards are encouraged to use the default ECC layout defined
> > in NAND core.
> >
> > Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
> > ---
> >   arch/mips/include/asm/mach-jz4740/jz4740_nand.h | 2 --
> >   drivers/mtd/nand/jz4740_nand.c  | 3 ---
> >   2 files changed, 5 deletions(-)
> >
> > diff --git a/arch/mips/include/asm/mach-jz4740/jz4740_nand.h 
> > b/arch/mips/include/asm/mach-jz4740/jz4740_nand.h
> > index 79cff26..398733e 100644
> > --- a/arch/mips/include/asm/mach-jz4740/jz4740_nand.h
> > +++ b/arch/mips/include/asm/mach-jz4740/jz4740_nand.h
> > @@ -25,8 +25,6 @@ struct jz_nand_platform_data {
> > int num_partitions;
> > struct mtd_partition*partitions;
> >
> > -   struct nand_ecclayout   *ecc_layout;
> > -
> > unsigned char banks[JZ_NAND_NUM_BANKS];
> >
> > void (*ident_callback)(struct platform_device *, struct nand_chip *,
> > diff --git a/drivers/mtd/nand/jz4740_nand.c b/drivers/mtd/nand/jz4740_nand.c
> > index 5a99a93..c4fe446 100644
> > --- a/drivers/mtd/nand/jz4740_nand.c
> > +++ b/drivers/mtd/nand/jz4740_nand.c
> > @@ -446,9 +446,6 @@ static int jz_nand_probe(struct platform_device *pdev)
> > chip->ecc.bytes = 9;
> > chip->ecc.strength  = 4;
> >
> > -   if (pdata)
> > -   chip->ecc.layout = pdata->ecc_layout;
> > -
> > chip->chip_delay = 50;
> > chip->cmd_ctrl = jz_nand_cmd_ctrl;
> > chip->select_chip = jz_nand_select_chip;
> >
> 
> Is there a typo in this commit title? The JZ4740 and JZ4770 have quite 
> different NAND controller interfaces, so I don't think that the JZ4740 
> driver will support the JZ4770.

Yes, it's a typo, I meant jz4740, I'll fix my commit message
accordingly.

Thanks,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 03/23] mtd: nftl: kill unused oobinfo field

2015-12-07 Thread Boris Brezillon
Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 include/linux/mtd/nftl.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/linux/mtd/nftl.h b/include/linux/mtd/nftl.h
index b059629..044daa0 100644
--- a/include/linux/mtd/nftl.h
+++ b/include/linux/mtd/nftl.h
@@ -50,7 +50,6 @@ struct NFTLrecord {
 unsigned int nb_blocks;/* number of physical blocks */
 unsigned int nb_boot_blocks;   /* number of blocks used by the bios */
 struct erase_info instr;
-   struct nand_ecclayout oobinfo;
 };
 
 int NFTL_mount(struct NFTLrecord *s);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 20/23] mtd: onenand: switch to mtd_ooblayout_ops

2015-12-07 Thread Boris Brezillon
Implementing the mtd_ooblayout_ops interface is the new way of exposing
ECC/OOB layout to MTD users. Modify the onenand drivers to switch to this
approach.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/onenand/onenand_base.c | 144 +
 include/linux/mtd/onenand.h|   2 -
 2 files changed, 82 insertions(+), 64 deletions(-)

diff --git a/drivers/mtd/onenand/onenand_base.c 
b/drivers/mtd/onenand/onenand_base.c
index b5937b7..5c7ff9f 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -68,21 +68,29 @@ MODULE_PARM_DESC(otp,   "Corresponding behaviour of 
OneNAND in OTP"
  * flexonenand_oob_128 - oob info for Flex-Onenand with 4KB page
  * For now, we expose only 64 out of 80 ecc bytes
  */
-static struct nand_ecclayout flexonenand_oob_128 = {
-   .eccbytes   = 64,
-   .eccpos = {
-   6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-   22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-   38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-   54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-   70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-   86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-   102, 103, 104, 105
-   },
-   .oobfree= {
-   {2, 4}, {18, 4}, {34, 4}, {50, 4},
-   {66, 4}, {82, 4}, {98, 4}, {114, 4}
-   }
+static int flexonenand_eccpos(struct mtd_info *mtd, int eccbyte)
+{
+   if (eccbyte > 79)
+   return -ERANGE;
+
+   return ((eccbyte / 10) * 16) + 6 + (eccbyte % 10);
+}
+
+static int flexonenand_oobfree(struct mtd_info *mtd, int section,
+  struct nand_oobfree *oobfree)
+{
+   if (section > 7)
+   return -ERANGE;
+
+   oobfree->offset = (section * 16) + 2;
+   oobfree->length = 4;
+
+   return 0;
+}
+
+const struct mtd_ooblayout_ops flexonenand_ooblayout_ops = {
+   .eccpos = flexonenand_eccpos,
+   .oobfree = flexonenand_oobfree,
 };
 
 /*
@@ -91,56 +99,69 @@ static struct nand_ecclayout flexonenand_oob_128 = {
  * Based on specification:
  * 4Gb M-die OneNAND Flash (KFM4G16Q4M, KFN8G16Q4M). Rev. 1.3, Apr. 2010
  *
- * For eccpos we expose only 64 bytes out of 72 (see struct nand_ecclayout)
- *
  * oobfree uses the spare area fields marked as
  * "Managed by internal ECC logic for Logical Sector Number area"
  */
-static struct nand_ecclayout onenand_oob_128 = {
-   .eccbytes   = 64,
-   .eccpos = {
-   7, 8, 9, 10, 11, 12, 13, 14, 15,
-   23, 24, 25, 26, 27, 28, 29, 30, 31,
-   39, 40, 41, 42, 43, 44, 45, 46, 47,
-   55, 56, 57, 58, 59, 60, 61, 62, 63,
-   71, 72, 73, 74, 75, 76, 77, 78, 79,
-   87, 88, 89, 90, 91, 92, 93, 94, 95,
-   103, 104, 105, 106, 107, 108, 109, 110, 111,
-   119
-   },
-   .oobfree= {
-   {2, 3}, {18, 3}, {34, 3}, {50, 3},
-   {66, 3}, {82, 3}, {98, 3}, {114, 3}
-   }
+static int onenand_oob_128_eccpos(struct mtd_info *mtd, int eccbyte)
+{
+   if (eccbyte >= 72)
+   return -ERANGE;
+
+   return ((eccbyte / 9) * 16) + 7 + (eccbyte % 9);
+}
+
+static int onenand_oob_128_oobfree(struct mtd_info *mtd, int section,
+  struct nand_oobfree *oobfree)
+{
+   if (section >= 8)
+   return -ERANGE;
+
+   oobfree->offset = (section * 16) + 2;
+   oobfree->length = 3;
+
+   return 0;
+}
+
+const struct mtd_ooblayout_ops onenand_oob_128_ooblayout_ops = {
+   .eccpos = onenand_oob_128_eccpos,
+   .oobfree = onenand_oob_128_oobfree,
 };
 
 /**
- * onenand_oob_64 - oob info for large (2KB) page
+ * onenand_oob_32_64 - oob info for large (2KB) page
  */
-static struct nand_ecclayout onenand_oob_64 = {
-   .eccbytes   = 20,
-   .eccpos = {
-   8, 9, 10, 11, 12,
-   24, 25, 26, 27, 28,
-   40, 41, 42, 43, 44,
-   56, 57, 58, 59, 60,
-   },
-   .oobfree= {
-   {2, 3}, {14, 2}, {18, 3}, {30, 2},
-   {34, 3}, {46, 2}, {50, 3}, {62, 2}
+static int onenand_oob_32_64_eccpos(struct mtd_info *mtd, int eccbyte)
+{
+   int eccbytes = (mtd->oobsize / 32) * 10;
+
+   if (eccbyte >= eccbytes)
+   return -ERANGE;
+
+   return ((eccbyte / 5) * 16) + 8 + (eccbyte % 5);
+}
+
+static int onenand_oob_32_64_oobfree(struct mtd_info *mtd, int section,
+struct nand_oobfree *oobfree)
+{
+   int sections = (mtd->oobsize / 32) * 2;
+
+   if (section >= sections)
+   return -ERANGE;
+
+   if (section & 1) {
+   oobfree->offset = ((section - 1) * 16) + 14;
+   oobfree->length = 2

[PATCH 21/23] staging: mt29f_spinand: switch to mtd_ooblayout_ops

2015-12-07 Thread Boris Brezillon
Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/staging/mt29f_spinand/mt29f_spinand.c | 44 ---
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.c 
b/drivers/staging/mt29f_spinand/mt29f_spinand.c
index cb9d5ab..967d50a 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
@@ -42,23 +42,29 @@ static inline struct spinand_state *mtd_to_state(struct 
mtd_info *mtd)
 static int enable_hw_ecc;
 static int enable_read_hw_ecc;
 
-static struct nand_ecclayout spinand_oob_64 = {
-   .eccbytes = 24,
-   .eccpos = {
-   1, 2, 3, 4, 5, 6,
-   17, 18, 19, 20, 21, 22,
-   33, 34, 35, 36, 37, 38,
-   49, 50, 51, 52, 53, 54, },
-   .oobfree = {
-   {.offset = 8,
-   .length = 8},
-   {.offset = 24,
-   .length = 8},
-   {.offset = 40,
-   .length = 8},
-   {.offset = 56,
-   .length = 8},
-   }
+static int spinand_oob_64_eccpos(struct mtd_info *mtd, int eccbyte)
+{
+   if (eccbyte > 23)
+   return -ERANGE;
+
+   return ((eccbyte / 6) * 16) + 1;
+}
+
+static int spinand_oob_64_oobfree(struct mtd_info *mtd, int section,
+ struct nand_oobfree *oobfree)
+{
+   if (section > 3)
+   return -ERANGE;
+
+   oobfree->offset = (section * 16) + 8;
+   oobfree->length = 8;
+
+   return 0;
+}
+
+const struct mtd_ooblayout_ops spinand_oob_64_ops = {
+   .eccpos = spinand_oob_64_eccpos,
+   .oobfree = spinand_oob_64_oobfree,
 };
 #endif
 
@@ -883,7 +889,6 @@ static int spinand_probe(struct spi_device *spi_nand)
 
chip->ecc.strength = 1;
chip->ecc.total = chip->ecc.steps * chip->ecc.bytes;
-   chip->ecc.layout = _oob_64;
chip->ecc.read_page = spinand_read_page_hwecc;
chip->ecc.write_page = spinand_write_page_hwecc;
 #else
@@ -911,6 +916,9 @@ static int spinand_probe(struct spi_device *spi_nand)
mtd->priv = chip;
mtd->dev.parent = _nand->dev;
mtd->oobsize = 64;
+#ifdef CONFIG_MTD_SPINAND_ONDIEECC
+   mtd_set_ooblayout(mtd, _oob_64_ops);
+#endif
 
if (nand_scan(mtd, 1))
return -ENXIO;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 23/23] mtd: kill the nand_ecclayout struct

2015-12-07 Thread Boris Brezillon
Now that all mtd drivers have moved to the mtd_ooblayout_ops model we can
safely remove the struct nand_ecclayout definition, and all the remaining
places where it was still used.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/mtdchar.c  | 12 ++--
 drivers/mtd/mtdcore.c  | 44 
 include/linux/mtd/mtd.h| 20 
 include/uapi/mtd/mtd-abi.h |  2 +-
 4 files changed, 7 insertions(+), 71 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index c03b678..322e838 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -465,12 +465,12 @@ static int mtdchar_readoob(struct file *file, struct 
mtd_info *mtd,
 }
 
 /*
- * Copies (and truncates, if necessary) data from the larger struct,
- * nand_ecclayout, to the smaller, deprecated layout struct,
- * nand_ecclayout_user. This is necessary only to support the deprecated
- * API ioctl ECCGETLAYOUT while allowing all new functionality to use
- * nand_ecclayout flexibly (i.e. the struct may change size in new
- * releases without requiring major rewrites).
+ * Copies (and truncates, if necessary) OOB layout information to the
+ * deprecated layout struct, nand_ecclayout_user. This is necessary only to
+ * support the deprecated API ioctl ECCGETLAYOUT while allowing all new
+ * functionality to use mtd_ooblayout_ops flexibly (i.e. mtd_ooblayout_ops
+ * can describe any kind of OOB layout with almost zero overhead from a
+ * memory usage point of view).
  */
 static int shrink_ecclayout(struct mtd_info *mtd,
struct nand_ecclayout_user *to)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index d87f3621..62f83b0 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -833,50 +833,6 @@ void __put_mtd_device(struct mtd_info *mtd)
 }
 EXPORT_SYMBOL_GPL(__put_mtd_device);
 
-static int nand_ecclayout_eccpos(struct mtd_info *mtd, int eccbyte)
-{
-   struct nand_ecclayout *layout = mtd->ecclayout;
-
-   if (!layout)
-   return -ENOTSUPP;
-
-   if (eccbyte >= layout->eccbytes)
-   return -ERANGE;
-
-   return layout->eccpos[eccbyte];
-}
-
-static int nand_ecclayout_oobfree(struct mtd_info *mtd, int section,
- struct nand_oobfree *oobfree)
-{
-   struct nand_ecclayout *layout = mtd->ecclayout;
-
-   if (!layout)
-   return -ENOTSUPP;
-
-   if (section >= MTD_MAX_OOBFREE_ENTRIES_LARGE)
-   return -ERANGE;
-
-   *oobfree = layout->oobfree[section];
-
-   return 0;
-}
-
-static const struct mtd_ooblayout_ops nand_ecclayout_ops = {
-   .eccpos = nand_ecclayout_eccpos,
-   .oobfree = nand_ecclayout_oobfree,
-};
-
-void mtd_set_ecclayout(struct mtd_info *mtd, struct nand_ecclayout *ecclayout)
-{
-   if (!mtd || !ecclayout)
-   return;
-
-   mtd->ecclayout = ecclayout;
-   mtd_set_ooblayout(mtd, _ecclayout_ops);
-}
-EXPORT_SYMBOL_GPL(mtd_set_ecclayout);
-
 /*
  * Erase is an asynchronous operation.  Device drivers are supposed
  * to call instr->callback() whenever the operation completes, even
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 9c3699b..3a4bab7 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -96,21 +96,6 @@ struct mtd_oob_ops {
 
 #define MTD_MAX_OOBFREE_ENTRIES_LARGE  32
 #define MTD_MAX_ECCPOS_ENTRIES_LARGE   640
-/*
- * Internal ECC layout control structure. For historical reasons, there is a
- * similar, smaller struct nand_ecclayout_user (in mtd-abi.h) that is retained
- * for export to user-space via the ECCGETLAYOUT ioctl.
- * nand_ecclayout should be expandable in the future simply by the above 
macros.
- *
- * This structure is now deprecated, you should use struct nand_ecclayout_ops
- * to describe your OOB layout.
- */
-struct nand_ecclayout {
-   __u32 eccbytes;
-   __u32 eccpos[MTD_MAX_ECCPOS_ENTRIES_LARGE];
-   struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES_LARGE];
-};
-
 /**
  * struct mtd_ooblayout_ops - NAND OOB layout operations.
  *
@@ -183,9 +168,6 @@ struct mtd_info {
const char *name;
int index;
 
-   /* [Deprecated] ECC layout structure pointer - read only! */
-   struct nand_ecclayout *ecclayout;
-
/* OOB layout description */
const struct mtd_ooblayout_ops *ooblayout;
 
@@ -279,8 +261,6 @@ static inline void mtd_set_ooblayout(struct mtd_info *mtd,
mtd->ooblayout = ooblayout;
 }
 
-void mtd_set_ecclayout(struct mtd_info *mtd, struct nand_ecclayout *ecclayout);
-
 static inline int mtd_eccpos(struct mtd_info *mtd, int eccbyte)
 {
if (!mtd->ooblayout || !mtd->ooblayout->eccpos)
diff --git a/include/uapi/mtd/mtd-abi.h b/include/uapi/mtd/mtd-abi.h
index 763bb69..0ec1da2 100644
--- a/include/uapi/mtd/mtd-abi.h
+++ b/include/uapi/mtd/mtd-abi.h
@@ -228,7 +22

[PATCH 22/23] mtd: nand: kill layout field

2015-12-07 Thread Boris Brezillon
Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/nand_base.c | 8 
 drivers/mtd/nand/nand_bch.c  | 9 -
 include/linux/mtd/nand.h | 1 -
 3 files changed, 18 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 6440c5d..85deacb 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -4148,13 +4148,6 @@ int nand_scan_tail(struct mtd_info *mtd)
chip->oob_poi = chip->buffers->databuf + mtd->writesize;
 
/*
-* Set the provided ECC layout. If ecc->layout is NULL, the MTD core
-* will just leave mtd->ooblayout to NULL, if it's not NULL, it will
-* set ->ooblayout to the default ecclayout wrapper.
-*/
-   mtd_set_ecclayout(mtd, ecc->layout);
-
-   /*
 * If no default placement scheme is given, select an appropriate one.
 */
if (!mtd->ooblayout && (ecc->mode != NAND_ECC_SOFT_BCH)) {
@@ -4401,7 +4394,6 @@ int nand_scan_tail(struct mtd_info *mtd)
mtd->writebufsize = mtd->writesize;
 
/* propagate ecc info to mtd_info */
-   mtd_set_ecclayout(mtd, ecc->layout);
mtd->ecc_strength = ecc->strength;
mtd->ecc_step_size = ecc->size;
/*
diff --git a/drivers/mtd/nand/nand_bch.c b/drivers/mtd/nand/nand_bch.c
index 2937b49..3b90643 100644
--- a/drivers/mtd/nand/nand_bch.c
+++ b/drivers/mtd/nand/nand_bch.c
@@ -158,15 +158,6 @@ struct nand_bch_control *nand_bch_init(struct mtd_info 
*mtd)
 
eccsteps = mtd->writesize/eccsize;
 
-   /*
-* Rely on the default ecclayout to ooblayout wrapper provided by MTD
-* core if ecc.layout is not NULL.
-* FIXME: this should be removed when all callers have moved to the
-* mtd_ooblayout_ops approach.
-*/
-   if (nand->ecc.layout)
-   mtd_set_ecclayout(mtd, nand->ecc.layout);
-
/* if no ecc placement scheme was provided, build one */
if (!mtd->ooblayout) {
 
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 9ba9daba..f4ba147 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -494,7 +494,6 @@ struct nand_ecc_ctrl {
int strength;
int prepad;
int postpad;
-   struct nand_ecclayout   *layout;
void *priv;
void (*hwctl)(struct mtd_info *mtd, int mode);
int (*calculate)(struct mtd_info *mtd, const uint8_t *dat,
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 18/23] mtd: nand: bch: switch to nand_ecclayout_pos

2015-12-07 Thread Boris Brezillon
Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/nand_bch.c | 33 +++--
 1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/drivers/mtd/nand/nand_bch.c b/drivers/mtd/nand/nand_bch.c
index 9cff544..2937b49 100644
--- a/drivers/mtd/nand/nand_bch.c
+++ b/drivers/mtd/nand/nand_bch.c
@@ -32,13 +32,11 @@
 /**
  * struct nand_bch_control - private NAND BCH control structure
  * @bch:   BCH control structure
- * @ecclayout: private ecc layout for this BCH configuration
  * @errloc:error location array
  * @eccmask:   XOR ecc mask, allows erased pages to be decoded as valid
  */
 struct nand_bch_control {
struct bch_control   *bch;
-   struct nand_ecclayout ecclayout;
unsigned int *errloc;
unsigned char*eccmask;
 };
@@ -124,7 +122,6 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
 {
struct nand_chip *nand = mtd_to_nand(mtd);
unsigned int m, t, eccsteps, i;
-   struct nand_ecclayout *layout = nand->ecc.layout;
struct nand_bch_control *nbc = NULL;
unsigned char *erased_page;
unsigned int eccsize = nand->ecc.size;
@@ -161,8 +158,17 @@ struct nand_bch_control *nand_bch_init(struct mtd_info 
*mtd)
 
eccsteps = mtd->writesize/eccsize;
 
+   /*
+* Rely on the default ecclayout to ooblayout wrapper provided by MTD
+* core if ecc.layout is not NULL.
+* FIXME: this should be removed when all callers have moved to the
+* mtd_ooblayout_ops approach.
+*/
+   if (nand->ecc.layout)
+   mtd_set_ecclayout(mtd, nand->ecc.layout);
+
/* if no ecc placement scheme was provided, build one */
-   if (!layout) {
+   if (!mtd->ooblayout) {
 
/* handle large page devices only */
if (mtd->oobsize < 64) {
@@ -171,24 +177,7 @@ struct nand_bch_control *nand_bch_init(struct mtd_info 
*mtd)
goto fail;
}
 
-   layout = >ecclayout;
-   layout->eccbytes = eccsteps*eccbytes;
-
-   /* reserve 2 bytes for bad block marker */
-   if (layout->eccbytes+2 > mtd->oobsize) {
-   printk(KERN_WARNING "no suitable oob scheme available "
-  "for oobsize %d eccbytes %u\n", mtd->oobsize,
-  eccbytes);
-   goto fail;
-   }
-   /* put ecc bytes at oob tail */
-   for (i = 0; i < layout->eccbytes; i++)
-   layout->eccpos[i] = mtd->oobsize-layout->eccbytes+i;
-
-   layout->oobfree[0].offset = 2;
-   layout->oobfree[0].length = mtd->oobsize-2-layout->eccbytes;
-
-   nand->ecc.layout = layout;
+   mtd_set_ooblayout(mtd, _ooblayout_lp_ops);
}
 
/* sanity checks */
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 15/23] mtd: create an mtd_ooblayout_ops struct to ease ECC layout definition

2015-12-07 Thread Boris Brezillon
ECC layout definitions are currently exposed using the nand_ecclayout
struct which embeds oobfree and eccpos arrays with predefined size.
This approach was acceptable when the NAND were providing relatively small
OOB regions, but MLC and TLC now provide OOB regions of several hundreds
of bytes, which implies a non negigible size penalty for everybody even
those who only need to support legacy NANDs.

Create an mtd_ooblayout_ops interface providing the same functionality
(expose the ECC and OOBFREE layout) without the need for this huge
structure.

The mtd->ecclayout is now deprecated and should be replaced by the
equivalent mtd_ooblayout_ops. In the meantime we provide a wrapper around
the ->ecclayout field to ease migration to this new model.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/mtdchar.c   |  4 ++--
 drivers/mtd/mtdconcat.c |  2 +-
 drivers/mtd/mtdcore.c   | 44 
 drivers/mtd/mtdpart.c   | 22 +++-
 include/linux/mtd/mtd.h | 53 +
 5 files changed, 104 insertions(+), 21 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 66d0898..c03b678 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -862,7 +862,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, 
u_long arg)
{
struct nand_oobinfo oi;
 
-   if (!mtd->ecclayout)
+   if (!mtd->ooblayout)
return -EOPNOTSUPP;
 
ret = get_oobinfo(mtd, );
@@ -956,7 +956,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, 
u_long arg)
{
struct nand_ecclayout_user *usrlay;
 
-   if (!mtd->ecclayout)
+   if (!mtd->ooblayout)
return -EOPNOTSUPP;
 
usrlay = kmalloc(sizeof(*usrlay), GFP_KERNEL);
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 481565e..d573606 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -777,7 +777,7 @@ struct mtd_info *mtd_concat_create(struct mtd_info 
*subdev[],   /* subdevices to c
 
}
 
-   mtd_set_ecclayout(>mtd, subdev[0]->ecclayout);
+   mtd_set_ooblayout(>mtd, subdev[0]->ooblayout);
 
concat->num_subdev = num_devs;
concat->mtd.name = name;
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 62f83b0..d87f3621 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -833,6 +833,50 @@ void __put_mtd_device(struct mtd_info *mtd)
 }
 EXPORT_SYMBOL_GPL(__put_mtd_device);
 
+static int nand_ecclayout_eccpos(struct mtd_info *mtd, int eccbyte)
+{
+   struct nand_ecclayout *layout = mtd->ecclayout;
+
+   if (!layout)
+   return -ENOTSUPP;
+
+   if (eccbyte >= layout->eccbytes)
+   return -ERANGE;
+
+   return layout->eccpos[eccbyte];
+}
+
+static int nand_ecclayout_oobfree(struct mtd_info *mtd, int section,
+ struct nand_oobfree *oobfree)
+{
+   struct nand_ecclayout *layout = mtd->ecclayout;
+
+   if (!layout)
+   return -ENOTSUPP;
+
+   if (section >= MTD_MAX_OOBFREE_ENTRIES_LARGE)
+   return -ERANGE;
+
+   *oobfree = layout->oobfree[section];
+
+   return 0;
+}
+
+static const struct mtd_ooblayout_ops nand_ecclayout_ops = {
+   .eccpos = nand_ecclayout_eccpos,
+   .oobfree = nand_ecclayout_oobfree,
+};
+
+void mtd_set_ecclayout(struct mtd_info *mtd, struct nand_ecclayout *ecclayout)
+{
+   if (!mtd || !ecclayout)
+   return;
+
+   mtd->ecclayout = ecclayout;
+   mtd_set_ooblayout(mtd, _ecclayout_ops);
+}
+EXPORT_SYMBOL_GPL(mtd_set_ecclayout);
+
 /*
  * Erase is an asynchronous operation.  Device drivers are supposed
  * to call instr->callback() whenever the operation completes, even
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 244faa8..2b5c8ca 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -320,6 +320,26 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t 
ofs)
return res;
 }
 
+static int part_ooblayout_eccpos(struct mtd_info *mtd, int eccbyte)
+{
+   struct mtd_part *part = mtd_to_part(mtd);
+
+   return mtd_eccpos(part->master, eccbyte);
+}
+
+static int part_ooblayout_oobfree(struct mtd_info *mtd, int section,
+ struct nand_oobfree *oobfree)
+{
+   struct mtd_part *part = mtd_to_part(mtd);
+
+   return mtd_oobfree(part->master, section, oobfree);
+}
+
+static const struct mtd_ooblayout_ops part_ooblayout_ops = {
+   .eccpos = part_ooblayout_eccpos,
+   .oobfree = part_ooblayout_oobfree,
+};
+
 static inline void free_partition(struct mtd_part *p)
 {
kfree(p->mtd.name);
@@ -536,7 +556,7 @@ static struct mtd_part *a

[PATCH 17/23] mtd: nand: implement the default mtd_ooblayout_ops

2015-12-07 Thread Boris Brezillon
Replace the default nand_ecclayout definitions for large and small page
devices with the equivalent mtd_ooblayout_ops.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/nand_base.c | 138 +++
 include/linux/mtd/nand.h |   3 +
 2 files changed, 90 insertions(+), 51 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 2b334cf..6440c5d 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -48,50 +48,6 @@
 #include 
 #include 
 
-/* Define default oob placement schemes for large and small page devices */
-static struct nand_ecclayout nand_oob_8 = {
-   .eccbytes = 3,
-   .eccpos = {0, 1, 2},
-   .oobfree = {
-   {.offset = 3,
-.length = 2},
-   {.offset = 6,
-.length = 2} }
-};
-
-static struct nand_ecclayout nand_oob_16 = {
-   .eccbytes = 6,
-   .eccpos = {0, 1, 2, 3, 6, 7},
-   .oobfree = {
-   {.offset = 8,
-. length = 8} }
-};
-
-static struct nand_ecclayout nand_oob_64 = {
-   .eccbytes = 24,
-   .eccpos = {
-  40, 41, 42, 43, 44, 45, 46, 47,
-  48, 49, 50, 51, 52, 53, 54, 55,
-  56, 57, 58, 59, 60, 61, 62, 63},
-   .oobfree = {
-   {.offset = 2,
-.length = 38} }
-};
-
-static struct nand_ecclayout nand_oob_128 = {
-   .eccbytes = 48,
-   .eccpos = {
-  80, 81, 82, 83, 84, 85, 86, 87,
-  88, 89, 90, 91, 92, 93, 94, 95,
-  96, 97, 98, 99, 100, 101, 102, 103,
-  104, 105, 106, 107, 108, 109, 110, 111,
-  112, 113, 114, 115, 116, 117, 118, 119,
-  120, 121, 122, 123, 124, 125, 126, 127},
-   .oobfree = {
-   {.offset = 2,
-.length = 78} }
-};
-
 static int nand_get_device(struct mtd_info *mtd, int new_state);
 
 static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
@@ -103,6 +59,83 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t 
to,
  */
 DEFINE_LED_TRIGGER(nand_led_trigger);
 
+/* Define default oob placement schemes for large and small page devices */
+static int nand_ooblayout_eccpos_sp(struct mtd_info *mtd, int eccbyte)
+{
+   struct nand_chip *chip = mtd->priv;
+   struct nand_ecc_ctrl *ecc = >ecc;
+
+   if (eccbyte >= ecc->bytes * ecc->steps)
+   return -ERANGE;
+
+   if (eccbyte < 4)
+   return eccbyte;
+
+   return eccbyte + 2;
+}
+
+static int nand_ooblayout_oobfree_sp(struct mtd_info *mtd, int section,
+struct nand_oobfree *oobfree)
+{
+   if (section > 1)
+   return -ERANGE;
+
+   if (mtd->oobsize == 16) {
+   if (section)
+   return -ERANGE;
+
+   oobfree->length = 8;
+   oobfree->offset = 8;
+   } else {
+   oobfree->length = 2;
+   if (!section)
+   oobfree->offset = 3;
+   else
+   oobfree->offset = 6;
+   }
+
+   return 0;
+}
+
+const struct mtd_ooblayout_ops nand_ooblayout_sp_ops = {
+   .eccpos = nand_ooblayout_eccpos_sp,
+   .oobfree = nand_ooblayout_oobfree_sp,
+};
+EXPORT_SYMBOL_GPL(nand_ooblayout_sp_ops);
+
+static int nand_ooblayout_eccpos_lp(struct mtd_info *mtd, int eccbyte)
+{
+   struct nand_chip *chip = mtd->priv;
+   struct nand_ecc_ctrl *ecc = >ecc;
+   int eccbytes = ecc->bytes * ecc->steps;
+
+   if (eccbyte >= eccbytes)
+   return -ERANGE;
+
+   return mtd->oobsize - eccbytes + eccbyte;
+}
+
+static int nand_ooblayout_oobfree_lp(struct mtd_info *mtd, int section,
+struct nand_oobfree *oobfree)
+{
+   struct nand_chip *chip = mtd->priv;
+   struct nand_ecc_ctrl *ecc = >ecc;
+
+   if (section)
+   return -ERANGE;
+
+   oobfree->length = mtd->oobsize - (ecc->bytes * ecc->steps) - 2;
+   oobfree->offset = 2;
+
+   return 0;
+}
+
+const struct mtd_ooblayout_ops nand_ooblayout_lp_ops = {
+   .eccpos = nand_ooblayout_eccpos_lp,
+   .oobfree = nand_ooblayout_oobfree_lp,
+};
+EXPORT_SYMBOL_GPL(nand_ooblayout_lp_ops);
+
 static int check_offs_len(struct mtd_info *mtd,
loff_t ofs, uint64_t len)
 {
@@ -4115,21 +4148,24 @@ int nand_scan_tail(struct mtd_info *mtd)
chip->oob_poi = chip->buffers->databuf + mtd->writesize;
 
/*
+* Set the provided ECC layout. If ecc->layout is NULL, the MTD core
+* will just leave mtd->ooblayout to NULL, if it's not NULL, it will
+* set ->ooblayout to the default ecclayout wrapper.
+*/
+   mtd_set_ecclayout(mtd,

[PATCH 12/23] mtd: use mtd_eccpos() and mtd_oobfree() where appropriate

2015-12-07 Thread Boris Brezillon
The mtd_eccpos(), mtd_oobfree() and mtd_eccbytes() helper functions have
been added to avoid direct accesses to the ecclayout, and thus allow for
future rework.
Use these helpers in all places where the oobfree[] and eccpos[] arrays
are referenced.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/mtdchar.c  | 79 
 drivers/mtd/mtdswap.c  |  4 +-
 drivers/mtd/nand/atmel_nand.c  | 21 -
 drivers/mtd/nand/fsl_ifc_nand.c|  2 +-
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c |  9 ++--
 drivers/mtd/nand/lpc32xx_slc.c |  4 +-
 drivers/mtd/nand/nand_base.c   | 83 ++
 drivers/mtd/nand/nand_bch.c|  2 +-
 drivers/mtd/nand/omap2.c   | 11 ++---
 drivers/mtd/onenand/onenand_base.c | 61 +
 10 files changed, 163 insertions(+), 113 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 6d19835..66d0898 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -472,31 +472,78 @@ static int mtdchar_readoob(struct file *file, struct 
mtd_info *mtd,
  * nand_ecclayout flexibly (i.e. the struct may change size in new
  * releases without requiring major rewrites).
  */
-static int shrink_ecclayout(const struct nand_ecclayout *from,
-   struct nand_ecclayout_user *to)
+static int shrink_ecclayout(struct mtd_info *mtd,
+   struct nand_ecclayout_user *to)
 {
int i;
 
-   if (!from || !to)
+   if (!mtd || !to)
return -EINVAL;
 
memset(to, 0, sizeof(*to));
 
-   to->eccbytes = min((int)from->eccbytes, MTD_MAX_ECCPOS_ENTRIES);
-   for (i = 0; i < to->eccbytes; i++)
-   to->eccpos[i] = from->eccpos[i];
+   to->eccbytes = 0;
+   for (i = 0; i < MTD_MAX_ECCPOS_ENTRIES; i++) {
+   int pos = mtd_eccpos(mtd, i);
+
+   if (pos < 0)
+   break;
+
+   to->eccpos[i] = pos;
+   to->eccbytes++;
+   }
 
for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES; i++) {
-   if (from->oobfree[i].length == 0 &&
-   from->oobfree[i].offset == 0)
+   mtd_oobfree(mtd, i, >oobfree[i]);
+   if (to->oobfree[i].length == 0 &&
+   to->oobfree[i].offset == 0)
break;
-   to->oobavail += from->oobfree[i].length;
-   to->oobfree[i] = from->oobfree[i];
+   to->oobavail += to->oobfree[i].length;
}
 
return 0;
 }
 
+static int get_oobinfo(struct mtd_info *mtd, struct nand_oobinfo *to)
+{
+   int i;
+
+   if (!mtd || !to)
+   return -EINVAL;
+
+   memset(to, 0, sizeof(*to));
+
+   to->eccbytes = 0;
+   for (i = 0; i < ARRAY_SIZE(to->eccpos); i++) {
+   int pos = mtd_eccpos(mtd, i);
+
+   if (pos < 0)
+   break;
+
+   to->eccpos[i] = pos;
+   to->eccbytes++;
+   }
+
+   if (i == ARRAY_SIZE(to->eccpos))
+   return -EINVAL;
+
+   for (i = 0; i < 8; i++) {
+   struct nand_oobfree oobfree;
+
+   mtd_oobfree(mtd, i, );
+   if (oobfree.length == 0 &&
+   oobfree.offset == 0)
+   break;
+
+   to->oobfree[i][0] = oobfree.offset;
+   to->oobfree[i][1] = oobfree.length;
+   }
+
+   to->useecc = MTD_NANDECC_AUTOPLACE;
+
+   return 0;
+}
+
 static int mtdchar_blkpg_ioctl(struct mtd_info *mtd,
   struct blkpg_ioctl_arg *arg)
 {
@@ -817,14 +864,10 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, 
u_long arg)
 
if (!mtd->ecclayout)
return -EOPNOTSUPP;
-   if (mtd->ecclayout->eccbytes > ARRAY_SIZE(oi.eccpos))
-   return -EINVAL;
 
-   oi.useecc = MTD_NANDECC_AUTOPLACE;
-   memcpy(, mtd->ecclayout->eccpos, sizeof(oi.eccpos));
-   memcpy(, mtd->ecclayout->oobfree,
-  sizeof(oi.oobfree));
-   oi.eccbytes = mtd->ecclayout->eccbytes;
+   ret = get_oobinfo(mtd, );
+   if (ret)
+   return ret;
 
if (copy_to_user(argp, , sizeof(struct nand_oobinfo)))
return -EFAULT;
@@ -920,7 +963,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, 
u_long arg)
if (!usrlay)
return -ENOMEM;
 
-   shrink_ecclayout(mtd->ecclayout, usrlay);
+   shrink_ecclayout(mtd, usrlay);
 
if (copy_to_user(argp, usrlay, sizeof(*

[PATCH 16/23] mtd: docg3: switch to mtd_ooblayout_ops

2015-12-07 Thread Boris Brezillon
Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/devices/docg3.c | 34 +-
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
index 6b516e1..7463dd8 100644
--- a/drivers/mtd/devices/docg3.c
+++ b/drivers/mtd/devices/docg3.c
@@ -73,10 +73,34 @@ MODULE_PARM_DESC(reliable_mode, "Set the docg3 mode 
(0=normal MLC, 1=fast, "
  * @eccpos: ecc positions (byte 7 is Hamming ECC, byte 8-14 are BCH ECC)
  * @oobfree: free pageinfo bytes (byte 0 until byte 6, byte 15
  */
-static struct nand_ecclayout docg3_oobinfo = {
-   .eccbytes = 8,
-   .eccpos = {7, 8, 9, 10, 11, 12, 13, 14},
-   .oobfree = {{0, 7}, {15, 1} },
+static int docg3_eccpos(struct mtd_info *mtd, int eccbyte)
+{
+   if (eccbyte >= 8)
+   return -ERANGE;
+
+   return eccbyte + 7;
+}
+
+static int docg3_oobfree(struct mtd_info *mtd, int section,
+struct nand_oobfree *oobfree)
+{
+   if (section > 1)
+   return -ERANGE;
+
+   if (!section) {
+   oobfree->offset = 0;
+   oobfree->length = 7;
+   } else {
+   oobfree->offset = 15;
+   oobfree->length = 1;
+   }
+
+   return 0;
+}
+
+static const struct nand_ooblayout_ops nand_ooblayout_docg3_ops = {
+   .eccpos = docg3_eccpos,
+   .oobfree = docg3_oobfree,
 };
 
 static inline u8 doc_readb(struct docg3 *docg3, u16 reg)
@@ -1857,7 +1881,7 @@ static int __init doc_set_driver_info(int chip_id, struct 
mtd_info *mtd)
mtd->_read_oob = doc_read_oob;
mtd->_write_oob = doc_write_oob;
mtd->_block_isbad = doc_block_isbad;
-   mtd_set_ecclayout(mtd, _oobinfo);
+   mtd_set_ooblayout_ops(mtd, _ooblayout_docg3_ops);
mtd->oobavail = 8;
mtd->ecc_strength = DOC_ECC_BCH_T;
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 14/23] mtd: use mtd_set_ecclayout() where appropriate

2015-12-07 Thread Boris Brezillon
Use the mtd_set_ecclayout() helper instead of directly assigning the
mtd->ecclayout field.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/devices/docg3.c| 2 +-
 drivers/mtd/mtdconcat.c| 2 +-
 drivers/mtd/mtdpart.c  | 2 +-
 drivers/mtd/nand/nand_base.c   | 2 +-
 drivers/mtd/onenand/onenand_base.c | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
index e7b2e43..6b516e1 100644
--- a/drivers/mtd/devices/docg3.c
+++ b/drivers/mtd/devices/docg3.c
@@ -1857,7 +1857,7 @@ static int __init doc_set_driver_info(int chip_id, struct 
mtd_info *mtd)
mtd->_read_oob = doc_read_oob;
mtd->_write_oob = doc_write_oob;
mtd->_block_isbad = doc_block_isbad;
-   mtd->ecclayout = _oobinfo;
+   mtd_set_ecclayout(mtd, _oobinfo);
mtd->oobavail = 8;
mtd->ecc_strength = DOC_ECC_BCH_T;
 
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 239a8c8..481565e 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -777,7 +777,7 @@ struct mtd_info *mtd_concat_create(struct mtd_info 
*subdev[],   /* subdevices to c
 
}
 
-   concat->mtd.ecclayout = subdev[0]->ecclayout;
+   mtd_set_ecclayout(>mtd, subdev[0]->ecclayout);
 
concat->num_subdev = num_devs;
concat->mtd.name = name;
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index c32b127..244faa8 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -536,7 +536,7 @@ static struct mtd_part *allocate_partition(struct mtd_info 
*master,
part->name);
}
 
-   slave->mtd.ecclayout = master->ecclayout;
+   mtd_set_ecclayout(>mtd, master->ecclayout);
slave->mtd.ecc_step_size = master->ecc_step_size;
slave->mtd.ecc_strength = master->ecc_strength;
slave->mtd.bitflip_threshold = master->bitflip_threshold;
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 30a0721..2b334cf 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -4365,7 +4365,7 @@ int nand_scan_tail(struct mtd_info *mtd)
mtd->writebufsize = mtd->writesize;
 
/* propagate ecc info to mtd_info */
-   mtd->ecclayout = ecc->layout;
+   mtd_set_ecclayout(mtd, ecc->layout);
mtd->ecc_strength = ecc->strength;
mtd->ecc_step_size = ecc->size;
/*
diff --git a/drivers/mtd/onenand/onenand_base.c 
b/drivers/mtd/onenand/onenand_base.c
index 25e6bf2..b5937b7 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -4059,7 +4059,7 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
 mtd_oobfree(mtd, i++, ))
mtd->oobavail += oobfree.length;
 
-   mtd->ecclayout = this->ecclayout;
+   mtd_set_ecclayout(mtd, this->ecclayout);
mtd->ecc_strength = 1;
 
/* Fill in remaining MTD driver data */
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 13/23] mtd: add mtd_set_ecclayout() helper function

2015-12-07 Thread Boris Brezillon
Add an mtd_set_ecclayout() helper function to avoid direct accesses to the
mtd->ecclayout field. This will ease future refactor of ECC layout
definition.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 include/linux/mtd/mtd.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 25e3d0f..80e32fa 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -253,6 +253,12 @@ struct mtd_info {
int usecount;
 };
 
+static inline void mtd_set_ecclayout(struct mtd_info *mtd,
+struct nand_ecclayout *ecclayout)
+{
+   mtd->ecclayout = ecclayout;
+}
+
 static inline int mtd_eccpos(struct mtd_info *mtd, int eccbyte)
 {
if (!mtd->ecclayout)
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 11/23] mtd: add mtd_eccpos(), mtd_oobfree() and mtd_eccbytes() helper functions

2015-12-07 Thread Boris Brezillon
In order to make the ecclayout definition completely dynamic we need to
rework the way these different ECC layouts are defined and iterated.

Create the mtd_eccpos(), mtd_oobfree() and mtd_eccbytes() helpers to hide
ecclayout definition internals to their users.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 include/linux/mtd/mtd.h | 32 
 1 file changed, 32 insertions(+)

diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 9cf13c4..25e3d0f 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -253,6 +253,38 @@ struct mtd_info {
int usecount;
 };
 
+static inline int mtd_eccpos(struct mtd_info *mtd, int eccbyte)
+{
+   if (!mtd->ecclayout)
+   return -ENOTSUPP;
+
+   if (eccbyte >= mtd->ecclayout->eccbytes)
+   return -ERANGE;
+
+   return mtd->ecclayout->eccpos[eccbyte];
+}
+
+static inline int mtd_oobfree(struct mtd_info *mtd, int section,
+ struct nand_oobfree *oobfree)
+{
+   memset(oobfree, 0, sizeof(*oobfree));
+
+   if (!mtd->ecclayout)
+   return -ENOTSUPP;
+
+   if (section >= MTD_MAX_OOBFREE_ENTRIES_LARGE)
+   return -ERANGE;
+
+   *oobfree = mtd->ecclayout->oobfree[section];
+
+   return 0;
+}
+
+static inline int mtd_eccbytes(struct mtd_info *mtd)
+{
+   return mtd->ecclayout ? mtd->ecclayout->eccbytes : 0;
+}
+
 static inline void mtd_set_of_node(struct mtd_info *mtd,
   struct device_node *np)
 {
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 09/23] mtd: nand: vf610: remove useless mtd->ecclayout assignment

2015-12-07 Thread Boris Brezillon
The NAND core layer is already taking care of ecclayout propagation. Remove
this useless assignment.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/vf610_nfc.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index 1c86c6b..0413e24 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -794,8 +794,6 @@ static int vf610_nfc_probe(struct platform_device *pdev)
goto error;
}
 
-   /* propagate ecc.layout to mtd_info */
-   mtd->ecclayout = chip->ecc.layout;
chip->ecc.read_page = vf610_nfc_read_page;
chip->ecc.write_page = vf610_nfc_write_page;
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/23] mtd: nand: simplify nand_bch_init() usage

2015-12-07 Thread Boris Brezillon
nand_bch_init() requires several arguments which could directly be deduced
from the mtd device. Get rid of those useless parameters.

nand_bch_init() is also requiring the caller to provide a proper eccbytes
value, while this value could be deduced from the ecc.size and
ecc.strength value. Fallback to eccbytes calculation when it is set to 0.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/nand_base.c |  6 ++
 drivers/mtd/nand/nand_bch.c  | 27 +--
 drivers/mtd/nand/omap2.c | 28 
 include/linux/mtd/nand_bch.h |  8 ++--
 4 files changed, 33 insertions(+), 36 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 1107f5c1..b99b442 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -4247,10 +4247,8 @@ int nand_scan_tail(struct mtd_info *mtd)
}
 
/* See nand_bch_init() for details. */
-   ecc->bytes = DIV_ROUND_UP(
-   ecc->strength * fls(8 * ecc->size), 8);
-   ecc->priv = nand_bch_init(mtd, ecc->size, ecc->bytes,
-  >layout);
+   ecc->bytes = 0;
+   ecc->priv = nand_bch_init(mtd);
if (!ecc->priv) {
pr_warn("BCH ECC initialization failed!\n");
BUG();
diff --git a/drivers/mtd/nand/nand_bch.c b/drivers/mtd/nand/nand_bch.c
index 3803e0b..3456c20 100644
--- a/drivers/mtd/nand/nand_bch.c
+++ b/drivers/mtd/nand/nand_bch.c
@@ -107,9 +107,6 @@ EXPORT_SYMBOL(nand_bch_correct_data);
 /**
  * nand_bch_init - [NAND Interface] Initialize NAND BCH error correction
  * @mtd:   MTD block structure
- * @eccsize:   ecc block size in bytes
- * @eccbytes:  ecc length in bytes
- * @ecclayout: output default layout
  *
  * Returns:
  *  a pointer to a new NAND BCH control structure, or NULL upon failure
@@ -123,14 +120,21 @@ EXPORT_SYMBOL(nand_bch_correct_data);
  * @eccsize = 512  (thus, m=13 is the smallest integer such that 2^m-1 > 512*8)
  * @eccbytes = 7   (7 bytes are required to store m*t = 13*4 = 52 bits)
  */
-struct nand_bch_control *
-nand_bch_init(struct mtd_info *mtd, unsigned int eccsize, unsigned int 
eccbytes,
- struct nand_ecclayout **ecclayout)
+struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
 {
+   struct nand_chip *nand = mtd_to_nand(mtd);
unsigned int m, t, eccsteps, i;
-   struct nand_ecclayout *layout;
+   struct nand_ecclayout *layout = nand->ecc.layout;
struct nand_bch_control *nbc = NULL;
unsigned char *erased_page;
+   unsigned int eccsize = nand->ecc.size;
+   unsigned int eccbytes = nand->ecc.bytes;
+   unsigned int eccstrength = nand->ecc.strength;
+
+   if (!eccbytes && eccstrength) {
+   eccbytes = DIV_ROUND_UP(eccstrength * fls(8 * eccsize), 8);
+   nand->ecc.bytes = eccbytes;
+   }
 
if (!eccsize || !eccbytes) {
printk(KERN_WARNING "ecc parameters not supplied\n");
@@ -158,7 +162,7 @@ nand_bch_init(struct mtd_info *mtd, unsigned int eccsize, 
unsigned int eccbytes,
eccsteps = mtd->writesize/eccsize;
 
/* if no ecc placement scheme was provided, build one */
-   if (!*ecclayout) {
+   if (!layout) {
 
/* handle large page devices only */
if (mtd->oobsize < 64) {
@@ -184,7 +188,7 @@ nand_bch_init(struct mtd_info *mtd, unsigned int eccsize, 
unsigned int eccbytes,
layout->oobfree[0].offset = 2;
layout->oobfree[0].length = mtd->oobsize-2-layout->eccbytes;
 
-   *ecclayout = layout;
+   nand->ecc.layout = layout;
}
 
/* sanity checks */
@@ -192,7 +196,7 @@ nand_bch_init(struct mtd_info *mtd, unsigned int eccsize, 
unsigned int eccbytes,
printk(KERN_WARNING "eccsize %u is too large\n", eccsize);
goto fail;
}
-   if ((*ecclayout)->eccbytes != (eccsteps*eccbytes)) {
+   if (layout->eccbytes != (eccsteps*eccbytes)) {
printk(KERN_WARNING "invalid ecc layout\n");
goto fail;
}
@@ -216,6 +220,9 @@ nand_bch_init(struct mtd_info *mtd, unsigned int eccsize, 
unsigned int eccbytes,
for (i = 0; i < eccbytes; i++)
nbc->eccmask[i] ^= 0xff;
 
+   if (!eccstrength)
+   nand->ecc.strength = (eccbytes * 8) / fls(8 * eccsize);
+
return nbc;
 fail:
nand_bch_free(nbc);
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index e307576..a2f015d 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -1820,13 +1820,19 @@ static int omap_nand_probe(struct platform

[PATCH 08/23] mtd: nand: lpc32xx_mlc: fix ecc.size

2015-12-07 Thread Boris Brezillon
According to the ECC layout description the actual ecc.size is 512 bytes
and not mtd->writesize.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/lpc32xx_mlc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/lpc32xx_mlc.c b/drivers/mtd/nand/lpc32xx_mlc.c
index 57c4b71..0ee81a0 100644
--- a/drivers/mtd/nand/lpc32xx_mlc.c
+++ b/drivers/mtd/nand/lpc32xx_mlc.c
@@ -751,7 +751,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
}
 
nand_chip->ecc.mode = NAND_ECC_HW;
-   nand_chip->ecc.size = mtd->writesize;
+   nand_chip->ecc.size = 512;
nand_chip->ecc.layout = _nand_oob;
host->mlcsubpages = mtd->writesize / 512;
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/23] mtd: kill the ecclayout->oobavail field

2015-12-07 Thread Boris Brezillon
ecclayout->oobavail is just redundant with the mtd->oobavail field.
Moreover, it prevents static const definition of ecc layouts since the
NAND framework is calculating this value based on the ecclayout->oobfree
field.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/devices/docg3.c   |  5 ++-
 drivers/mtd/mtdswap.c | 16 -
 drivers/mtd/nand/brcmnand/brcmnand.c  |  3 --
 drivers/mtd/nand/docg4.c  |  1 -
 drivers/mtd/nand/hisi504_nand.c   |  1 -
 drivers/mtd/nand/nand_base.c  | 12 +++
 drivers/mtd/onenand/onenand_base.c| 16 -
 drivers/mtd/tests/oobtest.c   | 49 +--
 drivers/staging/mt29f_spinand/mt29f_spinand.c |  1 -
 fs/jffs2/wbuf.c   |  6 ++--
 include/linux/mtd/mtd.h   |  1 -
 11 files changed, 48 insertions(+), 63 deletions(-)

diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
index c3a2695..e7b2e43 100644
--- a/drivers/mtd/devices/docg3.c
+++ b/drivers/mtd/devices/docg3.c
@@ -72,13 +72,11 @@ MODULE_PARM_DESC(reliable_mode, "Set the docg3 mode 
(0=normal MLC, 1=fast, "
  * @eccbytes: 8 bytes are used (1 for Hamming ECC, 7 for BCH ECC)
  * @eccpos: ecc positions (byte 7 is Hamming ECC, byte 8-14 are BCH ECC)
  * @oobfree: free pageinfo bytes (byte 0 until byte 6, byte 15
- * @oobavail: 8 available bytes remaining after ECC toll
  */
 static struct nand_ecclayout docg3_oobinfo = {
.eccbytes = 8,
.eccpos = {7, 8, 9, 10, 11, 12, 13, 14},
.oobfree = {{0, 7}, {15, 1} },
-   .oobavail = 8,
 };
 
 static inline u8 doc_readb(struct docg3 *docg3, u16 reg)
@@ -1438,7 +1436,7 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
oobdelta = mtd->oobsize;
break;
case MTD_OPS_AUTO_OOB:
-   oobdelta = mtd->ecclayout->oobavail;
+   oobdelta = mtd->oobavail;
break;
default:
return -EINVAL;
@@ -1860,6 +1858,7 @@ static int __init doc_set_driver_info(int chip_id, struct 
mtd_info *mtd)
mtd->_write_oob = doc_write_oob;
mtd->_block_isbad = doc_block_isbad;
mtd->ecclayout = _oobinfo;
+   mtd->oobavail = 8;
mtd->ecc_strength = DOC_ECC_BCH_T;
 
return 0;
diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c
index fc8b3d1..d330eb1 100644
--- a/drivers/mtd/mtdswap.c
+++ b/drivers/mtd/mtdswap.c
@@ -346,7 +346,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, 
struct swap_eb *eb)
if (mtd_can_have_bb(d->mtd) && mtd_block_isbad(d->mtd, offset))
return MTDSWAP_SCANNED_BAD;
 
-   ops.ooblen = 2 * d->mtd->ecclayout->oobavail;
+   ops.ooblen = 2 * d->mtd->oobavail;
ops.oobbuf = d->oob_buf;
ops.ooboffs = 0;
ops.datbuf = NULL;
@@ -359,7 +359,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, 
struct swap_eb *eb)
 
data = (struct mtdswap_oobdata *)d->oob_buf;
data2 = (struct mtdswap_oobdata *)
-   (d->oob_buf + d->mtd->ecclayout->oobavail);
+   (d->oob_buf + d->mtd->oobavail);
 
if (le16_to_cpu(data->magic) == MTDSWAP_MAGIC_CLEAN) {
eb->erase_count = le32_to_cpu(data->count);
@@ -933,7 +933,7 @@ static unsigned int mtdswap_eblk_passes(struct mtdswap_dev 
*d,
 
ops.mode = MTD_OPS_AUTO_OOB;
ops.len = mtd->writesize;
-   ops.ooblen = mtd->ecclayout->oobavail;
+   ops.ooblen = mtd->oobavail;
ops.ooboffs = 0;
ops.datbuf = d->page_buf;
ops.oobbuf = d->oob_buf;
@@ -945,7 +945,7 @@ static unsigned int mtdswap_eblk_passes(struct mtdswap_dev 
*d,
for (i = 0; i < mtd_pages; i++) {
patt = mtdswap_test_patt(test + i);
memset(d->page_buf, patt, mtd->writesize);
-   memset(d->oob_buf, patt, mtd->ecclayout->oobavail);
+   memset(d->oob_buf, patt, mtd->oobavail);
ret = mtd_write_oob(mtd, pos, );
if (ret)
goto error;
@@ -964,7 +964,7 @@ static unsigned int mtdswap_eblk_passes(struct mtdswap_dev 
*d,
if (p1[j] != patt)
goto error;
 
-   for (j = 0; j < mtd->ecclayout->oobavail; j++)
+   for (j = 0; j < mtd->oobavail; j++)
if (p2[j] != (unsigned char)patt)
goto error;
 
@@ -1387,7 +1387,7 @@ static int mtdswap_init(struct mtdswap_dev *d, unsigned 
int eblocks,
if (!d->p

[PATCH 06/23] mtd: nand: kill unused ->ecclayout field in platform_nand_chip struct

2015-12-07 Thread Boris Brezillon
This field is not set in any board file and can thus be dropped.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/plat_nand.c | 1 -
 include/linux/mtd/nand.h | 2 --
 2 files changed, 3 deletions(-)

diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index 06ac6c6..71aaa09 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -74,7 +74,6 @@ static int plat_nand_probe(struct platform_device *pdev)
data->chip.bbt_options |= pdata->chip.bbt_options;
 
data->chip.ecc.hwctl = pdata->ctrl.hwcontrol;
-   data->chip.ecc.layout = pdata->chip.ecclayout;
data->chip.ecc.mode = NAND_ECC_SOFT;
 
platform_set_drvdata(pdev, data);
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index fad634e..cbedcb0 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -866,7 +866,6 @@ extern int nand_do_read(struct mtd_info *mtd, loff_t from, 
size_t len,
  * @chip_delay:R/B delay value in us
  * @options:   Option flags, e.g. 16bit buswidth
  * @bbt_options:   BBT option flags, e.g. NAND_BBT_USE_FLASH
- * @ecclayout: ECC layout info structure
  * @part_probe_types:  NULL-terminated array of probe types
  */
 struct platform_nand_chip {
@@ -874,7 +873,6 @@ struct platform_nand_chip {
int chip_offset;
int nr_partitions;
struct mtd_partition *partitions;
-   struct nand_ecclayout *ecclayout;
int chip_delay;
unsigned int options;
unsigned int bbt_options;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 05/23] mtd: nand: jz4770: kill the ->ecc_layout field

2015-12-07 Thread Boris Brezillon
->ecc_layout is not used by any board file. Kill this field to avoid any
confusion. New boards are encouraged to use the default ECC layout defined
in NAND core.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 arch/mips/include/asm/mach-jz4740/jz4740_nand.h | 2 --
 drivers/mtd/nand/jz4740_nand.c  | 3 ---
 2 files changed, 5 deletions(-)

diff --git a/arch/mips/include/asm/mach-jz4740/jz4740_nand.h 
b/arch/mips/include/asm/mach-jz4740/jz4740_nand.h
index 79cff26..398733e 100644
--- a/arch/mips/include/asm/mach-jz4740/jz4740_nand.h
+++ b/arch/mips/include/asm/mach-jz4740/jz4740_nand.h
@@ -25,8 +25,6 @@ struct jz_nand_platform_data {
int num_partitions;
struct mtd_partition*partitions;
 
-   struct nand_ecclayout   *ecc_layout;
-
unsigned char banks[JZ_NAND_NUM_BANKS];
 
void (*ident_callback)(struct platform_device *, struct nand_chip *,
diff --git a/drivers/mtd/nand/jz4740_nand.c b/drivers/mtd/nand/jz4740_nand.c
index 5a99a93..c4fe446 100644
--- a/drivers/mtd/nand/jz4740_nand.c
+++ b/drivers/mtd/nand/jz4740_nand.c
@@ -446,9 +446,6 @@ static int jz_nand_probe(struct platform_device *pdev)
chip->ecc.bytes = 9;
chip->ecc.strength  = 4;
 
-   if (pdata)
-   chip->ecc.layout = pdata->ecc_layout;
-
chip->chip_delay = 50;
chip->cmd_ctrl = jz_nand_cmd_ctrl;
chip->select_chip = jz_nand_select_chip;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 07/23] staging: mt29f_spinand: kill unused ecclayout field

2015-12-07 Thread Boris Brezillon
The spinand_info struct embeds a pointer to an ecclayout definition, but
this field is never used in the mt29f driver.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/staging/mt29f_spinand/mt29f_spinand.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.h 
b/drivers/staging/mt29f_spinand/mt29f_spinand.h
index ae62975..457dc7f 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.h
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.h
@@ -78,7 +78,6 @@
 #define BL_ALL_UNLOCKED0
 
 struct spinand_info {
-   struct nand_ecclayout *ecclayout;
struct spi_device *spi;
void *priv;
 };
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 04/23] mtd: nand: s3c2410: kill the ->ecc_layout field

2015-12-07 Thread Boris Brezillon
The s3c2410 is allowing board data to overload the default ECC layout
defined inside the driver, but this feature is not used by board
specific definitions.
Kill this field so that we can easily move to a model where ecclayout
are dynamically allocated by the NAND controller driver.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 arch/arm/plat-samsung/devs.c   | 9 -
 drivers/mtd/nand/s3c2410.c | 3 ---
 include/linux/platform_data/mtd-nand-s3c2410.h | 1 -
 3 files changed, 13 deletions(-)

diff --git a/arch/arm/plat-samsung/devs.c b/arch/arm/plat-samsung/devs.c
index 8207462..a903ee8 100644
--- a/arch/arm/plat-samsung/devs.c
+++ b/arch/arm/plat-samsung/devs.c
@@ -710,15 +710,6 @@ static int __init s3c_nand_copy_set(struct 
s3c2410_nand_set *set)
return -ENOMEM;
}
 
-   if (set->ecc_layout) {
-   ptr = kmemdup(set->ecc_layout,
- sizeof(struct nand_ecclayout), GFP_KERNEL);
-   set->ecc_layout = ptr;
-
-   if (!ptr)
-   return -ENOMEM;
-   }
-
return 0;
 }
 
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index 05105ca..b569200 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -860,9 +860,6 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info 
*info,
chip->ecc.mode  = NAND_ECC_SOFT;
 #endif
 
-   if (set->ecc_layout != NULL)
-   chip->ecc.layout = set->ecc_layout;
-
if (set->disable_ecc)
chip->ecc.mode  = NAND_ECC_NONE;
 
diff --git a/include/linux/platform_data/mtd-nand-s3c2410.h 
b/include/linux/platform_data/mtd-nand-s3c2410.h
index 36bb921..c55e42ee 100644
--- a/include/linux/platform_data/mtd-nand-s3c2410.h
+++ b/include/linux/platform_data/mtd-nand-s3c2410.h
@@ -40,7 +40,6 @@ struct s3c2410_nand_set {
char*name;
int *nr_map;
struct mtd_partition*partitions;
-   struct nand_ecclayout   *ecc_layout;
 };
 
 struct s3c2410_platform_nand {
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/23] mtd: inftl: kill unused oobinfo field

2015-12-07 Thread Boris Brezillon
Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 include/linux/mtd/inftl.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/linux/mtd/inftl.h b/include/linux/mtd/inftl.h
index 02cd5f9..8255118 100644
--- a/include/linux/mtd/inftl.h
+++ b/include/linux/mtd/inftl.h
@@ -44,7 +44,6 @@ struct INFTLrecord {
unsigned int nb_blocks; /* number of physical blocks */
unsigned int nb_boot_blocks;/* number of blocks used by the bios */
struct erase_info instr;
-   struct nand_ecclayout oobinfo;
 };
 
 int INFTL_mount(struct INFTLrecord *s);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 00/23] mtd: rework ECC layout definition

2015-12-07 Thread Boris Brezillon
Hello,

This patchset aims at getting rid of the nand_ecclayout limitations.
struct nand_ecclayout is defining fixed eccpos and oobfree arrays which
can only be increased by modifying the MTD_MAX_ECCPOS_ENTRIES_LARGE and
MTD_MAX_OOBFREE_ENTRIES_LARGE macros.
This approach forces us to modify the macro values each time we add a
new NAND chip with a bigger OOB area, and increasing these arrays also
penalize all platforms, even those who only support small NAND devices
(with small OOB area).

The idea to overcome this limitation, is to define the ECC/OOB layout
by the mean of two functions: ->eccpos() and ->oobfree(), which will
basically return the same information has those stored in the
nand_ecclayout struct.

Another advantage of this solution is that ECC layouts are usually
following a repetitive pattern (i.e. leave X bytes free and put Y bytes
of ECC per ECC chunk), which allows one to implement the ->eccpos()
and ->oobfree() functions with a simple logic that can be applied
to any size of OOB.

Patches 1 to 10 are just cleanups or trivial fixes that can be taken
independently.

Patch 19 is just an aggregate of several smaller commits (one per
driver), and has been submitted this way to limit the size of the
series. If everybody agrees on this approach, I'll resubmit the series
will those changes separated in different commits (as done here [1]).

Also note that the last two commits are removing the nand_ecclayout
definition, thus preventing any new driver to use this structure.
Of course, this step can be delayed if some of the previous patches
are not accepted.

Best Regards,

Boris

[1]https://github.com/bbrezillon/linux-sunxi/commits/nand/ecclayout2

Boris Brezillon (23):
  mtd: kill the ecclayout->oobavail field
  mtd: inftl: kill unused oobinfo field
  mtd: nftl: kill unused oobinfo field
  mtd: nand: s3c2410: kill the ->ecc_layout field
  mtd: nand: jz4770: kill the ->ecc_layout field
  mtd: nand: kill unused ->ecclayout field in platform_nand_chip struct
  staging: mt29f_spinand: kill unused ecclayout field
  mtd: nand: lpc32xx_mlc: fix ecc.size
  mtd: nand: vf610: remove useless mtd->ecclayout assignment
  mtd: nand: simplify nand_bch_init() usage
  mtd: add mtd_eccpos(), mtd_oobfree() and mtd_eccbytes() helper
functions
  mtd: use mtd_eccpos() and mtd_oobfree() where appropriate
  mtd: add mtd_set_ecclayout() helper function
  mtd: use mtd_set_ecclayout() where appropriate
  mtd: create an mtd_ooblayout_ops struct to ease ECC layout definition
  mtd: docg3: switch to mtd_ooblayout_ops
  mtd: nand: implement the default mtd_ooblayout_ops
  mtd: nand: bch: switch to nand_ecclayout_pos
  mtd: nand: switch all drivers to mtd_ooblayout_ops
  mtd: onenand: switch to mtd_ooblayout_ops
  staging: mt29f_spinand: switch to mtd_ooblayout_ops
  mtd: nand: kill layout field
  mtd: kill the nand_ecclayout struct

 arch/arm/mach-pxa/spitz.c   |  41 +++-
 arch/arm/plat-samsung/devs.c|   9 -
 arch/mips/include/asm/mach-jz4740/jz4740_nand.h |   4 +-
 arch/mips/jz4740/board-qi_lb60.c|  83 ---
 drivers/mtd/devices/docg3.c |  39 +++-
 drivers/mtd/mtdchar.c   |  95 +---
 drivers/mtd/mtdconcat.c |   2 +-
 drivers/mtd/mtdpart.c   |  22 +-
 drivers/mtd/mtdswap.c   |  20 +-
 drivers/mtd/nand/atmel_nand.c   | 100 
 drivers/mtd/nand/bf5xx_nand.c   |  47 ++--
 drivers/mtd/nand/brcmnand/brcmnand.c| 258 -
 drivers/mtd/nand/cafe_nand.c|  42 +++-
 drivers/mtd/nand/davinci_nand.c | 114 -
 drivers/mtd/nand/denali.c   |  48 ++--
 drivers/mtd/nand/diskonchip.c   |  34 ++-
 drivers/mtd/nand/docg4.c|  30 ++-
 drivers/mtd/nand/fsl_elbc_nand.c|  79 ---
 drivers/mtd/nand/fsl_ifc_nand.c | 226 +-
 drivers/mtd/nand/fsmc_nand.c| 294 +++-
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c  |  57 +++--
 drivers/mtd/nand/hisi504_nand.c |  27 ++-
 drivers/mtd/nand/jz4740_nand.c  |   5 +-
 drivers/mtd/nand/lpc32xx_mlc.c  |  51 ++--
 drivers/mtd/nand/lpc32xx_slc.c  |  41 +++-
 drivers/mtd/nand/mxc_nand.c | 206 -
 drivers/mtd/nand/nand_base.c| 229 ++
 drivers/mtd/nand/nand_bch.c |  45 ++--
 drivers/mtd/nand/omap2.c| 219 ++
 drivers/mtd/nand/plat_nand.c|   1 -
 drivers/mtd/nand/pxa3xx_nand.c  | 101 
 drivers/mtd/nand/s3c2410.c  |  31 ++-
 drivers/mtd/nand/sh_flctl.c |  80 +--

[PATCH v3 17/25] mtd: nand: remove useless mtd->priv = chip assignments

2015-12-02 Thread Boris Brezillon
mtd_to_nand() now uses the container_of() approach to transform an
mtd_info pointer into a nand_chip one. Drop useless mtd->priv
assignments from NAND controller drivers.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Patch generated with the following coccinelle script:

---8<
virtual patch

@@
struct mtd_info m;
struct mtd_info *mp;
struct nand_chip *c;
@@
(
-(m).priv = c;
|
-(mp)->priv = c;
|
-(mp)->priv = (void *)c;
)
---8<
---
Changes since v2:
- fixes a compilation warning

 drivers/mtd/nand/ams-delta.c   | 3 ---
 drivers/mtd/nand/atmel_nand.c  | 1 -
 drivers/mtd/nand/au1550nd.c| 1 -
 drivers/mtd/nand/bcm47xxnflash/main.c  | 1 -
 drivers/mtd/nand/bf5xx_nand.c  | 1 -
 drivers/mtd/nand/brcmnand/brcmnand.c   | 1 -
 drivers/mtd/nand/cafe_nand.c   | 1 -
 drivers/mtd/nand/cmx270_nand.c | 1 -
 drivers/mtd/nand/cs553x_nand.c | 1 -
 drivers/mtd/nand/davinci_nand.c| 1 -
 drivers/mtd/nand/denali.c  | 1 -
 drivers/mtd/nand/diskonchip.c  | 1 -
 drivers/mtd/nand/docg4.c   | 1 -
 drivers/mtd/nand/fsl_elbc_nand.c   | 1 -
 drivers/mtd/nand/fsl_ifc_nand.c| 1 -
 drivers/mtd/nand/fsl_upm.c | 1 -
 drivers/mtd/nand/fsmc_nand.c   | 1 -
 drivers/mtd/nand/gpio.c| 1 -
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 1 -
 drivers/mtd/nand/hisi504_nand.c| 1 -
 drivers/mtd/nand/jz4740_nand.c | 1 -
 drivers/mtd/nand/lpc32xx_mlc.c | 1 -
 drivers/mtd/nand/lpc32xx_slc.c | 1 -
 drivers/mtd/nand/mpc5121_nfc.c | 1 -
 drivers/mtd/nand/mxc_nand.c| 1 -
 drivers/mtd/nand/nandsim.c | 1 -
 drivers/mtd/nand/ndfc.c| 1 -
 drivers/mtd/nand/nuc900_nand.c | 1 -
 drivers/mtd/nand/omap2.c   | 1 -
 drivers/mtd/nand/orion_nand.c  | 1 -
 drivers/mtd/nand/pasemi_nand.c | 1 -
 drivers/mtd/nand/plat_nand.c   | 1 -
 drivers/mtd/nand/pxa3xx_nand.c | 1 -
 drivers/mtd/nand/r852.c| 1 -
 drivers/mtd/nand/s3c2410.c | 2 --
 drivers/mtd/nand/sh_flctl.c| 1 -
 drivers/mtd/nand/sharpsl.c | 1 -
 drivers/mtd/nand/socrates_nand.c   | 1 -
 drivers/mtd/nand/sunxi_nand.c  | 1 -
 drivers/mtd/nand/tmio_nand.c   | 1 -
 drivers/mtd/nand/txx9ndfmc.c   | 2 --
 drivers/mtd/nand/vf610_nfc.c   | 1 -
 42 files changed, 46 deletions(-)

diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c
index 0f638c6..1a18938 100644
--- a/drivers/mtd/nand/ams-delta.c
+++ b/drivers/mtd/nand/ams-delta.c
@@ -193,9 +193,6 @@ static int ams_delta_init(struct platform_device *pdev)
ams_delta_mtd = nand_to_mtd(this);
ams_delta_mtd->owner = THIS_MODULE;
 
-   /* Link the private data with the MTD structure */
-   ams_delta_mtd->priv = this;
-
/*
 * Don't try to request the memory region from here,
 * it should have been already requested from the
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 9ba2831..18c4e14 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -2128,7 +2128,6 @@ static int atmel_nand_probe(struct platform_device *pdev)
}
 
nand_chip->priv = host; /* link the private data structures */
-   mtd->priv = nand_chip;
mtd->dev.parent = >dev;
 
/* Set address of NAND IO lines */
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index 280e5b6..341ea49 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -441,7 +441,6 @@ static int au1550nd_probe(struct platform_device *pdev)
 
this = >chip;
mtd = nand_to_mtd(this);
-   mtd->priv = this;
mtd->dev.parent = >dev;
 
/* figure out which CS# r->start belongs to */
diff --git a/drivers/mtd/nand/bcm47xxnflash/main.c 
b/drivers/mtd/nand/bcm47xxnflash/main.c
index 4711ca2b..0f0a798 100644
--- a/drivers/mtd/nand/bcm47xxnflash/main.c
+++ b/drivers/mtd/nand/bcm47xxnflash/main.c
@@ -37,7 +37,6 @@ static int bcm47xxnflash_probe(struct platform_device *pdev)
b47n->nand_chip.priv = b47n;
mtd = nand_to_mtd(>nand_chip);
mtd->dev.parent = >dev;
-   mtd->priv = >nand_chip; /* Required */
b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash);
 
if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
diff --git a/drivers/mtd/nand/bf5xx_nand.c b/drivers/mtd/nand/bf5xx_nand.c
index 928d599..9514e13 100644
--- a/drivers/mtd/nand/bf5xx_nand.c
+++ b/drivers/mtd/nand/bf5xx_nand.c
@@ -782,7 +782,6 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
chip->chip_delay   = 0;
 
/* initialise mtd info data struct */
-   mtd->priv   = chip;
mtd->d

Re: [PATCH v2 17/25] mtd: nand: remove useless mtd->priv = chip assignments

2015-12-02 Thread Boris Brezillon
Hi Brian,

On Tue, 1 Dec 2015 14:17:47 -0800
Brian Norris <computersforpe...@gmail.com> wrote:

> On Tue, Dec 01, 2015 at 12:03:14PM +0100, Boris Brezillon wrote:
> > mtd_to_nand() now uses the container_of() approach to transform an
> > mtd_info pointer into a nand_chip one. Drop useless mtd->priv
> > assignments from NAND controller drivers.
> > 
> > Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
> > ---
> > Patch generated with the following coccinelle script:
> > 
> > ---8<
> > virtual patch
> > 
> > @@
> > struct mtd_info m;
> > struct mtd_info *mp;
> > struct nand_chip *c;
> > @@
> > (
> > -(m).priv = c;
> > |
> > -(mp)->priv = c;
> > |
> > -(mp)->priv = (void *)c;
> > )
> > ---8<
> > ---
> 
> ...
> 
> > diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
> > index 3f29734..ed4184c 100644
> > --- a/drivers/mtd/nand/s3c2410.c
> > +++ b/drivers/mtd/nand/s3c2410.c
> > @@ -834,7 +834,6 @@ static void s3c2410_nand_init_chip(struct 
> > s3c2410_nand_info *info,
> > chip->IO_ADDR_R = chip->IO_ADDR_W;
> >  
> > nmtd->info = info;
> > -   mtd->priv  = chip;
> 
> After this one, we have:
> 
> drivers/mtd/nand/s3c2410.c: In function ‘s3c2410_nand_init_chip’:
> drivers/mtd/nand/s3c2410.c:791:19: warning: unused variable ‘mtd’ 
> [-Wunused-variable]

I fixed all the warnings/errors you pointed in patch 12 and 17 and
resent a v3 only for those patches to avoid annoying all recipients
again. Let me know if you want me to resend the whole patchset.

Best Regards,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 22/25] mtd: nand: add helpers to access ->priv

2015-12-01 Thread Boris Brezillon
Add two helpers to access the field reserved for private controller data.
This makes it clearer what this field is reserved for and ease future
refactoring.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 include/linux/mtd/nand.h | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index f12efe1..4afa263 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -739,6 +739,16 @@ static inline struct mtd_info *nand_to_mtd(struct 
nand_chip *chip)
return >mtd;
 }
 
+static inline void *nand_get_controller_data(struct nand_chip *chip)
+{
+   return chip->priv;
+}
+
+static inline void nand_set_controller_data(struct nand_chip *chip, void *priv)
+{
+   chip->priv = priv;
+}
+
 /*
  * NAND Flash Manufacturer ID Codes
  */
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 20/25] mtd: nand: simplify nand_dt_init() usage

2015-12-01 Thread Boris Brezillon
nand_dt_init() function requires 3 arguments where it actually needs one
(dn and mtd can both be retrieved from chip). Drop these parameters.

Testing for dn != NULL inside nand_dt_init() also helps simplifying the
caller code.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/nand_base.c | 21 +++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 5aec154..ae3fd2a 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3937,11 +3937,17 @@ ident_done:
return type;
 }
 
-static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip,
-   struct device_node *dn)
+static int nand_dt_init(struct nand_chip *chip)
 {
+   struct device_node *dn = nand_get_flash_node(chip);
int ecc_mode, ecc_strength, ecc_step;
 
+   if (!dn)
+   return 0;
+
+   /* MTD can automatically handle DT partitions, etc. */
+   mtd_set_of_node(nand_to_mtd(chip), dn);
+
if (of_get_nand_bus_width(dn) == 16)
chip->options |= NAND_BUSWIDTH_16;
 
@@ -3989,14 +3995,9 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
struct nand_flash_dev *type;
int ret;
 
-   if (nand_get_flash_node(chip)) {
-   /* MTD can automatically handle DT partitions, etc. */
-   mtd_set_of_node(mtd, nand_get_flash_node(chip));
-
-   ret = nand_dt_init(mtd, chip, nand_get_flash_node(chip));
-   if (ret)
-   return ret;
-   }
+   ret = nand_dt_init(chip);
+   if (ret)
+   return ret;
 
/* Set the default functions */
nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 21/25] mtd: nand: kill the chip->flash_node field

2015-12-01 Thread Boris Brezillon
Now that the nand_chip struct directly embeds an mtd_info struct we can
get rid of the ->flash_node field and forward set/get_flash_node requests
to the MTD layer.

As a side effect, we no longer need the mtd_set_of_node() call done in
nand_dt_init().

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/mtd/nand/nand_base.c | 3 ---
 include/linux/mtd/nand.h | 7 ++-
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index ae3fd2a..8bb8ebd6 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3945,9 +3945,6 @@ static int nand_dt_init(struct nand_chip *chip)
if (!dn)
return 0;
 
-   /* MTD can automatically handle DT partitions, etc. */
-   mtd_set_of_node(nand_to_mtd(chip), dn);
-
if (of_get_nand_bus_width(dn) == 16)
chip->options |= NAND_BUSWIDTH_16;
 
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 873646d..f12efe1 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -545,7 +545,6 @@ struct nand_buffers {
  * flash device
  * @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the
  * flash device.
- * @flash_node:[BOARDSPECIFIC] device node describing this 
instance
  * @read_byte: [REPLACEABLE] read one byte from the chip
  * @read_word: [REPLACEABLE] read one word from the chip
  * @write_byte:[REPLACEABLE] write a single byte to the chip 
on the
@@ -645,8 +644,6 @@ struct nand_chip {
void __iomem *IO_ADDR_R;
void __iomem *IO_ADDR_W;
 
-   struct device_node *flash_node;
-
uint8_t (*read_byte)(struct mtd_info *mtd);
u16 (*read_word)(struct mtd_info *mtd);
void (*write_byte)(struct mtd_info *mtd, uint8_t byte);
@@ -724,12 +721,12 @@ struct nand_chip {
 static inline void nand_set_flash_node(struct nand_chip *chip,
   struct device_node *np)
 {
-   chip->flash_node = np;
+   mtd_set_of_node(>mtd, np);
 }
 
 static inline struct device_node *nand_get_flash_node(struct nand_chip *chip)
 {
-   return chip->flash_node;
+   return mtd_get_of_node(>mtd);
 }
 
 static inline struct nand_chip *mtd_to_nand(struct mtd_info *mtd)
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 19/25] staging: mt29f_spinand: remove useless mtd->priv = chip assignment

2015-12-01 Thread Boris Brezillon
mtd_to_nand() now uses the container_of() approach to transform an
mtd_info pointer into a nand_chip one. Drop useless mtd->priv
assignments from NAND controller drivers.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Patch generated with the following coccinelle script:

---8<
virtual patch

@@
struct mtd_info m;
struct mtd_info *mp;
struct nand_chip *c;
@@
(
-(m).priv = c;
|
-(mp)->priv = c;
|
-(mp)->priv = (void *)c;
)
---8<
---
 drivers/staging/mt29f_spinand/mt29f_spinand.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.c 
b/drivers/staging/mt29f_spinand/mt29f_spinand.c
index 8171b74..b7d429d 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
@@ -907,7 +907,6 @@ static int spinand_probe(struct spi_device *spi_nand)
 
dev_set_drvdata(_nand->dev, mtd);
 
-   mtd->priv = chip;
mtd->dev.parent = _nand->dev;
mtd->oobsize = 64;
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 23/25] ARM: make use of nand_set/get_controller_data() helpers

2015-12-01 Thread Boris Brezillon
New helpers have been added to avoid directly accessing chip->field. Use
them where appropriate.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 arch/arm/mach-ixp4xx/ixdp425-setup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-ixp4xx/ixdp425-setup.c 
b/arch/arm/mach-ixp4xx/ixdp425-setup.c
index 333b0f9..508c2d7 100644
--- a/arch/arm/mach-ixp4xx/ixdp425-setup.c
+++ b/arch/arm/mach-ixp4xx/ixdp425-setup.c
@@ -77,7 +77,7 @@ static void
 ixdp425_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
struct nand_chip *this = mtd_to_nand(mtd);
-   int offset = (int)this->priv;
+   int offset = (int)nand_get_controller_data(this);
 
if (ctrl & NAND_CTRL_CHANGE) {
if (ctrl & NAND_NCE) {
@@ -88,7 +88,7 @@ ixdp425_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 
unsigned int ctrl)
 
offset = (ctrl & NAND_CLE) ? IXDP425_NAND_CMD_BYTE : 0;
offset |= (ctrl & NAND_ALE) ? IXDP425_NAND_ADDR_BYTE : 0;
-   this->priv = (void *)offset;
+   nand_set_controller_data(this, (void *)offset);
}
 
if (cmd != NAND_CMD_NONE)
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 15/25] cris: nand: use the mtd instance embedded in struct nand_chip

2015-12-01 Thread Boris Brezillon
struct nand_chip now embeds an mtd device. Patch all drivers to make use
of this mtd instance instead of using the instance embedded in their
private struct or dynamically allocated.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
Most of those changes were generated with the coccinelle script added
in commit c671312 "coccinelle: nand: detect and correct drivers embedding
an mtd_info object"
---
 arch/cris/arch-v32/drivers/mach-a3/nandflash.c | 3 +--
 arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/cris/arch-v32/drivers/mach-a3/nandflash.c 
b/arch/cris/arch-v32/drivers/mach-a3/nandflash.c
index db953cf..ee74e45 100644
--- a/arch/cris/arch-v32/drivers/mach-a3/nandflash.c
+++ b/arch/cris/arch-v32/drivers/mach-a3/nandflash.c
@@ -36,7 +36,6 @@
 #define CE_BIT 12
 
 struct mtd_info_wrapper {
-   struct mtd_info info;
struct nand_chip chip;
 };
 
@@ -148,7 +147,7 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)
 
/* Get pointer to private data */
this = >chip;
-   crisv32_mtd = >info;
+   crisv32_mtd = nand_to_mtd(this);
 
/* Link the private data with the MTD structure */
crisv32_mtd->priv = this;
diff --git a/arch/cris/arch-v32/drivers/mach-fs/nandflash.c 
b/arch/cris/arch-v32/drivers/mach-fs/nandflash.c
index 22a6467..5626297 100644
--- a/arch/cris/arch-v32/drivers/mach-fs/nandflash.c
+++ b/arch/cris/arch-v32/drivers/mach-fs/nandflash.c
@@ -31,7 +31,6 @@
 #define BY_BIT 7
 
 struct mtd_info_wrapper {
-   struct mtd_info info;
struct nand_chip chip;
 };
 
@@ -129,7 +128,7 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)
 
/* Get pointer to private data */
this = >chip;
-   crisv32_mtd = >info;
+   crisv32_mtd = nand_to_mtd(this);
 
pa_oe.oe |= 1 << CE_BIT;
pa_oe.oe |= 1 << ALE_BIT;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 25/25] staging: mt29f_spinand: make use of nand_set/get_controller_data() helpers

2015-12-01 Thread Boris Brezillon
New helpers have been added to avoid directly accessing chip->field. Use
them where appropriate.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 drivers/staging/mt29f_spinand/mt29f_spinand.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.c 
b/drivers/staging/mt29f_spinand/mt29f_spinand.c
index b7d429d..5b3027a 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
@@ -32,7 +32,7 @@
 static inline struct spinand_state *mtd_to_state(struct mtd_info *mtd)
 {
struct nand_chip *chip = mtd_to_nand(mtd);
-   struct spinand_info *info = (struct spinand_info *)chip->priv;
+   struct spinand_info *info = (struct spinand_info 
*)nand_get_controller_data(chip);
struct spinand_state *state = (struct spinand_state *)info->priv;
 
return state;
@@ -633,7 +633,7 @@ static int spinand_read_page_hwecc(struct mtd_info *mtd, 
struct nand_chip *chip,
u8 *p = buf;
int eccsize = chip->ecc.size;
int eccsteps = chip->ecc.steps;
-   struct spinand_info *info = (struct spinand_info *)chip->priv;
+   struct spinand_info *info = (struct spinand_info 
*)nand_get_controller_data(chip);
 
enable_read_hw_ecc = 1;
 
@@ -679,7 +679,7 @@ static u8 spinand_read_byte(struct mtd_info *mtd)
 
 static int spinand_wait(struct mtd_info *mtd, struct nand_chip *chip)
 {
-   struct spinand_info *info = (struct spinand_info *)chip->priv;
+   struct spinand_info *info = (struct spinand_info 
*)nand_get_controller_data(chip);
 
unsigned long timeo = jiffies;
int retval, state = chip->state;
@@ -745,7 +745,7 @@ static void spinand_cmdfunc(struct mtd_info *mtd, unsigned 
int command,
int column, int page)
 {
struct nand_chip *chip = mtd_to_nand(mtd);
-   struct spinand_info *info = (struct spinand_info *)chip->priv;
+   struct spinand_info *info = (struct spinand_info 
*)nand_get_controller_data(chip);
struct spinand_state *state = (struct spinand_state *)info->priv;
 
switch (command) {
@@ -894,7 +894,7 @@ static int spinand_probe(struct spi_device *spi_nand)
 #endif
 
nand_set_flash_node(chip, spi_nand->dev.of_node);
-   chip->priv  = info;
+   nand_set_controller_data(chip, info);
chip->read_buf  = spinand_read_buf;
chip->write_buf = spinand_write_buf;
chip->read_byte = spinand_read_byte;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 01/25] ARM: nand: make use of mtd_to_nand() where appropriate

2015-12-01 Thread Boris Brezillon
mtd_to_nand() was recently introduced to avoid direct accesses to the
mtd->priv field. Update all ARM specific implementations to use this
helper.

Signed-off-by: Boris Brezillon <boris.brezil...@free-electrons.com>
---
 arch/arm/mach-ep93xx/snappercl15.c   | 4 ++--
 arch/arm/mach-ep93xx/ts72xx.c| 4 ++--
 arch/arm/mach-imx/mach-qong.c| 2 +-
 arch/arm/mach-ixp4xx/ixdp425-setup.c | 2 +-
 arch/arm/mach-omap1/board-nand.c | 2 +-
 arch/arm/mach-orion5x/ts78xx-setup.c | 6 +++---
 arch/arm/mach-pxa/balloon3.c | 2 +-
 arch/arm/mach-pxa/em-x270.c  | 2 +-
 arch/arm/mach-pxa/palmtx.c   | 2 +-
 9 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/arch/arm/mach-ep93xx/snappercl15.c 
b/arch/arm/mach-ep93xx/snappercl15.c
index c490426..b2db791 100644
--- a/arch/arm/mach-ep93xx/snappercl15.c
+++ b/arch/arm/mach-ep93xx/snappercl15.c
@@ -49,7 +49,7 @@
 static void snappercl15_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  unsigned int ctrl)
 {
-   struct nand_chip *chip = mtd->priv;
+   struct nand_chip *chip = mtd_to_nand(mtd);
static u16 nand_state = SNAPPERCL15_NAND_WPN;
u16 set;
 
@@ -76,7 +76,7 @@ static void snappercl15_nand_cmd_ctrl(struct mtd_info *mtd, 
int cmd,
 
 static int snappercl15_nand_dev_ready(struct mtd_info *mtd)
 {
-   struct nand_chip *chip = mtd->priv;
+   struct nand_chip *chip = mtd_to_nand(mtd);
 
return !!(__raw_readw(NAND_CTRL_ADDR(chip)) & SNAPPERCL15_NAND_RDY);
 }
diff --git a/arch/arm/mach-ep93xx/ts72xx.c b/arch/arm/mach-ep93xx/ts72xx.c
index 61f4b5d..45b81a2 100644
--- a/arch/arm/mach-ep93xx/ts72xx.c
+++ b/arch/arm/mach-ep93xx/ts72xx.c
@@ -74,7 +74,7 @@ static void __init ts72xx_map_io(void)
 static void ts72xx_nand_hwcontrol(struct mtd_info *mtd,
  int cmd, unsigned int ctrl)
 {
-   struct nand_chip *chip = mtd->priv;
+   struct nand_chip *chip = mtd_to_nand(mtd);
 
if (ctrl & NAND_CTRL_CHANGE) {
void __iomem *addr = chip->IO_ADDR_R;
@@ -96,7 +96,7 @@ static void ts72xx_nand_hwcontrol(struct mtd_info *mtd,
 
 static int ts72xx_nand_device_ready(struct mtd_info *mtd)
 {
-   struct nand_chip *chip = mtd->priv;
+   struct nand_chip *chip = mtd_to_nand(mtd);
void __iomem *addr = chip->IO_ADDR_R;
 
addr += (1 << TS72XX_NAND_BUSY_ADDR_LINE);
diff --git a/arch/arm/mach-imx/mach-qong.c b/arch/arm/mach-imx/mach-qong.c
index a213e7b..5c27646 100644
--- a/arch/arm/mach-imx/mach-qong.c
+++ b/arch/arm/mach-imx/mach-qong.c
@@ -131,7 +131,7 @@ static void qong_init_nor_mtd(void)
  */
 static void qong_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int 
ctrl)
 {
-   struct nand_chip *nand_chip = mtd->priv;
+   struct nand_chip *nand_chip = mtd_to_nand(mtd);
 
if (cmd == NAND_CMD_NONE)
return;
diff --git a/arch/arm/mach-ixp4xx/ixdp425-setup.c 
b/arch/arm/mach-ixp4xx/ixdp425-setup.c
index e7b8bef..333b0f9 100644
--- a/arch/arm/mach-ixp4xx/ixdp425-setup.c
+++ b/arch/arm/mach-ixp4xx/ixdp425-setup.c
@@ -76,7 +76,7 @@ static struct mtd_partition ixdp425_partitions[] = {
 static void
 ixdp425_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-   struct nand_chip *this = mtd->priv;
+   struct nand_chip *this = mtd_to_nand(mtd);
int offset = (int)this->priv;
 
if (ctrl & NAND_CTRL_CHANGE) {
diff --git a/arch/arm/mach-omap1/board-nand.c b/arch/arm/mach-omap1/board-nand.c
index 4d08353..7684f92 100644
--- a/arch/arm/mach-omap1/board-nand.c
+++ b/arch/arm/mach-omap1/board-nand.c
@@ -22,7 +22,7 @@
 
 void omap1_nand_cmd_ctl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-   struct nand_chip *this = mtd->priv;
+   struct nand_chip *this = mtd_to_nand(mtd);
unsigned long mask;
 
if (cmd == NAND_CMD_NONE)
diff --git a/arch/arm/mach-orion5x/ts78xx-setup.c 
b/arch/arm/mach-orion5x/ts78xx-setup.c
index 1b704d3..96cf6b5 100644
--- a/arch/arm/mach-orion5x/ts78xx-setup.c
+++ b/arch/arm/mach-orion5x/ts78xx-setup.c
@@ -176,7 +176,7 @@ static void ts78xx_ts_rtc_unload(void)
 static void ts78xx_ts_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
unsigned int ctrl)
 {
-   struct nand_chip *this = mtd->priv;
+   struct nand_chip *this = mtd_to_nand(mtd);
 
if (ctrl & NAND_CTRL_CHANGE) {
unsigned char bits;
@@ -200,7 +200,7 @@ static int ts78xx_ts_nand_dev_ready(struct mtd_info *mtd)
 static void ts78xx_ts_nand_write_buf(struct mtd_info *mtd,
const uint8_t *buf, int len)
 {
-   struct nand_chip *chip = mtd->priv;
+   struct nand_chip *chip = mtd_to_nand(mtd);
void __iomem *io_base = chip->IO_ADDR_W;
unsigned long off = ((unsigned long)buf & 3);
int sz;
@@ -227,7 +227,7 @@ static void ts78xx_ts_nand_write_buf(struc

[PATCH v2 00/25] mtd: nand: refactor the NAND subsystem (part 1)

2015-12-01 Thread Boris Brezillon
Hello,

This huge series aims at clarifying the relationship between the mtd and
nand_chip structures and hiding NAND framework internals to NAND
controller drivers.

The first part of the series provide an mtd_to_nand() helper to hide the
way mtd and nand_chip are linked together.

The second part of the series embeds the mtd structure into the nand_chip
one so that NAND controller drivers don't have to bother allocating the
MTD device and linking it with the NAND chip.

The last part of the series hides accesses to the chip->priv field behind
two helper functions.

This allows removal of some of the boilerplate code done in all NAND
controller drivers, but most importantly, it unifies a bit the way NAND
chip structures are instantiated (even though we still have two different
kinds of drivers: those embedding the nand_chip struct into their private
nand chip representation, and those allocating two different structures
and linking them together with the chip->priv field).

As said in the title, this refactoring is only the first step. I plan to
rework the NAND controller / NAND chip separation for pretty much the same
reasons: clarifying the separation between the two concepts, and getting
rid of more boilerplate code in NAND controller drivers.

Stay tuned ;-).

Best Regards,

Boris

Changes since v1:
- dropped already applied patches
- fixed some typos
- manually fixed some modifications omitted by the coccinelle scripts
- manually reworked modifactions done by coccinelle scripts to improve
  readability and fix coding style issues

Boris Brezillon (25):
  ARM: nand: make use of mtd_to_nand() where appropriate
  blackfin: nand: make use of mtd_to_nand() where appropriate
  cris: nand: make use of mtd_to_nand() where appropriate
  mips: nand: make use of mtd_to_nand() where appropriate
  sh: nand: make use of mtd_to_nand() where appropriate
  mtd: nand: make use of mtd_to_nand() in NAND core code
  mtd: nand: make use of mtd_to_nand() in NAND drivers
  staging: mt29f_spinand: make use of mtd_to_nand()
  mtd: nand: embed an mtd_info structure into nand_chip
  mtd: nand: add nand_to_mtd() helper
  coccinelle: nand: detect and correct drivers embedding an mtd_info
object
  mtd: nand: use the mtd instance embedded in struct nand_chip
  mtd: nand: update the documentation to reflect framework changes
  staging: mt29f_spinand: use the mtd instance embedded in struct
nand_chip
  cris: nand: use the mtd instance embedded in struct nand_chip
  mtd: nand: update mtd_to_nand()
  mtd: nand: remove useless mtd->priv = chip assignments
  cris: nand: remove useless mtd->priv = chip assignments
  staging: mt29f_spinand: remove useless mtd->priv = chip assignment
  mtd: nand: simplify nand_dt_init() usage
  mtd: nand: kill the chip->flash_node field
  mtd: nand: add helpers to access ->priv
  ARM: make use of nand_set/get_controller_data() helpers
  mtd: nand: make use of nand_set/get_controller_data() helpers
  staging: mt29f_spinand: make use of nand_set/get_controller_data()
helpers

 Documentation/DocBook/mtdnand.tmpl |  31 +++---
 arch/arm/mach-ep93xx/snappercl15.c |   4 +-
 arch/arm/mach-ep93xx/ts72xx.c  |   4 +-
 arch/arm/mach-imx/mach-qong.c  |   2 +-
 arch/arm/mach-ixp4xx/ixdp425-setup.c   |   6 +-
 arch/arm/mach-omap1/board-nand.c   |   2 +-
 arch/arm/mach-orion5x/ts78xx-setup.c   |   6 +-
 arch/arm/mach-pxa/balloon3.c   |   2 +-
 arch/arm/mach-pxa/em-x270.c|   2 +-
 arch/arm/mach-pxa/palmtx.c |   2 +-
 arch/blackfin/mach-bf537/boards/stamp.c|   2 +-
 arch/blackfin/mach-bf561/boards/acvilon.c  |   2 +-
 arch/cris/arch-v32/drivers/mach-a3/nandflash.c |   8 +-
 arch/cris/arch-v32/drivers/mach-fs/nandflash.c |   8 +-
 arch/mips/alchemy/devboards/db1200.c   |   2 +-
 arch/mips/alchemy/devboards/db1300.c   |   2 +-
 arch/mips/alchemy/devboards/db1550.c   |   2 +-
 arch/mips/pnx833x/common/platform.c|   2 +-
 arch/mips/rb532/devices.c  |   2 +-
 arch/sh/boards/mach-migor/setup.c  |   2 +-
 drivers/mtd/nand/ams-delta.c   |  26 ++---
 drivers/mtd/nand/atmel_nand.c  | 118 ++--
 drivers/mtd/nand/au1550nd.c|  40 +++
 drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h |   1 -
 drivers/mtd/nand/bcm47xxnflash/main.c  |   9 +-
 drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c   |  34 +++---
 drivers/mtd/nand/bf5xx_nand.c  |  25 ++---
 drivers/mtd/nand/brcmnand/brcmnand.c   |  54 +
 drivers/mtd/nand/cafe_nand.c   |  51 +
 drivers/mtd/nand/cmx270_nand.c |  20 ++--
 drivers/mtd/nand/cs553x_nand.c |  30 +++--
 drivers/mtd/nand/davinci_nand.c|  37 ---
 drivers/mtd/nand/denali.c  |  67

  1   2   >