Skip to contentSkip to conversation

Regulator: LP3972 PMIC regulator driver

PATCH Applied Axel Lin 3 participants 3 messages Sep 16, 2010 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 Regulator: LP3972 PMIC regulator driver

This patch adds regulator drivers for National Semiconductors LP3972 PMIC. This LP3972 PMIC controller has 3 DC/DC voltage converters and 5 low drop-out (LDO) regulators. LP3972 PMIC controller uses I2C interface.

---
 drivers/regulator/Kconfig        |    7 +
 drivers/regulator/Makefile       |    1 +
 drivers/regulator/lp3972.c       |  649 ++++++++++++++++++++++++++++++++++++++
 include/linux/regulator/lp3972.h |   48 +++
 4 files changed, 705 insertions(+), 0 deletions(-)
 create mode 100644 drivers/regulator/lp3972.c
 create mode 100644 include/linux/regulator/lp3972.h
drivers/regulator/Kconfig +7 -0
index 4889caa..dd30e88 100644
@@ -172,6 +172,13 @@ config REGULATOR_LP3971
 	 Say Y here to support the voltage regulators and convertors
 	 on National Semiconductors LP3971 PMIC
 
+config REGULATOR_LP3972
+	tristate "National Semiconductors LP3972 PMIC regulator driver"
+	depends on I2C
+	help
+	 Say Y here to support the voltage regulators and convertors
+	 on National Semiconductors LP3972 PMIC
+
 config REGULATOR_PCAP
 	tristate "PCAP2 regulator driver"
 	depends on EZX_PCAP
drivers/regulator/Makefile +1 -0
index beff6da..6cae641 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o
 obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
 obj-$(CONFIG_REGULATOR_DUMMY) += dummy.o
 obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
+obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o
 obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
 obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o
 obj-$(CONFIG_REGULATOR_MAX8649)	+= max8649.o
drivers/regulator/lp3972.c new file +649 -0

649 lines not on this page · raw message

include/linux/regulator/lp3972.h new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
1.7.2
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Axel Lin

This patch adds regulator drivers for National Semiconductors LP3972 PMIC. This LP3972 PMIC controller has 3 DC/DC voltage converters and 5 low drop-out (LDO) regulators. LP3972 PMIC controller uses I2C interface.

but a few things below which it'd be good to fix up incrementally.

drivers/regulator/lp3972.c line 177

Quoted 2 lines
drivers/regulator/lp3972.c new file +2 -0
+#define LP3972_LDO_VOL_MIN_IDX(x) (((x) == 4) ? 0x05 : 0x00)
+#define LP3972_LDO_VOL_MAX_IDX(x) ((x) ? (((x) == 4) ? 0x1f : 0x0f) : 0x0c)

I suspect that writing these out as inline functions without the ternery operator would be rather more legible.

drivers/regulator/lp3972.c line 195

Quoted 3 lines
drivers/regulator/lp3972.c new file +3 -0
+	ret = i2c_smbus_read_byte_data(i2c, reg);
+	if (ret < 0)
+		return -EIO;

Better to return the actual error you got.

drivers/regulator/lp3972.c line 218

Quoted 10 lines
drivers/regulator/lp3972.c new file +10 -0
+static u8 lp3972_reg_read(struct lp3972 *lp3972, u8 reg)
+{
+	u16 val = 0;
+
+	mutex_lock(&lp3972->io_lock);
+
+	lp3972_i2c_read(lp3972->i2c, reg, 1, &val);
+
+	dev_dbg(lp3972->dev, "reg read 0x%02x -> 0x%02x\n", (int)reg,
+		(unsigned)val&0xff);

Some spaces here would be helpful for legiblility.

Quoted 4 lines
drivers/regulator/lp3972.c new file +4 -0
+	switch (ldo) {
+	case LP3972_LDO1:
+	case LP3972_LDO5:
+		shift = LP3972_LDO_VOL_CHANGE_SHIFT(ldo);

drivers/regulator/lp3972.c line 336

Quoted 10 lines
drivers/regulator/lp3972.c new file +10 -0
+		ret = lp3972_set_bits(lp3972, LP3972_VOL_CHANGE_REG,
+			LP3972_VOL_CHANGE_FLAG_MASK << shift,
+			LP3972_VOL_CHANGE_FLAG_GO << shift);
+		if (ret)
+			return ret;
+
+		ret = lp3972_set_bits(lp3972, LP3972_VOL_CHANGE_REG,
+			LP3972_VOL_CHANGE_FLAG_MASK << shift, 0);
+		break;
+	}

A comment explaining why it's OK to only handle these two LDOs here would be helpful.

drivers/regulator/lp3972.c line 404

Quoted 6 lines
drivers/regulator/lp3972.c new file +6 -0
+	reg &= LP3972_BUCK_VOL_MASK;
+	if (reg <= LP3972_BUCK_VOL_MAX_IDX(buck))
+		val = 1000 * buck_voltage_map[buck][reg];
+	else {
+		val = 0;
+		dev_warn(&dev->dev, "chip reported incorrect voltage value.\n");

Logging the value would be useful for diagnostics.

drivers/regulator/lp3972.c line 527

Quoted 2 lines
drivers/regulator/lp3972.c new file +2 -0
+static int setup_regulators(struct lp3972 *lp3972,
+	struct lp3972_platform_data *pdata)

This could be flagged as __devinit.

drivers/regulator/lp3972.c line 591

Quoted 7 lines
drivers/regulator/lp3972.c new file +7 -0
+	/* Detect LP3972 */
+	ret = lp3972_i2c_read(i2c, LP3972_SYS_CONTROL1_REG, 1, &val);
+	if (ret == 0 && (val & SYS_CONTROL1_INIT_MASK) != SYS_CONTROL1_INIT_VAL)
+		ret = -ENODEV;
+	if (ret < 0) {
+		dev_err(&i2c->dev, "failed to detect device\n");
+		goto err_detect;

Again, logging the rejected value is useful.

#2 lore raw
Quoted 10 lines · Mark Brown
Quoted 1 line · Axel Lin

This patch adds regulator drivers for National Semiconductors LP3972

PMIC.

Quoted 1 line

This LP3972 PMIC controller has 3 DC/DC voltage converters and 5 low

drop-out

Quoted 3 lines

(LDO) regulators. LP3972 PMIC controller uses I2C interface.

Applied.

Thanks

Liam

Signature · 3 lines
Freelance Developer, SlimLogic Ltd
ASoC and Voltage Regulator Maintainer.
http://www.slimlogic.co.uk