Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1268387ybh; Thu, 12 Mar 2020 21:09:08 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuKg7c/DqM+MOxYmAmu5MjaaFMUmFguJx9iKXlJItFlSnSbMkPUJXTr/XiAD2M+jpYLklhf X-Received: by 2002:aca:ac89:: with SMTP id v131mr5468477oie.7.1584072548242; Thu, 12 Mar 2020 21:09:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584072548; cv=none; d=google.com; s=arc-20160816; b=osSyV8vzYtRWDUJx30SacM44/lgzF/BEGPK2Po3N4zQu6nx8yvLbcp90lxlnyQulgg SZUd5GrseUqclmwo2/eawZsKY9P74ZLydnl3GVFkxhmMLrOR/khM0xWk8UkNFEHcP7KT 2xLzh/cgp99D+8x7+xhZ6SCauWN4Ic9brMuRLwtkmWxErXrXaJiRSE/E19G2iyLLzaSU KTDBwFpafk8rzQoSYHRhyxNqzbaHVYhy6kY7i4h1D33WckBDwht+lGFG7+GYycEM48WZ jRYpk0Az8cf6sKjS/2MH3TdIdmq1wwYPE+NxQpK9p5KIq2emoxeDw5d9pR0AXkpw4xZT /4pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=0tp1yOfTBJtTk7/G231IbB/x4IfZsz2lYkWgFKOzAYA=; b=xBVsbMIOdJwWbUdcxzgHhz84BZUNHbO5GU4RN6eOdCkF9Rc0y9Y88qe1vcfpUia+KU zP1ydaA3JCWQvvXZEFqPPPqLzbWsw7T8bH6tXhd1cqXQ1/EWbMVc0LTT/XKhgF7hDmoY p6xenzKJ4kc2S9wpkdfIj0HEiAtUcTFmMxLkx2pvxiStvqI6DTwbgj0gMPbK+WJFsv0u gM3F6E2wPbHvOc5nJn8PjmrY8OD1aFeN8Ui+7AjARbXJOe0duF6UKpDKXjOnAyl38Lhs EgDdOSGTTFBaGgZk458ES301TTunDfRrxAieQZwsHpfU96vvOKljaJ1kaaTtGRAexyqB bbDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=D0KKUIxW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m20si4033452otk.238.2020.03.12.21.08.56; Thu, 12 Mar 2020 21:09:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=D0KKUIxW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726455AbgCMEH1 (ORCPT + 99 others); Fri, 13 Mar 2020 00:07:27 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:36870 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725809AbgCMEH1 (ORCPT ); Fri, 13 Mar 2020 00:07:27 -0400 Received: by mail-pl1-f194.google.com with SMTP id f16so3596503plj.4 for ; Thu, 12 Mar 2020 21:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=0tp1yOfTBJtTk7/G231IbB/x4IfZsz2lYkWgFKOzAYA=; b=D0KKUIxWRC1vEGlakiinbwOPwjQR7/q6REyklE9YYxS7GMsKuqAhO88JySWEPp8GaP 1eX4IST5+tsNabcvCdi1O0HXRgw7NZm487HuB5/PRZz2FJQPWjIbPMLG7OUSLQlu+U49 JphwzczpwoKY+qK+FqsLMOxH8lZSfvQ9ZXO9OXS7uOeSHYmDJO36fE8yLbCOXllpbHUQ rylxqDPCaTP9SoO+Zkj2/yGT9DXPBjUNJO/AirH2H41HMi2D1/snJEDoC7rQRxWMjUDJ 0R/RA9B2ONvLNIQw/UxfFE+Ylet6vRAZXUy8SfWfLN7qHW6TWpviPzjdb6MXlGUcvd68 1rfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=0tp1yOfTBJtTk7/G231IbB/x4IfZsz2lYkWgFKOzAYA=; b=qpiu/iFnyPYdn7LIJMcbhx/nCSBxFQ7SPvGKIIpkvqDBX7esOGqyjaVcsP9ass2EBN Leg/8/iy2ROumVDibXfEHw3ou2v31MYWPvOXV9OotB3yEF7vp6fciwnOYYlLoo8msQpX z9T07/LnUi+zFcykwSg0Xb995fN7i3inDQT3frEBxtpgxQYKHTv8moXKQoFEGc1hB8zF Dj04BR8tydTsKSq0Crz1CSafky1O0rOBiz09dVaOUJb+MvPeVXIAsJhbmpvqRMIUR760 /l7EL9KWXgkieAgkMGJCqg6lonj4m1HAE22y/EiJ6TtGquhIT6m2aoHGS8ayOAO8M8xD kTcQ== X-Gm-Message-State: ANhLgQ3vKT7KPAKkLDYBgDrZYUulygZQhF4sIjybZfd5eO4Rws2DlVlB K7QWLhSpjyGUk1nzrggHeJDB6Zz5 X-Received: by 2002:a17:902:bcca:: with SMTP id o10mr11000766pls.160.1584072446143; Thu, 12 Mar 2020 21:07:26 -0700 (PDT) Received: from sh03840pcu.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id 6sm15576661pfx.69.2020.03.12.21.07.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Mar 2020 21:07:25 -0700 (PDT) From: Baolin Wang To: srinivas.kandagatla@linaro.org Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com, freeman.liu@unisoc.com, baolin.wang7@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] nvmem: sprd: Optimize the block lock operation Date: Fri, 13 Mar 2020 12:07:08 +0800 Message-Id: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Freeman Liu 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. Signed-off-by: Freeman Liu Signed-off-by: Baolin Wang --- drivers/nvmem/sprd-efuse.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/nvmem/sprd-efuse.c b/drivers/nvmem/sprd-efuse.c index 7a189ef..43b3f6e 100644 --- a/drivers/nvmem/sprd-efuse.c +++ b/drivers/nvmem/sprd-efuse.c @@ -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); -- 1.9.1