Lines Matching +full:clk +full:- +full:out +full:- +full:strength

1 // SPDX-License-Identifier: GPL-2.0 OR MIT
5 * Author: Yifeng Zhao <yifeng.zhao@rock-chips.com>
8 #include <linux/clk.h>
10 #include <linux/dma-mapping.h>
30 * nand_chip->oob_poi data layout:
62 #define DMA_INC_NUM (9) /* 1 - 16 */
170 struct clk *nfc_clk;
171 struct clk *ahb_clk;
197 return (u8 *)p + i * chip->ecc.size; in rk_nfc_buf_to_data_ptr()
204 poi = chip->oob_poi + i * NFC_SYS_DATA_SIZE; in rk_nfc_buf_to_oob_ptr()
214 poi = chip->oob_poi + rknand->metadata_size + chip->ecc.bytes * i; in rk_nfc_buf_to_oob_ecc_ptr()
221 return chip->ecc.size + chip->ecc.bytes + NFC_SYS_DATA_SIZE; in rk_nfc_data_len()
228 return nfc->page_buf + i * rk_nfc_data_len(chip); in rk_nfc_data_ptr()
235 return nfc->page_buf + i * rk_nfc_data_len(chip) + chip->ecc.size; in rk_nfc_oob_ptr()
238 static int rk_nfc_hw_ecc_setup(struct nand_chip *chip, u32 strength) in rk_nfc_hw_ecc_setup() argument
244 if (strength == nfc->cfg->ecc_strengths[i]) { in rk_nfc_hw_ecc_setup()
245 reg = nfc->cfg->ecc_cfgs[i]; in rk_nfc_hw_ecc_setup()
251 return -EINVAL; in rk_nfc_hw_ecc_setup()
253 writel(reg, nfc->regs + nfc->cfg->bchctl_off); in rk_nfc_hw_ecc_setup()
256 nfc->cur_ecc = strength; in rk_nfc_hw_ecc_setup()
265 struct nand_ecc_ctrl *ecc = &chip->ecc; in rk_nfc_select_chip()
269 nfc->selected_bank = -1; in rk_nfc_select_chip()
271 val = readl_relaxed(nfc->regs + NFC_FMCTL); in rk_nfc_select_chip()
273 writel(val, nfc->regs + NFC_FMCTL); in rk_nfc_select_chip()
277 nfc->selected_bank = rknand->sels[cs]; in rk_nfc_select_chip()
278 nfc->band_offset = NFC_BANK + nfc->selected_bank * NFC_BANK_STEP; in rk_nfc_select_chip()
280 val = readl_relaxed(nfc->regs + NFC_FMCTL); in rk_nfc_select_chip()
282 val |= FMCTL_CE_SEL(nfc->selected_bank); in rk_nfc_select_chip()
284 writel(val, nfc->regs + NFC_FMCTL); in rk_nfc_select_chip()
290 if (nfc->cur_timing != rknand->timing) { in rk_nfc_select_chip()
291 writel(rknand->timing, nfc->regs + NFC_FMWAIT); in rk_nfc_select_chip()
292 nfc->cur_timing = rknand->timing; in rk_nfc_select_chip()
299 if (nfc->cur_ecc != ecc->strength) in rk_nfc_select_chip()
300 rk_nfc_hw_ecc_setup(chip, ecc->strength); in rk_nfc_select_chip()
308 rc = readl_relaxed_poll_timeout(nfc->regs + NFC_FMCTL, val, in rk_nfc_wait_ioready()
319 buf[i] = readb_relaxed(nfc->regs + nfc->band_offset + in rk_nfc_read_buf()
328 writeb(buf[i], nfc->regs + nfc->band_offset + BANK_DATA); in rk_nfc_write_buf()
336 int reg_offset = nfc->band_offset; in rk_nfc_cmd()
342 for (i = 0; i < subop->ninstrs; i++) { in rk_nfc_cmd()
343 const struct nand_op_instr *instr = &subop->instrs[i]; in rk_nfc_cmd()
345 switch (instr->type) { in rk_nfc_cmd()
347 writeb(instr->ctx.cmd.opcode, in rk_nfc_cmd()
348 nfc->regs + reg_offset + BANK_CMD); in rk_nfc_cmd()
356 writeb(instr->ctx.addr.addrs[j + start], in rk_nfc_cmd()
357 nfc->regs + reg_offset + BANK_ADDR); in rk_nfc_cmd()
365 if (instr->type == NAND_OP_DATA_OUT_INSTR) { in rk_nfc_cmd()
366 outbuf = instr->ctx.data.buf.out + start; in rk_nfc_cmd()
369 inbuf = instr->ctx.data.buf.in + start; in rk_nfc_cmd()
376 ret = -ETIMEDOUT; in rk_nfc_cmd()
377 dev_err(nfc->dev, "IO not ready\n"); in rk_nfc_cmd()
408 rk_nfc_select_chip(chip, op->cs); in rk_nfc_exec_op()
425 return -EOPNOTSUPP; in rk_nfc_setup_interface()
430 if (IS_ERR(nfc->nfc_clk)) in rk_nfc_setup_interface()
431 rate = clk_get_rate(nfc->ahb_clk); in rk_nfc_setup_interface()
433 rate = clk_get_rate(nfc->nfc_clk); in rk_nfc_setup_interface()
441 trwpw = max(timings->tWC_min, timings->tRC_min) / 1000; in rk_nfc_setup_interface()
444 temp = timings->tREA_max / 1000; in rk_nfc_setup_interface()
452 * ------------------------------------- in rk_nfc_setup_interface()
463 rknand->timing = ACCTIMING(tc2rw, trwpw, trw2c); in rk_nfc_setup_interface()
479 if (nfc->cfg->type == NFC_V6 || nfc->cfg->type == NFC_V8) { in rk_nfc_xfer_start()
480 bch_reg = readl_relaxed(nfc->regs + nfc->cfg->bchctl_off); in rk_nfc_xfer_start()
482 (nfc->selected_bank << BCHCTL_BANK); in rk_nfc_xfer_start()
483 writel(bch_reg, nfc->regs + nfc->cfg->bchctl_off); in rk_nfc_xfer_start()
486 writel(dma_reg, nfc->regs + nfc->cfg->dma_cfg_off); in rk_nfc_xfer_start()
487 writel((u32)dma_data, nfc->regs + nfc->cfg->dma_data_buf_off); in rk_nfc_xfer_start()
488 writel((u32)dma_oob, nfc->regs + nfc->cfg->dma_oob_buf_off); in rk_nfc_xfer_start()
489 writel(fl_reg, nfc->regs + nfc->cfg->flctl_off); in rk_nfc_xfer_start()
491 writel(fl_reg, nfc->regs + nfc->cfg->flctl_off); in rk_nfc_xfer_start()
499 ptr = nfc->regs + nfc->cfg->flctl_off; in rk_nfc_wait_for_xfer_done()
512 struct nand_ecc_ctrl *ecc = &chip->ecc; in rk_nfc_write_page_raw()
515 pages_per_blk = mtd->erasesize / mtd->writesize; in rk_nfc_write_page_raw()
516 if ((chip->options & NAND_IS_BOOT_MEDIUM) && in rk_nfc_write_page_raw()
517 (page < (pages_per_blk * rknand->boot_blks)) && in rk_nfc_write_page_raw()
518 rknand->boot_ecc != ecc->strength) { in rk_nfc_write_page_raw()
521 * a different ECC strength is in use for the boot blocks. in rk_nfc_write_page_raw()
523 return -EIO; in rk_nfc_write_page_raw()
527 memset(nfc->page_buf, 0xff, mtd->writesize + mtd->oobsize); in rk_nfc_write_page_raw()
529 for (i = 0; i < ecc->steps; i++) { in rk_nfc_write_page_raw()
534 ecc->size); in rk_nfc_write_page_raw()
543 * bad = chip->oob_poi[chip->badblockpos]; in rk_nfc_write_page_raw()
545 * chip->badblockpos == 0 for a large page NAND Flash, in rk_nfc_write_page_raw()
546 * so chip->oob_poi[0] is the bad block mask (BBM). in rk_nfc_write_page_raw()
559 * The chip->oob_poi data layout: in rk_nfc_write_page_raw()
567 * oob_region->length = rknand->metadata_size - NFC_SYS_DATA_SIZE - 2; in rk_nfc_write_page_raw()
571 rk_nfc_buf_to_oob_ptr(chip, ecc->steps - 1), in rk_nfc_write_page_raw()
575 rk_nfc_buf_to_oob_ptr(chip, i - 1), in rk_nfc_write_page_raw()
580 ecc->bytes); in rk_nfc_write_page_raw()
584 rk_nfc_write_buf(nfc, buf, mtd->writesize + mtd->oobsize); in rk_nfc_write_page_raw()
594 struct nand_ecc_ctrl *ecc = &chip->ecc; in rk_nfc_write_page_hwecc()
595 int oob_step = (ecc->bytes > 60) ? NFC_MAX_OOB_PER_STEP : in rk_nfc_write_page_hwecc()
597 int pages_per_blk = mtd->erasesize / mtd->writesize; in rk_nfc_write_page_hwecc()
606 memcpy(nfc->page_buf, buf, mtd->writesize); in rk_nfc_write_page_hwecc()
608 memset(nfc->page_buf, 0xFF, mtd->writesize); in rk_nfc_write_page_hwecc()
630 * The chip->oob_poi data layout: in rk_nfc_write_page_hwecc()
636 if ((page < (pages_per_blk * rknand->boot_blks)) && in rk_nfc_write_page_hwecc()
637 (chip->options & NAND_IS_BOOT_MEDIUM)) { in rk_nfc_write_page_hwecc()
639 if (rknand->boot_ecc != ecc->strength) in rk_nfc_write_page_hwecc()
640 rk_nfc_hw_ecc_setup(chip, rknand->boot_ecc); in rk_nfc_write_page_hwecc()
643 for (i = 0; i < ecc->steps; i++) { in rk_nfc_write_page_hwecc()
645 oob = chip->oob_poi + (ecc->steps - 1) * NFC_SYS_DATA_SIZE; in rk_nfc_write_page_hwecc()
647 oob = chip->oob_poi + (i - 1) * NFC_SYS_DATA_SIZE; in rk_nfc_write_page_hwecc()
651 if (nfc->cfg->type == NFC_V9) in rk_nfc_write_page_hwecc()
652 nfc->oob_buf[i] = tmp; in rk_nfc_write_page_hwecc()
654 nfc->oob_buf[i * (oob_step / 4)] = tmp; in rk_nfc_write_page_hwecc()
657 dma_data = dma_map_single(nfc->dev, (void *)nfc->page_buf, in rk_nfc_write_page_hwecc()
658 mtd->writesize, DMA_TO_DEVICE); in rk_nfc_write_page_hwecc()
659 dma_oob = dma_map_single(nfc->dev, nfc->oob_buf, in rk_nfc_write_page_hwecc()
660 ecc->steps * oob_step, in rk_nfc_write_page_hwecc()
663 reinit_completion(&nfc->done); in rk_nfc_write_page_hwecc()
664 writel(INT_DMA, nfc->regs + nfc->cfg->int_en_off); in rk_nfc_write_page_hwecc()
666 rk_nfc_xfer_start(nfc, NFC_WRITE, ecc->steps, dma_data, in rk_nfc_write_page_hwecc()
668 ret = wait_for_completion_timeout(&nfc->done, in rk_nfc_write_page_hwecc()
671 dev_warn(nfc->dev, "write: wait dma done timeout.\n"); in rk_nfc_write_page_hwecc()
679 dma_unmap_single(nfc->dev, dma_data, mtd->writesize, in rk_nfc_write_page_hwecc()
681 dma_unmap_single(nfc->dev, dma_oob, ecc->steps * oob_step, in rk_nfc_write_page_hwecc()
684 if (boot_rom_mode && rknand->boot_ecc != ecc->strength) in rk_nfc_write_page_hwecc()
685 rk_nfc_hw_ecc_setup(chip, ecc->strength); in rk_nfc_write_page_hwecc()
688 dev_err(nfc->dev, "write: wait transfer done timeout.\n"); in rk_nfc_write_page_hwecc()
689 return -ETIMEDOUT; in rk_nfc_write_page_hwecc()
706 struct nand_ecc_ctrl *ecc = &chip->ecc; in rk_nfc_read_page_raw()
709 pages_per_blk = mtd->erasesize / mtd->writesize; in rk_nfc_read_page_raw()
710 if ((chip->options & NAND_IS_BOOT_MEDIUM) && in rk_nfc_read_page_raw()
711 (page < (pages_per_blk * rknand->boot_blks)) && in rk_nfc_read_page_raw()
712 rknand->boot_ecc != ecc->strength) { in rk_nfc_read_page_raw()
715 * a different ECC strength is in use for the boot blocks. in rk_nfc_read_page_raw()
717 return -EIO; in rk_nfc_read_page_raw()
721 rk_nfc_read_buf(nfc, nfc->page_buf, mtd->writesize + mtd->oobsize); in rk_nfc_read_page_raw()
722 for (i = 0; i < ecc->steps; i++) { in rk_nfc_read_page_raw()
731 memcpy(rk_nfc_buf_to_oob_ptr(chip, ecc->steps - 1), in rk_nfc_read_page_raw()
735 memcpy(rk_nfc_buf_to_oob_ptr(chip, i - 1), in rk_nfc_read_page_raw()
742 ecc->bytes); in rk_nfc_read_page_raw()
748 ecc->size); in rk_nfc_read_page_raw()
760 struct nand_ecc_ctrl *ecc = &chip->ecc; in rk_nfc_read_page_hwecc()
761 int oob_step = (ecc->bytes > 60) ? NFC_MAX_OOB_PER_STEP : in rk_nfc_read_page_hwecc()
763 int pages_per_blk = mtd->erasesize / mtd->writesize; in rk_nfc_read_page_hwecc()
772 dma_data = dma_map_single(nfc->dev, nfc->page_buf, in rk_nfc_read_page_hwecc()
773 mtd->writesize, in rk_nfc_read_page_hwecc()
775 dma_oob = dma_map_single(nfc->dev, nfc->oob_buf, in rk_nfc_read_page_hwecc()
776 ecc->steps * oob_step, in rk_nfc_read_page_hwecc()
784 if ((page < (pages_per_blk * rknand->boot_blks)) && in rk_nfc_read_page_hwecc()
785 (chip->options & NAND_IS_BOOT_MEDIUM)) { in rk_nfc_read_page_hwecc()
787 if (rknand->boot_ecc != ecc->strength) in rk_nfc_read_page_hwecc()
788 rk_nfc_hw_ecc_setup(chip, rknand->boot_ecc); in rk_nfc_read_page_hwecc()
791 reinit_completion(&nfc->done); in rk_nfc_read_page_hwecc()
792 writel(INT_DMA, nfc->regs + nfc->cfg->int_en_off); in rk_nfc_read_page_hwecc()
793 rk_nfc_xfer_start(nfc, NFC_READ, ecc->steps, dma_data, in rk_nfc_read_page_hwecc()
795 ret = wait_for_completion_timeout(&nfc->done, in rk_nfc_read_page_hwecc()
798 dev_warn(nfc->dev, "read: wait dma done timeout.\n"); in rk_nfc_read_page_hwecc()
806 dma_unmap_single(nfc->dev, dma_data, mtd->writesize, in rk_nfc_read_page_hwecc()
808 dma_unmap_single(nfc->dev, dma_oob, ecc->steps * oob_step, in rk_nfc_read_page_hwecc()
812 ret = -ETIMEDOUT; in rk_nfc_read_page_hwecc()
813 dev_err(nfc->dev, "read: wait transfer done timeout.\n"); in rk_nfc_read_page_hwecc()
817 for (i = 0; i < ecc->steps; i++) { in rk_nfc_read_page_hwecc()
819 oob = chip->oob_poi + (ecc->steps - 1) * NFC_SYS_DATA_SIZE; in rk_nfc_read_page_hwecc()
821 oob = chip->oob_poi + (i - 1) * NFC_SYS_DATA_SIZE; in rk_nfc_read_page_hwecc()
823 if (nfc->cfg->type == NFC_V9) in rk_nfc_read_page_hwecc()
824 tmp = nfc->oob_buf[i]; in rk_nfc_read_page_hwecc()
826 tmp = nfc->oob_buf[i * (oob_step / 4)]; in rk_nfc_read_page_hwecc()
834 for (i = 0; i < (ecc->steps / 2); i++) { in rk_nfc_read_page_hwecc()
835 bch_st = readl_relaxed(nfc->regs + in rk_nfc_read_page_hwecc()
836 nfc->cfg->bch_st_off + i * 4); in rk_nfc_read_page_hwecc()
837 if (bch_st & BIT(nfc->cfg->ecc0.err_flag_bit) || in rk_nfc_read_page_hwecc()
838 bch_st & BIT(nfc->cfg->ecc1.err_flag_bit)) { in rk_nfc_read_page_hwecc()
839 mtd->ecc_stats.failed++; in rk_nfc_read_page_hwecc()
842 cnt = ECC_ERR_CNT(bch_st, nfc->cfg->ecc0); in rk_nfc_read_page_hwecc()
843 mtd->ecc_stats.corrected += cnt; in rk_nfc_read_page_hwecc()
846 cnt = ECC_ERR_CNT(bch_st, nfc->cfg->ecc1); in rk_nfc_read_page_hwecc()
847 mtd->ecc_stats.corrected += cnt; in rk_nfc_read_page_hwecc()
853 memcpy(buf, nfc->page_buf, mtd->writesize); in rk_nfc_read_page_hwecc()
856 if (boot_rom_mode && rknand->boot_ecc != ecc->strength) in rk_nfc_read_page_hwecc()
857 rk_nfc_hw_ecc_setup(chip, ecc->strength); in rk_nfc_read_page_hwecc()
863 dev_err(nfc->dev, "read page: %x ecc error!\n", page); in rk_nfc_read_page_hwecc()
878 writel(FMCTL_WP, nfc->regs + NFC_FMCTL); in rk_nfc_hw_init()
880 writel(0x1081, nfc->regs + NFC_FMWAIT); in rk_nfc_hw_init()
881 nfc->cur_timing = 0x1081; in rk_nfc_hw_init()
883 writel(0, nfc->regs + nfc->cfg->randmz_off); in rk_nfc_hw_init()
884 writel(0, nfc->regs + nfc->cfg->dma_cfg_off); in rk_nfc_hw_init()
885 writel(FLCTL_RST, nfc->regs + nfc->cfg->flctl_off); in rk_nfc_hw_init()
893 sta = readl_relaxed(nfc->regs + nfc->cfg->int_st_off); in rk_nfc_irq()
894 ien = readl_relaxed(nfc->regs + nfc->cfg->int_en_off); in rk_nfc_irq()
899 writel(sta, nfc->regs + nfc->cfg->int_clr_off); in rk_nfc_irq()
900 writel(~sta & ien, nfc->regs + nfc->cfg->int_en_off); in rk_nfc_irq()
902 complete(&nfc->done); in rk_nfc_irq()
911 if (!IS_ERR(nfc->nfc_clk)) { in rk_nfc_enable_clks()
912 ret = clk_prepare_enable(nfc->nfc_clk); in rk_nfc_enable_clks()
914 dev_err(dev, "failed to enable NFC clk\n"); in rk_nfc_enable_clks()
919 ret = clk_prepare_enable(nfc->ahb_clk); in rk_nfc_enable_clks()
921 dev_err(dev, "failed to enable ahb clk\n"); in rk_nfc_enable_clks()
922 clk_disable_unprepare(nfc->nfc_clk); in rk_nfc_enable_clks()
931 clk_disable_unprepare(nfc->nfc_clk); in rk_nfc_disable_clks()
932 clk_disable_unprepare(nfc->ahb_clk); in rk_nfc_disable_clks()
942 return -ERANGE; in rk_nfc_ooblayout_free()
944 oob_region->length = rknand->metadata_size - NFC_SYS_DATA_SIZE - 2; in rk_nfc_ooblayout_free()
945 oob_region->offset = 2; in rk_nfc_ooblayout_free()
957 return -ERANGE; in rk_nfc_ooblayout_ecc()
959 oob_region->length = mtd->oobsize - rknand->metadata_size; in rk_nfc_ooblayout_ecc()
960 oob_region->offset = rknand->metadata_size; in rk_nfc_ooblayout_ecc()
974 struct nand_ecc_ctrl *ecc = &chip->ecc; in rk_nfc_ecc_init()
975 const u8 *strengths = nfc->cfg->ecc_strengths; in rk_nfc_ecc_init()
979 nfc_max_strength = nfc->cfg->ecc_strengths[0]; in rk_nfc_ecc_init()
981 if (!ecc->size || !ecc->strength || in rk_nfc_ecc_init()
982 ecc->strength > nfc_max_strength) { in rk_nfc_ecc_init()
983 chip->ecc.size = 1024; in rk_nfc_ecc_init()
984 ecc->steps = mtd->writesize / ecc->size; in rk_nfc_ecc_init()
990 max_strength = ((mtd->oobsize / ecc->steps) - 4) * 8 / in rk_nfc_ecc_init()
1001 dev_err(nfc->dev, "unsupported ECC strength\n"); in rk_nfc_ecc_init()
1002 return -EOPNOTSUPP; in rk_nfc_ecc_init()
1005 ecc->strength = strengths[i]; in rk_nfc_ecc_init()
1007 ecc->steps = mtd->writesize / ecc->size; in rk_nfc_ecc_init()
1008 ecc->bytes = DIV_ROUND_UP(ecc->strength * fls(8 * chip->ecc.size), 8); in rk_nfc_ecc_init()
1016 struct device *dev = mtd->dev.parent; in rk_nfc_attach_chip()
1019 struct nand_ecc_ctrl *ecc = &chip->ecc; in rk_nfc_attach_chip()
1024 if (chip->options & NAND_BUSWIDTH_16) { in rk_nfc_attach_chip()
1026 return -EINVAL; in rk_nfc_attach_chip()
1029 if (ecc->engine_type != NAND_ECC_ENGINE_TYPE_ON_HOST) in rk_nfc_attach_chip()
1036 rknand->metadata_size = NFC_SYS_DATA_SIZE * ecc->steps; in rk_nfc_attach_chip()
1038 if (rknand->metadata_size < NFC_SYS_DATA_SIZE + 2) { in rk_nfc_attach_chip()
1042 return -EIO; in rk_nfc_attach_chip()
1046 new_page_len = mtd->writesize + mtd->oobsize; in rk_nfc_attach_chip()
1047 if (nfc->page_buf && new_page_len > nfc->page_buf_size) { in rk_nfc_attach_chip()
1048 buf = krealloc(nfc->page_buf, new_page_len, in rk_nfc_attach_chip()
1051 return -ENOMEM; in rk_nfc_attach_chip()
1052 nfc->page_buf = buf; in rk_nfc_attach_chip()
1053 nfc->page_buf_size = new_page_len; in rk_nfc_attach_chip()
1056 new_oob_len = ecc->steps * NFC_MAX_OOB_PER_STEP; in rk_nfc_attach_chip()
1057 if (nfc->oob_buf && new_oob_len > nfc->oob_buf_size) { in rk_nfc_attach_chip()
1058 buf = krealloc(nfc->oob_buf, new_oob_len, in rk_nfc_attach_chip()
1061 kfree(nfc->page_buf); in rk_nfc_attach_chip()
1062 nfc->page_buf = NULL; in rk_nfc_attach_chip()
1063 return -ENOMEM; in rk_nfc_attach_chip()
1065 nfc->oob_buf = buf; in rk_nfc_attach_chip()
1066 nfc->oob_buf_size = new_oob_len; in rk_nfc_attach_chip()
1069 if (!nfc->page_buf) { in rk_nfc_attach_chip()
1070 nfc->page_buf = kzalloc(new_page_len, GFP_KERNEL | GFP_DMA); in rk_nfc_attach_chip()
1071 if (!nfc->page_buf) in rk_nfc_attach_chip()
1072 return -ENOMEM; in rk_nfc_attach_chip()
1073 nfc->page_buf_size = new_page_len; in rk_nfc_attach_chip()
1076 if (!nfc->oob_buf) { in rk_nfc_attach_chip()
1077 nfc->oob_buf = kzalloc(new_oob_len, GFP_KERNEL | GFP_DMA); in rk_nfc_attach_chip()
1078 if (!nfc->oob_buf) { in rk_nfc_attach_chip()
1079 kfree(nfc->page_buf); in rk_nfc_attach_chip()
1080 nfc->page_buf = NULL; in rk_nfc_attach_chip()
1081 return -ENOMEM; in rk_nfc_attach_chip()
1083 nfc->oob_buf_size = new_oob_len; in rk_nfc_attach_chip()
1086 chip->ecc.write_page_raw = rk_nfc_write_page_raw; in rk_nfc_attach_chip()
1087 chip->ecc.write_page = rk_nfc_write_page_hwecc; in rk_nfc_attach_chip()
1088 chip->ecc.write_oob = rk_nfc_write_oob; in rk_nfc_attach_chip()
1090 chip->ecc.read_page_raw = rk_nfc_read_page_raw; in rk_nfc_attach_chip()
1091 chip->ecc.read_page = rk_nfc_read_page_hwecc; in rk_nfc_attach_chip()
1092 chip->ecc.read_oob = rk_nfc_read_oob; in rk_nfc_attach_chip()
1115 return -ENODEV; in rk_nfc_nand_chip_init()
1119 return -EINVAL; in rk_nfc_nand_chip_init()
1125 return -ENOMEM; in rk_nfc_nand_chip_init()
1127 rknand->nsels = nsels; in rk_nfc_nand_chip_init()
1137 return -EINVAL; in rk_nfc_nand_chip_init()
1140 if (test_and_set_bit(tmp, &nfc->assigned_cs)) { in rk_nfc_nand_chip_init()
1142 return -EINVAL; in rk_nfc_nand_chip_init()
1145 rknand->sels[i] = tmp; in rk_nfc_nand_chip_init()
1148 chip = &rknand->chip; in rk_nfc_nand_chip_init()
1149 chip->controller = &nfc->controller; in rk_nfc_nand_chip_init()
1155 chip->options |= NAND_USES_DMA | NAND_NO_SUBPAGE_WRITE; in rk_nfc_nand_chip_init()
1156 chip->bbt_options = NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB; in rk_nfc_nand_chip_init()
1159 chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; in rk_nfc_nand_chip_init()
1162 mtd->owner = THIS_MODULE; in rk_nfc_nand_chip_init()
1163 mtd->dev.parent = dev; in rk_nfc_nand_chip_init()
1165 if (!mtd->name) { in rk_nfc_nand_chip_init()
1166 dev_err(nfc->dev, "NAND label property is mandatory\n"); in rk_nfc_nand_chip_init()
1167 return -EINVAL; in rk_nfc_nand_chip_init()
1176 if (chip->options & NAND_IS_BOOT_MEDIUM) { in rk_nfc_nand_chip_init()
1177 ret = of_property_read_u32(np, "rockchip,boot-blks", &tmp); in rk_nfc_nand_chip_init()
1178 rknand->boot_blks = ret ? 0 : tmp; in rk_nfc_nand_chip_init()
1180 ret = of_property_read_u32(np, "rockchip,boot-ecc-strength", in rk_nfc_nand_chip_init()
1182 rknand->boot_ecc = ret ? chip->ecc.strength : tmp; in rk_nfc_nand_chip_init()
1192 list_add_tail(&rknand->node, &nfc->chips); in rk_nfc_nand_chip_init()
1203 list_for_each_entry_safe(rknand, tmp, &nfc->chips, node) { in rk_nfc_chips_cleanup()
1204 chip = &rknand->chip; in rk_nfc_chips_cleanup()
1208 list_del(&rknand->node); in rk_nfc_chips_cleanup()
1214 struct device_node *np = dev->of_node; in rk_nfc_nand_chips_init()
1219 dev_err(nfc->dev, "incorrect number of NAND chips (%d)\n", in rk_nfc_nand_chips_init()
1221 return -EINVAL; in rk_nfc_nand_chips_init()
1348 .compatible = "rockchip,px30-nfc",
1352 .compatible = "rockchip,rk2928-nfc",
1356 .compatible = "rockchip,rv1108-nfc",
1365 struct device *dev = &pdev->dev; in rk_nfc_probe()
1371 return -ENOMEM; in rk_nfc_probe()
1373 nand_controller_init(&nfc->controller); in rk_nfc_probe()
1374 INIT_LIST_HEAD(&nfc->chips); in rk_nfc_probe()
1375 nfc->controller.ops = &rk_nfc_controller_ops; in rk_nfc_probe()
1377 nfc->cfg = of_device_get_match_data(dev); in rk_nfc_probe()
1378 nfc->dev = dev; in rk_nfc_probe()
1380 init_completion(&nfc->done); in rk_nfc_probe()
1382 nfc->regs = devm_platform_ioremap_resource(pdev, 0); in rk_nfc_probe()
1383 if (IS_ERR(nfc->regs)) { in rk_nfc_probe()
1384 ret = PTR_ERR(nfc->regs); in rk_nfc_probe()
1388 nfc->nfc_clk = devm_clk_get(dev, "nfc"); in rk_nfc_probe()
1389 if (IS_ERR(nfc->nfc_clk)) { in rk_nfc_probe()
1390 dev_dbg(dev, "no NFC clk\n"); in rk_nfc_probe()
1391 /* Some earlier models, such as rk3066, have no NFC clk. */ in rk_nfc_probe()
1394 nfc->ahb_clk = devm_clk_get(dev, "ahb"); in rk_nfc_probe()
1395 if (IS_ERR(nfc->ahb_clk)) { in rk_nfc_probe()
1396 dev_err(dev, "no ahb clk\n"); in rk_nfc_probe()
1397 ret = PTR_ERR(nfc->ahb_clk); in rk_nfc_probe()
1407 ret = -EINVAL; in rk_nfc_probe()
1411 writel(0, nfc->regs + nfc->cfg->int_en_off); in rk_nfc_probe()
1412 ret = devm_request_irq(dev, irq, rk_nfc_irq, 0x0, "rk-nand", nfc); in rk_nfc_probe()
1437 kfree(nfc->page_buf); in rk_nfc_remove()
1438 kfree(nfc->oob_buf); in rk_nfc_remove()
1465 list_for_each_entry(rknand, &nfc->chips, node) { in rk_nfc_resume()
1466 chip = &rknand->chip; in rk_nfc_resume()
1467 for (i = 0; i < rknand->nsels; i++) in rk_nfc_resume()
1482 .name = "rockchip-nfc",
1491 MODULE_AUTHOR("Yifeng Zhao <yifeng.zhao@rock-chips.com>");
1493 MODULE_ALIAS("platform:rockchip-nand-controller");