1 // SPDX-License-Identifier: GPL-2.0
3 // Driver for the SPI-NAND mode of Mediatek NAND Flash Interface
5 // Copyright (c) 2022 Chuanhong Guo <gch981213@gmail.com>
7 // This driver is based on the SPI-NAND mtd driver from Mediatek SDK:
9 // Copyright (C) 2020 MediaTek Inc.
10 // Author: Weijie Gao <weijie.gao@mediatek.com>
12 // This controller organize the page data as several interleaved sectors
13 // like the following: (sizeof(FDM + ECC) = snf->nfi_cfg.spare_size)
14 // +---------+------+------+---------+------+------+-----+
15 // | Sector1 | FDM1 | ECC1 | Sector2 | FDM2 | ECC2 | ... |
16 // +---------+------+------+---------+------+------+-----+
17 // With auto-format turned on, DMA only returns this part:
18 // +---------+---------+-----+
19 // | Sector1 | Sector2 | ... |
20 // +---------+---------+-----+
21 // The FDM data will be filled to the registers, and ECC parity data isn't
23 // With auto-format off, all ((Sector+FDM+ECC)*nsectors) will be read over DMA
24 // in it's original order shown in the first table. ECC can't be turned on when
25 // auto-format is off.
27 // However, Linux SPI-NAND driver expects the data returned as:
31 // where the page data is continuously stored instead of interleaved.
32 // So we assume all instructions matching the page_op template between ECC
33 // prepare_io_req and finish_io_req are for page cache r/w.
34 // Here's how this spi-mem driver operates when reading:
35 // 1. Always set snf->autofmt = true in prepare_io_req (even when ECC is off).
36 // 2. Perform page ops and let the controller fill the DMA bounce buffer with
37 // de-interleaved sector data and set FDM registers.
38 // 3. Return the data as:
39 // +---------+---------+-----+------+------+-----+
40 // | Sector1 | Sector2 | ... | FDM1 | FDM2 | ... |
41 // +---------+---------+-----+------+------+-----+
42 // 4. For other matching spi_mem ops outside a prepare/finish_io_req pair,
43 // read the data with auto-format off into the bounce buffer and copy
44 // needed data to the buffer specified in the request.
46 // Write requests operates in a similar manner.
47 // As a limitation of this strategy, we won't be able to access any ECC parity
48 // data at all in Linux.
50 // Here's the bad block mark situation on MTK chips:
51 // In older chips like mt7622, MTK uses the first FDM byte in the first sector
52 // as the bad block mark. After de-interleaving, this byte appears at [pagesize]
53 // in the returned data, which is the BBM position expected by kernel. However,
54 // the conventional bad block mark is the first byte of the OOB, which is part
55 // of the last sector data in the interleaved layout. Instead of fixing their
56 // hardware, MTK decided to address this inconsistency in software. On these
57 // later chips, the BootROM expects the following:
58 // 1. The [pagesize] byte on a nand page is used as BBM, which will appear at
59 // (page_size - (nsectors - 1) * spare_size) in the DMA buffer.
60 // 2. The original byte stored at that position in the DMA buffer will be stored
61 // as the first byte of the FDM section in the last sector.
62 // We can't disagree with the BootROM, so after de-interleaving, we need to
63 // perform the following swaps in read:
64 // 1. Store the BBM at [page_size - (nsectors - 1) * spare_size] to [page_size],
65 // which is the expected BBM position by kernel.
66 // 2. Store the page data byte at [pagesize + (nsectors-1) * fdm] back to
67 // [page_size - (nsectors - 1) * spare_size]
68 // Similarly, when writing, we need to perform swaps in the other direction.
70 #include <linux/kernel.h>
71 #include <linux/module.h>
72 #include <linux/init.h>
73 #include <linux/device.h>
74 #include <linux/mutex.h>
75 #include <linux/clk.h>
76 #include <linux/interrupt.h>
77 #include <linux/dma-mapping.h>
78 #include <linux/iopoll.h>
79 #include <linux/of_platform.h>
80 #include <linux/mtd/nand-ecc-mtk.h>
81 #include <linux/spi/spi.h>
82 #include <linux/spi/spi-mem.h>
83 #include <linux/mtd/nand.h>
86 #define NFI_CNFG 0x000
87 #define CNFG_OP_MODE_S 12
88 #define CNFG_OP_MODE_CUST 6
89 #define CNFG_OP_MODE_PROGRAM 3
90 #define CNFG_AUTO_FMT_EN BIT(9)
91 #define CNFG_HW_ECC_EN BIT(8)
92 #define CNFG_DMA_BURST_EN BIT(2)
93 #define CNFG_READ_MODE BIT(1)
94 #define CNFG_DMA_MODE BIT(0)
96 #define NFI_PAGEFMT 0x0004
97 #define NFI_SPARE_SIZE_LS_S 16
98 #define NFI_FDM_ECC_NUM_S 12
99 #define NFI_FDM_NUM_S 8
100 #define NFI_SPARE_SIZE_S 4
101 #define NFI_SEC_SEL_512 BIT(2)
102 #define NFI_PAGE_SIZE_S 0
103 #define NFI_PAGE_SIZE_512_2K 0
104 #define NFI_PAGE_SIZE_2K_4K 1
105 #define NFI_PAGE_SIZE_4K_8K 2
106 #define NFI_PAGE_SIZE_8K_16K 3
108 #define NFI_CON 0x008
109 #define CON_SEC_NUM_S 12
110 #define CON_BWR BIT(9)
111 #define CON_BRD BIT(8)
112 #define CON_NFI_RST BIT(1)
113 #define CON_FIFO_FLUSH BIT(0)
115 #define NFI_INTR_EN 0x010
116 #define NFI_INTR_STA 0x014
117 #define NFI_IRQ_INTR_EN BIT(31)
118 #define NFI_IRQ_CUS_READ BIT(8)
119 #define NFI_IRQ_CUS_PG BIT(7)
121 #define NFI_CMD 0x020
122 #define NFI_CMD_DUMMY_READ 0x00
123 #define NFI_CMD_DUMMY_WRITE 0x80
125 #define NFI_STRDATA 0x040
126 #define STR_DATA BIT(0)
128 #define NFI_STA 0x060
129 #define NFI_NAND_FSM GENMASK(28, 24)
130 #define NFI_FSM GENMASK(19, 16)
131 #define READ_EMPTY BIT(12)
133 #define NFI_FIFOSTA 0x064
134 #define FIFO_WR_REMAIN_S 8
135 #define FIFO_RD_REMAIN_S 0
137 #define NFI_ADDRCNTR 0x070
138 #define SEC_CNTR GENMASK(16, 12)
139 #define SEC_CNTR_S 12
140 #define NFI_SEC_CNTR(val) (((val)&SEC_CNTR) >> SEC_CNTR_S)
142 #define NFI_STRADDR 0x080
144 #define NFI_BYTELEN 0x084
145 #define BUS_SEC_CNTR(val) (((val)&SEC_CNTR) >> SEC_CNTR_S)
147 #define NFI_FDM0L 0x0a0
148 #define NFI_FDM0M 0x0a4
149 #define NFI_FDML(n) (NFI_FDM0L + (n)*8)
150 #define NFI_FDMM(n) (NFI_FDM0M + (n)*8)
152 #define NFI_DEBUG_CON1 0x220
153 #define WBUF_EN BIT(2)
155 #define NFI_MASTERSTA 0x224
156 #define MAS_ADDR GENMASK(11, 9)
157 #define MAS_RD GENMASK(8, 6)
158 #define MAS_WR GENMASK(5, 3)
159 #define MAS_RDDLY GENMASK(2, 0)
160 #define NFI_MASTERSTA_MASK_7622 (MAS_ADDR | MAS_RD | MAS_WR | MAS_RDDLY)
163 #define SNF_MAC_CTL 0x500
164 #define MAC_XIO_SEL BIT(4)
165 #define SF_MAC_EN BIT(3)
166 #define SF_TRIG BIT(2)
167 #define WIP_READY BIT(1)
170 #define SNF_MAC_OUTL 0x504
171 #define SNF_MAC_INL 0x508
173 #define SNF_RD_CTL2 0x510
174 #define DATA_READ_DUMMY_S 8
175 #define DATA_READ_MAX_DUMMY 0xf
176 #define DATA_READ_CMD_S 0
178 #define SNF_RD_CTL3 0x514
180 #define SNF_PG_CTL1 0x524
181 #define PG_LOAD_CMD_S 8
183 #define SNF_PG_CTL2 0x528
185 #define SNF_MISC_CTL 0x538
186 #define SW_RST BIT(28)
187 #define FIFO_RD_LTC_S 25
188 #define PG_LOAD_X4_EN BIT(20)
189 #define DATA_READ_MODE_S 16
190 #define DATA_READ_MODE GENMASK(18, 16)
191 #define DATA_READ_MODE_X1 0
192 #define DATA_READ_MODE_X2 1
193 #define DATA_READ_MODE_X4 2
194 #define DATA_READ_MODE_DUAL 5
195 #define DATA_READ_MODE_QUAD 6
196 #define PG_LOAD_CUSTOM_EN BIT(7)
197 #define DATARD_CUSTOM_EN BIT(6)
198 #define CS_DESELECT_CYC_S 0
200 #define SNF_MISC_CTL2 0x53c
201 #define PROGRAM_LOAD_BYTE_NUM_S 16
202 #define READ_DATA_BYTE_NUM_S 11
204 #define SNF_DLY_CTL3 0x548
205 #define SFCK_SAM_DLY_S 0
207 #define SNF_STA_CTL1 0x550
208 #define CUS_PG_DONE BIT(28)
209 #define CUS_READ_DONE BIT(27)
210 #define SPI_STATE_S 0
211 #define SPI_STATE GENMASK(3, 0)
213 #define SNF_CFG 0x55c
214 #define SPI_MODE BIT(0)
216 #define SNF_GPRAM 0x800
217 #define SNF_GPRAM_SIZE 0xa0
219 #define SNFI_POLL_INTERVAL 1000000
221 static const u8 mt7622_spare_sizes[] = { 16, 26, 27, 28 };
223 struct mtk_snand_caps {
231 bool empty_page_check;
234 const u8 *spare_sizes;
238 static const struct mtk_snand_caps mt7622_snand_caps = {
245 .empty_page_check = false,
246 .mastersta_mask = NFI_MASTERSTA_MASK_7622,
247 .spare_sizes = mt7622_spare_sizes,
248 .num_spare_size = ARRAY_SIZE(mt7622_spare_sizes)
251 static const struct mtk_snand_caps mt7629_snand_caps = {
258 .empty_page_check = false,
259 .mastersta_mask = NFI_MASTERSTA_MASK_7622,
260 .spare_sizes = mt7622_spare_sizes,
261 .num_spare_size = ARRAY_SIZE(mt7622_spare_sizes)
264 struct mtk_snand_conf {
272 struct spi_controller *ctlr;
276 void __iomem *nfi_base;
278 struct completion op_done;
279 const struct mtk_snand_caps *caps;
280 struct mtk_ecc_config *ecc_cfg;
282 struct mtk_snand_conf nfi_cfg;
283 struct mtk_ecc_stats ecc_stats;
284 struct nand_ecc_engine ecc_eng;
290 static struct mtk_snand *nand_to_mtk_snand(struct nand_device *nand)
292 struct nand_ecc_engine *eng = nand->ecc.engine;
294 return container_of(eng, struct mtk_snand, ecc_eng);
297 static inline int snand_prepare_bouncebuf(struct mtk_snand *snf, size_t size)
299 if (snf->buf_len >= size)
302 snf->buf = kmalloc(size, GFP_KERNEL);
306 memset(snf->buf, 0xff, snf->buf_len);
310 static inline u32 nfi_read32(struct mtk_snand *snf, u32 reg)
312 return readl(snf->nfi_base + reg);
315 static inline void nfi_write32(struct mtk_snand *snf, u32 reg, u32 val)
317 writel(val, snf->nfi_base + reg);
320 static inline void nfi_write16(struct mtk_snand *snf, u32 reg, u16 val)
322 writew(val, snf->nfi_base + reg);
325 static inline void nfi_rmw32(struct mtk_snand *snf, u32 reg, u32 clr, u32 set)
329 val = readl(snf->nfi_base + reg);
332 writel(val, snf->nfi_base + reg);
335 static void nfi_read_data(struct mtk_snand *snf, u32 reg, u8 *data, u32 len)
337 u32 i, val = 0, es = sizeof(u32);
339 for (i = reg; i < reg + len; i++) {
340 if (i == reg || i % es == 0)
341 val = nfi_read32(snf, i & ~(es - 1));
343 *data++ = (u8)(val >> (8 * (i % es)));
347 static int mtk_nfi_reset(struct mtk_snand *snf)
352 nfi_write32(snf, NFI_CON, CON_FIFO_FLUSH | CON_NFI_RST);
354 ret = readw_poll_timeout(snf->nfi_base + NFI_MASTERSTA, val,
355 !(val & snf->caps->mastersta_mask), 0,
358 dev_err(snf->dev, "NFI master is still busy after reset\n");
362 ret = readl_poll_timeout(snf->nfi_base + NFI_STA, val,
363 !(val & (NFI_FSM | NFI_NAND_FSM)), 0,
366 dev_err(snf->dev, "Failed to reset NFI\n");
370 fifo_mask = ((snf->caps->fifo_size - 1) << FIFO_RD_REMAIN_S) |
371 ((snf->caps->fifo_size - 1) << FIFO_WR_REMAIN_S);
372 ret = readw_poll_timeout(snf->nfi_base + NFI_FIFOSTA, val,
373 !(val & fifo_mask), 0, SNFI_POLL_INTERVAL);
375 dev_err(snf->dev, "NFI FIFOs are not empty\n");
382 static int mtk_snand_mac_reset(struct mtk_snand *snf)
387 nfi_rmw32(snf, SNF_MISC_CTL, 0, SW_RST);
389 ret = readl_poll_timeout(snf->nfi_base + SNF_STA_CTL1, val,
390 !(val & SPI_STATE), 0, SNFI_POLL_INTERVAL);
392 dev_err(snf->dev, "Failed to reset SNFI MAC\n");
394 nfi_write32(snf, SNF_MISC_CTL,
395 (2 << FIFO_RD_LTC_S) | (10 << CS_DESELECT_CYC_S));
400 static int mtk_snand_mac_trigger(struct mtk_snand *snf, u32 outlen, u32 inlen)
405 nfi_write32(snf, SNF_MAC_CTL, SF_MAC_EN);
406 nfi_write32(snf, SNF_MAC_OUTL, outlen);
407 nfi_write32(snf, SNF_MAC_INL, inlen);
409 nfi_write32(snf, SNF_MAC_CTL, SF_MAC_EN | SF_TRIG);
411 ret = readl_poll_timeout(snf->nfi_base + SNF_MAC_CTL, val,
412 val & WIP_READY, 0, SNFI_POLL_INTERVAL);
414 dev_err(snf->dev, "Timed out waiting for WIP_READY\n");
418 ret = readl_poll_timeout(snf->nfi_base + SNF_MAC_CTL, val, !(val & WIP),
419 0, SNFI_POLL_INTERVAL);
421 dev_err(snf->dev, "Timed out waiting for WIP cleared\n");
424 nfi_write32(snf, SNF_MAC_CTL, 0);
429 static int mtk_snand_mac_io(struct mtk_snand *snf, const struct spi_mem_op *op)
434 const u8 *tx_buf = NULL;
439 if (op->data.dir == SPI_MEM_DATA_IN) {
440 rx_len = op->data.nbytes;
441 rx_buf = op->data.buf.in;
443 tx_buf = op->data.buf.out;
446 mtk_snand_mac_reset(snf);
448 for (i = 0; i < op->cmd.nbytes; i++, reg_offs++) {
449 b = (op->cmd.opcode >> ((op->cmd.nbytes - i - 1) * 8)) & 0xff;
450 val |= b << (8 * (reg_offs % 4));
451 if (reg_offs % 4 == 3) {
452 nfi_write32(snf, SNF_GPRAM + reg_offs - 3, val);
457 for (i = 0; i < op->addr.nbytes; i++, reg_offs++) {
458 b = (op->addr.val >> ((op->addr.nbytes - i - 1) * 8)) & 0xff;
459 val |= b << (8 * (reg_offs % 4));
460 if (reg_offs % 4 == 3) {
461 nfi_write32(snf, SNF_GPRAM + reg_offs - 3, val);
466 for (i = 0; i < op->dummy.nbytes; i++, reg_offs++) {
467 if (reg_offs % 4 == 3) {
468 nfi_write32(snf, SNF_GPRAM + reg_offs - 3, val);
473 if (op->data.dir == SPI_MEM_DATA_OUT) {
474 for (i = 0; i < op->data.nbytes; i++, reg_offs++) {
475 val |= tx_buf[i] << (8 * (reg_offs % 4));
476 if (reg_offs % 4 == 3) {
477 nfi_write32(snf, SNF_GPRAM + reg_offs - 3, val);
484 nfi_write32(snf, SNF_GPRAM + (reg_offs & ~3), val);
486 for (i = 0; i < reg_offs; i += 4)
487 dev_dbg(snf->dev, "%d: %08X", i,
488 nfi_read32(snf, SNF_GPRAM + i));
490 dev_dbg(snf->dev, "SNF TX: %u RX: %u", reg_offs, rx_len);
492 ret = mtk_snand_mac_trigger(snf, reg_offs, rx_len);
499 nfi_read_data(snf, SNF_GPRAM + reg_offs, rx_buf, rx_len);
503 static int mtk_snand_setup_pagefmt(struct mtk_snand *snf, u32 page_size,
507 u32 spare_size, spare_size_shift, pagesize_idx;
512 // skip if it's already configured as required.
513 if (snf->nfi_cfg.page_size == page_size &&
514 snf->nfi_cfg.oob_size == oob_size)
517 nsectors = page_size / snf->caps->sector_size;
518 if (nsectors > snf->caps->max_sectors) {
519 dev_err(snf->dev, "too many sectors required.\n");
523 if (snf->caps->sector_size == 512) {
524 sector_size_512 = NFI_SEC_SEL_512;
525 spare_size_shift = NFI_SPARE_SIZE_S;
528 spare_size_shift = NFI_SPARE_SIZE_LS_S;
533 pagesize_idx = NFI_PAGE_SIZE_512_2K;
536 if (snf->caps->sector_size == 512)
537 pagesize_idx = NFI_PAGE_SIZE_2K_4K;
539 pagesize_idx = NFI_PAGE_SIZE_512_2K;
542 if (snf->caps->sector_size == 512)
543 pagesize_idx = NFI_PAGE_SIZE_4K_8K;
545 pagesize_idx = NFI_PAGE_SIZE_2K_4K;
548 if (snf->caps->sector_size == 512)
549 pagesize_idx = NFI_PAGE_SIZE_8K_16K;
551 pagesize_idx = NFI_PAGE_SIZE_4K_8K;
554 pagesize_idx = NFI_PAGE_SIZE_8K_16K;
557 dev_err(snf->dev, "unsupported page size.\n");
561 spare_size = oob_size / nsectors;
562 // If we're using the 1KB sector size, HW will automatically double the
563 // spare size. We should only use half of the value in this case.
564 if (snf->caps->sector_size == 1024)
567 for (i = snf->caps->num_spare_size - 1; i >= 0; i--) {
568 if (snf->caps->spare_sizes[i] <= spare_size) {
569 spare_size = snf->caps->spare_sizes[i];
570 if (snf->caps->sector_size == 1024)
578 dev_err(snf->dev, "unsupported spare size: %u\n", spare_size);
582 nfi_write32(snf, NFI_PAGEFMT,
583 (snf->caps->fdm_ecc_size << NFI_FDM_ECC_NUM_S) |
584 (snf->caps->fdm_size << NFI_FDM_NUM_S) |
585 (spare_idx << spare_size_shift) |
586 (pagesize_idx << NFI_PAGE_SIZE_S) |
589 snf->nfi_cfg.page_size = page_size;
590 snf->nfi_cfg.oob_size = oob_size;
591 snf->nfi_cfg.nsectors = nsectors;
592 snf->nfi_cfg.spare_size = spare_size;
594 dev_dbg(snf->dev, "page format: (%u + %u) * %u\n",
595 snf->caps->sector_size, spare_size, nsectors);
596 return snand_prepare_bouncebuf(snf, page_size + oob_size);
598 dev_err(snf->dev, "page size %u + %u is not supported\n", page_size,
603 static int mtk_snand_ooblayout_ecc(struct mtd_info *mtd, int section,
604 struct mtd_oob_region *oobecc)
606 // ECC area is not accessible
610 static int mtk_snand_ooblayout_free(struct mtd_info *mtd, int section,
611 struct mtd_oob_region *oobfree)
613 struct nand_device *nand = mtd_to_nanddev(mtd);
614 struct mtk_snand *ms = nand_to_mtk_snand(nand);
616 if (section >= ms->nfi_cfg.nsectors)
619 oobfree->length = ms->caps->fdm_size - 1;
620 oobfree->offset = section * ms->caps->fdm_size + 1;
624 static const struct mtd_ooblayout_ops mtk_snand_ooblayout = {
625 .ecc = mtk_snand_ooblayout_ecc,
626 .free = mtk_snand_ooblayout_free,
629 static int mtk_snand_ecc_init_ctx(struct nand_device *nand)
631 struct mtk_snand *snf = nand_to_mtk_snand(nand);
632 struct nand_ecc_props *conf = &nand->ecc.ctx.conf;
633 struct nand_ecc_props *reqs = &nand->ecc.requirements;
634 struct nand_ecc_props *user = &nand->ecc.user_conf;
635 struct mtd_info *mtd = nanddev_to_mtd(nand);
636 int step_size = 0, strength = 0, desired_correction = 0, steps;
637 bool ecc_user = false;
639 u32 parity_bits, max_ecc_bytes;
640 struct mtk_ecc_config *ecc_cfg;
642 ret = mtk_snand_setup_pagefmt(snf, nand->memorg.pagesize,
643 nand->memorg.oobsize);
647 ecc_cfg = kzalloc(sizeof(*ecc_cfg), GFP_KERNEL);
651 nand->ecc.ctx.priv = ecc_cfg;
653 if (user->step_size && user->strength) {
654 step_size = user->step_size;
655 strength = user->strength;
657 } else if (reqs->step_size && reqs->strength) {
658 step_size = reqs->step_size;
659 strength = reqs->strength;
662 if (step_size && strength) {
663 steps = mtd->writesize / step_size;
664 desired_correction = steps * strength;
665 strength = desired_correction / snf->nfi_cfg.nsectors;
668 ecc_cfg->mode = ECC_NFI_MODE;
669 ecc_cfg->sectors = snf->nfi_cfg.nsectors;
670 ecc_cfg->len = snf->caps->sector_size + snf->caps->fdm_ecc_size;
672 // calculate the max possible strength under current page format
673 parity_bits = mtk_ecc_get_parity_bits(snf->ecc);
674 max_ecc_bytes = snf->nfi_cfg.spare_size - snf->caps->fdm_size;
675 ecc_cfg->strength = max_ecc_bytes * 8 / parity_bits;
676 mtk_ecc_adjust_strength(snf->ecc, &ecc_cfg->strength);
678 // if there's a user requested strength, find the minimum strength that
679 // meets the requirement. Otherwise use the maximum strength which is
680 // expected by BootROM.
681 if (ecc_user && strength) {
682 u32 s_next = ecc_cfg->strength - 1;
685 mtk_ecc_adjust_strength(snf->ecc, &s_next);
686 if (s_next >= ecc_cfg->strength)
688 if (s_next < strength)
690 s_next = ecc_cfg->strength - 1;
694 mtd_set_ooblayout(mtd, &mtk_snand_ooblayout);
696 conf->step_size = snf->caps->sector_size;
697 conf->strength = ecc_cfg->strength;
699 if (ecc_cfg->strength < strength)
700 dev_warn(snf->dev, "unable to fulfill ECC of %u bits.\n",
702 dev_info(snf->dev, "ECC strength: %u bits per %u bytes\n",
703 ecc_cfg->strength, snf->caps->sector_size);
708 static void mtk_snand_ecc_cleanup_ctx(struct nand_device *nand)
710 struct mtk_ecc_config *ecc_cfg = nand_to_ecc_ctx(nand);
715 static int mtk_snand_ecc_prepare_io_req(struct nand_device *nand,
716 struct nand_page_io_req *req)
718 struct mtk_snand *snf = nand_to_mtk_snand(nand);
719 struct mtk_ecc_config *ecc_cfg = nand_to_ecc_ctx(nand);
722 ret = mtk_snand_setup_pagefmt(snf, nand->memorg.pagesize,
723 nand->memorg.oobsize);
727 snf->ecc_cfg = ecc_cfg;
731 static int mtk_snand_ecc_finish_io_req(struct nand_device *nand,
732 struct nand_page_io_req *req)
734 struct mtk_snand *snf = nand_to_mtk_snand(nand);
735 struct mtd_info *mtd = nanddev_to_mtd(nand);
738 snf->autofmt = false;
739 if ((req->mode == MTD_OPS_RAW) || (req->type != NAND_PAGE_READ))
742 if (snf->ecc_stats.failed)
743 mtd->ecc_stats.failed += snf->ecc_stats.failed;
744 mtd->ecc_stats.corrected += snf->ecc_stats.corrected;
745 return snf->ecc_stats.failed ? -EBADMSG : snf->ecc_stats.bitflips;
748 static struct nand_ecc_engine_ops mtk_snfi_ecc_engine_ops = {
749 .init_ctx = mtk_snand_ecc_init_ctx,
750 .cleanup_ctx = mtk_snand_ecc_cleanup_ctx,
751 .prepare_io_req = mtk_snand_ecc_prepare_io_req,
752 .finish_io_req = mtk_snand_ecc_finish_io_req,
755 static void mtk_snand_read_fdm(struct mtk_snand *snf, u8 *buf)
761 for (i = 0; i < snf->nfi_cfg.nsectors; i++) {
762 vall = nfi_read32(snf, NFI_FDML(i));
763 valm = nfi_read32(snf, NFI_FDMM(i));
765 for (j = 0; j < snf->caps->fdm_size; j++)
766 oobptr[j] = (j >= 4 ? valm : vall) >> ((j % 4) * 8);
768 oobptr += snf->caps->fdm_size;
772 static void mtk_snand_write_fdm(struct mtk_snand *snf, const u8 *buf)
774 u32 fdm_size = snf->caps->fdm_size;
775 const u8 *oobptr = buf;
779 for (i = 0; i < snf->nfi_cfg.nsectors; i++) {
783 for (j = 0; j < 8; j++) {
785 vall |= (j < fdm_size ? oobptr[j] : 0xff)
788 valm |= (j < fdm_size ? oobptr[j] : 0xff)
792 nfi_write32(snf, NFI_FDML(i), vall);
793 nfi_write32(snf, NFI_FDMM(i), valm);
799 static void mtk_snand_bm_swap(struct mtk_snand *snf, u8 *buf)
801 u32 buf_bbm_pos, fdm_bbm_pos;
803 if (!snf->caps->bbm_swap || snf->nfi_cfg.nsectors == 1)
806 // swap [pagesize] byte on nand with the first fdm byte
807 // in the last sector.
808 buf_bbm_pos = snf->nfi_cfg.page_size -
809 (snf->nfi_cfg.nsectors - 1) * snf->nfi_cfg.spare_size;
810 fdm_bbm_pos = snf->nfi_cfg.page_size +
811 (snf->nfi_cfg.nsectors - 1) * snf->caps->fdm_size;
813 swap(snf->buf[fdm_bbm_pos], buf[buf_bbm_pos]);
816 static void mtk_snand_fdm_bm_swap(struct mtk_snand *snf)
818 u32 fdm_bbm_pos1, fdm_bbm_pos2;
820 if (!snf->caps->bbm_swap || snf->nfi_cfg.nsectors == 1)
823 // swap the first fdm byte in the first and the last sector.
824 fdm_bbm_pos1 = snf->nfi_cfg.page_size;
825 fdm_bbm_pos2 = snf->nfi_cfg.page_size +
826 (snf->nfi_cfg.nsectors - 1) * snf->caps->fdm_size;
827 swap(snf->buf[fdm_bbm_pos1], snf->buf[fdm_bbm_pos2]);
830 static int mtk_snand_read_page_cache(struct mtk_snand *snf,
831 const struct spi_mem_op *op)
834 u8 *buf_fdm = buf + snf->nfi_cfg.page_size;
835 // the address part to be sent by the controller
836 u32 op_addr = op->addr.val;
837 // where to start copying data from bounce buffer
839 u32 dummy_clk = (op->dummy.nbytes * BITS_PER_BYTE / op->dummy.buswidth);
841 u32 dma_len = snf->buf_len;
843 u32 rd_mode, rd_bytes, val;
850 dma_len = snf->nfi_cfg.page_size;
851 op_mode = CNFG_AUTO_FMT_EN;
853 op_mode |= CNFG_HW_ECC_EN;
854 // extract the plane bit:
855 // Find the highest bit set in (pagesize+oobsize).
856 // Bits higher than that in op->addr are kept and sent over SPI
857 // Lower bits are used as an offset for copying data from DMA
859 last_bit = fls(snf->nfi_cfg.page_size + snf->nfi_cfg.oob_size);
860 mask = (1 << last_bit) - 1;
861 rd_offset = op_addr & mask;
864 // check if we can dma to the caller memory
865 if (rd_offset == 0 && op->data.nbytes >= snf->nfi_cfg.page_size)
866 buf = op->data.buf.in;
868 mtk_snand_mac_reset(snf);
871 // command and dummy cycles
872 nfi_write32(snf, SNF_RD_CTL2,
873 (dummy_clk << DATA_READ_DUMMY_S) |
874 (op->cmd.opcode << DATA_READ_CMD_S));
877 nfi_write32(snf, SNF_RD_CTL3, op_addr);
880 if (op->data.buswidth == 4)
881 rd_mode = op->addr.buswidth == 4 ? DATA_READ_MODE_QUAD :
883 else if (op->data.buswidth == 2)
884 rd_mode = op->addr.buswidth == 2 ? DATA_READ_MODE_DUAL :
887 rd_mode = DATA_READ_MODE_X1;
888 rd_mode <<= DATA_READ_MODE_S;
889 nfi_rmw32(snf, SNF_MISC_CTL, DATA_READ_MODE,
890 rd_mode | DATARD_CUSTOM_EN);
893 rd_bytes = (snf->nfi_cfg.spare_size + snf->caps->sector_size) *
894 snf->nfi_cfg.nsectors;
895 nfi_write32(snf, SNF_MISC_CTL2,
896 (rd_bytes << PROGRAM_LOAD_BYTE_NUM_S) | rd_bytes);
899 nfi_write16(snf, NFI_CNFG,
900 (CNFG_OP_MODE_CUST << CNFG_OP_MODE_S) | CNFG_DMA_BURST_EN |
901 CNFG_READ_MODE | CNFG_DMA_MODE | op_mode);
903 nfi_write32(snf, NFI_CON, (snf->nfi_cfg.nsectors << CON_SEC_NUM_S));
905 buf_dma = dma_map_single(snf->dev, buf, dma_len, DMA_FROM_DEVICE);
906 ret = dma_mapping_error(snf->dev, buf_dma);
908 dev_err(snf->dev, "DMA mapping failed.\n");
911 nfi_write32(snf, NFI_STRADDR, buf_dma);
913 snf->ecc_cfg->op = ECC_DECODE;
914 ret = mtk_ecc_enable(snf->ecc, snf->ecc_cfg);
918 // Prepare for custom read interrupt
919 nfi_write32(snf, NFI_INTR_EN, NFI_IRQ_INTR_EN | NFI_IRQ_CUS_READ);
920 reinit_completion(&snf->op_done);
922 // Trigger NFI into custom mode
923 nfi_write16(snf, NFI_CMD, NFI_CMD_DUMMY_READ);
926 nfi_rmw32(snf, NFI_CON, 0, CON_BRD);
927 nfi_write16(snf, NFI_STRDATA, STR_DATA);
929 if (!wait_for_completion_timeout(
930 &snf->op_done, usecs_to_jiffies(SNFI_POLL_INTERVAL))) {
931 dev_err(snf->dev, "DMA timed out for reading from cache.\n");
936 // Wait for BUS_SEC_CNTR returning expected value
937 ret = readl_poll_timeout(snf->nfi_base + NFI_BYTELEN, val,
938 BUS_SEC_CNTR(val) >= snf->nfi_cfg.nsectors, 0,
941 dev_err(snf->dev, "Timed out waiting for BUS_SEC_CNTR\n");
945 // Wait for bus becoming idle
946 ret = readl_poll_timeout(snf->nfi_base + NFI_MASTERSTA, val,
947 !(val & snf->caps->mastersta_mask), 0,
950 dev_err(snf->dev, "Timed out waiting for bus becoming idle\n");
955 ret = mtk_ecc_wait_done(snf->ecc, ECC_DECODE);
957 dev_err(snf->dev, "wait ecc done timeout\n");
960 // save status before disabling ecc
961 mtk_ecc_get_stats(snf->ecc, &snf->ecc_stats,
962 snf->nfi_cfg.nsectors);
965 dma_unmap_single(snf->dev, buf_dma, dma_len, DMA_FROM_DEVICE);
968 mtk_snand_read_fdm(snf, buf_fdm);
969 if (snf->caps->bbm_swap) {
970 mtk_snand_bm_swap(snf, buf);
971 mtk_snand_fdm_bm_swap(snf);
976 if (nfi_read32(snf, NFI_STA) & READ_EMPTY) {
977 memset(op->data.buf.in, 0xff, op->data.nbytes);
978 snf->ecc_stats.bitflips = 0;
979 snf->ecc_stats.failed = 0;
980 snf->ecc_stats.corrected = 0;
982 if (buf == op->data.buf.in) {
983 u32 cap_len = snf->buf_len - snf->nfi_cfg.page_size;
984 u32 req_left = op->data.nbytes - snf->nfi_cfg.page_size;
987 memcpy(op->data.buf.in + snf->nfi_cfg.page_size,
989 cap_len < req_left ? cap_len : req_left);
990 } else if (rd_offset < snf->buf_len) {
991 u32 cap_len = snf->buf_len - rd_offset;
993 if (op->data.nbytes < cap_len)
994 cap_len = op->data.nbytes;
995 memcpy(op->data.buf.in, snf->buf + rd_offset, cap_len);
1000 mtk_ecc_disable(snf->ecc);
1002 // unmap dma only if any error happens. (otherwise it's done before
1005 dma_unmap_single(snf->dev, buf_dma, dma_len, DMA_FROM_DEVICE);
1008 nfi_write32(snf, NFI_CON, 0);
1009 nfi_write16(snf, NFI_CNFG, 0);
1011 // Clear SNF done flag
1012 nfi_rmw32(snf, SNF_STA_CTL1, 0, CUS_READ_DONE);
1013 nfi_write32(snf, SNF_STA_CTL1, 0);
1015 // Disable interrupt
1016 nfi_read32(snf, NFI_INTR_STA);
1017 nfi_write32(snf, NFI_INTR_EN, 0);
1019 nfi_rmw32(snf, SNF_MISC_CTL, DATARD_CUSTOM_EN, 0);
1023 static int mtk_snand_write_page_cache(struct mtk_snand *snf,
1024 const struct spi_mem_op *op)
1026 // the address part to be sent by the controller
1027 u32 op_addr = op->addr.val;
1028 // where to start copying data from bounce buffer
1033 u32 dma_len = snf->buf_len;
1042 dma_len = snf->nfi_cfg.page_size;
1043 op_mode = CNFG_AUTO_FMT_EN;
1045 op_mode |= CNFG_HW_ECC_EN;
1047 last_bit = fls(snf->nfi_cfg.page_size + snf->nfi_cfg.oob_size);
1048 mask = (1 << last_bit) - 1;
1049 wr_offset = op_addr & mask;
1052 mtk_snand_mac_reset(snf);
1056 memset(snf->buf, 0xff, wr_offset);
1058 cap_len = snf->buf_len - wr_offset;
1059 if (op->data.nbytes < cap_len)
1060 cap_len = op->data.nbytes;
1061 memcpy(snf->buf + wr_offset, op->data.buf.out, cap_len);
1063 if (snf->caps->bbm_swap) {
1064 mtk_snand_fdm_bm_swap(snf);
1065 mtk_snand_bm_swap(snf, snf->buf);
1067 mtk_snand_write_fdm(snf, snf->buf + snf->nfi_cfg.page_size);
1071 nfi_write32(snf, SNF_PG_CTL1, (op->cmd.opcode << PG_LOAD_CMD_S));
1074 nfi_write32(snf, SNF_PG_CTL2, op_addr);
1077 if (op->data.buswidth == 4)
1078 wr_mode = PG_LOAD_X4_EN;
1080 nfi_rmw32(snf, SNF_MISC_CTL, PG_LOAD_X4_EN,
1081 wr_mode | PG_LOAD_CUSTOM_EN);
1083 // Set bytes to write
1084 wr_bytes = (snf->nfi_cfg.spare_size + snf->caps->sector_size) *
1085 snf->nfi_cfg.nsectors;
1086 nfi_write32(snf, SNF_MISC_CTL2,
1087 (wr_bytes << PROGRAM_LOAD_BYTE_NUM_S) | wr_bytes);
1089 // NFI write prepare
1090 nfi_write16(snf, NFI_CNFG,
1091 (CNFG_OP_MODE_PROGRAM << CNFG_OP_MODE_S) |
1092 CNFG_DMA_BURST_EN | CNFG_DMA_MODE | op_mode);
1094 nfi_write32(snf, NFI_CON, (snf->nfi_cfg.nsectors << CON_SEC_NUM_S));
1095 buf_dma = dma_map_single(snf->dev, snf->buf, dma_len, DMA_TO_DEVICE);
1096 ret = dma_mapping_error(snf->dev, buf_dma);
1098 dev_err(snf->dev, "DMA mapping failed.\n");
1101 nfi_write32(snf, NFI_STRADDR, buf_dma);
1103 snf->ecc_cfg->op = ECC_ENCODE;
1104 ret = mtk_ecc_enable(snf->ecc, snf->ecc_cfg);
1108 // Prepare for custom write interrupt
1109 nfi_write32(snf, NFI_INTR_EN, NFI_IRQ_INTR_EN | NFI_IRQ_CUS_PG);
1110 reinit_completion(&snf->op_done);
1113 // Trigger NFI into custom mode
1114 nfi_write16(snf, NFI_CMD, NFI_CMD_DUMMY_WRITE);
1117 nfi_rmw32(snf, NFI_CON, 0, CON_BWR);
1118 nfi_write16(snf, NFI_STRDATA, STR_DATA);
1120 if (!wait_for_completion_timeout(
1121 &snf->op_done, usecs_to_jiffies(SNFI_POLL_INTERVAL))) {
1122 dev_err(snf->dev, "DMA timed out for program load.\n");
1127 // Wait for NFI_SEC_CNTR returning expected value
1128 ret = readl_poll_timeout(snf->nfi_base + NFI_ADDRCNTR, val,
1129 NFI_SEC_CNTR(val) >= snf->nfi_cfg.nsectors, 0,
1130 SNFI_POLL_INTERVAL);
1132 dev_err(snf->dev, "Timed out waiting for NFI_SEC_CNTR\n");
1136 mtk_ecc_disable(snf->ecc);
1138 dma_unmap_single(snf->dev, buf_dma, dma_len, DMA_TO_DEVICE);
1141 nfi_write32(snf, NFI_CON, 0);
1142 nfi_write16(snf, NFI_CNFG, 0);
1144 // Clear SNF done flag
1145 nfi_rmw32(snf, SNF_STA_CTL1, 0, CUS_PG_DONE);
1146 nfi_write32(snf, SNF_STA_CTL1, 0);
1148 // Disable interrupt
1149 nfi_read32(snf, NFI_INTR_STA);
1150 nfi_write32(snf, NFI_INTR_EN, 0);
1152 nfi_rmw32(snf, SNF_MISC_CTL, PG_LOAD_CUSTOM_EN, 0);
1158 * mtk_snand_is_page_ops() - check if the op is a controller supported page op.
1159 * @op spi-mem op to check
1161 * Check whether op can be executed with read_from_cache or program_load
1162 * mode in the controller.
1163 * This controller can execute typical Read From Cache and Program Load
1164 * instructions found on SPI-NAND with 2-byte address.
1165 * DTR and cmd buswidth & nbytes should be checked before calling this.
1167 * Return: true if the op matches the instruction template
1169 static bool mtk_snand_is_page_ops(const struct spi_mem_op *op)
1171 if (op->addr.nbytes != 2)
1174 if (op->addr.buswidth != 1 && op->addr.buswidth != 2 &&
1175 op->addr.buswidth != 4)
1178 // match read from page instructions
1179 if (op->data.dir == SPI_MEM_DATA_IN) {
1180 // check dummy cycle first
1181 if (op->dummy.nbytes * BITS_PER_BYTE / op->dummy.buswidth >
1182 DATA_READ_MAX_DUMMY)
1184 // quad io / quad out
1185 if ((op->addr.buswidth == 4 || op->addr.buswidth == 1) &&
1186 op->data.buswidth == 4)
1189 // dual io / dual out
1190 if ((op->addr.buswidth == 2 || op->addr.buswidth == 1) &&
1191 op->data.buswidth == 2)
1195 if (op->addr.buswidth == 1 && op->data.buswidth == 1)
1197 } else if (op->data.dir == SPI_MEM_DATA_OUT) {
1198 // check dummy cycle first
1199 if (op->dummy.nbytes)
1201 // program load quad out
1202 if (op->addr.buswidth == 1 && op->data.buswidth == 4)
1205 if (op->addr.buswidth == 1 && op->data.buswidth == 1)
1211 static bool mtk_snand_supports_op(struct spi_mem *mem,
1212 const struct spi_mem_op *op)
1214 if (!spi_mem_default_supports_op(mem, op))
1216 if (op->cmd.nbytes != 1 || op->cmd.buswidth != 1)
1218 if (mtk_snand_is_page_ops(op))
1220 return ((op->addr.nbytes == 0 || op->addr.buswidth == 1) &&
1221 (op->dummy.nbytes == 0 || op->dummy.buswidth == 1) &&
1222 (op->data.nbytes == 0 || op->data.buswidth == 1));
1225 static int mtk_snand_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
1227 struct mtk_snand *ms = spi_controller_get_devdata(mem->spi->master);
1228 // page ops transfer size must be exactly ((sector_size + spare_size) *
1229 // nsectors). Limit the op size if the caller requests more than that.
1230 // exec_op will read more than needed and discard the leftover if the
1231 // caller requests less data.
1232 if (mtk_snand_is_page_ops(op)) {
1234 // skip adjust_op_size for page ops
1237 l = ms->caps->sector_size + ms->nfi_cfg.spare_size;
1238 l *= ms->nfi_cfg.nsectors;
1239 if (op->data.nbytes > l)
1240 op->data.nbytes = l;
1242 size_t hl = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes;
1244 if (hl >= SNF_GPRAM_SIZE)
1246 if (op->data.nbytes > SNF_GPRAM_SIZE - hl)
1247 op->data.nbytes = SNF_GPRAM_SIZE - hl;
1252 static int mtk_snand_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
1254 struct mtk_snand *ms = spi_controller_get_devdata(mem->spi->master);
1256 dev_dbg(ms->dev, "OP %02x ADDR %08llX@%d:%u DATA %d:%u", op->cmd.opcode,
1257 op->addr.val, op->addr.buswidth, op->addr.nbytes,
1258 op->data.buswidth, op->data.nbytes);
1259 if (mtk_snand_is_page_ops(op)) {
1260 if (op->data.dir == SPI_MEM_DATA_IN)
1261 return mtk_snand_read_page_cache(ms, op);
1263 return mtk_snand_write_page_cache(ms, op);
1265 return mtk_snand_mac_io(ms, op);
1269 static const struct spi_controller_mem_ops mtk_snand_mem_ops = {
1270 .adjust_op_size = mtk_snand_adjust_op_size,
1271 .supports_op = mtk_snand_supports_op,
1272 .exec_op = mtk_snand_exec_op,
1275 static const struct spi_controller_mem_caps mtk_snand_mem_caps = {
1279 static irqreturn_t mtk_snand_irq(int irq, void *id)
1281 struct mtk_snand *snf = id;
1284 sta = nfi_read32(snf, NFI_INTR_STA);
1285 ien = nfi_read32(snf, NFI_INTR_EN);
1290 nfi_write32(snf, NFI_INTR_EN, 0);
1291 complete(&snf->op_done);
1295 static const struct of_device_id mtk_snand_ids[] = {
1296 { .compatible = "mediatek,mt7622-snand", .data = &mt7622_snand_caps },
1297 { .compatible = "mediatek,mt7629-snand", .data = &mt7629_snand_caps },
1301 MODULE_DEVICE_TABLE(of, mtk_snand_ids);
1303 static int mtk_snand_enable_clk(struct mtk_snand *ms)
1307 ret = clk_prepare_enable(ms->nfi_clk);
1309 dev_err(ms->dev, "unable to enable nfi clk\n");
1312 ret = clk_prepare_enable(ms->pad_clk);
1314 dev_err(ms->dev, "unable to enable pad clk\n");
1319 clk_disable_unprepare(ms->nfi_clk);
1323 static void mtk_snand_disable_clk(struct mtk_snand *ms)
1325 clk_disable_unprepare(ms->pad_clk);
1326 clk_disable_unprepare(ms->nfi_clk);
1329 static int mtk_snand_probe(struct platform_device *pdev)
1331 struct device_node *np = pdev->dev.of_node;
1332 const struct of_device_id *dev_id;
1333 struct spi_controller *ctlr;
1334 struct mtk_snand *ms;
1337 dev_id = of_match_node(mtk_snand_ids, np);
1341 ctlr = devm_spi_alloc_master(&pdev->dev, sizeof(*ms));
1344 platform_set_drvdata(pdev, ctlr);
1346 ms = spi_controller_get_devdata(ctlr);
1349 ms->caps = dev_id->data;
1351 ms->ecc = of_mtk_ecc_get(np);
1352 if (IS_ERR(ms->ecc))
1353 return PTR_ERR(ms->ecc);
1357 ms->nfi_base = devm_platform_ioremap_resource(pdev, 0);
1358 if (IS_ERR(ms->nfi_base)) {
1359 ret = PTR_ERR(ms->nfi_base);
1363 ms->dev = &pdev->dev;
1365 ms->nfi_clk = devm_clk_get(&pdev->dev, "nfi_clk");
1366 if (IS_ERR(ms->nfi_clk)) {
1367 ret = PTR_ERR(ms->nfi_clk);
1368 dev_err(&pdev->dev, "unable to get nfi_clk, err = %d\n", ret);
1372 ms->pad_clk = devm_clk_get(&pdev->dev, "pad_clk");
1373 if (IS_ERR(ms->pad_clk)) {
1374 ret = PTR_ERR(ms->pad_clk);
1375 dev_err(&pdev->dev, "unable to get pad_clk, err = %d\n", ret);
1379 ret = mtk_snand_enable_clk(ms);
1383 init_completion(&ms->op_done);
1385 ms->irq = platform_get_irq(pdev, 0);
1390 ret = devm_request_irq(ms->dev, ms->irq, mtk_snand_irq, 0x0,
1393 dev_err(ms->dev, "failed to request snfi irq\n");
1397 ret = dma_set_mask(ms->dev, DMA_BIT_MASK(32));
1399 dev_err(ms->dev, "failed to set dma mask\n");
1403 // switch to SNFI mode
1404 nfi_write32(ms, SNF_CFG, SPI_MODE);
1406 // setup an initial page format for ops matching page_cache_op template
1407 // before ECC is called.
1408 ret = mtk_snand_setup_pagefmt(ms, ms->caps->sector_size,
1409 ms->caps->spare_sizes[0]);
1411 dev_err(ms->dev, "failed to set initial page format\n");
1416 ms->ecc_eng.dev = &pdev->dev;
1417 ms->ecc_eng.integration = NAND_ECC_ENGINE_INTEGRATION_PIPELINED;
1418 ms->ecc_eng.ops = &mtk_snfi_ecc_engine_ops;
1419 ms->ecc_eng.priv = ms;
1421 ret = nand_ecc_register_on_host_hw_engine(&ms->ecc_eng);
1423 dev_err(&pdev->dev, "failed to register ecc engine.\n");
1427 ctlr->num_chipselect = 1;
1428 ctlr->mem_ops = &mtk_snand_mem_ops;
1429 ctlr->mem_caps = &mtk_snand_mem_caps;
1430 ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
1431 ctlr->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD | SPI_TX_DUAL | SPI_TX_QUAD;
1432 ctlr->dev.of_node = pdev->dev.of_node;
1433 ret = spi_register_controller(ctlr);
1435 dev_err(&pdev->dev, "spi_register_controller failed.\n");
1441 mtk_snand_disable_clk(ms);
1443 mtk_ecc_release(ms->ecc);
1447 static int mtk_snand_remove(struct platform_device *pdev)
1449 struct spi_controller *ctlr = platform_get_drvdata(pdev);
1450 struct mtk_snand *ms = spi_controller_get_devdata(ctlr);
1452 spi_unregister_controller(ctlr);
1453 mtk_snand_disable_clk(ms);
1454 mtk_ecc_release(ms->ecc);
1459 static struct platform_driver mtk_snand_driver = {
1460 .probe = mtk_snand_probe,
1461 .remove = mtk_snand_remove,
1463 .name = "mtk-snand",
1464 .of_match_table = mtk_snand_ids,
1468 module_platform_driver(mtk_snand_driver);
1470 MODULE_LICENSE("GPL");
1471 MODULE_AUTHOR("Chuanhong Guo <gch981213@gmail.com>");
1472 MODULE_DESCRIPTION("MeidaTek SPI-NAND Flash Controller Driver");