Skip to content

Commit 7f52bb9

Browse files
committed
Merge tag 'i2c-for-6.11-final-but-missed-it' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c fixes from Wolfram Sang: "The Aspeed driver tracks the controller's state (stop, pending, start, etc.). Previously, when the stop command was sent, the state was not updated. The fix ensures the driver's state is aligned with the device status. The Intel SCH driver receives a new look, and among the cleanups, there is a fix where, due to an oversight, an if/else statement was missing the else, causing it to move forward instead of exiting the function in case of an error. The Qualcomm GENI I2C driver adds the IRQF_NO_AUTOEN flag to the IRQ setup to prevent unwanted interrupts during probe. The Xilinx XPS controller fixes TX FIFO handling to avoid missed NAKs. Another fix ensures the controller is reinitialized when the bus appears busy" * tag 'i2c-for-6.11-final-but-missed-it' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: i2c: qcom-geni: Use IRQF_NO_AUTOEN flag in request_irq() i2c: isch: Add missed 'else' i2c: xiic: Try re-initialization on bus busy timeout i2c: xiic: Wait for TX empty to avoid missed TX NAKs i2c: aspeed: Update the stop sw state when the bus recovery occurs
2 parents 839c4f5 + e03ad65 commit 7f52bb9

File tree

4 files changed

+45
-38
lines changed

4 files changed

+45
-38
lines changed

drivers/i2c/busses/i2c-aspeed.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ struct aspeed_i2c_bus {
170170

171171
static int aspeed_i2c_reset(struct aspeed_i2c_bus *bus);
172172

173+
/* precondition: bus.lock has been acquired. */
174+
static void aspeed_i2c_do_stop(struct aspeed_i2c_bus *bus)
175+
{
176+
bus->master_state = ASPEED_I2C_MASTER_STOP;
177+
writel(ASPEED_I2CD_M_STOP_CMD, bus->base + ASPEED_I2C_CMD_REG);
178+
}
179+
173180
static int aspeed_i2c_recover_bus(struct aspeed_i2c_bus *bus)
174181
{
175182
unsigned long time_left, flags;
@@ -187,7 +194,7 @@ static int aspeed_i2c_recover_bus(struct aspeed_i2c_bus *bus)
187194
command);
188195

189196
reinit_completion(&bus->cmd_complete);
190-
writel(ASPEED_I2CD_M_STOP_CMD, bus->base + ASPEED_I2C_CMD_REG);
197+
aspeed_i2c_do_stop(bus);
191198
spin_unlock_irqrestore(&bus->lock, flags);
192199

193200
time_left = wait_for_completion_timeout(
@@ -390,13 +397,6 @@ static void aspeed_i2c_do_start(struct aspeed_i2c_bus *bus)
390397
writel(command, bus->base + ASPEED_I2C_CMD_REG);
391398
}
392399

393-
/* precondition: bus.lock has been acquired. */
394-
static void aspeed_i2c_do_stop(struct aspeed_i2c_bus *bus)
395-
{
396-
bus->master_state = ASPEED_I2C_MASTER_STOP;
397-
writel(ASPEED_I2CD_M_STOP_CMD, bus->base + ASPEED_I2C_CMD_REG);
398-
}
399-
400400
/* precondition: bus.lock has been acquired. */
401401
static void aspeed_i2c_next_msg_or_stop(struct aspeed_i2c_bus *bus)
402402
{

drivers/i2c/busses/i2c-isch.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ static int sch_transaction(void)
9999
if (retries > MAX_RETRIES) {
100100
dev_err(&sch_adapter.dev, "SMBus Timeout!\n");
101101
result = -ETIMEDOUT;
102-
}
103-
if (temp & 0x04) {
102+
} else if (temp & 0x04) {
104103
result = -EIO;
105104
dev_dbg(&sch_adapter.dev, "Bus collision! SMBus may be "
106105
"locked until next hard reset. (sorry!)\n");

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -818,15 +818,13 @@ static int geni_i2c_probe(struct platform_device *pdev)
818818
init_completion(&gi2c->done);
819819
spin_lock_init(&gi2c->lock);
820820
platform_set_drvdata(pdev, gi2c);
821-
ret = devm_request_irq(dev, gi2c->irq, geni_i2c_irq, 0,
821+
ret = devm_request_irq(dev, gi2c->irq, geni_i2c_irq, IRQF_NO_AUTOEN,
822822
dev_name(dev), gi2c);
823823
if (ret) {
824824
dev_err(dev, "Request_irq failed:%d: err:%d\n",
825825
gi2c->irq, ret);
826826
return ret;
827827
}
828-
/* Disable the interrupt so that the system can enter low-power mode */
829-
disable_irq(gi2c->irq);
830828
i2c_set_adapdata(&gi2c->adap, gi2c);
831829
gi2c->adap.dev.parent = dev;
832830
gi2c->adap.dev.of_node = dev->of_node;

drivers/i2c/busses/i2c-xiic.c

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -772,14 +772,17 @@ static irqreturn_t xiic_process(int irq, void *dev_id)
772772
goto out;
773773
}
774774

775-
xiic_fill_tx_fifo(i2c);
776-
777-
/* current message sent and there is space in the fifo */
778-
if (!xiic_tx_space(i2c) && xiic_tx_fifo_space(i2c) >= 2) {
775+
if (xiic_tx_space(i2c)) {
776+
xiic_fill_tx_fifo(i2c);
777+
} else {
778+
/* current message fully written */
779779
dev_dbg(i2c->adap.dev.parent,
780780
"%s end of message sent, nmsgs: %d\n",
781781
__func__, i2c->nmsgs);
782-
if (i2c->nmsgs > 1) {
782+
/* Don't move onto the next message until the TX FIFO empties,
783+
* to ensure that a NAK is not missed.
784+
*/
785+
if (i2c->nmsgs > 1 && (pend & XIIC_INTR_TX_EMPTY_MASK)) {
783786
i2c->nmsgs--;
784787
i2c->tx_msg++;
785788
xfer_more = 1;
@@ -790,11 +793,7 @@ static irqreturn_t xiic_process(int irq, void *dev_id)
790793
"%s Got TX IRQ but no more to do...\n",
791794
__func__);
792795
}
793-
} else if (!xiic_tx_space(i2c) && (i2c->nmsgs == 1))
794-
/* current frame is sent and is last,
795-
* make sure to disable tx half
796-
*/
797-
xiic_irq_dis(i2c, XIIC_INTR_TX_HALF_MASK);
796+
}
798797
}
799798

800799
if (pend & XIIC_INTR_BNB_MASK) {
@@ -844,23 +843,11 @@ static int xiic_bus_busy(struct xiic_i2c *i2c)
844843
return (sr & XIIC_SR_BUS_BUSY_MASK) ? -EBUSY : 0;
845844
}
846845

847-
static int xiic_busy(struct xiic_i2c *i2c)
846+
static int xiic_wait_not_busy(struct xiic_i2c *i2c)
848847
{
849848
int tries = 3;
850849
int err;
851850

852-
if (i2c->tx_msg || i2c->rx_msg)
853-
return -EBUSY;
854-
855-
/* In single master mode bus can only be busy, when in use by this
856-
* driver. If the register indicates bus being busy for some reason we
857-
* should ignore it, since bus will never be released and i2c will be
858-
* stuck forever.
859-
*/
860-
if (i2c->singlemaster) {
861-
return 0;
862-
}
863-
864851
/* for instance if previous transfer was terminated due to TX error
865852
* it might be that the bus is on it's way to become available
866853
* give it at most 3 ms to wake
@@ -1104,13 +1091,36 @@ static int xiic_start_xfer(struct xiic_i2c *i2c, struct i2c_msg *msgs, int num)
11041091

11051092
mutex_lock(&i2c->lock);
11061093

1107-
ret = xiic_busy(i2c);
1108-
if (ret) {
1094+
if (i2c->tx_msg || i2c->rx_msg) {
11091095
dev_err(i2c->adap.dev.parent,
11101096
"cannot start a transfer while busy\n");
1097+
ret = -EBUSY;
11111098
goto out;
11121099
}
11131100

1101+
/* In single master mode bus can only be busy, when in use by this
1102+
* driver. If the register indicates bus being busy for some reason we
1103+
* should ignore it, since bus will never be released and i2c will be
1104+
* stuck forever.
1105+
*/
1106+
if (!i2c->singlemaster) {
1107+
ret = xiic_wait_not_busy(i2c);
1108+
if (ret) {
1109+
/* If the bus is stuck in a busy state, such as due to spurious low
1110+
* pulses on the bus causing a false start condition to be detected,
1111+
* then try to recover by re-initializing the controller and check
1112+
* again if the bus is still busy.
1113+
*/
1114+
dev_warn(i2c->adap.dev.parent, "I2C bus busy timeout, reinitializing\n");
1115+
ret = xiic_reinit(i2c);
1116+
if (ret)
1117+
goto out;
1118+
ret = xiic_wait_not_busy(i2c);
1119+
if (ret)
1120+
goto out;
1121+
}
1122+
}
1123+
11141124
i2c->tx_msg = msgs;
11151125
i2c->rx_msg = NULL;
11161126
i2c->nmsgs = num;

0 commit comments

Comments
 (0)