mfd: tp6586x: enhancements in the driver
Subsystems (2)
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.
Laxman Dewangan (5):
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
mfd: tps6586x: remove gpio support from core driver
drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-tps6586x.c | 158 ++++++++++++++++++++++ drivers/mfd/Kconfig | 3 +- drivers/mfd/tps6586x.c | 301 ++++++++++++------------------------------ 5 files changed, 255 insertions(+), 215 deletions(-) create mode 100644 drivers/gpio/gpio-tps6586x.c
PATCH 1/5 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.
--- drivers/mfd/tps6586x.c | 23 ++++++++--------------- 1 files changed, 8 insertions(+), 15 deletions(-)
drivers/mfd/tps6586x.c +8 -15
@@ -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
PATCH 2/5 mfd: Use regmap for tps6586x register access.
In reply to Laxman DewanganUsing regmap apis for accessing the device registers.
--- drivers/mfd/Kconfig | 1 + drivers/mfd/tps6586x.c | 157 ++++++++++++++---------------------------------- 2 files changed, 47 insertions(+), 111 deletions(-)
drivers/mfd/Kconfig +1 -0
@@ -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
PATCH 3/5 mfd: tps6586x: cache register through regmap
In reply to Laxman DewanganTo cache the interrupt mask register, use the regmap RB_TREE cache-ing mechanism in place of implementing it locally.
--- drivers/mfd/tps6586x.c | 24 ++++++++++++++++-------- 1 files changed, 16 insertions(+), 8 deletions(-)
drivers/mfd/tps6586x.c +16 -8
@@ -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
PATCH 4/5 gpio: tps6586x: add gpio support through platform driver
In reply to Laxman DewanganConverting 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.
--- drivers/gpio/Kconfig | 7 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-tps6586x.c | 159 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+), 0 deletions(-) create mode 100644 drivers/gpio/gpio-tps6586x.c
drivers/gpio/Kconfig +7 -0
@@ -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
@@ -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 +159 -0
159 lines not on this page · raw message
Signature · 1 line
1.7.1.1
Re: [PATCH 4/5] gpio: tps6586x: add gpio support through platform driver
Quoted 12 lines · 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.
Quoted 1 line
Signed-off-by Laxman Dewangan <[email protected]>
Overall this is very, very good and you're doing the right thing.
drivers/gpio/gpio-tps6586x.c
Quoted 4 lines
drivers/gpio/gpio-tps6586x.c new file +1
-0+#include <linux/i2c.h>
Why?
Yours,
Linus Walleij
Re: [PATCH 4/5] gpio: tps6586x: add gpio support through platform driver
Quoted 14 lines · Linus Walleij
Quoted 12 lines · 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.
Quoted 8 lines
Quoted 1 line
Signed-off-by Laxman Dewangan<[email protected]>Overall this is very, very good and you're doing the right thing.
drivers/gpio/gpio-tps6586x.c
Quoted 3 lines
drivers/gpio/gpio-tps6586x.c new file +1
-0+#include <linux/i2c.h> Why?
Removed this inclusion as it is not require.
Quoted 1 line
Reviewed-by Linus Walleij<[email protected]>
I will add your reviewed-by in my next patch for easyness.
PATCH 5/5 mfd: tps6586x: remove gpio support from core driver
In reply to Laxman DewanganThe 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.
--- drivers/mfd/Kconfig | 2 +- drivers/mfd/tps6586x.c | 99 +++++++++--------------------------------------- 2 files changed, 19 insertions(+), 82 deletions(-)
drivers/mfd/Kconfig +1 -1
@@ -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
Re: [PATCH 5/5] mfd: tps6586x: remove gpio support from core driver
Quoted 6 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.
Signed-off-by Laxman Dewangan <[email protected]>
The only thing I worry about is if old defconfig files are now missing this config option and then this patch becomes an unbisectable showstopper for them because they don't get this driver by default anymore.
So please make sure you've grepped around and checked that of some platforms defconfig was previously selecting the core driver, make sure it selects this driver too for the moment, it's better if they later deactivate it if they don't need it.
Yours,
Linus Walleij
Re: [PATCH 5/5] mfd: tps6586x: remove gpio support from core driver
Quoted 13 lines · Linus Walleij
Quoted 6 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.
Signed-off-by Laxman Dewangan<[email protected]>The only thing I worry about is if old defconfig files are now missing this config option and then this patch becomes an unbisectable showstopper for them because they don't get this driver by default anymore.
Quoted 5 lines
So please make sure you've grepped around and checked that of some platforms defconfig was previously selecting the core driver, make sure it selects this driver too for the moment, it's better if they later deactivate it if they don't need it.
Grep shows that only arm based platform tegra_defconfig is using this device. I have added the change in tegra_defconfig and will send as part of this series.