7bcfd515da9d86be617c9579a91d9bb785c33b3a
[openwrt/openwrt.git] / target / linux / layerscape / patches-4.4 / 1086-mtd-spi-nor-wait-until-lock-unlock-operations-are-re.patch
1 From 3a06c61b48fbc23046928275e37a693e1055ae74 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Ezequiel=20Garc=C3=ADa?= <ezequiel@vanguardiasur.com.ar>
3 Date: Mon, 28 Dec 2015 17:54:51 -0300
4 Subject: [PATCH 086/113] mtd: spi-nor: wait until lock/unlock operations are
5 ready
6
7 On Micron and Numonyx devices, the status register write command
8 (WRSR), raises a work-in-progress bit (WIP) on the status register.
9 The datasheets for these devices specify that while the status
10 register write is in progress, the status register WIP bit can still
11 be read to check the end of the operation.
12
13 This commit adds a wait_till_ready call on lock/unlock operations,
14 which is required for Micron and Numonyx but should be harmless for
15 others. This is needed to prevent applications from issuing erase or
16 program operations before the unlock operation is completed.
17
18 Reported-by: Stas Sergeev <stsp@list.ru>
19 Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
20 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
21 ---
22 drivers/mtd/spi-nor/spi-nor.c | 12 ++++++++++--
23 1 file changed, 10 insertions(+), 2 deletions(-)
24
25 --- a/drivers/mtd/spi-nor/spi-nor.c
26 +++ b/drivers/mtd/spi-nor/spi-nor.c
27 @@ -481,6 +481,7 @@ static int stm_lock(struct spi_nor *nor,
28 int status_old, status_new;
29 u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
30 u8 shift = ffs(mask) - 1, pow, val;
31 + int ret;
32
33 status_old = read_sr(nor);
34 if (status_old < 0)
35 @@ -519,7 +520,10 @@ static int stm_lock(struct spi_nor *nor,
36 return -EINVAL;
37
38 write_enable(nor);
39 - return write_sr(nor, status_new);
40 + ret = write_sr(nor, status_new);
41 + if (ret)
42 + return ret;
43 + return spi_nor_wait_till_ready(nor);
44 }
45
46 /*
47 @@ -533,6 +537,7 @@ static int stm_unlock(struct spi_nor *no
48 int status_old, status_new;
49 u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
50 u8 shift = ffs(mask) - 1, pow, val;
51 + int ret;
52
53 status_old = read_sr(nor);
54 if (status_old < 0)
55 @@ -569,7 +574,10 @@ static int stm_unlock(struct spi_nor *no
56 return -EINVAL;
57
58 write_enable(nor);
59 - return write_sr(nor, status_new);
60 + ret = write_sr(nor, status_new);
61 + if (ret)
62 + return ret;
63 + return spi_nor_wait_till_ready(nor);
64 }
65
66 /*