From: Raymond Mao <[email protected]>

Add Spacemit P1 SoC support in SPL. And set the default voltage
for BUCKs and LDOs.

Also update MAINTAINERS: add Guodong Xu as co-maintainer, list the
u-boot-spacemit mailing list, register the new K1 driver files (i2c,
PMIC, regulator), and fix a pre-existing '@@' typo in Huan Zhou's
email.

Fixes: 1cd239f44438 ("riscv: spacemit: bananapi_f3: initial support added")
Signed-off-by: Raymond Mao <[email protected]>
Signed-off-by: Guodong Xu <[email protected]>

---
v4:
- DT: drop forked pmic@41; overlay keeps bootph + regulator-name
  overrides for regulator_get_by_platname().
- Overlay: explicit `resets = <&syscon_apbc RESET_TWSI8>` on &i2c8.
- set_vdd_mmc(): program 1.8 V before enable.
- defconfig: SPL_DM_REGULATOR (not SPL_DM_PMIC).
- Drop duplicate <cpu_func.h>.
- MAINTAINERS: fix Huan Zhou email typo (@@ -> @, Fixes: tag included).
---
 arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi | 32 ++++++++++++
 board/spacemit/k1/MAINTAINERS             |  7 ++-
 board/spacemit/k1/spl.c                   | 84 +++++++++++++++++++++++++++----
 configs/spacemit_k1_defconfig             |  6 +++
 4 files changed, 117 insertions(+), 12 deletions(-)

diff --git a/arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi 
b/arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi
index 1a6240a9725..b0224dc7827 100644
--- a/arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi
+++ b/arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi
@@ -74,6 +74,38 @@
        };
 };
 
+/*
+ * The kernel pmic@41 nodes use the standard regulator-* properties only;
+ * U-Boot's regulator framework looks up suppliers by `regulator-name`.
+ * Carry the U-Boot-specific names (vdd_core / vdd_1v8 / vdd_1v8_mmc) here
+ * so SPL can program the bucks that DDR training depends on.
+ */
+&i2c8 {
+       bootph-pre-ram;
+       resets = <&syscon_apbc RESET_TWSI8>;
+
+       pmic@41 {
+               bootph-pre-ram;
+
+               regulators {
+                       buck1 {
+                               regulator-name = "vdd_core";
+                               bootph-pre-ram;
+                       };
+
+                       buck3 {
+                               regulator-name = "vdd_1v8";
+                               bootph-pre-ram;
+                       };
+
+                       aldo1 {
+                               regulator-name = "vdd_1v8_mmc";
+                               bootph-pre-ram;
+                       };
+               };
+       };
+};
+
 &binman {
        u-boot-spl-ddr {
                type = "section";
diff --git a/board/spacemit/k1/MAINTAINERS b/board/spacemit/k1/MAINTAINERS
index b256cbe7978..8976c575dff 100644
--- a/board/spacemit/k1/MAINTAINERS
+++ b/board/spacemit/k1/MAINTAINERS
@@ -1,6 +1,11 @@
 BananaPi F3
-M:     Huan Zhou <pericycle.cc@@gmail.com>
+M:     Huan Zhou <[email protected]>
+M:     Guodong Xu <[email protected]>
+L:     [email protected]
 S:     Maintained
 F:     board/spacemit/k1/
 F:     configs/spacemit_k1_defconfig
 F:     doc/board/spacemit/bananapi-f3.rst
+F:     drivers/i2c/k1_i2c.c
+F:     drivers/power/pmic/pmic_spacemit_p1.c
+F:     drivers/power/regulator/spacemit_p1_regulator.c
diff --git a/board/spacemit/k1/spl.c b/board/spacemit/k1/spl.c
index bab4fac3a13..2afabc72a3f 100644
--- a/board/spacemit/k1/spl.c
+++ b/board/spacemit/k1/spl.c
@@ -15,6 +15,7 @@
 #include <i2c.h>
 #include <linux/delay.h>
 #include <log.h>
+#include <power/regulator.h>
 #include <spl.h>
 #include <tlv_eeprom.h>
 #include "tlv_codes.h"
@@ -136,6 +137,76 @@ void serial_early_init(void)
                panic("Serial uclass init failed: %d\n", ret);
 }
 
+static void set_vdd_core(void)
+{
+       struct udevice *dev;
+       int ret;
+
+       ret = regulator_get_by_platname("vdd_core", &dev);
+       if (ret)
+               panic("Fail to detect vdd_core (%d)\n", ret);
+       ret = regulator_set_enable(dev, true);
+       if (ret)
+               log_warning("Fail to enable vdd_core (%d)\n", ret);
+       ret = regulator_get_value(dev);
+       if (ret < 0)
+               log_warning("Fail to read vdd_core (%d)\n", ret);
+       log_info("vdd_core, value:%d\n", ret);
+}
+
+static void set_vdd_1v8(void)
+{
+       struct udevice *dev;
+       int ret;
+
+       ret = regulator_get_by_platname("vdd_1v8", &dev);
+       if (ret)
+               panic("Fail to detect vdd_1v8 (%d)\n", ret);
+       ret = regulator_set_value(dev, 1800000);
+       if (ret)
+               log_warning("Fail to set vdd_1v8 as 1800000 (%d)\n", ret);
+       ret = regulator_set_enable(dev, true);
+       if (ret)
+               log_warning("Fail to enable vdd_1v8 (%d)\n", ret);
+       ret = regulator_get_value(dev);
+       if (ret < 0)
+               log_warning("Fail to read vdd_1v8 (%d)\n", ret);
+       log_info("vdd_1v8, value:%d\n", ret);
+}
+
+static void set_vdd_mmc(void)
+{
+       struct udevice *dev;
+       int ret;
+
+       ret = regulator_get_by_platname("vdd_1v8_mmc", &dev);
+       if (ret)
+               panic("Fail to detect vdd_1v8_mmc (%d)\n", ret);
+       ret = regulator_set_value(dev, 1800000);
+       if (ret)
+               log_warning("Fail to set vdd_1v8_mmc as 1800000 (%d)\n", ret);
+       ret = regulator_set_enable(dev, true);
+       if (ret)
+               log_warning("Fail to enable vdd_1v8_mmc (%d)\n", ret);
+       ret = regulator_get_value(dev);
+       if (ret < 0)
+               log_warning("Fail to read vdd_1v8_mmc (%d)\n", ret);
+       log_info("vdd_1v8_mmc, value:%d\n", ret);
+}
+
+void pmic_init(void)
+{
+       struct udevice *pmic_dev;
+       int ret;
+
+       ret = uclass_get_device(UCLASS_PMIC, 0, &pmic_dev);
+       if (ret)
+               panic("Fail to detect PMIC (%d)\n", ret);
+       set_vdd_core();
+       set_vdd_1v8();
+       set_vdd_mmc();
+}
+
 /* Set default value for DDR chips */
 static void ddr_cfg_init(struct ddr_cfg *cfg)
 {
@@ -257,6 +328,8 @@ void board_init_f(ulong dummy)
                log_info("Fail to detect board:%d\n", ret);
        else
                log_info("Get board name:%s\n", (char *)i2c_buf);
+       pmic_init();
+
        ddr_early_init();
 }
 
@@ -265,17 +338,6 @@ u32 spl_boot_device(void)
        return BOOT_DEVICE_NOR;
 }
 
-void pmic_init(void)
-{
-       struct udevice *pmic_dev = NULL;
-       int ret;
-
-       ret = uclass_get_device(UCLASS_PMIC, 0, &pmic_dev);
-       if (ret)
-               panic("Fail to detect PMIC:%d\n", ret);
-}
-
 void spl_board_init(void)
 {
-       pmic_init();
 }
diff --git a/configs/spacemit_k1_defconfig b/configs/spacemit_k1_defconfig
index ce0314686ab..e71c079bef2 100644
--- a/configs/spacemit_k1_defconfig
+++ b/configs/spacemit_k1_defconfig
@@ -33,6 +33,7 @@ CONFIG_SPL_MAX_SIZE=0x33000
 CONFIG_SPL_HAVE_INIT_STACK=y
 CONFIG_SPL_I2C=y
 CONFIG_SPL_DM_RESET=y
+CONFIG_SPL_POWER=y
 CONFIG_HUSH_PARSER=y
 CONFIG_CMD_TLV_EEPROM=y
 CONFIG_SPL_CMD_TLV_EEPROM=y
@@ -51,6 +52,11 @@ CONFIG_I2C_EEPROM=y
 CONFIG_SPL_I2C_EEPROM=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
+CONFIG_DM_PMIC=y
+CONFIG_PMIC_SPACEMIT_P1=y
+CONFIG_DM_REGULATOR=y
+CONFIG_SPL_DM_REGULATOR=y
+CONFIG_DM_REGULATOR_SPACEMIT_P1=y
 CONFIG_DEBUG_UART_NS16550=y
 CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_DEBUG_UART_ANNOUNCE=y

-- 
2.43.0

Reply via email to