]> Git Repo - J-u-boot.git/blobdiff - drivers/mtd/nand/raw/nand_base.c
WS cleanup: remove SPACE(s) followed by TAB
[J-u-boot.git] / drivers / mtd / nand / raw / nand_base.c
index e07bd6b657eeba96f2afe9338500a5290c7b4b0a..b533683dfe6562c69fc6784ade5740060b482b7c 100644 (file)
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 #include <common.h>
-#if CONFIG_IS_ENABLED(OF_CONTROL)
-#include <fdtdec.h>
-#endif
+#include <log.h>
 #include <malloc.h>
 #include <watchdog.h>
+#include <dm/devres.h>
+#include <linux/bitops.h>
+#include <linux/bug.h>
+#include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/compat.h>
 #include <linux/mtd/mtd.h>
@@ -47,7 +49,7 @@
 #include <linux/errno.h>
 
 /* Define default oob placement schemes for large and small page devices */
-#ifdef CONFIG_SYS_NAND_DRIVER_ECC_LAYOUT
+#ifndef CONFIG_SYS_NAND_DRIVER_ECC_LAYOUT
 static struct nand_ecclayout nand_oob_8 = {
        .eccbytes = 3,
        .eccpos = {0, 1, 2},
@@ -261,7 +263,7 @@ static void ioread8_rep(void *addr, uint8_t *buf, int len)
 static void ioread16_rep(void *addr, void *buf, int len)
 {
        int i;
-       u16 *p = (u16 *) buf;
+       u16 *p = (u16 *) buf;
 
        for (i = 0; i < len; i++)
                p[i] = readw(addr);
@@ -903,11 +905,11 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
        if (ret)
                return ret;
 
-       u32 timer = (CONFIG_SYS_HZ * timeo) / 1000;
-       u32 time_start;
-       time_start = get_timer(0);
-       while (get_timer(time_start) < timer) {
+       u32 timer = (CONFIG_SYS_HZ * timeo) / 1000;
+       u32 time_start;
+
+       time_start = get_timer(0);
+       while (get_timer(time_start) < timer) {
                if (chip->dev_ready) {
                        if (chip->dev_ready(mtd))
                                break;
@@ -3554,6 +3556,8 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
                        pr_warn("%s: attempt to erase a bad block at page 0x%08x\n",
                                    __func__, page);
                        instr->state = MTD_ERASE_FAILED;
+                       instr->fail_addr =
+                               ((loff_t)page << chip->page_shift);
                        goto erase_exit;
                }
 
@@ -4569,22 +4573,20 @@ ident_done:
 EXPORT_SYMBOL(nand_get_flash_type);
 
 #if CONFIG_IS_ENABLED(OF_CONTROL)
-DECLARE_GLOBAL_DATA_PTR;
 
-static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, int node)
+static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode node)
 {
        int ret, ecc_mode = -1, ecc_strength, ecc_step;
-       const void *blob = gd->fdt_blob;
        const char *str;
 
-       ret = fdtdec_get_int(blob, node, "nand-bus-width", -1);
+       ret = ofnode_read_s32_default(node, "nand-bus-width", -1);
        if (ret == 16)
                chip->options |= NAND_BUSWIDTH_16;
 
-       if (fdtdec_get_bool(blob, node, "nand-on-flash-bbt"))
+       if (ofnode_read_bool(node, "nand-on-flash-bbt"))
                chip->bbt_options |= NAND_BBT_USE_FLASH;
 
-       str = fdt_getprop(blob, node, "nand-ecc-mode", NULL);
+       str = ofnode_read_string(node, "nand-ecc-mode");
        if (str) {
                if (!strcmp(str, "none"))
                        ecc_mode = NAND_ECC_NONE;
@@ -4600,9 +4602,10 @@ static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, int node)
                        ecc_mode = NAND_ECC_SOFT_BCH;
        }
 
-
-       ecc_strength = fdtdec_get_int(blob, node, "nand-ecc-strength", -1);
-       ecc_step = fdtdec_get_int(blob, node, "nand-ecc-step-size", -1);
+       ecc_strength = ofnode_read_s32_default(node,
+                                              "nand-ecc-strength", -1);
+       ecc_step = ofnode_read_s32_default(node,
+                                          "nand-ecc-step-size", -1);
 
        if ((ecc_step >= 0 && !(ecc_strength >= 0)) ||
            (!(ecc_step >= 0) && ecc_strength >= 0)) {
@@ -4619,13 +4622,13 @@ static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, int node)
        if (ecc_step > 0)
                chip->ecc.size = ecc_step;
 
-       if (fdt_getprop(blob, node, "nand-ecc-maximize", NULL))
+       if (ofnode_read_bool(node, "nand-ecc-maximize"))
                chip->ecc.options |= NAND_ECC_MAXIMIZE;
 
        return 0;
 }
 #else
-static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, int node)
+static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode node)
 {
        return 0;
 }
@@ -4649,7 +4652,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
        struct nand_flash_dev *type;
        int ret;
 
-       if (chip->flash_node) {
+       if (ofnode_valid(chip->flash_node)) {
                ret = nand_dt_init(mtd, chip, chip->flash_node);
                if (ret)
                        return ret;
@@ -5034,7 +5037,7 @@ int nand_scan_tail(struct mtd_info *mtd)
         */
        if (!ecc->layout && (ecc->mode != NAND_ECC_SOFT_BCH)) {
                switch (mtd->oobsize) {
-#ifdef CONFIG_SYS_NAND_DRIVER_ECC_LAYOUT
+#ifndef CONFIG_SYS_NAND_DRIVER_ECC_LAYOUT
                case 8:
                        ecc->layout = &nand_oob_8;
                        break;
This page took 0.031022 seconds and 4 git commands to generate.