If anybody wants to play around with the PMIC in u-boot, here is what I currently got:
diff --git a/board/sifive/unmatched/unmatched.c b/board/sifive/unmatched/unmatched.c
index da23a6ce24..c2c834fbb8 100644
--- a/board/sifive/unmatched/unmatched.c
+++ b/board/sifive/unmatched/unmatched.c
@@ -8,6 +8,8 @@
#include <common.h>
#include <dm.h>
+#include <power/pmic.h>
+#include <power/da9063_pmic.h>
#include <asm/arch/cache.h>
#include <asm/sections.h>
@@ -21,6 +23,67 @@ void *board_fdt_blob_setup(void)
}
}
+static int read_reg(struct udevice * const dev, const char * const name, uint8_t reg) {
+ int ret = pmic_reg_read(dev, reg);
+ if (ret < 0) {
+ printf("%s: error reading %s: %d\n", __func__, name, ret);
+ return ret;
+ }
+ printf("%s: %s[0x%02X]=0x%02X\n", __func__, name, reg, ret);
+ return ret;
+}
+
+int board_late_init(void)
+{
+ struct udevice *dev;
+ int off;
+ int ret;
+
+ off = fdt_path_offset(gd->fdt_blob, "/soc/i2c/pmic");
+ if (off < 0) {
+ printf("%s: No pmic path offset: %d\n", __func__, off);
+ return off;
+ }
+
+ ret = uclass_get_device_by_of_offset(UCLASS_PMIC, off, &dev);
+ if (ret) {
+ printf("%s: Could not find PMIC, %d\n", __func__, ret);
+ return ret;
+ }
+
+ ret = pmic_reg_write(dev, DA9063_REG_PAGE_CON, 0x00); // Select page 0
+ if (ret < 0) {
+ printf("%s: error selecting page 0: %d\n", __func__, ret);
+ return ret;
+ }
+
+ (void)read_reg(dev, "CONTROL_A", DA9063_REG_CONTROL_A);
+ (void)read_reg(dev, "CONTROL_B", DA9063_REG_CONTROL_B);
+ int ctrl_c = read_reg(dev, "CONTROL_C", DA9063_REG_CONTROL_C);
+ (void)read_reg(dev, "CONTROL_D", DA9063_REG_CONTROL_D);
+ (void)read_reg(dev, "CONTROL_E", DA9063_REG_CONTROL_E);
+ (void)read_reg(dev, "CONTROL_F", DA9063_REG_CONTROL_F);
+ int rst = read_reg(dev, "RESET", DA9063_REG_RESET);
+
+ ctrl_c |= 0x08; // Set AUTO_BOOT
+ printf("%s: writing 0x%02X to CONTROL_C\n", __func__, ctrl_c);
+ ret = pmic_reg_write(dev, DA9063_REG_CONTROL_C, ctrl_c);
+ if (ret < 0) {
+ printf("%s: error writing CONTROL_C: %d\n", __func__, ret);
+ return ret;
+ }
+
+ rst =0xFF; // set reset event and duration |= 0xC0; // Set RESET_EVENT in RESET
+ printf("%s: writing 0x%02X to RESET\n", __func__, rst);
+ ret = pmic_reg_write(dev, DA9063_REG_RESET, rst);
+ if (ret < 0) {
+ printf("%s: error writing RESET: %d\n", __func__, ret);
+ return ret;
+ }
+
+ return 0;
+}
+
int board_init(void)
{
int ret;
diff --git a/configs/sifive_unmatched_defconfig b/configs/sifive_unmatched_defconfig
index 548fcec17a..31911c37f0 100644
--- a/configs/sifive_unmatched_defconfig
+++ b/configs/sifive_unmatched_defconfig
@@ -23,6 +23,12 @@ CONFIG_DEFAULT_FDT_FILE="sifive/hifive-unmatched-a00.dtb"
CONFIG_DISPLAY_CPUINFO=y
CONFIG_DISPLAY_BOARDINFO=y
CONFIG_DISPLAY_BOARDINFO_LATE=y
+CONFIG_DM_PMIC=y
+CONFIG_PMIC_CHILDREN=y
+CONFIG_SPL_PMIC_CHILDREN=y
+CONFIG_DM_PMIC_DA9063=y
+CONFIG_SPL_DM_PMIC_DA9063=y
+CONFIG_BOARD_LATE_INIT=y
CONFIG_SPL_SEPARATE_BSS=y
CONFIG_SPL_MTD_SUPPORT=y
CONFIG_SPL_DM_SPI_FLASH=y