Skip to content

Commit 2618280

Browse files
committed
Merge tag 'i2c-for-6.7-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c fixes from Wolfram Sang: - error path fixes (qcom-geni) - polling mode fix (rk3x) - target mode state machine fix (aspeed) * tag 'i2c-for-6.7-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: i2c: aspeed: Handle the coalesced stop conditions with the start conditions. i2c: rk3x: fix potential spinlock recursion on poll i2c: qcom-geni: fix missing clk_disable_unprepare() and geni_se_resources_off()
2 parents a9ca033 + b4cc1cb commit 2618280

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

drivers/i2c/busses/i2c-aspeed.c

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,46 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status)
249249
if (!slave)
250250
return 0;
251251

252-
command = readl(bus->base + ASPEED_I2C_CMD_REG);
252+
/*
253+
* Handle stop conditions early, prior to SLAVE_MATCH. Some masters may drive
254+
* transfers with low enough latency between the nak/stop phase of the current
255+
* command and the start/address phase of the following command that the
256+
* interrupts are coalesced by the time we process them.
257+
*/
258+
if (irq_status & ASPEED_I2CD_INTR_NORMAL_STOP) {
259+
irq_handled |= ASPEED_I2CD_INTR_NORMAL_STOP;
260+
bus->slave_state = ASPEED_I2C_SLAVE_STOP;
261+
}
262+
263+
if (irq_status & ASPEED_I2CD_INTR_TX_NAK &&
264+
bus->slave_state == ASPEED_I2C_SLAVE_READ_PROCESSED) {
265+
irq_handled |= ASPEED_I2CD_INTR_TX_NAK;
266+
bus->slave_state = ASPEED_I2C_SLAVE_STOP;
267+
}
268+
269+
/* Propagate any stop conditions to the slave implementation. */
270+
if (bus->slave_state == ASPEED_I2C_SLAVE_STOP) {
271+
i2c_slave_event(slave, I2C_SLAVE_STOP, &value);
272+
bus->slave_state = ASPEED_I2C_SLAVE_INACTIVE;
273+
}
253274

254-
/* Slave was requested, restart state machine. */
275+
/*
276+
* Now that we've dealt with any potentially coalesced stop conditions,
277+
* address any start conditions.
278+
*/
255279
if (irq_status & ASPEED_I2CD_INTR_SLAVE_MATCH) {
256280
irq_handled |= ASPEED_I2CD_INTR_SLAVE_MATCH;
257281
bus->slave_state = ASPEED_I2C_SLAVE_START;
258282
}
259283

260-
/* Slave is not currently active, irq was for someone else. */
284+
/*
285+
* If the slave has been stopped and not started then slave interrupt
286+
* handling is complete.
287+
*/
261288
if (bus->slave_state == ASPEED_I2C_SLAVE_INACTIVE)
262289
return irq_handled;
263290

291+
command = readl(bus->base + ASPEED_I2C_CMD_REG);
264292
dev_dbg(bus->dev, "slave irq status 0x%08x, cmd 0x%08x\n",
265293
irq_status, command);
266294

@@ -279,17 +307,6 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status)
279307
irq_handled |= ASPEED_I2CD_INTR_RX_DONE;
280308
}
281309

282-
/* Slave was asked to stop. */
283-
if (irq_status & ASPEED_I2CD_INTR_NORMAL_STOP) {
284-
irq_handled |= ASPEED_I2CD_INTR_NORMAL_STOP;
285-
bus->slave_state = ASPEED_I2C_SLAVE_STOP;
286-
}
287-
if (irq_status & ASPEED_I2CD_INTR_TX_NAK &&
288-
bus->slave_state == ASPEED_I2C_SLAVE_READ_PROCESSED) {
289-
irq_handled |= ASPEED_I2CD_INTR_TX_NAK;
290-
bus->slave_state = ASPEED_I2C_SLAVE_STOP;
291-
}
292-
293310
switch (bus->slave_state) {
294311
case ASPEED_I2C_SLAVE_READ_REQUESTED:
295312
if (unlikely(irq_status & ASPEED_I2CD_INTR_TX_ACK))
@@ -324,8 +341,7 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status)
324341
i2c_slave_event(slave, I2C_SLAVE_WRITE_RECEIVED, &value);
325342
break;
326343
case ASPEED_I2C_SLAVE_STOP:
327-
i2c_slave_event(slave, I2C_SLAVE_STOP, &value);
328-
bus->slave_state = ASPEED_I2C_SLAVE_INACTIVE;
344+
/* Stop event handling is done early. Unreachable. */
329345
break;
330346
case ASPEED_I2C_SLAVE_START:
331347
/* Slave was just started. Waiting for the next event. */;

drivers/i2c/busses/i2c-qcom-geni.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ static int geni_i2c_probe(struct platform_device *pdev)
858858
ret = geni_se_resources_on(&gi2c->se);
859859
if (ret) {
860860
dev_err(dev, "Error turning on resources %d\n", ret);
861+
clk_disable_unprepare(gi2c->core_clk);
861862
return ret;
862863
}
863864
proto = geni_se_read_proto(&gi2c->se);
@@ -877,8 +878,11 @@ static int geni_i2c_probe(struct platform_device *pdev)
877878
/* FIFO is disabled, so we can only use GPI DMA */
878879
gi2c->gpi_mode = true;
879880
ret = setup_gpi_dma(gi2c);
880-
if (ret)
881+
if (ret) {
882+
geni_se_resources_off(&gi2c->se);
883+
clk_disable_unprepare(gi2c->core_clk);
881884
return dev_err_probe(dev, ret, "Failed to setup GPI DMA mode\n");
885+
}
882886

883887
dev_dbg(dev, "Using GPI DMA mode for I2C\n");
884888
} else {
@@ -891,6 +895,8 @@ static int geni_i2c_probe(struct platform_device *pdev)
891895

892896
if (!tx_depth) {
893897
dev_err(dev, "Invalid TX FIFO depth\n");
898+
geni_se_resources_off(&gi2c->se);
899+
clk_disable_unprepare(gi2c->core_clk);
894900
return -EINVAL;
895901
}
896902

drivers/i2c/busses/i2c-rk3x.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ struct rk3x_i2c_soc_data {
178178
* @clk: function clk for rk3399 or function & Bus clks for others
179179
* @pclk: Bus clk for rk3399
180180
* @clk_rate_nb: i2c clk rate change notify
181+
* @irq: irq number
181182
* @t: I2C known timing information
182183
* @lock: spinlock for the i2c bus
183184
* @wait: the waitqueue to wait for i2c transfer
@@ -200,6 +201,7 @@ struct rk3x_i2c {
200201
struct clk *clk;
201202
struct clk *pclk;
202203
struct notifier_block clk_rate_nb;
204+
int irq;
203205

204206
/* Settings */
205207
struct i2c_timings t;
@@ -1087,13 +1089,18 @@ static int rk3x_i2c_xfer_common(struct i2c_adapter *adap,
10871089

10881090
spin_unlock_irqrestore(&i2c->lock, flags);
10891091

1090-
rk3x_i2c_start(i2c);
1091-
10921092
if (!polling) {
1093+
rk3x_i2c_start(i2c);
1094+
10931095
timeout = wait_event_timeout(i2c->wait, !i2c->busy,
10941096
msecs_to_jiffies(WAIT_TIMEOUT));
10951097
} else {
1098+
disable_irq(i2c->irq);
1099+
rk3x_i2c_start(i2c);
1100+
10961101
timeout = rk3x_i2c_wait_xfer_poll(i2c);
1102+
1103+
enable_irq(i2c->irq);
10971104
}
10981105

10991106
spin_lock_irqsave(&i2c->lock, flags);
@@ -1310,6 +1317,8 @@ static int rk3x_i2c_probe(struct platform_device *pdev)
13101317
return ret;
13111318
}
13121319

1320+
i2c->irq = irq;
1321+
13131322
platform_set_drvdata(pdev, i2c);
13141323

13151324
if (i2c->soc_data->calc_timings == rk3x_i2c_v0_calc_timings) {

0 commit comments

Comments
 (0)