| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Freescale Integrated Flash Controller NAND driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2011-2012 Freescale Semiconductor, Inc |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Author: Dipen Dudhat <Dipen.Dudhat@freescale.com> |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 10 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | | - * (at your option) any later version. |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | | - * GNU General Public License for more details. |
|---|
| 17 | | - * |
|---|
| 18 | | - * You should have received a copy of the GNU General Public License |
|---|
| 19 | | - * along with this program; if not, write to the Free Software |
|---|
| 20 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 21 | 8 | */ |
|---|
| 22 | 9 | |
|---|
| 23 | 10 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 301 | 288 | } |
|---|
| 302 | 289 | |
|---|
| 303 | 290 | /* cmdfunc send commands to the IFC NAND Machine */ |
|---|
| 304 | | -static void fsl_ifc_cmdfunc(struct mtd_info *mtd, unsigned int command, |
|---|
| 305 | | - int column, int page_addr) { |
|---|
| 306 | | - struct nand_chip *chip = mtd_to_nand(mtd); |
|---|
| 291 | +static void fsl_ifc_cmdfunc(struct nand_chip *chip, unsigned int command, |
|---|
| 292 | + int column, int page_addr) { |
|---|
| 293 | + struct mtd_info *mtd = nand_to_mtd(chip); |
|---|
| 307 | 294 | struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); |
|---|
| 308 | 295 | struct fsl_ifc_ctrl *ctrl = priv->ctrl; |
|---|
| 309 | 296 | struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs; |
|---|
| .. | .. |
|---|
| 322 | 309 | ifc_nand_ctrl->read_bytes = mtd->writesize + mtd->oobsize; |
|---|
| 323 | 310 | ifc_nand_ctrl->index += column; |
|---|
| 324 | 311 | |
|---|
| 325 | | - if (chip->ecc.mode == NAND_ECC_HW) |
|---|
| 312 | + if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_ON_HOST) |
|---|
| 326 | 313 | ifc_nand_ctrl->eccread = 1; |
|---|
| 327 | 314 | |
|---|
| 328 | 315 | fsl_ifc_do_read(chip, 0, mtd); |
|---|
| .. | .. |
|---|
| 509 | 496 | } |
|---|
| 510 | 497 | } |
|---|
| 511 | 498 | |
|---|
| 512 | | -static void fsl_ifc_select_chip(struct mtd_info *mtd, int chip) |
|---|
| 499 | +static void fsl_ifc_select_chip(struct nand_chip *chip, int cs) |
|---|
| 513 | 500 | { |
|---|
| 514 | 501 | /* The hardware does not seem to support multiple |
|---|
| 515 | 502 | * chips per bank. |
|---|
| .. | .. |
|---|
| 519 | 506 | /* |
|---|
| 520 | 507 | * Write buf to the IFC NAND Controller Data Buffer |
|---|
| 521 | 508 | */ |
|---|
| 522 | | -static void fsl_ifc_write_buf(struct mtd_info *mtd, const u8 *buf, int len) |
|---|
| 509 | +static void fsl_ifc_write_buf(struct nand_chip *chip, const u8 *buf, int len) |
|---|
| 523 | 510 | { |
|---|
| 524 | | - struct nand_chip *chip = mtd_to_nand(mtd); |
|---|
| 511 | + struct mtd_info *mtd = nand_to_mtd(chip); |
|---|
| 525 | 512 | struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); |
|---|
| 526 | 513 | unsigned int bufsize = mtd->writesize + mtd->oobsize; |
|---|
| 527 | 514 | |
|---|
| .. | .. |
|---|
| 545 | 532 | * Read a byte from either the IFC hardware buffer |
|---|
| 546 | 533 | * read function for 8-bit buswidth |
|---|
| 547 | 534 | */ |
|---|
| 548 | | -static uint8_t fsl_ifc_read_byte(struct mtd_info *mtd) |
|---|
| 535 | +static uint8_t fsl_ifc_read_byte(struct nand_chip *chip) |
|---|
| 549 | 536 | { |
|---|
| 550 | | - struct nand_chip *chip = mtd_to_nand(mtd); |
|---|
| 551 | 537 | struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); |
|---|
| 552 | 538 | unsigned int offset; |
|---|
| 553 | 539 | |
|---|
| .. | .. |
|---|
| 568 | 554 | * Read two bytes from the IFC hardware buffer |
|---|
| 569 | 555 | * read function for 16-bit buswith |
|---|
| 570 | 556 | */ |
|---|
| 571 | | -static uint8_t fsl_ifc_read_byte16(struct mtd_info *mtd) |
|---|
| 557 | +static uint8_t fsl_ifc_read_byte16(struct nand_chip *chip) |
|---|
| 572 | 558 | { |
|---|
| 573 | | - struct nand_chip *chip = mtd_to_nand(mtd); |
|---|
| 574 | 559 | struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); |
|---|
| 575 | 560 | uint16_t data; |
|---|
| 576 | 561 | |
|---|
| .. | .. |
|---|
| 591 | 576 | /* |
|---|
| 592 | 577 | * Read from the IFC Controller Data Buffer |
|---|
| 593 | 578 | */ |
|---|
| 594 | | -static void fsl_ifc_read_buf(struct mtd_info *mtd, u8 *buf, int len) |
|---|
| 579 | +static void fsl_ifc_read_buf(struct nand_chip *chip, u8 *buf, int len) |
|---|
| 595 | 580 | { |
|---|
| 596 | | - struct nand_chip *chip = mtd_to_nand(mtd); |
|---|
| 597 | 581 | struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); |
|---|
| 598 | 582 | int avail; |
|---|
| 599 | 583 | |
|---|
| .. | .. |
|---|
| 617 | 601 | * This function is called after Program and Erase Operations to |
|---|
| 618 | 602 | * check for success or failure. |
|---|
| 619 | 603 | */ |
|---|
| 620 | | -static int fsl_ifc_wait(struct mtd_info *mtd, struct nand_chip *chip) |
|---|
| 604 | +static int fsl_ifc_wait(struct nand_chip *chip) |
|---|
| 621 | 605 | { |
|---|
| 606 | + struct mtd_info *mtd = nand_to_mtd(chip); |
|---|
| 622 | 607 | struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); |
|---|
| 623 | 608 | struct fsl_ifc_ctrl *ctrl = priv->ctrl; |
|---|
| 624 | 609 | struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs; |
|---|
| .. | .. |
|---|
| 679 | 664 | return bitflips; |
|---|
| 680 | 665 | } |
|---|
| 681 | 666 | |
|---|
| 682 | | -static int fsl_ifc_read_page(struct mtd_info *mtd, struct nand_chip *chip, |
|---|
| 683 | | - uint8_t *buf, int oob_required, int page) |
|---|
| 667 | +static int fsl_ifc_read_page(struct nand_chip *chip, uint8_t *buf, |
|---|
| 668 | + int oob_required, int page) |
|---|
| 684 | 669 | { |
|---|
| 670 | + struct mtd_info *mtd = nand_to_mtd(chip); |
|---|
| 685 | 671 | struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); |
|---|
| 686 | 672 | struct fsl_ifc_ctrl *ctrl = priv->ctrl; |
|---|
| 687 | 673 | struct fsl_ifc_nand_ctrl *nctrl = ifc_nand_ctrl; |
|---|
| 688 | 674 | |
|---|
| 689 | 675 | nand_read_page_op(chip, page, 0, buf, mtd->writesize); |
|---|
| 690 | 676 | if (oob_required) |
|---|
| 691 | | - fsl_ifc_read_buf(mtd, chip->oob_poi, mtd->oobsize); |
|---|
| 677 | + fsl_ifc_read_buf(chip, chip->oob_poi, mtd->oobsize); |
|---|
| 692 | 678 | |
|---|
| 693 | 679 | if (ctrl->nand_stat & IFC_NAND_EVTER_STAT_ECCER) { |
|---|
| 694 | 680 | if (!oob_required) |
|---|
| 695 | | - fsl_ifc_read_buf(mtd, chip->oob_poi, mtd->oobsize); |
|---|
| 681 | + fsl_ifc_read_buf(chip, chip->oob_poi, mtd->oobsize); |
|---|
| 696 | 682 | |
|---|
| 697 | 683 | return check_erased_page(chip, buf); |
|---|
| 698 | 684 | } |
|---|
| .. | .. |
|---|
| 706 | 692 | /* ECC will be calculated automatically, and errors will be detected in |
|---|
| 707 | 693 | * waitfunc. |
|---|
| 708 | 694 | */ |
|---|
| 709 | | -static int fsl_ifc_write_page(struct mtd_info *mtd, struct nand_chip *chip, |
|---|
| 710 | | - const uint8_t *buf, int oob_required, int page) |
|---|
| 695 | +static int fsl_ifc_write_page(struct nand_chip *chip, const uint8_t *buf, |
|---|
| 696 | + int oob_required, int page) |
|---|
| 711 | 697 | { |
|---|
| 698 | + struct mtd_info *mtd = nand_to_mtd(chip); |
|---|
| 699 | + |
|---|
| 712 | 700 | nand_prog_page_begin_op(chip, page, 0, buf, mtd->writesize); |
|---|
| 713 | | - fsl_ifc_write_buf(mtd, chip->oob_poi, mtd->oobsize); |
|---|
| 701 | + fsl_ifc_write_buf(chip, chip->oob_poi, mtd->oobsize); |
|---|
| 714 | 702 | |
|---|
| 715 | 703 | return nand_prog_page_end_op(chip); |
|---|
| 716 | 704 | } |
|---|
| .. | .. |
|---|
| 719 | 707 | { |
|---|
| 720 | 708 | struct mtd_info *mtd = nand_to_mtd(chip); |
|---|
| 721 | 709 | struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); |
|---|
| 710 | + struct fsl_ifc_ctrl *ctrl = priv->ctrl; |
|---|
| 711 | + struct fsl_ifc_global __iomem *ifc_global = ctrl->gregs; |
|---|
| 712 | + u32 csor; |
|---|
| 713 | + |
|---|
| 714 | + csor = ifc_in32(&ifc_global->csor_cs[priv->bank].csor); |
|---|
| 715 | + |
|---|
| 716 | + /* Must also set CSOR_NAND_ECC_ENC_EN if DEC_EN set */ |
|---|
| 717 | + if (csor & CSOR_NAND_ECC_DEC_EN) { |
|---|
| 718 | + chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; |
|---|
| 719 | + mtd_set_ooblayout(mtd, &fsl_ifc_ooblayout_ops); |
|---|
| 720 | + |
|---|
| 721 | + /* Hardware generates ECC per 512 Bytes */ |
|---|
| 722 | + chip->ecc.size = 512; |
|---|
| 723 | + if ((csor & CSOR_NAND_ECC_MODE_MASK) == CSOR_NAND_ECC_MODE_4) { |
|---|
| 724 | + chip->ecc.bytes = 8; |
|---|
| 725 | + chip->ecc.strength = 4; |
|---|
| 726 | + } else { |
|---|
| 727 | + chip->ecc.bytes = 16; |
|---|
| 728 | + chip->ecc.strength = 8; |
|---|
| 729 | + } |
|---|
| 730 | + } else { |
|---|
| 731 | + chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT; |
|---|
| 732 | + chip->ecc.algo = NAND_ECC_ALGO_HAMMING; |
|---|
| 733 | + } |
|---|
| 722 | 734 | |
|---|
| 723 | 735 | dev_dbg(priv->dev, "%s: nand->numchips = %d\n", __func__, |
|---|
| 724 | | - chip->numchips); |
|---|
| 736 | + nanddev_ntargets(&chip->base)); |
|---|
| 725 | 737 | dev_dbg(priv->dev, "%s: nand->chipsize = %lld\n", __func__, |
|---|
| 726 | | - chip->chipsize); |
|---|
| 738 | + nanddev_target_size(&chip->base)); |
|---|
| 727 | 739 | dev_dbg(priv->dev, "%s: nand->pagemask = %8x\n", __func__, |
|---|
| 728 | 740 | chip->pagemask); |
|---|
| 729 | | - dev_dbg(priv->dev, "%s: nand->chip_delay = %d\n", __func__, |
|---|
| 730 | | - chip->chip_delay); |
|---|
| 741 | + dev_dbg(priv->dev, "%s: nand->legacy.chip_delay = %d\n", __func__, |
|---|
| 742 | + chip->legacy.chip_delay); |
|---|
| 731 | 743 | dev_dbg(priv->dev, "%s: nand->badblockpos = %d\n", __func__, |
|---|
| 732 | 744 | chip->badblockpos); |
|---|
| 733 | 745 | dev_dbg(priv->dev, "%s: nand->chip_shift = %d\n", __func__, |
|---|
| .. | .. |
|---|
| 736 | 748 | chip->page_shift); |
|---|
| 737 | 749 | dev_dbg(priv->dev, "%s: nand->phys_erase_shift = %d\n", __func__, |
|---|
| 738 | 750 | chip->phys_erase_shift); |
|---|
| 739 | | - dev_dbg(priv->dev, "%s: nand->ecc.mode = %d\n", __func__, |
|---|
| 740 | | - chip->ecc.mode); |
|---|
| 751 | + dev_dbg(priv->dev, "%s: nand->ecc.engine_type = %d\n", __func__, |
|---|
| 752 | + chip->ecc.engine_type); |
|---|
| 741 | 753 | dev_dbg(priv->dev, "%s: nand->ecc.steps = %d\n", __func__, |
|---|
| 742 | 754 | chip->ecc.steps); |
|---|
| 743 | 755 | dev_dbg(priv->dev, "%s: nand->ecc.bytes = %d\n", __func__, |
|---|
| .. | .. |
|---|
| 857 | 869 | /* set up function call table */ |
|---|
| 858 | 870 | if ((ifc_in32(&ifc_global->cspr_cs[priv->bank].cspr)) |
|---|
| 859 | 871 | & CSPR_PORT_SIZE_16) |
|---|
| 860 | | - chip->read_byte = fsl_ifc_read_byte16; |
|---|
| 872 | + chip->legacy.read_byte = fsl_ifc_read_byte16; |
|---|
| 861 | 873 | else |
|---|
| 862 | | - chip->read_byte = fsl_ifc_read_byte; |
|---|
| 874 | + chip->legacy.read_byte = fsl_ifc_read_byte; |
|---|
| 863 | 875 | |
|---|
| 864 | | - chip->write_buf = fsl_ifc_write_buf; |
|---|
| 865 | | - chip->read_buf = fsl_ifc_read_buf; |
|---|
| 866 | | - chip->select_chip = fsl_ifc_select_chip; |
|---|
| 867 | | - chip->cmdfunc = fsl_ifc_cmdfunc; |
|---|
| 868 | | - chip->waitfunc = fsl_ifc_wait; |
|---|
| 869 | | - chip->set_features = nand_get_set_features_notsupp; |
|---|
| 870 | | - chip->get_features = nand_get_set_features_notsupp; |
|---|
| 876 | + chip->legacy.write_buf = fsl_ifc_write_buf; |
|---|
| 877 | + chip->legacy.read_buf = fsl_ifc_read_buf; |
|---|
| 878 | + chip->legacy.select_chip = fsl_ifc_select_chip; |
|---|
| 879 | + chip->legacy.cmdfunc = fsl_ifc_cmdfunc; |
|---|
| 880 | + chip->legacy.waitfunc = fsl_ifc_wait; |
|---|
| 881 | + chip->legacy.set_features = nand_get_set_features_notsupp; |
|---|
| 882 | + chip->legacy.get_features = nand_get_set_features_notsupp; |
|---|
| 871 | 883 | |
|---|
| 872 | 884 | chip->bbt_td = &bbt_main_descr; |
|---|
| 873 | 885 | chip->bbt_md = &bbt_mirror_descr; |
|---|
| .. | .. |
|---|
| 880 | 892 | |
|---|
| 881 | 893 | if (ifc_in32(&ifc_global->cspr_cs[priv->bank].cspr) |
|---|
| 882 | 894 | & CSPR_PORT_SIZE_16) { |
|---|
| 883 | | - chip->read_byte = fsl_ifc_read_byte16; |
|---|
| 895 | + chip->legacy.read_byte = fsl_ifc_read_byte16; |
|---|
| 884 | 896 | chip->options |= NAND_BUSWIDTH_16; |
|---|
| 885 | 897 | } else { |
|---|
| 886 | | - chip->read_byte = fsl_ifc_read_byte; |
|---|
| 898 | + chip->legacy.read_byte = fsl_ifc_read_byte; |
|---|
| 887 | 899 | } |
|---|
| 888 | 900 | |
|---|
| 889 | 901 | chip->controller = &ifc_nand_ctrl->controller; |
|---|
| .. | .. |
|---|
| 920 | 932 | default: |
|---|
| 921 | 933 | dev_err(priv->dev, "bad csor %#x: bad page size\n", csor); |
|---|
| 922 | 934 | return -ENODEV; |
|---|
| 923 | | - } |
|---|
| 924 | | - |
|---|
| 925 | | - /* Must also set CSOR_NAND_ECC_ENC_EN if DEC_EN set */ |
|---|
| 926 | | - if (csor & CSOR_NAND_ECC_DEC_EN) { |
|---|
| 927 | | - chip->ecc.mode = NAND_ECC_HW; |
|---|
| 928 | | - mtd_set_ooblayout(mtd, &fsl_ifc_ooblayout_ops); |
|---|
| 929 | | - |
|---|
| 930 | | - /* Hardware generates ECC per 512 Bytes */ |
|---|
| 931 | | - chip->ecc.size = 512; |
|---|
| 932 | | - if ((csor & CSOR_NAND_ECC_MODE_MASK) == CSOR_NAND_ECC_MODE_4) { |
|---|
| 933 | | - chip->ecc.bytes = 8; |
|---|
| 934 | | - chip->ecc.strength = 4; |
|---|
| 935 | | - } else { |
|---|
| 936 | | - chip->ecc.bytes = 16; |
|---|
| 937 | | - chip->ecc.strength = 8; |
|---|
| 938 | | - } |
|---|
| 939 | | - } else { |
|---|
| 940 | | - chip->ecc.mode = NAND_ECC_SOFT; |
|---|
| 941 | | - chip->ecc.algo = NAND_ECC_HAMMING; |
|---|
| 942 | 935 | } |
|---|
| 943 | 936 | |
|---|
| 944 | 937 | ret = fsl_ifc_sram_init(priv); |
|---|
| .. | .. |
|---|
| 1105 | 1098 | static int fsl_ifc_nand_remove(struct platform_device *dev) |
|---|
| 1106 | 1099 | { |
|---|
| 1107 | 1100 | struct fsl_ifc_mtd *priv = dev_get_drvdata(&dev->dev); |
|---|
| 1101 | + struct nand_chip *chip = &priv->chip; |
|---|
| 1102 | + int ret; |
|---|
| 1108 | 1103 | |
|---|
| 1109 | | - nand_release(&priv->chip); |
|---|
| 1104 | + ret = mtd_device_unregister(nand_to_mtd(chip)); |
|---|
| 1105 | + WARN_ON(ret); |
|---|
| 1106 | + nand_cleanup(chip); |
|---|
| 1107 | + |
|---|
| 1110 | 1108 | fsl_ifc_chip_remove(priv); |
|---|
| 1111 | 1109 | |
|---|
| 1112 | 1110 | mutex_lock(&fsl_ifc_nand_mutex); |
|---|