Skip to content

Commit 2cd9fbd

Browse files
itirdeaWolfram Sang
authored andcommitted
eeprom: at24: use i2c_smbus_read_i2c_block_data_or_emulated
For i2c busses that support only SMBUS extensions, the eeprom at24 driver reads data from the device using the SMBus block, word or byte read protocols depending on availability. Replace the block read emulation from the driver with the i2c_smbus_read_i2c_block_data_or_emulated call from i2c core. Signed-off-by: Irina Tirdea <irina.tirdea@intel.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
1 parent 01eef96 commit 2cd9fbd

File tree

1 file changed

+6
-31
lines changed

1 file changed

+6
-31
lines changed

drivers/misc/eeprom/at24.c

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,11 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
186186
if (count > io_limit)
187187
count = io_limit;
188188

189-
switch (at24->use_smbus) {
190-
case I2C_SMBUS_I2C_BLOCK_DATA:
189+
if (at24->use_smbus) {
191190
/* Smaller eeproms can work given some SMBus extension calls */
192191
if (count > I2C_SMBUS_BLOCK_MAX)
193192
count = I2C_SMBUS_BLOCK_MAX;
194-
break;
195-
case I2C_SMBUS_WORD_DATA:
196-
count = 2;
197-
break;
198-
case I2C_SMBUS_BYTE_DATA:
199-
count = 1;
200-
break;
201-
default:
193+
} else {
202194
/*
203195
* When we have a better choice than SMBus calls, use a
204196
* combined I2C message. Write address; then read up to
@@ -229,27 +221,10 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
229221
timeout = jiffies + msecs_to_jiffies(write_timeout);
230222
do {
231223
read_time = jiffies;
232-
switch (at24->use_smbus) {
233-
case I2C_SMBUS_I2C_BLOCK_DATA:
234-
status = i2c_smbus_read_i2c_block_data(client, offset,
235-
count, buf);
236-
break;
237-
case I2C_SMBUS_WORD_DATA:
238-
status = i2c_smbus_read_word_data(client, offset);
239-
if (status >= 0) {
240-
buf[0] = status & 0xff;
241-
buf[1] = status >> 8;
242-
status = count;
243-
}
244-
break;
245-
case I2C_SMBUS_BYTE_DATA:
246-
status = i2c_smbus_read_byte_data(client, offset);
247-
if (status >= 0) {
248-
buf[0] = status;
249-
status = count;
250-
}
251-
break;
252-
default:
224+
if (at24->use_smbus) {
225+
status = i2c_smbus_read_i2c_block_data_or_emulated(client, offset,
226+
count, buf);
227+
} else {
253228
status = i2c_transfer(client->adapter, msg, 2);
254229
if (status == 2)
255230
status = count;

0 commit comments

Comments
 (0)