Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Author:
0004  * Felix Matouschek <felix@matouschek.org>
0005  */
0006 
0007 #include <linux/device.h>
0008 #include <linux/kernel.h>
0009 #include <linux/mtd/spinand.h>
0010 
0011 #define SPINAND_MFR_XTX 0x0B
0012 
0013 #define XT26G0XA_STATUS_ECC_MASK    GENMASK(5, 2)
0014 #define XT26G0XA_STATUS_ECC_NO_DETECTED (0 << 2)
0015 #define XT26G0XA_STATUS_ECC_8_CORRECTED (3 << 4)
0016 #define XT26G0XA_STATUS_ECC_UNCOR_ERROR (2 << 4)
0017 
0018 static SPINAND_OP_VARIANTS(read_cache_variants,
0019         SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
0020         SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
0021         SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
0022         SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
0023         SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
0024         SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
0025 
0026 static SPINAND_OP_VARIANTS(write_cache_variants,
0027         SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
0028         SPINAND_PROG_LOAD(true, 0, NULL, 0));
0029 
0030 static SPINAND_OP_VARIANTS(update_cache_variants,
0031         SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
0032         SPINAND_PROG_LOAD(false, 0, NULL, 0));
0033 
0034 static int xt26g0xa_ooblayout_ecc(struct mtd_info *mtd, int section,
0035                    struct mtd_oob_region *region)
0036 {
0037     if (section)
0038         return -ERANGE;
0039 
0040     region->offset = 48;
0041     region->length = 16;
0042 
0043     return 0;
0044 }
0045 
0046 static int xt26g0xa_ooblayout_free(struct mtd_info *mtd, int section,
0047                    struct mtd_oob_region *region)
0048 {
0049     if (section)
0050         return -ERANGE;
0051 
0052     region->offset = 1;
0053     region->length = 47;
0054 
0055     return 0;
0056 }
0057 
0058 static const struct mtd_ooblayout_ops xt26g0xa_ooblayout = {
0059     .ecc = xt26g0xa_ooblayout_ecc,
0060     .free = xt26g0xa_ooblayout_free,
0061 };
0062 
0063 static int xt26g0xa_ecc_get_status(struct spinand_device *spinand,
0064                      u8 status)
0065 {
0066     status = status & XT26G0XA_STATUS_ECC_MASK;
0067 
0068     switch (status) {
0069     case XT26G0XA_STATUS_ECC_NO_DETECTED:
0070         return 0;
0071     case XT26G0XA_STATUS_ECC_8_CORRECTED:
0072         return 8;
0073     case XT26G0XA_STATUS_ECC_UNCOR_ERROR:
0074         return -EBADMSG;
0075     default:
0076         break;
0077     }
0078 
0079     /* At this point values greater than (2 << 4) are invalid  */
0080     if (status > XT26G0XA_STATUS_ECC_UNCOR_ERROR)
0081         return -EINVAL;
0082 
0083     /* (1 << 2) through (7 << 2) are 1-7 corrected errors */
0084     return status >> 2;
0085 }
0086 
0087 static const struct spinand_info xtx_spinand_table[] = {
0088     SPINAND_INFO("XT26G01A",
0089              SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0xE1),
0090              NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
0091              NAND_ECCREQ(8, 512),
0092              SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
0093                           &write_cache_variants,
0094                           &update_cache_variants),
0095              SPINAND_HAS_QE_BIT,
0096              SPINAND_ECCINFO(&xt26g0xa_ooblayout,
0097                      xt26g0xa_ecc_get_status)),
0098     SPINAND_INFO("XT26G02A",
0099              SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0xE2),
0100              NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
0101              NAND_ECCREQ(8, 512),
0102              SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
0103                           &write_cache_variants,
0104                           &update_cache_variants),
0105              SPINAND_HAS_QE_BIT,
0106              SPINAND_ECCINFO(&xt26g0xa_ooblayout,
0107                      xt26g0xa_ecc_get_status)),
0108     SPINAND_INFO("XT26G04A",
0109              SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0xE3),
0110              NAND_MEMORG(1, 2048, 64, 128, 2048, 40, 1, 1, 1),
0111              NAND_ECCREQ(8, 512),
0112              SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
0113                           &write_cache_variants,
0114                           &update_cache_variants),
0115              SPINAND_HAS_QE_BIT,
0116              SPINAND_ECCINFO(&xt26g0xa_ooblayout,
0117                      xt26g0xa_ecc_get_status)),
0118 };
0119 
0120 static const struct spinand_manufacturer_ops xtx_spinand_manuf_ops = {
0121 };
0122 
0123 const struct spinand_manufacturer xtx_spinand_manufacturer = {
0124     .id = SPINAND_MFR_XTX,
0125     .name = "XTX",
0126     .chips = xtx_spinand_table,
0127     .nchips = ARRAY_SIZE(xtx_spinand_table),
0128     .ops = &xtx_spinand_manuf_ops,
0129 };