X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=target%2Flinux%2Far71xx%2Ffiles%2Fdrivers%2Fmtd%2Fnand%2Far934x_nfc.c;h=a135e0f52f02172acf75311da44bfe9e48ae184c;hb=7bbf4117c6fe4b764d9d7c62fb2bcf6dd93bff2c;hp=923125159376656c5e160fdcd0dcaef5217c7536;hpb=7815af409af011e1a5572fde06450cb42130d461;p=openwrt%2Fstaging%2Fmkresin.git diff --git a/target/linux/ar71xx/files/drivers/mtd/nand/ar934x_nfc.c b/target/linux/ar71xx/files/drivers/mtd/nand/ar934x_nfc.c index 9231251593..a135e0f52f 100644 --- a/target/linux/ar71xx/files/drivers/mtd/nand/ar934x_nfc.c +++ b/target/linux/ar71xx/files/drivers/mtd/nand/ar934x_nfc.c @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -187,7 +188,9 @@ nfc_debug_data(const char *label, void *data, int len) {} #endif /* AR934X_NFC_DEBUG_DATA */ struct ar934x_nfc { +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0) struct mtd_info mtd; +#endif struct nand_chip nand_chip; struct device *parent; void __iomem *base; @@ -259,7 +262,22 @@ ar934x_nfc_get_platform_data(struct ar934x_nfc *nfc) static inline struct ar934x_nfc *mtd_to_ar934x_nfc(struct mtd_info *mtd) { +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0) return container_of(mtd, struct ar934x_nfc, mtd); +#else + struct nand_chip *chip = mtd_to_nand(mtd); + + return container_of(chip, struct ar934x_nfc, nand_chip); +#endif +} + +static struct mtd_info *ar934x_nfc_to_mtd(struct ar934x_nfc *nfc) +{ +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0) + return &nfc->mtd; +#else + return nand_to_mtd(&nfc->nand_chip); +#endif } static inline bool ar934x_nfc_use_irq(struct ar934x_nfc *nfc) @@ -648,7 +666,7 @@ ar934x_nfc_cmdfunc(struct mtd_info *mtd, unsigned int command, int column, int page_addr) { struct ar934x_nfc *nfc = mtd_to_ar934x_nfc(mtd); - struct nand_chip *nand = mtd->priv; + struct nand_chip *nand = &nfc->nand_chip; nfc->read_id = false; if (command != NAND_CMD_PAGEPROG) @@ -983,14 +1001,11 @@ ar934x_nfc_read_page(struct mtd_info *mtd, struct nand_chip *chip, static int ar934x_nfc_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, - const u8 *buf, int oob_required) + const u8 *buf, int oob_required, int page) { struct ar934x_nfc *nfc = mtd_to_ar934x_nfc(mtd); - int page; int len; - page = nfc->seqin_page_addr; - nfc_dbg(nfc, "write_page_raw: page:%d oob:%d\n", page, oob_required); memcpy(nfc->buf, buf, mtd->writesize); @@ -1006,14 +1021,11 @@ ar934x_nfc_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, static int ar934x_nfc_write_page(struct mtd_info *mtd, struct nand_chip *chip, - const u8 *buf, int oob_required) + const u8 *buf, int oob_required, int page) { struct ar934x_nfc *nfc = mtd_to_ar934x_nfc(mtd); - int page; int err; - page = nfc->seqin_page_addr; - nfc_dbg(nfc, "write_page: page:%d oob:%d\n", page, oob_required); /* write OOB first */ @@ -1247,6 +1259,7 @@ ar934x_nfc_init_tail(struct mtd_info *mtd) return err; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0) static struct nand_ecclayout ar934x_nfc_oob_64_hwecc = { .eccbytes = 28, .eccpos = { @@ -1267,19 +1280,60 @@ static struct nand_ecclayout ar934x_nfc_oob_64_hwecc = { }, }; +#else + +static int ar934x_nfc_ooblayout_ecc(struct mtd_info *mtd, int section, + struct mtd_oob_region *oobregion) +{ + if (section) + return -ERANGE; + + oobregion->offset = 20; + oobregion->length = 28; + + return 0; +} + +static int ar934x_nfc_ooblayout_free(struct mtd_info *mtd, int section, + struct mtd_oob_region *oobregion) +{ + switch (section) { + case 0: + oobregion->offset = 4; + oobregion->length = 16; + return 0; + case 1: + oobregion->offset = 48; + oobregion->length = 16; + return 0; + default: + return -ERANGE; + } +} + +static const struct mtd_ooblayout_ops ar934x_nfc_ecclayout_ops = { + .ecc = ar934x_nfc_ooblayout_ecc, + .free = ar934x_nfc_ooblayout_free, +}; +#endif /* < 4.6 */ + static int ar934x_nfc_setup_hwecc(struct ar934x_nfc *nfc) { struct nand_chip *nand = &nfc->nand_chip; + struct mtd_info *mtd = ar934x_nfc_to_mtd(nfc); u32 ecc_cap; u32 ecc_thres; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0) + struct mtd_oob_region oobregion; +#endif - if (!config_enabled(CONFIG_MTD_NAND_AR934X_HW_ECC)) { + if (!IS_ENABLED(CONFIG_MTD_NAND_AR934X_HW_ECC)) { dev_err(nfc->parent, "hardware ECC support is disabled\n"); return -EINVAL; } - switch (nfc->mtd.writesize) { + switch (mtd->writesize) { case 2048: /* * Writing a subpage separately is not supported, because @@ -1290,17 +1344,25 @@ ar934x_nfc_setup_hwecc(struct ar934x_nfc *nfc) nand->ecc.size = 512; nand->ecc.bytes = 7; nand->ecc.strength = 4; +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0) nand->ecc.layout = &ar934x_nfc_oob_64_hwecc; +#else + mtd_set_ooblayout(mtd, &ar934x_nfc_ecclayout_ops); +#endif break; default: dev_err(nfc->parent, "hardware ECC is not available for %d byte pages\n", - nfc->mtd.writesize); + mtd->writesize); return -EINVAL; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0) BUG_ON(!nand->ecc.layout); +#else + BUG_ON(!mtd->ooblayout->ecc); +#endif switch (nand->ecc.strength) { case 4: @@ -1315,12 +1377,17 @@ ar934x_nfc_setup_hwecc(struct ar934x_nfc *nfc) } nfc->ecc_thres = ecc_thres; +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0) nfc->ecc_oob_pos = nand->ecc.layout->eccpos[0]; +#else + mtd->ooblayout->ecc(mtd, 0, &oobregion); + nfc->ecc_oob_pos = oobregion.offset; +#endif nfc->ecc_ctrl_reg = ecc_cap << AR934X_NFC_ECC_CTRL_ECC_CAP_S; nfc->ecc_ctrl_reg |= ecc_thres << AR934X_NFC_ECC_CTRL_ERR_THRES_S; - nfc->ecc_offset_reg = nfc->mtd.writesize + nfc->ecc_oob_pos; + nfc->ecc_offset_reg = mtd->writesize + nfc->ecc_oob_pos; nand->ecc.mode = NAND_ECC_HW; nand->ecc.read_page = ar934x_nfc_read_page; @@ -1376,7 +1443,7 @@ ar934x_nfc_probe(struct platform_device *pdev) } init_waitqueue_head(&nfc->irq_waitq); - ret = request_irq(nfc->irq, ar934x_nfc_irq_handler, IRQF_DISABLED, + ret = request_irq(nfc->irq, ar934x_nfc_irq_handler, 0, dev_name(&pdev->dev), nfc); if (ret) { dev_err(&pdev->dev, "requast_irq failed, err:%d\n", ret); @@ -1388,9 +1455,11 @@ ar934x_nfc_probe(struct platform_device *pdev) nfc->swap_dma = pdata->swap_dma; nand = &nfc->nand_chip; - mtd = &nfc->mtd; + mtd = ar934x_nfc_to_mtd(nfc); +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0) mtd->priv = nand; +#endif mtd->owner = THIS_MODULE; if (pdata->name) mtd->name = pdata->name; @@ -1435,6 +1504,18 @@ ar934x_nfc_probe(struct platform_device *pdev) switch (pdata->ecc_mode) { case AR934X_NFC_ECC_SOFT: nand->ecc.mode = NAND_ECC_SOFT; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0) + nand->ecc.algo = NAND_ECC_HAMMING; +#endif + break; + + case AR934X_NFC_ECC_SOFT_BCH: +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0) + nand->ecc.mode = NAND_ECC_SOFT_BCH; +#else + nand->ecc.mode = NAND_ECC_SOFT; + nand->ecc.algo = NAND_ECC_BCH; +#endif break; case AR934X_NFC_ECC_HW: @@ -1476,10 +1557,12 @@ static int ar934x_nfc_remove(struct platform_device *pdev) { struct ar934x_nfc *nfc; + struct mtd_info *mtd; nfc = platform_get_drvdata(pdev); if (nfc) { - nand_release(&nfc->mtd); + mtd = ar934x_nfc_to_mtd(nfc); + nand_release(mtd); ar934x_nfc_free_buf(nfc); free_irq(nfc->irq, nfc); }