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 if (section) 37 return -ERANGE; 38 39 region->offset = 64; 40 region->length = 64; 41 42 return 0; 43 } 44 45 static int fsxxndxxg_ooblayout_free(struct mtd_info *mtd, int section, 46 struct mtd_oob_region *region) 47 { 48 if (section) 49 return -ERANGE; 50 51 /* Reserve 1 bytes for the BBM. */ 52 region->offset = 1; 53 region->length = 63; 54 55 return 0; 56 } 57 58 static const struct mtd_ooblayout_ops fsxxndxxg_ooblayout = { 59 .ecc = fsxxndxxg_ooblayout_ecc, 60 .rfree = fsxxndxxg_ooblayout_free, 61 }; 62 63 static const struct spinand_info foresee_spinand_table[] = { 64 SPINAND_INFO("FS35ND01G-S1Y2", 0xEA, 65 NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1), 66 NAND_ECCREQ(4, 512), 67 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 68 &write_cache_variants, 69 &update_cache_variants), 70 0, 71 SPINAND_ECCINFO(&fsxxndxxg_ooblayout, NULL)), 72 SPINAND_INFO("FS35ND02G-S3Y2", 0xEB, 73 NAND_MEMORG(1, 2048, 64, 64, 2048, 1, 1, 1), 74 NAND_ECCREQ(4, 512), 75 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 76 &write_cache_variants, 77 &update_cache_variants), 78 0, 79 SPINAND_ECCINFO(&fsxxndxxg_ooblayout, NULL)), 80 SPINAND_INFO("FS35ND04G-S2Y2", 0xEC, 81 NAND_MEMORG(1, 2048, 64, 64, 4096, 1, 1, 1), 82 NAND_ECCREQ(4, 512), 83 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 84 &write_cache_variants, 85 &update_cache_variants), 86 0, 87 SPINAND_ECCINFO(&fsxxndxxg_ooblayout, NULL)), 88 }; 89 90 /** 91 * foresee_spinand_detect - initialize device related part in spinand_device 92 * struct if it is a foresee device. 93 * @spinand: SPI NAND device structure 94 */ 95 static int foresee_spinand_detect(struct spinand_device *spinand) 96 { 97 u8 *id = spinand->id.data; 98 int ret; 99 100 /* 101 * foresee SPI NAND read ID need a dummy byte, 102 * so the first byte in raw_id is dummy. 103 */ 104 if (id[1] != SPINAND_MFR_FORESEE) 105 return 0; 106 107 ret = spinand_match_and_init(spinand, foresee_spinand_table, 108 ARRAY_SIZE(foresee_spinand_table), id[2]); 109 if (ret) 110 return ret; 111 112 return 1; 113 } 114 115 static int foresee_spinand_init(struct spinand_device *spinand) 116 { 117 return 0; 118 } 119 120 static const struct spinand_manufacturer_ops foresee_spinand_manuf_ops = { 121 .detect = foresee_spinand_detect, 122 .init = foresee_spinand_init, 123 }; 124 125 const struct spinand_manufacturer foresee_spinand_manufacturer = { 126 .id = SPINAND_MFR_FORESEE, 127 .name = "foresee", 128 .ops = &foresee_spinand_manuf_ops, 129 }; 130