i2c: slave-eeprom: initialize empty eeprom properly
Subsystems (2)
PATCH 1/2 i2c: slave-eeprom: initialize empty eeprom properly
The i2c-slave-eeprom driver emulates at24 class eeprom devices, which come initialized with all 1s. Do the same in the software emulation.
--- drivers/i2c/i2c-slave-eeprom.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/i2c/i2c-slave-eeprom.c +2 -0
@@ -131,6 +131,8 @@ static int i2c_slave_eeprom_probe(struct i2c_client *client, const struct i2c_deif (!eeprom)return -ENOMEM ; +memset (eeprom->buffer,0xFF , size); + eeprom->idx_write_cnt =0 ; eeprom->num_address_bytes = flag_addr16 ?2 :1 ; eeprom->address_mask = size -1 ;
Signature · 1 line
2.17.2 (Apple Git-113)
PATCH 2/2 i2c: slave-eeprom: support additional models
Add support for emulating the following EEPROMs:
* 24c01 - 1024 bit
* 24c128 - 128k bit
* 24c256 - 256k bit
* 24c512 - 512k bit
The flag bits in the device id were shifted up 1 bit to make room for saving the 24c512's size. 24c512 uses the full 16-bit address space of a 2-byte addressable EEPROM.
--- drivers/i2c/i2c-slave-eeprom.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/i2c/i2c-slave-eeprom.c +11 -3
@@ -37,9 +37,9 @@ struct eeprom_data {u8 buffer[]; }; -#define I2C_SLAVE_BYTELEN GENMASK(15, 0) -#define I2C_SLAVE_FLAG_ADDR16 BIT(16) -#define I2C_SLAVE_FLAG_RO BIT(17) +#define I2C_SLAVE_BYTELEN GENMASK(16, 0) +#define I2C_SLAVE_FLAG_ADDR16 BIT(17) +#define I2C_SLAVE_FLAG_RO BIT(18)#define I2C_SLAVE_DEVICE_MAGIC (_len, _flags) ((_flags) | (_len)) static int i2c_slave_eeprom_slave_cb(struct i2c_client *client,
@@ -171,12 +171,20 @@ static int i2c_slave_eeprom_remove(struct i2c_client *client) }static const struct i2c_device_id i2c_slave_eeprom_id[] = { + {"slave-24c01" ,I2C_SLAVE_DEVICE_MAGIC (1024 /8 ,0 ) }, + {"slave-24c01ro" ,I2C_SLAVE_DEVICE_MAGIC (1024 /8 ,I2C_SLAVE_FLAG_RO ) }, {"slave-24c02" ,I2C_SLAVE_DEVICE_MAGIC (2048 /8 ,0 ) }, {"slave-24c02ro" ,I2C_SLAVE_DEVICE_MAGIC (2048 /8 ,I2C_SLAVE_FLAG_RO ) }, {"slave-24c32" ,I2C_SLAVE_DEVICE_MAGIC (32768 /8 ,I2C_SLAVE_FLAG_ADDR16 ) }, {"slave-24c32ro" ,I2C_SLAVE_DEVICE_MAGIC (32768 /8 ,I2C_SLAVE_FLAG_ADDR16 |I2C_SLAVE_FLAG_RO ) }, {"slave-24c64" ,I2C_SLAVE_DEVICE_MAGIC (65536 /8 ,I2C_SLAVE_FLAG_ADDR16 ) }, {"slave-24c64ro" ,I2C_SLAVE_DEVICE_MAGIC (65536 /8 ,I2C_SLAVE_FLAG_ADDR16 |I2C_SLAVE_FLAG_RO ) }, + {"slave-24c128" ,I2C_SLAVE_DEVICE_MAGIC (131072 /8 ,I2C_SLAVE_FLAG_ADDR16 ) }, + {"slave-24c128ro" ,I2C_SLAVE_DEVICE_MAGIC (131072 /8 ,I2C_SLAVE_FLAG_ADDR16 |I2C_SLAVE_FLAG_RO ) }, + {"slave-24c256" ,I2C_SLAVE_DEVICE_MAGIC (262144 /8 ,I2C_SLAVE_FLAG_ADDR16 ) }, + {"slave-24c256ro" ,I2C_SLAVE_DEVICE_MAGIC (262144 /8 ,I2C_SLAVE_FLAG_ADDR16 |I2C_SLAVE_FLAG_RO ) }, + {"slave-24c512" ,I2C_SLAVE_DEVICE_MAGIC (524288 /8 ,I2C_SLAVE_FLAG_ADDR16 ) }, + {"slave-24c512ro" ,I2C_SLAVE_DEVICE_MAGIC (524288 /8 ,I2C_SLAVE_FLAG_ADDR16 |I2C_SLAVE_FLAG_RO ) }, { } };MODULE_DEVICE_TABLE (i2c, i2c_slave_eeprom_id);
Signature · 1 line
2.17.2 (Apple Git-113)
Re: [PATCH 2/2] i2c: slave-eeprom: support additional models
Quoted 11 lines · Patrick Williams
Add support for emulating the following EEPROMs:
* 24c01 - 1024 bit
* 24c128 - 128k bit
* 24c256 - 256k bit
* 24c512 - 512k bitThe flag bits in the device id were shifted up 1 bit to make room for saving the 24c512's size. 24c512 uses the full 16-bit address space of a 2-byte addressable EEPROM.
Signed-off-by Patrick Williams <[email protected]>
Do you really need them or is it just nice to have?
I am undecided. I definately don't want all the EEPROM types which exist, but the full 16 bit address range makes sense...
More opinions welcome.
Re: [PATCH 2/2] i2c: slave-eeprom: support additional models
Quoted 11 lines · Wolfram Sang
Quoted 10 lines · Patrick Williams
Add support for emulating the following EEPROMs:
* 24c01 - 1024 bit
* 24c128 - 128k bit
* 24c256 - 256k bit
* 24c512 - 512k bitThe flag bits in the device id were shifted up 1 bit to make room for saving the 24c512's size. 24c512 uses the full 16-bit address space of a 2-byte addressable EEPROM.
Quoted 9 lines
Quoted 1 line
Signed-off-by Patrick Williams <[email protected]>Do you really need them or is it just nice to have?
I am undecided. I definately don't want all the EEPROM types which exist, but the full 16 bit address range makes sense...
More opinions welcome.
I don't remember exactly which ones we needed (and I am no longer at Amazon), but it was pretty trivial to add them all to the table so I went ahead and did it. As long as we had one of the 2-byte addressable EEPROMs, anything else necessary could be handleded as a small out-of-tree patch.
Signature · 1 line
Patrick Williams
Hi,
I sent in another patch earlier that added support for specifying a file in devicetree to initilize the eeprom from, corresponding to the case of pre-flashed eeprom. Maybe these two patches should be merged so this initialization is only done if no file is specified?
/BA
Quoted 22 lines · Patrick Williams
The i2c-slave-eeprom driver emulates at24 class eeprom devices, which come initialized with all 1s. Do the same in the software emulation.
Signed-off-by Patrick Williams <[email protected]>--- drivers/i2c/i2c-slave-eeprom.c | 2 ++ 1 file changed, 2 insertions(+)drivers/i2c/i2c-slave-eeprom.c +2
-0@@ -131,6 +131,8 @@ static int i2c_slave_eeprom_probe(struct i2c_client *client, const struct i2c_deif (!eeprom)return -ENOMEM ; +memset (eeprom->buffer,0xFF , size); + eeprom->idx_write_cnt =0 ; eeprom->num_address_bytes = flag_addr16 ?2 :1 ; eeprom->address_mask = size -1 ;
Quoted 7 lines · Bjorn Ardo
Hi,
I sent in another patch earlier that added support for specifying a file in devicetree to initilize the eeprom from, corresponding to the case of pre-flashed eeprom. Maybe these two patches should be merged so this initialization is only done if no file is specified?
Yes, I agree.
Quoted 24 lines
/BA
Quoted 21 lines · Patrick Williams
The i2c-slave-eeprom driver emulates at24 class eeprom devices, which come initialized with all 1s. Do the same in the software emulation.
Signed-off-by Patrick Williams <[email protected]>--- drivers/i2c/i2c-slave-eeprom.c | 2 ++ 1 file changed, 2 insertions(+)drivers/i2c/i2c-slave-eeprom.c +2
-0@@ -131,6 +131,8 @@ static int i2c_slave_eeprom_probe(struct i2c_client *client, const struct i2c_deif (!eeprom)return -ENOMEM ; +memset (eeprom->buffer,0xFF , size); + eeprom->idx_write_cnt =0 ; eeprom->num_address_bytes = flag_addr16 ?2 :1 ; eeprom->address_mask = size -1 ;
Quoted 11 lines · Wolfram Sang
Quoted 7 lines · Bjorn Ardo
Hi,
I sent in another patch earlier that added support for specifying a file in devicetree to initilize the eeprom from, corresponding to the case of pre-flashed eeprom. Maybe these two patches should be merged so this initialization is only done if no file is specified?
Yes, I agree.
I've been meaning to get back to this... I'll rebase the commit on the latest tree.
Signature · 1 line
Patrick Williams
Quoted 11 lines · Wolfram Sang
Quoted 7 lines · Bjorn Ardo
Hi,
I sent in another patch earlier that added support for specifying a file in devicetree to initilize the eeprom from, corresponding to the case of pre-flashed eeprom. Maybe these two patches should be merged so this initialization is only done if no file is specified?
Yes, I agree.
It looks like Bjorn's referenced patches are still unmerged also?
Signature · 1 line
Patrick Williams
Quoted 10 lines · Patrick Williams
Quoted 9 lines · Wolfram Sang
Quoted 7 lines · Bjorn Ardo
Hi,
I sent in another patch earlier that added support for specifying a file in devicetree to initilize the eeprom from, corresponding to the case of pre-flashed eeprom. Maybe these two patches should be merged so this initialization is only done if no file is specified?
Quoted 4 lines
Quoted 2 lines
Yes, I agree.
It looks like Bjorn's referenced patches are still unmerged also?
Yes, it might be easiest if he merges your patch (with attribution) into the else branch of his fw-load patch.
Quoted 10 lines · Wolfram Sang
Quoted 9 lines · Patrick Williams
Quoted 8 lines · Wolfram Sang
Quoted 7 lines · Bjorn Ardo
Hi,
I sent in another patch earlier that added support for specifying a file in devicetree to initilize the eeprom from, corresponding to the case of pre-flashed eeprom. Maybe these two patches should be merged so this initialization is only done if no file is specified?
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
Yes, I agree.
It looks like Bjorn's referenced patches are still unmerged also?
Yes, it might be easiest if he merges your patch (with attribution) into the else branch of his fw-load patch.
OK, so to summarize, I should update my patch to use device_property_read_string() instead and also init the memory to 0XFF if no file is present. And change name of the function to i2c_slave_init_eeprom_data.
I will look into that and let you know once I'm done.
/BA
Quoted 8 lines
Quoted 4 lines
Yes, it might be easiest if he merges your patch (with attribution) into the else branch of his fw-load patch.
OK, so to summarize, I should update my patch to use
device_property_read_string()instead and also init the memory to0XFFif no file is present. And change name of the function to
Or something else went wrong.
Quoted 1 line
i2c_slave_init_eeprom_data.
Yes, that is my idea. You also need to replace checking for an of_node with some equivalent for device properties maybe, but that should be easy to find out.
Quoted 1 line
I will look into that and let you know once I'm done.
Thank you!
Quoted 7 lines · Wolfram Sang
Quoted 6 lines
Quoted 3 lines
Yes, it might be easiest if he merges your patch (with attribution) into the else branch of his fw-load patch.
OK, so to summarize, I should update my patch to use
device_property_read_string()instead and also init the memory to0XFFif no file is present. And change name of the function toOr something else went wrong.
I did like this now: If device_property_read_string() returns a firmware name, I use that, otherwise init to 0xFF. But if it returns a firmware name, and for some reason I get an error when trying to load that firmware I will not default to 0xFF, but rather fail the probe. The logic in that is that if you actively supply a firmware name, you should not silently get 0xFF in your eeprom. Does that sound good?
Quoted 4 lines
Quoted 1 line
i2c_slave_init_eeprom_data.Yes, that is my idea. You also need to replace checking for an
of_nodewith some equivalent for device properties maybe, but that should be easy to find out.
It appears to me that those kind of checks are done inside device_property_read_string() so I can just remove them and only look at the return value of that function.
Quoted 3 lines
Quoted 1 line
I will look into that and let you know once I'm done.
Thank you!
I have a patch now working on 4.14, will run some tests on it and then try to forward-port to latest kernel och see if it works there as well.
/BA
Quoted 7 lines
I did like this now: If
device_property_read_string()returns a firmware name, I use that, otherwise init to0xFF. But if it returns a firmware name, and for some reason I get an error when trying to load that firmware I will not default to0xFF, but rather fail the probe. The logic in that is that if you actively supply a firmware name, you should not silently get0xFFin your eeprom. Does that sound good?
Sounds perfect to me.
Quoted 7 lines
Quoted 3 lines
Yes, that is my idea. You also need to replace checking for an
of_nodewith some equivalent for device properties maybe, but that should be easy to find out.It appears to me that those kind of checks are done inside
device_property_read_string()so I can just remove them and only look at the return value of that function.
Even better!
Quoted 2 lines
I have a patch now working on 4.14, will run some tests on it and then try to forward-port to latest kernel och see if it works there as well.
Looking forward to it. I will look at it right away then!
Quoted 4 lines · Wolfram Sang
Quoted 2 lines
I have a patch now working on 4.14, will run some tests on it and then try to forward-port to latest kernel och see if it works there as well.
Looking forward to it. I will look at it right away then!
Patch tested on latest kernel and submitted.
/BA