All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Schultz <d.schultz@phytec.de>
To: <u-boot@lists.denx.de>, <upstream@lists.phytec.de>
Cc: Daniel Schultz <d.schultz@phytec.de>
Subject: [PATCH 1/6] board: phytec: common: Move eeprom read to new function
Date: Tue, 21 May 2024 23:18:22 -0700	[thread overview]
Message-ID: <20240522061827.601699-2-d.schultz@phytec.de> (raw)
In-Reply-To: <20240522061827.601699-1-d.schultz@phytec.de>

We need to read multiple times from different offsets in API v3.
Move the EEPROM read logic into a dedicated function to make it
usable multiple times.

Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
---
 board/phytec/common/phytec_som_detection.c | 38 ++++++++++++++--------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/board/phytec/common/phytec_som_detection.c b/board/phytec/common/phytec_som_detection.c
index b14bb3dbb7f..a089fe9bc90 100644
--- a/board/phytec/common/phytec_som_detection.c
+++ b/board/phytec/common/phytec_som_detection.c
@@ -47,16 +47,9 @@ int phytec_eeprom_data_setup(struct phytec_eeprom_data *data,
 	return ret;
 }
 
-int phytec_eeprom_data_init(struct phytec_eeprom_data *data,
-			    int bus_num, int addr)
+int phytec_eeprom_read(u8 *data, int bus_num, int addr, int size, int offset)
 {
-	int ret, i;
-	unsigned int crc;
-	u8 *ptr;
-	const unsigned int payload_size = sizeof(struct phytec_eeprom_payload);
-
-	if (!data)
-		data = &eeprom_data;
+	int ret;
 
 #if CONFIG_IS_ENABLED(DM_I2C)
 	struct udevice *dev;
@@ -64,19 +57,36 @@ int phytec_eeprom_data_init(struct phytec_eeprom_data *data,
 	ret = i2c_get_chip_for_busnum(bus_num, addr, 2, &dev);
 	if (ret) {
 		pr_err("%s: i2c EEPROM not found: %i.\n", __func__, ret);
-		goto err;
+		return ret;
 	}
 
-	ret = dm_i2c_read(dev, 0, (uint8_t *)data, payload_size);
+	ret = dm_i2c_read(dev, offset, (uint8_t *)data, size);
 	if (ret) {
 		pr_err("%s: Unable to read EEPROM data: %i\n", __func__, ret);
-		goto err;
+		return ret;
 	}
 #else
 	i2c_set_bus_num(bus_num);
-	ret = i2c_read(addr, 0, 2, (uint8_t *)data,
-		       sizeof(struct phytec_eeprom_data));
+	ret = i2c_read(addr, offset, 2, (uint8_t *)data, size);
 #endif
+	return ret;
+}
+
+int phytec_eeprom_data_init(struct phytec_eeprom_data *data,
+			    int bus_num, int addr)
+{
+	int ret, i;
+	unsigned int crc;
+	u8 *ptr;
+	const unsigned int payload_size = sizeof(struct phytec_eeprom_payload);
+
+	if (!data)
+		data = &eeprom_data;
+
+	ret = phytec_eeprom_read((u8 *)data, bus_num, addr,
+				 payload_size, 0);
+	if (ret)
+		goto err;
 
 	if (data->payload.api_rev == 0xff) {
 		pr_err("%s: EEPROM is not flashed. Prototype?\n", __func__);
-- 
2.25.1


  reply	other threads:[~2024-05-22 14:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-22  6:18 [PATCH 0/6] PHYTEC SOM Detection API v3 Daniel Schultz
2024-05-22  6:18 ` Daniel Schultz [this message]
2024-05-22  6:18 ` [PATCH 2/6] board: phytec: common: Define PHYTEC_API2_DATA_LEN Daniel Schultz
2024-05-22  6:18 ` [PATCH 3/6] board: phytec: common: Move API v2 init to new function Daniel Schultz
2024-05-22  6:18 ` [PATCH 4/6] board: phytec: common: Add API v3 Daniel Schultz
2024-05-22  6:18 ` [PATCH 5/6] board: phytec: common: k3: Set MAC Daniel Schultz
2024-05-22  8:38   ` [Upstream] " Wadim Egorov
2024-05-22  6:18 ` [PATCH 6/6] configs: phycore_am62x_a53_defconfig: Enable CONFIG_ENV_OVERWRITE Daniel Schultz
2024-05-22  8:30   ` [Upstream] " Wadim Egorov
2024-05-22  8:46     ` Daniel Schultz
2024-05-22  8:28 ` [Upstream] [PATCH 0/6] PHYTEC SOM Detection API v3 Wadim Egorov
2024-06-07 22:03 ` Tom Rini

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=20240522061827.601699-2-d.schultz@phytec.de \
    --to=d.schultz@phytec.de \
    --cc=u-boot@lists.denx.de \
    --cc=upstream@lists.phytec.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.