1 From 10949af1681d5bb5cdbcc012815c6e40eec17d02 Mon Sep 17 00:00:00 2001
2 From: Schrempf Frieder <frieder.schrempf@kontron.De>
3 Date: Thu, 8 Nov 2018 08:32:11 +0000
4 Subject: [PATCH 2/8] mtd: spinand: Add initial support for Toshiba TC58CVG2S0H
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Add minimal support for the Toshiba TC58CVG2S0H SPI NAND chip.
11 Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
12 Acked-by: Clément Péron <peron.clem@gmail.com>
13 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
15 drivers/mtd/nand/spi/Makefile | 2 +-
16 drivers/mtd/nand/spi/core.c | 1 +
17 drivers/mtd/nand/spi/toshiba.c | 137 +++++++++++++++++++++++++++++++++
18 include/linux/mtd/spinand.h | 1 +
19 4 files changed, 140 insertions(+), 1 deletion(-)
20 create mode 100644 drivers/mtd/nand/spi/toshiba.c
22 --- a/drivers/mtd/nand/spi/Makefile
23 +++ b/drivers/mtd/nand/spi/Makefile
25 # SPDX-License-Identifier: GPL-2.0
26 -spinand-objs := core.o macronix.o micron.o winbond.o
27 +spinand-objs := core.o macronix.o micron.o toshiba.o winbond.o
28 obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
29 --- a/drivers/mtd/nand/spi/core.c
30 +++ b/drivers/mtd/nand/spi/core.c
31 @@ -764,6 +764,7 @@ static const struct nand_ops spinand_ops
32 static const struct spinand_manufacturer *spinand_manufacturers[] = {
33 ¯onix_spinand_manufacturer,
34 µn_spinand_manufacturer,
35 + &toshiba_spinand_manufacturer,
36 &winbond_spinand_manufacturer,
40 +++ b/drivers/mtd/nand/spi/toshiba.c
42 +// SPDX-License-Identifier: GPL-2.0
44 + * Copyright (c) 2018 exceet electronics GmbH
45 + * Copyright (c) 2018 Kontron Electronics GmbH
47 + * Author: Frieder Schrempf <frieder.schrempf@kontron.de>
50 +#include <linux/device.h>
51 +#include <linux/kernel.h>
52 +#include <linux/mtd/spinand.h>
54 +#define SPINAND_MFR_TOSHIBA 0x98
55 +#define TOSH_STATUS_ECC_HAS_BITFLIPS_T (3 << 4)
57 +static SPINAND_OP_VARIANTS(read_cache_variants,
58 + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
59 + SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
60 + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
61 + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
63 +static SPINAND_OP_VARIANTS(write_cache_variants,
64 + SPINAND_PROG_LOAD(true, 0, NULL, 0));
66 +static SPINAND_OP_VARIANTS(update_cache_variants,
67 + SPINAND_PROG_LOAD(false, 0, NULL, 0));
69 +static int tc58cvg2s0h_ooblayout_ecc(struct mtd_info *mtd, int section,
70 + struct mtd_oob_region *region)
75 + region->offset = 128 + 16 * section;
76 + region->length = 16;
81 +static int tc58cvg2s0h_ooblayout_free(struct mtd_info *mtd, int section,
82 + struct mtd_oob_region *region)
87 + /* 2 bytes reserved for BBM */
89 + region->length = 126;
94 +static const struct mtd_ooblayout_ops tc58cvg2s0h_ooblayout = {
95 + .ecc = tc58cvg2s0h_ooblayout_ecc,
96 + .free = tc58cvg2s0h_ooblayout_free,
99 +static int tc58cvg2s0h_ecc_get_status(struct spinand_device *spinand,
102 + struct nand_device *nand = spinand_to_nand(spinand);
104 + struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, &mbf);
106 + switch (status & STATUS_ECC_MASK) {
107 + case STATUS_ECC_NO_BITFLIPS:
110 + case STATUS_ECC_UNCOR_ERROR:
113 + case STATUS_ECC_HAS_BITFLIPS:
114 + case TOSH_STATUS_ECC_HAS_BITFLIPS_T:
116 + * Let's try to retrieve the real maximum number of bitflips
117 + * in order to avoid forcing the wear-leveling layer to move
118 + * data around if it's not necessary.
120 + if (spi_mem_exec_op(spinand->spimem, &op))
121 + return nand->eccreq.strength;
125 + if (WARN_ON(mbf > nand->eccreq.strength || !mbf))
126 + return nand->eccreq.strength;
137 +static const struct spinand_info toshiba_spinand_table[] = {
138 + SPINAND_INFO("TC58CVG2S0H", 0xCD,
139 + NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 1),
140 + NAND_ECCREQ(8, 512),
141 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
142 + &write_cache_variants,
143 + &update_cache_variants),
144 + SPINAND_HAS_QE_BIT,
145 + SPINAND_ECCINFO(&tc58cvg2s0h_ooblayout,
146 + tc58cvg2s0h_ecc_get_status)),
149 +static int toshiba_spinand_detect(struct spinand_device *spinand)
151 + u8 *id = spinand->id.data;
155 + * Toshiba SPI NAND read ID needs a dummy byte,
156 + * so the first byte in id is garbage.
158 + if (id[1] != SPINAND_MFR_TOSHIBA)
161 + ret = spinand_match_and_init(spinand, toshiba_spinand_table,
162 + ARRAY_SIZE(toshiba_spinand_table),
170 +static const struct spinand_manufacturer_ops toshiba_spinand_manuf_ops = {
171 + .detect = toshiba_spinand_detect,
174 +const struct spinand_manufacturer toshiba_spinand_manufacturer = {
175 + .id = SPINAND_MFR_TOSHIBA,
177 + .ops = &toshiba_spinand_manuf_ops,
179 --- a/include/linux/mtd/spinand.h
180 +++ b/include/linux/mtd/spinand.h
181 @@ -196,6 +196,7 @@ struct spinand_manufacturer {
182 /* SPI NAND manufacturers */
183 extern const struct spinand_manufacturer macronix_spinand_manufacturer;
184 extern const struct spinand_manufacturer micron_spinand_manufacturer;
185 +extern const struct spinand_manufacturer toshiba_spinand_manufacturer;
186 extern const struct spinand_manufacturer winbond_spinand_manufacturer;