From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: mfe@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 8/9] i2c: add <pbl/pmic.h> for PBL use
Date: Fri, 5 Aug 2022 14:54:12 +0200 [thread overview]
Message-ID: <20220805125413.1046239-9-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220805125413.1046239-1-a.fatoum@pengutronix.de>
We have much duplication in the i.MX8M boards related to PMIC setup,
add a common header to cut down on it.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/pbl/i2c.h | 16 ++++++++++++++++
include/pbl/pmic.h | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+)
create mode 100644 include/pbl/pmic.h
diff --git a/include/pbl/i2c.h b/include/pbl/i2c.h
index 1f26e3dfc6ca..d9910f531f53 100644
--- a/include/pbl/i2c.h
+++ b/include/pbl/i2c.h
@@ -18,4 +18,20 @@ static inline int pbl_i2c_xfer(struct pbl_i2c *i2c,
struct pbl_i2c *imx8m_i2c_early_init(void __iomem *regs);
struct pbl_i2c *ls1046_i2c_init(void __iomem *regs);
+static inline int i2c_dev_probe(struct pbl_i2c *i2c, int addr, bool onebyte)
+{
+ u8 buf[1];
+ struct i2c_msg msgs[] = {
+ {
+ .addr = addr,
+ .buf = buf,
+ .flags = I2C_M_RD,
+ .len = onebyte,
+ },
+ };
+
+ return pbl_i2c_xfer(i2c, msgs, 1) == 1 ? 0 : -ENODEV;
+}
+
+
#endif /* __I2C_EARLY_H */
diff --git a/include/pbl/pmic.h b/include/pbl/pmic.h
new file mode 100644
index 000000000000..0f882c5649d9
--- /dev/null
+++ b/include/pbl/pmic.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __PBL_PMIC_H_
+#define __PBL_PMIC_H_
+
+#include <pbl/i2c.h>
+
+struct pmic_config {
+ u8 reg;
+ u8 val;
+};
+
+static void pmic_reg_write(struct pbl_i2c *i2c, int addr, u8 reg, u8 val)
+{
+ int ret;
+ u8 buf[32];
+ struct i2c_msg msgs[] = {
+ {
+ .addr = addr,
+ .buf = buf,
+ },
+ };
+
+ buf[0] = reg;
+ buf[1] = val;
+
+ msgs[0].len = 2;
+
+ ret = pbl_i2c_xfer(i2c, msgs, ARRAY_SIZE(msgs));
+ if (ret != 1)
+ pr_err("Failed to write to pmic@%x: %d\n", addr, ret);
+}
+
+static inline void pmic_configure(struct pbl_i2c *i2c, u8 addr,
+ const struct pmic_config *config,
+ size_t config_len)
+{
+ for (; config_len--; config++)
+ pmic_reg_write(i2c, addr, config->reg, config->val);
+}
+
+#endif
--
2.30.2
next prev parent reply other threads:[~2022-08-05 12:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-05 12:54 [PATCH 0/9] ARM: i.MX8MN: clean up and enable imx-usb-loader Ahmad Fatoum
2022-08-05 12:54 ` [PATCH 1/9] ARM: i.MX8M: move TF-A chainload functions in <mach/xload.h> Ahmad Fatoum
2022-08-05 12:54 ` [PATCH 2/9] ARM: i.MX8M: imx8mn-evk: use generic imx8mn_load_and_start_image_via_tfa Ahmad Fatoum
2022-08-05 12:54 ` [PATCH 3/9] ARM: i.MX8MN: add SDPS barebox-side support Ahmad Fatoum
2022-08-05 12:54 ` [PATCH 4/9] ARM: i.MX8MN: evk: simplify DDR4/LPDDR4 selection code Ahmad Fatoum
2022-08-05 12:54 ` [PATCH 5/9] ddr: imx8m: rename type to more fitting ddrc|dram_type Ahmad Fatoum
2022-08-05 12:54 ` [PATCH 6/9] ARM: i.MX8M: remove struct dram_timing_info::dram_type again Ahmad Fatoum
2022-08-05 12:54 ` [PATCH 7/9] pbl: generalize fsl i2c_early API into pbl_i2c Ahmad Fatoum
2022-08-08 8:44 ` Ahmad Fatoum
2022-08-05 12:54 ` Ahmad Fatoum [this message]
2022-08-05 12:54 ` [PATCH 9/9] ARM: i.MX8M: use new pbl/pmic.h API Ahmad Fatoum
2022-08-08 8:30 ` [PATCH 0/9] ARM: i.MX8MN: clean up and enable imx-usb-loader Marco Felsch
2022-08-08 12:32 ` 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=20220805125413.1046239-9-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=mfe@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