Mikhail Kshevetskiy | 2a1e78b | 2023-01-10 12:58:40 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2019 Jeff Kletsky |
| 4 | * |
| 5 | * Author: Jeff Kletsky <git-commits@allycomm.com> |
| 6 | */ |
| 7 | |
| 8 | #ifndef __UBOOT__ |
| 9 | #include <linux/device.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #endif |
| 12 | #include <linux/mtd/spinand.h> |
| 13 | |
Mikhail Kshevetskiy | 2a1e78b | 2023-01-10 12:58:40 +0100 | [diff] [blame] | 14 | #define SPINAND_MFR_PARAGON 0xa1 |
| 15 | |
Mikhail Kshevetskiy | 2a1e78b | 2023-01-10 12:58:40 +0100 | [diff] [blame] | 16 | #define PN26G0XA_STATUS_ECC_BITMASK (3 << 4) |
| 17 | |
| 18 | #define PN26G0XA_STATUS_ECC_NONE_DETECTED (0 << 4) |
| 19 | #define PN26G0XA_STATUS_ECC_1_7_CORRECTED (1 << 4) |
| 20 | #define PN26G0XA_STATUS_ECC_ERRORED (2 << 4) |
| 21 | #define PN26G0XA_STATUS_ECC_8_CORRECTED (3 << 4) |
| 22 | |
Mikhail Kshevetskiy | 2a1e78b | 2023-01-10 12:58:40 +0100 | [diff] [blame] | 23 | static SPINAND_OP_VARIANTS(read_cache_variants, |
| 24 | SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0), |
| 25 | SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0), |
| 26 | SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0), |
| 27 | SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0), |
| 28 | SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0), |
| 29 | SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0)); |
| 30 | |
| 31 | static SPINAND_OP_VARIANTS(write_cache_variants, |
| 32 | SPINAND_PROG_LOAD_X4(true, 0, NULL, 0), |
| 33 | SPINAND_PROG_LOAD(true, 0, NULL, 0)); |
| 34 | |
| 35 | static SPINAND_OP_VARIANTS(update_cache_variants, |
| 36 | SPINAND_PROG_LOAD_X4(false, 0, NULL, 0), |
| 37 | SPINAND_PROG_LOAD(false, 0, NULL, 0)); |
| 38 | |
Mikhail Kshevetskiy | 2a1e78b | 2023-01-10 12:58:40 +0100 | [diff] [blame] | 39 | static int pn26g0xa_ooblayout_ecc(struct mtd_info *mtd, int section, |
| 40 | struct mtd_oob_region *region) |
| 41 | { |
| 42 | if (section > 3) |
| 43 | return -ERANGE; |
| 44 | |
| 45 | region->offset = 6 + (15 * section); /* 4 BBM + 2 user bytes */ |
| 46 | region->length = 13; |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static int pn26g0xa_ooblayout_free(struct mtd_info *mtd, int section, |
| 52 | struct mtd_oob_region *region) |
| 53 | { |
| 54 | if (section > 4) |
| 55 | return -ERANGE; |
| 56 | |
| 57 | if (section == 4) { |
| 58 | region->offset = 64; |
| 59 | region->length = 64; |
| 60 | } else { |
| 61 | region->offset = 4 + (15 * section); |
| 62 | region->length = 2; |
| 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static int pn26g0xa_ecc_get_status(struct spinand_device *spinand, |
| 69 | u8 status) |
| 70 | { |
| 71 | switch (status & PN26G0XA_STATUS_ECC_BITMASK) { |
| 72 | case PN26G0XA_STATUS_ECC_NONE_DETECTED: |
| 73 | return 0; |
| 74 | |
| 75 | case PN26G0XA_STATUS_ECC_1_7_CORRECTED: |
| 76 | return 7; /* Return upper limit by convention */ |
| 77 | |
| 78 | case PN26G0XA_STATUS_ECC_8_CORRECTED: |
| 79 | return 8; |
| 80 | |
| 81 | case PN26G0XA_STATUS_ECC_ERRORED: |
| 82 | return -EBADMSG; |
| 83 | |
| 84 | default: |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | return -EINVAL; |
| 89 | } |
| 90 | |
| 91 | static const struct mtd_ooblayout_ops pn26g0xa_ooblayout = { |
| 92 | .ecc = pn26g0xa_ooblayout_ecc, |
| 93 | .rfree = pn26g0xa_ooblayout_free, |
| 94 | }; |
| 95 | |
Mikhail Kshevetskiy | 2a1e78b | 2023-01-10 12:58:40 +0100 | [diff] [blame] | 96 | static const struct spinand_info paragon_spinand_table[] = { |
| 97 | SPINAND_INFO("PN26G01A", |
| 98 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xe1), |
| 99 | NAND_MEMORG(1, 2048, 128, 64, 1024, 21, 1, 1, 1), |
| 100 | NAND_ECCREQ(8, 512), |
| 101 | SPINAND_INFO_OP_VARIANTS(&read_cache_variants, |
| 102 | &write_cache_variants, |
| 103 | &update_cache_variants), |
| 104 | 0, |
| 105 | SPINAND_ECCINFO(&pn26g0xa_ooblayout, |
| 106 | pn26g0xa_ecc_get_status)), |
| 107 | SPINAND_INFO("PN26G02A", |
| 108 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xe2), |
| 109 | NAND_MEMORG(1, 2048, 128, 64, 2048, 41, 1, 1, 1), |
| 110 | NAND_ECCREQ(8, 512), |
| 111 | SPINAND_INFO_OP_VARIANTS(&read_cache_variants, |
| 112 | &write_cache_variants, |
| 113 | &update_cache_variants), |
| 114 | 0, |
| 115 | SPINAND_ECCINFO(&pn26g0xa_ooblayout, |
| 116 | pn26g0xa_ecc_get_status)), |
| 117 | }; |
| 118 | |
| 119 | static const struct spinand_manufacturer_ops paragon_spinand_manuf_ops = { |
| 120 | }; |
| 121 | |
| 122 | const struct spinand_manufacturer paragon_spinand_manufacturer = { |
| 123 | .id = SPINAND_MFR_PARAGON, |
| 124 | .name = "Paragon", |
| 125 | .chips = paragon_spinand_table, |
| 126 | .nchips = ARRAY_SIZE(paragon_spinand_table), |
| 127 | .ops = ¶gon_spinand_manuf_ops, |
| 128 | }; |