at24: support eeproms that do not auto-rollover reads.
v5 cover at24: support eeproms that do not auto-rollover reads.
v5:
at Rob Herring's request, renamed devicetree property: at24,no-read-rollover -> no-read-rollover
v4:
renamed devicetree property:
no-read-rollover -> at24,no-read-rollover
dt-bindings update now a separate patch
v3:
rebased against at24 maintainer's devel staging branch:
git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git at24/devel clarified some of the comments and wording
v2:
kbuild test robot feedback: correct
"warning: comparison of distinct pointer types lacks a cast"
build warning on some compilers / architectures.
v1:
original patch
Sven Van Asbroeck (2):
at24: support eeproms that do not auto-rollover reads.
dt-bindings: add eeprom "at24,no-read-rollover" property
.../devicetree/bindings/eeprom/eeprom.txt | 5 +++ drivers/misc/eeprom/at24.c | 37 +++++++++++++++------- include/linux/platform_data/at24.h | 2 ++ 3 files changed, 32 insertions(+), 12 deletions(-)
Signature · 1 line
1.9.1
PATCH v5 1/2 at24: support eeproms that do not auto-rollover reads.
Some multi-address eeproms in the at24 family may not automatically roll-over reads to the next slave address. On those eeproms, reads that straddle slave boundaries will not work correctly.
Solution:
Mark such eeproms with a flag that prevents reads straddling slave boundaries. Add the AT24_FLAG_NO_RDROL flag to the eeprom entry in the device_id table, or add 'no-read-rollover' to the eeprom devicetree entry.
Note that I have not personally enountered an at24 chip that does not support read rollovers. They may or may not exist. However, my hardware requires this functionality because of a quirk.
It's up to the Linux community to decide if this patch is useful/ general enough to warrant merging.
--- drivers/misc/eeprom/at24.c | 37 +++++++++++++++++++++++++------------ include/linux/platform_data/at24.h | 2 ++ 2 files changed, 27 insertions(+), 12 deletions(-)
drivers/misc/eeprom/at24.c +25 -12
@@ -251,15 +251,6 @@ struct at24_data {* Slave address and byte offset derive from the offset. Always * set the byte address; on a multi-master board, another master * may have changed the chip's "current" address pointer. -* -* REVISIT some multi-address chips don't rollover page reads to -* the next slave address, so we may need to truncate the count. -* Those chips might need another quirk flag. -* -* If the real hardware used four adjacent 24c02 chips and that -* were misconfigured as one 24c08, that would be a similar effect: -* one "eeprom" file not four, but larger reads would fail when -* they crossed certain pages. */ static struct at24_client *at24_translate_offset (struct at24_data *at24,unsigned int *offset)
@@ -277,6 +268,28 @@ static struct at24_client *at24_translate_offset(struct at24_data *at24,return &at24->client[i]; } +static size_t at24_adjust_read_count (struct at24_data *at24, +unsigned int offset,size_t count) +{ +unsigned int bits; +size_t remainder; +/* +* In case of multi-address chips that don't rollover reads to +* the next slave address: truncate the count to the slave boundary, +* so that the read never straddles slaves. +*/ +if (at24->chip.flags &AT24_FLAG_NO_RDROL ) { + bits = (at24->chip.flags &AT24_FLAG_ADDR16 ) ?16 :8 ; + remainder =BIT (bits) - offset; +if (count > remainder) + count = remainder; + } +if (count > io_limit) + count = io_limit; + +return count; +} +static ssize_t at24_regmap_read (struct at24_data *at24,char *buf,unsigned int offset,size_t count) {
@@ -289,9 +302,7 @@ static ssize_t at24_regmap_read(struct at24_data *at24, char *buf, at24_client =at24_translate_offset (at24, &offset); regmap = at24_client->regmap; client = at24_client->client; - -if (count > io_limit) - count = io_limit; + count =at24_adjust_read_count (at24, offset, count);/* adjust offset for mac and serial read ops */ offset += at24->offset_adj;
@@ -457,6 +468,8 @@ static void at24_get_pdata(struct device *dev, struct at24_platform_data *chip)if (device_property_present (dev,"read-only" )) chip->flags |=AT24_FLAG_READONLY ; +if (device_property_present (dev,"no-read-rollover" )) + chip->flags |=AT24_FLAG_NO_RDROL ; err =device_property_read_u32 (dev,"size" , &val);if (!err)
include/linux/platform_data/at24.h +2 -0
@@ -50,6 +50,8 @@ struct at24_platform_data {#define AT24_FLAG_TAKE8ADDR BIT(4)/* take always 8 addresses (24c00) */ #define AT24_FLAG_SERIAL BIT(3)/* factory-programmed serial number */ #define AT24_FLAG_MAC BIT(2)/* factory-programmed mac address */ +#define AT24_FLAG_NO_RDROL BIT(1)/* does not auto-rollover reads to */ +/* the next slave address */ void (*setup)(struct nvmem_device *nvmem,void *context);void *context;
Signature · 1 line
1.9.1
2017-12-07 15:36 GMT+01:00 Sven Van Asbroeck <[email protected]>:
Quoted 15 lines
Some multi-address eeproms in the at24 family may not automatically roll-over reads to the next slave address. On those eeproms, reads that straddle slave boundaries will not work correctly.
Solution:
Mark such eeproms with a flag that prevents reads straddling slave boundaries. Add theAT24_FLAG_NO_RDROLflag to the eeprom entry in thedevice_idtable, or add 'no-read-rollover' to the eeprom devicetree entry.Note that I have not personally enountered an at24 chip that does not support read rollovers. They may or may not exist. However, my hardware requires this functionality because of a quirk.
Quoted 9 lines
It's up to the Linux community to decide if this patch is useful/ general enough to warrant merging.
Signed-off-by Sven Van Asbroeck <[email protected]>--- drivers/misc/eeprom/at24.c | 37 +++++++++++++++++++++++++------------ include/linux/platform_data/at24.h | 2 ++ 2 files changed, 27 insertions(+), 12 deletions(-)
Hi Sven,
looks good in general, just a couple nits to fix below and it can be applied.
Quoted 21 lines
drivers/misc/eeprom/at24.c +0
-9@@ -251,15 +251,6 @@ struct at24_data {* Slave address and byte offset derive from the offset. Always * set the byte address; on a multi-master board, another master * may have changed the chip's "current" address pointer. -* -* REVISIT some multi-address chips don't rollover page reads to -* the next slave address, so we may need to truncate the count. -* Those chips might need another quirk flag. -* -* If the real hardware used four adjacent 24c02 chips and that -* were misconfigured as one 24c08, that would be a similar effect: -* one "eeprom" file not four, but larger reads would fail when -* they crossed certain pages. */ static struct at24_client *at24_translate_offset (struct at24_data *at24,unsigned int *offset)
drivers/misc/eeprom/at24.c static struct at24_client *at24_translate_offset(struct at24_data *at24, · line 275
Quoted 8 lines
drivers/misc/eeprom/at24.c +5
-0@@ -277,6 +268,28 @@ static struct at24_client *at24_translate_offset(struct at24_data *at24,return &at24->client[i]; } +static size_t at24_adjust_read_count (struct at24_data *at24, +unsigned int offset,size_t count) +{ +unsigned int bits; +size_t remainder;
Add a newline here.
drivers/misc/eeprom/at24.c static struct at24_client *at24_translate_offset(struct at24_data *at24, · line 282
Quoted 7 lines
drivers/misc/eeprom/at24.c +7
-0+/* +* In case of multi-address chips that don't rollover reads to +* the next slave address: truncate the count to the slave boundary, +* so that the read never straddles slaves. +*/ +if (at24->chip.flags &AT24_FLAG_NO_RDROL ) { + bits = (at24->chip.flags &AT24_FLAG_ADDR16 ) ?16 :8 ;
There's no need for braces around the ternary operator's condition.
drivers/misc/eeprom/at24.c static struct at24_client *at24_translate_offset(struct at24_data *at24, · line 286
Quoted 4 lines
drivers/misc/eeprom/at24.c +4
-0+ remainder =BIT (bits) - offset; +if (count > remainder) + count = remainder; + }
Another newline here.
Quoted 43 lines
drivers/misc/eeprom/at24.c +9
-3+if (count > io_limit) + count = io_limit; + +return count; +} +static ssize_t at24_regmap_read (struct at24_data *at24,char *buf,unsigned int offset,size_t count) {@@ -289,9 +302,7 @@ static ssize_t at24_regmap_read(struct at24_data *at24, char *buf, at24_client =at24_translate_offset (at24, &offset); regmap = at24_client->regmap; client = at24_client->client; - -if (count > io_limit) - count = io_limit; + count =at24_adjust_read_count (at24, offset, count);/* adjust offset for mac and serial read ops */ offset += at24->offset_adj;@@ -457,6 +468,8 @@ static void at24_get_pdata(struct device *dev, struct at24_platform_data *chip)if (device_property_present (dev,"read-only" )) chip->flags |=AT24_FLAG_READONLY ; +if (device_property_present (dev,"no-read-rollover" )) + chip->flags |=AT24_FLAG_NO_RDROL ; err =device_property_read_u32 (dev,"size" , &val);if (!err)include/linux/platform_data/at24.h +2
-1@@ -50,6 +50,8 @@ struct at24_platform_data {#define AT24_FLAG_TAKE8ADDR BIT(4)/* take always 8 addresses (24c00) */ #define AT24_FLAG_SERIAL BIT(3)/* factory-programmed serial number */ #define AT24_FLAG_MAC BIT(2)/* factory-programmed mac address */ +#define AT24_FLAG_NO_RDROL BIT(1)/* does not auto-rollover reads to */ +/* the next slave address */ void (*setup)(struct nvmem_device *nvmem,void *context);void *context; --
Quoted 2 lines
1.9.1
Thanks,
Bartosz
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hello,
Quoted 4 lines · Bartosz Golaszewski
drivers/misc/eeprom/at24.c static struct at24_client *at24_translate_offset(struct at24_data *at24, · line 282
Quoted 2 lines
drivers/misc/eeprom/at24.c +2
-0+if (at24->chip.flags &AT24_FLAG_NO_RDROL ) { + bits = (at24->chip.flags &AT24_FLAG_ADDR16 ) ?16 :8 ;There's no need for braces around the ternary operator's condition.
Even if not required, I'd keep them for clearity.
Best regards
Uwe
Signature · 6 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ | -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
2017-12-07 20:02 GMT+01:00 Uwe Kleine-König <[email protected]>:
Quoted 10 lines
Hello,
Quoted 4 lines · Bartosz Golaszewski
drivers/misc/eeprom/at24.c static struct at24_client *at24_translate_offset(struct at24_data *at24, · line 282
Quoted 2 lines
drivers/misc/eeprom/at24.c +2
-0+if (at24->chip.flags &AT24_FLAG_NO_RDROL ) { + bits = (at24->chip.flags &AT24_FLAG_ADDR16 ) ?16 :8 ;There's no need for braces around the ternary operator's condition.
Even if not required, I'd keep them for clearity.
I don't want to start bikeshedding, so I'll take it as it is, but I prefer to avoid braces wherever it's not necessary.
Thanks,
Bartosz
Quoted 7 lines · Bartosz Golaszewski
2017-12-07 20:02 GMT+01:00 Uwe Kleine-König <[email protected]>:
Quoted 6 lines
Hello,
Quoted 3 lines · Bartosz Golaszewski
Quoted 2 lines
drivers/misc/eeprom/at24.c +2
-0+if (at24->chip.flags &AT24_FLAG_NO_RDROL ) { + bits = (at24->chip.flags &AT24_FLAG_ADDR16 ) ?16 :8 ;
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
There's no need for braces around the ternary operator's condition.
Even if not required, I'd keep them for clearity.
I don't want to start bikeshedding, so I'll take it as it is, but I prefer to avoid braces wherever it's not necessary.
For me the reasoning is: Most people (me included) don't know off-hand if the semantic of
a & b ? c : d
is
(a & b) ? c : d
or
a & (b ? c : d)
In some situations (e.g. a & b == c) gcc even warns when you don't add syntactically needless parentheses. The case under discussion isn't such an example though.
Best regards
Uwe
Signature · 6 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ | -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v5 2/2 dt-bindings: add eeprom "no-read-rollover" property
In reply to Sven Van AsbroeckAdds an optional property for at24 eeproms.
This parameterless property indicates that the multi-address eeprom does not automatically roll over reads to the next slave address.
--- Documentation/devicetree/bindings/eeprom/eeprom.txt | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/eeprom/eeprom.txt +5 -0
@@ -38,6 +38,11 @@ Optional properties: - size: total eeprom size in bytes + - no-read-rollover: + This parameterless property indicates that the multi-address + eeprom does not automatically roll over reads to the next + slave address. Please consult the manual of your device. + Example: eeprom@52 {
Signature · 1 line
1.9.1
Re: [PATCH v5 2/2] dt-bindings: add eeprom "no-read-rollover" property
Quoted 8 lines · Sven Van Asbroeck
Adds an optional property for at24 eeproms.
This parameterless property indicates that the multi-address eeprom does not automatically roll over reads to the next slave address.Signed-off-by Sven Van Asbroeck <[email protected]>--- Documentation/devicetree/bindings/eeprom/eeprom.txt | 5 +++++ 1 file changed, 5 insertions(+)