Skip to contentSkip to conversation

mfd: tp6586x: enhancements in the driver

PATCH Superseded Laxman Dewangan 3 participants 16 messages Jul 16, 2012 – Jul 18, 2012

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

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           |  301 +++++++++++---------------------------
 6 files changed, 256 insertions(+), 215 deletions(-)
 create mode 100644 drivers/gpio/gpio-tps6586x.c
#1 lore raw

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

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

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

 drivers/mfd/tps6586x.c |   23 ++++++++---------------
 1 files changed, 8 insertions(+), 15 deletions(-)
drivers/mfd/tps6586x.c +8 -15
index c84b550..1256b7f 100644
@@ -432,8 +432,8 @@ static int __devinit tps6586x_irq_init(struct tps6586x *tps6586x, int irq,
 #endif
 	}
 
-	ret = request_threaded_irq(irq, NULL, tps6586x_irq, IRQF_ONESHOT,
-				   "tps6586x", tps6586x);
+	ret = devm_request_threaded_irq(tps6586x->dev, irq, NULL, tps6586x_irq,
+			IRQF_ONESHOT, "tps6586x", tps6586x);
 
 	if (!ret) {
 		device_init_wakeup(tps6586x->dev, 1);
@@ -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,14 +596,14 @@ 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;
 		}
 	}
 
 	ret = tps6586x_gpio_init(tps6586x, pdata->gpio_base);
 	if (ret) {
 		dev_err(&client->dev, "GPIO registration failed: %d\n", ret);
-		goto err_gpio_init;
+		return ret;
 	}
 
 	ret = tps6586x_add_subdevs(tps6586x, pdata);
@@ -619,11 +621,6 @@ err_add_devs:
 			dev_err(&client->dev, "Can't remove gpio chip: %d\n",
 				ret);
 	}
-err_gpio_init:
-	if (client->irq)
-		free_irq(client->irq, tps6586x);
-err_irq_init:
-	kfree(tps6586x);
 	return ret;
 }
 
@@ -633,9 +630,6 @@ static int __devexit tps6586x_i2c_remove(struct i2c_client *client)
 	struct tps6586x_platform_data *pdata = client->dev.platform_data;
 	int ret;
 
-	if (client->irq)
-		free_irq(client->irq, tps6586x);
-
 	if (pdata->gpio_base) {
 		ret = gpiochip_remove(&tps6586x->gpio);
 		if (ret)
@@ -644,7 +638,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

Re: [PATCH V2 1/6] mfd: tps6586x:use devm managed resources

drivers/mfd/tps6586x.c static int __devinit tps6586x_irq_init(struct tps6586x *tps6586x, int irq, · line 436

Quoted 4 lines · Laxman Dewangan
drivers/mfd/tps6586x.c +2 -2
-	ret = request_threaded_irq(irq, NULL, tps6586x_irq, IRQF_ONESHOT,
-				   "tps6586x", tps6586x);
+	ret = devm_request_threaded_irq(tps6586x->dev, irq, NULL, tps6586x_irq,
+			IRQF_ONESHOT, "tps6586x", tps6586x);

Are you sure this is safe - what guarantees that we can't get an interrupt while tearing the device down?

#3 lore raw

Re: [PATCH V2 1/6] mfd: tps6586x:use devm managed resources

Quoted 8 lines · Mark Brown

drivers/mfd/tps6586x.c static int __devinit tps6586x_irq_init(struct tps6586x *tps6586x, int irq, · line 436

Quoted 4 lines · Laxman Dewangan
drivers/mfd/tps6586x.c +2 -2
-	ret = request_threaded_irq(irq, NULL, tps6586x_irq, IRQF_ONESHOT,
-				   "tps6586x", tps6586x);
+	ret = devm_request_threaded_irq(tps6586x->dev, irq, NULL, tps6586x_irq,
+			IRQF_ONESHOT, "tps6586x", tps6586x);

Are you sure this is safe - what guarantees that we can't get an interrupt while tearing the device down?

I think device_remove will get called before the managed resource get freed. So do we need to call disable_irq() in remove() to avoid any interrupts?

#4 lore raw

Re: [PATCH V2 1/6] mfd: tps6586x:use devm managed resources

Quoted 11 lines · Laxman Dewangan
Quoted 9 lines · Mark Brown

drivers/mfd/tps6586x.c static int __devinit tps6586x_irq_init(struct tps6586x *tps6586x, int irq, · line 436

Quoted 4 lines · Laxman Dewangan
drivers/mfd/tps6586x.c +2 -2
-	ret = request_threaded_irq(irq, NULL, tps6586x_irq, IRQF_ONESHOT,
-				   "tps6586x", tps6586x);
+	ret = devm_request_threaded_irq(tps6586x->dev, irq, NULL, tps6586x_irq,
+			IRQF_ONESHOT, "tps6586x", tps6586x);

Are you sure this is safe - what guarantees that we can't get an interrupt while tearing the device down?

Quoted 3 lines

I think device_remove will get called before the managed resource get freed.
So do we need to call disable_irq() in remove() to avoid any interrupts?

That would be very rude if the IRQ happened to get shared, though that's not possible at the moment. In general it's pretty hard to use devm_ IRQs safely, it's normally safest to avoid them due to the issues with ensuring that the interrupt handler is safe to be called even while the device is being torn down.

#5 lore raw

Re: [PATCH V2 1/6] mfd: tps6586x:use devm managed resources

Quoted 6 lines · Mark Brown

* PGP Signed by an unknown key

Quoted 2 lines · Laxman Dewangan
Quoted 1 line · Mark Brown

On Mon, Jul 16, 2012 at 12:21:45PM +0530, Laxman Dewangan wrote:

Quoted 8 lines
Quoted 3 lines

I think device_remove will get called before the managed resource get freed.
So do we need to call disable_irq() in remove() to avoid any interrupts?

That would be very rude if the IRQ happened to get shared, though that's not possible at the moment. In general it's pretty hard to use devm_ IRQs safely, it's normally safest to avoid them due to the issues with ensuring that the interrupt handler is safe to be called even while the device is being torn down.

OK, then I will revert this specific change if it is not safe. I will send the another patch (part of series v3 1/6) for this change only.

#6 lore raw

PATCH v2 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.

 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
#8 lore raw

PATCH v2 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.

 drivers/mfd/tps6586x.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)
drivers/mfd/tps6586x.c +16 -8
index fb0c109..7210fa7 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
Reviewed-by on v2 3/6
#9 lore raw

Re: [PATCH V2 3/6] mfd: tps6586x: cache register through regmap

Quoted 2 lines · Laxman Dewangan

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

Can you use regmap-irq?

#10 lore raw

Re: [PATCH V2 3/6] mfd: tps6586x: cache register through regmap

Quoted 9 lines · Mark Brown

* PGP Signed by an unknown key

Quoted 2 lines · Laxman Dewangan

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

Can you use regmap-irq?

Sure, I will convert it to regmap_irq and will send new patch after this series in linux-next. Thanks,
Laxman

#11 lore raw

PATCH v2 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.

 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
#12 lore raw

PATCH v2 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.

 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
#14 lore raw

PATCH v2 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.

 drivers/mfd/Kconfig    |    2 +-
 drivers/mfd/tps6586x.c |   99 +++++++++---------------------------------------
 2 files changed, 19 insertions(+), 82 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 +18 -81

148 lines not on this page · raw message

Signature · 1 line
1.7.1.1
Acked-by on v2 6/6
#15 lore raw

Re: [PATCH V2 6/6] mfd: tps6586x: remove gpio support from core driver

Quoted 10 lines · 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.

Yours,
Linus Walleij