Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (c) 2017 exceet electronics GmbH
0004  *
0005  * Authors:
0006  *  Frieder Schrempf <frieder.schrempf@exceet.de>
0007  *  Boris Brezillon <boris.brezillon@bootlin.com>
0008  */
0009 
0010 #include <linux/device.h>
0011 #include <linux/kernel.h>
0012 #include <linux/mtd/spinand.h>
0013 
0014 #define SPINAND_MFR_WINBOND     0xEF
0015 
0016 #define WINBOND_CFG_BUF_READ        BIT(3)
0017 
0018 static SPINAND_OP_VARIANTS(read_cache_variants,
0019         SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
0020         SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
0021         SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
0022         SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
0023         SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
0024         SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
0025 
0026 static SPINAND_OP_VARIANTS(write_cache_variants,
0027         SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
0028         SPINAND_PROG_LOAD(true, 0, NULL, 0));
0029 
0030 static SPINAND_OP_VARIANTS(update_cache_variants,
0031         SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
0032         SPINAND_PROG_LOAD(false, 0, NULL, 0));
0033 
0034 static int w25m02gv_ooblayout_ecc(struct mtd_info *mtd, int section,
0035                   struct mtd_oob_region *region)
0036 {
0037     if (section > 3)
0038         return -ERANGE;
0039 
0040     region->offset = (16 * section) + 8;
0041     region->length = 8;
0042 
0043     return 0;
0044 }
0045 
0046 static int w25m02gv_ooblayout_free(struct mtd_info *mtd, int section,
0047                    struct mtd_oob_region *region)
0048 {
0049     if (section > 3)
0050         return -ERANGE;
0051 
0052     region->offset = (16 * section) + 2;
0053     region->length = 6;
0054 
0055     return 0;
0056 }
0057 
0058 static const struct mtd_ooblayout_ops w25m02gv_ooblayout = {
0059     .ecc = w25m02gv_ooblayout_ecc,
0060     .free = w25m02gv_ooblayout_free,
0061 };
0062 
0063 static int w25m02gv_select_target(struct spinand_device *spinand,
0064                   unsigned int target)
0065 {
0066     struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(0xc2, 1),
0067                       SPI_MEM_OP_NO_ADDR,
0068                       SPI_MEM_OP_NO_DUMMY,
0069                       SPI_MEM_OP_DATA_OUT(1,
0070                             spinand->scratchbuf,
0071                             1));
0072 
0073     *spinand->scratchbuf = target;
0074     return spi_mem_exec_op(spinand->spimem, &op);
0075 }
0076 
0077 static const struct spinand_info winbond_spinand_table[] = {
0078     SPINAND_INFO("W25M02GV",
0079              SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xab),
0080              NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 2),
0081              NAND_ECCREQ(1, 512),
0082              SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
0083                           &write_cache_variants,
0084                           &update_cache_variants),
0085              0,
0086              SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
0087              SPINAND_SELECT_TARGET(w25m02gv_select_target)),
0088     SPINAND_INFO("W25N01GV",
0089              SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa),
0090              NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
0091              NAND_ECCREQ(1, 512),
0092              SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
0093                           &write_cache_variants,
0094                           &update_cache_variants),
0095              0,
0096              SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)),
0097 };
0098 
0099 static int winbond_spinand_init(struct spinand_device *spinand)
0100 {
0101     struct nand_device *nand = spinand_to_nand(spinand);
0102     unsigned int i;
0103 
0104     /*
0105      * Make sure all dies are in buffer read mode and not continuous read
0106      * mode.
0107      */
0108     for (i = 0; i < nand->memorg.ntargets; i++) {
0109         spinand_select_target(spinand, i);
0110         spinand_upd_cfg(spinand, WINBOND_CFG_BUF_READ,
0111                 WINBOND_CFG_BUF_READ);
0112     }
0113 
0114     return 0;
0115 }
0116 
0117 static const struct spinand_manufacturer_ops winbond_spinand_manuf_ops = {
0118     .init = winbond_spinand_init,
0119 };
0120 
0121 const struct spinand_manufacturer winbond_spinand_manufacturer = {
0122     .id = SPINAND_MFR_WINBOND,
0123     .name = "Winbond",
0124     .chips = winbond_spinand_table,
0125     .nchips = ARRAY_SIZE(winbond_spinand_table),
0126     .ops = &winbond_spinand_manuf_ops,
0127 };