Add Active-Semi act8865 series PMU support. Signed-off-by: Bo Shen <voice.s...@atmel.com> ---
drivers/power/Makefile | 1 + drivers/power/act8865.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++ include/act8865.h | 54 +++++++++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 drivers/power/act8865.c create mode 100644 include/act8865.h diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 2145652..0c2a8cf 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -5,6 +5,7 @@ # SPDX-License-Identifier: GPL-2.0+ # +obj-$(CONFIG_ACT8865_POWER) += act8865.o obj-$(CONFIG_AS3722_POWER) += as3722.o obj-$(CONFIG_AXP152_POWER) += axp152.o obj-$(CONFIG_AXP209_POWER) += axp209.o diff --git a/drivers/power/act8865.c b/drivers/power/act8865.c new file mode 100644 index 0000000..c36f7bd --- /dev/null +++ b/drivers/power/act8865.c @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2015 Atmel Corporation + * Bo Shen <voice.s...@atmel.com> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <i2c.h> +#include <act8865.h> + +static int act8865_read(u32 reg, uchar *val) +{ + return i2c_read(ACT8865_I2C_ADDR, reg, 1, val, 1); +} + +static int act8865_write(u32 reg, uchar val) +{ + return i2c_write(ACT8865_I2C_ADDR, reg, 1, &val, 1); +} + +int act8865_disable_i2c_interface(void) +{ + uchar val; + + /* Check the I2C interface is disabled or not */ + if (act8865_read(ACT8865_SYS_CONTROL0, &val)) { + debug("ACT8865: i2c interface has been disabled\n"); + return 0; + } + + /* + * As the ACT8865 don't have ID register, so we try one by one + * to disable the exist chips (303, 304, 305) in this series. + */ + + /* Try to disable ACT8865QI303 */ + act8865_write(0x0B, 0xE9); + act8865_write(0x02, 0x07); + if (act8865_write(0x03, 0x01)) { + debug("ACT8865: subtype 303 has been disabled\n"); + return 0; + } + + /* Try to disable ACT8865QI304 */ + act8865_write(0x0B, 0xEE); + act8865_write(0x02, 0x07); + if (act8865_write(0x03, 0x01)) { + debug("ACT8865: subtype 304 has been disabled\n"); + return 0; + } + + /* Try to disable ACT8865QI305 */ + act8865_write(0x0B, 0xEE); + act8865_write(0x02, 0x07); + if (act8865_write(0x03, 0x01)) { + debug("ACT8865: subtype 305 has been disabled\n"); + return 0; + } + + debug("ACT8865: the chip can not be disabled\n"); + + return 0; +} + +int act8865_enable_ldo_output(enum act8865_ldo ldo, enum act8865_volt volt) +{ + u32 conf_reg, ctrl_reg; + uchar val; + + switch (ldo) { + case ACT8865_LDO_REG4: + conf_reg = ACT8865_REG4_CONFIG0; + ctrl_reg = ACT8865_REG4_CONTROL; + break; + + case ACT8865_LDO_REG5: + conf_reg = ACT8865_REG5_CONFIG0; + ctrl_reg = ACT8865_REG5_CONTROL; + break; + + case ACT8865_LDO_REG6: + conf_reg = ACT8865_REG6_CONFIG0; + ctrl_reg = ACT8865_REG6_CONTROL; + break; + + case ACT8865_LDO_REG7: + conf_reg = ACT8865_REG7_CONFIG0; + ctrl_reg = ACT8865_REG7_CONTROL; + break; + default: + error("ACT8865: unsupported LDO\n"); + return -1; + } + + /* Set the LDO output voltage */ + act8865_write(conf_reg, 0x18); + /* Enable the LDO */ + act8865_read(ctrl_reg, &val); + val |= ACT8865_OUTPUT_ENABLE; + act8865_write(ctrl_reg, val); + + return 0; +} diff --git a/include/act8865.h b/include/act8865.h new file mode 100644 index 0000000..f6053ac --- /dev/null +++ b/include/act8865.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2015 Atmel Corporation + * Bo Shen <voice.s...@atmel.com> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#define ACT8865_SYS_CONTROL0 0x00 +#define ACT8865_SYS_CONTROL1 0x01 + +#define ACT8865_REG1_CONFIG0 0x20 +#define ACT8865_REG1_CONFIG1 0x21 +#define ACT8865_REG1_CONTROL 0x22 + +#define ACT8865_REG2_CONFIG0 0x30 +#define ACT8865_REG2_CONFIG1 0x31 +#define ACT8865_REG2_CONTROL 0x32 + +#define ACT8865_REG3_CONFIG0 0x40 +#define ACT8865_REG3_CONFIG1 0x41 +#define ACT8865_REG3_CONTROL 0x42 + +#define ACT8865_REG4_CONFIG0 0x50 +#define ACT8865_REG4_CONTROL 0x51 + +#define ACT8865_REG5_CONFIG0 0x54 +#define ACT8865_REG5_CONTROL 0x55 + +#define ACT8865_REG6_CONFIG0 0x60 +#define ACT8865_REG6_CONTROL 0x61 + +#define ACT8865_REG7_CONFIG0 0x64 +#define ACT8865_REG7_CONTROL 0x65 + +#define ACT8865_OUTPUT_ENABLE (0x01 << 7) + +#define ACT8865_I2C_ADDR 0x5B + +enum act8865_ldo { + ACT8865_LDO_REG4 = 4, + ACT8865_LDO_REG5, + ACT8865_LDO_REG6, + ACT8865_LDO_REG7, +}; + +enum act8865_volt { + ACT8865_1V2_VOLT, + ACT8865_1V8_VOLT, + ACT8865_2V5_VOLT, + ACT8865_3V3_VOLT, +}; + +int act8865_enable_ldo_output(enum act8865_ldo ldo, enum act8865_volt volt); +int act8865_disable_i2c_interface(void); -- 2.3.0 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot