]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
mtd: rawnand: check ONFI timings have been acked by the chip
authorMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 19 Mar 2018 13:47:24 +0000 (14:47 +0100)
committerBoris Brezillon <boris.brezillon@bootlin.com>
Tue, 20 Mar 2018 08:49:41 +0000 (09:49 +0100)
Choosing ONFI timings when ->set/get_features() calls are supported
by the NAND chip is a matter of reading the chip's ONFI parameter page
and telling the chip the chosen mode (between all of the supported ones)
with ->set_feature().

Add a check on whether the chip "acked" the timing mode or not.

This can be a problem for NAND chips that do not follow entirely the
ONFI specification. These chips actually support other modes than
"mode 0", but either:
1/ do not update the timing mode register once a timing mode has been
   selected.
or
2/ do not support the TIMING_MODE featured and thus do not require users
   to change the timing mode at all.

These issues will be addressed in another patch that will add the
feature to overwrite NAND chips features within the parameter page, from
the NAND chip driver.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Tested-by: Han Xu <han.xu@nxp.com>
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
drivers/mtd/nand/raw/nand_base.c

index 9d5c2739fe6dff4bbd32a0e1d89ba570bd340c3d..837ea698af083cee6d57db0238e0c9d620d1e6b0 100644 (file)
@@ -1283,7 +1283,41 @@ static int nand_setup_data_interface(struct nand_chip *chip, int chipnr)
        }
 
        /* Change the mode on the controller side */
-       return chip->setup_data_interface(mtd, chipnr, &chip->data_interface);
+       ret = chip->setup_data_interface(mtd, chipnr, &chip->data_interface);
+       if (ret)
+               return ret;
+
+       /* Check the mode has been accepted by the chip, if supported */
+       if (!nand_supports_set_get_features(chip))
+               return 0;
+
+       memset(tmode_param, 0, ONFI_SUBFEATURE_PARAM_LEN);
+       chip->select_chip(mtd, chipnr);
+       ret = nand_get_features(chip, ONFI_FEATURE_ADDR_TIMING_MODE,
+                               tmode_param);
+       chip->select_chip(mtd, -1);
+       if (ret)
+               goto err_reset_chip;
+
+       if (tmode_param[0] != chip->onfi_timing_mode_default) {
+               pr_warn("timing mode %d not acknowledged by the NAND chip\n",
+                       chip->onfi_timing_mode_default);
+               goto err_reset_chip;
+       }
+
+       return 0;
+
+err_reset_chip:
+       /*
+        * Fallback to mode 0 if the chip explicitly did not ack the chosen
+        * timing mode.
+        */
+       nand_reset_data_interface(chip, chipnr);
+       chip->select_chip(mtd, chipnr);
+       nand_reset_op(chip);
+       chip->select_chip(mtd, -1);
+
+       return ret;
 }
 
 /**