power: pmic: add the base MAX8907 PMIC support
authorSvyatoslav Ryhel <clamor95@gmail.com>
Sun, 6 Oct 2024 11:50:02 +0000 (14:50 +0300)
committerSvyatoslav Ryhel <clamor95@gmail.com>
Thu, 8 May 2025 05:30:53 +0000 (08:30 +0300)
Add basic i2c based read/write functions to access PMIC registers.

Tested-by: Ion Agorria <ion@agorria.com>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
drivers/power/pmic/Kconfig
drivers/power/pmic/Makefile
drivers/power/pmic/max8907.c [new file with mode: 0644]

index 5a61cd4..ec7ccc3 100644 (file)
@@ -184,6 +184,15 @@ config SPL_DM_PMIC_PFUZE100
        This config enables implementation of driver-model pmic uclass features
        for PMIC PFUZE100 in SPL. The driver implements read/write operations.
 
+config DM_PMIC_MAX8907
+       bool "Enable Driver Model for PMIC MAX8907"
+       ---help---
+       This config enables implementation of driver-model pmic uclass features
+       for PMIC MAX8907. The driver implements read/write operations.
+       This is a Power Management IC with a decent set of peripherals from which
+       3 DC-to-DC Step-Down (SD) Regulators, 20 Low-Dropout Linear (LDO) Regulators,
+       Real-Time Clock (RTC) and more with I2C Compatible Interface.
+
 config DM_PMIC_MAX77663
        bool "Enable Driver Model for PMIC MAX77663"
        ---help---
index 2210b1a..6bebffb 100644 (file)
@@ -7,6 +7,7 @@ obj-$(CONFIG_$(PHASE_)DM_PMIC) += pmic-uclass.o
 obj-$(CONFIG_$(PHASE_)DM_PMIC_FAN53555) += fan53555.o
 obj-$(CONFIG_$(PHASE_)DM_PMIC_DA9063) += da9063.o
 obj-$(CONFIG_$(PHASE_)DM_PMIC_MAX77663) += max77663.o
+obj-$(CONFIG_$(PHASE_)DM_PMIC_MAX8907) += max8907.o
 obj-$(CONFIG_DM_PMIC_MAX77686) += max77686.o
 obj-$(CONFIG_DM_PMIC_MAX8998) += max8998.o
 obj-$(CONFIG_DM_PMIC_MC34708) += mc34708.o
diff --git a/drivers/power/pmic/max8907.c b/drivers/power/pmic/max8907.c
new file mode 100644 (file)
index 0000000..aeb6fe7
--- /dev/null
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  Copyright(C) 2024 Svyatoslav Ryhel <clamor95@gmail.com>
+ */
+
+#include <dm.h>
+#include <dm/lists.h>
+#include <power/pmic.h>
+
+static int max8907_write(struct udevice *dev, uint reg, const uint8_t *buff, int len)
+{
+       int ret;
+
+       ret = dm_i2c_write(dev, reg, buff, len);
+       if (ret) {
+               log_debug("%s: write error to device: %p register: %#x!\n",
+                         __func__, dev, reg);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int max8907_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
+{
+       int ret;
+
+       ret = dm_i2c_read(dev, reg, buff, len);
+       if (ret) {
+               log_debug("%s: read error from device: %p register: %#x!\n",
+                         __func__, dev, reg);
+               return ret;
+       }
+
+       return 0;
+}
+
+static struct dm_pmic_ops max8907_ops = {
+       .read = max8907_read,
+       .write = max8907_write,
+};
+
+static const struct udevice_id max8907_ids[] = {
+       { .compatible = "maxim,max8907" },
+       { }
+};
+
+U_BOOT_DRIVER(pmic_max8907) = {
+       .name = "max8907_pmic",
+       .id = UCLASS_PMIC,
+       .of_match = max8907_ids,
+       .ops = &max8907_ops,
+};