All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: "Stefan Roese" <sr@denx.de>, "Marek Behún" <kabel@kernel.org>
Cc: u-boot@lists.denx.de
Subject: [PATCH 1/3] arm: mvebu: Add support for programming LD0 and LD1 eFuse
Date: Thu, 22 Sep 2022 13:43:44 +0200	[thread overview]
Message-ID: <20220922114346.25495-2-pali@kernel.org> (raw)
In-Reply-To: <20220922114346.25495-1-pali@kernel.org>

This patch implements LD eFuse programming support. Armada 385 contains two
LD eFuse lines, each is 256 bit long with one additional lock bit. LD 0
line is mapped to U-Boot fuse bank 64 and LD 1 line to fuse bank 65. U-Boot
32-bit fuse words 0-8 are mapped to LD eFuse line bits 0-255. U-Boot fuse
word 9 is mapped to LD eFuse line lock bit.

So to program LD 1 General Purpose Data line, use U-Boot fuse command:

    => fuse prog -y 65 0 0x76543210
    => fuse prog -y 65 1 0xfedcba98
    => fuse prog -y 65 2 0x76543210
    => fuse prog -y 65 3 0xfedcba98
    => fuse prog -y 65 4 0x76543210
    => fuse prog -y 65 5 0xfedcba98
    => fuse prog -y 65 6 0x76543210
    => fuse prog -y 65 7 0xfedcba98
    => fuse prog -y 65 8 0x1

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 arch/arm/mach-mvebu/efuse.c              | 43 ++++++++++++++++++++++++
 arch/arm/mach-mvebu/include/mach/efuse.h |  4 +++
 2 files changed, 47 insertions(+)

diff --git a/arch/arm/mach-mvebu/efuse.c b/arch/arm/mach-mvebu/efuse.c
index 80318c339eb7..4b0433782171 100644
--- a/arch/arm/mach-mvebu/efuse.c
+++ b/arch/arm/mach-mvebu/efuse.c
@@ -132,6 +132,46 @@ static int prog_efuse(int nr, struct efuse_val *new_val, u32 mask0, u32 mask1)
 	return res;
 }
 
+int mvebu_prog_ld_efuse(int ld1, u32 word, u32 val)
+{
+	int i, res;
+	u32 line[EFUSE_LD_WORDS];
+
+	res = mvebu_efuse_init_hw();
+	if (res)
+		return res;
+
+	mvebu_read_ld_efuse(ld1, line);
+
+	/* check if lock bit is already programmed */
+	if (line[EFUSE_LD_WORDS - 1])
+		return -EPERM;
+
+	/* check if word is valid */
+	if (word >= EFUSE_LD_WORDS)
+		return -EINVAL;
+
+	/* check if there is some bit for programming */
+	if (val == (line[word] & val))
+		return 0;
+
+	enable_efuse_program();
+
+	mvebu_read_ld_efuse(ld1, line);
+	line[word] |= val;
+
+	for (i = 0; i < EFUSE_LD_WORDS; i++) {
+		writel(line[i], ld_efuses + i);
+		mdelay(1);
+	}
+
+	mdelay(5);
+
+	disable_efuse_program();
+
+	return 0;
+}
+
 int mvebu_efuse_init_hw(void)
 {
 	int ret;
@@ -254,6 +294,9 @@ int fuse_prog(u32 bank, u32 word, u32 val)
 {
 	int res = 0;
 
+	if (bank == EFUSE_LD0_LINE || bank == EFUSE_LD1_LINE)
+		return mvebu_prog_ld_efuse(bank == EFUSE_LD1_LINE, word, val);
+
 	/*
 	 * NOTE: Fuse line should be written as whole.
 	 * So how can we do that with this API?
diff --git a/arch/arm/mach-mvebu/include/mach/efuse.h b/arch/arm/mach-mvebu/include/mach/efuse.h
index 122e735f2fc7..b125c30beb8c 100644
--- a/arch/arm/mach-mvebu/include/mach/efuse.h
+++ b/arch/arm/mach-mvebu/include/mach/efuse.h
@@ -70,4 +70,8 @@ int mvebu_write_efuse(int nr, struct efuse_val *val);
 
 int mvebu_lock_efuse(int nr);
 
+void mvebu_read_ld_efuse(int ld1, u32 *line);
+
+int mvebu_prog_ld_efuse(int ld1, u32 word, u32 val);
+
 #endif
-- 
2.20.1


  reply	other threads:[~2022-09-22 11:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-22 11:43 [PATCH 0/3] arm: mvebu: Add support for programming LD eFuse on Armada 385 Pali Rohár
2022-09-22 11:43 ` Pali Rohár [this message]
2022-09-22 11:43 ` [PATCH 2/3] arm: mvebu: Add support for specifying VHV_Enable GPIO Pali Rohár
2022-09-22 11:43 ` [PATCH 3/3] arm: mvebu: turris_omnia: Specify VHV gpio for eFUSE programming Pali Rohár

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220922114346.25495-2-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=kabel@kernel.org \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.