U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v5 0/6] power: pmic: Add support for Palmas family of PMICs
@ 2016-09-28  4:27 Keerthy
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 1/6] power: regulator: Add ctrl_reg and volt_reg fields for pmic Keerthy
                   ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Keerthy @ 2016-09-28  4:27 UTC (permalink / raw)
  To: u-boot

The series adds support for Palmas family of PMICs.
Implements functions to configure regulators. Enable/Disable
Get/Set voltages of regulators.

Supports TPS659038, TPS65917, Palmas.

Tested on TPS659038, TPS65917 using DRA7XX-EVM and AM57XX-EVM.

Changes in v5:

removed u8 i2c read/write functions made use of already
existing functions.

Added read/write functions.

Changes in v4:

Added Reviewed-by and a minor change from printf to debug.

Changes in v3:

Introduced u8 i2c read/write functions. 

Keerthy (6):
  power: regulator: Add ctrl_reg and volt_reg fields for pmic
  power: pmic: Palmas: Add the base pmic support
  power: regulator: palmas: Add regulator support
  configs: dra7xx_evm_defconfig: Enable PALMAS options
  configs: am57xx_evm_defconfig: Enable PALMAS options
  configs: am57xx_evm_defconfig: Enable CMD_REG option

 configs/am57xx_evm_defconfig               |   5 +
 configs/dra7xx_evm_defconfig               |   3 +
 drivers/power/pmic/Kconfig                 |   7 +
 drivers/power/pmic/Makefile                |   1 +
 drivers/power/pmic/palmas.c                | 108 +++++++
 drivers/power/regulator/Kconfig            |   8 +
 drivers/power/regulator/Makefile           |   1 +
 drivers/power/regulator/palmas_regulator.c | 453 +++++++++++++++++++++++++++++
 include/power/palmas.h                     |  25 ++
 include/power/regulator.h                  |   4 +
 10 files changed, 615 insertions(+)
 create mode 100644 drivers/power/pmic/palmas.c
 create mode 100644 drivers/power/regulator/palmas_regulator.c
 create mode 100644 include/power/palmas.h

-- 
1.9.1

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v5 1/6] power: regulator: Add ctrl_reg and volt_reg fields for pmic
  2016-09-28  4:27 [U-Boot] [PATCH v5 0/6] power: pmic: Add support for Palmas family of PMICs Keerthy
@ 2016-09-28  4:27 ` Keerthy
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 2/6] power: pmic: Palmas: Add the base pmic support Keerthy
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Keerthy @ 2016-09-28  4:27 UTC (permalink / raw)
  To: u-boot

The ctrl reg contains bit fields to enable and disable regulators,
and volt_reg has the bit fields to configure the voltage values.
The registers are frequently accessed hence make them part
of dm_regulator_uclass_platdata structure.

Signed-off-by: Keerthy <j-keerthy@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
 include/power/regulator.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/power/regulator.h b/include/power/regulator.h
index 9bcd728..2117f55 100644
--- a/include/power/regulator.h
+++ b/include/power/regulator.h
@@ -152,6 +152,8 @@ enum regulator_flag {
  * TODO(sjg at chromium.org): Consider putting the above two into @flags
  * @flags:     - flags value (see REGULATOR_FLAG_...)
  * @name**     - fdt regulator name - should be taken from the device tree
+ * ctrl_reg:   - Control register offset used to enable/disable regulator
+ * volt_reg:   - register offset for writing voltage vsel values
  *
  * Note:
  * *  - set automatically on device probe by the uclass's '.pre_probe' method.
@@ -171,6 +173,8 @@ struct dm_regulator_uclass_platdata {
 	bool boot_on;
 	const char *name;
 	int flags;
+	u8 ctrl_reg;
+	u8 volt_reg;
 };
 
 /* Regulator device operations */
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v5 2/6] power: pmic: Palmas: Add the base pmic support
  2016-09-28  4:27 [U-Boot] [PATCH v5 0/6] power: pmic: Add support for Palmas family of PMICs Keerthy
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 1/6] power: regulator: Add ctrl_reg and volt_reg fields for pmic Keerthy
@ 2016-09-28  4:27 ` Keerthy
  2016-09-28 17:51   ` Simon Glass
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 3/6] power: regulator: palmas: Add regulator support Keerthy
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Keerthy @ 2016-09-28  4:27 UTC (permalink / raw)
  To: u-boot

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>
---

Changes in v5:

  * Added pmic read/write functions.

 drivers/power/pmic/Kconfig  |   7 +++
 drivers/power/pmic/Makefile |   1 +
 drivers/power/pmic/palmas.c | 108 ++++++++++++++++++++++++++++++++++++++++++++
 include/power/palmas.h      |  25 ++++++++++
 4 files changed, 141 insertions(+)
 create mode 100644 drivers/power/pmic/palmas.c
 create mode 100644 include/power/palmas.h

diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
index 69f8d51..92931c5 100644
--- a/drivers/power/pmic/Kconfig
+++ b/drivers/power/pmic/Kconfig
@@ -135,3 +135,10 @@ 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_PALMAS
+	bool "Enable driver for Texas Instruments PALMAS PMIC"
+	depends on DM_PMIC
+	---help---
+	The PALMAS is a PMIC containing several LDOs, SMPS.
+	This driver binds the pmic children.
diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
index 52b4f71..828c0cf 100644
--- a/drivers/power/pmic/Makefile
+++ b/drivers/power/pmic/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_PMIC_PM8916) += pm8916.o
 obj-$(CONFIG_PMIC_RK808) += rk808.o
 obj-$(CONFIG_PMIC_TPS65090) += tps65090.o
 obj-$(CONFIG_PMIC_S5M8767) += s5m8767.o
+obj-$(CONFIG_$(SPL_)PMIC_PALMAS) += palmas.o
 
 obj-$(CONFIG_POWER_LTC3676) += pmic_ltc3676.o
 obj-$(CONFIG_POWER_MAX77696) += pmic_max77696.o
diff --git a/drivers/power/pmic/palmas.c b/drivers/power/pmic/palmas.c
new file mode 100644
index 0000000..1d2bd67
--- /dev/null
+++ b/drivers/power/pmic/palmas.c
@@ -0,0 +1,108 @@
+/*
+ * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
+ * Keerthy <j-keerthy@ti.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <fdtdec.h>
+#include <errno.h>
+#include <dm.h>
+#include <i2c.h>
+#include <power/pmic.h>
+#include <power/regulator.h>
+#include <power/palmas.h>
+#include <dm/device.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static const struct pmic_child_info pmic_children_info[] = {
+	{ .prefix = "ldo", .driver = PALMAS_LDO_DRIVER },
+	{ .prefix = "smps", .driver = PALMAS_SMPS_DRIVER },
+	{ },
+};
+
+static int palmas_write(struct udevice *dev, uint reg, const uint8_t *buff,
+			  int len)
+{
+	if (dm_i2c_reg_write(dev, reg, *buff)) {
+		error("write error to device: %p register: %#x!", dev, reg);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static int palmas_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
+{
+	int ret;
+
+	ret = dm_i2c_reg_read(dev, reg);
+	if (ret < 0) {
+		error("read error %d from device: %p register: %#x!", ret, dev,
+		      reg);
+		return -EIO;
+	}
+
+	return ret;
+}
+
+static int palmas_bind(struct udevice *dev)
+{
+	int pmic_node = -1, regulators_node;
+	const void *blob = gd->fdt_blob;
+	int children;
+	int node = dev->of_offset;
+	int subnode, len;
+
+	fdt_for_each_subnode(blob, subnode, node) {
+		const char *name;
+		char *temp;
+
+		name = fdt_get_name(blob, subnode, &len);
+		temp = strstr(name, "pmic");
+		if (temp) {
+			pmic_node = subnode;
+			break;
+		}
+	}
+
+	if (pmic_node <= 0) {
+		debug("%s: %s pmic subnode not found!", __func__, dev->name);
+		return -ENXIO;
+	}
+
+	regulators_node = fdt_subnode_offset(blob, pmic_node, "regulators");
+
+	if (regulators_node <= 0) {
+		debug("%s: %s reg subnode not found!", __func__, dev->name);
+		return -ENXIO;
+	}
+
+	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 struct dm_pmic_ops palmas_ops = {
+	.read = palmas_read,
+	.write = palmas_write,
+};
+
+static const struct udevice_id palmas_ids[] = {
+	{ .compatible = "ti,tps659038", .data = TPS659038 },
+	{ .compatible = "ti,tps65917" , .data = TPS65917 },
+	{ }
+};
+
+U_BOOT_DRIVER(pmic_palmas) = {
+	.name = "palmas_pmic",
+	.id = UCLASS_PMIC,
+	.of_match = palmas_ids,
+	.bind = palmas_bind,
+	.ops = &palmas_ops,
+};
diff --git a/include/power/palmas.h b/include/power/palmas.h
new file mode 100644
index 0000000..bad5a35
--- /dev/null
+++ b/include/power/palmas.h
@@ -0,0 +1,25 @@
+#define	PALMAS		0x0
+#define TPS659038	0x1
+#define TPS65917	0x2
+
+/* I2C device address for pmic palmas */
+#define PALMAS_I2C_ADDR	(0x12 >> 1)
+#define PALMAS_LDO_NUM		11
+#define PALMAS_SMPS_NUM	8
+
+/* Drivers name */
+#define PALMAS_LDO_DRIVER     "palmas_ldo"
+#define PALMAS_SMPS_DRIVER    "palmas_smps"
+
+#define PALMAS_SMPS_VOLT_MASK		0x7F
+#define PALMAS_SMPS_RANGE_MASK		0x80
+#define PALMAS_SMPS_VOLT_MAX_HEX	0x7F
+#define PALMAS_SMPS_VOLT_MAX		3300000
+#define PALMAS_SMPS_MODE_MASK		0x3
+#define	PALMAS_SMPS_STATUS_MASK		0x30
+
+#define PALMAS_LDO_VOLT_MASK    0x3F
+#define PALMAS_LDO_VOLT_MAX_HEX 0x3F
+#define PALMAS_LDO_VOLT_MAX     3300000
+#define PALMAS_LDO_MODE_MASK	0x1
+#define PALMAS_LDO_STATUS_MASK	0x10
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v5 3/6] power: regulator: palmas: Add regulator support
  2016-09-28  4:27 [U-Boot] [PATCH v5 0/6] power: pmic: Add support for Palmas family of PMICs Keerthy
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 1/6] power: regulator: Add ctrl_reg and volt_reg fields for pmic Keerthy
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 2/6] power: pmic: Palmas: Add the base pmic support Keerthy
@ 2016-09-28  4:27 ` Keerthy
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 4/6] configs: dra7xx_evm_defconfig: Enable PALMAS options Keerthy
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Keerthy @ 2016-09-28  4:27 UTC (permalink / raw)
  To: u-boot

The driver provides regulator set/get voltage
enable/disable functions for palmas family of PMICs.

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

Changes in v5:

  * Used pmic_reg_read pmic_reg_write functions instead of
    direct i2c calls.

 drivers/power/regulator/Kconfig            |   8 +
 drivers/power/regulator/Makefile           |   1 +
 drivers/power/regulator/palmas_regulator.c | 453 +++++++++++++++++++++++++++++
 3 files changed, 462 insertions(+)
 create mode 100644 drivers/power/regulator/palmas_regulator.c

diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig
index 17f22dd..adb710a 100644
--- a/drivers/power/regulator/Kconfig
+++ b/drivers/power/regulator/Kconfig
@@ -115,3 +115,11 @@ config REGULATOR_TPS65090
 	regulators, one for each FET. The standard regulator interface is
 	supported, but it is only possible to turn the regulators on or off.
 	There is no voltage/current control.
+
+config DM_REGULATOR_PALMAS
+	bool "Enable driver for PALMAS PMIC regulators"
+       depends on PMIC_PALMAS
+	---help---
+	This enables implementation of driver-model regulator uclass
+	features for REGULATOR PALMAS and the family of PALMAS PMICs.
+	The driver implements get/set api for: value and enable.
diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile
index 1590d85..75080d4 100644
--- a/drivers/power/regulator/Makefile
+++ b/drivers/power/regulator/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_REGULATOR_RK808) += rk808.o
 obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
 obj-$(CONFIG_DM_REGULATOR_SANDBOX) += sandbox.o
 obj-$(CONFIG_REGULATOR_TPS65090) += tps65090_regulator.o
+obj-$(CONFIG_$(SPL_)DM_REGULATOR_PALMAS) += palmas_regulator.o
diff --git a/drivers/power/regulator/palmas_regulator.c b/drivers/power/regulator/palmas_regulator.c
new file mode 100644
index 0000000..cce7cd2
--- /dev/null
+++ b/drivers/power/regulator/palmas_regulator.c
@@ -0,0 +1,453 @@
+/*
+ * (C) Copyright 2016
+ * Texas Instruments Incorporated, <www.ti.com>
+ *
+ * Keerthy <j-keerthy@ti.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <fdtdec.h>
+#include <errno.h>
+#include <dm.h>
+#include <i2c.h>
+#include <power/pmic.h>
+#include <power/regulator.h>
+#include <power/palmas.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define	REGULATOR_ON		0x1
+#define	REGULATOR_OFF		0x0
+
+#define	SMPS_MODE_MASK		0x3
+#define	SMPS_MODE_SHIFT		0x0
+#define	LDO_MODE_MASK		0x1
+#define	LDO_MODE_SHIFT		0x0
+
+static const char palmas_smps_ctrl[][PALMAS_SMPS_NUM] = {
+	{0x20, 0x24, 0x28, 0x2c, 0x30, 0x34, 0x38, 0x3c},
+	{0x20, 0x24, 0x28, 0x2c, 0x30, 0x34, 0x38},
+	{0x20, 0x24, 0x2c, 0x30, 0x38},
+};
+
+static const char palmas_smps_volt[][PALMAS_SMPS_NUM] = {
+	{0x23, 0x27, 0x2b, 0x2f, 0x33, 0x37, 0x3b, 0x3c},
+	{0x23, 0x27, 0x2b, 0x2f, 0x33, 0x37, 0x3b},
+	{0x23, 0x27, 0x2f, 0x33, 0x3B}
+};
+
+static const char palmas_ldo_ctrl[][PALMAS_LDO_NUM] = {
+	{0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e, 0x60, 0x62, 0x64},
+	{0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e, 0x60, 0x62, 0x64},
+	{0x50, 0x52, 0x54, 0x5e, 0x62}
+};
+
+static const char palmas_ldo_volt[][PALMAS_LDO_NUM] = {
+	{0x51, 0x53, 0x55, 0x57, 0x59, 0x5b, 0x5d, 0x5f, 0x61, 0x63, 0x65},
+	{0x51, 0x53, 0x55, 0x57, 0x59, 0x5b, 0x5d, 0x5f, 0x61, 0x63, 0x65},
+	{0x51, 0x53, 0x55, 0x5f, 0x63}
+};
+
+static int palmas_smps_enable(struct udevice *dev, int op, bool *enable)
+{
+	int ret;
+	unsigned int adr;
+	struct dm_regulator_uclass_platdata *uc_pdata;
+
+	uc_pdata = dev_get_uclass_platdata(dev);
+	adr = uc_pdata->ctrl_reg;
+
+	ret = pmic_reg_read(dev->parent, adr);
+		if (ret < 0)
+			return ret;
+
+	if (op == PMIC_OP_GET) {
+		ret &= PALMAS_SMPS_STATUS_MASK;
+
+		if (ret)
+			*enable = true;
+		else
+			*enable = false;
+
+		return 0;
+	} else if (op == PMIC_OP_SET) {
+		if (*enable)
+			ret |= PALMAS_SMPS_MODE_MASK;
+		else
+			ret &= ~(PALMAS_SMPS_MODE_MASK);
+
+		ret = pmic_reg_write(dev->parent, adr, ret);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int palmas_smps_volt2hex(int uV)
+{
+	if (uV > PALMAS_LDO_VOLT_MAX)
+		return -EINVAL;
+
+	if (uV > 1650000)
+		return (uV - 1000000) / 20000 + 0x6;
+
+	if (uV == 500000)
+		return 0x6;
+	else
+		return 0x6 + ((uV - 500000) / 10000);
+}
+
+static int palmas_smps_hex2volt(int hex, bool range)
+{
+	unsigned int uV = 0;
+
+	if (hex > PALMAS_SMPS_VOLT_MAX_HEX)
+		return -EINVAL;
+
+	if (hex < 0x7)
+		uV = 500000;
+	else
+		uV = 500000 + (hex - 0x6) * 10000;
+
+	if (range)
+		uV *= 2;
+
+	return uV;
+}
+
+static int palmas_smps_val(struct udevice *dev, int op, int *uV)
+{
+	unsigned int hex, adr;
+	int ret;
+	bool range;
+	struct dm_regulator_uclass_platdata *uc_pdata;
+
+	uc_pdata = dev_get_uclass_platdata(dev);
+
+	if (op == PMIC_OP_GET)
+		*uV = 0;
+
+	adr = uc_pdata->volt_reg;
+
+	ret = pmic_reg_read(dev->parent, adr);
+	if (ret < 0)
+		return ret;
+
+	if (op == PMIC_OP_GET) {
+		if (ret & PALMAS_SMPS_RANGE_MASK)
+			range =  true;
+		else
+			range = false;
+
+		ret &= PALMAS_SMPS_VOLT_MASK;
+		ret = palmas_smps_hex2volt(ret, range);
+		if (ret < 0)
+			return ret;
+		*uV = ret;
+
+		return 0;
+	}
+
+	hex = palmas_smps_volt2hex(*uV);
+	if (hex < 0)
+		return hex;
+
+	ret &= ~PALMAS_SMPS_VOLT_MASK;
+	ret |= hex;
+	if (*uV > 1650000)
+		ret |= PALMAS_SMPS_RANGE_MASK;
+
+	return pmic_reg_write(dev->parent, adr, ret);
+}
+
+static int palmas_ldo_enable(struct udevice *dev, int op, bool *enable)
+{
+	int ret;
+	unsigned int adr;
+	struct dm_regulator_uclass_platdata *uc_pdata;
+
+	uc_pdata = dev_get_uclass_platdata(dev);
+	adr = uc_pdata->ctrl_reg;
+
+	ret = pmic_reg_read(dev->parent, adr);
+		if (ret < 0)
+			return ret;
+
+	if (op == PMIC_OP_GET) {
+		ret &= PALMAS_LDO_STATUS_MASK;
+
+		if (ret)
+			*enable = true;
+		else
+			*enable = false;
+
+		return 0;
+	} else if (op == PMIC_OP_SET) {
+		if (*enable)
+			ret |= PALMAS_LDO_MODE_MASK;
+		else
+			ret &= ~(PALMAS_LDO_MODE_MASK);
+
+		ret = pmic_reg_write(dev->parent, adr, ret);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int palmas_ldo_volt2hex(int uV)
+{
+	if (uV > PALMAS_LDO_VOLT_MAX)
+		return -EINVAL;
+
+	return (uV - 850000) / 50000;
+}
+
+static int palmas_ldo_hex2volt(int hex)
+{
+	if (hex > PALMAS_LDO_VOLT_MAX_HEX)
+		return -EINVAL;
+
+	if (!hex)
+		return 0;
+
+	return (hex * 50000) + 850000;
+}
+
+static int palmas_ldo_val(struct udevice *dev, int op, int *uV)
+{
+	unsigned int hex, adr;
+	int ret;
+
+	struct dm_regulator_uclass_platdata *uc_pdata;
+
+	if (op == PMIC_OP_GET)
+		*uV = 0;
+
+	uc_pdata = dev_get_uclass_platdata(dev);
+
+	adr = uc_pdata->volt_reg;
+
+	ret = pmic_reg_read(dev->parent, adr);
+	if (ret < 0)
+		return ret;
+
+	if (op == PMIC_OP_GET) {
+		ret &= PALMAS_LDO_VOLT_MASK;
+		ret = palmas_ldo_hex2volt(ret);
+		if (ret < 0)
+			return ret;
+		*uV = ret;
+		return 0;
+	}
+
+	hex = palmas_ldo_volt2hex(*uV);
+	if (hex < 0)
+		return hex;
+
+	ret &= ~PALMAS_LDO_VOLT_MASK;
+	ret |= hex;
+	if (*uV > 1650000)
+		ret |= 0x80;
+
+	return pmic_reg_write(dev->parent, adr, ret);
+}
+
+static int palmas_ldo_probe(struct udevice *dev)
+{
+	struct dm_regulator_uclass_platdata *uc_pdata;
+	struct udevice *parent;
+
+	uc_pdata = dev_get_uclass_platdata(dev);
+
+	parent = dev_get_parent(dev);
+	int type = dev_get_driver_data(parent);
+
+	uc_pdata->type = REGULATOR_TYPE_LDO;
+
+	if (dev->driver_data) {
+		u8 idx = dev->driver_data - 1;
+		uc_pdata->ctrl_reg = palmas_ldo_ctrl[type][idx];
+		uc_pdata->volt_reg = palmas_ldo_volt[type][idx];
+	} else {
+		/* check for ldoln and ldousb cases */
+		if (!strcmp("ldoln", dev->name)) {
+			uc_pdata->ctrl_reg = palmas_ldo_ctrl[type][9];
+			uc_pdata->volt_reg = palmas_ldo_volt[type][9];
+		} else if (!strcmp("ldousb", dev->name)) {
+			uc_pdata->ctrl_reg = palmas_ldo_ctrl[type][10];
+			uc_pdata->volt_reg = palmas_ldo_volt[type][10];
+		}
+	}
+
+	return 0;
+}
+
+static int ldo_get_value(struct udevice *dev)
+{
+	int uV;
+	int ret;
+
+	ret = palmas_ldo_val(dev, PMIC_OP_GET, &uV);
+	if (ret)
+		return ret;
+
+	return uV;
+}
+
+static int ldo_set_value(struct udevice *dev, int uV)
+{
+	return palmas_ldo_val(dev, PMIC_OP_SET, &uV);
+}
+
+static bool ldo_get_enable(struct udevice *dev)
+{
+	bool enable = false;
+	int ret;
+
+	ret = palmas_ldo_enable(dev, PMIC_OP_GET, &enable);
+	if (ret)
+		return ret;
+
+	return enable;
+}
+
+static int ldo_set_enable(struct udevice *dev, bool enable)
+{
+	return palmas_ldo_enable(dev, PMIC_OP_SET, &enable);
+}
+
+static int palmas_smps_probe(struct udevice *dev)
+{
+	struct dm_regulator_uclass_platdata *uc_pdata;
+	struct udevice *parent;
+	int idx;
+
+	uc_pdata = dev_get_uclass_platdata(dev);
+
+	parent = dev_get_parent(dev);
+	int type = dev_get_driver_data(parent);
+
+	uc_pdata->type = REGULATOR_TYPE_BUCK;
+
+	switch (type) {
+	case PALMAS:
+	case TPS659038:
+		switch (dev->driver_data) {
+		case 123:
+		case 12:
+			uc_pdata->ctrl_reg = palmas_smps_ctrl[type][0];
+			uc_pdata->volt_reg = palmas_smps_volt[type][0];
+			break;
+		case 3:
+			uc_pdata->ctrl_reg = palmas_smps_ctrl[type][1];
+			uc_pdata->volt_reg = palmas_smps_volt[type][1];
+			break;
+		case 45:
+			uc_pdata->ctrl_reg = palmas_smps_ctrl[type][2];
+			uc_pdata->volt_reg = palmas_smps_volt[type][2];
+			break;
+		case 6:
+		case 7:
+		case 8:
+		case 9:
+		case 10:
+			idx = dev->driver_data - 4;
+			uc_pdata->ctrl_reg = palmas_smps_ctrl[type][idx];
+			uc_pdata->volt_reg = palmas_smps_volt[type][idx];
+			break;
+
+		default:
+			printf("Wrong ID for regulator\n");
+		}
+		break;
+
+	case TPS65917:
+		switch (dev->driver_data) {
+		case 1:
+		case 2:
+		case 3:
+		case 4:
+		case 5:
+			idx = dev->driver_data - 1;
+			uc_pdata->ctrl_reg = palmas_smps_ctrl[type][idx];
+			uc_pdata->volt_reg = palmas_smps_volt[type][idx];
+			break;
+
+		default:
+			printf("Wrong ID for regulator\n");
+		}
+		break;
+
+	default:
+			printf("Invalid PMIC ID\n");
+	}
+
+	return 0;
+}
+
+static int smps_get_value(struct udevice *dev)
+{
+	int uV;
+	int ret;
+
+	ret = palmas_smps_val(dev, PMIC_OP_GET, &uV);
+	if (ret)
+		return ret;
+
+	return uV;
+}
+
+static int smps_set_value(struct udevice *dev, int uV)
+{
+	return palmas_smps_val(dev, PMIC_OP_SET, &uV);
+}
+
+static bool smps_get_enable(struct udevice *dev)
+{
+	bool enable = false;
+	int ret;
+
+	ret = palmas_smps_enable(dev, PMIC_OP_GET, &enable);
+	if (ret)
+		return ret;
+
+	return enable;
+}
+
+static int smps_set_enable(struct udevice *dev, bool enable)
+{
+	return palmas_smps_enable(dev, PMIC_OP_SET, &enable);
+}
+
+static const struct dm_regulator_ops palmas_ldo_ops = {
+	.get_value  = ldo_get_value,
+	.set_value  = ldo_set_value,
+	.get_enable = ldo_get_enable,
+	.set_enable = ldo_set_enable,
+};
+
+U_BOOT_DRIVER(palmas_ldo) = {
+	.name = PALMAS_LDO_DRIVER,
+	.id = UCLASS_REGULATOR,
+	.ops = &palmas_ldo_ops,
+	.probe = palmas_ldo_probe,
+};
+
+static const struct dm_regulator_ops palmas_smps_ops = {
+	.get_value  = smps_get_value,
+	.set_value  = smps_set_value,
+	.get_enable = smps_get_enable,
+	.set_enable = smps_set_enable,
+};
+
+U_BOOT_DRIVER(palmas_smps) = {
+	.name = PALMAS_SMPS_DRIVER,
+	.id = UCLASS_REGULATOR,
+	.ops = &palmas_smps_ops,
+	.probe = palmas_smps_probe,
+};
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v5 4/6] configs: dra7xx_evm_defconfig: Enable PALMAS options
  2016-09-28  4:27 [U-Boot] [PATCH v5 0/6] power: pmic: Add support for Palmas family of PMICs Keerthy
                   ` (2 preceding siblings ...)
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 3/6] power: regulator: palmas: Add regulator support Keerthy
@ 2016-09-28  4:27 ` Keerthy
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 5/6] configs: am57xx_evm_defconfig: " Keerthy
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Keerthy @ 2016-09-28  4:27 UTC (permalink / raw)
  To: u-boot

Enable palmas PMIC config options.

Signed-off-by: Keerthy <j-keerthy@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
---
 configs/dra7xx_evm_defconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/configs/dra7xx_evm_defconfig b/configs/dra7xx_evm_defconfig
index c74dc18..4af1b03 100644
--- a/configs/dra7xx_evm_defconfig
+++ b/configs/dra7xx_evm_defconfig
@@ -50,8 +50,11 @@ CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_BAR=y
 CONFIG_SPI_FLASH_SPANSION=y
 CONFIG_DM_ETH=y
+CONFIG_DM_PMIC=y
+CONFIG_PMIC_PALMAS=y
 CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
+CONFIG_DM_REGULATOR_PALMAS=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
 CONFIG_DM_SPI=y
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v5 5/6] configs: am57xx_evm_defconfig: Enable PALMAS options
  2016-09-28  4:27 [U-Boot] [PATCH v5 0/6] power: pmic: Add support for Palmas family of PMICs Keerthy
                   ` (3 preceding siblings ...)
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 4/6] configs: dra7xx_evm_defconfig: Enable PALMAS options Keerthy
@ 2016-09-28  4:27 ` Keerthy
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 6/6] configs: am57xx_evm_defconfig: Enable CMD_REG option Keerthy
  2016-09-28  4:29 ` [U-Boot] [PATCH v5 0/6] power: pmic: Add support for Palmas family of PMICs Keerthy
  6 siblings, 0 replies; 14+ messages in thread
From: Keerthy @ 2016-09-28  4:27 UTC (permalink / raw)
  To: u-boot

Enable palmas PMIC config options.

Signed-off-by: Keerthy <j-keerthy@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
---
 configs/am57xx_evm_defconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/configs/am57xx_evm_defconfig b/configs/am57xx_evm_defconfig
index 27ea472..6c60d9b 100644
--- a/configs/am57xx_evm_defconfig
+++ b/configs/am57xx_evm_defconfig
@@ -43,6 +43,9 @@ CONFIG_DM_SPI_FLASH=y
 CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_BAR=y
 CONFIG_SPI_FLASH_SPANSION=y
+CONFIG_DM_PMIC=y
+CONFIG_PMIC_PALMAS=y
+CONFIG_DM_REGULATOR_PALMAS=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
 CONFIG_DM_SPI=y
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v5 6/6] configs: am57xx_evm_defconfig: Enable CMD_REG option
  2016-09-28  4:27 [U-Boot] [PATCH v5 0/6] power: pmic: Add support for Palmas family of PMICs Keerthy
                   ` (4 preceding siblings ...)
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 5/6] configs: am57xx_evm_defconfig: " Keerthy
@ 2016-09-28  4:27 ` Keerthy
  2016-10-01  2:17   ` Tom Rini
  2016-09-28  4:29 ` [U-Boot] [PATCH v5 0/6] power: pmic: Add support for Palmas family of PMICs Keerthy
  6 siblings, 1 reply; 14+ messages in thread
From: Keerthy @ 2016-09-28  4:27 UTC (permalink / raw)
  To: u-boot

Enable CMD_REG option.

Signed-off-by: Keerthy <j-keerthy@ti.com>
---
 configs/am57xx_evm_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/am57xx_evm_defconfig b/configs/am57xx_evm_defconfig
index 6c60d9b..38424e6 100644
--- a/configs/am57xx_evm_defconfig
+++ b/configs/am57xx_evm_defconfig
@@ -28,6 +28,7 @@ CONFIG_CMD_GPIO=y
 CONFIG_CMD_DHCP=y
 CONFIG_CMD_MII=y
 CONFIG_CMD_PING=y
+CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
@@ -45,6 +46,7 @@ CONFIG_SPI_FLASH_BAR=y
 CONFIG_SPI_FLASH_SPANSION=y
 CONFIG_DM_PMIC=y
 CONFIG_PMIC_PALMAS=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_PALMAS=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v5 0/6] power: pmic: Add support for Palmas family of PMICs
  2016-09-28  4:27 [U-Boot] [PATCH v5 0/6] power: pmic: Add support for Palmas family of PMICs Keerthy
                   ` (5 preceding siblings ...)
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 6/6] configs: am57xx_evm_defconfig: Enable CMD_REG option Keerthy
@ 2016-09-28  4:29 ` Keerthy
  6 siblings, 0 replies; 14+ messages in thread
From: Keerthy @ 2016-09-28  4:29 UTC (permalink / raw)
  To: u-boot

Simon,

On Wednesday 28 September 2016 09:57 AM, Keerthy wrote:
> The series adds support for Palmas family of PMICs.
> Implements functions to configure regulators. Enable/Disable
> Get/Set voltages of regulators.
>
> Supports TPS659038, TPS65917, Palmas.
>
> Tested on TPS659038, TPS65917 using DRA7XX-EVM and AM57XX-EVM.
>

I have removed direct i2c read/write calls from regulator driver and 
introduced pmic read/write functions. Let me know if you are okay with 
series.

Regards,
Keerthy

> Changes in v5:
>
> removed u8 i2c read/write functions made use of already
> existing functions.
>
> Added read/write functions.
>
> Changes in v4:
>
> Added Reviewed-by and a minor change from printf to debug.
>
> Changes in v3:
>
> Introduced u8 i2c read/write functions.
>
> Keerthy (6):
>   power: regulator: Add ctrl_reg and volt_reg fields for pmic
>   power: pmic: Palmas: Add the base pmic support
>   power: regulator: palmas: Add regulator support
>   configs: dra7xx_evm_defconfig: Enable PALMAS options
>   configs: am57xx_evm_defconfig: Enable PALMAS options
>   configs: am57xx_evm_defconfig: Enable CMD_REG option
>
>  configs/am57xx_evm_defconfig               |   5 +
>  configs/dra7xx_evm_defconfig               |   3 +
>  drivers/power/pmic/Kconfig                 |   7 +
>  drivers/power/pmic/Makefile                |   1 +
>  drivers/power/pmic/palmas.c                | 108 +++++++
>  drivers/power/regulator/Kconfig            |   8 +
>  drivers/power/regulator/Makefile           |   1 +
>  drivers/power/regulator/palmas_regulator.c | 453 +++++++++++++++++++++++++++++
>  include/power/palmas.h                     |  25 ++
>  include/power/regulator.h                  |   4 +
>  10 files changed, 615 insertions(+)
>  create mode 100644 drivers/power/pmic/palmas.c
>  create mode 100644 drivers/power/regulator/palmas_regulator.c
>  create mode 100644 include/power/palmas.h
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v5 2/6] power: pmic: Palmas: Add the base pmic support
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 2/6] power: pmic: Palmas: Add the base pmic support Keerthy
@ 2016-09-28 17:51   ` Simon Glass
  2016-09-29  6:02     ` Keerthy
  0 siblings, 1 reply; 14+ messages in thread
From: Simon Glass @ 2016-09-28 17:51 UTC (permalink / raw)
  To: u-boot

Hi Keerthy,

On 27 September 2016 at 22:27, Keerthy <j-keerthy@ti.com> wrote:
> 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>
> ---
>
> Changes in v5:
>
>   * Added pmic read/write functions.
>
>  drivers/power/pmic/Kconfig  |   7 +++
>  drivers/power/pmic/Makefile |   1 +
>  drivers/power/pmic/palmas.c | 108 ++++++++++++++++++++++++++++++++++++++++++++
>  include/power/palmas.h      |  25 ++++++++++
>  4 files changed, 141 insertions(+)
>  create mode 100644 drivers/power/pmic/palmas.c
>  create mode 100644 include/power/palmas.h
>
> diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
> index 69f8d51..92931c5 100644
> --- a/drivers/power/pmic/Kconfig
> +++ b/drivers/power/pmic/Kconfig
> @@ -135,3 +135,10 @@ 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_PALMAS
> +       bool "Enable driver for Texas Instruments PALMAS PMIC"
> +       depends on DM_PMIC
> +       ---help---
> +       The PALMAS is a PMIC containing several LDOs, SMPS.
> +       This driver binds the pmic children.
> diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
> index 52b4f71..828c0cf 100644
> --- a/drivers/power/pmic/Makefile
> +++ b/drivers/power/pmic/Makefile
> @@ -15,6 +15,7 @@ obj-$(CONFIG_PMIC_PM8916) += pm8916.o
>  obj-$(CONFIG_PMIC_RK808) += rk808.o
>  obj-$(CONFIG_PMIC_TPS65090) += tps65090.o
>  obj-$(CONFIG_PMIC_S5M8767) += s5m8767.o
> +obj-$(CONFIG_$(SPL_)PMIC_PALMAS) += palmas.o
>
>  obj-$(CONFIG_POWER_LTC3676) += pmic_ltc3676.o
>  obj-$(CONFIG_POWER_MAX77696) += pmic_max77696.o
> diff --git a/drivers/power/pmic/palmas.c b/drivers/power/pmic/palmas.c
> new file mode 100644
> index 0000000..1d2bd67
> --- /dev/null
> +++ b/drivers/power/pmic/palmas.c
> @@ -0,0 +1,108 @@
> +/*
> + * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
> + * Keerthy <j-keerthy@ti.com>
> + *
> + * SPDX-License-Identifier:    GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <fdtdec.h>
> +#include <errno.h>
> +#include <dm.h>
> +#include <i2c.h>
> +#include <power/pmic.h>
> +#include <power/regulator.h>
> +#include <power/palmas.h>
> +#include <dm/device.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +static const struct pmic_child_info pmic_children_info[] = {
> +       { .prefix = "ldo", .driver = PALMAS_LDO_DRIVER },
> +       { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER },
> +       { },
> +};
> +
> +static int palmas_write(struct udevice *dev, uint reg, const uint8_t *buff,
> +                         int len)
> +{
> +       if (dm_i2c_reg_write(dev, reg, *buff)) {

I think this should be dm_i2c_write(). You are only writing a single byte.

> +               error("write error to device: %p register: %#x!", dev, reg);
> +               return -EIO;
> +       }
> +
> +       return 0;
> +}
> +
> +static int palmas_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
> +{
> +       int ret;
> +
> +       ret = dm_i2c_reg_read(dev, reg);

dm_i2c_read()

> +       if (ret < 0) {
> +               error("read error %d from device: %p register: %#x!", ret, dev,
> +                     reg);
> +               return -EIO;
> +       }
> +
> +       return ret;
> +}

[...]

Regards,
Simon

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v5 2/6] power: pmic: Palmas: Add the base pmic support
  2016-09-28 17:51   ` Simon Glass
@ 2016-09-29  6:02     ` Keerthy
  2016-09-29  6:11       ` Keerthy
  0 siblings, 1 reply; 14+ messages in thread
From: Keerthy @ 2016-09-29  6:02 UTC (permalink / raw)
  To: u-boot



On Wednesday 28 September 2016 11:21 PM, Simon Glass wrote:
> Hi Keerthy,
>
> On 27 September 2016 at 22:27, Keerthy <j-keerthy@ti.com> wrote:
>> 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>
>> ---
>>
>> Changes in v5:
>>
>>   * Added pmic read/write functions.
>>
>>  drivers/power/pmic/Kconfig  |   7 +++
>>  drivers/power/pmic/Makefile |   1 +
>>  drivers/power/pmic/palmas.c | 108 ++++++++++++++++++++++++++++++++++++++++++++
>>  include/power/palmas.h      |  25 ++++++++++
>>  4 files changed, 141 insertions(+)
>>  create mode 100644 drivers/power/pmic/palmas.c
>>  create mode 100644 include/power/palmas.h
>>
>> diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
>> index 69f8d51..92931c5 100644
>> --- a/drivers/power/pmic/Kconfig
>> +++ b/drivers/power/pmic/Kconfig
>> @@ -135,3 +135,10 @@ 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_PALMAS
>> +       bool "Enable driver for Texas Instruments PALMAS PMIC"
>> +       depends on DM_PMIC
>> +       ---help---
>> +       The PALMAS is a PMIC containing several LDOs, SMPS.
>> +       This driver binds the pmic children.
>> diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
>> index 52b4f71..828c0cf 100644
>> --- a/drivers/power/pmic/Makefile
>> +++ b/drivers/power/pmic/Makefile
>> @@ -15,6 +15,7 @@ obj-$(CONFIG_PMIC_PM8916) += pm8916.o
>>  obj-$(CONFIG_PMIC_RK808) += rk808.o
>>  obj-$(CONFIG_PMIC_TPS65090) += tps65090.o
>>  obj-$(CONFIG_PMIC_S5M8767) += s5m8767.o
>> +obj-$(CONFIG_$(SPL_)PMIC_PALMAS) += palmas.o
>>
>>  obj-$(CONFIG_POWER_LTC3676) += pmic_ltc3676.o
>>  obj-$(CONFIG_POWER_MAX77696) += pmic_max77696.o
>> diff --git a/drivers/power/pmic/palmas.c b/drivers/power/pmic/palmas.c
>> new file mode 100644
>> index 0000000..1d2bd67
>> --- /dev/null
>> +++ b/drivers/power/pmic/palmas.c
>> @@ -0,0 +1,108 @@
>> +/*
>> + * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
>> + * Keerthy <j-keerthy@ti.com>
>> + *
>> + * SPDX-License-Identifier:    GPL-2.0+
>> + */
>> +
>> +#include <common.h>
>> +#include <fdtdec.h>
>> +#include <errno.h>
>> +#include <dm.h>
>> +#include <i2c.h>
>> +#include <power/pmic.h>
>> +#include <power/regulator.h>
>> +#include <power/palmas.h>
>> +#include <dm/device.h>
>> +
>> +DECLARE_GLOBAL_DATA_PTR;
>> +
>> +static const struct pmic_child_info pmic_children_info[] = {
>> +       { .prefix = "ldo", .driver = PALMAS_LDO_DRIVER },
>> +       { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER },
>> +       { },
>> +};
>> +
>> +static int palmas_write(struct udevice *dev, uint reg, const uint8_t *buff,
>> +                         int len)
>> +{
>> +       if (dm_i2c_reg_write(dev, reg, *buff)) {
>
> I think this should be dm_i2c_write(). You are only writing a single byte.

Now the v2 of this series had comments suggesting the opposite:

https://www.mail-archive.com/u-boot at lists.denx.de/msg225123.html

>
>> +               error("write error to device: %p register: %#x!", dev, reg);
>> +               return -EIO;
>> +       }
>> +
>> +       return 0;
>> +}
>> +
>> +static int palmas_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
>> +{
>> +       int ret;
>> +
>> +       ret = dm_i2c_reg_read(dev, reg);
>
> dm_i2c_read()
>
>> +       if (ret < 0) {
>> +               error("read error %d from device: %p register: %#x!", ret, dev,
>> +                     reg);
>> +               return -EIO;
>> +       }
>> +
>> +       return ret;
>> +}
>
> [...]
>
> Regards,
> Simon
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v5 2/6] power: pmic: Palmas: Add the base pmic support
  2016-09-29  6:02     ` Keerthy
@ 2016-09-29  6:11       ` Keerthy
  2016-09-29 23:42         ` Simon Glass
  0 siblings, 1 reply; 14+ messages in thread
From: Keerthy @ 2016-09-29  6:11 UTC (permalink / raw)
  To: u-boot



On Thursday 29 September 2016 11:32 AM, Keerthy wrote:
>
>
> On Wednesday 28 September 2016 11:21 PM, Simon Glass wrote:
>> Hi Keerthy,
>>
>> On 27 September 2016 at 22:27, Keerthy <j-keerthy@ti.com> wrote:
>>> 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>
>>> ---
>>>
>>> Changes in v5:
>>>
>>>   * Added pmic read/write functions.
>>>
>>>  drivers/power/pmic/Kconfig  |   7 +++
>>>  drivers/power/pmic/Makefile |   1 +
>>>  drivers/power/pmic/palmas.c | 108
>>> ++++++++++++++++++++++++++++++++++++++++++++
>>>  include/power/palmas.h      |  25 ++++++++++
>>>  4 files changed, 141 insertions(+)
>>>  create mode 100644 drivers/power/pmic/palmas.c
>>>  create mode 100644 include/power/palmas.h
>>>
>>> diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
>>> index 69f8d51..92931c5 100644
>>> --- a/drivers/power/pmic/Kconfig
>>> +++ b/drivers/power/pmic/Kconfig
>>> @@ -135,3 +135,10 @@ 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_PALMAS
>>> +       bool "Enable driver for Texas Instruments PALMAS PMIC"
>>> +       depends on DM_PMIC
>>> +       ---help---
>>> +       The PALMAS is a PMIC containing several LDOs, SMPS.
>>> +       This driver binds the pmic children.
>>> diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
>>> index 52b4f71..828c0cf 100644
>>> --- a/drivers/power/pmic/Makefile
>>> +++ b/drivers/power/pmic/Makefile
>>> @@ -15,6 +15,7 @@ obj-$(CONFIG_PMIC_PM8916) += pm8916.o
>>>  obj-$(CONFIG_PMIC_RK808) += rk808.o
>>>  obj-$(CONFIG_PMIC_TPS65090) += tps65090.o
>>>  obj-$(CONFIG_PMIC_S5M8767) += s5m8767.o
>>> +obj-$(CONFIG_$(SPL_)PMIC_PALMAS) += palmas.o
>>>
>>>  obj-$(CONFIG_POWER_LTC3676) += pmic_ltc3676.o
>>>  obj-$(CONFIG_POWER_MAX77696) += pmic_max77696.o
>>> diff --git a/drivers/power/pmic/palmas.c b/drivers/power/pmic/palmas.c
>>> new file mode 100644
>>> index 0000000..1d2bd67
>>> --- /dev/null
>>> +++ b/drivers/power/pmic/palmas.c
>>> @@ -0,0 +1,108 @@
>>> +/*
>>> + * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
>>> + * Keerthy <j-keerthy@ti.com>
>>> + *
>>> + * SPDX-License-Identifier:    GPL-2.0+
>>> + */
>>> +
>>> +#include <common.h>
>>> +#include <fdtdec.h>
>>> +#include <errno.h>
>>> +#include <dm.h>
>>> +#include <i2c.h>
>>> +#include <power/pmic.h>
>>> +#include <power/regulator.h>
>>> +#include <power/palmas.h>
>>> +#include <dm/device.h>
>>> +
>>> +DECLARE_GLOBAL_DATA_PTR;
>>> +
>>> +static const struct pmic_child_info pmic_children_info[] = {
>>> +       { .prefix = "ldo", .driver = PALMAS_LDO_DRIVER },
>>> +       { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER },
>>> +       { },
>>> +};
>>> +
>>> +static int palmas_write(struct udevice *dev, uint reg, const uint8_t
>>> *buff,
>>> +                         int len)
>>> +{
>>> +       if (dm_i2c_reg_write(dev, reg, *buff)) {
>>
>> I think this should be dm_i2c_write(). You are only writing a single
>> byte.
>
> Now the v2 of this series had comments suggesting the opposite:
>
> https://www.mail-archive.com/u-boot at lists.denx.de/msg225123.html

And i thought dm_i2c_reg_write/read was specifically introduced for 
writing and reading one byte value?

int dm_i2c_reg_write(struct udevice *dev, uint offset, uint value)
{
         uint8_t val = value;

         return dm_i2c_write(dev, offset, &val, 1);
}

Regards,
Keerthy
>
>>
>>> +               error("write error to device: %p register: %#x!",
>>> dev, reg);
>>> +               return -EIO;
>>> +       }
>>> +
>>> +       return 0;
>>> +}
>>> +
>>> +static int palmas_read(struct udevice *dev, uint reg, uint8_t *buff,
>>> int len)
>>> +{
>>> +       int ret;
>>> +
>>> +       ret = dm_i2c_reg_read(dev, reg);
>>
>> dm_i2c_read()
>>
>>> +       if (ret < 0) {
>>> +               error("read error %d from device: %p register: %#x!",
>>> ret, dev,
>>> +                     reg);
>>> +               return -EIO;
>>> +       }
>>> +
>>> +       return ret;
>>> +}
>>
>> [...]
>>
>> Regards,
>> Simon
>>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v5 2/6] power: pmic: Palmas: Add the base pmic support
  2016-09-29  6:11       ` Keerthy
@ 2016-09-29 23:42         ` Simon Glass
  2016-09-30  3:18           ` Keerthy
  0 siblings, 1 reply; 14+ messages in thread
From: Simon Glass @ 2016-09-29 23:42 UTC (permalink / raw)
  To: u-boot

Hi Keethy,

On 29 September 2016 at 00:11, Keerthy <a0393675@ti.com> wrote:
>
>
> On Thursday 29 September 2016 11:32 AM, Keerthy wrote:
>>
>>
>>
>> On Wednesday 28 September 2016 11:21 PM, Simon Glass wrote:
>>>
>>> Hi Keerthy,
>>>
>>> On 27 September 2016 at 22:27, Keerthy <j-keerthy@ti.com> wrote:
>>>>
>>>> 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>
>>>> ---
>>>>
>>>> Changes in v5:
>>>>
>>>>   * Added pmic read/write functions.
>>>>
>>>>  drivers/power/pmic/Kconfig  |   7 +++
>>>>  drivers/power/pmic/Makefile |   1 +
>>>>  drivers/power/pmic/palmas.c | 108
>>>> ++++++++++++++++++++++++++++++++++++++++++++
>>>>  include/power/palmas.h      |  25 ++++++++++
>>>>  4 files changed, 141 insertions(+)
>>>>  create mode 100644 drivers/power/pmic/palmas.c
>>>>  create mode 100644 include/power/palmas.h
>>>>
>>>> diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
>>>> index 69f8d51..92931c5 100644
>>>> --- a/drivers/power/pmic/Kconfig
>>>> +++ b/drivers/power/pmic/Kconfig
>>>> @@ -135,3 +135,10 @@ 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_PALMAS
>>>> +       bool "Enable driver for Texas Instruments PALMAS PMIC"
>>>> +       depends on DM_PMIC
>>>> +       ---help---
>>>> +       The PALMAS is a PMIC containing several LDOs, SMPS.
>>>> +       This driver binds the pmic children.
>>>> diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
>>>> index 52b4f71..828c0cf 100644
>>>> --- a/drivers/power/pmic/Makefile
>>>> +++ b/drivers/power/pmic/Makefile
>>>> @@ -15,6 +15,7 @@ obj-$(CONFIG_PMIC_PM8916) += pm8916.o
>>>>  obj-$(CONFIG_PMIC_RK808) += rk808.o
>>>>  obj-$(CONFIG_PMIC_TPS65090) += tps65090.o
>>>>  obj-$(CONFIG_PMIC_S5M8767) += s5m8767.o
>>>> +obj-$(CONFIG_$(SPL_)PMIC_PALMAS) += palmas.o
>>>>
>>>>  obj-$(CONFIG_POWER_LTC3676) += pmic_ltc3676.o
>>>>  obj-$(CONFIG_POWER_MAX77696) += pmic_max77696.o
>>>> diff --git a/drivers/power/pmic/palmas.c b/drivers/power/pmic/palmas.c
>>>> new file mode 100644
>>>> index 0000000..1d2bd67
>>>> --- /dev/null
>>>> +++ b/drivers/power/pmic/palmas.c
>>>> @@ -0,0 +1,108 @@
>>>> +/*
>>>> + * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
>>>> + * Keerthy <j-keerthy@ti.com>
>>>> + *
>>>> + * SPDX-License-Identifier:    GPL-2.0+
>>>> + */
>>>> +
>>>> +#include <common.h>
>>>> +#include <fdtdec.h>
>>>> +#include <errno.h>
>>>> +#include <dm.h>
>>>> +#include <i2c.h>
>>>> +#include <power/pmic.h>
>>>> +#include <power/regulator.h>
>>>> +#include <power/palmas.h>
>>>> +#include <dm/device.h>
>>>> +
>>>> +DECLARE_GLOBAL_DATA_PTR;
>>>> +
>>>> +static const struct pmic_child_info pmic_children_info[] = {
>>>> +       { .prefix = "ldo", .driver = PALMAS_LDO_DRIVER },
>>>> +       { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER },
>>>> +       { },
>>>> +};
>>>> +
>>>> +static int palmas_write(struct udevice *dev, uint reg, const uint8_t
>>>> *buff,
>>>> +                         int len)
>>>> +{
>>>> +       if (dm_i2c_reg_write(dev, reg, *buff)) {
>>>
>>>
>>> I think this should be dm_i2c_write(). You are only writing a single
>>> byte.
>>
>>
>> Now the v2 of this series had comments suggesting the opposite:
>>
>> https://www.mail-archive.com/u-boot at lists.denx.de/msg225123.html
>
>
> And i thought dm_i2c_reg_write/read was specifically introduced for writing
> and reading one byte value?
>
> int dm_i2c_reg_write(struct udevice *dev, uint offset, uint value)
> {
>         uint8_t val = value;
>
>         return dm_i2c_write(dev, offset, &val, 1);
> }

Yes, but your palmas_write() function should be able to write multiple
bytes. If you look at the function signature and the comments in
pmic.h you should be able to see that.

[...]

Regards,
Simon

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v5 2/6] power: pmic: Palmas: Add the base pmic support
  2016-09-29 23:42         ` Simon Glass
@ 2016-09-30  3:18           ` Keerthy
  0 siblings, 0 replies; 14+ messages in thread
From: Keerthy @ 2016-09-30  3:18 UTC (permalink / raw)
  To: u-boot



On Friday 30 September 2016 05:12 AM, Simon Glass wrote:
> Hi Keethy,
>
> On 29 September 2016 at 00:11, Keerthy <a0393675@ti.com> wrote:
>>
>>
>> On Thursday 29 September 2016 11:32 AM, Keerthy wrote:
>>>
>>>
>>>
>>> On Wednesday 28 September 2016 11:21 PM, Simon Glass wrote:
>>>>
>>>> Hi Keerthy,
>>>>
>>>> On 27 September 2016 at 22:27, Keerthy <j-keerthy@ti.com> wrote:
>>>>>
>>>>> 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>
>>>>> ---
>>>>>
>>>>> Changes in v5:
>>>>>
>>>>>   * Added pmic read/write functions.
>>>>>
>>>>>  drivers/power/pmic/Kconfig  |   7 +++
>>>>>  drivers/power/pmic/Makefile |   1 +
>>>>>  drivers/power/pmic/palmas.c | 108
>>>>> ++++++++++++++++++++++++++++++++++++++++++++
>>>>>  include/power/palmas.h      |  25 ++++++++++
>>>>>  4 files changed, 141 insertions(+)
>>>>>  create mode 100644 drivers/power/pmic/palmas.c
>>>>>  create mode 100644 include/power/palmas.h
>>>>>
>>>>> diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
>>>>> index 69f8d51..92931c5 100644
>>>>> --- a/drivers/power/pmic/Kconfig
>>>>> +++ b/drivers/power/pmic/Kconfig
>>>>> @@ -135,3 +135,10 @@ 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_PALMAS
>>>>> +       bool "Enable driver for Texas Instruments PALMAS PMIC"
>>>>> +       depends on DM_PMIC
>>>>> +       ---help---
>>>>> +       The PALMAS is a PMIC containing several LDOs, SMPS.
>>>>> +       This driver binds the pmic children.
>>>>> diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
>>>>> index 52b4f71..828c0cf 100644
>>>>> --- a/drivers/power/pmic/Makefile
>>>>> +++ b/drivers/power/pmic/Makefile
>>>>> @@ -15,6 +15,7 @@ obj-$(CONFIG_PMIC_PM8916) += pm8916.o
>>>>>  obj-$(CONFIG_PMIC_RK808) += rk808.o
>>>>>  obj-$(CONFIG_PMIC_TPS65090) += tps65090.o
>>>>>  obj-$(CONFIG_PMIC_S5M8767) += s5m8767.o
>>>>> +obj-$(CONFIG_$(SPL_)PMIC_PALMAS) += palmas.o
>>>>>
>>>>>  obj-$(CONFIG_POWER_LTC3676) += pmic_ltc3676.o
>>>>>  obj-$(CONFIG_POWER_MAX77696) += pmic_max77696.o
>>>>> diff --git a/drivers/power/pmic/palmas.c b/drivers/power/pmic/palmas.c
>>>>> new file mode 100644
>>>>> index 0000000..1d2bd67
>>>>> --- /dev/null
>>>>> +++ b/drivers/power/pmic/palmas.c
>>>>> @@ -0,0 +1,108 @@
>>>>> +/*
>>>>> + * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
>>>>> + * Keerthy <j-keerthy@ti.com>
>>>>> + *
>>>>> + * SPDX-License-Identifier:    GPL-2.0+
>>>>> + */
>>>>> +
>>>>> +#include <common.h>
>>>>> +#include <fdtdec.h>
>>>>> +#include <errno.h>
>>>>> +#include <dm.h>
>>>>> +#include <i2c.h>
>>>>> +#include <power/pmic.h>
>>>>> +#include <power/regulator.h>
>>>>> +#include <power/palmas.h>
>>>>> +#include <dm/device.h>
>>>>> +
>>>>> +DECLARE_GLOBAL_DATA_PTR;
>>>>> +
>>>>> +static const struct pmic_child_info pmic_children_info[] = {
>>>>> +       { .prefix = "ldo", .driver = PALMAS_LDO_DRIVER },
>>>>> +       { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER },
>>>>> +       { },
>>>>> +};
>>>>> +
>>>>> +static int palmas_write(struct udevice *dev, uint reg, const uint8_t
>>>>> *buff,
>>>>> +                         int len)
>>>>> +{
>>>>> +       if (dm_i2c_reg_write(dev, reg, *buff)) {
>>>>
>>>>
>>>> I think this should be dm_i2c_write(). You are only writing a single
>>>> byte.
>>>
>>>
>>> Now the v2 of this series had comments suggesting the opposite:
>>>
>>> https://www.mail-archive.com/u-boot at lists.denx.de/msg225123.html
>>
>>
>> And i thought dm_i2c_reg_write/read was specifically introduced for writing
>> and reading one byte value?
>>
>> int dm_i2c_reg_write(struct udevice *dev, uint offset, uint value)
>> {
>>         uint8_t val = value;
>>
>>         return dm_i2c_write(dev, offset, &val, 1);
>> }
>
> Yes, but your palmas_write() function should be able to write multiple
> bytes. If you look at the function signature and the comments in
> pmic.h you should be able to see that.

Okay.

>
> [...]
>
> Regards,
> Simon
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v5 6/6] configs: am57xx_evm_defconfig: Enable CMD_REG option
  2016-09-28  4:27 ` [U-Boot] [PATCH v5 6/6] configs: am57xx_evm_defconfig: Enable CMD_REG option Keerthy
@ 2016-10-01  2:17   ` Tom Rini
  0 siblings, 0 replies; 14+ messages in thread
From: Tom Rini @ 2016-10-01  2:17 UTC (permalink / raw)
  To: u-boot

On Wed, Sep 28, 2016 at 09:57:31AM +0530, Keerthy wrote:

> Enable CMD_REG option.
> 
> Signed-off-by: Keerthy <j-keerthy@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160930/32a6ba09/attachment.sig>

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2016-10-01  2:17 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-28  4:27 [U-Boot] [PATCH v5 0/6] power: pmic: Add support for Palmas family of PMICs Keerthy
2016-09-28  4:27 ` [U-Boot] [PATCH v5 1/6] power: regulator: Add ctrl_reg and volt_reg fields for pmic Keerthy
2016-09-28  4:27 ` [U-Boot] [PATCH v5 2/6] power: pmic: Palmas: Add the base pmic support Keerthy
2016-09-28 17:51   ` Simon Glass
2016-09-29  6:02     ` Keerthy
2016-09-29  6:11       ` Keerthy
2016-09-29 23:42         ` Simon Glass
2016-09-30  3:18           ` Keerthy
2016-09-28  4:27 ` [U-Boot] [PATCH v5 3/6] power: regulator: palmas: Add regulator support Keerthy
2016-09-28  4:27 ` [U-Boot] [PATCH v5 4/6] configs: dra7xx_evm_defconfig: Enable PALMAS options Keerthy
2016-09-28  4:27 ` [U-Boot] [PATCH v5 5/6] configs: am57xx_evm_defconfig: " Keerthy
2016-09-28  4:27 ` [U-Boot] [PATCH v5 6/6] configs: am57xx_evm_defconfig: Enable CMD_REG option Keerthy
2016-10-01  2:17   ` Tom Rini
2016-09-28  4:29 ` [U-Boot] [PATCH v5 0/6] power: pmic: Add support for Palmas family of PMICs Keerthy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox