From: Quanyang Wang <[email protected]>

This reverts commit 9f2e5a64a4621d8986af9d5ac063ce77ec7fe279.

Now the code for flash lock/unlock in linux-yocto can work with
zynqmp/zc706/zc702 boards and the SDK patches break them. let's
revert it.

Signed-off-by: Quanyang Wang <[email protected]>
---
 drivers/mtd/spi-nor/core.c  | 133 +-----------------------------------
 include/linux/mtd/spi-nor.h |   2 +-
 2 files changed, 2 insertions(+), 133 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index c9dcd9ce66da2..f134ba02e10af 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1957,7 +1957,7 @@ static int spi_nor_sr_unlock(struct spi_nor *nor, loff_t 
ofs, uint64_t len)
                val = 0; /* fully unlocked */
        } else {
                min_prot_len = spi_nor_get_min_prot_length_sr(nor);
-               pow = ilog2(mtd->size) - ilog2(min_prot_len) + 1;
+               pow = ilog2(lock_len) - ilog2(min_prot_len) + 1;
                val = pow << SR_BP_SHIFT;
 
                if (nor->flags & SNOR_F_HAS_SR_BP3_BIT6 && val & SR_BP3)
@@ -2012,121 +2012,10 @@ static const struct spi_nor_locking_ops 
spi_nor_sr_locking_ops = {
        .is_locked = spi_nor_sr_is_locked,
 };
 
-static int write_sr_modify_protection(struct spi_nor *nor, u8 status,
-                                     u8 lock_bits)
-{
-       u8 status_new, bp_mask;
-
-       status_new = status & ~SR_BP_BIT_MASK;
-       bp_mask = (lock_bits << SR_BP_BIT_OFFSET) & SR_BP_BIT_MASK;
-
-       /* Micron */
-       if (nor->jedec_id == CFI_MFR_ST) {
-               /* To support chips with more than 896 sectors (56MB) */
-               status_new &= ~SR_BP3;
-
-               /* Protected area starts from top */
-               status_new &= ~SR_BP_TB;
-
-               if (lock_bits > 7)
-                       bp_mask |= SR_BP3;
-       }
-
-       if (nor->is_lock)
-               status_new |= bp_mask;
-
-       /* For spansion flashes */
-       if (nor->jedec_id == CFI_MFR_AMD) {
-               spi_nor_read_cr(nor, &nor->bouncebuf[1]);
-               nor->bouncebuf[0] |= status_new;
-               if (spi_nor_write_sr(nor, nor->bouncebuf, 2) < 0)
-                       return 1;
-       } else {
-               nor->bouncebuf[0] = status_new;
-               if (spi_nor_write_sr(nor, &nor->bouncebuf[0], 1) < 0)
-                       return 1;
-       }
-       return 0;
-}
-
-static u8 bp_bits_from_sr(struct spi_nor *nor, u8 status)
-{
-       u8 ret;
-
-       ret = (((status) & SR_BP_BIT_MASK) >> SR_BP_BIT_OFFSET);
-       if (nor->jedec_id == 0x20)
-               ret |= ((status & SR_BP3) >> (SR_BP_BIT_OFFSET + 1));
-
-       return ret;
-}
-
-static inline u16 min_lockable_sectors(struct spi_nor *nor,
-                                      u16 n_sectors)
-{
-       u16 lock_granularity;
-
-       /*
-        * Revisit - SST (not used by us) has the same JEDEC ID as micron but
-        * protected area table is similar to that of spansion.
-        */
-       lock_granularity = max(1, n_sectors / M25P_MAX_LOCKABLE_SECTORS);
-       if (nor->jedec_id == CFI_MFR_ST)        /* Micron */
-               lock_granularity = 1;
-
-       return lock_granularity;
-}
-
-static inline uint32_t get_protected_area_start(struct spi_nor *nor,
-                                               u8 lock_bits)
-{
-       u16 n_sectors;
-       u32 sector_size;
-       u64 mtd_size;
-       struct mtd_info *mtd = &nor->mtd;
-
-       n_sectors = nor->n_sectors;
-       sector_size = nor->sector_size;
-       mtd_size = mtd->size;
-
-       if (nor->isparallel) {
-               sector_size = (nor->sector_size >> 1);
-               mtd_size = (mtd->size >> 1);
-       }
-       if (nor->isstacked) {
-               n_sectors = (nor->n_sectors >> 1);
-               mtd_size = (mtd->size >> 1);
-       }
-
-       return mtd_size - (1 << (lock_bits - 1)) *
-               min_lockable_sectors(nor, n_sectors) * sector_size;
-}
-
-static u8 min_protected_area_including_offset(struct spi_nor *nor,
-                                             uint32_t offset)
-{
-       u8 lock_bits, lockbits_limit;
-
-       /*
-        * Revisit - SST (not used by us) has the same JEDEC ID as micron but
-        * protected area table is similar to that of spansion.
-        * Mircon has 4 block protect bits.
-        */
-       lockbits_limit = 7;
-       if (nor->jedec_id == CFI_MFR_ST)        /* Micron */
-               lockbits_limit = 15;
-
-       for (lock_bits = 1; lock_bits < lockbits_limit; lock_bits++) {
-               if (offset >= get_protected_area_start(nor, lock_bits))
-                       break;
-       }
-       return lock_bits;
-}
-
 static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
        struct spi_nor *nor = mtd_to_spi_nor(mtd);
        int ret;
-       u8 lock_bits;
 
        ret = spi_nor_lock_and_prep(nor);
        if (ret)
@@ -2147,16 +2036,6 @@ static int spi_nor_lock(struct mtd_info *mtd, loff_t 
ofs, uint64_t len)
                goto err;
 
        ret = spi_nor_read_sr(nor, nor->bouncebuf);
-
-       lock_bits = min_protected_area_including_offset(nor, ofs);
-
-       /* Only modify protection if it will not unlock other areas */
-       if (lock_bits > bp_bits_from_sr(nor, nor->bouncebuf[0])) {
-               nor->is_lock = 1;
-               ret = write_sr_modify_protection(nor, nor->bouncebuf[0], 
lock_bits);
-       } else {
-               dev_err(nor->dev, "trying to unlock already locked area\n");
-       }
 err:
        spi_nor_unlock_and_unprep(nor);
        return ret;
@@ -2166,7 +2045,6 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t 
ofs, uint64_t len)
 {
        struct spi_nor *nor = mtd_to_spi_nor(mtd);
        int ret;
-       u8 lock_bits;
 
        ret = spi_nor_lock_and_prep(nor);
        if (ret)
@@ -2187,15 +2065,6 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t 
ofs, uint64_t len)
                goto err;
 
        ret = spi_nor_read_sr(nor, nor->bouncebuf);
-
-       lock_bits = min_protected_area_including_offset(nor, ofs + len) - 1;
-       /* Only modify protection if it will not lock other areas */
-       if (lock_bits < bp_bits_from_sr(nor, nor->bouncebuf[0])) {
-               nor->is_lock = 0;
-               ret = write_sr_modify_protection(nor, nor->bouncebuf[0], 
lock_bits);
-       } else {
-               dev_err(nor->dev, "trying to lock already unlocked area\n");
-       }
 err:
        spi_nor_unlock_and_unprep(nor);
        return ret;
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 5d5eee3f2d780..03f1517a232ca 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -125,7 +125,7 @@
 #define SR_BP2                 BIT(4)  /* Block protect 2 */
 #define        SR_BP_BIT_OFFSET        2       /* Offset to Block protect 0 */
 #define        SR_BP_BIT_MASK          (SR_BP2 | SR_BP1 | SR_BP0)
-#define SR_BP3                 BIT(6)  /* Block protect 3 */
+#define SR_BP3                 BIT(5)  /* Block protect 3 */
 #define SR_TB_BIT5             BIT(5)  /* Top/Bottom protect */
 #define SR_BP3_BIT6            BIT(6)  /* Block protect 3 */
 #define SR_TB_BIT6             BIT(6)  /* Top/Bottom protect */
-- 
2.25.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#10546): 
https://lists.yoctoproject.org/g/linux-yocto/message/10546
Mute This Topic: https://lists.yoctoproject.org/mt/86435181/21656
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to