Lines Matching +full:clk +full:- +full:out +full:- +full:strength
1 // SPDX-License-Identifier: GPL-2.0 OR MIT
6 * Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
10 #include <linux/dma-mapping.h>
13 #include <linux/clk.h>
19 #include <linux/mtd/nand-ecc-mtk.h>
89 #define MTK_NAME "mtk-nand"
138 struct clk *nfi_clk;
139 struct clk *pad_clk;
145 struct mtk_nfc_clk clk; member
185 return (u8 *)p + i * chip->ecc.size; in data_ptr()
197 if (i < mtk_nand->bad_mark.sec) in oob_ptr()
198 poi = chip->oob_poi + (i + 1) * mtk_nand->fdm.reg_size; in oob_ptr()
199 else if (i == mtk_nand->bad_mark.sec) in oob_ptr()
200 poi = chip->oob_poi; in oob_ptr()
202 poi = chip->oob_poi + i * mtk_nand->fdm.reg_size; in oob_ptr()
211 return chip->ecc.size + mtk_nand->spare_per_sector; in mtk_data_len()
218 return nfc->buffer + i * mtk_data_len(chip); in mtk_data_ptr()
225 return nfc->buffer + i * mtk_data_len(chip) + chip->ecc.size; in mtk_oob_ptr()
230 writel(val, nfc->regs + reg); in nfi_writel()
235 writew(val, nfc->regs + reg); in nfi_writew()
240 writeb(val, nfc->regs + reg); in nfi_writeb()
245 return readl_relaxed(nfc->regs + reg); in nfi_readl()
250 return readw_relaxed(nfc->regs + reg); in nfi_readw()
255 return readb_relaxed(nfc->regs + reg); in nfi_readb()
260 struct device *dev = nfc->dev; in mtk_nfc_hw_reset()
268 ret = readl_poll_timeout(nfc->regs + NFI_MASTER_STA, val, in mtk_nfc_hw_reset()
282 struct device *dev = nfc->dev; in mtk_nfc_send_command()
288 ret = readl_poll_timeout_atomic(nfc->regs + NFI_STA, val, in mtk_nfc_send_command()
291 dev_warn(dev, "nfi core timed out entering command mode\n"); in mtk_nfc_send_command()
292 return -EIO; in mtk_nfc_send_command()
300 struct device *dev = nfc->dev; in mtk_nfc_send_address()
308 ret = readl_poll_timeout_atomic(nfc->regs + NFI_STA, val, in mtk_nfc_send_address()
311 dev_warn(dev, "nfi core timed out entering address mode\n"); in mtk_nfc_send_address()
312 return -EIO; in mtk_nfc_send_address()
325 if (!mtd->writesize) in mtk_nfc_hw_runtime_config()
328 spare = mtk_nand->spare_per_sector; in mtk_nfc_hw_runtime_config()
330 switch (mtd->writesize) { in mtk_nfc_hw_runtime_config()
335 if (chip->ecc.size == 512) in mtk_nfc_hw_runtime_config()
341 if (chip->ecc.size == 512) in mtk_nfc_hw_runtime_config()
347 if (chip->ecc.size == 512) in mtk_nfc_hw_runtime_config()
356 dev_err(nfc->dev, "invalid page len: %d\n", mtd->writesize); in mtk_nfc_hw_runtime_config()
357 return -EINVAL; in mtk_nfc_hw_runtime_config()
364 if (chip->ecc.size == 1024) in mtk_nfc_hw_runtime_config()
367 for (i = 0; i < nfc->caps->num_spare_size; i++) { in mtk_nfc_hw_runtime_config()
368 if (nfc->caps->spare_size[i] == spare) in mtk_nfc_hw_runtime_config()
372 if (i == nfc->caps->num_spare_size) { in mtk_nfc_hw_runtime_config()
373 dev_err(nfc->dev, "invalid spare size %d\n", spare); in mtk_nfc_hw_runtime_config()
374 return -EINVAL; in mtk_nfc_hw_runtime_config()
377 fmt |= i << nfc->caps->pageformat_spare_shift; in mtk_nfc_hw_runtime_config()
379 fmt |= mtk_nand->fdm.reg_size << PAGEFMT_FDM_SHIFT; in mtk_nfc_hw_runtime_config()
380 fmt |= mtk_nand->fdm.ecc_size << PAGEFMT_FDM_ECC_SHIFT; in mtk_nfc_hw_runtime_config()
383 nfc->ecc_cfg.strength = chip->ecc.strength; in mtk_nfc_hw_runtime_config()
384 nfc->ecc_cfg.len = chip->ecc.size + mtk_nand->fdm.ecc_size; in mtk_nfc_hw_runtime_config()
394 rc = readb_poll_timeout_atomic(nfc->regs + NFI_PIO_DIRDY, val, in mtk_nfc_wait_ioready()
397 dev_err(nfc->dev, "data not ready\n"); in mtk_nfc_wait_ioready()
416 reg = (nfc->caps->max_sector << CON_SEC_SHIFT) | CON_BRD; in mtk_nfc_read_byte()
447 reg = nfc->caps->max_sector << CON_SEC_SHIFT | CON_BWR; in mtk_nfc_write_byte()
472 switch (instr->type) { in mtk_nfc_exec_instr()
474 mtk_nfc_send_command(nfc, instr->ctx.cmd.opcode); in mtk_nfc_exec_instr()
477 for (i = 0; i < instr->ctx.addr.naddrs; i++) in mtk_nfc_exec_instr()
478 mtk_nfc_send_address(nfc, instr->ctx.addr.addrs[i]); in mtk_nfc_exec_instr()
481 mtk_nfc_read_buf(chip, instr->ctx.data.buf.in, in mtk_nfc_exec_instr()
482 instr->ctx.data.len); in mtk_nfc_exec_instr()
485 mtk_nfc_write_buf(chip, instr->ctx.data.buf.out, in mtk_nfc_exec_instr()
486 instr->ctx.data.len); in mtk_nfc_exec_instr()
489 return readl_poll_timeout(nfc->regs + NFI_STA, status, in mtk_nfc_exec_instr()
491 instr->ctx.waitrdy.timeout_ms * 1000); in mtk_nfc_exec_instr()
496 return -EINVAL; in mtk_nfc_exec_instr()
506 nfi_writel(nfc, mtk_nand->sels[cs], NFI_CSEL); in mtk_nfc_select_target()
522 mtk_nfc_select_target(chip, op->cs); in mtk_nfc_exec_op()
524 for (i = 0; i < op->ninstrs; i++) { in mtk_nfc_exec_op()
525 ret = mtk_nfc_exec_instr(chip, &op->instrs[i]); in mtk_nfc_exec_op()
543 return -ENOTSUPP; in mtk_nfc_setup_interface()
548 rate = clk_get_rate(nfc->clk.nfi_clk); in mtk_nfc_setup_interface()
550 rate /= nfc->caps->nfi_clk_div; in mtk_nfc_setup_interface()
555 tpoecs = max(timings->tALH_min, timings->tCLH_min) / 1000; in mtk_nfc_setup_interface()
559 tprecs = max(timings->tCLS_min, timings->tALS_min) / 1000; in mtk_nfc_setup_interface()
566 tw2r = timings->tWHR_min / 1000; in mtk_nfc_setup_interface()
568 tw2r = DIV_ROUND_UP(tw2r - 1, 2); in mtk_nfc_setup_interface()
571 twh = max(timings->tREH_min, timings->tWH_min) / 1000; in mtk_nfc_setup_interface()
572 twh = DIV_ROUND_UP(twh * rate, 1000000) - 1; in mtk_nfc_setup_interface()
584 if (temp < timings->tWC_min) in mtk_nfc_setup_interface()
585 twst = timings->tWC_min - temp; in mtk_nfc_setup_interface()
586 twst = max(timings->tWP_min, twst) / 1000; in mtk_nfc_setup_interface()
587 twst = DIV_ROUND_UP(twst * rate, 1000000) - 1; in mtk_nfc_setup_interface()
594 if (temp < timings->tRC_min) in mtk_nfc_setup_interface()
595 trlt = timings->tRC_min - temp; in mtk_nfc_setup_interface()
596 trlt = max(trlt, timings->tRP_min) / 1000; in mtk_nfc_setup_interface()
597 trlt = DIV_ROUND_UP(trlt * rate, 1000000) - 1; in mtk_nfc_setup_interface()
608 if (temp < timings->tREA_max) { in mtk_nfc_setup_interface()
609 tsel = timings->tREA_max / 1000; in mtk_nfc_setup_interface()
611 tsel -= (trlt + 1); in mtk_nfc_setup_interface()
613 trlt += tsel - MAX_STROBE_DLY; in mtk_nfc_setup_interface()
624 * ------------------------------------- in mtk_nfc_setup_interface()
645 int size = chip->ecc.size + mtk_nand->fdm.reg_size; in mtk_nfc_sector_encode()
647 nfc->ecc_cfg.mode = ECC_DMA_MODE; in mtk_nfc_sector_encode()
648 nfc->ecc_cfg.op = ECC_ENCODE; in mtk_nfc_sector_encode()
650 return mtk_ecc_encode(nfc->ecc, &nfc->ecc_cfg, data, size); in mtk_nfc_sector_encode()
662 u32 bad_pos = nand->bad_mark.pos; in mtk_nfc_bad_mark_swap()
665 bad_pos += nand->bad_mark.sec * mtk_data_len(chip); in mtk_nfc_bad_mark_swap()
667 bad_pos += nand->bad_mark.sec * chip->ecc.size; in mtk_nfc_bad_mark_swap()
669 swap(chip->oob_poi[0], buf[bad_pos]); in mtk_nfc_bad_mark_swap()
678 struct mtk_nfc_fdm *fdm = &mtk_nand->fdm; in mtk_nfc_format_subpage()
682 start = offset / chip->ecc.size; in mtk_nfc_format_subpage()
683 end = DIV_ROUND_UP(offset + len, chip->ecc.size); in mtk_nfc_format_subpage()
685 memset(nfc->buffer, 0xff, mtd->writesize + mtd->oobsize); in mtk_nfc_format_subpage()
686 for (i = 0; i < chip->ecc.steps; i++) { in mtk_nfc_format_subpage()
688 chip->ecc.size); in mtk_nfc_format_subpage()
693 if (i == mtk_nand->bad_mark.sec) in mtk_nfc_format_subpage()
694 mtk_nand->bad_mark.bm_swap(mtd, nfc->buffer, 1); in mtk_nfc_format_subpage()
696 memcpy(mtk_oob_ptr(chip, i), oob_ptr(chip, i), fdm->reg_size); in mtk_nfc_format_subpage()
712 struct mtk_nfc_fdm *fdm = &mtk_nand->fdm; in mtk_nfc_format_page()
715 memset(nfc->buffer, 0xff, mtd->writesize + mtd->oobsize); in mtk_nfc_format_page()
716 for (i = 0; i < chip->ecc.steps; i++) { in mtk_nfc_format_page()
719 chip->ecc.size); in mtk_nfc_format_page()
721 if (i == mtk_nand->bad_mark.sec) in mtk_nfc_format_page()
722 mtk_nand->bad_mark.bm_swap(mtd, nfc->buffer, 1); in mtk_nfc_format_page()
724 memcpy(mtk_oob_ptr(chip, i), oob_ptr(chip, i), fdm->reg_size); in mtk_nfc_format_page()
733 struct mtk_nfc_fdm *fdm = &mtk_nand->fdm; in mtk_nfc_read_fdm()
743 for (j = 0; j < fdm->reg_size; j++) in mtk_nfc_read_fdm()
752 struct mtk_nfc_fdm *fdm = &mtk_nand->fdm; in mtk_nfc_write_fdm()
757 for (i = 0; i < chip->ecc.steps; i++) { in mtk_nfc_write_fdm()
763 vall |= (j < fdm->reg_size ? oobptr[j] : 0xff) in mtk_nfc_write_fdm()
766 valm |= (j < fdm->reg_size ? oobptr[j] : 0xff) in mtk_nfc_write_fdm()
767 << ((j - 4) * 8); in mtk_nfc_write_fdm()
778 struct device *dev = nfc->dev; in mtk_nfc_do_write_page()
784 ret = dma_mapping_error(nfc->dev, addr); in mtk_nfc_do_write_page()
786 dev_err(nfc->dev, "dma mapping error\n"); in mtk_nfc_do_write_page()
787 return -EINVAL; in mtk_nfc_do_write_page()
793 nfi_writel(nfc, chip->ecc.steps << CON_SEC_SHIFT, NFI_CON); in mtk_nfc_do_write_page()
797 init_completion(&nfc->done); in mtk_nfc_do_write_page()
803 ret = wait_for_completion_timeout(&nfc->done, msecs_to_jiffies(500)); in mtk_nfc_do_write_page()
807 ret = -ETIMEDOUT; in mtk_nfc_do_write_page()
811 ret = readl_poll_timeout_atomic(nfc->regs + NFI_ADDRCNTR, reg, in mtk_nfc_do_write_page()
812 ADDRCNTR_SEC(reg) >= chip->ecc.steps, in mtk_nfc_do_write_page()
819 dma_unmap_single(nfc->dev, addr, len, DMA_TO_DEVICE); in mtk_nfc_do_write_page()
835 mtk_nfc_select_target(chip, chip->cur_cs); in mtk_nfc_write_page()
843 nfc->ecc_cfg.op = ECC_ENCODE; in mtk_nfc_write_page()
844 nfc->ecc_cfg.mode = ECC_NFI_MODE; in mtk_nfc_write_page()
845 ret = mtk_ecc_enable(nfc->ecc, &nfc->ecc_cfg); in mtk_nfc_write_page()
855 memcpy(nfc->buffer, buf, mtd->writesize); in mtk_nfc_write_page()
856 mtk_nand->bad_mark.bm_swap(mtd, nfc->buffer, raw); in mtk_nfc_write_page()
857 bufpoi = nfc->buffer; in mtk_nfc_write_page()
865 len = mtd->writesize + (raw ? mtd->oobsize : 0); in mtk_nfc_write_page()
869 mtk_ecc_disable(nfc->ecc); in mtk_nfc_write_page()
890 return mtk_nfc_write_page(mtd, chip, nfc->buffer, pg, 1); in mtk_nfc_write_page_raw()
906 return mtk_nfc_write_page(mtd, chip, nfc->buffer, page, 1); in mtk_nfc_write_subpage_hwecc()
921 u32 reg_size = mtk_nand->fdm.reg_size; in mtk_nfc_update_ecc_stats()
926 memset(buf, 0xff, sectors * chip->ecc.size); in mtk_nfc_update_ecc_stats()
932 mtk_ecc_get_stats(nfc->ecc, &stats, sectors); in mtk_nfc_update_ecc_stats()
933 mtd->ecc_stats.corrected += stats.corrected; in mtk_nfc_update_ecc_stats()
934 mtd->ecc_stats.failed += stats.failed; in mtk_nfc_update_ecc_stats()
945 u32 spare = mtk_nand->spare_per_sector; in mtk_nfc_read_subpage()
953 mtk_nfc_select_target(chip, chip->cur_cs); in mtk_nfc_read_subpage()
954 start = data_offs / chip->ecc.size; in mtk_nfc_read_subpage()
955 end = DIV_ROUND_UP(data_offs + readlen, chip->ecc.size); in mtk_nfc_read_subpage()
957 sectors = end - start; in mtk_nfc_read_subpage()
958 column = start * (chip->ecc.size + spare); in mtk_nfc_read_subpage()
960 len = sectors * chip->ecc.size + (raw ? sectors * spare : 0); in mtk_nfc_read_subpage()
961 buf = bufpoi + start * chip->ecc.size; in mtk_nfc_read_subpage()
965 addr = dma_map_single(nfc->dev, buf, len, DMA_FROM_DEVICE); in mtk_nfc_read_subpage()
966 rc = dma_mapping_error(nfc->dev, addr); in mtk_nfc_read_subpage()
968 dev_err(nfc->dev, "dma mapping error\n"); in mtk_nfc_read_subpage()
970 return -EINVAL; in mtk_nfc_read_subpage()
979 nfc->ecc_cfg.mode = ECC_NFI_MODE; in mtk_nfc_read_subpage()
980 nfc->ecc_cfg.sectors = sectors; in mtk_nfc_read_subpage()
981 nfc->ecc_cfg.op = ECC_DECODE; in mtk_nfc_read_subpage()
982 rc = mtk_ecc_enable(nfc->ecc, &nfc->ecc_cfg); in mtk_nfc_read_subpage()
984 dev_err(nfc->dev, "ecc enable\n"); in mtk_nfc_read_subpage()
989 dma_unmap_single(nfc->dev, addr, len, DMA_FROM_DEVICE); in mtk_nfc_read_subpage()
1001 init_completion(&nfc->done); in mtk_nfc_read_subpage()
1006 rc = wait_for_completion_timeout(&nfc->done, msecs_to_jiffies(500)); in mtk_nfc_read_subpage()
1008 dev_warn(nfc->dev, "read ahb/dma done timeout\n"); in mtk_nfc_read_subpage()
1010 rc = readl_poll_timeout_atomic(nfc->regs + NFI_BYTELEN, reg, in mtk_nfc_read_subpage()
1014 dev_err(nfc->dev, "subpage done timeout\n"); in mtk_nfc_read_subpage()
1015 bitflips = -EIO; in mtk_nfc_read_subpage()
1017 rc = mtk_ecc_wait_done(nfc->ecc, ECC_DECODE); in mtk_nfc_read_subpage()
1018 bitflips = rc < 0 ? -ETIMEDOUT : in mtk_nfc_read_subpage()
1023 dma_unmap_single(nfc->dev, addr, len, DMA_FROM_DEVICE); in mtk_nfc_read_subpage()
1028 mtk_ecc_disable(nfc->ecc); in mtk_nfc_read_subpage()
1030 if (clamp(mtk_nand->bad_mark.sec, start, end) == mtk_nand->bad_mark.sec) in mtk_nfc_read_subpage()
1031 mtk_nand->bad_mark.bm_swap(mtd, bufpoi, raw); in mtk_nfc_read_subpage()
1050 return mtk_nfc_read_subpage(mtd, chip, 0, mtd->writesize, p, pg, 0); in mtk_nfc_read_page_hwecc()
1059 struct mtk_nfc_fdm *fdm = &mtk_nand->fdm; in mtk_nfc_read_page_raw()
1062 memset(nfc->buffer, 0xff, mtd->writesize + mtd->oobsize); in mtk_nfc_read_page_raw()
1063 ret = mtk_nfc_read_subpage(mtd, chip, 0, mtd->writesize, nfc->buffer, in mtk_nfc_read_page_raw()
1068 for (i = 0; i < chip->ecc.steps; i++) { in mtk_nfc_read_page_raw()
1069 memcpy(oob_ptr(chip, i), mtk_oob_ptr(chip, i), fdm->reg_size); in mtk_nfc_read_page_raw()
1071 if (i == mtk_nand->bad_mark.sec) in mtk_nfc_read_page_raw()
1072 mtk_nand->bad_mark.bm_swap(mtd, nfc->buffer, 1); in mtk_nfc_read_page_raw()
1076 chip->ecc.size); in mtk_nfc_read_page_raw()
1091 * ------------------------------- in mtk_nfc_hw_init()
1116 complete(&nfc->done); in mtk_nfc_irq()
1126 struct mtk_nfc_fdm *fdm = &mtk_nand->fdm; in mtk_nfc_ooblayout_free()
1129 eccsteps = mtd->writesize / chip->ecc.size; in mtk_nfc_ooblayout_free()
1132 return -ERANGE; in mtk_nfc_ooblayout_free()
1134 oob_region->length = fdm->reg_size - fdm->ecc_size; in mtk_nfc_ooblayout_free()
1135 oob_region->offset = section * fdm->reg_size + fdm->ecc_size; in mtk_nfc_ooblayout_free()
1148 return -ERANGE; in mtk_nfc_ooblayout_ecc()
1150 eccsteps = mtd->writesize / chip->ecc.size; in mtk_nfc_ooblayout_ecc()
1151 oob_region->offset = mtk_nand->fdm.reg_size * eccsteps; in mtk_nfc_ooblayout_ecc()
1152 oob_region->length = mtd->oobsize - oob_region->offset; in mtk_nfc_ooblayout_ecc()
1169 ecc_bytes = DIV_ROUND_UP(nand->ecc.strength * in mtk_nfc_set_fdm()
1170 mtk_ecc_get_parity_bits(nfc->ecc), 8); in mtk_nfc_set_fdm()
1172 fdm->reg_size = chip->spare_per_sector - ecc_bytes; in mtk_nfc_set_fdm()
1173 if (fdm->reg_size > NFI_FDM_MAX_SIZE) in mtk_nfc_set_fdm()
1174 fdm->reg_size = NFI_FDM_MAX_SIZE; in mtk_nfc_set_fdm()
1177 fdm->ecc_size = 1; in mtk_nfc_set_fdm()
1185 if (mtd->writesize == 512) { in mtk_nfc_set_bad_mark_ctl()
1186 bm_ctl->bm_swap = mtk_nfc_no_bad_mark_swap; in mtk_nfc_set_bad_mark_ctl()
1188 bm_ctl->bm_swap = mtk_nfc_bad_mark_swap; in mtk_nfc_set_bad_mark_ctl()
1189 bm_ctl->sec = mtd->writesize / mtk_data_len(nand); in mtk_nfc_set_bad_mark_ctl()
1190 bm_ctl->pos = mtd->writesize % mtk_data_len(nand); in mtk_nfc_set_bad_mark_ctl()
1198 const u8 *spare = nfc->caps->spare_size; in mtk_nfc_set_spare_per_sector()
1201 eccsteps = mtd->writesize / nand->ecc.size; in mtk_nfc_set_spare_per_sector()
1202 *sps = mtd->oobsize / eccsteps; in mtk_nfc_set_spare_per_sector()
1204 if (nand->ecc.size == 1024) in mtk_nfc_set_spare_per_sector()
1208 return -EINVAL; in mtk_nfc_set_spare_per_sector()
1210 for (i = 0; i < nfc->caps->num_spare_size; i++) { in mtk_nfc_set_spare_per_sector()
1220 if (nand->ecc.size == 1024) in mtk_nfc_set_spare_per_sector()
1230 nanddev_get_ecc_requirements(&nand->base); in mtk_nfc_ecc_init()
1236 if (nand->ecc.engine_type != NAND_ECC_ENGINE_TYPE_ON_HOST) { in mtk_nfc_ecc_init()
1238 return -EINVAL; in mtk_nfc_ecc_init()
1242 if (!nand->ecc.size || !nand->ecc.strength) { in mtk_nfc_ecc_init()
1244 nand->ecc.strength = requirements->strength; in mtk_nfc_ecc_init()
1245 nand->ecc.size = requirements->step_size; in mtk_nfc_ecc_init()
1251 if (nand->ecc.size < 1024) { in mtk_nfc_ecc_init()
1252 if (mtd->writesize > 512 && in mtk_nfc_ecc_init()
1253 nfc->caps->max_sector_size > 512) { in mtk_nfc_ecc_init()
1254 nand->ecc.size = 1024; in mtk_nfc_ecc_init()
1255 nand->ecc.strength <<= 1; in mtk_nfc_ecc_init()
1257 nand->ecc.size = 512; in mtk_nfc_ecc_init()
1260 nand->ecc.size = 1024; in mtk_nfc_ecc_init()
1268 free = (nand->ecc.strength * mtk_ecc_get_parity_bits(nfc->ecc) in mtk_nfc_ecc_init()
1270 free = spare - free; in mtk_nfc_ecc_init()
1273 * enhance ecc strength if oob left is bigger than max FDM size in mtk_nfc_ecc_init()
1274 * or reduce ecc strength if oob size is not enough for ecc in mtk_nfc_ecc_init()
1278 spare -= NFI_FDM_MAX_SIZE; in mtk_nfc_ecc_init()
1279 nand->ecc.strength = (spare << 3) / in mtk_nfc_ecc_init()
1280 mtk_ecc_get_parity_bits(nfc->ecc); in mtk_nfc_ecc_init()
1282 spare -= NFI_FDM_MIN_SIZE; in mtk_nfc_ecc_init()
1283 nand->ecc.strength = (spare << 3) / in mtk_nfc_ecc_init()
1284 mtk_ecc_get_parity_bits(nfc->ecc); in mtk_nfc_ecc_init()
1288 mtk_ecc_adjust_strength(nfc->ecc, &nand->ecc.strength); in mtk_nfc_ecc_init()
1291 nand->ecc.size, nand->ecc.strength); in mtk_nfc_ecc_init()
1299 struct device *dev = mtd->dev.parent; in mtk_nfc_attach_chip()
1305 if (chip->options & NAND_BUSWIDTH_16) { in mtk_nfc_attach_chip()
1307 return -EINVAL; in mtk_nfc_attach_chip()
1311 if (chip->bbt_options & NAND_BBT_USE_FLASH) in mtk_nfc_attach_chip()
1312 chip->bbt_options |= NAND_BBT_NO_OOB; in mtk_nfc_attach_chip()
1318 ret = mtk_nfc_set_spare_per_sector(&mtk_nand->spare_per_sector, mtd); in mtk_nfc_attach_chip()
1322 mtk_nfc_set_fdm(&mtk_nand->fdm, mtd); in mtk_nfc_attach_chip()
1323 mtk_nfc_set_bad_mark_ctl(&mtk_nand->bad_mark, mtd); in mtk_nfc_attach_chip()
1325 len = mtd->writesize + mtd->oobsize; in mtk_nfc_attach_chip()
1326 nfc->buffer = devm_kzalloc(dev, len, GFP_KERNEL); in mtk_nfc_attach_chip()
1327 if (!nfc->buffer) in mtk_nfc_attach_chip()
1328 return -ENOMEM; in mtk_nfc_attach_chip()
1351 return -ENODEV; in mtk_nfc_nand_chip_init()
1356 return -EINVAL; in mtk_nfc_nand_chip_init()
1362 return -ENOMEM; in mtk_nfc_nand_chip_init()
1364 chip->nsels = nsels; in mtk_nfc_nand_chip_init()
1374 return -EINVAL; in mtk_nfc_nand_chip_init()
1377 if (test_and_set_bit(tmp, &nfc->assigned_cs)) { in mtk_nfc_nand_chip_init()
1379 return -EINVAL; in mtk_nfc_nand_chip_init()
1382 chip->sels[i] = tmp; in mtk_nfc_nand_chip_init()
1385 nand = &chip->nand; in mtk_nfc_nand_chip_init()
1386 nand->controller = &nfc->controller; in mtk_nfc_nand_chip_init()
1391 nand->options |= NAND_USES_DMA | NAND_SUBPAGE_READ; in mtk_nfc_nand_chip_init()
1394 nand->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; in mtk_nfc_nand_chip_init()
1396 nand->ecc.write_subpage = mtk_nfc_write_subpage_hwecc; in mtk_nfc_nand_chip_init()
1397 nand->ecc.write_page_raw = mtk_nfc_write_page_raw; in mtk_nfc_nand_chip_init()
1398 nand->ecc.write_page = mtk_nfc_write_page_hwecc; in mtk_nfc_nand_chip_init()
1399 nand->ecc.write_oob_raw = mtk_nfc_write_oob_std; in mtk_nfc_nand_chip_init()
1400 nand->ecc.write_oob = mtk_nfc_write_oob_std; in mtk_nfc_nand_chip_init()
1402 nand->ecc.read_subpage = mtk_nfc_read_subpage_hwecc; in mtk_nfc_nand_chip_init()
1403 nand->ecc.read_page_raw = mtk_nfc_read_page_raw; in mtk_nfc_nand_chip_init()
1404 nand->ecc.read_page = mtk_nfc_read_page_hwecc; in mtk_nfc_nand_chip_init()
1405 nand->ecc.read_oob_raw = mtk_nfc_read_oob_std; in mtk_nfc_nand_chip_init()
1406 nand->ecc.read_oob = mtk_nfc_read_oob_std; in mtk_nfc_nand_chip_init()
1409 mtd->owner = THIS_MODULE; in mtk_nfc_nand_chip_init()
1410 mtd->dev.parent = dev; in mtk_nfc_nand_chip_init()
1411 mtd->name = MTK_NAME; in mtk_nfc_nand_chip_init()
1427 list_add_tail(&chip->node, &nfc->chips); in mtk_nfc_nand_chip_init()
1438 while (!list_empty(&nfc->chips)) { in mtk_nfc_nand_chips_cleanup()
1439 mtk_chip = list_first_entry(&nfc->chips, in mtk_nfc_nand_chips_cleanup()
1441 chip = &mtk_chip->nand; in mtk_nfc_nand_chips_cleanup()
1445 list_del(&mtk_chip->node); in mtk_nfc_nand_chips_cleanup()
1451 struct device_node *np = dev->of_node; in mtk_nfc_nand_chips_init()
1494 .compatible = "mediatek,mt2701-nfc",
1497 .compatible = "mediatek,mt2712-nfc",
1500 .compatible = "mediatek,mt7622-nfc",
1509 struct device *dev = &pdev->dev; in mtk_nfc_probe()
1510 struct device_node *np = dev->of_node; in mtk_nfc_probe()
1516 return -ENOMEM; in mtk_nfc_probe()
1518 nand_controller_init(&nfc->controller); in mtk_nfc_probe()
1519 INIT_LIST_HEAD(&nfc->chips); in mtk_nfc_probe()
1520 nfc->controller.ops = &mtk_nfc_controller_ops; in mtk_nfc_probe()
1523 nfc->ecc = of_mtk_ecc_get(np); in mtk_nfc_probe()
1524 if (IS_ERR(nfc->ecc)) in mtk_nfc_probe()
1525 return PTR_ERR(nfc->ecc); in mtk_nfc_probe()
1526 else if (!nfc->ecc) in mtk_nfc_probe()
1527 return -ENODEV; in mtk_nfc_probe()
1529 nfc->caps = of_device_get_match_data(dev); in mtk_nfc_probe()
1530 nfc->dev = dev; in mtk_nfc_probe()
1532 nfc->regs = devm_platform_ioremap_resource(pdev, 0); in mtk_nfc_probe()
1533 if (IS_ERR(nfc->regs)) { in mtk_nfc_probe()
1534 ret = PTR_ERR(nfc->regs); in mtk_nfc_probe()
1538 nfc->clk.nfi_clk = devm_clk_get_enabled(dev, "nfi_clk"); in mtk_nfc_probe()
1539 if (IS_ERR(nfc->clk.nfi_clk)) { in mtk_nfc_probe()
1540 dev_err(dev, "no clk\n"); in mtk_nfc_probe()
1541 ret = PTR_ERR(nfc->clk.nfi_clk); in mtk_nfc_probe()
1545 nfc->clk.pad_clk = devm_clk_get_enabled(dev, "pad_clk"); in mtk_nfc_probe()
1546 if (IS_ERR(nfc->clk.pad_clk)) { in mtk_nfc_probe()
1547 dev_err(dev, "no pad clk\n"); in mtk_nfc_probe()
1548 ret = PTR_ERR(nfc->clk.pad_clk); in mtk_nfc_probe()
1554 ret = -EINVAL; in mtk_nfc_probe()
1558 ret = devm_request_irq(dev, irq, mtk_nfc_irq, 0x0, "mtk-nand", nfc); in mtk_nfc_probe()
1581 mtk_ecc_release(nfc->ecc); in mtk_nfc_probe()
1591 mtk_ecc_release(nfc->ecc); in mtk_nfc_remove()
1599 clk_disable_unprepare(nfc->clk.nfi_clk); in mtk_nfc_suspend()
1600 clk_disable_unprepare(nfc->clk.pad_clk); in mtk_nfc_suspend()
1615 ret = clk_prepare_enable(nfc->clk.nfi_clk); in mtk_nfc_resume()
1617 dev_err(dev, "failed to enable nfi clk\n"); in mtk_nfc_resume()
1621 ret = clk_prepare_enable(nfc->clk.pad_clk); in mtk_nfc_resume()
1623 dev_err(dev, "failed to enable pad clk\n"); in mtk_nfc_resume()
1624 clk_disable_unprepare(nfc->clk.nfi_clk); in mtk_nfc_resume()
1629 list_for_each_entry(chip, &nfc->chips, node) { in mtk_nfc_resume()
1630 nand = &chip->nand; in mtk_nfc_resume()
1631 for (i = 0; i < chip->nsels; i++) in mtk_nfc_resume()