Skip to contentSkip to conversation

mfd: tp6586x: enhancements in the driver

PATCH In review Laxman Dewangan 3 participants 9 messages Jul 18, 2012 – Jul 24, 2012

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover mfd: tp6586x: enhancements in the driver

Doing some enhancements in the tps6586x core driver which is based on some recent driver framework enhancements. Following are highlights of changes:
- Use devm for allocation to remove the code for freeing it.
- Use regmap i2c for register access in place of direct i2c apis. This will give the debug fs and cache functionality through regmap framework.
- Use the regmap caching for some fo register in place of local implementation.
- Move the gpio support driver to the drivers/gpio and implement it as platform driver. The registration will be done as mfd sub devices.

Changes V1 -> V2:
- Remove the unnecessariy header inclusion in the gpio-tps6586x.
- To avoid bisect functionality break, grep the user of tps6586x and found that tegra_defconfig is only using this. Added the GPIO_TPS6586x in config variable on this series.
This results 6 patch on this series.

Changes V2->V3
- Revert the irq regsitration through devm_* and used normal api.
- Rebased the series with above change as there was conflict.

Laxman Dewangan (6):
mfd: tps6586x:use devm managed resources
mfd: Use regmap for tps6586x register access.
mfd: tps6586x: cache register through regmap
gpio: tps6586x: add gpio support through platform driver
ARM: tegra: defconfig: enable tps6586x gpio
mfd: tps6586x: remove gpio support from core driver

 arch/arm/configs/tegra_defconfig |    1 +
 drivers/gpio/Kconfig             |    7 +
 drivers/gpio/Makefile            |    1 +
 drivers/gpio/gpio-tps6586x.c     |  158 ++++++++++++++++++++
 drivers/mfd/Kconfig              |    3 +-
 drivers/mfd/tps6586x.c           |  296 +++++++++++---------------------------
 6 files changed, 256 insertions(+), 210 deletions(-)
 create mode 100644 drivers/gpio/gpio-tps6586x.c
#1 lore raw

PATCH v3 1/6 mfd: tps6586x:use devm managed resources

Allocate memory for device state using devm_kzalloc() to simplify accounting and letting the kernel do the garbage-collection.

---
Changes V1 -> V2:
No change, generated new patch for V2 series.

Changes V2->V3:
Revert the request registration through devm_* and use the normal api.

 drivers/mfd/tps6586x.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
drivers/mfd/tps6586x.c +6 -6
index c84b550..c103ea9 100644
@@ -579,9 +579,11 @@ static int __devinit tps6586x_i2c_probe(struct i2c_client *client,
 
 	dev_info(&client->dev, "VERSIONCRC is %02x\n", ret);
 
-	tps6586x = kzalloc(sizeof(struct tps6586x), GFP_KERNEL);
-	if (tps6586x == NULL)
+	tps6586x = devm_kzalloc(&client->dev, sizeof(*tps6586x), GFP_KERNEL);
+	if (tps6586x == NULL) {
+		dev_err(&client->dev, "memory for tps6586x alloc failed\n");
 		return -ENOMEM;
+	}
 
 	tps6586x->client = client;
 	tps6586x->dev = &client->dev;
@@ -594,7 +596,7 @@ static int __devinit tps6586x_i2c_probe(struct i2c_client *client,
 					pdata->irq_base);
 		if (ret) {
 			dev_err(&client->dev, "IRQ init failed: %d\n", ret);
-			goto err_irq_init;
+			return ret;
 		}
 	}
 
@@ -622,8 +624,7 @@ err_add_devs:
 err_gpio_init:
 	if (client->irq)
 		free_irq(client->irq, tps6586x);
-err_irq_init:
-	kfree(tps6586x);
+
 	return ret;
 }
 
@@ -644,7 +645,6 @@ static int __devexit tps6586x_i2c_remove(struct i2c_client *client)
 	}
 
 	tps6586x_remove_subdevs(tps6586x);
-	kfree(tps6586x);
 	return 0;
 }
 
Signature · 1 line
1.7.1.1
#2 lore raw

PATCH v3 2/6 mfd: Use regmap for tps6586x register access.

In reply to Laxman Dewangan

Using regmap apis for accessing the device registers.

---
Changes V1 -> V2:
No change, generated new patch for V2 series.
Changes V2 -> V3:
No change, generated new patch for V3 series.

 drivers/mfd/Kconfig    |    1 +
 drivers/mfd/tps6586x.c |  157 ++++++++++++++----------------------------------
 2 files changed, 47 insertions(+), 111 deletions(-)
drivers/mfd/Kconfig +1 -0
index fa267d4..ec885a9 100644
@@ -200,6 +200,7 @@ config MFD_TPS6586X
 	bool "TPS6586x Power Management chips"
 	depends on I2C=y && GPIOLIB && GENERIC_HARDIRQS
 	select MFD_CORE
+	select REGMAP_I2C
 	depends on REGULATOR
 	help
 	  If you say yes here you get support for the TPS6586X series of
drivers/mfd/tps6586x.c +46 -111

241 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#3 lore raw

PATCH v3 3/6 mfd: tps6586x: cache register through regmap

In reply to Laxman Dewangan

To cache the interrupt mask register, use the regmap RB_TREE cache-ing mechanism in place of implementing it locally.

---
Changes V1 -> V2:
No change, generated new patch for V2 series.
Changes V2 -> V3:
No change, generated new patch for V3 series.

 drivers/mfd/tps6586x.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)
drivers/mfd/tps6586x.c +16 -8
index 6f59594..d59bfb7 100644
@@ -104,7 +104,6 @@ struct tps6586x {
 	struct mutex		irq_lock;
 	int			irq_base;
 	u32			irq_en;
-	u8			mask_cache[5];
 	u8			mask_reg[5];
 };
 
@@ -276,12 +275,11 @@ static void tps6586x_irq_sync_unlock(struct irq_data *data)
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(tps6586x->mask_reg); i++) {
-		if (tps6586x->mask_reg[i] != tps6586x->mask_cache[i]) {
-			if (!WARN_ON(tps6586x_write(tps6586x->dev,
-						    TPS6586X_INT_MASK1 + i,
-						    tps6586x->mask_reg[i])))
-				tps6586x->mask_cache[i] = tps6586x->mask_reg[i];
-		}
+		int ret;
+		ret = tps6586x_write(tps6586x->dev,
+					    TPS6586X_INT_MASK1 + i,
+					    tps6586x->mask_reg[i]);
+		WARN_ON(ret);
 	}
 
 	mutex_unlock(&tps6586x->irq_lock);
@@ -328,7 +326,6 @@ static int __devinit tps6586x_irq_init(struct tps6586x *tps6586x, int irq,
 
 	mutex_init(&tps6586x->irq_lock);
 	for (i = 0; i < 5; i++) {
-		tps6586x->mask_cache[i] = 0xff;
 		tps6586x->mask_reg[i] = 0xff;
 		tps6586x_write(tps6586x->dev, TPS6586X_INT_MASK1 + i, 0xff);
 	}
@@ -478,10 +475,21 @@ static struct tps6586x_platform_data *tps6586x_parse_dt(struct i2c_client *clien
 }
 #endif
 
+static bool is_volatile_reg(struct device *dev, unsigned int reg)
+{
+	/* Cache all interrupt mask register */
+	if ((reg >= TPS6586X_INT_MASK1) && (reg <= TPS6586X_INT_MASK5))
+		return false;
+
+	return true;
+}
+
 static const struct regmap_config tps6586x_regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
 	.max_register = TPS6586X_MAX_REGISTER - 1,
+	.volatile_reg = is_volatile_reg,
+	.cache_type = REGCACHE_RBTREE,
 };
 
 static int __devinit tps6586x_i2c_probe(struct i2c_client *client,
Signature · 1 line
1.7.1.1
#4 lore raw

PATCH v3 4/6 gpio: tps6586x: add gpio support through platform driver

In reply to Laxman Dewangan

Converting the gpio driver of tps6586x to a platform driver in place of registering the gpio through core driver.
The motivation of the change is:
- This is inline with the mfd drivers implementation.
- This will move the related gpio support to gpio driver folder where all gpio related drivers are available. This will be easy the maintenance and enhancement is anything done for gpio.
- The gpio functionality can be selected through config variable.

---
Changes V1 -> V2:
Remove non-require header inclusion.
Changes V2 -> V3:
No change, generated new patch for V3 series.

 drivers/gpio/Kconfig         |    7 ++
 drivers/gpio/Makefile        |    1 +
 drivers/gpio/gpio-tps6586x.c |  158 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 166 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpio/gpio-tps6586x.c
drivers/gpio/Kconfig +7 -0
index 502b5ea..b16c8a7 100644
@@ -597,6 +597,13 @@ config GPIO_AB8500
 	help
 	  Select this to enable the AB8500 IC GPIO driver
 
+config GPIO_TPS6586X
+	bool "TPS6586X GPIO"
+	depends on MFD_TPS6586X
+	help
+	  Select this option to enable GPIO driver for the TPS6586X
+	  chip family.
+
 config GPIO_TPS65910
 	bool "TPS65910 GPIO"
 	depends on MFD_TPS65910
drivers/gpio/Makefile +1 -0
index d370481..153cace 100644
@@ -63,6 +63,7 @@ obj-$(CONFIG_GPIO_TC3589X)	+= gpio-tc3589x.o
 obj-$(CONFIG_ARCH_TEGRA)	+= gpio-tegra.o
 obj-$(CONFIG_GPIO_TIMBERDALE)	+= gpio-timberdale.o
 obj-$(CONFIG_ARCH_DAVINCI_TNETV107X) += gpio-tnetv107x.o
+obj-$(CONFIG_GPIO_TPS6586X)	+= gpio-tps6586x.o
 obj-$(CONFIG_GPIO_TPS65910)	+= gpio-tps65910.o
 obj-$(CONFIG_GPIO_TPS65912)	+= gpio-tps65912.o
 obj-$(CONFIG_GPIO_TWL4030)	+= gpio-twl4030.o
drivers/gpio/gpio-tps6586x.c new file +158 -0

158 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#5 lore raw

PATCH v3 5/6 ARM: tegra: defconfig: enable tps6586x gpio

In reply to Laxman Dewangan

Enable GPIO_TPS6586X as the gpio functionality of
this device moved as platform driver.

---
Changes V1 -> V2:
New change in V2 series. To avoid bisect, added change in defconfig.

Changes V2->V3:
No Change, just recreated part of series.

 arch/arm/configs/tegra_defconfig |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/arm/configs/tegra_defconfig +1 -0
index 4be9c1e..5ae3889 100644
@@ -105,6 +105,7 @@ CONFIG_I2C_MUX_PINCTRL=y
 CONFIG_I2C_TEGRA=y
 CONFIG_SPI=y
 CONFIG_SPI_TEGRA=y
+CONFIG_GPIO_TPS6586X=y
 CONFIG_GPIO_TPS65910=y
 CONFIG_POWER_SUPPLY=y
 CONFIG_BATTERY_SBS=y
Signature · 1 line
1.7.1.1
#7 lore raw

PATCH v3 6/6 mfd: tps6586x: remove gpio support from core driver

In reply to Laxman Dewangan

The GPIO functionality of device tps6586x is added through platform gpio driver and it can be register as the mfd sub device and hence removing the duplicates code which register the gpio functionality from core driver.

---
Changes from V1->V2
No changes in code, just patch become 6th of series as change in defconfig got added.
Changes from V2->V3:
Rebased on top of 1/6 change of this series.

 drivers/mfd/Kconfig    |    2 +-
 drivers/mfd/tps6586x.c |  107 +++++++++--------------------------------------
 2 files changed, 22 insertions(+), 87 deletions(-)
drivers/mfd/Kconfig +1 -1
index ec885a9..872dfe4 100644
@@ -198,7 +198,7 @@ config MFD_TPS65217
 
 config MFD_TPS6586X
 	bool "TPS6586x Power Management chips"
-	depends on I2C=y && GPIOLIB && GENERIC_HARDIRQS
+	depends on I2C=y && GENERIC_HARDIRQS
 	select MFD_CORE
 	select REGMAP_I2C
 	depends on REGULATOR
drivers/mfd/tps6586x.c +21 -86

159 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#8 lore raw
In reply to Laxman Dewangan

Hi Laxman,

Quoted 11 lines · Laxman Dewangan

Doing some enhancements in the tps6586x core driver which is based on some recent driver framework enhancements. Following are highlights of changes:
- Use devm for allocation to remove the code for freeing it.
- Use regmap i2c for register access in place of direct i2c apis. This will give the debug fs and cache functionality through regmap framework.
- Use the regmap caching for some fo register in place of local implementation.
- Move the gpio support driver to the drivers/gpio and implement it as platform driver. The registration will be done as mfd sub devices.

Nice, all 6 patches applied. I had to manually apply #5, please let me know if there are some issues.

Cheers,
Samuel.

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/