Skip to content

Instantly share code, notes, and snippets.

@jelly
Created February 5, 2016 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jelly/baf3696e09368d11f3fc to your computer and use it in GitHub Desktop.
Save jelly/baf3696e09368d11f3fc to your computer and use it in GitHub Desktop.
SY8106A
SY8106A is a PMIC which is used on the Allwinner
H3 Orange Pi Pc board. The VOUT1_SEL register is
implemented to set thea default V-CPU voltage to 1200 mV.
Signed-off-by: Jelle van der Waa <jelle@vdwaa.nl>
---
arch/arm/cpu/armv7/sunxi/Makefile | 1 +
board/sunxi/board.c | 6 ++++++
configs/orangepi_pc_defconfig | 1 +
drivers/power/Kconfig | 19 ++++++++++++++++++-
drivers/power/Makefile | 1 +
drivers/power/sy8106a.c | 22 ++++++++++++++++++++++
include/configs/sunxi-common.h | 6 ++++--
include/sy8106a.h | 5 +++++
8 files changed, 58 insertions(+), 3 deletions(-)
create mode 100644 drivers/power/sy8106a.c
create mode 100644 include/sy8106a.h
diff --git a/arch/arm/cpu/armv7/sunxi/Makefile b/arch/arm/cpu/armv7/sunxi/Makefile
index dfb0a3e..dafbb89 100644
--- a/arch/arm/cpu/armv7/sunxi/Makefile
+++ b/arch/arm/cpu/armv7/sunxi/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_AXP152_POWER) += pmic_bus.o
obj-$(CONFIG_AXP209_POWER) += pmic_bus.o
obj-$(CONFIG_AXP221_POWER) += pmic_bus.o
obj-$(CONFIG_AXP818_POWER) += pmic_bus.o
+obj-$(CONFIG_SY8106A_POWER) += pmic_bus.o
ifndef CONFIG_SPL_BUILD
ifdef CONFIG_ARMV7_PSCI
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 1cc39e4..f26fc6d 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -25,6 +25,8 @@
#include <asm/io.h>
#include <nand.h>
#include <net.h>
+#include <i2c.h>
+#include <sy8106a.h>
#if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
/* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */
@@ -430,11 +432,15 @@ void i2c_init_board(void)
#endif
}
+
#ifdef CONFIG_SPL_BUILD
void sunxi_board_init(void)
{
int power_failed = 0;
unsigned long ramsize;
+#ifdef CONFIG_SY8106A_POWER
+ power_failed = sy8106a_set_vout1(CONFIG_SY8106A_VOUT1_VOLT);
+#endif
#if defined CONFIG_AXP152_POWER || defined CONFIG_AXP209_POWER || \
defined CONFIG_AXP221_POWER || defined CONFIG_AXP818_POWER
diff --git a/configs/orangepi_pc_defconfig b/configs/orangepi_pc_defconfig
index ea9ed87..0bd1d6f 100644
--- a/configs/orangepi_pc_defconfig
+++ b/configs/orangepi_pc_defconfig
@@ -13,3 +13,4 @@ CONFIG_SPL=y
# CONFIG_CMD_FPGA is not set
CONFIG_CMD_GPIO=y
CONFIG_R_I2C_ENABLE=y
+CONFIG_SY8106A_POWER=y
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index e86dd72..9e1d7b6 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -10,7 +10,7 @@ choice
default AXP209_POWER if MACH_SUN4I || MACH_SUN5I || MACH_SUN7I
default AXP221_POWER if MACH_SUN6I || MACH_SUN8I_A23 || MACH_SUN8I_A33
default AXP818_POWER if MACH_SUN8I_A83T
- default SUNXI_NO_PMIC if MACH_SUN8I_H3
+ default SY8106A_POWER if MACH_SUN8I_H3
config SUNXI_NO_PMIC
boolean "board without a pmic"
@@ -45,6 +45,14 @@ config AXP818_POWER
Say y here to enable support for the axp818 pmic found on
A83T dev board.
+config SY8106A_POWER
+ boolean "SY8106A pmic support"
+ depends on MACH_SUN8I
+ default 0
+ ---help---
+ Select this to enable support for the SY8106A pmic found on most
+ H3 boards.
+
endchoice
config AXP_DCDC1_VOLT
@@ -222,4 +230,13 @@ config AXP_ELDO3_VOLT
1.2V for the SSD2828 chip (converter of parallel LCD interface
into MIPI DSI).
+config SY8106A_VOUT1_VOLT
+ int "SY8106A pmic VOUT1 voltage"
+ depends on SY8106A_POWER
+ default 1200
+ ---help---
+ Set the voltage (mV) to program the SY8106A pmic VOUT1. This
+ is typically used to power the VDD-CPU and should be 1200mV.
+ Values can range from 680mV till 1950mV.
+
endmenu
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 0fdbca3..7385bcd 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -21,3 +21,4 @@ obj-$(CONFIG_DIALOG_POWER) += power_dialog.o
obj-$(CONFIG_POWER_FSL) += power_fsl.o
obj-$(CONFIG_POWER_I2C) += power_i2c.o
obj-$(CONFIG_POWER_SPI) += power_spi.o
+obj-$(CONFIG_SY8106A_POWER) += sy8106a.o
diff --git a/drivers/power/sy8106a.c b/drivers/power/sy8106a.c
new file mode 100644
index 0000000..fb6ee7c
--- /dev/null
+++ b/drivers/power/sy8106a.c
@@ -0,0 +1,22 @@
+#include <common.h>
+#include <i2c.h>
+
+#define SY8106A_I2C_ADDR 0x65
+#define SY8106A_VOUT1_SEL 1
+#define SY8106A_VOUT1_SEL_ENABLE (1 << 7)
+
+static u8 sy8106a_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 sy8106a_set_vout1(unsigned int mvolt)
+{
+ u8 data = sy8106a_mvolt_to_cfg(mvolt, 680, 1950, 10) | SY8106A_VOUT1_SEL_ENABLE;
+ return i2c_write(SY8106A_I2C_ADDR, SY8106A_VOUT1_SEL, 1, &data, 1);
+}
diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
index b4dfb3c..40850e5 100644
--- a/include/configs/sunxi-common.h
+++ b/include/configs/sunxi-common.h
@@ -206,7 +206,8 @@
#define CONFIG_SPL_STACK LOW_LEVEL_SRAM_STACK
/* I2C */
-#if defined CONFIG_AXP152_POWER || defined CONFIG_AXP209_POWER
+#if defined CONFIG_AXP152_POWER || defined CONFIG_AXP209_POWER || \
+ defined CONFIG_SY8106A_POWER
#define CONFIG_SPL_I2C_SUPPORT
#endif
@@ -240,7 +241,8 @@ extern int soft_i2c_gpio_scl;
/* PMU */
#if defined CONFIG_AXP152_POWER || defined CONFIG_AXP209_POWER || \
- defined CONFIG_AXP221_POWER || defined CONFIG_AXP818_POWER
+ defined CONFIG_AXP221_POWER || defined CONFIG_AXP818_POWER || \
+ defined CONFIG_SY8106A_POWER
#define CONFIG_SPL_POWER_SUPPORT
#endif
diff --git a/include/sy8106a.h b/include/sy8106a.h
new file mode 100644
index 0000000..714c314
--- /dev/null
+++ b/include/sy8106a.h
@@ -0,0 +1,5 @@
+#ifndef _SY8106A_PMIC_H_
+
+int sy8106a_set_vout1(unsigned int mvolt);
+
+#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment