b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2021 ASR Micro Limited |
| 4 | * |
| 5 | * Authors: |
| 6 | * Fei Lv <feilv@asrmicro.com> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/device.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/mtd/spinand.h> |
| 12 | |
| 13 | #define SPINAND_MFR_ESMT 0xC8 |
| 14 | |
| 15 | static SPINAND_OP_VARIANTS(read_cache_variants, |
| 16 | SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0), |
| 17 | SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0), |
| 18 | SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0), |
| 19 | SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0), |
| 20 | SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0), |
| 21 | SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0)); |
| 22 | |
| 23 | static SPINAND_OP_VARIANTS(write_cache_variants, |
| 24 | SPINAND_PROG_LOAD_X4(true, 0, NULL, 0), |
| 25 | SPINAND_PROG_LOAD(true, 0, NULL, 0)); |
| 26 | |
| 27 | static SPINAND_OP_VARIANTS(update_cache_variants, |
| 28 | SPINAND_PROG_LOAD_X4(false, 0, NULL, 0), |
| 29 | SPINAND_PROG_LOAD(false, 0, NULL, 0)); |
| 30 | |
| 31 | static int f50d1g41lb_ooblayout_ecc(struct mtd_info *mtd, int section, |
| 32 | struct mtd_oob_region *region) |
| 33 | { |
| 34 | if (section > 3) |
| 35 | return -ERANGE; |
| 36 | |
| 37 | region->offset = (16 * section) + 8; |
| 38 | region->length = 8; |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static int f50d1g41lb_ooblayout_free(struct mtd_info *mtd, int section, |
| 44 | struct mtd_oob_region *region) |
| 45 | { |
| 46 | if (section > 3) |
| 47 | return -ERANGE; |
| 48 | |
| 49 | region->offset = (16 * section) + 2; |
| 50 | region->length = 6; |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | static const struct mtd_ooblayout_ops f50d1g41lb_ooblayout = { |
| 56 | .ecc = f50d1g41lb_ooblayout_ecc, |
| 57 | .free = f50d1g41lb_ooblayout_free, |
| 58 | }; |
| 59 | |
| 60 | static const struct spinand_info esmt_spinand_table[] = { |
| 61 | SPINAND_INFO("F50D1G41LB", 0x11, |
| 62 | NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1), |
| 63 | NAND_ECCREQ(1, 512), |
| 64 | SPINAND_INFO_OP_VARIANTS_TIMING( |
| 65 | &read_cache_variants, |
| 66 | &write_cache_variants, |
| 67 | &update_cache_variants, |
| 68 | 15, 2, 2, 52000000), |
| 69 | 0, |
| 70 | SPINAND_ECCINFO(&f50d1g41lb_ooblayout, NULL)), |
| 71 | }; |
| 72 | |
| 73 | /** |
| 74 | * esmt_spinand_detect - initialize device related part in spinand_device |
| 75 | * struct if it is a Winbond device. |
| 76 | * @spinand: SPI NAND device structure |
| 77 | */ |
| 78 | static int esmt_spinand_detect(struct spinand_device *spinand) |
| 79 | { |
| 80 | u8 *id = spinand->id.data; |
| 81 | int ret; |
| 82 | |
| 83 | /* |
| 84 | * Winbond SPI NAND read ID need a dummy byte, |
| 85 | * so the first byte in raw_id is dummy. |
| 86 | */ |
| 87 | if (id[1] != SPINAND_MFR_ESMT) |
| 88 | return 0; |
| 89 | |
| 90 | ret = spinand_match_and_init(spinand, esmt_spinand_table, |
| 91 | ARRAY_SIZE(esmt_spinand_table), id[2]); |
| 92 | if (ret) |
| 93 | return ret; |
| 94 | |
| 95 | return 1; |
| 96 | } |
| 97 | |
| 98 | static const struct spinand_manufacturer_ops esmt_spinand_manuf_ops = { |
| 99 | .detect = esmt_spinand_detect, |
| 100 | }; |
| 101 | |
| 102 | const struct spinand_manufacturer esmt_spinand_manufacturer = { |
| 103 | .id = SPINAND_MFR_ESMT, |
| 104 | .name = "ESMT", |
| 105 | .ops = &esmt_spinand_manuf_ops, |
| 106 | }; |