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 }; 67 68 /** 69 * fmsh_spinand_detect - initialize device related part in spinand_device 70 * struct if it is a FMSH device. 71 * @spinand: SPI NAND device structure 72 */ 73 static int fmsh_spinand_detect(struct spinand_device *spinand) 74 { 75 u8 *id = spinand->id.data; 76 int ret; 77 78 /* 79 * FMSH SPI NAND read ID need a dummy byte, 80 * so the first byte in raw_id is dummy. 81 */ 82 if (id[1] != SPINAND_MFR_FMSH) 83 return 0; 84 85 ret = spinand_match_and_init(spinand, fmsh_spinand_table, 86 ARRAY_SIZE(fmsh_spinand_table), id[2]); 87 if (ret) 88 return ret; 89 90 return 1; 91 } 92 93 static const struct spinand_manufacturer_ops fmsh_spinand_manuf_ops = { 94 .detect = fmsh_spinand_detect, 95 }; 96 97 const struct spinand_manufacturer fmsh_spinand_manufacturer = { 98 .id = SPINAND_MFR_FMSH, 99 .name = "FMSH", 100 .ops = &fmsh_spinand_manuf_ops, 101 }; 102