public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Igor Opaniuk <igor.opaniuk@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 02/14] toradex: tdx-cfg-block: add EEPROM read/store wrappers
Date: Wed, 15 Jul 2020 13:30:53 +0300	[thread overview]
Message-ID: <20200715103105.8622-3-igor.opaniuk@gmail.com> (raw)
In-Reply-To: <20200715103105.8622-1-igor.opaniuk@gmail.com>

From: Igor Opaniuk <igor.opaniuk@toradex.com>

These functions wrap functionality for storing config blocks in EEPROM.

Signed-off-by: Igor Opaniuk <igor.opaniuk@toradex.com>
---

(no changes since v1)

 board/toradex/common/Makefile     |  1 +
 board/toradex/common/tdx-eeprom.c | 90 +++++++++++++++++++++++++++++++
 board/toradex/common/tdx-eeprom.h | 14 +++++
 3 files changed, 105 insertions(+)
 create mode 100644 board/toradex/common/tdx-eeprom.c
 create mode 100644 board/toradex/common/tdx-eeprom.h

diff --git a/board/toradex/common/Makefile b/board/toradex/common/Makefile
index 6b9fccb6b9..7b19b6e4c8 100644
--- a/board/toradex/common/Makefile
+++ b/board/toradex/common/Makefile
@@ -8,4 +8,5 @@ obj- := __dummy__.o
 else
 obj-$(CONFIG_TDX_CFG_BLOCK) += tdx-cfg-block.o
 obj-y += tdx-common.o
+obj-y += tdx-eeprom.o
 endif
diff --git a/board/toradex/common/tdx-eeprom.c b/board/toradex/common/tdx-eeprom.c
new file mode 100644
index 0000000000..fbc267dab6
--- /dev/null
+++ b/board/toradex/common/tdx-eeprom.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2020 Toradex
+ */
+
+#include <dm.h>
+#include <i2c_eeprom.h>
+#include <linux/errno.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static int get_tdx_eeprom(u32 eeprom_id, struct udevice **devp)
+{
+	int ret = 0;
+	int node;
+	ofnode eeprom;
+	char eeprom_str[16];
+	const char *path;
+
+	if (!gd->fdt_blob) {
+		printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
+		return -EFAULT;
+	}
+
+	node = fdt_path_offset(gd->fdt_blob, "/aliases");
+	if (node < 0)
+		return -ENODEV;
+
+	sprintf(eeprom_str, "eeprom%d", eeprom_id);
+
+	path = fdt_getprop(gd->fdt_blob, node, eeprom_str, NULL);
+	if (!path) {
+		printf("%s: no alias for %s\n", __func__, eeprom_str);
+		return -ENODEV;
+	}
+
+	eeprom = ofnode_path(path);
+	if (!ofnode_valid(eeprom)) {
+		printf("%s: invalid hardware path to EEPROM\n", __func__);
+		return -ENODEV;
+	}
+
+	ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, devp);
+	if (ret) {
+		printf("%s: cannot find EEPROM by node\n", __func__);
+		return ret;
+	}
+
+	return ret;
+}
+
+int read_tdx_eeprom_data(u32 eeprom_id, int offset, u8 *buf,
+			 int size)
+{
+	struct udevice *dev;
+	int ret;
+
+	ret = get_tdx_eeprom(eeprom_id, &dev);
+	if (ret)
+		return ret;
+
+	ret = i2c_eeprom_read(dev, 0x0, buf, size);
+	if (ret) {
+		printf("%s: error reading data from EEPROM id: %d!, ret = %d\n",
+		       __func__, eeprom_id, ret);
+		return ret;
+	}
+
+	return ret;
+}
+
+int write_tdx_eeprom_data(u32 eeprom_id, int offset, u8 *buf,
+			  int size)
+{
+	struct udevice *dev;
+	int ret;
+
+	ret = get_tdx_eeprom(eeprom_id, &dev);
+	if (ret)
+		return ret;
+
+	ret = i2c_eeprom_write(dev, 0x0, buf, size);
+	if (ret) {
+		printf("%s: error writing data to EEPROM id: %d, ret = %d\n",
+		       __func__, eeprom_id, ret);
+		return ret;
+	}
+
+	return ret;
+}
diff --git a/board/toradex/common/tdx-eeprom.h b/board/toradex/common/tdx-eeprom.h
new file mode 100644
index 0000000000..a6772d2f3f
--- /dev/null
+++ b/board/toradex/common/tdx-eeprom.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2020 Toradex
+ */
+
+#ifndef _TDX_EEPROM_H
+#define _TDX_EEPROM_H
+
+#include <i2c_eeprom.h>
+
+int read_tdx_eeprom_data(u32 eeprom_id, int offset, uint8_t *buf, int size);
+int write_tdx_eeprom_data(u32 eeprom_id, int offset, uint8_t *buf, int size);
+
+#endif /* _TDX_EEPROM_H */
-- 
2.17.1

  parent reply	other threads:[~2020-07-15 10:30 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-15 10:30 [PATCH v2 00/14] toradex: imx: fixes and updates for v2020.10 Igor Opaniuk
2020-07-15 10:30 ` [PATCH v2 01/14] imx: mx7: fix DDRC size in A7-M4 mapping table Igor Opaniuk
2020-07-27 19:09   ` sbabic at denx.de
2020-07-15 10:30 ` Igor Opaniuk [this message]
2020-07-27 12:49   ` [PATCH v2 02/14] toradex: tdx-cfg-block: add EEPROM read/store wrappers Stefano Babic
2020-07-27 13:35     ` Tom Rini
2020-07-27 14:17       ` Stefano Babic
2020-07-27 19:09   ` sbabic at denx.de
2020-07-15 10:30 ` [PATCH v2 03/14] toradex: tdx-cfg-block: add carrier boards and display adapters Igor Opaniuk
2020-07-27 19:09   ` sbabic at denx.de
2020-07-15 10:30 ` [PATCH v2 04/14] toradex: tdx-cfg-block: add support for EEPROM Igor Opaniuk
2020-07-27 19:09   ` sbabic at denx.de
2020-07-15 10:30 ` [PATCH v2 05/14] toradex: tdx-cfg-clock: add migration routine from PID8 Igor Opaniuk
2020-07-27 19:10   ` sbabic at denx.de
2020-07-15 10:30 ` [PATCH v2 06/14] toradex: tdx-cfg-block: add carrier board info printing Igor Opaniuk
2020-07-27 19:09   ` sbabic at denx.de
2020-07-15 10:30 ` [PATCH v2 07/14] ARM: dts: imx8mm-verdin: eeprom nodes adjustments Igor Opaniuk
2020-07-27 19:09   ` sbabic at denx.de
2020-07-15 10:30 ` [PATCH v2 08/14] verdin-imx8mm: add EEPROM support for carrier board Igor Opaniuk
2020-07-27 19:09   ` sbabic at denx.de
2020-07-15 10:31 ` [PATCH v2 09/14] ARM: dts: imx6ull-colibri: move u-boot specific node Igor Opaniuk
2020-07-27 19:10   ` sbabic at denx.de
2020-07-15 10:31 ` [PATCH v2 10/14] toradex: common: show boot logo Igor Opaniuk
2020-07-27 19:09   ` sbabic at denx.de
2020-07-15 10:31 ` [PATCH v2 11/14] ARM: dts: imx7-colibri: multiple node updates Igor Opaniuk
2020-07-27 19:09   ` sbabic at denx.de
2020-07-15 10:31 ` [PATCH v2 12/14] colibri-imx6ull: show boot logo Igor Opaniuk
2020-07-27 19:09   ` sbabic at denx.de
2020-07-15 10:31 ` [PATCH v2 13/14] colibri-imx6ull: fix splash screen logo drawing Igor Opaniuk
2020-07-27 19:09   ` sbabic at denx.de
2020-07-15 10:31 ` [PATCH v2 14/14] colibri-imx7: fix splash " Igor Opaniuk
2020-07-27 19:09   ` sbabic at denx.de
2020-07-23 15:03 ` [PATCH v2 00/14] toradex: imx: fixes and updates for v2020.10 Igor Opaniuk
2020-07-23 15:16   ` Stefano Babic

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=20200715103105.8622-3-igor.opaniuk@gmail.com \
    --to=igor.opaniuk@gmail.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