mfd: tps65910: use regmap for device register access.
Subsystems (4)
PATCH 1/2 mfd: tps65910: use regmap for device register access.
Using regmap apis for accessing the device register. using the RBTREE caching mechanims for caching registers. Also provided apis for enabling register cache from different sub devices of ts65910.
---
This patch is towards the performance improvements in the voltage change.
drivers/mfd/Kconfig | 1 + drivers/mfd/tps65910.c | 136 +++++++++++++++++++----------------------- include/linux/mfd/tps65910.h | 3 + 3 files changed, 65 insertions(+), 75 deletions(-)
drivers/mfd/Kconfig +1 -0
@@ -162,6 +162,7 @@ config MFD_TPS65910 depends on I2C=y && GPIOLIB select MFD_CORE select GPIO_TPS65910 + select REGMAP_I2C help if you say yes here you get support for the TPS65910 series of Power Management chips.
drivers/mfd/tps65910.c +61 -75
192 lines not on this page · raw message
include/linux/mfd/tps65910.h +3 -0
@@ -805,6 +805,7 @@ struct tps65910_board {struct tps65910 {struct device *dev;struct i2c_client *i2c_client; +struct regmap *regmap;struct mutex io_mutex;unsigned int id;int (*read)(struct tps65910 *tps65910,u8 reg,int size,void *dest);
@@ -824,6 +825,7 @@ struct tps65910 {int irq_base;int irq_num;u32 irq_mask; +unsigned long cache_reg[BITS_TO_LONGS (TPS65910_MAX_REGISTER )]; };struct tps65910_platform_data {
@@ -837,6 +839,7 @@ void tps65910_gpio_init(struct tps65910 *tps65910, int gpio_base);int tps65910_irq_init (struct tps65910 *tps65910,int irq,struct tps65910_platform_data *pdata);int tps65910_irq_exit (struct tps65910 *tps65910); +void tps65910_enable_reg_cache (struct tps65910 *tps65910,int reg);static inline int tps65910_chip_id (struct tps65910 *tps65910) {
Signature · 1 line
1.7.1.1
PATCH 2/2 regulator: tps65910: Enable register caching of voltage controls.
Enabling the caching of the registers which is used for voltage controls. By doing this, the modify_bits operation is faster as it does not involve the i2c register read from device, just read from cache. This results faster set voltage operation.
--- drivers/regulator/tps65910-regulator.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
drivers/regulator/tps65910-regulator.c +12 -0
@@ -1123,6 +1123,18 @@ static __devinit int tps65910_probe(struct platform_device *pdev) pmic->desc[i].ops = &tps65911_ops; } +/* Enable register caching */ +tps65910_enable_reg_cache (tps65910, pmic->get_ctrl_reg (i)); +/* VDD1/VDD2/VDDCTRL-TPS65911 have SR and OP register */ +if ((i ==TPS65910_REG_VDD1 ) || (i ==TPS65910_REG_VDD2 ) || + ((tps65910_chip_id (tps65910) ==TPS65911 ) && + (i ==TPS65911_REG_VDDCTRL ))) { +tps65910_enable_reg_cache (tps65910, + pmic->get_ctrl_reg (i) +1 ); +tps65910_enable_reg_cache (tps65910, + pmic->get_ctrl_reg (i) +2 ); + } + err =tps65910_set_ext_sleep_config (pmic, i, pmic_plat_data->regulator_ext_sleep_control[i]);/*
Signature · 1 line
1.7.1.1
drivers/mfd/tps65910.c static struct mfd_cell tps65910s[] = { · line 43
Quoted 5 lines · Laxman Dewangan
drivers/mfd/tps65910.c +5
-0+static bool is_volatile_reg (struct device *dev,unsigned int reg) +{ +struct tps65910 *tps65910 =dev_get_drvdata (dev); +return test_bit (reg, tps65910->cache_reg) ? false : true; +}
This is *really* odd. Why is this not static data (or mostly static data), why does it vary at runtime?
drivers/mfd/tps65910.c static struct mfd_cell tps65910s[] = { · line 53
Quoted 9 lines
drivers/mfd/tps65910.c +9
-0+static bool regmap_volatile_range (struct tps65910 *tps65910, +unsigned int reg,unsigned int bytes) +{ +unsigned int i; +for (i =0 ; i < bytes; i++) +if (!is_volatile_reg (tps65910->dev, reg + i)) +return false; +return true; +}
I don't think this should be here (the naming is a bit of a clue - it's named like a core function), see below where you're using it...
drivers/mfd/tps65910.c static struct mfd_cell tps65910s[] = { · line 78
Quoted 13 lines
drivers/mfd/tps65910.c +13
-0+unsigned char *wbuf = src; +unsigned int ival; + +if (regmap_volatile_range (tps65910, reg, bytes)) +return regmap_raw_write (tps65910->regmap, reg, src, bytes); + +/* If any of register is non-volatile then use byte-wise transfer */ +for (i =0 ; i < bytes; ++i) { + ival = (unsigned int ) (*wbuf++); + ret =regmap_write (tps65910->regmap, reg, ival); +if (ret <0 ) +return ret; + }
There's nothing specific to the driver about this, if this is a good idea add support for it to the core.
drivers/mfd/tps65910.c static struct mfd_cell tps65910s[] = { · line 98
Quoted 5 lines
drivers/mfd/tps65910.c +5
-0+void tps65910_enable_reg_cache (struct tps65910 *tps65910,int reg) +{ +set_bit (reg, tps65910->cache_reg); +} +EXPORT_SYMBOL_GPL (tps65910_enable_reg_cache);
Why are you doing this? This looks very icky, and if it is needed there needs to be more code here to make sure the register cache and device are in sync.
Thanks for quick review.
Quoted 4 lines · Mark Brown
* PGP Signed by an unknown key
On Wed, Feb 08, 2012 at 04:16:24PM +0530, Laxman Dewangan wrote:
Quoted 8 lines
drivers/mfd/tps65910.c static struct mfd_cell tps65910s[] = { · line 43
Quoted 5 lines
drivers/mfd/tps65910.c +5
-0+static bool is_volatile_reg (struct device *dev,unsigned int reg) +{ +struct tps65910 *tps65910 =dev_get_drvdata (dev); +return test_bit (reg, tps65910->cache_reg) ? false : true; +}This is *really* odd. Why is this not static data (or mostly static data), why does it vary at runtime?
I did not wanted to make the list of register in core driver. Wanted to leave the decision to the sub-devices driver where they need to enable cache based on their requirements. Do you think that the register list (although it is used in the regulator driver) should be in the core file? If this is allow then I can make the static table in core driver.
Quoted 12 lines
drivers/mfd/tps65910.c static struct mfd_cell tps65910s[] = { · line 53
Quoted 9 lines
drivers/mfd/tps65910.c +9
-0+static bool regmap_volatile_range (struct tps65910 *tps65910, +unsigned int reg,unsigned int bytes) +{ +unsigned int i; +for (i =0 ; i< bytes; i++) +if (!is_volatile_reg (tps65910->dev, reg + i)) +return false; +return true; +}I don't think this should be here (the naming is a bit of a clue - it's named like a core function), see below where you're using it...
Oops, the function is copied from the regmap and so this error... sorry.. There is no core function where bulk_write is happening on which some of register is cached.
Quoted 7 lines
Quoted 7 lines
drivers/mfd/tps65910.c +7
-0+unsigned char *wbuf = src; +unsigned int ival; + +if (regmap_volatile_range (tps65910, reg, bytes)) +return regmap_raw_write (tps65910->regmap, reg, src, bytes); + +/* If any of register is non-volatile then use byte-wise transfer */
Quoted 9 lines
drivers/mfd/tps65910.c static struct mfd_cell tps65910s[] = { · line 78
Quoted 6 lines
drivers/mfd/tps65910.c +6
-0+for (i =0 ; i< bytes; ++i) { + ival = (unsigned int ) (*wbuf++); + ret =regmap_write (tps65910->regmap, reg, ival); +if (ret<0 ) +return ret; + }There's nothing specific to the driver about this, if this is a good idea add support for it to the core.
This function added because there is no bulk_write function in core driver which supports the non-volatile in the list. Even if number of bytes read is 1. Should we move the above logic to core driver?
- If any of the register is non-volatile in bulk write then split the transfer into the byte-wise/short-wise/long-wise (format.val_bytes) based on register width?
- If all register is volatile the uses the regmap_raw_write()
Does it sounds reasonable? If yes then I can move this code to regmap.c as regmap_bulk_write() i.e. new function.
Quoted 8 lines
drivers/mfd/tps65910.c static struct mfd_cell tps65910s[] = { · line 98
Quoted 5 lines
drivers/mfd/tps65910.c +5
-0+void tps65910_enable_reg_cache (struct tps65910 *tps65910,int reg) +{ +set_bit (reg, tps65910->cache_reg); +} +EXPORT_SYMBOL_GPL (tps65910_enable_reg_cache);Why are you doing this? This looks very icky, and if it is needed there needs to be more code here to make sure the register cache and device are in sync.
I think If register are volatile then read/write happen to device only i.e. without caching. There is no entry for such register in cache table. Once this is cache enable, new entry is created on cache and the first value for the cache-val is read from device. So it will be in sync. All read/writes are io-locked in regmap and so not seeing any issue here.
Quoted 2 lines
* Unknown Key
*0x6E30FDDD
Quoted 11 lines · Laxman Dewangan
Quoted 2 lines · Mark Brown
This is *really* odd. Why is this not static data (or mostly static data), why does it vary at runtime?
I did not wanted to make the list of register in core driver. Wanted to leave the decision to the sub-devices driver where they need to enable cache based on their requirements.
Do you think that the register list (although it is used in the regulator driver) should be in the core file? If this is allow then I can make the static table in core driver.
Yes, it should be in the core driver.
Quoted 11 lines
Quoted 10 lines
drivers/mfd/tps65910.c static struct mfd_cell tps65910s[] = { · line 78
Quoted 7 lines
drivers/mfd/tps65910.c +7
-0+/* If any of register is non-volatile then use byte-wise transfer */ +for (i =0 ; i< bytes; ++i) { + ival = (unsigned int ) (*wbuf++); + ret =regmap_write (tps65910->regmap, reg, ival); +if (ret<0 ) +return ret; + }There's nothing specific to the driver about this, if this is a good idea add support for it to the core.
Quoted 4 lines
This function added because there is no
bulk_writefunction in core driver which supports the non-volatile in the list. Even if number of bytes read is 1.
Should we move the above logic to core driver?
This is the core driver? If you mean the regmap core then yes.
Quoted 7 lines
- If any of the register is non-volatile in bulk write then split the transfer into the byte-wise/short-wise/long-wise (format.val_bytes) based on register width?
- If all register is volatile the uses theregmap_raw_write()Does it sounds reasonable? If yes then I can move this code to
regmap.casregmap_bulk_write()i.e. new function.
Yes, though bulk_write() is tricky as it's *really* unclear what it should take as an argument - should it be raw register size (in which case it's just raw_write()) or should it be ints (in which case it needs to repack the data too)? I suspect ints but I'm really not convinced there's much use case for this.
Quoted 4 lines · Mark Brown
* PGP Signed by an unknown key
On Wed, Feb 08, 2012 at 05:45:43PM +0530, Laxman Dewangan wrote:
Quoted 8 lines
Quoted 6 lines
I did not wanted to make the list of register in core driver. Wanted to leave the decision to the sub-devices driver where they need to enable cache based on their requirements.
Do you think that the register list (although it is used in the regulator driver) should be in the core file? If this is allow then I can make the static table in core driver.Yes, it should be in the core driver.
Fine, it will much simple in this case.
Quoted 7 lines
Quoted 5 lines
This function added because there is no
bulk_writefunction in core driver which supports the non-volatile in the list. Even if number of bytes read is 1.
Should we move the above logic to core driver?This is the core driver? If you mean the regmap core then yes.
Yes, change regmap core driver i.e. regmap.c
Quoted 6 lines
Quoted 6 lines
- If any of the register is non-volatile in bulk write then split the transfer into the byte-wise/short-wise/long-wise (format.val_bytes) based on register width?
- If all register is volatile the uses theregmap_raw_write()Does it sounds reasonable? If yes then I can move this code toregmap.casregmap_bulk_write()i.e. new function.
Quoted 6 lines
Yes, though
bulk_write()is tricky as it's *really* unclear what it should take as an argument - should it be raw register size (in which case it's justraw_write()) or should it be ints (in which case it needs to repack the data too)? I suspect ints but I'm really not convinced there's much use case for this.
* @map: Register map to write to
* @reg: Initial register to write to
* @val: Block of data to be written, laid out for direct transmission
to the
* device
* @@val_count: Number of registers to write
int regmap_bulk_write(struct regmap *map, unsigned int reg, void *val,
size_t val_count)
only support if map->format.parse_val not null like bulk_read.
It will just do the regamp_raw_write() if all regs are volatile
otherwise make the unsigned int from the val by function map->format.parse_val for separate write for each register.
Quoted 2 lines
* Unknown Key
*0x6E30FDDD
Quoted 16 lines · Laxman Dewangan
Quoted 5 lines · Mark Brown
Yes, though
bulk_write()is tricky as it's *really* unclear what it should take as an argument - should it be raw register size (in which case it's justraw_write()) or should it be ints (in which case it needs to repack the data too)? I suspect ints but I'm really not convinced there's much use case for this.* @map: Register map to write to
* @reg: Initial register to write to
* @val: Block of data to be written, laid out for direct transmission to the
* device
* @@val_count: Number of registers to write
int regmap_bulk_write(struct regmap *map, unsigned int reg, void *val,
size_tval_count)
Quoted 5 lines
only support if
map->format.parse_valnot null likebulk_read.It will just do the
regamp_raw_write()if all regs are volatile otherwise make the unsigned int from the val by functionmap->format.parse_valfor separate write for each register.
But that's just raw_write(), there's no benefit to the additional API call.
Quoted 20 lines · Mark Brown
* PGP Signed by an unknown key
Quoted 6 lines · Laxman Dewangan
Quoted 5 lines · Mark Brown
Yes, though
bulk_write()is tricky as it's *really* unclear what it should take as an argument - should it be raw register size (in which case it's justraw_write()) or should it be ints (in which case it needs to repack the data too)? I suspect ints but I'm really not convinced there's much use case for this.Quoted 11 lines
* @map: Register map to write to
* @reg: Initial register to write to
* @val: Block of data to be written, laid out for direct transmission to the
* device
* @@val_count: Number of registers to write
int regmap_bulk_write(struct regmap *map, unsigned int reg, void *val,
size_tval_count)
only support ifmap->format.parse_valnot null likebulk_read.
It will just do theregamp_raw_write()if all regs are volatile otherwise make the unsigned int from the val by functionmap->format.parse_valfor separate write for each register.
Quoted 3 lines
But that's just
raw_write(), there's no benefit to the additional API call.
raw_write supported for the volatile register only.
I require an api which can work for volatile as well as non-volatile registers. Either extend raw_write to support both cases (remove warning and handle properly) or add bulk_write.
I think as bulk_read is there and so having bulk_write on same line should be OK.
Quoted 2 lines
* Unknown Key
*0x6E30FDDD
Quoted 6 lines · Laxman Dewangan
Quoted 2 lines · Mark Brown
But that's just
raw_write(), there's no benefit to the additional API call.
raw_writesupported for the volatile register only.
That's an implementation detail since there's little if any use case for such use, the main use of raw_write() is dumping blocks of data like firmwares and coefficients which are rarely cached.
Quoted 7 lines
I require an api which can work for volatile as well as non-volatile registers.
Either extendraw_writeto support both cases (remove warning and handle properly) or addbulk_write.I think as
bulk_readis there and so havingbulk_writeon same line should be OK.
Note that there's a very important difference between the bulk and raw versions of the API which you're not taking into account: the bulk version takes care of endianness differences between the device and the host. This would mean that for send we'd need to rewrite the input array which means we have to take a copy of the data as we probably shouldn't be changing the input data.
Indeed, looking at the drivers in mainline I can't actually see any of them which do block writes.
Quoted 6 lines · Mark Brown
* PGP Signed by an unknown key
Quoted 3 lines · Laxman Dewangan
Quoted 2 lines · Mark Brown
But that's just
raw_write(), there's no benefit to the additional API call.
Quoted 9 lines
Quoted 1 line
raw_writesupported for the volatile register only.Note that there's a very important difference between the bulk and raw versions of the API which you're not taking into account: the bulk version takes care of endianness differences between the device and the host. This would mean that for send we'd need to rewrite the input array which means we have to take a copy of the data as we probably shouldn't be changing the input data.
Yes, I am taking care of this. Probably my code will explain this :)
I have my patch ready. Let me send this..
Quoted 3 lines
Indeed, looking at the drivers in mainline I can't actually see any of them which do block writes.
I am working on mfd/tps65910.c and function is:
static int tps65910_i2c_write(struct tps65910 *tps65910, u8 reg,
int bytes, void *src)
All your feedback will help me to improve my next two mfd/pmic drivers which I am planning to upstream...
Quoted 2 lines
* Unknown Key
*0x6E30FDDD
Quoted 6 lines · Laxman Dewangan
I am working on
mfd/tps65910.cand function is:
static int tps65910_i2c_write(struct tps65910 *tps65910, u8 reg,
int bytes, void *src)All your feedback will help me to improve my next two mfd/pmic drivers which I am planning to upstream...
Yeah, I know that's the i2c_write() function but all the callers I noticed were calling it with bytes set to 1.
Quoted 4 lines · Mark Brown
* PGP Signed by an unknown key
On Thu, Feb 09, 2012 at 05:29:38PM +0530, Laxman Dewangan wrote:
Quoted 8 lines
Quoted 5 lines
I am working on
mfd/tps65910.cand function is:
static int tps65910_i2c_write(struct tps65910 *tps65910, u8 reg,
int bytes, void *src)
All your feedback will help me to improve my next two mfd/pmic drivers which I am planning to upstream...Yeah, I know that's the
i2c_write()function but all the callers I noticed were calling it with bytes set to 1.
Yes, currently all callers are calling with 1 byte but when we will add rtc (which is not there currently), at that time, it may call multibyte read/write.
The interface is such that it can support multi-byte transfer. And when using for single byte transfer (currently) and if it is cached, regmap_raw_write() is creating warnings and that's why I broken transfer in multi-transfer in tps65910.c which was not a good idea..
Quoted 2 lines
* Unknown Key
*0x6E30FDDD