From: Marc Kleine-Budde <mkl@pengutronix.de>
To: barebox@lists.infradead.org
Cc: afa@pengutronix.de, kernel@pengutronix.de
Subject: [PATCH v4 1/3] i2c: add <pbl/eeprom.h> for PBL use
Date: Wed, 09 Aug 2023 09:26:04 +0200 [thread overview]
Message-ID: <20230809-phytec-som-imx8mm-v4-1-b9d4759582d8@pengutronix.de> (raw)
In-Reply-To: <20230809-phytec-som-imx8mm-v4-0-b9d4759582d8@pengutronix.de>
Add a small helper to read a single page of EEPROM data.
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
include/pbl/eeprom.h | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/include/pbl/eeprom.h b/include/pbl/eeprom.h
new file mode 100644
index 000000000000..df868b1a37fb
--- /dev/null
+++ b/include/pbl/eeprom.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __PBL_EEPROM_H_
+#define __PBL_EEPROM_H_
+
+#include <common.h>
+#include <pbl/i2c.h>
+
+static inline void eeprom_read(struct pbl_i2c *i2c, u16 client_addr, u32 addr, void *buf, u16 count)
+{
+ u8 msgbuf[2];
+ struct i2c_msg msg[] = {
+ {
+ .addr = client_addr,
+ .buf = msgbuf,
+ }, {
+ .addr = client_addr,
+ .flags = I2C_M_RD,
+ .buf = buf,
+ .len = count,
+ },
+ };
+ int ret, i = 0;
+
+ if (addr & I2C_ADDR_16_BIT)
+ msgbuf[i++] = addr >> 8;
+ msgbuf[i++] = addr;
+ msg[0].len = i;
+
+ ret = pbl_i2c_xfer(i2c, msg, ARRAY_SIZE(msg));
+ if (ret != ARRAY_SIZE(msg))
+ pr_err("Failed to read from eeprom@%x: %d\n", client_addr, ret);
+}
+
+#endif
--
2.40.1
next prev parent reply other threads:[~2023-08-09 7:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-09 7:26 [PATCH v4 0/3] ARM: i.MX8MM: add Phytec i.MX8 SoM support Marc Kleine-Budde
2023-08-09 7:26 ` Marc Kleine-Budde [this message]
2023-08-09 8:47 ` [PATCH v4 1/3] i2c: add <pbl/eeprom.h> for PBL use Ahmad Fatoum
2023-08-09 7:26 ` [PATCH v4 2/3] common: board: phytec: import SoM detection for imx8m based SoM from u-boot Marc Kleine-Budde
2023-08-09 7:26 ` [PATCH v4 3/3] ARM: i.MX8MM: add Phytec i.MX8MM SoM support Marc Kleine-Budde
2023-09-04 10:40 ` [PATCH v4 0/3] ARM: i.MX8MM: add Phytec i.MX8 " 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=20230809-phytec-som-imx8mm-v4-1-b9d4759582d8@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=afa@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=kernel@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