1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (c) 2024 Rockchip Electronics Co., Ltd 4 * 5 * Authors: 6 * Dingqiang Lin <jon.lin@rock-chips.com> 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_HIKSEMI 0x3C 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 hsesyhdswxg_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 hsesyhdswxg_ooblayout_free(struct mtd_info *mtd, int section, 46 struct mtd_oob_region *region) 47 { 48 if (section) 49 return -ERANGE; 50 51 region->offset = 2; 52 region->length = 62; 53 54 return 0; 55 } 56 57 static const struct mtd_ooblayout_ops hsesyhdswxg_ooblayout = { 58 .ecc = hsesyhdswxg_ooblayout_ecc, 59 .rfree = hsesyhdswxg_ooblayout_free, 60 }; 61 62 static const struct spinand_info hiksemi_spinand_table[] = { 63 SPINAND_INFO("HSESYHDSW2G", 64 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xD2), 65 NAND_MEMORG(1, 2048, 128, 64, 2048, 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(&hsesyhdswxg_ooblayout, NULL)), 72 SPINAND_INFO("HSESDFDSW4G", 73 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xD4), 74 NAND_MEMORG(1, 2048, 128, 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(&hsesyhdswxg_ooblayout, NULL)), 81 }; 82 83 static const struct spinand_manufacturer_ops hiksemi_spinand_manuf_ops = { 84 }; 85 86 const struct spinand_manufacturer hiksemi_spinand_manufacturer = { 87 .id = SPINAND_MFR_HIKSEMI, 88 .name = "HIKSEMI", 89 .chips = hiksemi_spinand_table, 90 .nchips = ARRAY_SIZE(hiksemi_spinand_table), 91 .ops = &hiksemi_spinand_manuf_ops, 92 }; 93