Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c: octeon: Support I2C_M_RECV_LEN

If I2C_M_RECV_LEN is set consider the length byte.

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
Signed-off-by: Jan Glauber <jglauber@cavium.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

authored by

David Daney and committed by
Wolfram Sang
886f6f83 54108e56

+17 -5
+17 -5
drivers/i2c/busses/i2c-octeon.c
··· 315 315 * @i2c: The struct octeon_i2c 316 316 * @target: Target address 317 317 * @data: Pointer to the location to store the data 318 - * @length: Length of the data 318 + * @rlength: Length of the data 319 + * @recv_len: flag for length byte 319 320 * 320 321 * The address is sent over the bus, then the data is read. 321 322 * 322 323 * Returns 0 on success, otherwise a negative errno. 323 324 */ 324 325 static int octeon_i2c_read(struct octeon_i2c *i2c, int target, 325 - u8 *data, int length) 326 + u8 *data, u16 *rlength, bool recv_len) 326 327 { 327 - int i, result; 328 + int i, result, length = *rlength; 328 329 u8 tmp; 329 330 330 331 if (length < 1) ··· 364 363 return result; 365 364 366 365 data[i] = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_DATA); 366 + if (recv_len && i == 0) { 367 + if (data[i] > I2C_SMBUS_BLOCK_MAX + 1) { 368 + dev_err(i2c->dev, 369 + "%s: read len > I2C_SMBUS_BLOCK_MAX %d\n", 370 + __func__, data[i]); 371 + return -EPROTO; 372 + } 373 + length += data[i]; 374 + } 367 375 } 376 + *rlength = length; 368 377 return 0; 369 378 } 370 379 ··· 401 390 pmsg->len, pmsg->addr, i + 1, num); 402 391 if (pmsg->flags & I2C_M_RD) 403 392 ret = octeon_i2c_read(i2c, pmsg->addr, pmsg->buf, 404 - pmsg->len); 393 + &pmsg->len, pmsg->flags & I2C_M_RECV_LEN); 405 394 else 406 395 ret = octeon_i2c_write(i2c, pmsg->addr, pmsg->buf, 407 396 pmsg->len); ··· 413 402 414 403 static u32 octeon_i2c_functionality(struct i2c_adapter *adap) 415 404 { 416 - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 405 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | 406 + I2C_FUNC_SMBUS_READ_BLOCK_DATA | I2C_SMBUS_BLOCK_PROC_CALL; 417 407 } 418 408 419 409 static const struct i2c_algorithm octeon_i2c_algo = {