regmap: Allow read_reg_mask to be 0
Subsystems (2)
PATCH 1/1 regmap: Allow read_reg_mask to be 0
There may be spi devices that do not require a register read mask to read the registers.
Currently the code sets the read mask based on a non-zero value passed in from the driver or if that value is 0 sets the read mask to 0x80.
A mask of 0 is a valid mask as well. Create a define to indicate that the read mask can be zero and separate out the read flag mask and the write flag mask.
--- drivers/base/regmap/regmap.c | 11 +++++++---- include/linux/regmap.h | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-)
drivers/base/regmap/regmap.c +7 -4
@@ -528,12 +528,15 @@ struct regmap *regmap_init(struct device *dev,INIT_LIST_HEAD (&map->async_free);init_waitqueue_head (&map->async_waitq); -if (config->read_flag_mask || config->write_flag_mask) { +if (config->read_flag_mask ==REGMAP_NO_READ_MASK ) + map->read_flag_mask =0x00 ; +else if (config->read_flag_mask) map->read_flag_mask = config->read_flag_mask; - map->write_flag_mask = config->write_flag_mask; - }else if (bus) { +else if (bus) map->read_flag_mask = bus->read_flag_mask; - } + +if (config->write_flag_mask) + map->write_flag_mask = config->write_flag_mask;if (!bus) { map->reg_read = config->reg_read;
include/linux/regmap.h +2 -0
@@ -18,6 +18,8 @@#include <linux/err.h> #include <linux/bug.h> +#define REGMAP_NO_READ_MASK 0xff +struct module ;struct device ;struct i2c_client ;
Signature · 1 line
1.7.9.5
Mark Brown
maintainerdrivers/base/regmap/regmap.c struct regmap *regmap_init(struct device *dev, · line 533
Quoted 4 lines · Dan Murphy
drivers/base/regmap/regmap.c +3
-1-if (config->read_flag_mask || config->write_flag_mask) { +if (config->read_flag_mask ==REGMAP_NO_READ_MASK ) + map->read_flag_mask =0x00 ; +else if (config->read_flag_mask)
This breaks the symmetry in handling of read and write masks which isn't great, please make the equivalent update for the write mask too.
Quoted 1 line
+#define
REGMAP_NO_READ_MASK0xff
An actual out of band value might be preferable here though that'd involve changing the type and more checking so perhaps inessential.
Mark
Thanks for the review
Quoted 8 lines · Mark Brown
drivers/base/regmap/regmap.c struct regmap *regmap_init(struct device *dev, · line 533
Quoted 4 lines · Dan Murphy
drivers/base/regmap/regmap.c +3
-1-if (config->read_flag_mask || config->write_flag_mask) { +if (config->read_flag_mask ==REGMAP_NO_READ_MASK ) + map->read_flag_mask =0x00 ; +else if (config->read_flag_mask)This breaks the symmetry in handling of read and write masks which isn't great, please make the equivalent update for the write mask too.
Hmmm. If I make the similar change for the write mask I will be adding dead code as write_flag_mask is not defaulted by the bus like the read_flag_mask which is defaulted to 0x80 in the regmap-spi code. The i2c code does not make this assumption.
The original code did not seem to have symmetry as the only instance that write_flag_mask is modified is if it is non-zero.
Let me know what you think. I can add the code to make it more symmetrical but we may be adding code that is dead. If I remove the defaulted read_flag_mask value out of the spi driver then I will need to find every spi device that needs that flag and set it. IMHO that would be really messy and probably mess us some drivers.
Quoted 4 lines
Quoted 2 lines
+#define
REGMAP_NO_READ_MASK0xffAn actual out of band value might be preferable here though that'd involve changing the type and more checking so perhaps inessential.
Thought about making this -1 with a variable change but that seemed really drastic where a value of 0xff seems to be a value that no one should use.
Dan
Signature · 2 lines
------------------ Dan Murphy
Quoted 8 lines · Mark Brown
drivers/base/regmap/regmap.c struct regmap *regmap_init(struct device *dev, · line 533
Quoted 4 lines · Dan Murphy
drivers/base/regmap/regmap.c +3
-1-if (config->read_flag_mask || config->write_flag_mask) { +if (config->read_flag_mask ==REGMAP_NO_READ_MASK ) + map->read_flag_mask =0x00 ; +else if (config->read_flag_mask)This breaks the symmetry in handling of read and write masks which isn't great, please make the equivalent update for the write mask too.
Hmmm. If I make the similar change for the write mask I will be adding dead code as write_flag_mask is not defaulted by the bus like the read_flag_mask which is defaulted to 0x80 in the regmap-spi code. The i2c code does not make this assumption.
The original code did not seem to have symmetry as the only instance that write_flag_mask is modified is if it is non-zero.
Let me know what you think. I can add the code to make it more symmetrical but we may be adding code that is dead. If I remove the defaulted read_flag_mask value out of the spi driver then I will need to find every spi device that needs that flag and set it. IMHO that would be really messy and probably mess us some drivers.
Quoted 3 lines
Quoted 1 line
+#define
REGMAP_NO_READ_MASK0xffAn actual out of band value might be preferable here though that'd involve changing the type and more checking so perhaps inessential.
Thought about making this -1 with a variable change but that seemed really drastic where a value of 0xff seems to be a value that no one should use.
Dan
Signature · 2 lines
------------------ Dan Murphy
Mark
Thanks for the quick review
Quoted 10 lines · Mark Brown
drivers/base/regmap/regmap.c struct regmap *regmap_init(struct device *dev, · line 533
Quoted 4 lines · Dan Murphy
drivers/base/regmap/regmap.c +3
-1-if (config->read_flag_mask || config->write_flag_mask) { +if (config->read_flag_mask ==REGMAP_NO_READ_MASK ) + map->read_flag_mask =0x00 ; +else if (config->read_flag_mask)This breaks the symmetry in handling of read and write masks which isn't great, please make the equivalent update for the write mask too.
Hmmm. If I make the similar change for the write mask I will be adding dead code as write_flag_mask is not defaulted by the bus like the read_flag_mask which is defaulted to 0x80 in the regmap-spi code. The i2c code does not make this assumption.
The original code did not seem to have symmetry as the only instance that write_flag_mask is modified is if it is non-zero.
Let me know what you think. I can add the code to make it more symmetrical but we may be adding code that is dead. If I remove the defaulted read_flag_mask value out of the spi driver then I will need to find every spi device that needs that flag and set it. IMHO that would be really messy and probably mess us some drivers.
Quoted 3 lines
Quoted 1 line
+#define
REGMAP_NO_READ_MASK0xffAn actual out of band value might be preferable here though that'd involve changing the type and more checking so perhaps inessential.
Thought about making this -1 with a variable change but that seemed really drastic where a value of 0xff seems to be a value that no one should use.
Dan
Signature · 2 lines
------------------ Dan Murphy
Quoted 6 lines · Dan Murphy
There may be spi devices that do not require a register read mask to read the registers.
Currently the code sets the read mask based on a non-zero value passed in from the driver or if that value is 0 sets the read mask to
0x80.
It only sets it to the bus default if both read_flag_mask and write_flag_mask are 0. The assumption is that both of them being zero is a invalid configuration and either of them (or both) have to be non-zero for proper operation, since otherwise the device can't tell the difference between a read and a write.
Do you have a device where both the read and the write mask is 0?
- Lars
Lars
Quoted 8 lines · Lars-Peter Clausen
Quoted 6 lines · Dan Murphy
There may be spi devices that do not require a register read mask to read the registers.
Currently the code sets the read mask based on a non-zero value passed in from the driver or if that value is 0 sets the read mask to
0x80.
Quoted 5 lines
It only sets it to the bus default if both
read_flag_maskandwrite_flag_maskare 0. The assumption is that both of them being zero is a invalid configuration and either of them (or both) have to be non-zero for proper operation, since otherwise the device can't tell the difference between a read and a write.Do you have a device where both the read and the write mask is 0?
- Lars
Yes I do have a device that the read/write mask are both 0.
The device, which is already in production, has a specific control register that sets either the reading or writing of the rest of the registers.
Here is the data sheet
http://www.ti.com/lit/ds/symlink/afe4403.pdf
See page 61 control0.
Driver is written for this part just want to get this lead patch in or maybe an alternate solution.
Dan
Signature · 2 lines
------------------ Dan Murphy
Quoted 21 lines · Dan Murphy
Lars
Quoted 8 lines · Lars-Peter Clausen
Quoted 6 lines · Dan Murphy
There may be spi devices that do not require a register read mask to read the registers.
Currently the code sets the read mask based on a non-zero value passed in from the driver or if that value is 0 sets the read mask to
0x80.Quoted 5 lines
It only sets it to the bus default if both
read_flag_maskandwrite_flag_maskare 0. The assumption is that both of them being zero is a invalid configuration and either of them (or both) have to be non-zero for proper operation, since otherwise the device can't tell the difference between a read and a write.Do you have a device where both the read and the write mask is 0?
- Lars
Yes I do have a device that the read/write mask are both 0.
The device, which is already in production, has a specific control register that sets either the reading or writing of the rest of the registers.
Quoted 7 lines
Here is the data sheet
http://www.ti.com/lit/ds/symlink/afe4403.pdf
See page 61 control0.
Driver is written for this part just want to get this lead patch in or maybe an alternate solution.
Looking at this the generic SPI regmap implementation might not necessarily be the best thing to use here and you are probably better of implementing either your own regmap bus or reg_read/reg_write callbacks that automatically set/clear the SPI_READ bit in the control register depending on the operation.
- Lars
Mark Brown
maintainerQuoted 1 line · Lars-Peter Clausen
On 09/30/2014 11:18 PM, Dan Murphy wrote:
Dan, please fix your mail client to word wrap within paragraphs.
Quoted 8 lines
Quoted 7 lines
The device, which is already in production, has a specific control register that sets either the reading or writing of the rest of the registers.
Here is the data sheet
http://www.ti.com/lit/ds/symlink/afe4403.pdf
See page 61 control0.
Quoted 7 lines
Quoted 1 line
Driver is written for this part just want to get this lead patch in or maybe an alternate solution.
Looking at this the generic SPI regmap implementation might not necessarily be the best thing to use here and you are probably better of implementing either your own regmap bus or reg_read/reg_write callbacks that automatically set/clear the
SPI_READbit in the control register depending on the operation.
It definitely needs more than just this change at any rate - any generic infrastructure that tries to work with the regmap is not going to know about this read/write register.
Lars
Quoted 26 lines · Lars-Peter Clausen
Quoted 25 lines · Dan Murphy
Lars
Quoted 8 lines · Lars-Peter Clausen
Quoted 6 lines · Dan Murphy
There may be spi devices that do not require a register read mask to read the registers.
Currently the code sets the read mask based on a non-zero value passed in from the driver or if that value is 0 sets the read mask to
0x80.Quoted 5 lines
It only sets it to the bus default if both
read_flag_maskandwrite_flag_maskare 0. The assumption is that both of them being zero is a invalid configuration and either of them (or both) have to be non-zero for proper operation, since otherwise the device can't tell the difference between a read and a write.Do you have a device where both the read and the write mask is 0?
- Lars
Yes I do have a device that the read/write mask are both 0.
The device, which is already in production, has a specific control register that sets either the reading or writing of the rest of the registers.
Here is the data sheet
Quoted 7 lines
Quoted 3 lines
See page 61 control0.
Driver is written for this part just want to get this lead patch in or maybe an alternate solution.
Looking at this the generic SPI regmap implementation might not necessarily be the best thing to use here and you are probably better of implementing either your own regmap bus or reg_read/reg_write callbacks that automatically set/clear the
SPI_READbit in the control register depending on the operation.- Lars
I am not sure implementing a different SPI regmap implementation is really the best thing.
I am handling this control bit toggling in the peripheral driver.
The device only needs to be written at init and then during calibration. Other then that it is read read read.
Dan
Signature · 2 lines
------------------ Dan Murphy
Quoted 31 lines · Dan Murphy
Lars
Quoted 28 lines · Lars-Peter Clausen
Quoted 27 lines · Dan Murphy
Lars
Quoted 8 lines · Lars-Peter Clausen
Quoted 6 lines · Dan Murphy
There may be spi devices that do not require a register read mask to read the registers.
Currently the code sets the read mask based on a non-zero value passed in from the driver or if that value is 0 sets the read mask to
0x80.Quoted 5 lines
It only sets it to the bus default if both
read_flag_maskandwrite_flag_maskare 0. The assumption is that both of them being zero is a invalid configuration and either of them (or both) have to be non-zero for proper operation, since otherwise the device can't tell the difference between a read and a write.Do you have a device where both the read and the write mask is 0?
- Lars
Yes I do have a device that the read/write mask are both 0.
The device, which is already in production, has a specific control register that sets either the reading or writing of the rest of the registers.
Here is the data sheet
http://www.ti.com/lit/ds/symlink/afe4403.pdf
See page 61 control0.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Driver is written for this part just want to get this lead patch in or maybe an alternate solution.
Looking at this the generic SPI regmap implementation might not necessarily be the best thing to use here and you are probably better of implementing either your own regmap bus or reg_read/reg_write callbacks that automatically set/clear the
SPI_READbit in the control register depending on the operation.- Lars
I am not sure implementing a different SPI regmap implementation is really the best thing. I am handling this control bit toggling in the peripheral driver.
This is the very thing that regmap is supposed to hide, the specifics of how the read or write access happens. regmap_read() is supposed to do a read, regmap_write() is supposed to do a write. If regmap_read() only does a write if you previously did a regmap_write(regmap, CTRL0, SPI_READ); then the semantics of the interface are broken. This means you can't use generic infrastructure and it will confuse people who read and review your code.
- Lars