aboutsummaryrefslogtreecommitdiff
path: root/drivers/mtd/nand/sunxi_nand.c
AgeCommit message (Collapse)Author
2016-03-04mtd: nand: sunxi: remove direct mtd->priv accessesBoris BREZILLON
mtd->priv is no longer pointing to the struct nand_chip it is attached to. Replace those accesses by mtd_to_nand() calls. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Fixes: 4be4e03efc7f ("mtd: nand: sunxi: add randomizer support") Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2016-01-23mtd: nand: sunxi: use mtd_div_by_ws() helperBrian Norris
Suggested-by: Richard Weinberger <richard@nod.at> Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
2016-01-22mtd: nand: sunxi: add randomizer supportBoris BREZILLON
Add support for the randomizer engine available in Allwinner's NFC IP. Randomization is useful to support modern NAND chips which are sensitive to repeated patterns. On such NANDs you might experience an unexpectedly high number of bitflips when you repeat the same pattern all over a given NAND block. Randomizing input data mitigate this problem by avoiding such repeated patterns. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-12-18mtd: nand: remove useless mtd->priv = chip assignmentsBoris 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.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-12-18mtd: nand: sunxi: use the mtd instance embedded in struct nand_chipBoris BREZILLON
struct nand_chip now embeds an mtd device. Make use of this mtd instance. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-12-08mtd: nand: make use of mtd_to_nand() in NAND driversBoris BREZILLON
mtd_to_nand() was recently introduced to avoid direct accesses to the mtd->priv field. Update all NAND drivers to use it. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-11-30mtd: nand: sunxi: add missing of_node_putJulia Lawall
for_each_child_of_node performs an of_node_get on each iteration, so a break out of the loop requires an of_node_put. A simplified version of the semantic patch that fixes this problem is as follows (http://coccinelle.lip6.fr): // <smpl> @@ expression root,e; local idexpression child; @@ for_each_child_of_node(root, child) { ... when != of_node_put(child) when != e = child ( return child; | + of_node_put(child); ? return ...; ) ... } // </smpl> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Acked-by: Chen-Yu Tsai <wens@csie.org> Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-11-11mtd: nand: drop unnecessary partition parser dataBrian Norris
All of these drivers set up a parser data struct just to communicate DT partition data. This field has been deprecated and is instead supported by telling nand_scan_ident() about the 'flash_node'. This patch: * sets chip->flash_node for those drivers that didn't already (but used OF partitioning) * drops the parser data * switches to the simpler mtd_device_register() where possible, now that we've eliminated one of the auxiliary parameters Now that we've assigned chip->flash_node for these drivers, we can probably rely on nand_dt_init() to do more of the DT parsing for us, but for now, I don't want to fiddle with each of these drivers. The parsing is done in duplicate for now on some drivers. I don't think this should break things. (Famous last words.) (Rolled in some changes by Boris Brezillon) Signed-off-by: Brian Norris <computersforpeace@gmail.com> Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
2015-11-11mtd: nand: convert to nand_set_flash_node()Brian Norris
Used semantic patch with 'make coccicheck MODE=patch COCCI=script.cocci': ---8<---- virtual patch @@ struct nand_chip *c; struct device_node *d; @@ -(c)->flash_node = (d) +nand_set_flash_node(c, d) ---8<---- Signed-off-by: Brian Norris <computersforpeace@gmail.com> Reviewed-by: Marek Vasut <marex@denx.de> Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
2015-11-02mtd: nand: sunxi: avoid retrieving data before ECC passBoris BREZILLON
The in-band data are copied twice: before ECC correction and after the ECC engine has fixed all the fixable bitflips. Drop the useless memcpy_fromio operation by passing a NULL pointer when calling sunxi_nfc_read_buf(). Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-11-02mtd: nand: sunxi: fix sunxi_nfc_hw_ecc_read/write_chunk()Boris BREZILLON
The sunxi_nfc_hw_ecc_read/write_chunk() functions try to avoid changing the column address if unnecessary, but the logic to determine whether it's necessary or not is currently wrong: it adds the ecc->bytes value to the current offset where it should actually add ecc->size. Fixes: 913821bdd211 ("mtd: nand: sunxi: introduce sunxi_nfc_hw_ecc_read/write_chunk()") Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-10-13mtd: nand: pass page number to ecc->write_xxx() methodsBoris BREZILLON
The ->read_xxx() methods are all passed the page number the NAND controller is supposed to read, but ->write_xxx() do not have such a parameter. This is a problem if we want to properly implement data scrambling/randomization in order to mitigate MLC sensibility to repeated pattern: to prevent bitflips in adjacent pages in the same block we need to avoid repeating the same pattern at the same offset in those pages, hence the randomizer/scrambler engine need to be passed the page value in order to adapt its seed accordingly. Moreover, adding the page parameter to the ->write_xxx() methods add some consistency to the current API. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> CC: Josh Wu <josh.wu@atmel.com> CC: Ezequiel Garcia <ezequiel.garcia@free-electrons.com> CC: Maxime Ripard <maxime.ripard@free-electrons.com> CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org> CC: Huang Shijie <shijie.huang@arm.com> CC: Stefan Agner <stefan@agner.ch> CC: devel@driverdev.osuosl.org CC: linux-arm-kernel@lists.infradead.org CC: linux-kernel@vger.kernel.org Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-10-13mtd: nand: sunxi_nand: drop owner assignmentFrans Klaver
Owner is automatically set by mtdcore. Make use of that. Signed-off-by: Frans Klaver <fransklaver@gmail.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-10-02mtd: nand: sunxi: fix bitflips in erased pagesBoris BREZILLON
Use the nand_check_erased_ecc_chunk() function to test if the ECC error was triggered by an erased page containing a few bitflips. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-10-02mtd: nand: sunxi: replace the NFC_BUF_TO_USER_DATA() macro by an inline functionBoris BREZILLON
sunxi_nfc_user_data_to_buf() is exposed as an inline function, replace the NFC_BUF_TO_USER_DATA() macro by an inline function to be consistent. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-10-02mtd: nand: sunxi: retrieve corrected OOB bytesBoris BREZILLON
The ECC engine is protecting a few OOB bytes. Retrieve them from the USER_DATA register instead of reading them in raw mode (ie without the ECC protection). Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-10-02mtd: nand: sunxi: factorize extra OOB bytes handlingBoris BREZILLON
Add helper functions to factorize the code dealing extra OOB bytes in the normal and syndrome ECC implementations. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-10-02mtd: nand: sunxi: make use of sunxi_nfc_hw_ecc_read/write_chunk()Boris BREZILLON
The sunxi_nfc_hw_ecc_read/write_chunk() functions have been created to factorize the code in the normal and syndrome ECC implementation. Make use of them where appropriate. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-10-02mtd: nand: sunxi: introduce sunxi_nfc_hw_ecc_read/write_chunk()Boris BREZILLON
The logic behind normal and syndrome ECC handling is pretty much the same, the only difference is the ECC bytes placement. Create two functions to read/write ECC chunks. Those functions will later be used by the sunxi_nfc_hw_ecc_read/write_page() and sunxi_nfc_hw_syndrome_ecc_read/write_page() functions. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-10-02mtd: nand: sunxi: create sunxi_nfc_hw_ecc_enable()/disable() functionsBoris BREZILLON
The code used to enable/disable the hardware ECC engine is repeated in a lot of places. Create two functions to avoid code duplication. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-09-30mtd: nand: sunxi: rework macrosBoris BREZILLON
Suffix mask macros with _MSK and add new helper macros to avoid manually shifting values. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-09-30Merge MTD 4.3-rc updates into -nextBrian Norris
2015-09-21mtd: nand: sunxi: fix sunxi_nand_chips_cleanup()Boris BREZILLON
The sunxi_nand_chips_cleanup() function is missing a call to list_del() which generates a double free error. Reported-by: Priit Laes <plaes@plaes.org> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Cc: <stable@vger.kernel.org> # 3.19+ Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Tested-by: Priit Laes <plaes@plaes.org> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-09-21mtd: nand: sunxi: fix OOB handling in ->write_xxx() functionsBoris BREZILLON
The USER_DATA register cannot be accessed using byte accessors on A13 SoCs, thus triggering a bug when using memcpy_toio on this register. Declare an helper macros to convert an OOB buffer into a suitable USER_DATA value and vice-versa. This patch also fixes an error in the oob_required logic (some OOB data are not written even if the user required it) by removing the oob_required condition, which is perfectly valid since the core already fill ->oob_poi with FFs when oob_required is false. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Cc: <stable@vger.kernel.org> # 3.19+ Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-09-11mtd: nand: sunxi: rely on nand_dt_init initializationBoris BREZILLON
nand_dt_init(), called from nand_scan_ident(), is already parsing the generic MTD/NAND DT properties, and initializing the nand_chip struct accordingly. Rely on this initialization instead of manually parsing those properties. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> [Brian: rename 'np' -> 'flash_node' to accomodate for prior rename patch] Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-09-09mtd: sunxi_nand: Select the chip in sunxi_nand_chip_init_timings()Stefan Roese
nand_scan_ident() leaves the chip deselected. So just issuing some commands from the sunxi driver does not work. We need to select the chip before writing the commands to the NAND device. This patch takes care of this. Set the new timing on all dies implemented as suggested by Boris. This was detected on the in-circuit ICnova-A20 SoM equipped with the Micron MT29F32G08CBACAWP (4GiB) ONFI NAND device. Signed-off-by: Stefan Roese <sr@denx.de> Cc: Hans de Goede <hdegoede@redhat.com> Cc: Maxime Ripard <maxime.ripard@free-electrons.com> Cc: Roy Spliet <r.spliet@ultimaker.com> Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com> [Brian: fixup whitespace] Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-07-20mtd: nand: sunxi: Set serial access mode correctlyRoy Spliet
Replaces the hard coded "always use EDO" policy with that prescribed by the ONFI 3.1 specification that EDO mode should always be used if tRC is below 30ns. Signed-off-by: Roy Spliet <r.spliet@ultimaker.com> Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-07-20mtd: nand: sunxi: Replace failsafe timing cfg with calculated valueRoy Spliet
The TIMING_CFG register was previously statically set to a magic value (extracted from Allwinner's BSP) when initializing the NAND controller. Now that we have more details about the TIMING_CFG register layout (extracted from the A83 user manual) we can dynamically calculate the appropriate value for each NAND chip and set it when selecting the chip. Signed-off-by: Roy Spliet <r.spliet@ultimaker.com> Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-02-01mtd: nand: Request strength instead of bytes for soft BCHAaron Sierra
Previously, we requested that drivers pass ecc.size and ecc.bytes when using NAND_ECC_SOFT_BCH. However, a driver is likely to only know the ECC strength required for its NAND, so each driver would need to perform a strength-to-bytes calculation. Avoid duplicating this calculation in each driver by asking drivers to pass ecc.size and ecc.strength so that the strength-to-bytes calculation need only be implemented once. This reverts/generalizes this commit: mtd: nand: Base BCH ECC bytes on required strength Signed-off-by: Aaron Sierra <asierra@xes-inc.com> Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-10-29mtd: nand: add sunxi NAND flash controller supportBoris BREZILLON
Add support for the sunxi NAND Flash Controller (NFC). Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> [Brian: tweaked to fix ecc->steps issue] Signed-off-by: Brian Norris <computersforpeace@gmail.com>