Skip to contentSkip to conversation

tps80031: Add mfd and regulator driver

PATCH Superseded Laxman Dewangan 2 participants 8 messages Nov 5, 2012 – Nov 6, 2012

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover tps80031: Add mfd and regulator driver

This patch series supports mfd core and regulator driver for the Texas Instruments TPS80031/ TPS80032 Fully Integrated Power Management with Power Path and Battery Charger. The device provides five configurable step-down converters, 11 general purpose LDOs, USB OTG Module, ADC, RTC, 2 PWM, System Voltage Regulator/Battery Charger with Power Path from USB, 32K clock generator.

Laxman Dewangan (2):
mfd: add TI TPS80031 mfd core driver
regulator: tps80031: add regulator driver for tps80031

 drivers/mfd/Kconfig                    |   14 +
 drivers/mfd/Makefile                   |    1 +
 drivers/mfd/tps80031.c                 |  580 ++++++++++++++++++++++
 drivers/regulator/Kconfig              |    9 +
 drivers/regulator/Makefile             |    1 +
 drivers/regulator/tps80031-regulator.c |  821 ++++++++++++++++++++++++++++++++
 include/linux/mfd/tps80031.h           |  624 ++++++++++++++++++++++++
 7 files changed, 2050 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/tps80031.c
 create mode 100644 drivers/regulator/tps80031-regulator.c
 create mode 100644 include/linux/mfd/tps80031.h
#1 lore raw

PATCH 1/2 mfd: add TI TPS80031 mfd core driver

TPS80031/ TPS80032 Fully Integrated Power Management with Power Path and Battery Charger. The device provides five configurable step-down converters, 11 general purpose LDOs, USB OTG Module, ADC, RTC, 2 PWM, System Voltage Regulator/Battery Charger with Power Path from USB, 32K clock generator.

Add the mfd core driver for TPS80031/TPS80032.

---
 drivers/mfd/Kconfig          |   14 +
 drivers/mfd/Makefile         |    1 +
 drivers/mfd/tps80031.c       |  580 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/tps80031.h |  569 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1164 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/tps80031.c
 create mode 100644 include/linux/mfd/tps80031.h
drivers/mfd/Kconfig +14 -0
index 637bcdf..a1caf81 100644
@@ -244,6 +244,20 @@ config MFD_TPS65912_SPI
 	  If you say yes here you get support for the TPS65912 series of
 	  PM chips with SPI interface.
 
+config MFD_TPS80031
+	bool "TI TPS80031/TPS80032 Power Management chips"
+	depends on I2C && GENERIC_HARDIRQS
+	select MFD_CORE
+	select REGMAP_I2C
+	select IRQ_DOMAIN
+	help
+	  If you say yes here you get support for the Texas Instruments
+	  TPS80031/ TPS80032 Fully Integrated Power Management with Power
+	  Path and Battery Charger. The device provides five configurable
+	  step-down converters, 11 general purpose LDOs, USB OTG Module,
+	  ADC, RTC, 2 PWM, System Voltage Regulator/Battery Charger with
+	  Power Path from USB, 32K clock generator.
+
 config MENELAUS
 	bool "Texas Instruments TWL92330/Menelaus PM chip"
 	depends on I2C=y && ARCH_OMAP2
drivers/mfd/Makefile +1 -0
index 296817c..3595f2d 100644
@@ -57,6 +57,7 @@ tps65912-objs                   := tps65912-core.o tps65912-irq.o
 obj-$(CONFIG_MFD_TPS65912)	+= tps65912.o
 obj-$(CONFIG_MFD_TPS65912_I2C)	+= tps65912-i2c.o
 obj-$(CONFIG_MFD_TPS65912_SPI)  += tps65912-spi.o
+obj-$(CONFIG_MFD_TPS80031)	+= tps80031.o
 obj-$(CONFIG_MENELAUS)		+= menelaus.o
 
 obj-$(CONFIG_TWL4030_CORE)	+= twl-core.o twl4030-irq.o twl6030-irq.o
drivers/mfd/tps80031.c new file +580 -0

580 lines not on this page · raw message

include/linux/mfd/tps80031.h new file +569 -0

569 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#2 lore raw

Re: [PATCH 1/2] mfd: add TI TPS80031 mfd core driver

On Mon, Nov 05, 2012 at 03:14:17PM +0530, Laxman Dewangan wrote:

Looks pretty good, a few smaller issues though.

drivers/mfd/tps80031.c line 306

Quoted 4 lines
drivers/mfd/tps80031.c new file +4 -0
+static bool is_volatile_reg_id0(struct device *dev, unsigned int reg)
+{
+	return false;
+}

This is the default for all registers, you should not need to provide a function like this.

drivers/mfd/tps80031.c line 464

Quoted 2 lines
drivers/mfd/tps80031.c new file +2 -0
+	dev_info(&client->dev, "Jtag version 0x%02x and Eprom version 0x%02x\n",
+					jtag_ver, ep_ver);

EPROM is an acronym. For TI devices I think normally the ES revision is referred to as just that, otherwise JTAG is an acronym too.

drivers/mfd/tps80031.c line 476

Quoted 7 lines
drivers/mfd/tps80031.c new file +7 -0
+	if (client->irq) {
+		ret = tps80031_irq_init(tps80031, client->irq, pdata->irq_base);
+		if (ret) {
+			dev_err(&client->dev, "IRQ init failed: %d\n", ret);
+			goto fail_client_reg;
+		}
+	}

Since for current kernel versions we're using irqdomains we can set up all the interrupts without an irq. It can make life easier to just always set up the interrupt controller so drivers don't need to worry about it.

drivers/mfd/tps80031.c line 485

Quoted 4 lines
drivers/mfd/tps80031.c new file +4 -0
+	ret = mfd_add_devices(tps80031->dev, -1,
+			tps80031_cell, ARRAY_SIZE(tps80031_cell),
+			NULL, tps80031->irq_base,
+			regmap_irq_get_domain(tps80031->irq_data));

If you're supplying a domain you shouldn't need to provide an irq_base, the domain fulfuls the same role better.

drivers/mfd/tps80031.c line 517

Quoted 9 lines
drivers/mfd/tps80031.c new file +9 -0
+static int __devexit tps80031_remove(struct i2c_client *client)
+{
+	struct tps80031 *tps80031 = i2c_get_clientdata(client);
+	int i;
+
+	mfd_remove_devices(tps80031->dev);
+
+	if (client->irq)
+		free_irq(client->irq, tps80031);

regmap_irq_exit()

drivers/mfd/tps80031.c line 532

Quoted 7 lines
drivers/mfd/tps80031.c new file +7 -0
+#ifdef CONFIG_PM_SLEEP
+static int tps80031_suspend(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+
+	if (client->irq)
+		disable_irq(client->irq);

The interrupt core should take care of this for you if it's important, and note that people often use things like RTC alarms to wake the system.

#3 lore raw

PATCH 2/2 regulator: tps80031: add regulator driver for tps80031

In reply to Laxman Dewangan

Add regulator driver for Texas Instrument TPS80031/TPS80032 device. TPS80031/ TPS80032 Fully Integrated Power Management with Power Path and Battery Charger. It has 5 configurable step-down converters, 11 general purpose LDOs, VBUS generator and digital output to control regulators.

---
 drivers/regulator/Kconfig              |    9 +
 drivers/regulator/Makefile             |    1 +
 drivers/regulator/tps80031-regulator.c |  821 ++++++++++++++++++++++++++++++++
 include/linux/mfd/tps80031.h           |   55 +++
 4 files changed, 886 insertions(+), 0 deletions(-)
 create mode 100644 drivers/regulator/tps80031-regulator.c
drivers/regulator/Kconfig +9 -0
index cbc685d..0ae658f 100644
@@ -426,6 +426,15 @@ config REGULATOR_TPS65912
 	help
 	    This driver supports TPS65912 voltage regulator chip.
 
+config REGULATOR_TPS80031
+	tristate "TI TPS80031/TPS80032 power regualtor driver"
+	depends on MFD_TPS80031
+	help
+	  TPS80031/ TPS80032 Fully Integrated Power Management with Power
+	  Path and Battery Charger. It has 5 configurable step-down
+	  converters, 11 general purpose LDOs, VBUS generator and digital
+	  output to control regulators.
+
 config REGULATOR_TWL4030
 	bool "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC"
 	depends on TWL4030_CORE
drivers/regulator/Makefile +1 -0
index db274dc..6166d12 100644
@@ -57,6 +57,7 @@ obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o
 obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o
 obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o
 obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o
+obj-$(CONFIG_REGULATOR_TPS80031) += tps80031-regulator.o
 obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o
 obj-$(CONFIG_REGULATOR_VEXPRESS) += vexpress.o
 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o
drivers/regulator/tps80031-regulator.c new file +821 -0

821 lines not on this page · raw message

include/linux/mfd/tps80031.h +55 -0

72 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#4 lore raw

Re: [PATCH 2/2] regulator: tps80031: add regulator driver for tps80031

drivers/regulator/tps80031-regulator.c line 162

Quoted 2 lines · Laxman Dewangan
drivers/regulator/tps80031-regulator.c new file +2 -0
+	switch (ri->device_flags) {
+	case 0:

Should we be using different versions of the ops depending on the device flags rather than having these switches? It seems like we can't change at runtime and it would make the code a lot simpler.

drivers/regulator/tps80031-regulator.c line 174

Quoted 12 lines
drivers/regulator/tps80031-regulator.c new file +12 -0
+		if (sel < 57)
+			voltage = 607700 + 12660 * sel;
+		else if (sel == 57)
+			voltage = 1350 * 1000;
+		else if (sel == 58)
+			voltage = 1500 * 1000;
+		else if (sel == 59)
+			voltage = 1800 * 1000;
+		else if (sel == 60)
+			voltage = 1900 * 1000;
+		else if (sel == 61)
+			voltage = 2100 * 1000;

This looks like a switch statement with a default case (as do most of these).

drivers/regulator/tps80031-regulator.c line 312

Quoted 2 lines
drivers/regulator/tps80031-regulator.c new file +2 -0
+	ret = tps80031_write(parent, ri->rinfo->volt_id,
+			ri->rinfo->volt_reg, sel + 1);

Why the + 1 (and - 1 in the get()). I'd expect we can just use the register value directly as a selector.

drivers/regulator/tps80031-regulator.c line 347

Quoted 5 lines
drivers/regulator/tps80031-regulator.c new file +5 -0
+	if (!(ri->config_flags & VBUS_SW_ONLY)) {
+		dev_err(&rdev->dev, "%s() is not supported with flag 0x%08x\n",
+			 __func__, ri->config_flags);
+		return -EIO;
+	}

Same as the device flags above - we should this be set by changing the ops when we register?

#5 lore raw

Re: [PATCH 2/2] regulator: tps80031: add regulator driver for tps80031

Thanks for quickest review.

Quoted 9 lines · Mark Brown

* PGP Signed by an unknown key

drivers/regulator/tps80031-regulator.c line 162

Quoted 2 lines · Laxman Dewangan
drivers/regulator/tps80031-regulator.c new file +2 -0
+	switch (ri->device_flags) {
+	case 0:

Should we be using different versions of the ops depending on the device flags rather than having these switches? It seems like we can't change at runtime and it would make the code a lot simpler.

I have single dcdc ops for all DCDC VIO, SMPS1 to 3.
There is different configuration bit for selecting any DCDC to normal, extended or offset. As this ops are share, I can not change the callbacks. However, I rewrite this apis using tables and equation to reduce code size.

Quoted 2 lines

Why the + 1 (and - 1 in the get()). I'd expect we can just use the register value directly as a selector.

The device sets vout = 0 if vsel = 0 and then equation talk about the Vmin + vsel * step. I exported the Vout minimum as Vmin for sel = 0 and hence this is there.

I will export this in true equation in my next patch.

Quoted 7 lines

drivers/regulator/tps80031-regulator.c line 347

Quoted 5 lines
drivers/regulator/tps80031-regulator.c new file +5 -0
+	if (!(ri->config_flags&  VBUS_SW_ONLY)) {
+		dev_err(&rdev->dev, "%s() is not supported with flag 0x%08x\n",
+			 __func__, ri->config_flags);
+		return -EIO;
+	}

Same as the device flags above - we should this be set by changing the ops when we register?

Ok, so I will have two ops, hw (empty) and sw(implemented). If sw is selected then only sw ops will get initialized and so it will not need any checks.

#6 lore raw

Re: [PATCH 2/2] regulator: tps80031: add regulator driver for tps80031

Quoted 10 lines · Laxman Dewangan
Quoted 3 lines · Mark Brown

Should we be using different versions of the ops depending on the device flags rather than having these switches? It seems like we can't change at runtime and it would make the code a lot simpler.

I have single dcdc ops for all DCDC VIO, SMPS1 to 3. There is different configuration bit for selecting any DCDC to normal, extended or offset. As this ops are share, I can not change the callbacks.

You can change your code so that it changes the ops it registers depending on the configuration.

Quoted 8 lines
Quoted 2 lines

Why the + 1 (and - 1 in the get()). I'd expect we can just use the register value directly as a selector.

The device sets vout = 0 if vsel = 0 and then equation talk about the Vmin + vsel * step.
I exported the Vout minimum as Vmin for sel = 0 and hence this is there.

I will export this in true equation in my next patch.

You can just have list_voltage() return 0 for this voltage - it's OK to have missing selector values.

#7 lore raw

Re: [PATCH 2/2] regulator: tps80031: add regulator driver for tps80031

Quoted 11 lines · Mark Brown

* PGP Signed by an unknown key

Quoted 6 lines · Laxman Dewangan

On Monday 05 November 2012 04:12 PM, Mark Brown wrote:

I have single dcdc ops for all DCDC VIO, SMPS1 to 3. There is different configuration bit for selecting any DCDC to normal, extended or offset. As this ops are share, I can not change the callbacks.

You can change your code so that it changes the ops it registers depending on the configuration.

I rewrote this using the desc.min_uV and desc.step_uV and table in another patch which I posted. This parameter get configured based on these bits value. I have updated the patch v2.