1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (c) 2020 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_DOSILICON 0xE5 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 ds35xxga_ooblayout_ecc(struct mtd_info *mtd, int section, 34 struct mtd_oob_region *region) 35 { 36 if (section > 3) 37 return -ERANGE; 38 39 region->offset = (16 * section) + 8; 40 region->length = 8; 41 42 return 0; 43 } 44 45 static int ds35xxga_ooblayout_free(struct mtd_info *mtd, int section, 46 struct mtd_oob_region *region) 47 { 48 if (section > 3) 49 return -ERANGE; 50 51 region->offset = (16 * section) + 2; 52 region->length = 6; 53 54 return 0; 55 } 56 57 static const struct mtd_ooblayout_ops ds35xxga_ooblayout = { 58 .ecc = ds35xxga_ooblayout_ecc, 59 .rfree = ds35xxga_ooblayout_free, 60 }; 61 62 static const struct spinand_info dosilicon_spinand_table[] = { 63 SPINAND_INFO("DS35X1GA", 0x71, 64 NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1), 65 NAND_ECCREQ(4, 512), 66 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 67 &write_cache_variants, 68 &update_cache_variants), 69 SPINAND_HAS_QE_BIT, 70 SPINAND_ECCINFO(&ds35xxga_ooblayout, NULL)), 71 SPINAND_INFO("DS35X2GA", 0x72, 72 NAND_MEMORG(1, 2048, 64, 64, 2048, 2, 1, 1), 73 NAND_ECCREQ(4, 512), 74 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 75 &write_cache_variants, 76 &update_cache_variants), 77 SPINAND_HAS_QE_BIT, 78 SPINAND_ECCINFO(&ds35xxga_ooblayout, NULL)), 79 }; 80 81 /** 82 * dosilicon_spinand_detect - initialize device related part in spinand_device 83 * struct if it is a dosilicon device. 84 * @spinand: SPI NAND device structure 85 */ 86 static int dosilicon_spinand_detect(struct spinand_device *spinand) 87 { 88 u8 *id = spinand->id.data; 89 int ret; 90 91 /* 92 * dosilicon SPI NAND read ID need a dummy byte, 93 * so the first byte in raw_id is dummy. 94 */ 95 if (id[1] != SPINAND_MFR_DOSILICON) 96 return 0; 97 98 ret = spinand_match_and_init(spinand, dosilicon_spinand_table, 99 ARRAY_SIZE(dosilicon_spinand_table), id[2]); 100 if (ret) 101 return ret; 102 103 return 1; 104 } 105 106 static int dosilicon_spinand_init(struct spinand_device *spinand) 107 { 108 return 0; 109 } 110 111 static const struct spinand_manufacturer_ops dosilicon_spinand_manuf_ops = { 112 .detect = dosilicon_spinand_detect, 113 .init = dosilicon_spinand_init, 114 }; 115 116 const struct spinand_manufacturer dosilicon_spinand_manufacturer = { 117 .id = SPINAND_MFR_DOSILICON, 118 .name = "dosilicon", 119 .ops = &dosilicon_spinand_manuf_ops, 120 }; 121