I have a I2C client driver that reads some registers on a device via an I2C bus driver. Depending on the length of data to be read, it either calls i2c_smbus_read_byte_data, i2c_smbus_read_word_data or i2c_smbus_read_i2c_block_data depending on the length of data to be read:
Code:
if (count == 1) { /* I2C_SMBUS_BYTE_DATA */
*reg_val = i2c_smbus_read_byte_data(i2c_client, reg_addr);
noBytes = 1;
} else if (count == 2) { /* I2C_SMBUS_WORD_DATA */
*((uint16_t *)reg_val) = i2c_smbus_read_word_data(i2c_client, reg_addr);
noBytes = 2;
} else if (count > 2) { /* I2C_SMBUS_I2C_BLOCK_DATA */
noBytes = i2c_smbus_read_i2c_block_data(i2c_client, reg_addr, count, reg_val);
}
The block read function returns the number of bytes read, so I can use this to determine if the read was successful, but the byte and word read functions return the value read. How can I determine whether or not this was successful? When the device is unplugged, the registers read 0xff or 0xffff, but those are also valid register values.
I'll probably figure something out myself eventually but if anyone has any ideas?