drm: bridge: adv7511: remove s32 format from i2s capabilities
[drm/drm-misc.git] / drivers / mtd / nand / spi / alliancememory.c
blob7936ea546b038e3441fcd81bd92e358a0f22ed82
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Author: Mario Kicherer <dev@kicherer.org>
4 */
6 #include <linux/device.h>
7 #include <linux/kernel.h>
8 #include <linux/mtd/spinand.h>
10 #define SPINAND_MFR_ALLIANCEMEMORY 0x52
12 #define AM_STATUS_ECC_BITMASK (3 << 4)
14 #define AM_STATUS_ECC_NONE_DETECTED (0 << 4)
15 #define AM_STATUS_ECC_CORRECTED (1 << 4)
16 #define AM_STATUS_ECC_ERRORED (2 << 4)
17 #define AM_STATUS_ECC_MAX_CORRECTED (3 << 4)
19 static SPINAND_OP_VARIANTS(read_cache_variants,
20 SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
21 SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
22 SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
23 SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
24 SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
25 SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
27 static SPINAND_OP_VARIANTS(write_cache_variants,
28 SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
29 SPINAND_PROG_LOAD(true, 0, NULL, 0));
31 static SPINAND_OP_VARIANTS(update_cache_variants,
32 SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
33 SPINAND_PROG_LOAD(false, 0, NULL, 0));
35 static int am_get_eccsize(struct mtd_info *mtd)
37 if (mtd->oobsize == 64)
38 return 0x20;
39 else if (mtd->oobsize == 128)
40 return 0x38;
41 else if (mtd->oobsize == 256)
42 return 0x70;
43 else
44 return -EINVAL;
47 static int am_ooblayout_ecc(struct mtd_info *mtd, int section,
48 struct mtd_oob_region *region)
50 int ecc_bytes;
52 ecc_bytes = am_get_eccsize(mtd);
53 if (ecc_bytes < 0)
54 return ecc_bytes;
56 region->offset = mtd->oobsize - ecc_bytes;
57 region->length = ecc_bytes;
59 return 0;
62 static int am_ooblayout_free(struct mtd_info *mtd, int section,
63 struct mtd_oob_region *region)
65 int ecc_bytes;
67 if (section)
68 return -ERANGE;
70 ecc_bytes = am_get_eccsize(mtd);
71 if (ecc_bytes < 0)
72 return ecc_bytes;
75 * It is unclear how many bytes are used for the bad block marker. We
76 * reserve the common two bytes here.
78 * The free area in this kind of flash is divided into chunks where the
79 * first 4 bytes of each chunk are unprotected. The number of chunks
80 * depends on the specific model. The models with 4096+256 bytes pages
81 * have 8 chunks, the others 4 chunks.
84 region->offset = 2;
85 region->length = mtd->oobsize - 2 - ecc_bytes;
87 return 0;
90 static const struct mtd_ooblayout_ops am_ooblayout = {
91 .ecc = am_ooblayout_ecc,
92 .free = am_ooblayout_free,
95 static int am_ecc_get_status(struct spinand_device *spinand, u8 status)
97 switch (status & AM_STATUS_ECC_BITMASK) {
98 case AM_STATUS_ECC_NONE_DETECTED:
99 return 0;
101 case AM_STATUS_ECC_CORRECTED:
103 * use oobsize to determine the flash model and the maximum of
104 * correctable errors and return maximum - 1 by convention
106 if (spinand->base.mtd.oobsize == 64)
107 return 3;
108 else
109 return 7;
111 case AM_STATUS_ECC_ERRORED:
112 return -EBADMSG;
114 case AM_STATUS_ECC_MAX_CORRECTED:
116 * use oobsize to determine the flash model and the maximum of
117 * correctable errors
119 if (spinand->base.mtd.oobsize == 64)
120 return 4;
121 else
122 return 8;
124 default:
125 break;
128 return -EINVAL;
131 static const struct spinand_info alliancememory_spinand_table[] = {
132 SPINAND_INFO("AS5F34G04SND",
133 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x2f),
134 NAND_MEMORG(1, 2048, 128, 64, 4096, 80, 1, 1, 1),
135 NAND_ECCREQ(4, 512),
136 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
137 &write_cache_variants,
138 &update_cache_variants),
139 SPINAND_HAS_QE_BIT,
140 SPINAND_ECCINFO(&am_ooblayout,
141 am_ecc_get_status)),
144 static const struct spinand_manufacturer_ops alliancememory_spinand_manuf_ops = {
147 const struct spinand_manufacturer alliancememory_spinand_manufacturer = {
148 .id = SPINAND_MFR_ALLIANCEMEMORY,
149 .name = "AllianceMemory",
150 .chips = alliancememory_spinand_table,
151 .nchips = ARRAY_SIZE(alliancememory_spinand_table),
152 .ops = &alliancememory_spinand_manuf_ops,