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_SILICONGO 0xEA 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 sgm7000i_ooblayout_ecc(struct mtd_info *mtd, int section, 34 struct mtd_oob_region *region) 35 { 36 return -ERANGE; 37 } 38 39 static int sgm7000i_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 sgm7000i_ooblayout = { 52 .ecc = sgm7000i_ooblayout_ecc, 53 .rfree = sgm7000i_ooblayout_free, 54 }; 55 56 static const struct spinand_info silicongo_spinand_table[] = { 57 SPINAND_INFO("SGM7000I-S24W1GH", 0xC1, 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 SPINAND_HAS_QE_BIT, 64 SPINAND_ECCINFO(&sgm7000i_ooblayout, NULL)), 65 }; 66 67 /** 68 * silicongo_spinand_detect - initialize device related part in spinand_device 69 * struct if it is a silicongo device. 70 * @spinand: SPI NAND device structure 71 */ 72 static int silicongo_spinand_detect(struct spinand_device *spinand) 73 { 74 u8 *id = spinand->id.data; 75 int ret; 76 77 /* 78 * silicongo SPI NAND read ID need a dummy byte, 79 * so the first byte in raw_id is dummy. 80 */ 81 if (id[1] != SPINAND_MFR_SILICONGO) 82 return 0; 83 84 ret = spinand_match_and_init(spinand, silicongo_spinand_table, 85 ARRAY_SIZE(silicongo_spinand_table), id[2]); 86 /* Not Only SILICONGO Nands MFR equals C8h */ 87 if (ret) 88 return 0; 89 90 return 1; 91 } 92 93 static int silicongo_spinand_init(struct spinand_device *spinand) 94 { 95 return 0; 96 } 97 98 static const struct spinand_manufacturer_ops silicongo_spinand_manuf_ops = { 99 .detect = silicongo_spinand_detect, 100 .init = silicongo_spinand_init, 101 }; 102 103 const struct spinand_manufacturer silicongo_spinand_manufacturer = { 104 .id = SPINAND_MFR_SILICONGO, 105 .name = "silicongo", 106 .ops = &silicongo_spinand_manuf_ops, 107 }; 108