Skip to content

Commit 5d9d4c1

Browse files
committed
i2c: Add work-around to make i2c scan work
The I2C HW cannot support 0-byte transfer as I2C scan requests. Send one dummy byte for I2C scan to make it work. Signed-off-by: Dong Wang <dong.d.wang@intel.com>
1 parent cab34ab commit 5d9d4c1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

bsp_sedi/drivers/i2c/sedi_i2c_dw_apb_200a.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ int32_t sedi_i2c_master_write_async(IN sedi_i2c_t i2c_device, IN uint32_t addr,
878878
DBG_CHECK(i2c_device < SEDI_I2C_NUM, SEDI_DRIVER_ERROR_PARAMETER);
879879
DBG_CHECK(0 != (addr & SEDI_RBFM(I2C, TAR, IC_TAR)), SEDI_DRIVER_ERROR_PARAMETER);
880880
DBG_CHECK(NULL != data, SEDI_DRIVER_ERROR_PARAMETER);
881-
DBG_CHECK(0 != num, SEDI_DRIVER_ERROR_PARAMETER);
881+
DBG_CHECK((0 != num) || (NULL != data), SEDI_DRIVER_ERROR_PARAMETER);
882882

883883
struct i2c_context *context = &contexts[i2c_device];
884884

@@ -909,7 +909,12 @@ int32_t sedi_i2c_master_write_async(IN sedi_i2c_t i2c_device, IN uint32_t addr,
909909
context->status.event = SEDI_I2C_EVENT_TRANSFER_NONE;
910910

911911
context->buf = (uint8_t *)data;
912-
context->buf_size = num;
912+
if ((num == 0) && (data != NULL)) {
913+
/* Workaround for I2C scanner as HW does not support 0 byte transfers. */
914+
context->buf_size = 1;
915+
} else {
916+
context->buf_size = num;
917+
}
913918
context->rx_cmd_index = 0;
914919
context->buf_index = 0;
915920
context->pending = pending;

0 commit comments

Comments
 (0)