mtd: rawnand: ams-delta: Write protect device during probe
authorJanusz Krzysztofik <jmkrzyszt@gmail.com>
Wed, 12 Feb 2020 00:39:16 +0000 (01:39 +0100)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 9 Mar 2020 13:51:01 +0000 (14:51 +0100)
Initialise NWP GPIO pin as asserted to protect the device from hazard
during setup of other GPIO pins.

Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20200212003929.6682-2-jmkrzyszt@gmail.com
drivers/mtd/nand/raw/ams-delta.c

index 8312182088c1dee9cc4117e08a4e5219308349a6..2501cfe00f43902ced6f4a7e354bf882ca2491ab 100644 (file)
@@ -251,8 +251,8 @@ static int ams_delta_init(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, priv);
 
-       /* Set chip enabled, but  */
-       priv->gpiod_nwp = devm_gpiod_get(&pdev->dev, "nwp", GPIOD_OUT_HIGH);
+       /* Set chip enabled but write protected */
+       priv->gpiod_nwp = devm_gpiod_get(&pdev->dev, "nwp", GPIOD_OUT_LOW);
        if (IS_ERR(priv->gpiod_nwp)) {
                err = PTR_ERR(priv->gpiod_nwp);
                dev_err(&pdev->dev, "NWP GPIO request failed (%d)\n", err);
@@ -309,6 +309,17 @@ static int ams_delta_init(struct platform_device *pdev)
        nand_controller_init(&priv->base);
        this->controller = &priv->base;
 
+       /*
+        * FIXME: We should release write protection only after nand_scan() to
+        * be on the safe side but we can't do that until we have a generic way
+        * to assert/deassert WP from the core.  Even if the core shouldn't
+        * write things in the nand_scan() path, it should have control on this
+        * pin just in case we ever need to disable write protection during
+        * chip detection/initialization.
+        */
+       /* Release write protection */
+       gpiod_set_value(priv->gpiod_nwp, 1);
+
        /* Scan to find existence of the device */
        err = nand_scan(this, 1);
        if (err)
@@ -336,6 +347,9 @@ static int ams_delta_cleanup(struct platform_device *pdev)
        struct ams_delta_nand *priv = platform_get_drvdata(pdev);
        struct mtd_info *mtd = nand_to_mtd(&priv->nand_chip);
 
+       /* Apply write protection */
+       gpiod_set_value(priv->gpiod_nwp, 0);
+
        /* Unregister device */
        nand_release(mtd_to_nand(mtd));