Skip to content

Commit 5c71ca4

Browse files
Wolfram Sangwsakernel
authored andcommitted
i2c: slave-eeprom: add support for 24c512 EEPROMs
I don't plan to support every EEPROM type, but the 24c512 ones need a tiny code update, so let's have that upstream. Reported-by: Patrick Williams <[email protected]> Signed-off-by: Wolfram Sang <[email protected]> Reviewed-by: Patrick Williams <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent be5ce0e commit 5c71ca4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/i2c/i2c-slave-eeprom.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct eeprom_data {
4141
#define I2C_SLAVE_BYTELEN GENMASK(15, 0)
4242
#define I2C_SLAVE_FLAG_ADDR16 BIT(16)
4343
#define I2C_SLAVE_FLAG_RO BIT(17)
44-
#define I2C_SLAVE_DEVICE_MAGIC(_len, _flags) ((_flags) | (_len))
44+
#define I2C_SLAVE_DEVICE_MAGIC(_len, _flags) ((_flags) | ((_len) - 1))
4545

4646
static int i2c_slave_eeprom_slave_cb(struct i2c_client *client,
4747
enum i2c_slave_event event, u8 *val)
@@ -145,7 +145,7 @@ static int i2c_slave_eeprom_probe(struct i2c_client *client, const struct i2c_de
145145
{
146146
struct eeprom_data *eeprom;
147147
int ret;
148-
unsigned int size = FIELD_GET(I2C_SLAVE_BYTELEN, id->driver_data);
148+
unsigned int size = FIELD_GET(I2C_SLAVE_BYTELEN, id->driver_data) + 1;
149149
unsigned int flag_addr16 = FIELD_GET(I2C_SLAVE_FLAG_ADDR16, id->driver_data);
150150

151151
eeprom = devm_kzalloc(&client->dev, sizeof(struct eeprom_data) + size, GFP_KERNEL);
@@ -200,6 +200,8 @@ static const struct i2c_device_id i2c_slave_eeprom_id[] = {
200200
{ "slave-24c32ro", I2C_SLAVE_DEVICE_MAGIC(32768 / 8, I2C_SLAVE_FLAG_ADDR16 | I2C_SLAVE_FLAG_RO) },
201201
{ "slave-24c64", I2C_SLAVE_DEVICE_MAGIC(65536 / 8, I2C_SLAVE_FLAG_ADDR16) },
202202
{ "slave-24c64ro", I2C_SLAVE_DEVICE_MAGIC(65536 / 8, I2C_SLAVE_FLAG_ADDR16 | I2C_SLAVE_FLAG_RO) },
203+
{ "slave-24c512", I2C_SLAVE_DEVICE_MAGIC(524288 / 8, I2C_SLAVE_FLAG_ADDR16) },
204+
{ "slave-24c512ro", I2C_SLAVE_DEVICE_MAGIC(524288 / 8, I2C_SLAVE_FLAG_ADDR16 | I2C_SLAVE_FLAG_RO) },
203205
{ }
204206
};
205207
MODULE_DEVICE_TABLE(i2c, i2c_slave_eeprom_id);

0 commit comments

Comments
 (0)