From ae07c5c0cc8173d198fd2a420ac31958a1bbbf32 Mon Sep 17 00:00:00 2001 From: Philipp Tomsich Date: Sun, 18 Sep 2016 13:07:25 +0200 Subject: pmic: add DM driver for the AXP806 and AXP809 --- drivers/power/pmic/Kconfig | 7 ++ drivers/power/pmic/Makefile | 3 +- drivers/power/pmic/axp80x.c | 179 ++++++++++++++++++++++++++++++++++++++++++++ include/power/axp806_pmic.h | 59 +++++++++++++++ 4 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 drivers/power/pmic/axp80x.c create mode 100644 include/power/axp806_pmic.h diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig index 7f69ae1ca8..3e7f23bc38 100644 --- a/drivers/power/pmic/Kconfig +++ b/drivers/power/pmic/Kconfig @@ -40,6 +40,13 @@ config PMIC_ACT8846 functions. It uses an I2C interface and is designed for use with tablets and smartphones. +config PMIC_AXP80X + bool "Enable support for the X-Powers AXP806 and AXP809 PMICs" + depends on DM_PMIC && MACH_SUN9I + ---help--- + These devices is used with the Allwinner A80 (AW1869) SoC. This + driver implements register read/write operations. + config DM_PMIC_PFUZE100 bool "Enable Driver Model for PMIC PFUZE100" depends on DM_PMIC diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile index c6e8d0c610..05c48d2b14 100644 --- a/drivers/power/pmic/Makefile +++ b/drivers/power/pmic/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_DM_PMIC_PFUZE100) += pfuze100.o obj-$(CONFIG_PMIC_S2MPS11) += s2mps11.o obj-$(CONFIG_DM_PMIC_SANDBOX) += sandbox.o i2c_pmic_emul.o obj-$(CONFIG_PMIC_ACT8846) += act8846.o +obj-$(CONFIG_PMIC_AXP80X) += axp80x.o obj-$(CONFIG_PMIC_RK808) += rk808.o obj-$(CONFIG_PMIC_TPS65090) += tps65090.o obj-$(CONFIG_PMIC_S5M8767) += s5m8767.o @@ -27,4 +28,4 @@ obj-$(CONFIG_POWER_TPS65217) += pmic_tps65217.o obj-$(CONFIG_POWER_TPS65218) += pmic_tps62362.o obj-$(CONFIG_POWER_TPS65218) += pmic_tps65218.o obj-$(CONFIG_POWER_TPS65910) += pmic_tps65910.o -obj-$(CONFIG_POWER_HI6553) += pmic_hi6553.o +obj-$(CONFIG_POWER_HI6553) += pmic_hi6553.o \ No newline at end of file diff --git a/drivers/power/pmic/axp80x.c b/drivers/power/pmic/axp80x.c new file mode 100644 index 0000000000..727e421433 --- /dev/null +++ b/drivers/power/pmic/axp80x.c @@ -0,0 +1,179 @@ +/* + * (C) Copyright 2016 Theobroma Systems Design und Consulting GmbH + * Written by Philipp Tomsich + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef CONFIG_SPL_BUILD + +DECLARE_GLOBAL_DATA_PTR; + + +#if 0 +/* TODO: implement me */ +static const struct pmic_child_info pmic_children_info[] = { + { .prefix = "DCDC_REG", .driver = "rk808_buck"}, + { .prefix = "LDO_REG", .driver = "rk808_ldo"}, + { .prefix = "SWITCH_REG", .driver = "rk808_switch"}, + { }, +}; +#endif + +static int axp806_reg_count(struct udevice *dev) +{ + return AXP806_NUM_OF_REGS; +} + +static int axp808_reg_count(struct udevice *dev) +{ + return 0xff; /* TODO */ +} + +static int axp80x_write(struct udevice *dev, + uint reg, const uint8_t *buff, int len) +{ + int ret; + + ret = dm_i2c_write(dev, reg, buff, len); + if (ret) { + debug("write error to device: %p register: %#x!", dev, reg); + return ret; + } + + return 0; +} + +static int axp80x_read(struct udevice *dev, uint reg, uint8_t *buff, int len) +{ + int ret; + + ret = dm_i2c_read(dev, reg, buff, len); + if (ret) { + debug("read error from device: %p register: %#x!", dev, reg); + return ret; + } + + return 0; +} + +#if CONFIG_IS_ENABLED(PMIC_CHILDREN) +static int axp80x_bind(struct udevice *dev, const struct pmic_child_info* pmic_children) +{ + const void *blob = gd->fdt_blob; + int regulators_node; + int children; + + regulators_node = fdt_subnode_offset(blob, dev->of_offset, + "regulators"); + if (regulators_node <= 0) { + debug("%s: %s regulators subnode not found!", __func__, + dev->name); + return -ENXIO; + } + + debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); + + children = pmic_bind_children(dev, regulators_node, pmic_children_info); + if (!children) + debug("%s: %s - no child found\n", __func__, dev->name); + + /* Always return success for this device */ + return 0; +} + +static int axp806_bind(struct udevice *dev) +{ + return axp80x_bind(dev, axp806_children_info); +} + +static int axp808_bind(struct udevice *dev) +{ + return axp80x_bind(dev, axp808_children_info); +} +#endif + +static void axp80x_set_name(struct udevice *dev, const char* prefix) +{ + struct dm_i2c_chip *chip = dev_get_parent_platdata(dev); + char devname[16]; + + snprintf(devname, sizeof(devname), "%s@%x", prefix, chip->chip_addr); + device_set_name(dev, devname); +} + +static int axp806_probe(struct udevice *dev) +{ + /* Perform chip-specific initialisation */ + axp80x_set_name(dev, "axp806"); + /* The AXP806 needs to write to the 'register address + extension' register to fully initialise it for + communication using this driver. */ + dm_i2c_write(dev, AXP806_REGADDR_EXT, (const uint8_t*)"\x10", 1); + + return 0; +} + +static int axp808_probe(struct udevice *dev) +{ + /* Perform chip-specific initialisation */ + axp80x_set_name(dev, "axp808"); + + return 0; +} + +static struct dm_pmic_ops axp806_ops = { + .reg_count = axp806_reg_count, + .read = axp80x_read, + .write = axp80x_write, +}; + +static struct dm_pmic_ops axp808_ops = { + .reg_count = axp808_reg_count, + .read = axp80x_read, + .write = axp80x_write, +}; + +static const struct udevice_id axp806_ids[] = { + { .compatible = "x-powers,axp806" }, + { } +}; + +static const struct udevice_id axp808_ids[] = { + { .compatible = "x-powers,axp808" }, + { } +}; + +U_BOOT_DRIVER(pmic_axp806) = { + .name = "AXP806 PMIC", + .id = UCLASS_PMIC, + .probe = axp806_probe, + .of_match = axp806_ids, +#if CONFIG_IS_ENABLED(PMIC_CHILDREN) + .bind = axp806_bind, +#endif + .ops = &axp806_ops, +}; + +U_BOOT_DRIVER(pmic_axp808) = { + .name = "AXP808 PMIC", + .id = UCLASS_PMIC, + .probe = axp808_probe, + .of_match = axp808_ids, +#if CONFIG_IS_ENABLED(PMIC_CHILDREN) + .bind = axp808_bind, +#endif + .ops = &axp808_ops, +}; + +#endif diff --git a/include/power/axp806_pmic.h b/include/power/axp806_pmic.h new file mode 100644 index 0000000000..9c29c26f98 --- /dev/null +++ b/include/power/axp806_pmic.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2016 Theobroma Systems Design und Consulting GmbH + * Written by Dr. Philipp Tomsich + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef _PMIC_AXP806_H_ +#define _PMIC_AXP806_H_ + +enum { + AXP806_STARTUP_SRC = 0x00, + AXP806_CHIP_ID = 0x03, + AXP806_PWR_OUT_CTRL1 = 0x10, + AXP806_PWR_OUT_CTRL2, + AXP806_DCDCA_V_CTRL, + AXP806_DCDCB_V_CTRL, + AXP806_DCDCC_V_CTRL, + AXP806_DCDCD_V_CTRL, + AXP806_DCDCE_V_CTRL, + AXP806_ALDO1_V_CTRL, + AXP806_ALDO2_V_CTRL, + AXP806_ALDO3_V_CTRL, + AXP806_DCDC_MODE_CTRL1, + AXP806_DCDC_MODE_CTRL2, + AXP806_DCDC_FREQ_CTRL, + AXP806_OUTPUT_MONITOR, + AXP806_IRQ_PWROK_OFF, + AXP806_BLDO1_V_CTRL, + AXP806_BLDO2_V_CTRL, + AXP806_BLDO3_V_CTRL, + AXP806_BLDO4_V_CTRL, + AXP806_CLDO1_V_CTRL, + AXP806_CLDO2_V_CTRL, + AXP806_CLDO3_V_CTRL, + AXP806_WAKEUP_CTRL = 0x31, + AXP806_POWERDOWN, + AXP806_WAKEUP_PINCTRL = 0x35, + AXP806_INTERFACE_MODE = 0x3e, + AXP806_SPECIAL_CTRL, + AXP806_IRQ_ENABLE1, + AXP806_IRQ_ENABLE2, + AXP806_IRQ_STATUS1 = 0x48, + AXP806_IRQ_STATUS2, + AXP806_VREF_TEMP_WARN_L = 0xf3, + AXP806_BUSADDR_EXT = 0xfe, + AXP806_REGADDR_EXT, + AXP806_NUM_OF_REGS, +}; + +struct axp806_reg_table { + char *name; + u8 reg_ctl; + u8 reg_vol; +}; + +// int rk808_spl_configure_buck(struct udevice *pmic, int buck, int uvolt); + +#endif -- cgit v1.2.3