1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (c) 2020 Grandstream Networks, Inc 4 * 5 * Authors: 6 * Carl <xjxia@grandstream.cn> 7 */ 8 9 #ifndef __UBOOT__ 10 #include <linux/device.h> 11 #include <linux/kernel.h> 12 #endif 13 #include <linux/mtd/spinand.h> 14 15 #define SPINAND_MFR_FORESEE 0xCD 16 17 static SPINAND_OP_VARIANTS(read_cache_variants, 18 SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0), 19 SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0), 20 SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0), 21 SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0), 22 SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0), 23 SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0)); 24 25 static SPINAND_OP_VARIANTS(write_cache_variants, 26 SPINAND_PROG_LOAD_X4(true, 0, NULL, 0), 27 SPINAND_PROG_LOAD(true, 0, NULL, 0)); 28 29 static SPINAND_OP_VARIANTS(update_cache_variants, 30 SPINAND_PROG_LOAD_X4(false, 0, NULL, 0), 31 SPINAND_PROG_LOAD(false, 0, NULL, 0)); 32 33 static int fsxxndxxg_ooblayout_ecc(struct mtd_info *mtd, int section, 34 struct mtd_oob_region *region) 35 { 36 return -ERANGE; 37 } 38 39 static int fsxxndxxg_ooblayout_free(struct mtd_info *mtd, int section, 40 struct mtd_oob_region *region) 41 { 42 if (section) 43 return -ERANGE; 44 45 region->offset = 2; 46 region->length = mtd->oobsize - 2; 47 48 return 0; 49 } 50 51 static const struct mtd_ooblayout_ops fsxxndxxg_ooblayout = { 52 .ecc = fsxxndxxg_ooblayout_ecc, 53 .rfree = fsxxndxxg_ooblayout_free, 54 }; 55 56 static const struct spinand_info foresee_spinand_table[] = { 57 SPINAND_INFO("FS35ND01G-S1Y2", 0xEA, 58 NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1), 59 NAND_ECCREQ(4, 512), 60 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 61 &write_cache_variants, 62 &update_cache_variants), 63 0, 64 SPINAND_ECCINFO(&fsxxndxxg_ooblayout, NULL)), 65 SPINAND_INFO("FS35ND02G-S3Y2", 0xEB, 66 NAND_MEMORG(1, 2048, 64, 64, 2048, 1, 1, 1), 67 NAND_ECCREQ(4, 512), 68 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 69 &write_cache_variants, 70 &update_cache_variants), 71 0, 72 SPINAND_ECCINFO(&fsxxndxxg_ooblayout, NULL)), 73 SPINAND_INFO("FS35ND04G-S2Y2", 0xEC, 74 NAND_MEMORG(1, 2048, 64, 64, 4096, 1, 1, 1), 75 NAND_ECCREQ(4, 512), 76 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 77 &write_cache_variants, 78 &update_cache_variants), 79 0, 80 SPINAND_ECCINFO(&fsxxndxxg_ooblayout, NULL)), 81 SPINAND_INFO("fsxxndxxg", 0x71, 82 NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1), 83 NAND_ECCREQ(1, 512), 84 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 85 &write_cache_variants, 86 &update_cache_variants), 87 SPINAND_HAS_QE_BIT, 88 SPINAND_ECCINFO(&fsxxndxxg_ooblayout, NULL)), 89 }; 90 91 /** 92 * foresee_spinand_detect - initialize device related part in spinand_device 93 * struct if it is a foresee device. 94 * @spinand: SPI NAND device structure 95 */ 96 static int foresee_spinand_detect(struct spinand_device *spinand) 97 { 98 u8 *id = spinand->id.data; 99 int ret; 100 101 /* 102 * foresee SPI NAND read ID need a dummy byte, 103 * so the first byte in raw_id is dummy. 104 */ 105 if (id[1] != SPINAND_MFR_FORESEE) 106 return 0; 107 108 ret = spinand_match_and_init(spinand, foresee_spinand_table, 109 ARRAY_SIZE(foresee_spinand_table), id[2]); 110 if (ret) 111 return ret; 112 113 return 1; 114 } 115 116 static int foresee_spinand_init(struct spinand_device *spinand) 117 { 118 return 0; 119 } 120 121 static const struct spinand_manufacturer_ops foresee_spinand_manuf_ops = { 122 .detect = foresee_spinand_detect, 123 .init = foresee_spinand_init, 124 }; 125 126 const struct spinand_manufacturer foresee_spinand_manufacturer = { 127 .id = SPINAND_MFR_FORESEE, 128 .name = "foresee", 129 .ops = &foresee_spinand_manuf_ops, 130 }; 131