Lines Matching +full:ctrl +full:- +full:len
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright 2011-2012 Freescale Semiconductor, Inc
32 struct fsl_ifc_ctrl *ctrl; member
51 unsigned int eccread; /* Non zero for a full-page ECC read */
67 .offs = 2, /* 0 on 8-bit small page */
68 .len = 4,
77 .offs = 2, /* 0 on 8-bit small page */
78 .len = 4,
90 return -ERANGE; in fsl_ifc_ooblayout_ecc()
92 oobregion->offset = 8; in fsl_ifc_ooblayout_ecc()
93 oobregion->length = chip->ecc.total; in fsl_ifc_ooblayout_ecc()
104 return -ERANGE; in fsl_ifc_ooblayout_free()
106 if (mtd->writesize == 512 && in fsl_ifc_ooblayout_free()
107 !(chip->options & NAND_BUSWIDTH_16)) { in fsl_ifc_ooblayout_free()
109 oobregion->offset = 0; in fsl_ifc_ooblayout_free()
110 oobregion->length = 5; in fsl_ifc_ooblayout_free()
112 oobregion->offset = 6; in fsl_ifc_ooblayout_free()
113 oobregion->length = 2; in fsl_ifc_ooblayout_free()
120 oobregion->offset = 2; in fsl_ifc_ooblayout_free()
121 oobregion->length = 6; in fsl_ifc_ooblayout_free()
123 oobregion->offset = chip->ecc.total + 8; in fsl_ifc_ooblayout_free()
124 oobregion->length = mtd->oobsize - oobregion->offset; in fsl_ifc_ooblayout_free()
143 struct fsl_ifc_ctrl *ctrl = priv->ctrl; in set_addr() local
144 struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs; in set_addr()
147 ifc_nand_ctrl->page = page_addr; in set_addr()
149 ifc_out32(page_addr, &ifc->ifc_nand.row0); in set_addr()
150 ifc_out32((oob ? IFC_NAND_COL_MS : 0) | column, &ifc->ifc_nand.col0); in set_addr()
152 buf_num = page_addr & priv->bufnum_mask; in set_addr()
154 ifc_nand_ctrl->addr = priv->vbase + buf_num * (mtd->writesize * 2); in set_addr()
155 ifc_nand_ctrl->index = column; in set_addr()
159 ifc_nand_ctrl->index += mtd->writesize; in set_addr()
163 static int check_read_ecc(struct mtd_info *mtd, struct fsl_ifc_ctrl *ctrl, in check_read_ecc() argument
166 return (eccstat >> ((3 - bufnum % 4) * 8)) & 15; in check_read_ecc()
176 struct fsl_ifc_ctrl *ctrl = priv->ctrl; in fsl_ifc_run_command() local
178 struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs; in fsl_ifc_run_command()
183 ifc_out32(priv->bank << IFC_NAND_CSEL_SHIFT, in fsl_ifc_run_command()
184 &ifc->ifc_nand.nand_csel); in fsl_ifc_run_command()
186 dev_vdbg(priv->dev, in fsl_ifc_run_command()
189 ifc_in32(&ifc->ifc_nand.nand_fir0), in fsl_ifc_run_command()
190 ifc_in32(&ifc->ifc_nand.nand_fcr0)); in fsl_ifc_run_command()
192 ctrl->nand_stat = 0; in fsl_ifc_run_command()
195 ifc_out32(IFC_NAND_SEQ_STRT_FIR_STRT, &ifc->ifc_nand.nandseq_strt); in fsl_ifc_run_command()
198 wait_event_timeout(ctrl->nand_wait, ctrl->nand_stat, in fsl_ifc_run_command()
201 /* ctrl->nand_stat will be updated from IRQ context */ in fsl_ifc_run_command()
202 if (!ctrl->nand_stat) in fsl_ifc_run_command()
203 dev_err(priv->dev, "Controller is not responding\n"); in fsl_ifc_run_command()
204 if (ctrl->nand_stat & IFC_NAND_EVTER_STAT_FTOER) in fsl_ifc_run_command()
205 dev_err(priv->dev, "NAND Flash Timeout Error\n"); in fsl_ifc_run_command()
206 if (ctrl->nand_stat & IFC_NAND_EVTER_STAT_WPER) in fsl_ifc_run_command()
207 dev_err(priv->dev, "NAND Flash Write Protect Error\n"); in fsl_ifc_run_command()
209 nctrl->max_bitflips = 0; in fsl_ifc_run_command()
211 if (nctrl->eccread) { in fsl_ifc_run_command()
213 int bufnum = nctrl->page & priv->bufnum_mask; in fsl_ifc_run_command()
214 int sector_start = bufnum * chip->ecc.steps; in fsl_ifc_run_command()
215 int sector_end = sector_start + chip->ecc.steps - 1; in fsl_ifc_run_command()
218 eccstat_regs = ifc->ifc_nand.nand_eccstat; in fsl_ifc_run_command()
225 errors = check_read_ecc(mtd, ctrl, eccstat, i); in fsl_ifc_run_command()
233 * erratum IFC-A002770 -- so report it now if we in fsl_ifc_run_command()
236 ctrl->nand_stat |= IFC_NAND_EVTER_STAT_ECCER; in fsl_ifc_run_command()
240 mtd->ecc_stats.corrected += errors; in fsl_ifc_run_command()
241 nctrl->max_bitflips = max_t(unsigned int, in fsl_ifc_run_command()
242 nctrl->max_bitflips, in fsl_ifc_run_command()
246 nctrl->eccread = 0; in fsl_ifc_run_command()
255 struct fsl_ifc_ctrl *ctrl = priv->ctrl; in fsl_ifc_do_read() local
256 struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs; in fsl_ifc_do_read()
259 if (mtd->writesize > 512) { in fsl_ifc_do_read()
265 &ifc->ifc_nand.nand_fir0); in fsl_ifc_do_read()
266 ifc_out32(0x0, &ifc->ifc_nand.nand_fir1); in fsl_ifc_do_read()
270 &ifc->ifc_nand.nand_fcr0); in fsl_ifc_do_read()
276 &ifc->ifc_nand.nand_fir0); in fsl_ifc_do_read()
277 ifc_out32(0x0, &ifc->ifc_nand.nand_fir1); in fsl_ifc_do_read()
282 &ifc->ifc_nand.nand_fcr0); in fsl_ifc_do_read()
286 &ifc->ifc_nand.nand_fcr0); in fsl_ifc_do_read()
295 struct fsl_ifc_ctrl *ctrl = priv->ctrl; in fsl_ifc_cmdfunc() local
296 struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs; in fsl_ifc_cmdfunc()
299 ifc_nand_ctrl->read_bytes = 0; in fsl_ifc_cmdfunc()
301 ifc_nand_ctrl->index = 0; in fsl_ifc_cmdfunc()
306 ifc_out32(0, &ifc->ifc_nand.nand_fbcr); in fsl_ifc_cmdfunc()
309 ifc_nand_ctrl->read_bytes = mtd->writesize + mtd->oobsize; in fsl_ifc_cmdfunc()
310 ifc_nand_ctrl->index += column; in fsl_ifc_cmdfunc()
312 if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_ON_HOST) in fsl_ifc_cmdfunc()
313 ifc_nand_ctrl->eccread = 1; in fsl_ifc_cmdfunc()
321 ifc_out32(mtd->oobsize - column, &ifc->ifc_nand.nand_fbcr); in fsl_ifc_cmdfunc()
324 ifc_nand_ctrl->read_bytes = mtd->writesize + mtd->oobsize; in fsl_ifc_cmdfunc()
335 * For PARAM, read all 3 copies of 256-bytes pages. in fsl_ifc_cmdfunc()
337 int len = 8; in fsl_ifc_cmdfunc() local
341 len = 256 * 3; in fsl_ifc_cmdfunc()
347 &ifc->ifc_nand.nand_fir0); in fsl_ifc_cmdfunc()
349 &ifc->ifc_nand.nand_fcr0); in fsl_ifc_cmdfunc()
350 ifc_out32(column, &ifc->ifc_nand.row3); in fsl_ifc_cmdfunc()
352 ifc_out32(len, &ifc->ifc_nand.nand_fbcr); in fsl_ifc_cmdfunc()
353 ifc_nand_ctrl->read_bytes = len; in fsl_ifc_cmdfunc()
370 &ifc->ifc_nand.nand_fir0); in fsl_ifc_cmdfunc()
374 &ifc->ifc_nand.nand_fcr0); in fsl_ifc_cmdfunc()
376 ifc_out32(0, &ifc->ifc_nand.nand_fbcr); in fsl_ifc_cmdfunc()
377 ifc_nand_ctrl->read_bytes = 0; in fsl_ifc_cmdfunc()
384 ifc_nand_ctrl->column = column; in fsl_ifc_cmdfunc()
385 ifc_nand_ctrl->oob = 0; in fsl_ifc_cmdfunc()
387 if (mtd->writesize > 512) { in fsl_ifc_cmdfunc()
399 &ifc->ifc_nand.nand_fir0); in fsl_ifc_cmdfunc()
404 &ifc->ifc_nand.nand_fir1); in fsl_ifc_cmdfunc()
419 &ifc->ifc_nand.nand_fir0); in fsl_ifc_cmdfunc()
425 &ifc->ifc_nand.nand_fir1); in fsl_ifc_cmdfunc()
427 if (column >= mtd->writesize) in fsl_ifc_cmdfunc()
435 if (column >= mtd->writesize) { in fsl_ifc_cmdfunc()
436 /* OOB area --> READOOB */ in fsl_ifc_cmdfunc()
437 column -= mtd->writesize; in fsl_ifc_cmdfunc()
438 ifc_nand_ctrl->oob = 1; in fsl_ifc_cmdfunc()
440 ifc_out32(nand_fcr0, &ifc->ifc_nand.nand_fcr0); in fsl_ifc_cmdfunc()
441 set_addr(mtd, column, page_addr, ifc_nand_ctrl->oob); in fsl_ifc_cmdfunc()
447 if (ifc_nand_ctrl->oob) { in fsl_ifc_cmdfunc()
448 ifc_out32(ifc_nand_ctrl->index - in fsl_ifc_cmdfunc()
449 ifc_nand_ctrl->column, in fsl_ifc_cmdfunc()
450 &ifc->ifc_nand.nand_fbcr); in fsl_ifc_cmdfunc()
452 ifc_out32(0, &ifc->ifc_nand.nand_fbcr); in fsl_ifc_cmdfunc()
464 &ifc->ifc_nand.nand_fir0); in fsl_ifc_cmdfunc()
466 &ifc->ifc_nand.nand_fcr0); in fsl_ifc_cmdfunc()
467 ifc_out32(1, &ifc->ifc_nand.nand_fbcr); in fsl_ifc_cmdfunc()
469 ifc_nand_ctrl->read_bytes = 1; in fsl_ifc_cmdfunc()
475 * write-protected, even when it is not. in fsl_ifc_cmdfunc()
477 addr = ifc_nand_ctrl->addr; in fsl_ifc_cmdfunc()
478 if (chip->options & NAND_BUSWIDTH_16) in fsl_ifc_cmdfunc()
487 &ifc->ifc_nand.nand_fir0); in fsl_ifc_cmdfunc()
489 &ifc->ifc_nand.nand_fcr0); in fsl_ifc_cmdfunc()
494 dev_err(priv->dev, "%s: error, unsupported command 0x%x.\n", in fsl_ifc_cmdfunc()
509 static void fsl_ifc_write_buf(struct nand_chip *chip, const u8 *buf, int len) in fsl_ifc_write_buf() argument
513 unsigned int bufsize = mtd->writesize + mtd->oobsize; in fsl_ifc_write_buf()
515 if (len <= 0) { in fsl_ifc_write_buf()
516 dev_err(priv->dev, "%s: len %d bytes", __func__, len); in fsl_ifc_write_buf()
520 if ((unsigned int)len > bufsize - ifc_nand_ctrl->index) { in fsl_ifc_write_buf()
521 dev_err(priv->dev, in fsl_ifc_write_buf()
523 __func__, len, bufsize - ifc_nand_ctrl->index); in fsl_ifc_write_buf()
524 len = bufsize - ifc_nand_ctrl->index; in fsl_ifc_write_buf()
527 memcpy_toio(ifc_nand_ctrl->addr + ifc_nand_ctrl->index, buf, len); in fsl_ifc_write_buf()
528 ifc_nand_ctrl->index += len; in fsl_ifc_write_buf()
533 * read function for 8-bit buswidth
544 if (ifc_nand_ctrl->index < ifc_nand_ctrl->read_bytes) { in fsl_ifc_read_byte()
545 offset = ifc_nand_ctrl->index++; in fsl_ifc_read_byte()
546 return ifc_in8(ifc_nand_ctrl->addr + offset); in fsl_ifc_read_byte()
549 dev_err(priv->dev, "%s: beyond end of buffer\n", __func__); in fsl_ifc_read_byte()
555 * read function for 16-bit buswith
566 if (ifc_nand_ctrl->index < ifc_nand_ctrl->read_bytes) { in fsl_ifc_read_byte16()
567 data = ifc_in16(ifc_nand_ctrl->addr + ifc_nand_ctrl->index); in fsl_ifc_read_byte16()
568 ifc_nand_ctrl->index += 2; in fsl_ifc_read_byte16()
572 dev_err(priv->dev, "%s: beyond end of buffer\n", __func__); in fsl_ifc_read_byte16()
579 static void fsl_ifc_read_buf(struct nand_chip *chip, u8 *buf, int len) in fsl_ifc_read_buf() argument
584 if (len < 0) { in fsl_ifc_read_buf()
585 dev_err(priv->dev, "%s: len %d bytes", __func__, len); in fsl_ifc_read_buf()
589 avail = min((unsigned int)len, in fsl_ifc_read_buf()
590 ifc_nand_ctrl->read_bytes - ifc_nand_ctrl->index); in fsl_ifc_read_buf()
591 memcpy_fromio(buf, ifc_nand_ctrl->addr + ifc_nand_ctrl->index, avail); in fsl_ifc_read_buf()
592 ifc_nand_ctrl->index += avail; in fsl_ifc_read_buf()
594 if (len > avail) in fsl_ifc_read_buf()
595 dev_err(priv->dev, in fsl_ifc_read_buf()
597 __func__, len, avail); in fsl_ifc_read_buf()
608 struct fsl_ifc_ctrl *ctrl = priv->ctrl; in fsl_ifc_wait() local
609 struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs; in fsl_ifc_wait()
616 &ifc->ifc_nand.nand_fir0); in fsl_ifc_wait()
618 &ifc->ifc_nand.nand_fcr0); in fsl_ifc_wait()
619 ifc_out32(1, &ifc->ifc_nand.nand_fbcr); in fsl_ifc_wait()
621 ifc_nand_ctrl->read_bytes = 1; in fsl_ifc_wait()
625 nand_fsr = ifc_in32(&ifc->ifc_nand.nand_fsr); in fsl_ifc_wait()
629 * write-protected, even when it is not. in fsl_ifc_wait()
641 u8 *ecc = chip->oob_poi; in check_erased_page()
642 const int ecc_size = chip->ecc.bytes; in check_erased_page()
643 const int pkt_size = chip->ecc.size; in check_erased_page()
650 for (i = 0; i < chip->ecc.steps; ++i) { in check_erased_page()
653 chip->ecc.strength); in check_erased_page()
655 mtd->ecc_stats.failed++; in check_erased_page()
657 mtd->ecc_stats.corrected += res; in check_erased_page()
672 struct fsl_ifc_ctrl *ctrl = priv->ctrl; in fsl_ifc_read_page() local
675 nand_read_page_op(chip, page, 0, buf, mtd->writesize); in fsl_ifc_read_page()
677 fsl_ifc_read_buf(chip, chip->oob_poi, mtd->oobsize); in fsl_ifc_read_page()
679 if (ctrl->nand_stat & IFC_NAND_EVTER_STAT_ECCER) { in fsl_ifc_read_page()
681 fsl_ifc_read_buf(chip, chip->oob_poi, mtd->oobsize); in fsl_ifc_read_page()
686 if (ctrl->nand_stat != IFC_NAND_EVTER_STAT_OPC) in fsl_ifc_read_page()
687 mtd->ecc_stats.failed++; in fsl_ifc_read_page()
689 return nctrl->max_bitflips; in fsl_ifc_read_page()
700 nand_prog_page_begin_op(chip, page, 0, buf, mtd->writesize); in fsl_ifc_write_page()
701 fsl_ifc_write_buf(chip, chip->oob_poi, mtd->oobsize); in fsl_ifc_write_page()
710 struct fsl_ifc_ctrl *ctrl = priv->ctrl; in fsl_ifc_attach_chip() local
711 struct fsl_ifc_global __iomem *ifc_global = ctrl->gregs; in fsl_ifc_attach_chip()
714 csor = ifc_in32(&ifc_global->csor_cs[priv->bank].csor); in fsl_ifc_attach_chip()
718 chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; in fsl_ifc_attach_chip()
722 chip->ecc.size = 512; in fsl_ifc_attach_chip()
724 chip->ecc.bytes = 8; in fsl_ifc_attach_chip()
725 chip->ecc.strength = 4; in fsl_ifc_attach_chip()
727 chip->ecc.bytes = 16; in fsl_ifc_attach_chip()
728 chip->ecc.strength = 8; in fsl_ifc_attach_chip()
731 chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT; in fsl_ifc_attach_chip()
732 chip->ecc.algo = NAND_ECC_ALGO_HAMMING; in fsl_ifc_attach_chip()
735 dev_dbg(priv->dev, "%s: nand->numchips = %d\n", __func__, in fsl_ifc_attach_chip()
736 nanddev_ntargets(&chip->base)); in fsl_ifc_attach_chip()
737 dev_dbg(priv->dev, "%s: nand->chipsize = %lld\n", __func__, in fsl_ifc_attach_chip()
738 nanddev_target_size(&chip->base)); in fsl_ifc_attach_chip()
739 dev_dbg(priv->dev, "%s: nand->pagemask = %8x\n", __func__, in fsl_ifc_attach_chip()
740 chip->pagemask); in fsl_ifc_attach_chip()
741 dev_dbg(priv->dev, "%s: nand->legacy.chip_delay = %d\n", __func__, in fsl_ifc_attach_chip()
742 chip->legacy.chip_delay); in fsl_ifc_attach_chip()
743 dev_dbg(priv->dev, "%s: nand->badblockpos = %d\n", __func__, in fsl_ifc_attach_chip()
744 chip->badblockpos); in fsl_ifc_attach_chip()
745 dev_dbg(priv->dev, "%s: nand->chip_shift = %d\n", __func__, in fsl_ifc_attach_chip()
746 chip->chip_shift); in fsl_ifc_attach_chip()
747 dev_dbg(priv->dev, "%s: nand->page_shift = %d\n", __func__, in fsl_ifc_attach_chip()
748 chip->page_shift); in fsl_ifc_attach_chip()
749 dev_dbg(priv->dev, "%s: nand->phys_erase_shift = %d\n", __func__, in fsl_ifc_attach_chip()
750 chip->phys_erase_shift); in fsl_ifc_attach_chip()
751 dev_dbg(priv->dev, "%s: nand->ecc.engine_type = %d\n", __func__, in fsl_ifc_attach_chip()
752 chip->ecc.engine_type); in fsl_ifc_attach_chip()
753 dev_dbg(priv->dev, "%s: nand->ecc.steps = %d\n", __func__, in fsl_ifc_attach_chip()
754 chip->ecc.steps); in fsl_ifc_attach_chip()
755 dev_dbg(priv->dev, "%s: nand->ecc.bytes = %d\n", __func__, in fsl_ifc_attach_chip()
756 chip->ecc.bytes); in fsl_ifc_attach_chip()
757 dev_dbg(priv->dev, "%s: nand->ecc.total = %d\n", __func__, in fsl_ifc_attach_chip()
758 chip->ecc.total); in fsl_ifc_attach_chip()
759 dev_dbg(priv->dev, "%s: mtd->ooblayout = %p\n", __func__, in fsl_ifc_attach_chip()
760 mtd->ooblayout); in fsl_ifc_attach_chip()
761 dev_dbg(priv->dev, "%s: mtd->flags = %08x\n", __func__, mtd->flags); in fsl_ifc_attach_chip()
762 dev_dbg(priv->dev, "%s: mtd->size = %lld\n", __func__, mtd->size); in fsl_ifc_attach_chip()
763 dev_dbg(priv->dev, "%s: mtd->erasesize = %d\n", __func__, in fsl_ifc_attach_chip()
764 mtd->erasesize); in fsl_ifc_attach_chip()
765 dev_dbg(priv->dev, "%s: mtd->writesize = %d\n", __func__, in fsl_ifc_attach_chip()
766 mtd->writesize); in fsl_ifc_attach_chip()
767 dev_dbg(priv->dev, "%s: mtd->oobsize = %d\n", __func__, in fsl_ifc_attach_chip()
768 mtd->oobsize); in fsl_ifc_attach_chip()
779 struct fsl_ifc_ctrl *ctrl = priv->ctrl; in fsl_ifc_sram_init() local
780 struct fsl_ifc_runtime __iomem *ifc_runtime = ctrl->rregs; in fsl_ifc_sram_init()
781 struct fsl_ifc_global __iomem *ifc_global = ctrl->gregs; in fsl_ifc_sram_init()
783 uint32_t cs = priv->bank; in fsl_ifc_sram_init()
785 if (ctrl->version < FSL_IFC_VERSION_1_1_0) in fsl_ifc_sram_init()
788 if (ctrl->version > FSL_IFC_VERSION_1_1_0) { in fsl_ifc_sram_init()
793 ncfgr = ifc_in32(&ifc_runtime->ifc_nand.ncfgr); in fsl_ifc_sram_init()
794 ifc_out32(ncfgr | IFC_NAND_NCFGR_SRAM_INIT_EN, &ifc_runtime->ifc_nand.ncfgr); in fsl_ifc_sram_init()
797 ret = readx_poll_timeout(ifc_in32, &ifc_runtime->ifc_nand.ncfgr, in fsl_ifc_sram_init()
801 dev_err(priv->dev, "Failed to initialize SRAM!\n"); in fsl_ifc_sram_init()
807 csor = ifc_in32(&ifc_global->csor_cs[cs].csor); in fsl_ifc_sram_init()
808 csor_ext = ifc_in32(&ifc_global->csor_cs[cs].csor_ext); in fsl_ifc_sram_init()
812 ifc_out32(csor_8k, &ifc_global->csor_cs[cs].csor); in fsl_ifc_sram_init()
813 ifc_out32(0x0000400, &ifc_global->csor_cs[cs].csor_ext); in fsl_ifc_sram_init()
819 &ifc_runtime->ifc_nand.nand_fir0); in fsl_ifc_sram_init()
821 &ifc_runtime->ifc_nand.nand_fcr0); in fsl_ifc_sram_init()
822 ifc_out32(0x0, &ifc_runtime->ifc_nand.row3); in fsl_ifc_sram_init()
824 ifc_out32(0x0, &ifc_runtime->ifc_nand.nand_fbcr); in fsl_ifc_sram_init()
827 ifc_out32(0x0, &ifc_runtime->ifc_nand.row0); in fsl_ifc_sram_init()
828 ifc_out32(0x0, &ifc_runtime->ifc_nand.col0); in fsl_ifc_sram_init()
832 &ifc_runtime->ifc_nand.nand_csel); in fsl_ifc_sram_init()
836 &ifc_runtime->ifc_nand.nandseq_strt); in fsl_ifc_sram_init()
839 wait_event_timeout(ctrl->nand_wait, ctrl->nand_stat, in fsl_ifc_sram_init()
842 if (ctrl->nand_stat != IFC_NAND_EVTER_STAT_OPC) { in fsl_ifc_sram_init()
843 pr_err("fsl-ifc: Failed to Initialise SRAM\n"); in fsl_ifc_sram_init()
844 return -ETIMEDOUT; in fsl_ifc_sram_init()
848 ifc_out32(csor, &ifc_global->csor_cs[cs].csor); in fsl_ifc_sram_init()
849 ifc_out32(csor_ext, &ifc_global->csor_cs[cs].csor_ext); in fsl_ifc_sram_init()
856 struct fsl_ifc_ctrl *ctrl = priv->ctrl; in fsl_ifc_chip_init() local
857 struct fsl_ifc_global __iomem *ifc_global = ctrl->gregs; in fsl_ifc_chip_init()
858 struct fsl_ifc_runtime __iomem *ifc_runtime = ctrl->rregs; in fsl_ifc_chip_init()
859 struct nand_chip *chip = &priv->chip; in fsl_ifc_chip_init()
860 struct mtd_info *mtd = nand_to_mtd(&priv->chip); in fsl_ifc_chip_init()
865 mtd->dev.parent = priv->dev; in fsl_ifc_chip_init()
866 nand_set_flash_node(chip, priv->dev->of_node); in fsl_ifc_chip_init()
870 if ((ifc_in32(&ifc_global->cspr_cs[priv->bank].cspr)) in fsl_ifc_chip_init()
872 chip->legacy.read_byte = fsl_ifc_read_byte16; in fsl_ifc_chip_init()
874 chip->legacy.read_byte = fsl_ifc_read_byte; in fsl_ifc_chip_init()
876 chip->legacy.write_buf = fsl_ifc_write_buf; in fsl_ifc_chip_init()
877 chip->legacy.read_buf = fsl_ifc_read_buf; in fsl_ifc_chip_init()
878 chip->legacy.select_chip = fsl_ifc_select_chip; in fsl_ifc_chip_init()
879 chip->legacy.cmdfunc = fsl_ifc_cmdfunc; in fsl_ifc_chip_init()
880 chip->legacy.waitfunc = fsl_ifc_wait; in fsl_ifc_chip_init()
881 chip->legacy.set_features = nand_get_set_features_notsupp; in fsl_ifc_chip_init()
882 chip->legacy.get_features = nand_get_set_features_notsupp; in fsl_ifc_chip_init()
884 chip->bbt_td = &bbt_main_descr; in fsl_ifc_chip_init()
885 chip->bbt_md = &bbt_mirror_descr; in fsl_ifc_chip_init()
887 ifc_out32(0x0, &ifc_runtime->ifc_nand.ncfgr); in fsl_ifc_chip_init()
890 chip->bbt_options = NAND_BBT_USE_FLASH; in fsl_ifc_chip_init()
891 chip->options = NAND_NO_SUBPAGE_WRITE; in fsl_ifc_chip_init()
893 if (ifc_in32(&ifc_global->cspr_cs[priv->bank].cspr) in fsl_ifc_chip_init()
895 chip->legacy.read_byte = fsl_ifc_read_byte16; in fsl_ifc_chip_init()
896 chip->options |= NAND_BUSWIDTH_16; in fsl_ifc_chip_init()
898 chip->legacy.read_byte = fsl_ifc_read_byte; in fsl_ifc_chip_init()
901 chip->controller = &ifc_nand_ctrl->controller; in fsl_ifc_chip_init()
904 chip->ecc.read_page = fsl_ifc_read_page; in fsl_ifc_chip_init()
905 chip->ecc.write_page = fsl_ifc_write_page; in fsl_ifc_chip_init()
907 csor = ifc_in32(&ifc_global->csor_cs[priv->bank].csor); in fsl_ifc_chip_init()
911 if (!(chip->options & NAND_BUSWIDTH_16)) { in fsl_ifc_chip_init()
917 priv->bufnum_mask = 15; in fsl_ifc_chip_init()
921 priv->bufnum_mask = 3; in fsl_ifc_chip_init()
925 priv->bufnum_mask = 1; in fsl_ifc_chip_init()
929 priv->bufnum_mask = 0; in fsl_ifc_chip_init()
933 dev_err(priv->dev, "bad csor %#x: bad page size\n", csor); in fsl_ifc_chip_init()
934 return -ENODEV; in fsl_ifc_chip_init()
945 if (ctrl->version >= FSL_IFC_VERSION_2_0_0) in fsl_ifc_chip_init()
946 priv->bufnum_mask = (priv->bufnum_mask * 2) + 1; in fsl_ifc_chip_init()
953 struct mtd_info *mtd = nand_to_mtd(&priv->chip); in fsl_ifc_chip_remove()
955 kfree(mtd->name); in fsl_ifc_chip_remove()
957 if (priv->vbase) in fsl_ifc_chip_remove()
958 iounmap(priv->vbase); in fsl_ifc_chip_remove()
960 ifc_nand_ctrl->chips[priv->bank] = NULL; in fsl_ifc_chip_remove()
968 u32 cspr = ifc_in32(&ifc_global->cspr_cs[bank].cspr); in match_bank()
989 struct device_node *node = dev->dev.of_node; in fsl_ifc_nand_probe()
992 if (!fsl_ifc_ctrl_dev || !fsl_ifc_ctrl_dev->rregs) in fsl_ifc_nand_probe()
993 return -ENODEV; in fsl_ifc_nand_probe()
994 ifc = fsl_ifc_ctrl_dev->rregs; in fsl_ifc_nand_probe()
999 dev_err(&dev->dev, "%s: failed to get resource\n", __func__); in fsl_ifc_nand_probe()
1004 for (bank = 0; bank < fsl_ifc_ctrl_dev->banks; bank++) { in fsl_ifc_nand_probe()
1005 if (match_bank(fsl_ifc_ctrl_dev->gregs, bank, res.start)) in fsl_ifc_nand_probe()
1009 if (bank >= fsl_ifc_ctrl_dev->banks) { in fsl_ifc_nand_probe()
1010 dev_err(&dev->dev, "%s: address did not match any chip selects\n", in fsl_ifc_nand_probe()
1012 return -ENODEV; in fsl_ifc_nand_probe()
1015 priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL); in fsl_ifc_nand_probe()
1017 return -ENOMEM; in fsl_ifc_nand_probe()
1020 if (!fsl_ifc_ctrl_dev->nand) { in fsl_ifc_nand_probe()
1024 return -ENOMEM; in fsl_ifc_nand_probe()
1027 ifc_nand_ctrl->read_bytes = 0; in fsl_ifc_nand_probe()
1028 ifc_nand_ctrl->index = 0; in fsl_ifc_nand_probe()
1029 ifc_nand_ctrl->addr = NULL; in fsl_ifc_nand_probe()
1030 fsl_ifc_ctrl_dev->nand = ifc_nand_ctrl; in fsl_ifc_nand_probe()
1032 nand_controller_init(&ifc_nand_ctrl->controller); in fsl_ifc_nand_probe()
1034 ifc_nand_ctrl = fsl_ifc_ctrl_dev->nand; in fsl_ifc_nand_probe()
1038 ifc_nand_ctrl->chips[bank] = priv; in fsl_ifc_nand_probe()
1039 priv->bank = bank; in fsl_ifc_nand_probe()
1040 priv->ctrl = fsl_ifc_ctrl_dev; in fsl_ifc_nand_probe()
1041 priv->dev = &dev->dev; in fsl_ifc_nand_probe()
1043 priv->vbase = ioremap(res.start, resource_size(&res)); in fsl_ifc_nand_probe()
1044 if (!priv->vbase) { in fsl_ifc_nand_probe()
1045 dev_err(priv->dev, "%s: failed to map chip region\n", __func__); in fsl_ifc_nand_probe()
1046 ret = -ENOMEM; in fsl_ifc_nand_probe()
1050 dev_set_drvdata(priv->dev, priv); in fsl_ifc_nand_probe()
1055 &ifc->ifc_nand.nand_evter_en); in fsl_ifc_nand_probe()
1061 &ifc->ifc_nand.nand_evter_intr_en); in fsl_ifc_nand_probe()
1063 mtd = nand_to_mtd(&priv->chip); in fsl_ifc_nand_probe()
1064 mtd->name = kasprintf(GFP_KERNEL, "%llx.flash", (u64)res.start); in fsl_ifc_nand_probe()
1065 if (!mtd->name) { in fsl_ifc_nand_probe()
1066 ret = -ENOMEM; in fsl_ifc_nand_probe()
1074 priv->chip.controller->ops = &fsl_ifc_controller_ops; in fsl_ifc_nand_probe()
1075 ret = nand_scan(&priv->chip, 1); in fsl_ifc_nand_probe()
1085 dev_info(priv->dev, "IFC NAND device at 0x%llx, bank %d\n", in fsl_ifc_nand_probe()
1086 (unsigned long long)res.start, priv->bank); in fsl_ifc_nand_probe()
1091 nand_cleanup(&priv->chip); in fsl_ifc_nand_probe()
1100 struct fsl_ifc_mtd *priv = dev_get_drvdata(&dev->dev); in fsl_ifc_nand_remove()
1101 struct nand_chip *chip = &priv->chip; in fsl_ifc_nand_remove()
1111 ifc_nand_ctrl->counter--; in fsl_ifc_nand_remove()
1112 if (!ifc_nand_ctrl->counter) { in fsl_ifc_nand_remove()
1113 fsl_ifc_ctrl_dev->nand = NULL; in fsl_ifc_nand_remove()
1121 .compatible = "fsl,ifc-nand",
1129 .name = "fsl,ifc-nand",