1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (c) 2020 exceet electronics GmbH 4 * 5 * Authors: 6 * Frieder Schrempf <frieder.schrempf@exceet.de> 7 * Boris Brezillon <boris.brezillon@bootlin.com> 8 */ 9 10 #ifndef __UBOOT__ 11 #include <linux/device.h> 12 #include <linux/kernel.h> 13 #endif 14 #include <linux/mtd/spinand.h> 15 16 #define SPINAND_MFR_FMSH 0xA1 17 18 static SPINAND_OP_VARIANTS(read_cache_variants, 19 SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0), 20 SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0), 21 SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0), 22 SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0), 23 SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0), 24 SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0)); 25 26 static SPINAND_OP_VARIANTS(write_cache_variants, 27 SPINAND_PROG_LOAD_X4(true, 0, NULL, 0), 28 SPINAND_PROG_LOAD(true, 0, NULL, 0)); 29 30 static SPINAND_OP_VARIANTS(update_cache_variants, 31 SPINAND_PROG_LOAD_X4(false, 0, NULL, 0), 32 SPINAND_PROG_LOAD(false, 0, NULL, 0)); 33 34 static int fm25s01a_ooblayout_ecc(struct mtd_info *mtd, int section, 35 struct mtd_oob_region *region) 36 { 37 return -ERANGE; 38 } 39 40 static int fm25s01a_ooblayout_free(struct mtd_info *mtd, int section, 41 struct mtd_oob_region *region) 42 { 43 if (section) 44 return -ERANGE; 45 46 region->offset = 2; 47 region->length = 62; 48 49 return 0; 50 } 51 52 static const struct mtd_ooblayout_ops fm25s01a_ooblayout = { 53 .ecc = fm25s01a_ooblayout_ecc, 54 .rfree = fm25s01a_ooblayout_free, 55 }; 56 57 static const struct spinand_info fmsh_spinand_table[] = { 58 SPINAND_INFO("FM25S01A", 0xE4, 59 NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1), 60 NAND_ECCREQ(1, 512), 61 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 62 &write_cache_variants, 63 &update_cache_variants), 64 0, 65 SPINAND_ECCINFO(&fm25s01a_ooblayout, NULL)), 66 SPINAND_INFO("FM25S02A", 0xE5, 67 NAND_MEMORG(1, 2048, 64, 64, 2048, 1, 1, 1), 68 NAND_ECCREQ(1, 512), 69 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 70 &write_cache_variants, 71 &update_cache_variants), 72 0, 73 SPINAND_ECCINFO(&fm25s01a_ooblayout, NULL)), 74 }; 75 76 /** 77 * fmsh_spinand_detect - initialize device related part in spinand_device 78 * struct if it is a FMSH device. 79 * @spinand: SPI NAND device structure 80 */ 81 static int fmsh_spinand_detect(struct spinand_device *spinand) 82 { 83 u8 *id = spinand->id.data; 84 int ret; 85 86 /* 87 * FMSH SPI NAND read ID need a dummy byte, 88 * so the first byte in raw_id is dummy. 89 */ 90 if (id[1] != SPINAND_MFR_FMSH) 91 return 0; 92 93 ret = spinand_match_and_init(spinand, fmsh_spinand_table, 94 ARRAY_SIZE(fmsh_spinand_table), id[2]); 95 if (ret) 96 return ret; 97 98 return 1; 99 } 100 101 static const struct spinand_manufacturer_ops fmsh_spinand_manuf_ops = { 102 .detect = fmsh_spinand_detect, 103 }; 104 105 const struct spinand_manufacturer fmsh_spinand_manufacturer = { 106 .id = SPINAND_MFR_FMSH, 107 .name = "FMSH", 108 .ops = &fmsh_spinand_manuf_ops, 109 }; 110