Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (C) 2019 Jeff Kletsky
0004  *
0005  * Author: Jeff Kletsky <git-commits@allycomm.com>
0006  */
0007 
0008 #include <linux/device.h>
0009 #include <linux/kernel.h>
0010 #include <linux/mtd/spinand.h>
0011 
0012 
0013 #define SPINAND_MFR_PARAGON 0xa1
0014 
0015 
0016 #define PN26G0XA_STATUS_ECC_BITMASK     (3 << 4)
0017 
0018 #define PN26G0XA_STATUS_ECC_NONE_DETECTED   (0 << 4)
0019 #define PN26G0XA_STATUS_ECC_1_7_CORRECTED   (1 << 4)
0020 #define PN26G0XA_STATUS_ECC_ERRORED     (2 << 4)
0021 #define PN26G0XA_STATUS_ECC_8_CORRECTED     (3 << 4)
0022 
0023 
0024 static SPINAND_OP_VARIANTS(read_cache_variants,
0025         SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
0026         SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
0027         SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
0028         SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
0029         SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
0030         SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
0031 
0032 static SPINAND_OP_VARIANTS(write_cache_variants,
0033         SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
0034         SPINAND_PROG_LOAD(true, 0, NULL, 0));
0035 
0036 static SPINAND_OP_VARIANTS(update_cache_variants,
0037         SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
0038         SPINAND_PROG_LOAD(false, 0, NULL, 0));
0039 
0040 
0041 static int pn26g0xa_ooblayout_ecc(struct mtd_info *mtd, int section,
0042                    struct mtd_oob_region *region)
0043 {
0044     if (section > 3)
0045         return -ERANGE;
0046 
0047     region->offset = 6 + (15 * section); /* 4 BBM + 2 user bytes */
0048     region->length = 13;
0049 
0050     return 0;
0051 }
0052 
0053 static int pn26g0xa_ooblayout_free(struct mtd_info *mtd, int section,
0054                    struct mtd_oob_region *region)
0055 {
0056     if (section > 4)
0057         return -ERANGE;
0058 
0059     if (section == 4) {
0060         region->offset = 64;
0061         region->length = 64;
0062     } else {
0063         region->offset = 4 + (15 * section);
0064         region->length = 2;
0065     }
0066 
0067     return 0;
0068 }
0069 
0070 static int pn26g0xa_ecc_get_status(struct spinand_device *spinand,
0071                    u8 status)
0072 {
0073     switch (status & PN26G0XA_STATUS_ECC_BITMASK) {
0074     case PN26G0XA_STATUS_ECC_NONE_DETECTED:
0075         return 0;
0076 
0077     case PN26G0XA_STATUS_ECC_1_7_CORRECTED:
0078         return 7;   /* Return upper limit by convention */
0079 
0080     case PN26G0XA_STATUS_ECC_8_CORRECTED:
0081         return 8;
0082 
0083     case PN26G0XA_STATUS_ECC_ERRORED:
0084         return -EBADMSG;
0085 
0086     default:
0087         break;
0088     }
0089 
0090     return -EINVAL;
0091 }
0092 
0093 static const struct mtd_ooblayout_ops pn26g0xa_ooblayout = {
0094     .ecc = pn26g0xa_ooblayout_ecc,
0095     .free = pn26g0xa_ooblayout_free,
0096 };
0097 
0098 
0099 static const struct spinand_info paragon_spinand_table[] = {
0100     SPINAND_INFO("PN26G01A",
0101              SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xe1),
0102              NAND_MEMORG(1, 2048, 128, 64, 1024, 21, 1, 1, 1),
0103              NAND_ECCREQ(8, 512),
0104              SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
0105                           &write_cache_variants,
0106                           &update_cache_variants),
0107              0,
0108              SPINAND_ECCINFO(&pn26g0xa_ooblayout,
0109                      pn26g0xa_ecc_get_status)),
0110     SPINAND_INFO("PN26G02A",
0111              SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xe2),
0112              NAND_MEMORG(1, 2048, 128, 64, 2048, 41, 1, 1, 1),
0113              NAND_ECCREQ(8, 512),
0114              SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
0115                           &write_cache_variants,
0116                           &update_cache_variants),
0117              0,
0118              SPINAND_ECCINFO(&pn26g0xa_ooblayout,
0119                      pn26g0xa_ecc_get_status)),
0120 };
0121 
0122 static const struct spinand_manufacturer_ops paragon_spinand_manuf_ops = {
0123 };
0124 
0125 const struct spinand_manufacturer paragon_spinand_manufacturer = {
0126     .id = SPINAND_MFR_PARAGON,
0127     .name = "Paragon",
0128     .chips = paragon_spinand_table,
0129     .nchips = ARRAY_SIZE(paragon_spinand_table),
0130     .ops = &paragon_spinand_manuf_ops,
0131 };