Commit 33621d247e771168ebaab2218d02e625371d144a

Authored by Keerthy
Committed by Simon Glass
1 parent 34514b8b9c

power: pmic: Palmas: Add the base pmic support

Add support to bind the regulators/child nodes with the pmic.
Also adds the pmic i2c based read/write funtions to access pmic
registers.

Signed-off-by: Keerthy <j-keerthy@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

Showing 4 changed files with 137 additions and 0 deletions Side-by-side Diff

drivers/power/pmic/Kconfig
... ... @@ -143,4 +143,11 @@
143 143 FETs and a battery charger. This driver provides register access
144 144 only, and you can enable the regulator/charger drivers separately if
145 145 required.
  146 +
  147 +config PMIC_PALMAS
  148 + bool "Enable driver for Texas Instruments PALMAS PMIC"
  149 + depends on DM_PMIC
  150 + ---help---
  151 + The PALMAS is a PMIC containing several LDOs, SMPS.
  152 + This driver binds the pmic children.
drivers/power/pmic/Makefile
... ... @@ -16,6 +16,7 @@
16 16 obj-$(CONFIG_PMIC_RN5T567) += rn5t567.o
17 17 obj-$(CONFIG_PMIC_TPS65090) += tps65090.o
18 18 obj-$(CONFIG_PMIC_S5M8767) += s5m8767.o
  19 +obj-$(CONFIG_$(SPL_)PMIC_PALMAS) += palmas.o
19 20  
20 21 obj-$(CONFIG_POWER_LTC3676) += pmic_ltc3676.o
21 22 obj-$(CONFIG_POWER_MAX77696) += pmic_max77696.o
drivers/power/pmic/palmas.c
  1 +/*
  2 + * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
  3 + * Keerthy <j-keerthy@ti.com>
  4 + *
  5 + * SPDX-License-Identifier: GPL-2.0+
  6 + */
  7 +
  8 +#include <common.h>
  9 +#include <fdtdec.h>
  10 +#include <errno.h>
  11 +#include <dm.h>
  12 +#include <i2c.h>
  13 +#include <power/pmic.h>
  14 +#include <power/regulator.h>
  15 +#include <power/palmas.h>
  16 +#include <dm/device.h>
  17 +
  18 +DECLARE_GLOBAL_DATA_PTR;
  19 +
  20 +static const struct pmic_child_info pmic_children_info[] = {
  21 + { .prefix = "ldo", .driver = PALMAS_LDO_DRIVER },
  22 + { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER },
  23 + { },
  24 +};
  25 +
  26 +static int palmas_write(struct udevice *dev, uint reg, const uint8_t *buff,
  27 + int len)
  28 +{
  29 + if (dm_i2c_write(dev, reg, buff, len)) {
  30 + error("write error to device: %p register: %#x!", dev, reg);
  31 + return -EIO;
  32 + }
  33 +
  34 + return 0;
  35 +}
  36 +
  37 +static int palmas_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
  38 +{
  39 + if (dm_i2c_read(dev, reg, buff, len)) {
  40 + error("read error from device: %p register: %#x!", dev, reg);
  41 + return -EIO;
  42 + }
  43 +
  44 + return 0;
  45 +}
  46 +
  47 +static int palmas_bind(struct udevice *dev)
  48 +{
  49 + int pmic_node = -1, regulators_node;
  50 + const void *blob = gd->fdt_blob;
  51 + int children;
  52 + int node = dev->of_offset;
  53 + int subnode, len;
  54 +
  55 + fdt_for_each_subnode(blob, subnode, node) {
  56 + const char *name;
  57 + char *temp;
  58 +
  59 + name = fdt_get_name(blob, subnode, &len);
  60 + temp = strstr(name, "pmic");
  61 + if (temp) {
  62 + pmic_node = subnode;
  63 + break;
  64 + }
  65 + }
  66 +
  67 + if (pmic_node <= 0) {
  68 + debug("%s: %s pmic subnode not found!", __func__, dev->name);
  69 + return -ENXIO;
  70 + }
  71 +
  72 + regulators_node = fdt_subnode_offset(blob, pmic_node, "regulators");
  73 +
  74 + if (regulators_node <= 0) {
  75 + debug("%s: %s reg subnode not found!", __func__, dev->name);
  76 + return -ENXIO;
  77 + }
  78 +
  79 + children = pmic_bind_children(dev, regulators_node, pmic_children_info);
  80 + if (!children)
  81 + debug("%s: %s - no child found\n", __func__, dev->name);
  82 +
  83 + /* Always return success for this device */
  84 + return 0;
  85 +}
  86 +
  87 +static struct dm_pmic_ops palmas_ops = {
  88 + .read = palmas_read,
  89 + .write = palmas_write,
  90 +};
  91 +
  92 +static const struct udevice_id palmas_ids[] = {
  93 + { .compatible = "ti,tps659038", .data = TPS659038 },
  94 + { .compatible = "ti,tps65917" , .data = TPS65917 },
  95 + { }
  96 +};
  97 +
  98 +U_BOOT_DRIVER(pmic_palmas) = {
  99 + .name = "palmas_pmic",
  100 + .id = UCLASS_PMIC,
  101 + .of_match = palmas_ids,
  102 + .bind = palmas_bind,
  103 + .ops = &palmas_ops,
  104 +};
include/power/palmas.h
  1 +#define PALMAS 0x0
  2 +#define TPS659038 0x1
  3 +#define TPS65917 0x2
  4 +
  5 +/* I2C device address for pmic palmas */
  6 +#define PALMAS_I2C_ADDR (0x12 >> 1)
  7 +#define PALMAS_LDO_NUM 11
  8 +#define PALMAS_SMPS_NUM 8
  9 +
  10 +/* Drivers name */
  11 +#define PALMAS_LDO_DRIVER "palmas_ldo"
  12 +#define PALMAS_SMPS_DRIVER "palmas_smps"
  13 +
  14 +#define PALMAS_SMPS_VOLT_MASK 0x7F
  15 +#define PALMAS_SMPS_RANGE_MASK 0x80
  16 +#define PALMAS_SMPS_VOLT_MAX_HEX 0x7F
  17 +#define PALMAS_SMPS_VOLT_MAX 3300000
  18 +#define PALMAS_SMPS_MODE_MASK 0x3
  19 +#define PALMAS_SMPS_STATUS_MASK 0x30
  20 +
  21 +#define PALMAS_LDO_VOLT_MASK 0x3F
  22 +#define PALMAS_LDO_VOLT_MAX_HEX 0x3F
  23 +#define PALMAS_LDO_VOLT_MAX 3300000
  24 +#define PALMAS_LDO_MODE_MASK 0x1
  25 +#define PALMAS_LDO_STATUS_MASK 0x10