• Masahiro Yamada's avatar
    mtd: nand: denali: avoid hard-coding ECC step, strength, bytes · 7de117fd
    Masahiro Yamada authored
    This driver was originally written for the Intel MRST platform with
    several platform-specific parameters hard-coded.
    
    Currently, the ECC settings are hard-coded as follows:
    
      #define ECC_SECTOR_SIZE 512
      #define ECC_8BITS       14
      #define ECC_15BITS      26
    
    Therefore, the driver can only support two cases.
     - ecc.size = 512, ecc.strength = 8    --> ecc.bytes = 14
     - ecc.size = 512, ecc.strength = 15   --> ecc.bytes = 26
    
    However, these are actually customizable parameters, for example,
    UniPhier platform supports the following:
    
     - ecc.size = 1024, ecc.strength = 8   --> ecc.bytes = 14
     - ecc.size = 1024, ecc.strength = 16  --> ecc.bytes = 28
     - ecc.size = 1024, ecc.strength = 24  --> ecc.bytes = 42
    
    So, we need to handle the ECC parameters in a more generic manner.
    Fortunately, the Denali User's Guide explains how to calculate the
    ecc.bytes.  The formula is:
    
      ecc.bytes = 2 * CEIL(13 * ecc.strength / 16)  (for ecc.size = 512)
      ecc.bytes = 2 * CEIL(14 * ecc.strength / 16)  (for ecc.size = 1024)
    
    For DT platforms, it would be reasonable to allow DT to specify ECC
    strength by either "nand-ecc-strength" or "nand-ecc-maximize".  If
    none of them is specified, the driver will try to meet the chip's ECC
    requirement.
    
    For PCI platforms, the max ECC strength is used to keep the original
    behavior.
    
    Newer versions of this IP need ecc.size and ecc.steps explicitly
    set up via the following registers:
      CFG_DATA_BLOCK_SIZE       (0x6b0)
      CFG_LAST_DATA_BLOCK_SIZE  (0x6c0)
      CFG_NUM_DATA_BLOCKS       (0x6d0)
    
    For older IP versions, write accesses to these registers are just
    ignored.
    Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
    Acked-by: default avatarRob Herring <robh@kernel.org>
    Signed-off-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
    7de117fd
denali.c 46.2 KB