ath79: ar934x: still advertise subpage on soft ecc
[openwrt/staging/chunkeey.git] / target / linux / ath79 / files / drivers / mtd / nand / raw / ar934x_nand.c
index ddc6d6d882c2619787eef7392e06101dbd3ce61e..28bdcb066d6032541fdfcad5781fba3ee1ab72c6 100644 (file)
@@ -14,9 +14,7 @@
 #include <linux/module.h>
 #include <linux/dma-mapping.h>
 #include <linux/mtd/mtd.h>
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
 #include <linux/mtd/nand.h>
-#endif
 #include <linux/mtd/rawnand.h>
 #include <linux/mtd/partitions.h>
 #include <linux/platform_device.h>
@@ -722,11 +720,7 @@ static void ar934x_nfc_cmdfunc(struct nand_chip *nand, unsigned int command,
                break;
 
        case NAND_CMD_PAGEPROG:
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
                if (nand->ecc.engine_type == NAND_ECC_ENGINE_TYPE_ON_HOST) {
-#else
-               if (nand->ecc.mode == NAND_ECC_HW) {
-#endif
                        /* the data is already written */
                        break;
                }
@@ -1273,7 +1267,6 @@ static int ar934x_nfc_setup_hwecc(struct ar934x_nfc *nfc)
                 * Writing a subpage separately is not supported, because
                 * the controller only does ECC on full-page accesses.
                 */
-               nand->options = NAND_NO_SUBPAGE_WRITE;
 
                nand->ecc.size = 512;
                nand->ecc.bytes = 7;
@@ -1332,29 +1325,18 @@ static int ar934x_nfc_attach_chip(struct nand_chip *nand)
        if (ret)
                return ret;
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
        if (nand->ecc.engine_type == NAND_ECC_ENGINE_TYPE_ON_HOST) {
-#else
-       if (nand->ecc.mode == NAND_ECC_HW) {
-#endif
+               if (mtd->writesize == 2048)
+                       nand->options |= NAND_NO_SUBPAGE_WRITE;
+
                ret = ar934x_nfc_setup_hwecc(nfc);
                if (ret)
                        return ret;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
        } else if (nand->ecc.engine_type != NAND_ECC_ENGINE_TYPE_SOFT) {
                dev_err(dev, "unknown ECC mode %d\n", nand->ecc.engine_type);
-#else
-       } else if (nand->ecc.mode != NAND_ECC_SOFT) {
-               dev_err(dev, "unknown ECC mode %d\n", nand->ecc.mode);
-#endif
                return -EINVAL;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
        } else if ((nand->ecc.algo != NAND_ECC_ALGO_BCH) &&
                   (nand->ecc.algo != NAND_ECC_ALGO_HAMMING)) {
-#else
-       } else if ((nand->ecc.algo != NAND_ECC_BCH) &&
-                  (nand->ecc.algo != NAND_ECC_HAMMING)) {
-#endif
                dev_err(dev, "unknown software ECC algo %d\n", nand->ecc.algo);
                return -EINVAL;
        }
@@ -1443,11 +1425,7 @@ static int ar934x_nfc_probe(struct platform_device *pdev)
        nand->legacy.read_byte = ar934x_nfc_read_byte;
        nand->legacy.write_buf = ar934x_nfc_write_buf;
        nand->legacy.read_buf = ar934x_nfc_read_buf;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
        nand->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;   /* default */
-#else
-       nand->ecc.mode = NAND_ECC_HW;   /* default */
-#endif
        nand->priv = nfc;
        platform_set_drvdata(pdev, nfc);
 
@@ -1487,12 +1465,8 @@ static int ar934x_nfc_remove(struct platform_device *pdev)
 
        nfc = platform_get_drvdata(pdev);
        if (nfc) {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,0)
                mtd_device_unregister(nand_to_mtd(&nfc->nand_chip));
                nand_cleanup(&nfc->nand_chip);
-#else
-               nand_release(&nfc->nand_chip);
-#endif
                ar934x_nfc_free_buf(nfc);
        }