i2c: designware: slave should do WRITE_REQUESTED before WRITE_RECEIVED
authorMichael Wu <michael.wu@vatics.com>
Fri, 30 Oct 2020 08:04:20 +0000 (16:04 +0800)
committerWolfram Sang <wsa@kernel.org>
Fri, 6 Nov 2020 15:02:00 +0000 (16:02 +0100)
commit3b5f7f10ff6e6b66f553e12cc50d9bb751ce60ad
treec84ae2f911eab4bd7ac94bad5d1dae4ea2c819f6
parent66b92313e2ca9208b5f3ebf5d86e9a818299d8fa
i2c: designware: slave should do WRITE_REQUESTED before WRITE_RECEIVED

Sometimes we would get the following flow when doing an i2cset:

0x1 STATUS SLAVE_ACTIVITY=0x1 : RAW_INTR_STAT=0x514 : INTR_STAT=0x4
I2C_SLAVE_WRITE_RECEIVED
0x1 STATUS SLAVE_ACTIVITY=0x0 : RAW_INTR_STAT=0x714 : INTR_STAT=0x204
I2C_SLAVE_WRITE_REQUESTED
I2C_SLAVE_WRITE_RECEIVED

Documentation/i2c/slave-interface.rst says that I2C_SLAVE_WRITE_REQUESTED,
which is mandatory, should be sent while the data did not arrive yet. It
means in a write-request I2C_SLAVE_WRITE_REQUESTED should be reported
before any I2C_SLAVE_WRITE_RECEIVED.

By the way, I2C_SLAVE_STOP didn't be reported in the above case because
DW_IC_INTR_STAT was not 0x200.

dev->status can be used to record the current state, especially Designware
I2C controller has no interrupts to identify a write-request. This patch
makes not only I2C_SLAVE_WRITE_REQUESTED been reported first when
IC_INTR_RX_FULL is rising and dev->status isn't STATUS_WRITE_IN_PROGRESS
but also I2C_SLAVE_STOP been reported when a STOP condition is received.

Signed-off-by: Michael Wu <michael.wu@vatics.com>
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
drivers/i2c/busses/i2c-designware-slave.c