mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] i2c: add pmic_reg_read8() for PBL use
@ 2024-01-02 11:26 Sascha Hauer
  0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2024-01-02 11:26 UTC (permalink / raw)
  To: Barebox List; +Cc: Ahmad Fatoum, bst

From: Bastian Krause <bst@pengutronix.de>

Add a common PMIC read function to PBL which allows easy porting of
U-Boot's pmic_reg_read() in lowlevel board code.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20231220104739.10700-1-bst@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/pbl/pmic.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/include/pbl/pmic.h b/include/pbl/pmic.h
index 695e47a564..91c5be3ff3 100644
--- a/include/pbl/pmic.h
+++ b/include/pbl/pmic.h
@@ -9,6 +9,27 @@ struct pmic_config {
 	u8 val;
 };
 
+static inline void pmic_reg_read8(struct pbl_i2c *i2c, int addr, u8 reg, u8 *val)
+{
+	int ret;
+	struct i2c_msg msg[] = {
+		{
+			.addr = addr,
+			.buf = &reg,
+			.len = 1,
+		}, {
+			.addr = addr,
+			.flags = I2C_M_RD,
+			.buf = val,
+			.len = 1,
+		},
+	};
+
+	ret = pbl_i2c_xfer(i2c, msg, ARRAY_SIZE(msg));
+	if (ret != ARRAY_SIZE(msg))
+		pr_err("Failed to read from pmic@%x: %d\n", addr, ret);
+}
+
 static void pmic_reg_write8(struct pbl_i2c *i2c, int addr, u8 reg, u8 val)
 {
 	int ret;
-- 
2.39.2




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-02 11:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-02 11:26 [PATCH] i2c: add pmic_reg_read8() for PBL use Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox