[U-Boot] [RFC PATCH 08/11] pmic: Add support for Qualcomm PM8916 PMIC
Simon Glass
sjg at chromium.org
Tue Dec 15 19:58:20 CET 2015
Hi Mateusz,
On 10 December 2015 at 14:41, Mateusz Kulikowski
<mateusz.kulikowski at gmail.com> wrote:
> This PMIC is connected on SPMI bus so needs SPMI support enabled.
>
> Signed-off-by: Mateusz Kulikowski <mateusz.kulikowski at gmail.com>
> ---
>
> drivers/power/pmic/Kconfig | 14 +++++++
> drivers/power/pmic/Makefile | 1 +
> drivers/power/pmic/pm8916.c | 92 +++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 107 insertions(+)
> create mode 100644 drivers/power/pmic/pm8916.c
>
> diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
> index fb29843..eb1dde0 100644
> --- a/drivers/power/pmic/Kconfig
> +++ b/drivers/power/pmic/Kconfig
> @@ -89,3 +89,17 @@ config PMIC_TPS65090
> FETs and a battery charger. This driver provides register access
> only, and you can enable the regulator/charger drivers separately if
> required.
> +
> +config PMIC_PM8916
> + bool "Enable Driver Model for Qualcomm PM8916 PMIC"
> + depends on DM_PMIC
> + ---help---
> + The PM8916 is a PMIC connected to one (or several) processors
> + with SPMI bus. It has 2 slaves with several peripherals:
> + - 18x LDO
> + - 4x GPIO
> + - Power and Reset buttons
> + - Watchdog
> + - RTC
> + - Vibrator drivers
> + - Others
Nice help!
> diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
> index 91e78f8..ac653c7 100644
> --- a/drivers/power/pmic/Makefile
> +++ b/drivers/power/pmic/Makefile
> @@ -13,6 +13,7 @@ obj-$(CONFIG_DM_PMIC_SANDBOX) += sandbox.o i2c_pmic_emul.o
> obj-$(CONFIG_PMIC_ACT8846) += act8846.o
> obj-$(CONFIG_PMIC_TPS65090) += tps65090.o
> obj-$(CONFIG_PMIC_S5M8767) += s5m8767.o
> +obj-$(CONFIG_PMIC_PM8916) += pm8916.o
>
> obj-$(CONFIG_POWER_LTC3676) += pmic_ltc3676.o
> obj-$(CONFIG_POWER_MAX77696) += pmic_max77696.o
> diff --git a/drivers/power/pmic/pm8916.c b/drivers/power/pmic/pm8916.c
> new file mode 100644
> index 0000000..5fe50ef
> --- /dev/null
> +++ b/drivers/power/pmic/pm8916.c
> @@ -0,0 +1,92 @@
> +/*
> + * Qualcomm pm8916 pmic driver
> + *
> + * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski at gmail.com>
> + *
> + * SPDX-License-Identifier: GPL-2.0+
> + */
> +#include <common.h>
> +#include <dm.h>
> +#include <asm/io.h>
> +#include <linux/bitops.h>
> +#include <power/pmic.h>
> +#include <spmi/spmi.h>
> +#include <asm/gpio.h>
> +#include <dm/root.h>
Fix ordering
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +#define EXTRACT_PID(x) (((x) >> 8) & 0xFF)
> +#define EXTRACT_REG(x) ((x) & 0xFF)
Can you define
#define PID_SHIFT 8
#define PID_MASK (0xff << PID_SHIFT)
and use those? I prefer lower-case hex but there is no convention on that.
> +
> +struct pm8916_priv {
> + uint16_t usid; /* Slave ID on SPMI bus */
> +};
> +
> +static int pm8916_reg_count(struct udevice *dev)
> +{
> + return 0xFFFF;
> +}
> +
> +static int pm8916_write(struct udevice *dev, uint reg, const uint8_t *buff,
> + int len)
> +{
> + struct pm8916_priv *priv = dev_get_priv(dev);
> +
> + if (len != 1)
> + return -EINVAL;
> +
> + return spmi_reg_write(dev->parent, priv->usid, EXTRACT_PID(reg),
> + EXTRACT_REG(reg), *buff);
> +}
> +
> +static int pm8916_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
> +{
> + struct pm8916_priv *priv = dev_get_priv(dev);
> + int val;
> +
> + if (len != 1)
> + return -EINVAL;
> +
> + val = spmi_reg_read(dev->parent, priv->usid, EXTRACT_PID(reg),
> + EXTRACT_REG(reg));
> +
> + if (val < 0)
> + return val;
> + *buff = val;
> + return 0;
> +}
> +
> +static struct dm_pmic_ops pm8916_ops = {
> + .reg_count = pm8916_reg_count,
> + .read = pm8916_read,
> + .write = pm8916_write,
> +};
> +
> +static const struct udevice_id pm8916_ids[] = {
> + { .compatible = "qcom,spmi-pmic" },
Binding doc?
> + { }
> +};
> +
> +static int pm8916_probe(struct udevice *dev)
> +{
> + struct pm8916_priv *priv = dev_get_priv(dev);
blank line
> + priv->usid = dev_get_addr(dev);
> + return 0;
> +}
> +
> +
> +static int pm8916_bind(struct udevice *dev)
> +{
> + return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
> +}
> +
> +U_BOOT_DRIVER(pmic_pm8916) = {
> + .name = "pmic_pm8916",
> + .id = UCLASS_PMIC,
> + .of_match = pm8916_ids,
> + .bind = pm8916_bind,
> + .probe = pm8916_probe,
> + .ops = &pm8916_ops,
> + .priv_auto_alloc_size = sizeof(struct pm8916_priv),
> +};
> --
> 2.5.0
>
Regards,
Simon
More information about the U-Boot
mailing list