Skip to content

Commit 3b5f7f1

Browse files
Michael Wuwsakernel
authored andcommitted
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>
1 parent 66b9231 commit 3b5f7f1

1 file changed

Lines changed: 18 additions & 27 deletions

File tree

drivers/i2c/busses/i2c-designware-slave.c

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -172,26 +172,25 @@ static int i2c_dw_irq_handler_slave(struct dw_i2c_dev *dev)
172172
"%#x STATUS SLAVE_ACTIVITY=%#x : RAW_INTR_STAT=%#x : INTR_STAT=%#x\n",
173173
enabled, slave_activity, raw_stat, stat);
174174

175-
if ((stat & DW_IC_INTR_RX_FULL) && (stat & DW_IC_INTR_STOP_DET))
176-
i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_REQUESTED, &val);
175+
if (stat & DW_IC_INTR_RX_FULL) {
176+
if (dev->status != STATUS_WRITE_IN_PROGRESS) {
177+
dev->status = STATUS_WRITE_IN_PROGRESS;
178+
i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_REQUESTED,
179+
&val);
180+
}
181+
182+
regmap_read(dev->map, DW_IC_DATA_CMD, &tmp);
183+
val = tmp;
184+
if (!i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_RECEIVED,
185+
&val))
186+
dev_vdbg(dev->dev, "Byte %X acked!", val);
187+
}
177188

178189
if (stat & DW_IC_INTR_RD_REQ) {
179190
if (slave_activity) {
180-
if (stat & DW_IC_INTR_RX_FULL) {
181-
regmap_read(dev->map, DW_IC_DATA_CMD, &tmp);
182-
val = tmp;
183-
184-
if (!i2c_slave_event(dev->slave,
185-
I2C_SLAVE_WRITE_RECEIVED,
186-
&val)) {
187-
dev_vdbg(dev->dev, "Byte %X acked!",
188-
val);
189-
}
190-
regmap_read(dev->map, DW_IC_CLR_RD_REQ, &tmp);
191-
} else {
192-
regmap_read(dev->map, DW_IC_CLR_RD_REQ, &tmp);
193-
regmap_read(dev->map, DW_IC_CLR_RX_UNDER, &tmp);
194-
}
191+
regmap_read(dev->map, DW_IC_CLR_RD_REQ, &tmp);
192+
193+
dev->status = STATUS_READ_IN_PROGRESS;
195194
if (!i2c_slave_event(dev->slave,
196195
I2C_SLAVE_READ_REQUESTED,
197196
&val))
@@ -203,18 +202,10 @@ static int i2c_dw_irq_handler_slave(struct dw_i2c_dev *dev)
203202
if (!i2c_slave_event(dev->slave, I2C_SLAVE_READ_PROCESSED,
204203
&val))
205204
regmap_read(dev->map, DW_IC_CLR_RX_DONE, &tmp);
206-
207-
i2c_slave_event(dev->slave, I2C_SLAVE_STOP, &val);
208-
return 1;
209205
}
210206

211-
if (stat & DW_IC_INTR_RX_FULL) {
212-
regmap_read(dev->map, DW_IC_DATA_CMD, &tmp);
213-
val = tmp;
214-
if (!i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_RECEIVED,
215-
&val))
216-
dev_vdbg(dev->dev, "Byte %X acked!", val);
217-
} else {
207+
if (stat & DW_IC_INTR_STOP_DET) {
208+
dev->status = STATUS_IDLE;
218209
i2c_slave_event(dev->slave, I2C_SLAVE_STOP, &val);
219210
}
220211

0 commit comments

Comments
 (0)