mtd: nand: add a shorthand to generate nand_ecc_caps structure

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Thu Jul 13 10:59:19 PDT 2017


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=a03c60178c181767ecfb26fb311a88742d228118
Commit:     a03c60178c181767ecfb26fb311a88742d228118
Parent:     2c8f8afa7f92acb07641bf95b940d384ed1d0294
Author:     Masahiro Yamada <yamada.masahiro at socionext.com>
AuthorDate: Wed Jun 7 20:52:11 2017 +0900
Committer:  Boris Brezillon <boris.brezillon at free-electrons.com>
CommitDate: Sat Jun 10 13:40:10 2017 +0200

    mtd: nand: add a shorthand to generate nand_ecc_caps structure
    
    struct nand_ecc_caps was designed as flexible as possible to support
    multiple stepsizes (like sunxi_nand.c).
    
    So, we need to write multiple arrays even for the simplest case.
    I guess many controllers support a single stepsize, so here is a
    shorthand macro for the case.
    
    It allows to describe like ...
    
    NAND_ECC_CAPS_SINGLE(denali_pci_ecc_caps, denali_calc_ecc_bytes, 512, 8, 15);
    
    ... instead of
    
    static const int denali_pci_ecc_strengths[] = {8, 15};
    static const struct nand_ecc_step_info denali_pci_ecc_stepinfo = {
            .stepsize = 512,
            .strengths = denali_pci_ecc_strengths,
            .nstrengths = ARRAY_SIZE(denali_pci_ecc_strengths),
    };
    static const struct nand_ecc_caps denali_pci_ecc_caps = {
            .stepinfos = &denali_pci_ecc_stepinfo,
            .nstepinfos = 1,
            .calc_ecc_bytes = denali_calc_ecc_bytes,
    };
    
    Signed-off-by: Masahiro Yamada <yamada.masahiro at socionext.com>
    Signed-off-by: Boris Brezillon <boris.brezillon at free-electrons.com>
---
 include/linux/mtd/nand.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 568f53e..dc8fbc0 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -505,6 +505,20 @@ struct nand_ecc_caps {
 	int (*calc_ecc_bytes)(int step_size, int strength);
 };
 
+/* a shorthand to generate struct nand_ecc_caps with only one ECC stepsize */
+#define NAND_ECC_CAPS_SINGLE(__name, __calc, __step, ...)	\
+static const int __name##_strengths[] = { __VA_ARGS__ };	\
+static const struct nand_ecc_step_info __name##_stepinfo = {	\
+	.stepsize = __step,					\
+	.strengths = __name##_strengths,			\
+	.nstrengths = ARRAY_SIZE(__name##_strengths),		\
+};								\
+static const struct nand_ecc_caps __name = {			\
+	.stepinfos = &__name##_stepinfo,			\
+	.nstepinfos = 1,					\
+	.calc_ecc_bytes = __calc,				\
+}
+
 /**
  * struct nand_ecc_ctrl - Control structure for ECC
  * @mode:	ECC mode



More information about the linux-mtd-cvs mailing list