Skip to contentSkip to conversation

Optimize the Spreadtrum eFuse controller

PATCH Applied Baolin Wang 2 participants 5 messages Mar 13, 2020 – Mar 18, 2020

Subsystems (2)
lore
Share & tools
lore

Baolin Wang

author maintainer
#0 lore raw

cover Optimize the Spreadtrum eFuse controller

This patch set optimizes the block lock operation and set the double data flag from device data.

Baolin Wang (1):
nvmem: sprd: Determine double data programming from device data

Freeman Liu (2):
nvmem: sprd: Fix the block lock operation
nvmem: sprd: Optimize the block lock operation

 drivers/nvmem/sprd-efuse.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)
Signature · 1 line
1.9.1
author maintainer
#1 lore raw

PATCH 1/3 nvmem: sprd: Fix the block lock operation

From: Freeman Liu <[email protected]>

According to the Spreadtrum eFuse specification, we should write 0 to the block to trigger the lock operation.

Fixes 096030e7f449 ("nvmem: sprd: Add Spreadtrum SoCs eFuse support")
---
 drivers/nvmem/sprd-efuse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvmem/sprd-efuse.c +1 -1
index 2f1e0fb..7a189ef 100644
@@ -239,7 +239,7 @@ static int sprd_efuse_raw_prog(struct sprd_efuse *efuse, u32 blk, bool doub,
 		ret = -EBUSY;
 	} else {
 		sprd_efuse_set_prog_lock(efuse, lock);
-		writel(*data, efuse->base + SPRD_EFUSE_MEM(blk));
+		writel(0, efuse->base + SPRD_EFUSE_MEM(blk));
 		sprd_efuse_set_prog_lock(efuse, false);
 	}
 
Signature · 1 line
1.9.1
author maintainer
#3 lore raw

PATCH 2/3 nvmem: sprd: Optimize the block lock operation

In reply to Baolin Wang

From: Freeman Liu <[email protected]>

We have some cases that will programme the eFuse block partially multiple times, so we should allow the block to be programmed again if it was programmed partially. But we should lock the block if the whole block was programmed. Thus add a condition to validate if we need lock the block or not.

Moreover we only enable the auto-check function when locking the block.

---
 drivers/nvmem/sprd-efuse.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
drivers/nvmem/sprd-efuse.c +20 -4
index 7a189ef..43b3f6e 100644
@@ -217,12 +217,14 @@ static int sprd_efuse_raw_prog(struct sprd_efuse *efuse, u32 blk, bool doub,
 	 * Enable the auto-check function to validate if the programming is
 	 * successful.
 	 */
-	sprd_efuse_set_auto_check(efuse, true);
+	if (lock)
+		sprd_efuse_set_auto_check(efuse, true);
 
 	writel(*data, efuse->base + SPRD_EFUSE_MEM(blk));
 
 	/* Disable auto-check and data double after programming */
-	sprd_efuse_set_auto_check(efuse, false);
+	if (lock)
+		sprd_efuse_set_auto_check(efuse, false);
 	sprd_efuse_set_data_double(efuse, false);
 
 	/*
@@ -237,7 +239,7 @@ static int sprd_efuse_raw_prog(struct sprd_efuse *efuse, u32 blk, bool doub,
 		writel(SPRD_EFUSE_ERR_CLR_MASK,
 		       efuse->base + SPRD_EFUSE_ERR_CLR);
 		ret = -EBUSY;
-	} else {
+	} else if (lock) {
 		sprd_efuse_set_prog_lock(efuse, lock);
 		writel(0, efuse->base + SPRD_EFUSE_MEM(blk));
 		sprd_efuse_set_prog_lock(efuse, false);
@@ -322,6 +324,7 @@ static int sprd_efuse_read(void *context, u32 offset, void *val, size_t bytes)
 static int sprd_efuse_write(void *context, u32 offset, void *val, size_t bytes)
 {
 	struct sprd_efuse *efuse = context;
+	bool lock;
 	int ret;
 
 	ret = sprd_efuse_lock(efuse);
@@ -332,7 +335,20 @@ static int sprd_efuse_write(void *context, u32 offset, void *val, size_t bytes)
 	if (ret)
 		goto unlock;
 
-	ret = sprd_efuse_raw_prog(efuse, offset, false, false, val);
+	/*
+	 * If the writing bytes are equal with the block width, which means the
+	 * whole block will be programmed. For this case, we should not allow
+	 * this block to be programmed again by locking this block.
+	 *
+	 * If the block was programmed partially, we should allow this block to
+	 * be programmed again.
+	 */
+	if (bytes < SPRD_EFUSE_BLOCK_WIDTH)
+		lock = false;
+	else
+		lock = true;
+
+	ret = sprd_efuse_raw_prog(efuse, offset, false, lock, val);
 
 	clk_disable_unprepare(efuse->clk);
 
Signature · 1 line
1.9.1
author maintainer
#4 lore raw

PATCH 3/3 nvmem: sprd: Determine double data programming from device data

In reply to Baolin Wang

We've saved the double data flag in the device data, so we should use it when programming a block.

---
 drivers/nvmem/sprd-efuse.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvmem/sprd-efuse.c +2 -1
index 43b3f6e..925feb2 100644
@@ -324,6 +324,7 @@ static int sprd_efuse_read(void *context, u32 offset, void *val, size_t bytes)
 static int sprd_efuse_write(void *context, u32 offset, void *val, size_t bytes)
 {
 	struct sprd_efuse *efuse = context;
+	bool blk_double = efuse->data->blk_double;
 	bool lock;
 	int ret;
 
@@ -348,7 +349,7 @@ static int sprd_efuse_write(void *context, u32 offset, void *val, size_t bytes)
 	else
 		lock = true;
 
-	ret = sprd_efuse_raw_prog(efuse, offset, false, lock, val);
+	ret = sprd_efuse_raw_prog(efuse, offset, blk_double, lock, val);
 
 	clk_disable_unprepare(efuse->clk);
 
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH 1/3] nvmem: sprd: Fix the block lock operation

In reply to Baolin Wang
Quoted 11 lines · Baolin Wang

From: Freeman Liu <[email protected]>

According to the Spreadtrum eFuse specification, we should write 0 to the block to trigger the lock operation.

Fixes 096030e7f449 ("nvmem: sprd: Add Spreadtrum SoCs eFuse support")
---
  drivers/nvmem/sprd-efuse.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Applied all thanks,
srini