public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Josua Mayer <josua@solid-run.com>
To: u-boot@lists.denx.de
Cc: Josua Mayer <josua@solid-run.com>
Subject: [RFC v2 2/3] mvebu: clearfog: convert tlv parsing to use new library
Date: Tue, 16 May 2023 14:41:52 +0300	[thread overview]
Message-ID: <20230516114153.3896-3-josua@solid-run.com> (raw)
In-Reply-To: <20230516114153.3896-1-josua@solid-run.com>

Update the existing code reading tlv data from eeprom to use the new tlv
library functions rather than relying on tlv_eeprom command internals.

Signed-off-by: Josua Mayer <josua@solid-run.com>
---
 board/solidrun/common/tlv_data.c | 46 ++++++++++++--------------------
 configs/clearfog_defconfig       |  4 ++-
 2 files changed, 20 insertions(+), 30 deletions(-)

diff --git a/board/solidrun/common/tlv_data.c b/board/solidrun/common/tlv_data.c
index 11d6e4a1380..31b4b473c75 100644
--- a/board/solidrun/common/tlv_data.c
+++ b/board/solidrun/common/tlv_data.c
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <compiler.h>
+#include <linux/err.h>
 #include <tlv_eeprom.h>
 #include "tlv_data.h"
 
@@ -50,44 +51,31 @@ static void parse_tlv_vendor_ext(struct tlvinfo_tlv *tlv_entry,
 	td->ram_size = val[5];
 }
 
-static void parse_tlv_data(u8 *eeprom, struct tlvinfo_header *hdr,
-			   struct tlvinfo_tlv *entry, struct tlv_data *td)
+static void parse_tlv_data(u8 *eeprom, struct tlvinfo_priv *tlv,
+						   struct tlv_data *td)
 {
-	unsigned int tlv_offset, tlv_len;
-
-	tlv_offset = sizeof(struct tlvinfo_header);
-	tlv_len = sizeof(struct tlvinfo_header) + be16_to_cpu(hdr->totallen);
-	while (tlv_offset < tlv_len) {
-		entry = (struct tlvinfo_tlv *)&eeprom[tlv_offset];
-
-		switch (entry->type) {
-		case TLV_CODE_PRODUCT_NAME:
-			store_product_name(entry, td);
-			break;
-		case TLV_CODE_VENDOR_EXT:
-			parse_tlv_vendor_ext(entry, td);
-			break;
-		default:
-			break;
-		}
-
-		tlv_offset += sizeof(struct tlvinfo_tlv) + entry->length;
-	}
+	struct tlvinfo_tlv *entry;
+
+	entry = tlv_entry_next_by_code(tlv, NULL, TLV_CODE_PRODUCT_NAME);
+	if (!IS_ERR(entry))
+		store_product_name(entry, td);
+
+	entry = tlv_entry_next_by_code(tlv, NULL, TLV_CODE_VENDOR_EXT);
+	if (!IS_ERR(entry))
+		parse_tlv_vendor_ext(entry, td);
 }
 
 void read_tlv_data(struct tlv_data *td)
 {
 	u8 eeprom_data[TLV_TOTAL_LEN_MAX];
-	struct tlvinfo_header *tlv_hdr;
-	struct tlvinfo_tlv *tlv_entry;
-	int ret, i;
+	struct tlvinfo_priv *priv;
+	int i;
 
 	for (i = 0; i < 2; i++) {
-		ret = read_tlvinfo_tlv_eeprom(eeprom_data, &tlv_hdr,
-					      &tlv_entry, i);
-		if (ret < 0)
+		priv = tlv_eeprom_read(tlv_eeprom_get_by_index(i), 0, eeprom_data, ARRAY_SIZE(eeprom_data));
+		if (IS_ERR(priv))
 			continue;
-		parse_tlv_data(eeprom_data, tlv_hdr, tlv_entry, td);
+		parse_tlv_data(eeprom_data, priv, td);
 	}
 }
 
diff --git a/configs/clearfog_defconfig b/configs/clearfog_defconfig
index b3ed1ec7bbe..fa86b23ef40 100644
--- a/configs/clearfog_defconfig
+++ b/configs/clearfog_defconfig
@@ -35,7 +35,7 @@ CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 # CONFIG_SPL_SHARES_INIT_SP_ADDR is not set
 CONFIG_SPL_I2C=y
 CONFIG_SYS_MAXARGS=32
-CONFIG_CMD_TLV_EEPROM=y
+# CONFIG_CMD_TLV_EEPROM is not set
 CONFIG_SPL_CMD_TLV_EEPROM=y
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_GPIO=y
@@ -81,3 +81,5 @@ CONFIG_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR=0x1
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET=0x0
+CONFIG_EEPROM_TLV_LIB=y
+CONFIG_SPL_EEPROM_TLV_LIB=y
-- 
2.35.3


  parent reply	other threads:[~2023-05-16 11:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16 11:41 [RFC v2 0/3] lib: tlv_eeprom: refactor API Josua Mayer
2023-05-16 11:41 ` [RFC v2 1/3] lib: add tlv_eeprom library Josua Mayer
2023-05-16 11:41 ` Josua Mayer [this message]
2023-05-16 11:41 ` [RFC v2 3/3] cmd: tlv_eeprom: port to new shared tlv library Josua Mayer

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=20230516114153.3896-3-josua@solid-run.com \
    --to=josua@solid-run.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox