mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Robin van der Gracht <robin@protonic.nl>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>,
	Robin van der Gracht <robin@protonic.nl>,
	david@protonic.nl
Subject: [PATCH 8/9] ARM: boards: protonic-imx6: Read serial and mac from fuses if available
Date: Thu, 16 Jun 2022 15:11:13 +0200	[thread overview]
Message-ID: <20220616131114.214628-9-robin@protonic.nl> (raw)
In-Reply-To: <20220616131114.214628-1-robin@protonic.nl>

Read board serial number from GP1 fuses if available and fall-back to the
i2c RFID eeprom (current method) otherwise.

Signed-off-by: Robin van der Gracht <robin@protonic.nl>
---
 arch/arm/boards/protonic-imx6/board.c | 44 ++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 7 deletions(-)

diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 95ec7be793..dd2c041e07 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -15,6 +15,7 @@
 #include <i2c/i2c.h>
 #include <mach/bbu.h>
 #include <mach/imx6.h>
+#include <mach/ocotp-fusemap.h>
 #include <mfd/imx6q-iomuxc-gpr.h>
 #include <mfd/syscon.h>
 #include <net.h>
@@ -211,12 +212,11 @@ static int prt_imx6_set_mac(struct prt_imx6_priv *priv,
 	return 0;
 }
 
-static int prt_imx6_set_serial(struct prt_imx6_priv *priv,
-			       struct prti6q_rfid_contents *rfid)
+static int prt_imx6_set_serial(struct prt_imx6_priv *priv, char *serial)
 {
-	rfid->serial[9] = 0; /* Failsafe */
-	dev_info(priv->dev, "Serial number: %s\n", rfid->serial);
-	barebox_set_serial_number(rfid->serial);
+	serial[9] = 0; /* Failsafe */
+	dev_info(priv->dev, "Serial number: %s\n", serial);
+	barebox_set_serial_number(serial);
 
 	return 0;
 }
@@ -240,13 +240,36 @@ static int prt_imx6_read_i2c_mac_serial(struct prt_imx6_priv *priv)
 	if (ret)
 		return ret;
 
-	ret = prt_imx6_set_serial(priv, &rfid);
+	ret = prt_imx6_set_serial(priv, rfid.serial);
 	if (ret)
 		return ret;
 
 	return 0;
 }
 
+#define PRT_IMX6_GP1_FMT_DEC		BIT(31)
+
+static int prt_imx6_read_ocotp_serial(struct prt_imx6_priv *priv)
+{
+	int ret;
+	char serial[11];
+	unsigned val;
+
+	ret = imx_ocotp_read_field(OCOTP_GP1, &val);
+	if (ret) {
+		dev_err(priv->dev, "Failed to read ocotp serial (%i)\n", ret);
+		return ret;
+	}
+
+	if (!(val & PRT_IMX6_GP1_FMT_DEC))
+		return -EINVAL;
+	val &= PRT_IMX6_GP1_FMT_DEC - 1;
+
+	snprintf(serial, sizeof(serial), "%u", val);
+
+	return prt_imx6_set_serial(priv, serial);
+}
+
 static int prt_imx6_usb_mount(struct prt_imx6_priv *priv)
 {
 	struct device_d *dev = priv->dev;
@@ -522,7 +545,14 @@ static int prt_imx6_devices_init(void)
 
 	prt_imx6_bbu(priv);
 
-	prt_imx6_read_i2c_mac_serial(priv);
+	/*
+	 * Read serial number from fuses. On success we'll assume the imx_ocotp
+	 * driver takes care of providing the mac address if needed. On
+	 * failure we'll fallback to reading and setting serial and mac from an
+	 * attached RFID eeprom.
+	 */
+	if (prt_imx6_read_ocotp_serial(priv) != 0)
+		prt_imx6_read_i2c_mac_serial(priv);
 
 	bootentry_register_provider(prt_imx6_bootentry_provider);
 
-- 
2.34.1




  parent reply	other threads:[~2022-06-16 13:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-16 13:11 [PATCH 0/9] ARM: boards: protonic-imx6: Updates Robin van der Gracht
2022-06-16 13:11 ` [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low Robin van der Gracht
2022-06-16 16:28   ` Oleksij Rempel
2022-06-16 16:38     ` Oleksij Rempel
2022-06-17  6:57       ` Sascha Hauer
2022-06-17  8:44         ` Marco Felsch
2022-06-20  7:51           ` Ahmad Fatoum
2022-06-20  8:16             ` Robin van der Gracht
2022-06-20 15:42             ` Robin van der Gracht
2022-06-20  6:48       ` Robin van der Gracht
2022-06-20  7:23         ` Oleksij Rempel
2022-06-16 13:11 ` [PATCH 2/9] ARM: boards: protonic-imx6: Update comment to match a recent code update Robin van der Gracht
2022-06-17  7:00   ` Sascha Hauer
2022-06-20  6:40     ` Robin van der Gracht
2022-06-16 13:11 ` [PATCH 3/9] ARM: boards: protonic-imx6: Free allocated autoboot_timeout string Robin van der Gracht
2022-06-16 13:11 ` [PATCH 4/9] ARM: boards: protonic-imx6: Always free allocated alias string Robin van der Gracht
2022-06-16 13:11 ` [PATCH 5/9] ARM: boards: protonic-imx6: Remove unsused argument from prt_imx6_usb_mount Robin van der Gracht
2022-06-16 13:11 ` [PATCH 6/9] ARM: boards: protonic-imx6: Register prt-usb boot entry Robin van der Gracht
2022-06-16 13:11 ` [PATCH 7/9] ARM: boards: protonic-imx6: Remove usb_delay from the priv struct Robin van der Gracht
2022-06-16 13:11 ` Robin van der Gracht [this message]
2022-06-16 13:11 ` [PATCH 9/9] ARM: boards: protonic-imx6: Register serial_number parameter with ocotp Robin van der Gracht
2022-06-17  7:10 ` (subset) [PATCH 0/9] ARM: boards: protonic-imx6: Updates Sascha Hauer

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=20220616131114.214628-9-robin@protonic.nl \
    --to=robin@protonic.nl \
    --cc=barebox@lists.infradead.org \
    --cc=david@protonic.nl \
    --cc=o.rempel@pengutronix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox