diff mbox series

[2/2] i2c: slave-eeprom: support additional models

Message ID 20191001164009.21610-2-alpawi@amazon.com
State Superseded
Headers show
Series [1/2] i2c: slave-eeprom: initialize empty eeprom properly | expand

Commit Message

Patrick Williams Oct. 1, 2019, 4:40 p.m. UTC
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.

Signed-off-by: Patrick Williams <alpawi@amazon.com>
---
 drivers/i2c/i2c-slave-eeprom.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Wolfram Sang April 20, 2020, 4:46 p.m. UTC | #1
On Tue, Oct 01, 2019 at 11:40:06AM -0500, Patrick Williams wrote:
> 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.
> 
> Signed-off-by: Patrick Williams <alpawi@amazon.com>

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.
Patrick Williams April 20, 2020, 8:23 p.m. UTC | #2
On Mon, Apr 20, 2020 at 06:46:19PM +0200, Wolfram Sang wrote:
> On Tue, Oct 01, 2019 at 11:40:06AM -0500, Patrick Williams wrote:
> > 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.
> > 
> > Signed-off-by: Patrick Williams <alpawi@amazon.com>
> 
> 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.
diff mbox series

Patch

diff --git a/drivers/i2c/i2c-slave-eeprom.c b/drivers/i2c/i2c-slave-eeprom.c
index efee56106251..65419441313b 100644
--- a/drivers/i2c/i2c-slave-eeprom.c
+++ b/drivers/i2c/i2c-slave-eeprom.c
@@ -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);