diff options
author | Philipp Tomsich <philipp.tomsich@theobroma-systems.com> | 2016-09-18 13:07:25 +0200 |
---|---|---|
committer | Klaus Goger <klaus.goger@theobroma-systems.com> | 2016-09-18 15:57:25 +0200 |
commit | ae07c5c0cc8173d198fd2a420ac31958a1bbbf32 (patch) | |
tree | 0dc10fdecc7be400e0615f86a285e4096c928249 /drivers | |
parent | d98f436149fbf3dc4c0d30ba7549f53f8d8f8259 (diff) |
pmic: add DM driver for the AXP806 and AXP809
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/power/pmic/Kconfig | 7 | ||||
-rw-r--r-- | drivers/power/pmic/Makefile | 3 | ||||
-rw-r--r-- | drivers/power/pmic/axp80x.c | 179 |
3 files changed, 188 insertions, 1 deletions
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 <philipp.tomsich@theobroma-systems.com> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <dm.h> +#include <i2c.h> +#include <errno.h> +#include <fdtdec.h> +#include <libfdt.h> +#include <power/axp806_pmic.h> +#include <power/pmic.h> +#include <asm/arch/rsb.h> + +#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 |