* [PATCH V4, 1/2] mtd: nand: brcmnand: Change brcmnand_set_wp() prototype
@ 2017-02-28 16:55 Kamal Dasu
2017-02-28 16:55 ` [PATCH V4, 2/2] mtd: nand: brcmnand: Check flash #WP pin status before nand erase/program Kamal Dasu
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Kamal Dasu @ 2017-02-28 16:55 UTC (permalink / raw)
To: linux-mtd
Cc: f.fainelli, bcm-kernel-feedback-list, dwmw2, computersforpeace,
boris.brezillon, marek.vasut, richard, cyrille.pitchen,
Kamal Dasu
Changing brcmnand_set_wp() prototype in prepration for refactoring the nand
write protect logic to add flash status byte check for the protection bit.
Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
---
drivers/mtd/nand/brcmnand/brcmnand.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c
index 42ebd73..c7c4efe 100644
--- a/drivers/mtd/nand/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/brcmnand/brcmnand.c
@@ -765,11 +765,14 @@ enum {
CS_SELECT_AUTO_DEVICE_ID_CFG = BIT(30),
};
-static inline void brcmnand_set_wp(struct brcmnand_controller *ctrl, bool en)
+static int brcmnand_set_wp(struct brcmnand_host *host, int en)
{
+ struct brcmnand_controller *ctrl = host->ctrl;
u32 val = en ? CS_SELECT_NAND_WP : 0;
brcmnand_rmw_reg(ctrl, BRCMNAND_CS_SELECT, CS_SELECT_NAND_WP, 0, val);
+
+ return 0;
}
/***********************************************************************
@@ -1029,7 +1032,7 @@ static void brcmnand_wp(struct mtd_info *mtd, int wp)
dev_dbg(ctrl->dev, "WP %s\n", wp ? "on" : "off");
old_wp = wp;
}
- brcmnand_set_wp(ctrl, wp);
+ brcmnand_set_wp(host, wp);
}
}
@@ -2462,14 +2465,6 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
/* Disable XOR addressing */
brcmnand_rmw_reg(ctrl, BRCMNAND_CS_XOR, 0xff, 0, 0);
- if (ctrl->features & BRCMNAND_HAS_WP) {
- /* Permanently disable write protection */
- if (wp_on == 2)
- brcmnand_set_wp(ctrl, false);
- } else {
- wp_on = 0;
- }
-
/* IRQ */
ctrl->irq = platform_get_irq(pdev, 0);
if ((int)ctrl->irq < 0) {
@@ -2522,6 +2517,18 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
}
list_add_tail(&host->node, &ctrl->host_list);
+
+ if (ctrl->features & BRCMNAND_HAS_WP) {
+ /* Permanently disable write protection */
+ if (wp_on == 2) {
+ ret = brcmnand_set_wp(host, false);
+ if (ret)
+ goto err;
+ }
+ } else {
+ wp_on = 0;
+ }
+
}
}
--
1.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH V4, 2/2] mtd: nand: brcmnand: Check flash #WP pin status before nand erase/program
2017-02-28 16:55 [PATCH V4, 1/2] mtd: nand: brcmnand: Change brcmnand_set_wp() prototype Kamal Dasu
@ 2017-02-28 16:55 ` Kamal Dasu
2017-02-28 18:25 ` [PATCH V4, 1/2] mtd: nand: brcmnand: Change brcmnand_set_wp() prototype Marek Vasut
2017-02-28 22:05 ` Boris Brezillon
2 siblings, 0 replies; 6+ messages in thread
From: Kamal Dasu @ 2017-02-28 16:55 UTC (permalink / raw)
To: linux-mtd
Cc: f.fainelli, bcm-kernel-feedback-list, dwmw2, computersforpeace,
boris.brezillon, marek.vasut, richard, cyrille.pitchen,
Kamal Dasu
brcmnand controller v6.x and v7.x lets driver to enable disable #WP pin
via NAND_WP bit in CS_SELECT register. Driver implementation assumes that
setting/resetting the bit would assert/de-assert #WP pin instantaneously
from the flash part's perspective, and was proceeding to erase/program
without verifying flash status byte for protection bit. In rigorous
testing this was causing rare data corruptions with erase and/or
subsequent programming. To fix this check NAND status in addition to
controller #WP pin status to make sure both sides are ready to accept
new commands.
Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
---
drivers/mtd/nand/brcmnand/brcmnand.c | 70 +++++++++++++++++++++++++++++++++---
1 file changed, 65 insertions(+), 5 deletions(-)
diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c
index c7c4efe..af32685 100644
--- a/drivers/mtd/nand/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/brcmnand/brcmnand.c
@@ -101,6 +101,9 @@ struct brcm_nand_dma_desc {
#define BRCMNAND_MIN_BLOCKSIZE (8 * 1024)
#define BRCMNAND_MIN_DEVSIZE (4ULL * 1024 * 1024)
+#define NAND_CTRL_RDY (INTFC_CTLR_READY | INTFC_FLASH_READY)
+#define NAND_POLL_STATUS_TIMEOUT_MS 100
+
/* Controller feature flags */
enum {
BRCMNAND_HAS_1K_SECTORS = BIT(0),
@@ -765,12 +768,69 @@ enum {
CS_SELECT_AUTO_DEVICE_ID_CFG = BIT(30),
};
-static int brcmnand_set_wp(struct brcmnand_host *host, int en)
+static int bcmnand_ctrl_poll_status(struct brcmnand_controller *ctrl,
+ u32 mask, u32 expected_val,
+ unsigned long timeout_ms)
+{
+ unsigned long limit;
+ u32 val;
+
+ if (!timeout_ms)
+ timeout_ms = NAND_POLL_STATUS_TIMEOUT_MS;
+
+ limit = jiffies + msecs_to_jiffies(timeout_ms);
+ do {
+ val = brcmnand_read_reg(ctrl, BRCMNAND_INTFC_STATUS);
+ if ((val & mask) == expected_val)
+ return 0;
+
+ cpu_relax();
+ } while (time_after(limit, jiffies));
+
+ dev_warn(ctrl->dev, "timeout on status poll (expected %x got %x)\n",
+ expected_val, val & mask);
+
+ return -ETIMEDOUT;
+}
+
+static inline void brcmnand_set_wp_reg(struct brcmnand_controller *ctrl, int en)
{
- struct brcmnand_controller *ctrl = host->ctrl;
u32 val = en ? CS_SELECT_NAND_WP : 0;
brcmnand_rmw_reg(ctrl, BRCMNAND_CS_SELECT, CS_SELECT_NAND_WP, 0, val);
+}
+
+static int brcmnand_set_wp(struct brcmnand_host *host, int en)
+{
+ struct brcmnand_controller *ctrl = host->ctrl;
+ struct mtd_info *mtd = nand_to_mtd(&host->chip);
+ struct nand_chip *chip = mtd_to_nand(mtd);
+ int ret;
+
+ /*
+ * make sure ctrl/flash ready before and after
+ * changing state of WP PIN
+ */
+ ret = bcmnand_ctrl_poll_status(ctrl, NAND_CTRL_RDY | NAND_STATUS_READY,
+ NAND_CTRL_RDY | NAND_STATUS_READY, 0);
+ if (ret)
+ return ret;
+
+ brcmnand_set_wp_reg(ctrl, en);
+ chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1);
+ /* NAND_STATUS_WP 0x00 = protected, 0x80 = not protected */
+ ret = bcmnand_ctrl_poll_status(ctrl,
+ NAND_CTRL_RDY | NAND_STATUS_READY |
+ NAND_STATUS_WP,
+ NAND_CTRL_RDY | NAND_STATUS_READY |
+ (en ? 0 : NAND_STATUS_WP), 0);
+
+ if (ret) {
+ dev_err_ratelimited(&host->pdev->dev,
+ "nand #WP expected %s\n",
+ en ? "On" : "Off");
+ return ret;
+ }
return 0;
}
@@ -1160,15 +1220,15 @@ static irqreturn_t brcmnand_dma_irq(int irq, void *data)
static void brcmnand_send_cmd(struct brcmnand_host *host, int cmd)
{
struct brcmnand_controller *ctrl = host->ctrl;
- u32 intfc;
+ int ret;
dev_dbg(ctrl->dev, "send native cmd %d addr_lo 0x%x\n", cmd,
brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS));
BUG_ON(ctrl->cmd_pending != 0);
ctrl->cmd_pending = cmd;
- intfc = brcmnand_read_reg(ctrl, BRCMNAND_INTFC_STATUS);
- WARN_ON(!(intfc & INTFC_CTLR_READY));
+ ret = bcmnand_ctrl_poll_status(ctrl, NAND_CTRL_RDY, NAND_CTRL_RDY, 0);
+ WARN_ON(ret);
mb(); /* flush previous writes */
brcmnand_write_reg(ctrl, BRCMNAND_CMD_START,
--
1.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH V4, 1/2] mtd: nand: brcmnand: Change brcmnand_set_wp() prototype
2017-02-28 16:55 [PATCH V4, 1/2] mtd: nand: brcmnand: Change brcmnand_set_wp() prototype Kamal Dasu
2017-02-28 16:55 ` [PATCH V4, 2/2] mtd: nand: brcmnand: Check flash #WP pin status before nand erase/program Kamal Dasu
@ 2017-02-28 18:25 ` Marek Vasut
2017-02-28 19:28 ` Kamal Dasu
2017-02-28 22:05 ` Boris Brezillon
2 siblings, 1 reply; 6+ messages in thread
From: Marek Vasut @ 2017-02-28 18:25 UTC (permalink / raw)
To: Kamal Dasu, linux-mtd
Cc: f.fainelli, bcm-kernel-feedback-list, dwmw2, computersforpeace,
boris.brezillon, richard, cyrille.pitchen
On 02/28/2017 05:55 PM, Kamal Dasu wrote:
> Changing brcmnand_set_wp() prototype in prepration for refactoring the nand
> write protect logic to add flash status byte check for the protection bit.
>
> Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
> ---
> drivers/mtd/nand/brcmnand/brcmnand.c | 27 +++++++++++++++++----------
> 1 file changed, 17 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c
> index 42ebd73..c7c4efe 100644
> --- a/drivers/mtd/nand/brcmnand/brcmnand.c
> +++ b/drivers/mtd/nand/brcmnand/brcmnand.c
> @@ -765,11 +765,14 @@ enum {
> CS_SELECT_AUTO_DEVICE_ID_CFG = BIT(30),
> };
>
> -static inline void brcmnand_set_wp(struct brcmnand_controller *ctrl, bool en)
> +static int brcmnand_set_wp(struct brcmnand_host *host, int en)
> {
> + struct brcmnand_controller *ctrl = host->ctrl;
> u32 val = en ? CS_SELECT_NAND_WP : 0;
>
> brcmnand_rmw_reg(ctrl, BRCMNAND_CS_SELECT, CS_SELECT_NAND_WP, 0, val);
> +
> + return 0;
> }
>
> /***********************************************************************
> @@ -1029,7 +1032,7 @@ static void brcmnand_wp(struct mtd_info *mtd, int wp)
> dev_dbg(ctrl->dev, "WP %s\n", wp ? "on" : "off");
> old_wp = wp;
> }
> - brcmnand_set_wp(ctrl, wp);
> + brcmnand_set_wp(host, wp);
> }
> }
>
> @@ -2462,14 +2465,6 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
> /* Disable XOR addressing */
> brcmnand_rmw_reg(ctrl, BRCMNAND_CS_XOR, 0xff, 0, 0);
>
> - if (ctrl->features & BRCMNAND_HAS_WP) {
> - /* Permanently disable write protection */
> - if (wp_on == 2)
> - brcmnand_set_wp(ctrl, false);
> - } else {
> - wp_on = 0;
> - }
> -
> /* IRQ */
> ctrl->irq = platform_get_irq(pdev, 0);
> if ((int)ctrl->irq < 0) {
> @@ -2522,6 +2517,18 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
> }
>
> list_add_tail(&host->node, &ctrl->host_list);
> +
> + if (ctrl->features & BRCMNAND_HAS_WP) {
> + /* Permanently disable write protection */
> + if (wp_on == 2) {
> + ret = brcmnand_set_wp(host, false);
> + if (ret)
> + goto err;
> + }
> + } else {
> + wp_on = 0;
> + }
> +
Would it be worth it to move this into separate function ? Or maybe make
brcmnand_set_wp() check for BRCMNAND_HAS_WP and only set the WP
if the controller is actually capable of that ? I think that might make
the code readability a bit better ...
> }
> }
>
>
--
Best regards,
Marek Vasut
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH V4, 1/2] mtd: nand: brcmnand: Change brcmnand_set_wp() prototype
2017-02-28 18:25 ` [PATCH V4, 1/2] mtd: nand: brcmnand: Change brcmnand_set_wp() prototype Marek Vasut
@ 2017-02-28 19:28 ` Kamal Dasu
0 siblings, 0 replies; 6+ messages in thread
From: Kamal Dasu @ 2017-02-28 19:28 UTC (permalink / raw)
To: Marek Vasut
Cc: Kamal Dasu, MTD Maling List, Florian Fainelli,
bcm-kernel-feedback-list, David Woodhouse, Brian Norris,
Boris Brezillon, Richard Weinberger, Cyrille Pitchen
Marek,
On Tue, Feb 28, 2017 at 1:25 PM, Marek Vasut <marek.vasut@gmail.com> wrote:
> On 02/28/2017 05:55 PM, Kamal Dasu wrote:
>> Changing brcmnand_set_wp() prototype in prepration for refactoring the nand
>> write protect logic to add flash status byte check for the protection bit.
>>
>> Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
>> ---
>> drivers/mtd/nand/brcmnand/brcmnand.c | 27 +++++++++++++++++----------
>> 1 file changed, 17 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c
>> index 42ebd73..c7c4efe 100644
>> --- a/drivers/mtd/nand/brcmnand/brcmnand.c
>> +++ b/drivers/mtd/nand/brcmnand/brcmnand.c
>> @@ -765,11 +765,14 @@ enum {
>> CS_SELECT_AUTO_DEVICE_ID_CFG = BIT(30),
>> };
>>
>> -static inline void brcmnand_set_wp(struct brcmnand_controller *ctrl, bool en)
>> +static int brcmnand_set_wp(struct brcmnand_host *host, int en)
>> {
>> + struct brcmnand_controller *ctrl = host->ctrl;
>> u32 val = en ? CS_SELECT_NAND_WP : 0;
>>
>> brcmnand_rmw_reg(ctrl, BRCMNAND_CS_SELECT, CS_SELECT_NAND_WP, 0, val);
>> +
>> + return 0;
>> }
>>
>> /***********************************************************************
>> @@ -1029,7 +1032,7 @@ static void brcmnand_wp(struct mtd_info *mtd, int wp)
>> dev_dbg(ctrl->dev, "WP %s\n", wp ? "on" : "off");
>> old_wp = wp;
>> }
>> - brcmnand_set_wp(ctrl, wp);
>> + brcmnand_set_wp(host, wp);
>> }
>> }
>>
>> @@ -2462,14 +2465,6 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
>> /* Disable XOR addressing */
>> brcmnand_rmw_reg(ctrl, BRCMNAND_CS_XOR, 0xff, 0, 0);
>>
>> - if (ctrl->features & BRCMNAND_HAS_WP) {
>> - /* Permanently disable write protection */
>> - if (wp_on == 2)
>> - brcmnand_set_wp(ctrl, false);
>> - } else {
>> - wp_on = 0;
>> - }
>> -
>> /* IRQ */
>> ctrl->irq = platform_get_irq(pdev, 0);
>> if ((int)ctrl->irq < 0) {
>> @@ -2522,6 +2517,18 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
>> }
>>
>> list_add_tail(&host->node, &ctrl->host_list);
>> +
>> + if (ctrl->features & BRCMNAND_HAS_WP) {
>> + /* Permanently disable write protection */
>> + if (wp_on == 2) {
>> + ret = brcmnand_set_wp(host, false);
>> + if (ret)
>> + goto err;
>> + }
>> + } else {
>> + wp_on = 0;
>> + }
>> +
>
> Would it be worth it to move this into separate function ? Or maybe make
> brcmnand_set_wp() check for BRCMNAND_HAS_WP and only set the WP
> if the controller is actually capable of that ? I think that might make
> the code readability a bit better ...
>
>> }
>> }
>>
>>
The above code is called during the probe and only when the bootline
wants to permanently set the wp off( wp == 2) hence structured that
way. I would prefer to leave it that way.
In all other cases there is already brcmand_wp(mtd_info *mtd, int wp)
checks and maintains the wp state.
>
> --
> Best regards,
> Marek Vasut
Thanks
Kamal
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH V4, 1/2] mtd: nand: brcmnand: Change brcmnand_set_wp() prototype
2017-02-28 16:55 [PATCH V4, 1/2] mtd: nand: brcmnand: Change brcmnand_set_wp() prototype Kamal Dasu
2017-02-28 16:55 ` [PATCH V4, 2/2] mtd: nand: brcmnand: Check flash #WP pin status before nand erase/program Kamal Dasu
2017-02-28 18:25 ` [PATCH V4, 1/2] mtd: nand: brcmnand: Change brcmnand_set_wp() prototype Marek Vasut
@ 2017-02-28 22:05 ` Boris Brezillon
2017-02-28 22:20 ` Kamal Dasu
2 siblings, 1 reply; 6+ messages in thread
From: Boris Brezillon @ 2017-02-28 22:05 UTC (permalink / raw)
To: Kamal Dasu
Cc: linux-mtd, f.fainelli, bcm-kernel-feedback-list, dwmw2,
computersforpeace, marek.vasut, richard, cyrille.pitchen
On Tue, 28 Feb 2017 11:55:25 -0500
Kamal Dasu <kdasu.kdev@gmail.com> wrote:
> Changing brcmnand_set_wp() prototype in prepration for refactoring the nand
> write protect logic to add flash status byte check for the protection bit.
>
> Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
> ---
> drivers/mtd/nand/brcmnand/brcmnand.c | 27 +++++++++++++++++----------
> 1 file changed, 17 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c
> index 42ebd73..c7c4efe 100644
> --- a/drivers/mtd/nand/brcmnand/brcmnand.c
> +++ b/drivers/mtd/nand/brcmnand/brcmnand.c
> @@ -765,11 +765,14 @@ enum {
> CS_SELECT_AUTO_DEVICE_ID_CFG = BIT(30),
> };
>
> -static inline void brcmnand_set_wp(struct brcmnand_controller *ctrl, bool en)
> +static int brcmnand_set_wp(struct brcmnand_host *host, int en)
> {
> + struct brcmnand_controller *ctrl = host->ctrl;
> u32 val = en ? CS_SELECT_NAND_WP : 0;
>
> brcmnand_rmw_reg(ctrl, BRCMNAND_CS_SELECT, CS_SELECT_NAND_WP, 0, val);
> +
> + return 0;
> }
>
> /***********************************************************************
> @@ -1029,7 +1032,7 @@ static void brcmnand_wp(struct mtd_info *mtd, int wp)
> dev_dbg(ctrl->dev, "WP %s\n", wp ? "on" : "off");
> old_wp = wp;
> }
> - brcmnand_set_wp(ctrl, wp);
> + brcmnand_set_wp(host, wp);
> }
> }
>
> @@ -2462,14 +2465,6 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
> /* Disable XOR addressing */
> brcmnand_rmw_reg(ctrl, BRCMNAND_CS_XOR, 0xff, 0, 0);
>
> - if (ctrl->features & BRCMNAND_HAS_WP) {
> - /* Permanently disable write protection */
> - if (wp_on == 2)
> - brcmnand_set_wp(ctrl, false);
> - } else {
> - wp_on = 0;
> - }
> -
if (!(ctrl->features & BRCMNAND_HAS_WP))
wp_on = 0;
> /* IRQ */
> ctrl->irq = platform_get_irq(pdev, 0);
> if ((int)ctrl->irq < 0) {
> @@ -2522,6 +2517,18 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
> }
>
> list_add_tail(&host->node, &ctrl->host_list);
> +
> + if (ctrl->features & BRCMNAND_HAS_WP) {
> + /* Permanently disable write protection */
> + if (wp_on == 2) {
> + ret = brcmnand_set_wp(host, false);
> + if (ret)
> + goto err;
> + }
> + } else {
> + wp_on = 0;
> + }
> +
/* Permanently disable write protection */
if (wp_on == 2) {
ret = brcmnand_set_wp(host, false);
if (ret)
goto err;
}
> }
> }
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH V4, 1/2] mtd: nand: brcmnand: Change brcmnand_set_wp() prototype
2017-02-28 22:05 ` Boris Brezillon
@ 2017-02-28 22:20 ` Kamal Dasu
0 siblings, 0 replies; 6+ messages in thread
From: Kamal Dasu @ 2017-02-28 22:20 UTC (permalink / raw)
To: Boris Brezillon
Cc: MTD Maling List, Florian Fainelli, bcm-kernel-feedback-list,
David Woodhouse, Brian Norris, Marek Vasut, richard,
Cyrille Pitchen
Boris,
On Tue, Feb 28, 2017 at 5:05 PM, Boris Brezillon
<boris.brezillon@free-electrons.com> wrote:
> On Tue, 28 Feb 2017 11:55:25 -0500
> Kamal Dasu <kdasu.kdev@gmail.com> wrote:
>
>> Changing brcmnand_set_wp() prototype in prepration for refactoring the nand
>> write protect logic to add flash status byte check for the protection bit.
>>
>> Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
>> ---
>> drivers/mtd/nand/brcmnand/brcmnand.c | 27 +++++++++++++++++----------
>> 1 file changed, 17 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c
>> index 42ebd73..c7c4efe 100644
>> --- a/drivers/mtd/nand/brcmnand/brcmnand.c
>> +++ b/drivers/mtd/nand/brcmnand/brcmnand.c
>> @@ -765,11 +765,14 @@ enum {
>> CS_SELECT_AUTO_DEVICE_ID_CFG = BIT(30),
>> };
>>
>> -static inline void brcmnand_set_wp(struct brcmnand_controller *ctrl, bool en)
>> +static int brcmnand_set_wp(struct brcmnand_host *host, int en)
>> {
>> + struct brcmnand_controller *ctrl = host->ctrl;
>> u32 val = en ? CS_SELECT_NAND_WP : 0;
>>
>> brcmnand_rmw_reg(ctrl, BRCMNAND_CS_SELECT, CS_SELECT_NAND_WP, 0, val);
>> +
>> + return 0;
>> }
>>
>> /***********************************************************************
>> @@ -1029,7 +1032,7 @@ static void brcmnand_wp(struct mtd_info *mtd, int wp)
>> dev_dbg(ctrl->dev, "WP %s\n", wp ? "on" : "off");
>> old_wp = wp;
>> }
>> - brcmnand_set_wp(ctrl, wp);
>> + brcmnand_set_wp(host, wp);
>> }
>> }
>>
>> @@ -2462,14 +2465,6 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
>> /* Disable XOR addressing */
>> brcmnand_rmw_reg(ctrl, BRCMNAND_CS_XOR, 0xff, 0, 0);
>>
>> - if (ctrl->features & BRCMNAND_HAS_WP) {
>> - /* Permanently disable write protection */
>> - if (wp_on == 2)
>> - brcmnand_set_wp(ctrl, false);
>> - } else {
>> - wp_on = 0;
>> - }
>> -
>
> if (!(ctrl->features & BRCMNAND_HAS_WP))
> wp_on = 0;
>
>> /* IRQ */
>> ctrl->irq = platform_get_irq(pdev, 0);
>> if ((int)ctrl->irq < 0) {
>> @@ -2522,6 +2517,18 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
>> }
>>
>> list_add_tail(&host->node, &ctrl->host_list);
>> +
>> + if (ctrl->features & BRCMNAND_HAS_WP) {
>> + /* Permanently disable write protection */
>> + if (wp_on == 2) {
>> + ret = brcmnand_set_wp(host, false);
>> + if (ret)
>> + goto err;
>> + }
>> + } else {
>> + wp_on = 0;
>> + }
>> +
>
> /* Permanently disable write protection */
> if (wp_on == 2) {
> ret = brcmnand_set_wp(host, false);
> if (ret)
> goto err;
> }
>
>
>> }
>> }
>>
>
Let me rework this and send a new patch. Actually I just need to set
the controller wp bit and the wp value since I do not need to worry
about the status since we are not going to try and change the #WP at
all in this case when we send the erase/program command.
brcmnand_set_wp_reg() calling this should be sufficient during probe.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-02-28 22:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-28 16:55 [PATCH V4, 1/2] mtd: nand: brcmnand: Change brcmnand_set_wp() prototype Kamal Dasu
2017-02-28 16:55 ` [PATCH V4, 2/2] mtd: nand: brcmnand: Check flash #WP pin status before nand erase/program Kamal Dasu
2017-02-28 18:25 ` [PATCH V4, 1/2] mtd: nand: brcmnand: Change brcmnand_set_wp() prototype Marek Vasut
2017-02-28 19:28 ` Kamal Dasu
2017-02-28 22:05 ` Boris Brezillon
2017-02-28 22:20 ` Kamal Dasu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.