[U-Boot] [PATCH 01/16] power: sunxi: add AXP803 PMIC support
Jagan Teki
jagan at amarulasolutions.com
Tue Dec 12 06:58:16 UTC 2017
AXP803 another PMIC produced by x-powers and paired with
A64 via RSB bus.
unlike other axp chip's support in SPL this is only added
for U-Boot proper since SPL on A64 has no space to add anything.
Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
---
arch/arm/mach-sunxi/Makefile | 9 ++
arch/arm/mach-sunxi/pmic_bus.c | 9 +-
arch/arm/mach-sunxi/rsb.c | 2 +-
board/sunxi/board.c | 40 +++++++
drivers/power/Kconfig | 95 ++++++++++-----
drivers/power/Makefile | 3 +
drivers/power/axp803.c | 260 +++++++++++++++++++++++++++++++++++++++++
include/axp803.h | 68 +++++++++++
include/axp_pmic.h | 4 +
9 files changed, 458 insertions(+), 32 deletions(-)
create mode 100644 drivers/power/axp803.c
create mode 100644 include/axp803.h
diff --git a/arch/arm/mach-sunxi/Makefile b/arch/arm/mach-sunxi/Makefile
index 2a3c379..aedf22f 100644
--- a/arch/arm/mach-sunxi/Makefile
+++ b/arch/arm/mach-sunxi/Makefile
@@ -19,9 +19,15 @@ endif
obj-$(CONFIG_MACH_SUN6I) += prcm.o
obj-$(CONFIG_MACH_SUN8I) += prcm.o
obj-$(CONFIG_MACH_SUN9I) += prcm.o
+ifndef CONFIG_SPL_BUILD
+obj-$(CONFIG_MACH_SUN50I) += prcm.o
+endif
obj-$(CONFIG_MACH_SUN6I) += p2wi.o
obj-$(CONFIG_MACH_SUN8I) += rsb.o
obj-$(CONFIG_MACH_SUN9I) += rsb.o
+ifndef CONFIG_SPL_BUILD
+obj-$(CONFIG_MACH_SUN50I) += rsb.o
+endif
obj-$(CONFIG_MACH_SUN4I) += clock_sun4i.o
obj-$(CONFIG_MACH_SUN5I) += clock_sun4i.o
obj-$(CONFIG_MACH_SUN6I) += clock_sun6i.o
@@ -38,6 +44,9 @@ obj-$(CONFIG_AXP152_POWER) += pmic_bus.o
obj-$(CONFIG_AXP209_POWER) += pmic_bus.o
obj-$(CONFIG_AXP221_POWER) += pmic_bus.o
obj-$(CONFIG_AXP809_POWER) += pmic_bus.o
+ifndef CONFIG_SPL_BUILD
+obj-$(CONFIG_AXP803_POWER) += pmic_bus.o
+endif
obj-$(CONFIG_AXP818_POWER) += pmic_bus.o
ifdef CONFIG_SPL_BUILD
diff --git a/arch/arm/mach-sunxi/pmic_bus.c b/arch/arm/mach-sunxi/pmic_bus.c
index f917c3e..34acd01 100644
--- a/arch/arm/mach-sunxi/pmic_bus.c
+++ b/arch/arm/mach-sunxi/pmic_bus.c
@@ -36,7 +36,8 @@ int pmic_bus_init(void)
if (!needs_init)
return 0;
-#if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
+#if defined CONFIG_AXP221_POWER || defined CONFIG_AXP803_POWER || \
+ defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
# ifdef CONFIG_MACH_SUN6I
p2wi_init();
ret = p2wi_change_to_p2wi_mode(AXP221_CHIP_ADDR, AXP221_CTRL_ADDR,
@@ -65,7 +66,8 @@ int pmic_bus_read(u8 reg, u8 *data)
return i2c_read(AXP152_I2C_ADDR, reg, 1, data, 1);
#elif defined CONFIG_AXP209_POWER
return i2c_read(AXP209_I2C_ADDR, reg, 1, data, 1);
-#elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
+#elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP803_POWER || \
+ defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
# ifdef CONFIG_MACH_SUN6I
return p2wi_read(reg, data);
# elif defined CONFIG_MACH_SUN8I_R40
@@ -82,7 +84,8 @@ int pmic_bus_write(u8 reg, u8 data)
return i2c_write(AXP152_I2C_ADDR, reg, 1, &data, 1);
#elif defined CONFIG_AXP209_POWER
return i2c_write(AXP209_I2C_ADDR, reg, 1, &data, 1);
-#elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
+#elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP803_POWER || \
+ defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
# ifdef CONFIG_MACH_SUN6I
return p2wi_write(reg, data);
# elif defined CONFIG_MACH_SUN8I_R40
diff --git a/arch/arm/mach-sunxi/rsb.c b/arch/arm/mach-sunxi/rsb.c
index 6fd11f1..ea52a6f 100644
--- a/arch/arm/mach-sunxi/rsb.c
+++ b/arch/arm/mach-sunxi/rsb.c
@@ -27,7 +27,7 @@ static void rsb_cfg_io(void)
sunxi_gpio_set_pull(SUNXI_GPL(1), 1);
sunxi_gpio_set_drv(SUNXI_GPL(0), 2);
sunxi_gpio_set_drv(SUNXI_GPL(1), 2);
-#elif defined CONFIG_MACH_SUN9I
+#elif defined CONFIG_MACH_SUN9I || defined CONFIG_MACH_SUN50I
sunxi_gpio_set_cfgpin(SUNXI_GPN(0), SUN9I_GPN_R_RSB);
sunxi_gpio_set_cfgpin(SUNXI_GPN(1), SUN9I_GPN_R_RSB);
sunxi_gpio_set_pull(SUNXI_GPN(0), 1);
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index dcacdf3..158282e 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -173,6 +173,40 @@ void i2c_init_board(void)
#endif
}
+#ifdef CONFIG_AXP803_POWER
+static int axp803_init(void)
+{
+ int power_failed = 0;
+
+ power_failed = axp_init();
+
+ power_failed |= axp_set_dcdc1(CONFIG_AXP_DCDC1_VOLT);
+ power_failed |= axp_set_dcdc2(CONFIG_AXP_DCDC2_VOLT);
+ power_failed |= axp_set_dcdc3(CONFIG_AXP_DCDC3_VOLT);
+ power_failed |= axp_set_dcdc4(CONFIG_AXP_DCDC4_VOLT);
+ power_failed |= axp_set_dcdc5(CONFIG_AXP_DCDC5_VOLT);
+ power_failed |= axp_set_dcdc6(CONFIG_AXP_DCDC6_VOLT);
+
+ power_failed |= axp_set_aldo1(CONFIG_AXP_ALDO1_VOLT);
+ power_failed |= axp_set_aldo2(CONFIG_AXP_ALDO2_VOLT);
+ power_failed |= axp_set_aldo3(CONFIG_AXP_ALDO3_VOLT);
+
+ power_failed |= axp_set_dldo(1, CONFIG_AXP_DLDO1_VOLT);
+ power_failed |= axp_set_dldo(2, CONFIG_AXP_DLDO2_VOLT);
+ power_failed |= axp_set_dldo(3, CONFIG_AXP_DLDO3_VOLT);
+ power_failed |= axp_set_dldo(4, CONFIG_AXP_DLDO4_VOLT);
+
+ power_failed |= axp_set_eldo(1, CONFIG_AXP_ELDO1_VOLT);
+ power_failed |= axp_set_eldo(2, CONFIG_AXP_ELDO2_VOLT);
+ power_failed |= axp_set_eldo(3, CONFIG_AXP_ELDO3_VOLT);
+
+ power_failed |= axp_set_fldo(1, CONFIG_AXP_FLDO1_VOLT);
+ power_failed |= axp_set_fldo(2, CONFIG_AXP_FLDO2_VOLT);
+
+ return power_failed;
+}
+#endif
+
/* add board specific code here */
int board_init(void)
{
@@ -209,6 +243,12 @@ int board_init(void)
}
#endif /* !CONFIG_ARM64 */
+#ifdef CONFIG_AXP803_POWER
+ ret = axp803_init();
+ if (ret)
+ return ret;
+#endif
+
ret = axp_gpio_init();
if (ret)
return ret;
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index d8c107e..6c1e4ff 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -11,8 +11,9 @@ choice
depends on ARCH_SUNXI
default AXP209_POWER if MACH_SUN4I || MACH_SUN5I || MACH_SUN7I
default AXP221_POWER if MACH_SUN6I || MACH_SUN8I_A23 || MACH_SUN8I_A33 || MACH_SUN8I_R40
+ default AXP803_POWER if MACH_SUN50I
default AXP818_POWER if MACH_SUN8I_A83T
- default SUNXI_NO_PMIC if MACH_SUNXI_H3_H5 || MACH_SUN50I
+ default SUNXI_NO_PMIC if MACH_SUNXI_H3_H5
config SUNXI_NO_PMIC
bool "board without a pmic"
@@ -43,6 +44,13 @@ config AXP221_POWER
Select this to enable support for the axp221/axp223 pmic found on most
A23 and A31 boards.
+config AXP803_POWER
+ bool "axp803 pmic support"
+ depends on MACH_SUN50I
+ select CMD_POWEROFF
+ ---help---
+ Say y here to enable support for the axp803 pmic found on A64 boards.
+
config AXP809_POWER
bool "axp809 pmic support"
depends on MACH_SUN9I
@@ -69,8 +77,8 @@ endchoice
config AXP_DCDC1_VOLT
int "axp pmic dcdc1 voltage"
- depends on AXP221_POWER || AXP809_POWER || AXP818_POWER
- default 3300 if AXP818_POWER || MACH_SUN8I_R40
+ depends on AXP221_POWER || AXP803_POWER || AXP809_POWER || AXP818_POWER
+ default 3300 if AXP818_POWER || MACH_SUN8I_R40 || MACH_SUN50I
default 3000 if MACH_SUN6I || MACH_SUN8I || MACH_SUN9I
---help---
Set the voltage (mV) to program the axp pmic dcdc1 at, set to 0 to
@@ -80,14 +88,15 @@ config AXP_DCDC1_VOLT
save battery. On A31 devices dcdc1 is also used for VCC-IO. On A83T
dcdc1 is used for VCC-IO, nand, usb0, sd , etc. On A80 dcdc1 normally
powers some of the pingroups, NAND/eMMC, SD/MMC, and USB OTG.
+ On A64 boards dcdc1 is used for Nand/eMMC/SDMMC/WIFI-IO and should be 3.3V.
config AXP_DCDC2_VOLT
int "axp pmic dcdc2 voltage"
- depends on AXP152_POWER || AXP209_POWER || AXP221_POWER || AXP809_POWER || AXP818_POWER
+ depends on AXP152_POWER || AXP209_POWER || AXP221_POWER || AXP803_POWER || AXP809_POWER || AXP818_POWER
default 900 if AXP818_POWER
default 1400 if AXP152_POWER || AXP209_POWER
default 1200 if MACH_SUN6I
- default 1100 if MACH_SUN8I
+ default 1100 if MACH_SUN8I || MACH_SUN50I
default 0 if MACH_SUN9I
---help---
Set the voltage (mV) to program the axp pmic dcdc2 at, set to 0 to
@@ -98,14 +107,15 @@ config AXP_DCDC2_VOLT
On A80 boards dcdc2 powers the GPU and can be left off.
On A83T boards dcdc2 is used for VDD-CPUA(cluster 0) and should be 0.9V.
On R40 boards dcdc2 is VDD-CPU and should be 1.1V
+ On A64 boards dcdc2 is used for VDD-CPUX and should be 1.1V.
config AXP_DCDC3_VOLT
int "axp pmic dcdc3 voltage"
- depends on AXP152_POWER || AXP209_POWER || AXP221_POWER || AXP809_POWER || AXP818_POWER
+ depends on AXP152_POWER || AXP209_POWER || AXP221_POWER || AXP803_POWER || AXP809_POWER || AXP818_POWER
default 900 if AXP809_POWER || AXP818_POWER
default 1500 if AXP152_POWER
default 1250 if AXP209_POWER
- default 1100 if MACH_SUN8I_R40
+ default 1100 if MACH_SUN8I_R40 || MACH_SUN50I
default 1200 if MACH_SUN6I || MACH_SUN8I
---help---
Set the voltage (mV) to program the axp pmic dcdc3 at, set to 0 to
@@ -117,13 +127,14 @@ config AXP_DCDC3_VOLT
On A80 boards dcdc3 is used for VDD-CPUA(cluster 0) and should be 0.9V.
On A83T boards dcdc3 is used for VDD-CPUB(cluster 1) and should be 0.9V.
On R40 boards dcdc3 is VDD-SYS and VDD-GPU and should be 1.1V.
+ On A64 boards dcdc2 is used for VDD-CPUX and should be 1.1V.
config AXP_DCDC4_VOLT
int "axp pmic dcdc4 voltage"
- depends on AXP152_POWER || AXP221_POWER || AXP809_POWER || AXP818_POWER
+ depends on AXP152_POWER || AXP221_POWER || AXP803_POWER || AXP809_POWER || AXP818_POWER
default 1250 if AXP152_POWER
default 1200 if MACH_SUN6I
- default 0 if MACH_SUN8I
+ default 0 if MACH_SUN8I || MACH_SUN50I
default 900 if MACH_SUN9I
---help---
Set the voltage (mV) to program the axp pmic dcdc4 at, set to 0 to
@@ -133,21 +144,31 @@ config AXP_DCDC4_VOLT
On A23 / A33 boards dcdc4 is unused and should be disabled.
On A80 boards dcdc4 powers VDD-SYS, HDMI, USB OTG and should be 0.9V.
On A83T boards dcdc4 is used for VDD-GPU.
+ On A64 boards dcdc4 is unused and should be disabled.
config AXP_DCDC5_VOLT
int "axp pmic dcdc5 voltage"
- depends on AXP221_POWER || AXP809_POWER || AXP818_POWER
- default 1500 if MACH_SUN6I || MACH_SUN8I || MACH_SUN9I
+ depends on AXP221_POWER || AXP803_POWER || AXP809_POWER || AXP818_POWER
+ default 1500 if MACH_SUN6I || MACH_SUN8I || MACH_SUN9I || MACH_SUN50I
---help---
Set the voltage (mV) to program the axp pmic dcdc5 at, set to 0 to
disable dcdc5.
- On A23 / A31 / A33 / A80 / A83T / R40 boards dcdc5 is VCC-DRAM and
+ On A23 / A31 / A33 / A80 / A83T / R40 / A64 boards dcdc5 is VCC-DRAM and
should be 1.5V, 1.35V if DDR3L is used.
+config AXP_DCDC6_VOLT
+ int "axp pmic dcdc6 voltage"
+ depends on AXP803_POWER
+ default 1100 if MACH_SUN50I
+ ---help---
+ Set the voltage (mV) to program the axp pmic dcdc6 at, set to 0 to
+ disable dcdc6.
+ On A64 boards dcdc6 is VDD-SYS and should be 1.1V.
+
config AXP_ALDO1_VOLT
int "axp pmic (a)ldo1 voltage"
- depends on AXP221_POWER || AXP809_POWER || AXP818_POWER
- default 0 if MACH_SUN6I || MACH_SUN8I_R40
+ depends on AXP221_POWER || AXP803_POWER || AXP809_POWER || AXP818_POWER
+ default 0 if MACH_SUN6I || MACH_SUN8I_R40 || MACH_SUN50I
default 1800 if MACH_SUN8I_A83T
default 3000 if MACH_SUN8I || MACH_SUN9I
---help---
@@ -158,13 +179,14 @@ config AXP_ALDO1_VOLT
On A80 boards aldo1 powers the USB hosts and should be 3.0V.
On A83T / H8 boards aldo1 is used for MIPI CSI, DSI, HDMI, EFUSE, and
should be 1.8V.
+ On A64 boards aldo1 is unused and should be disabled.
config AXP_ALDO2_VOLT
int "axp pmic (a)ldo2 voltage"
- depends on AXP152_POWER || AXP209_POWER || AXP221_POWER || AXP809_POWER || AXP818_POWER
+ depends on AXP152_POWER || AXP209_POWER || AXP221_POWER || AXP803_POWER || AXP809_POWER || AXP818_POWER
default 3000 if AXP152_POWER || AXP209_POWER
default 0 if MACH_SUN6I || MACH_SUN9I
- default 1800 if MACH_SUN8I_A83T
+ default 1800 if MACH_SUN8I_A83T || MACH_SUN50I
default 2500 if MACH_SUN8I
---help---
Set the voltage (mV) to program the axp pmic aldo2 at, set to 0 to
@@ -176,12 +198,13 @@ config AXP_ALDO2_VOLT
On A80 boards aldo2 powers PB pingroup and camera IO and can be left off.
On A83T / H8 boards aldo2 powers VDD-DLL, VCC18-PLL, CPVDD, VDD18-ADC,
LPDDR2, and the codec. It should be 1.8V.
+ On A64 boards aldo2 may be used for VCC-PL then it should be 1.8V.
config AXP_ALDO3_VOLT
int "axp pmic (a)ldo3 voltage"
- depends on AXP209_POWER || AXP221_POWER || AXP809_POWER || AXP818_POWER
+ depends on AXP209_POWER || AXP221_POWER || AXP803_POWER || AXP809_POWER || AXP818_POWER
default 0 if AXP209_POWER || MACH_SUN9I
- default 3000 if MACH_SUN6I || MACH_SUN8I
+ default 3000 if MACH_SUN6I || MACH_SUN8I || MACH_SUN50I
---help---
Set the voltage (mV) to program the axp pmic aldo3 at, set to 0 to
disable aldo3.
@@ -189,7 +212,7 @@ config AXP_ALDO3_VOLT
On A23 / A31 / A33 / R40 boards aldo3 is VCC-PLL and AVCC and should
be 3.0V.
On A80 boards aldo3 is normally not used.
- On A83T / H8 boards aldo3 is AVCC, VCC-PL, and VCC-LED, and should be
+ On A83T / H8 / A64 boards aldo3 is AVCC, VCC-PL, and VCC-LED, and should be
3.0V.
config AXP_ALDO4_VOLT
@@ -203,59 +226,71 @@ config AXP_ALDO4_VOLT
config AXP_DLDO1_VOLT
int "axp pmic dldo1 voltage"
- depends on AXP221_POWER || AXP809_POWER || AXP818_POWER
+ depends on AXP221_POWER || AXP803_POWER || AXP809_POWER || AXP818_POWER
+ default 3300 if MACH_SUN50I
default 0
---help---
Set the voltage (mV) to program the axp pmic dldo1 at, set to 0 to
disable dldo1. On sun6i (A31) boards with ethernet dldo1 is often used
to power the ethernet phy. On A23, A33 and A80 boards this is often
used to power the wifi.
+ On A64 boards dldo1 powers the HDMI, DSI, SENSOR pins and should be 3.3V.
config AXP_DLDO2_VOLT
int "axp pmic dldo2 voltage"
- depends on AXP221_POWER || AXP809_POWER || AXP818_POWER
+ depends on AXP221_POWER || AXP803_POWER || AXP809_POWER || AXP818_POWER
default 3000 if MACH_SUN9I
+ default 3300 if MACH_SUN50I
default 0
---help---
Set the voltage (mV) to program the axp pmic dldo2 at, set to 0 to
disable dldo2.
On A80 boards dldo2 normally powers the PL pins and should be 3.0V.
+ On A64 boards dldo2 normally powers the MIPI pins and should be 3.3V.
config AXP_DLDO3_VOLT
int "axp pmic dldo3 voltage"
- depends on AXP221_POWER || AXP818_POWER
+ depends on AXP221_POWER || AXP803_POWER || AXP818_POWER
+ default 2800 if MACH_SUN50I
default 0
---help---
Set the voltage (mV) to program the axp pmic dldo3 at, set to 0 to
disable dldo3.
+ On A64 boards dldo3 normally powers the AVDD-CSI pins and should be 2.8V.
config AXP_DLDO4_VOLT
int "axp pmic dldo4 voltage"
- depends on AXP221_POWER || AXP818_POWER
+ depends on AXP221_POWER || AXP803_POWER || AXP818_POWER
+ default 3300 if MACH_SUN50I
default 0
---help---
Set the voltage (mV) to program the axp pmic dldo4 at, set to 0 to
disable dldo4.
+ On A64 boards dldo4 normally powers the WIFI-IO pins and should be 3.3V.
config AXP_ELDO1_VOLT
int "axp pmic eldo1 voltage"
- depends on AXP221_POWER || AXP809_POWER || AXP818_POWER
+ depends on AXP221_POWER || AXP803_POWER || AXP809_POWER || AXP818_POWER
+ default 1800 if MACH_SUN50I
default 0
---help---
Set the voltage (mV) to program the axp pmic eldo1 at, set to 0 to
disable eldo1.
+ On A64 boards eldo1 normally powers the CPVDD pins and should be 1.8V.
config AXP_ELDO2_VOLT
int "axp pmic eldo2 voltage"
- depends on AXP221_POWER || AXP809_POWER || AXP818_POWER
+ depends on AXP221_POWER || AXP803_POWER || AXP809_POWER || AXP818_POWER
+ default 1800 if MACH_SUN50I
default 0
---help---
Set the voltage (mV) to program the axp pmic eldo2 at, set to 0 to
disable eldo2.
+ On A64 boards eldo2 normally powers the VCC-DVDD-CSI pins and should be 1.8V.
config AXP_ELDO3_VOLT
int "axp pmic eldo3 voltage"
- depends on AXP221_POWER || AXP809_POWER || AXP818_POWER
+ depends on AXP221_POWER || AXP803_POWER || AXP809_POWER || AXP818_POWER
default 3000 if MACH_SUN9I
default 0
---help---
@@ -267,22 +302,26 @@ config AXP_ELDO3_VOLT
config AXP_FLDO1_VOLT
int "axp pmic fldo1 voltage"
- depends on AXP818_POWER
+ depends on AXP803_POWER || AXP818_POWER
default 0 if MACH_SUN8I_A83T
+ default 1200 if MACH_SUN50I
---help---
Set the voltage (mV) to program the axp pmic fldo1 at, set to 0 to
disable fldo1.
On A83T / H8 boards fldo1 is VCC-HSIC and should be 1.2V if HSIC is
used.
+ On A64 boards fldo1 normally powers the HSCI pins and should be 1.2V.
config AXP_FLDO2_VOLT
int "axp pmic fldo2 voltage"
- depends on AXP818_POWER
+ depends on AXP803_POWER || AXP818_POWER
default 900 if MACH_SUN8I_A83T
+ default 1100 if MACH_SUN50I
---help---
Set the voltage (mV) to program the axp pmic fldo2 at, set to 0 to
disable fldo2.
On A83T / H8 boards fldo2 is VCC-CPUS and should be 0.9V.
+ On A64 boards fldo1 normally powers the VDD-CPUS pins and should be 1.1V.
config AXP_FLDO3_VOLT
int "axp pmic fldo3 voltage"
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 90a3b00..20cabaa 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -9,6 +9,9 @@ obj-$(CONFIG_AXP152_POWER) += axp152.o
obj-$(CONFIG_AXP209_POWER) += axp209.o
obj-$(CONFIG_AXP221_POWER) += axp221.o
obj-$(CONFIG_AXP809_POWER) += axp809.o
+ifndef CONFIG_SPL_BUILD
+obj-$(CONFIG_AXP803_POWER) += axp803.o
+endif
obj-$(CONFIG_AXP818_POWER) += axp818.o
obj-$(CONFIG_EXYNOS_TMU) += exynos-tmu.o
obj-$(CONFIG_FTPMU010_POWER) += ftpmu010.o
diff --git a/drivers/power/axp803.c b/drivers/power/axp803.c
new file mode 100644
index 0000000..0f43917
--- /dev/null
+++ b/drivers/power/axp803.c
@@ -0,0 +1,260 @@
+/*
+ * AXP803 driver based on AXP809 driver
+ * (C) Copyright 2017 Jagan Teki <jagan at amarulasolutions.com>
+ *
+ * Based on axp809.c
+ * (C) Copyright 2016 Chen-Yu Tsai <wens at csie.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/pmic_bus.h>
+#include <axp_pmic.h>
+
+static u8 axp803_mvolt_to_cfg(int mvolt, int min, int max, int div)
+{
+ if (mvolt < min)
+ mvolt = min;
+ else if (mvolt > max)
+ mvolt = max;
+
+ return (mvolt - min) / div;
+}
+
+int axp_set_dcdc1(unsigned int mvolt)
+{
+ int ret;
+ u8 cfg = axp803_mvolt_to_cfg(mvolt, 1600, 3400, 100);
+
+ if (mvolt >= 1200)
+ cfg = 0x47 + axp803_mvolt_to_cfg(mvolt, 1220, 1300, 20);
+
+ if (mvolt == 0)
+ return pmic_bus_clrbits(AXP803_OUTPUT_CTRL1,
+ AXP803_OUTPUT_CTRL1_DCDC1_EN);
+
+ ret = pmic_bus_write(AXP803_DCDC1_CTRL, cfg);
+ if (ret)
+ return ret;
+
+ ret = pmic_bus_setbits(AXP803_OUTPUT_CTRL2,
+ AXP803_OUTPUT_CTRL2_DC1SW_EN);
+ if (ret)
+ return ret;
+
+ return pmic_bus_setbits(AXP803_OUTPUT_CTRL1,
+ AXP803_OUTPUT_CTRL1_DCDC1_EN);
+}
+
+int axp_set_dcdc2(unsigned int mvolt)
+{
+ int ret;
+ u8 cfg = axp803_mvolt_to_cfg(mvolt, 500, 1200, 10);
+
+ if (mvolt >= 1200)
+ cfg = 0x47 + axp803_mvolt_to_cfg(mvolt, 1220, 1300, 20);
+
+ if (mvolt == 0)
+ return pmic_bus_clrbits(AXP803_OUTPUT_CTRL1,
+ AXP803_OUTPUT_CTRL1_DCDC2_EN);
+
+ ret = pmic_bus_write(AXP803_DCDC2_CTRL, cfg);
+ if (ret)
+ return ret;
+
+ return pmic_bus_setbits(AXP803_OUTPUT_CTRL1,
+ AXP803_OUTPUT_CTRL1_DCDC2_EN);
+}
+
+int axp_set_dcdc3(unsigned int mvolt)
+{
+ int ret;
+ u8 cfg = axp803_mvolt_to_cfg(mvolt, 500, 1200, 10);
+
+ if (mvolt >= 1200)
+ cfg = 0x47 + axp803_mvolt_to_cfg(mvolt, 1220, 1300, 20);
+
+ if (mvolt == 0)
+ return pmic_bus_clrbits(AXP803_OUTPUT_CTRL1,
+ AXP803_OUTPUT_CTRL1_DCDC3_EN);
+
+ ret = pmic_bus_write(AXP803_DCDC3_CTRL, cfg);
+ if (ret)
+ return ret;
+
+ return pmic_bus_setbits(AXP803_OUTPUT_CTRL1,
+ AXP803_OUTPUT_CTRL1_DCDC3_EN);
+}
+
+int axp_set_dcdc4(unsigned int mvolt)
+{
+ int ret;
+ u8 cfg = axp803_mvolt_to_cfg(mvolt, 500, 1200, 10);
+
+ if (mvolt >= 1200)
+ cfg = 0x47 + axp803_mvolt_to_cfg(mvolt, 1220, 1300, 20);
+
+ if (mvolt == 0)
+ return pmic_bus_clrbits(AXP803_OUTPUT_CTRL1,
+ AXP803_OUTPUT_CTRL1_DCDC4_EN);
+
+ ret = pmic_bus_write(AXP803_DCDC5_CTRL, cfg);
+ if (ret)
+ return ret;
+
+ return pmic_bus_setbits(AXP803_OUTPUT_CTRL1,
+ AXP803_OUTPUT_CTRL1_DCDC4_EN);
+}
+
+int axp_set_dcdc5(unsigned int mvolt)
+{
+ int ret;
+ u8 cfg = axp803_mvolt_to_cfg(mvolt, 800, 1220, 10);
+
+ if (mvolt >= 1220)
+ cfg = 0x21 + axp803_mvolt_to_cfg(mvolt, 1140, 1840, 20);
+
+ if (mvolt == 0)
+ return pmic_bus_clrbits(AXP803_OUTPUT_CTRL1,
+ AXP803_OUTPUT_CTRL1_DCDC5_EN);
+
+ ret = pmic_bus_write(AXP803_DCDC5_CTRL, cfg);
+ if (ret)
+ return ret;
+
+ return pmic_bus_setbits(AXP803_OUTPUT_CTRL1,
+ AXP803_OUTPUT_CTRL1_DCDC5_EN);
+}
+
+int axp_set_dcdc6(unsigned int mvolt)
+{
+ int ret;
+ u8 cfg = axp803_mvolt_to_cfg(mvolt, 600, 1100, 10);
+
+ if (mvolt >= 1100)
+ cfg = 0x33 + axp803_mvolt_to_cfg(mvolt, 1120, 1520, 20);
+
+ if (mvolt == 0)
+ return pmic_bus_clrbits(AXP803_OUTPUT_CTRL1,
+ AXP803_OUTPUT_CTRL1_DCDC6_EN);
+
+ ret = pmic_bus_write(AXP803_DCDC6_CTRL, cfg);
+ if (ret)
+ return ret;
+
+ return pmic_bus_setbits(AXP803_OUTPUT_CTRL1,
+ AXP803_OUTPUT_CTRL1_DCDC6_EN);
+}
+
+int axp_set_aldo(int aldo_num, unsigned int mvolt)
+{
+ int ret;
+ u8 cfg;
+
+ if (aldo_num < 1 || aldo_num > 3)
+ return -EINVAL;
+
+ if (mvolt == 0 && aldo_num == 3)
+ return pmic_bus_clrbits(AXP803_OUTPUT_CTRL3,
+ AXP803_OUTPUT_CTRL3_ALDO3_EN);
+ if (mvolt == 0)
+ return pmic_bus_clrbits(AXP803_OUTPUT_CTRL3,
+ AXP803_OUTPUT_CTRL3_ALDO1_EN << (aldo_num - 1));
+
+ cfg = axp803_mvolt_to_cfg(mvolt, 700, 3300, 100);
+ ret = pmic_bus_write(AXP803_ALDO1_CTRL + (aldo_num - 1), cfg);
+ if (ret)
+ return ret;
+
+ if (aldo_num == 3)
+ return pmic_bus_setbits(AXP803_OUTPUT_CTRL3,
+ AXP803_OUTPUT_CTRL3_ALDO3_EN);
+ return pmic_bus_setbits(AXP803_OUTPUT_CTRL3,
+ AXP803_OUTPUT_CTRL3_ALDO1_EN << (aldo_num - 1));
+}
+
+/* TODO: re-work other AXP drivers to consolidate ALDO functions. */
+int axp_set_aldo1(unsigned int mvolt)
+{
+ return axp_set_aldo(1, mvolt);
+}
+
+int axp_set_aldo2(unsigned int mvolt)
+{
+ return axp_set_aldo(2, mvolt);
+}
+
+int axp_set_aldo3(unsigned int mvolt)
+{
+ return axp_set_aldo(3, mvolt);
+}
+
+int axp_set_dldo(int dldo_num, unsigned int mvolt)
+{
+ u8 cfg = axp803_mvolt_to_cfg(mvolt, 700, 3300, 100);
+ int ret;
+
+ if (dldo_num < 1 || dldo_num > 4)
+ return -EINVAL;
+
+ if (mvolt == 0)
+ return pmic_bus_clrbits(AXP803_OUTPUT_CTRL2,
+ AXP803_OUTPUT_CTRL2_DLDO1_EN << (dldo_num - 1));
+
+ if (dldo_num == 2 && mvolt > 3300)
+ cfg += 1 + axp803_mvolt_to_cfg(mvolt, 3400, 4200, 200);
+ ret = pmic_bus_write(AXP803_DLDO1_CTRL + (dldo_num - 1), cfg);
+ if (ret)
+ return ret;
+
+ return pmic_bus_setbits(AXP803_OUTPUT_CTRL2,
+ AXP803_OUTPUT_CTRL2_DLDO1_EN << (dldo_num - 1));
+}
+
+int axp_set_eldo(int eldo_num, unsigned int mvolt)
+{
+ int ret;
+ u8 cfg = axp803_mvolt_to_cfg(mvolt, 700, 1900, 50);
+
+ if (eldo_num < 1 || eldo_num > 3)
+ return -EINVAL;
+
+ if (mvolt == 0)
+ return pmic_bus_clrbits(AXP803_OUTPUT_CTRL2,
+ AXP803_OUTPUT_CTRL2_ELDO1_EN << (eldo_num - 1));
+
+ ret = pmic_bus_write(AXP803_ELDO1_CTRL + (eldo_num - 1), cfg);
+ if (ret)
+ return ret;
+
+ return pmic_bus_setbits(AXP803_OUTPUT_CTRL2,
+ AXP803_OUTPUT_CTRL2_ELDO1_EN << (eldo_num - 1));
+}
+
+int axp_set_fldo(int fldo_num, unsigned int mvolt)
+{
+ int ret;
+ u8 cfg = axp803_mvolt_to_cfg(mvolt, 700, 1450, 50);
+
+ if (fldo_num < 1 || fldo_num > 2)
+ return -EINVAL;
+
+ if (mvolt == 0)
+ return pmic_bus_clrbits(AXP803_OUTPUT_CTRL3,
+ AXP803_OUTPUT_CTRL3_FLDO1_EN << (fldo_num - 1));
+
+ ret = pmic_bus_write(AXP803_FLDO1_CTRL + (fldo_num - 1), cfg);
+ if (ret)
+ return ret;
+
+ return pmic_bus_setbits(AXP803_OUTPUT_CTRL3,
+ AXP803_OUTPUT_CTRL3_FLDO1_EN << (fldo_num - 1));
+}
+
+int axp_init(void)
+{
+ return pmic_bus_init();
+}
diff --git a/include/axp803.h b/include/axp803.h
new file mode 100644
index 0000000..c69e207
--- /dev/null
+++ b/include/axp803.h
@@ -0,0 +1,68 @@
+/*
+ * (C) Copyright 2017 Jagan Teki <jagan at amarulasolutions.com>
+ *
+ * X-Powers AXP803 Power Management IC driver
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#define AXP809_CHIP_ID 0x03
+
+#define AXP803_OUTPUT_CTRL1 0x10
+#define AXP803_OUTPUT_CTRL1_DCDC1_EN (1 << 0)
+#define AXP803_OUTPUT_CTRL1_DCDC2_EN (1 << 1)
+#define AXP803_OUTPUT_CTRL1_DCDC3_EN (1 << 2)
+#define AXP803_OUTPUT_CTRL1_DCDC4_EN (1 << 3)
+#define AXP803_OUTPUT_CTRL1_DCDC5_EN (1 << 4)
+#define AXP803_OUTPUT_CTRL1_DCDC6_EN (1 << 5)
+#define AXP803_OUTPUT_CTRL2 0x12
+#define AXP803_OUTPUT_CTRL2_ELDO1_EN (1 << 0)
+#define AXP803_OUTPUT_CTRL2_ELDO2_EN (1 << 1)
+#define AXP803_OUTPUT_CTRL2_ELDO3_EN (1 << 2)
+#define AXP803_OUTPUT_CTRL2_DLDO1_EN (1 << 3)
+#define AXP803_OUTPUT_CTRL2_DLDO2_EN (1 << 4)
+#define AXP803_OUTPUT_CTRL2_DLDO3_EN (1 << 5)
+#define AXP803_OUTPUT_CTRL2_DLDO4_EN (1 << 6)
+#define AXP803_OUTPUT_CTRL2_DC1SW_EN (1 << 7)
+#define AXP803_OUTPUT_CTRL3 0x13
+#define AXP803_OUTPUT_CTRL3_FLDO1_EN (1 << 2)
+#define AXP803_OUTPUT_CTRL3_FLDO2_EN (1 << 3)
+#define AXP803_OUTPUT_CTRL3_ALDO1_EN (1 << 5)
+#define AXP803_OUTPUT_CTRL3_ALDO2_EN (1 << 6)
+#define AXP803_OUTPUT_CTRL3_ALDO3_EN (1 << 7)
+
+#define AXP803_DLDO1_CTRL 0x15
+#define AXP803_DLDO2_CTRL 0x16
+#define AXP803_DLDO3_CTRL 0x17
+#define AXP803_DLDO4_CTRL 0x18
+#define AXP803_ELDO1_CTRL 0x19
+#define AXP803_ELDO2_CTRL 0x1a
+#define AXP803_ELDO3_CTRL 0x1b
+#define AXP803_FLDO1_CTRL 0x1c
+#define AXP803_FLDO2_CTRL 0x1d
+#define AXP803_DCDC1_CTRL 0x20
+#define AXP803_DCDC2_CTRL 0x21
+#define AXP803_DCDC3_CTRL 0x22
+#define AXP803_DCDC4_CTRL 0x23
+#define AXP803_DCDC5_CTRL 0x24
+#define AXP803_DCDC6_CTRL 0x25
+#define AXP803_ALDO1_CTRL 0x28
+#define AXP803_ALDO2_CTRL 0x29
+#define AXP803_ALDO3_CTRL 0x2a
+#define AXP803_SHUTDOWN 0x32
+#define AXP803_SHUTDOWN_POWEROFF (1 << 7)
+
+/* For axp_gpio.c */
+#define AXP_POWER_STATUS 0x00
+#define AXP_POWER_STATUS_VBUS_PRESENT (1 << 5)
+#define AXP_VBUS_IPSOUT 0x30
+#define AXP_VBUS_IPSOUT_DRIVEBUS (1 << 2)
+#define AXP_MISC_CTRL 0x8f
+#define AXP_MISC_CTRL_N_VBUSEN_FUNC (1 << 4)
+#define AXP_GPIO0_CTRL 0x90
+#define AXP_GPIO1_CTRL 0x92
+#define AXP_GPIO_CTRL_OUTPUT_LOW 0x00 /* Drive pin low */
+#define AXP_GPIO_CTRL_OUTPUT_HIGH 0x01 /* Drive pin high */
+#define AXP_GPIO_CTRL_INPUT 0x02 /* Input */
+#define AXP_GPIO_STATE 0x94
+#define AXP_GPIO_STATE_OFFSET 0
diff --git a/include/axp_pmic.h b/include/axp_pmic.h
index d789ad8..7c17de9 100644
--- a/include/axp_pmic.h
+++ b/include/axp_pmic.h
@@ -16,6 +16,9 @@
#ifdef CONFIG_AXP221_POWER
#include <axp221.h>
#endif
+#ifdef CONFIG_AXP803_POWER
+#include <axp803.h>
+#endif
#ifdef CONFIG_AXP809_POWER
#include <axp809.h>
#endif
@@ -28,6 +31,7 @@ int axp_set_dcdc2(unsigned int mvolt);
int axp_set_dcdc3(unsigned int mvolt);
int axp_set_dcdc4(unsigned int mvolt);
int axp_set_dcdc5(unsigned int mvolt);
+int axp_set_dcdc6(unsigned int mvolt);
int axp_set_aldo1(unsigned int mvolt);
int axp_set_aldo2(unsigned int mvolt);
int axp_set_aldo3(unsigned int mvolt);
--
2.7.4
More information about the U-Boot
mailing list