Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mtd: spinand: Add support for XTX XT26G0xA

Add support for XTX Technology XT26G01AXXXXX, XTX26G02AXXXXX and
XTX26G04AXXXXX SPI NAND.

These are 3V, 1G/2G/4Gbit serial SLC NAND flash devices with on-die ECC
(8bit strength per 512bytes).

Tested on Teltonika RUTX10 flashed with OpenWrt.

Links:
- http://www.xtxtech.com/download/?AId=225
- https://datasheet.lcsc.com/szlcsc/2005251034_XTX-XT26G01AWSEGA_C558841.pdf
Signed-off-by: Felix Matouschek <felix@matouschek.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20220418132803.664103-1-felix@matouschek.org

authored by

Felix Matouschek and committed by
Miquel Raynal
f4c5c7f9 d9edc4bc

+132 -1
+1 -1
drivers/mtd/nand/spi/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - spinand-objs := core.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o 2 + spinand-objs := core.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o 3 3 obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
+1
drivers/mtd/nand/spi/core.c
··· 933 933 &paragon_spinand_manufacturer, 934 934 &toshiba_spinand_manufacturer, 935 935 &winbond_spinand_manufacturer, 936 + &xtx_spinand_manufacturer, 936 937 }; 937 938 938 939 static int spinand_manufacturer_match(struct spinand_device *spinand,
+129
drivers/mtd/nand/spi/xtx.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Author: 4 + * Felix Matouschek <felix@matouschek.org> 5 + */ 6 + 7 + #include <linux/device.h> 8 + #include <linux/kernel.h> 9 + #include <linux/mtd/spinand.h> 10 + 11 + #define SPINAND_MFR_XTX 0x0B 12 + 13 + #define XT26G0XA_STATUS_ECC_MASK GENMASK(5, 2) 14 + #define XT26G0XA_STATUS_ECC_NO_DETECTED (0 << 2) 15 + #define XT26G0XA_STATUS_ECC_8_CORRECTED (3 << 4) 16 + #define XT26G0XA_STATUS_ECC_UNCOR_ERROR (2 << 4) 17 + 18 + static SPINAND_OP_VARIANTS(read_cache_variants, 19 + SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0), 20 + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0), 21 + SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0), 22 + SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0), 23 + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0), 24 + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0)); 25 + 26 + static SPINAND_OP_VARIANTS(write_cache_variants, 27 + SPINAND_PROG_LOAD_X4(true, 0, NULL, 0), 28 + SPINAND_PROG_LOAD(true, 0, NULL, 0)); 29 + 30 + static SPINAND_OP_VARIANTS(update_cache_variants, 31 + SPINAND_PROG_LOAD_X4(false, 0, NULL, 0), 32 + SPINAND_PROG_LOAD(false, 0, NULL, 0)); 33 + 34 + static int xt26g0xa_ooblayout_ecc(struct mtd_info *mtd, int section, 35 + struct mtd_oob_region *region) 36 + { 37 + if (section) 38 + return -ERANGE; 39 + 40 + region->offset = 48; 41 + region->length = 16; 42 + 43 + return 0; 44 + } 45 + 46 + static int xt26g0xa_ooblayout_free(struct mtd_info *mtd, int section, 47 + struct mtd_oob_region *region) 48 + { 49 + if (section) 50 + return -ERANGE; 51 + 52 + region->offset = 1; 53 + region->length = 47; 54 + 55 + return 0; 56 + } 57 + 58 + static const struct mtd_ooblayout_ops xt26g0xa_ooblayout = { 59 + .ecc = xt26g0xa_ooblayout_ecc, 60 + .free = xt26g0xa_ooblayout_free, 61 + }; 62 + 63 + static int xt26g0xa_ecc_get_status(struct spinand_device *spinand, 64 + u8 status) 65 + { 66 + status = status & XT26G0XA_STATUS_ECC_MASK; 67 + 68 + switch (status) { 69 + case XT26G0XA_STATUS_ECC_NO_DETECTED: 70 + return 0; 71 + case XT26G0XA_STATUS_ECC_8_CORRECTED: 72 + return 8; 73 + case XT26G0XA_STATUS_ECC_UNCOR_ERROR: 74 + return -EBADMSG; 75 + default: 76 + break; 77 + } 78 + 79 + /* At this point values greater than (2 << 4) are invalid */ 80 + if (status > XT26G0XA_STATUS_ECC_UNCOR_ERROR) 81 + return -EINVAL; 82 + 83 + /* (1 << 2) through (7 << 2) are 1-7 corrected errors */ 84 + return status >> 2; 85 + } 86 + 87 + static const struct spinand_info xtx_spinand_table[] = { 88 + SPINAND_INFO("XT26G01A", 89 + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0xE1), 90 + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1), 91 + NAND_ECCREQ(8, 512), 92 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 93 + &write_cache_variants, 94 + &update_cache_variants), 95 + SPINAND_HAS_QE_BIT, 96 + SPINAND_ECCINFO(&xt26g0xa_ooblayout, 97 + xt26g0xa_ecc_get_status)), 98 + SPINAND_INFO("XT26G02A", 99 + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0xE2), 100 + NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1), 101 + NAND_ECCREQ(8, 512), 102 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 103 + &write_cache_variants, 104 + &update_cache_variants), 105 + SPINAND_HAS_QE_BIT, 106 + SPINAND_ECCINFO(&xt26g0xa_ooblayout, 107 + xt26g0xa_ecc_get_status)), 108 + SPINAND_INFO("XT26G04A", 109 + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0xE3), 110 + NAND_MEMORG(1, 2048, 64, 128, 2048, 40, 1, 1, 1), 111 + NAND_ECCREQ(8, 512), 112 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 113 + &write_cache_variants, 114 + &update_cache_variants), 115 + SPINAND_HAS_QE_BIT, 116 + SPINAND_ECCINFO(&xt26g0xa_ooblayout, 117 + xt26g0xa_ecc_get_status)), 118 + }; 119 + 120 + static const struct spinand_manufacturer_ops xtx_spinand_manuf_ops = { 121 + }; 122 + 123 + const struct spinand_manufacturer xtx_spinand_manufacturer = { 124 + .id = SPINAND_MFR_XTX, 125 + .name = "XTX", 126 + .chips = xtx_spinand_table, 127 + .nchips = ARRAY_SIZE(xtx_spinand_table), 128 + .ops = &xtx_spinand_manuf_ops, 129 + };
+1
include/linux/mtd/spinand.h
··· 266 266 extern const struct spinand_manufacturer paragon_spinand_manufacturer; 267 267 extern const struct spinand_manufacturer toshiba_spinand_manufacturer; 268 268 extern const struct spinand_manufacturer winbond_spinand_manufacturer; 269 + extern const struct spinand_manufacturer xtx_spinand_manufacturer; 269 270 270 271 /** 271 272 * struct spinand_op_variants - SPI NAND operation variants