misc: i2c_eeprom: implement different probe test eeprom offset
PATCH 1/1 misc: i2c_eeprom: implement different probe test eeprom offset
Because of this commit :5ae84860b0 ("misc: i2c_eeprom: verify that the chip is functional at probe()") at probe time, each eeprom is tested for read at offset 0.
The Atmel AT24MAC402 eeprom has different mapping. One i2c slave address is used for the lower 0x80 bytes and another i2c slave address is used for the upper 0x80 bytes. Because of this basically the i2c master sees 2 different slaves. We need the upper bytes because we read the unique MAC address from this EEPROM area.
However this implies that our slave address will return error on reads from address 0x0 to 0x80.
To solve this, implemented a way to figure out from the compatible udevice_id 'data' field which offset we should attempt to read.
Added the offset as one byte in the data field (byte number 3). Created two macros that will convert offset to 'data' field and back.
The probe function will now read this offset and use it, instead of blindly checking offset 0.
This will fix the regression noticed on these EEPROMs since the commit abovementioned that introduces the probe failed issue.
The offset field can for sure be updated later at a 2byte offset if needed by anyone.
--- drivers/misc/i2c_eeprom.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/misc/i2c_eeprom.c +16 -2
@@ -11,6 +11,13 @@#include <i2c.h> #include <i2c_eeprom.h> +/* These macros are used to encode/decode the starting EEPROM offset into the +* udevice_id structure's data field 3rd byte. +* Lower 2 bytes of the data field are used for pagewidth. +*/ +#define I2C_EEPROM_OFFSET_TO_DATA (v) ((v) << 16) +#define I2C_EEPROM_DATA_TO_OFFSET (v) ((v) >> 16) +int i2c_eeprom_read (struct udevice *dev,int offset,uint8_t *buf,int size) {const struct i2c_eeprom_ops *ops =device_get_ops (dev);
@@ -85,11 +92,17 @@ static int i2c_eeprom_std_ofdata_to_platdata(struct udevice *dev)static int i2c_eeprom_std_probe (struct udevice *dev) { +u64 data =dev_get_driver_data (dev);u8 test_byte;int ret;/* Verify that the chip is functional */ - ret =i2c_eeprom_read (dev,0 , &test_byte,1 ); +/* +* Not all eeproms start from offset 0. Valid offset is encoded in +* upper bits of the data (byte 3). +*/ + ret =i2c_eeprom_read (dev,I2C_EEPROM_DATA_TO_OFFSET (data) &0xFF , + &test_byte,1 );if (ret)return -ENODEV ;
@@ -105,7 +118,8 @@ static const struct udevice_id i2c_eeprom_std_ids[] = { { .compatible = "atmel,24c08", .data = 4 }, { .compatible = "atmel,24c08a", .data = 4 }, { .compatible = "atmel,24c16a", .data = 4 }, - { .compatible = "atmel,24mac402", .data = 4 }, + { .compatible = "atmel,24mac402", + .data = (4 | I2C_EEPROM_OFFSET_TO_DATA(0x80))}, { .compatible = "atmel,24c32", .data = 5 }, { .compatible = "atmel,24c64", .data = 5 }, { .compatible = "atmel,24c128", .data = 6 },
Signature · 1 line
2.25.1
PATCH 1/1 misc: i2c_eeprom: implement different probe test eeprom offset
Hi Eugen,
Quoted 18 lines · Eugen Hristev
Because of this commit :
5ae84860b0("misc:i2c_eeprom: verify that the chip is functional atprobe()") at probe time, each eeprom is tested for read at offset 0.The Atmel AT24MAC402 eeprom has different mapping. One i2c slave address is used for the lower
0x80bytes and another i2c slave address is used for the upper0x80bytes. Because of this basically the i2c master sees 2 different slaves. We need the upper bytes because we read the unique MAC address from this EEPROM area.However this implies that our slave address will return error on reads from address
0x0to0x80.To solve this, implemented a way to figure out from the compatible
udevice_id'data' field which offset we should attempt to read.
Added the offset as one byte in the data field (byte number 3). Created two macros that will convert offset to 'data' field and back.
Quoted 5 lines
The probe function will now read this offset and use it, instead of blindly checking offset 0.
This will fix the regression noticed on these EEPROMs since the commit abovementioned that introduces the probe failed issue.
Judging from the Linux at24 driver that commit appears to break a number of other eeprom chips. I suggest to just revert it.
baruch
Quoted 56 lines
The offset field can for sure be updated later at a 2byte offset if needed by anyone.
Signed-off-by Eugen Hristev <[email protected]>--- drivers/misc/i2c_eeprom.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)drivers/misc/i2c_eeprom.c +16
-2@@ -11,6 +11,13 @@#include <i2c.h> #include <i2c_eeprom.h> +/* These macros are used to encode/decode the starting EEPROM offset into the +* udevice_id structure's data field 3rd byte. +* Lower 2 bytes of the data field are used for pagewidth. +*/ +#define I2C_EEPROM_OFFSET_TO_DATA (v) ((v) << 16) +#define I2C_EEPROM_DATA_TO_OFFSET (v) ((v) >> 16) +int i2c_eeprom_read (struct udevice *dev,int offset,uint8_t *buf,int size) {const struct i2c_eeprom_ops *ops =device_get_ops (dev);@@ -85,11 +92,17 @@ static int i2c_eeprom_std_ofdata_to_platdata(struct udevice *dev)static int i2c_eeprom_std_probe (struct udevice *dev) { +u64 data =dev_get_driver_data (dev);u8 test_byte;int ret;/* Verify that the chip is functional */ - ret =i2c_eeprom_read (dev,0 , &test_byte,1 ); +/* +* Not all eeproms start from offset 0. Valid offset is encoded in +* upper bits of the data (byte 3). +*/ + ret =i2c_eeprom_read (dev,I2C_EEPROM_DATA_TO_OFFSET (data) &0xFF , + &test_byte,1 );if (ret)return -ENODEV ;@@ -105,7 +118,8 @@ static const struct udevice_id i2c_eeprom_std_ids[] = { { .compatible = "atmel,24c08", .data = 4 }, { .compatible = "atmel,24c08a", .data = 4 }, { .compatible = "atmel,24c16a", .data = 4 }, - { .compatible = "atmel,24mac402", .data = 4 }, + { .compatible = "atmel,24mac402", + .data = (4 | I2C_EEPROM_OFFSET_TO_DATA(0x80))}, { .compatible = "atmel,24c32", .data = 5 }, { .compatible = "atmel,24c64", .data = 5 }, { .compatible = "atmel,24c128", .data = 6 },
Signature · 3 lines
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -PATCH 1/1 misc: i2c_eeprom: implement different probe test eeprom offset
Quoted 24 lines · Baruch Siach
Hi Eugen,
Quoted 21 lines · Eugen Hristev
Because of this commit :
5ae84860b0("misc:i2c_eeprom: verify that the chip is functional atprobe()") at probe time, each eeprom is tested for read at offset 0.The Atmel AT24MAC402 eeprom has different mapping. One i2c slave address is used for the lower
0x80bytes and another i2c slave address is used for the upper0x80bytes. Because of this basically the i2c master sees 2 different slaves. We need the upper bytes because we read the unique MAC address from this EEPROM area.However this implies that our slave address will return error on reads from address
0x0to0x80.To solve this, implemented a way to figure out from the compatible
udevice_id'data' field which offset we should attempt to read.
Added the offset as one byte in the data field (byte number 3). Created two macros that will convert offset to 'data' field and back.The probe function will now read this offset and use it, instead of blindly checking offset 0.
Quoted 8 lines
Quoted 2 lines
This will fix the regression noticed on these EEPROMs since the commit abovementioned that introduces the probe failed issue.
Judging from the Linux at24 driver that commit appears to break a number of other eeprom chips. I suggest to just revert it.
baruch
Hi,
Please disregard this patch as it's done for u-boot 2020.01 . I did not notice driver changed in later versions. I sent a v2 that is done for the master u-boot.
Thanks !
Quoted 63 lines
Quoted 47 lines
The offset field can for sure be updated later at a 2byte offset if needed by anyone.
Signed-off-by Eugen Hristev <[email protected]>--- drivers/misc/i2c_eeprom.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)drivers/misc/i2c_eeprom.c +14
-1@@ -11,6 +11,13 @@#include <i2c.h> #include <i2c_eeprom.h> +/* These macros are used to encode/decode the starting EEPROM offset into the +* udevice_id structure's data field 3rd byte. +* Lower 2 bytes of the data field are used for pagewidth. +*/ +#define I2C_EEPROM_OFFSET_TO_DATA (v) ((v) << 16) +#define I2C_EEPROM_DATA_TO_OFFSET (v) ((v) >> 16) +int i2c_eeprom_read (struct udevice *dev,int offset,uint8_t *buf,int size) {const struct i2c_eeprom_ops *ops =device_get_ops (dev);@@ -85,11 +92,17 @@ static int i2c_eeprom_std_ofdata_to_platdata(struct udevice *dev)static int i2c_eeprom_std_probe (struct udevice *dev) { +u64 data =dev_get_driver_data (dev);u8 test_byte;int ret;/* Verify that the chip is functional */ - ret =i2c_eeprom_read (dev,0 , &test_byte,1 ); +/* +* Not all eeproms start from offset 0. Valid offset is encoded in +* upper bits of the data (byte 3). +*/ + ret =i2c_eeprom_read (dev,I2C_EEPROM_DATA_TO_OFFSET (data) &0xFF , + &test_byte,1 );if (ret)return -ENODEV ;drivers/misc/i2c_eeprom.c static const struct udevice_id i2c_eeprom_std_ids[] = { · line 125
Quoted 9 lines
drivers/misc/i2c_eeprom.c +2
-1@@ -105,7 +118,8 @@ static const struct udevice_id i2c_eeprom_std_ids[] = { { .compatible = "atmel,24c08", .data = 4 }, { .compatible = "atmel,24c08a", .data = 4 }, { .compatible = "atmel,24c16a", .data = 4 }, - { .compatible = "atmel,24mac402", .data = 4 }, + { .compatible = "atmel,24mac402", + .data = (4 | I2C_EEPROM_OFFSET_TO_DATA(0x80))}, { .compatible = "atmel,24c32", .data = 5 }, { .compatible = "atmel,24c64", .data = 5 }, { .compatible = "atmel,24c128", .data = 6 },--
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
PATCH 1/1 misc: i2c_eeprom: implement different probe test eeprom offset
In reply to Baruch SiachHello Baruch,
Am 06.05.2020 um 18:47 schrieb Baruch Siach:
Quoted 21 lines
Hi Eugen,
Quoted 18 lines · Eugen Hristev
Because of this commit :
5ae84860b0("misc:i2c_eeprom: verify that the chip is functional atprobe()") at probe time, each eeprom is tested for read at offset 0.The Atmel AT24MAC402 eeprom has different mapping. One i2c slave address is used for the lower
0x80bytes and another i2c slave address is used for the upper0x80bytes. Because of this basically the i2c master sees 2 different slaves. We need the upper bytes because we read the unique MAC address from this EEPROM area.However this implies that our slave address will return error on reads from address
0x0to0x80.To solve this, implemented a way to figure out from the compatible
udevice_id'data' field which offset we should attempt to read.
Added the offset as one byte in the data field (byte number 3). Created two macros that will convert offset to 'data' field and back.
Quoted 8 lines
Quoted 5 lines
The probe function will now read this offset and use it, instead of blindly checking offset 0.
This will fix the regression noticed on these EEPROMs since the commit abovementioned that introduces the probe failed issue.
Judging from the Linux at24 driver that commit appears to break a number of other eeprom chips. I suggest to just revert it.
Hmm... how does the linux driver than work, as it has exact the same read?
See:
https://elixir.bootlin.com/linux/latest/source/drivers/misc/eeprom/at24.c#L710
So the fix from Eugen seems not too bad to me... but it should be done also in linux ... or?
bye,
Heiko
Quoted 61 lines
baruch
Quoted 56 lines
The offset field can for sure be updated later at a 2byte offset if needed by anyone.
Signed-off-by Eugen Hristev <[email protected]>--- drivers/misc/i2c_eeprom.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)drivers/misc/i2c_eeprom.c +16
-2@@ -11,6 +11,13 @@#include <i2c.h> #include <i2c_eeprom.h> +/* These macros are used to encode/decode the starting EEPROM offset into the +* udevice_id structure's data field 3rd byte. +* Lower 2 bytes of the data field are used for pagewidth. +*/ +#define I2C_EEPROM_OFFSET_TO_DATA (v) ((v) << 16) +#define I2C_EEPROM_DATA_TO_OFFSET (v) ((v) >> 16) +int i2c_eeprom_read (struct udevice *dev,int offset,uint8_t *buf,int size) {const struct i2c_eeprom_ops *ops =device_get_ops (dev);@@ -85,11 +92,17 @@ static int i2c_eeprom_std_ofdata_to_platdata(struct udevice *dev)static int i2c_eeprom_std_probe (struct udevice *dev) { +u64 data =dev_get_driver_data (dev);u8 test_byte;int ret;/* Verify that the chip is functional */ - ret =i2c_eeprom_read (dev,0 , &test_byte,1 ); +/* +* Not all eeproms start from offset 0. Valid offset is encoded in +* upper bits of the data (byte 3). +*/ + ret =i2c_eeprom_read (dev,I2C_EEPROM_DATA_TO_OFFSET (data) &0xFF , + &test_byte,1 );if (ret)return -ENODEV ;@@ -105,7 +118,8 @@ static const struct udevice_id i2c_eeprom_std_ids[] = { { .compatible = "atmel,24c08", .data = 4 }, { .compatible = "atmel,24c08a", .data = 4 }, { .compatible = "atmel,24c16a", .data = 4 }, - { .compatible = "atmel,24mac402", .data = 4 }, + { .compatible = "atmel,24mac402", + .data = (4 | I2C_EEPROM_OFFSET_TO_DATA(0x80))}, { .compatible = "atmel,24c32", .data = 5 }, { .compatible = "atmel,24c64", .data = 5 }, { .compatible = "atmel,24c128", .data = 6 },
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de
PATCH 1/1 misc: i2c_eeprom: implement different probe test eeprom offset
Quoted 34 lines · Heiko Schocher
Hello Baruch,
Am 06.05.2020 um 18:47 schrieb Baruch Siach:
Quoted 31 lines
Hi Eugen,
Quoted 28 lines · Eugen Hristev
Because of this commit :
5ae84860b0("misc:i2c_eeprom: verify that the chip is functional atprobe()")
at probe time, each eeprom is tested for read at offset 0.The Atmel AT24MAC402 eeprom has different mapping. One i2c slave address is
used for the lower0x80bytes and another i2c slave address is used for the
upper0x80bytes. Because of this basically the i2c master sees 2 different
slaves. We need the upper bytes because we read the unique MAC address from
this EEPROM area.However this implies that our slave address will return error on reads from address
0x0to0x80.To solve this, implemented a way to figure out from the compatible
udevice_id
'data' field which offset we should attempt to read.
Added the offset as one byte in the data field (byte number 3). Created two macros that will convert offset to 'data' field and back.The probe function will now read this offset and use it, instead of blindly
checking offset 0.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
This will fix the regression noticed on these EEPROMs since the commit abovementioned that introduces the probe failed issue.
Judging from the Linux at24 driver that commit appears to break a number of other eeprom chips. I suggest to just revert it.
Hmm... how does the linux driver than work, as it has exact the same read?
Hi Heiko,
My feeling is that Linux driver is much more enhanced... it adds dummy devices for secondary addresses to be able to read the second part of the eeproms and adjusts the offset
https://elixir.bootlin.com/linux/latest/source/drivers/misc/eeprom
/at24.c#L530
and
https://elixir.bootlin.com/linux/latest/source/drivers/misc/eeprom/at24.c#L673
In our u-boot case our driver is much simpler so we would have to cope with this scenario.
Heiko can you please look at the v2 of this patch. My fix is even more simpler with the new changes in U-boot. This patch is based on old u-boot
Thanks !
Quoted 81 lines
See:
https://elixir.bootlin.com/linux/latest/source/drivers/misc/eeprom/at24.c#L710So the fix from Eugen seems not too bad to me... but it should be done also in linux ... or?
bye,
HeikoQuoted 66 lines
baruch
Quoted 61 lines
The offset field can for sure be updated later at a 2byte offset if needed
by anyone.Signed-off-by Eugen Hristev <[email protected]>---
?drivers/misc/i2c_eeprom.c| 18 ++++++++++++++++-- ? 1 file changed, 16 insertions(+), 2 deletions(-)drivers/misc/i2c_eeprom.c +0
-0@@ -11,6 +11,13 @@? #include <
i2c.h>
? #include <i2c_eeprom.h>+/* These macros are used to encode/decode the starting EEPROM offset into the
+ *udevice_idstructure's data field 3rd byte.
+ * Lower 2 bytes of the data field are used for pagewidth.
+ */drivers/misc/i2c_eeprom.c +3
-0+#define I2C_EEPROM_OFFSET_TO_DATA (v) ((v) << 16) +#define I2C_EEPROM_DATA_TO_OFFSET (v) ((v) >> 16) +? int
i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, int size)
? {
???? const structi2c_eeprom_ops*ops =device_get_ops(dev);drivers/misc/i2c_eeprom.c +1
-0@@ -85,11 +92,17 @@ static int i2c_eeprom_std_ofdata_to_platdata(struct udevice *dev) ? static int i2c_eeprom_std_probe(struct udevice *dev) ? { +??? u64 data = dev_get_driver_data(dev); ???? u8 test_byte; ???? int ret;???? /* Verify that the chip is functional */
-??? ret =i2c_eeprom_read(dev, 0, &test_byte, 1);
+??? /*
+???? * Not all eeproms start from offset 0. Valid offset is encoded in +???? * upper bits of the data (byte 3).
+???? */
+??? ret =i2c_eeprom_read(dev, I2C_EEPROM_DATA_TO_OFFSET(data) & 0xFF, +????????????????????????? &test_byte, 1);
???? if (ret)
???????????? return-ENODEV;drivers/misc/i2c_eeprom.c +2
-1@@ -105,7 +118,8 @@ static const struct udevice_id i2c_eeprom_std_ids[] = { ???? { .compatible = "atmel,24c08", .data = 4 }, ???? { .compatible = "atmel,24c08a", .data = 4 }, ???? { .compatible = "atmel,24c16a", .data = 4 }, -??? { .compatible = "atmel,24mac402", .data = 4 }, +??? { .compatible = "atmel,24mac402", +??????????? .data = (4 | I2C_EEPROM_OFFSET_TO_DATA(0x80))}, ???? { .compatible = "atmel,24c32", .data = 5 }, ???? { .compatible = "atmel,24c64", .data = 5 },???? { .compatible = "atmel,24c128", .data = 6 },
Signature · 3 lines
DENX Software Engineering GmbH,????? Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52?? Fax: +49-8142-66989-80?? Email: hs at denx.de