Skip to content

Commit 33256ce

Browse files
committed
Merge branch 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c fixes from Wolfram Sang: "Some more I2C driver updates. IMX updates are a tad bigger, but not exceptionally big" * 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: i2c: mlxbf: Fix the return check of devm_ioremap and ioremap i2c: mlxbf: select CONFIG_I2C_SLAVE i2c: imx: Don't generate STOP condition if arbitration has been lost i2c: imx: Check for I2SR_IAL after every byte i2c: imx: Fix reset of I2SR_IAL flag i2c: qcom: Fix IRQ error misassignement i2c: qup: Fix error return code in qup_i2c_bam_schedule_desc()
2 parents be1515b + 2bf9545 commit 33256ce

5 files changed

Lines changed: 47 additions & 17 deletions

File tree

drivers/i2c/busses/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ config I2C_LPC2K
734734
config I2C_MLXBF
735735
tristate "Mellanox BlueField I2C controller"
736736
depends on MELLANOX_PLATFORM && ARM64
737+
select I2C_SLAVE
737738
help
738739
Enabling this option will add I2C SMBus support for Mellanox BlueField
739740
system.

drivers/i2c/busses/i2c-imx.c

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,19 @@ static void i2c_imx_dma_free(struct imx_i2c_struct *i2c_imx)
412412
dma->chan_using = NULL;
413413
}
414414

415+
static void i2c_imx_clear_irq(struct imx_i2c_struct *i2c_imx, unsigned int bits)
416+
{
417+
unsigned int temp;
418+
419+
/*
420+
* i2sr_clr_opcode is the value to clear all interrupts. Here we want to
421+
* clear only <bits>, so we write ~i2sr_clr_opcode with just <bits>
422+
* toggled. This is required because i.MX needs W0C and Vybrid uses W1C.
423+
*/
424+
temp = ~i2c_imx->hwdata->i2sr_clr_opcode ^ bits;
425+
imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2SR);
426+
}
427+
415428
static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy, bool atomic)
416429
{
417430
unsigned long orig_jiffies = jiffies;
@@ -424,8 +437,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy, bool a
424437

425438
/* check for arbitration lost */
426439
if (temp & I2SR_IAL) {
427-
temp &= ~I2SR_IAL;
428-
imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2SR);
440+
i2c_imx_clear_irq(i2c_imx, I2SR_IAL);
429441
return -EAGAIN;
430442
}
431443

@@ -469,7 +481,7 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx, bool atomic)
469481
*/
470482
readb_poll_timeout_atomic(addr, regval, regval & I2SR_IIF, 5, 1000 + 100);
471483
i2c_imx->i2csr = regval;
472-
imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2SR);
484+
i2c_imx_clear_irq(i2c_imx, I2SR_IIF | I2SR_IAL);
473485
} else {
474486
wait_event_timeout(i2c_imx->queue, i2c_imx->i2csr & I2SR_IIF, HZ / 10);
475487
}
@@ -478,6 +490,16 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx, bool atomic)
478490
dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
479491
return -ETIMEDOUT;
480492
}
493+
494+
/* check for arbitration lost */
495+
if (i2c_imx->i2csr & I2SR_IAL) {
496+
dev_dbg(&i2c_imx->adapter.dev, "<%s> Arbitration lost\n", __func__);
497+
i2c_imx_clear_irq(i2c_imx, I2SR_IAL);
498+
499+
i2c_imx->i2csr = 0;
500+
return -EAGAIN;
501+
}
502+
481503
dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__);
482504
i2c_imx->i2csr = 0;
483505
return 0;
@@ -593,6 +615,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx, bool atomic)
593615
/* Stop I2C transaction */
594616
dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
595617
temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
618+
if (!(temp & I2CR_MSTA))
619+
i2c_imx->stopped = 1;
596620
temp &= ~(I2CR_MSTA | I2CR_MTX);
597621
if (i2c_imx->dma)
598622
temp &= ~I2CR_DMAEN;
@@ -623,9 +647,7 @@ static irqreturn_t i2c_imx_isr(int irq, void *dev_id)
623647
if (temp & I2SR_IIF) {
624648
/* save status register */
625649
i2c_imx->i2csr = temp;
626-
temp &= ~I2SR_IIF;
627-
temp |= (i2c_imx->hwdata->i2sr_clr_opcode & I2SR_IIF);
628-
imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2SR);
650+
i2c_imx_clear_irq(i2c_imx, I2SR_IIF);
629651
wake_up(&i2c_imx->queue);
630652
return IRQ_HANDLED;
631653
}
@@ -758,9 +780,12 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx,
758780
*/
759781
dev_dbg(dev, "<%s> clear MSTA\n", __func__);
760782
temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
783+
if (!(temp & I2CR_MSTA))
784+
i2c_imx->stopped = 1;
761785
temp &= ~(I2CR_MSTA | I2CR_MTX);
762786
imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
763-
i2c_imx_bus_busy(i2c_imx, 0, false);
787+
if (!i2c_imx->stopped)
788+
i2c_imx_bus_busy(i2c_imx, 0, false);
764789
} else {
765790
/*
766791
* For i2c master receiver repeat restart operation like:
@@ -885,9 +910,12 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs,
885910
dev_dbg(&i2c_imx->adapter.dev,
886911
"<%s> clear MSTA\n", __func__);
887912
temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
913+
if (!(temp & I2CR_MSTA))
914+
i2c_imx->stopped = 1;
888915
temp &= ~(I2CR_MSTA | I2CR_MTX);
889916
imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
890-
i2c_imx_bus_busy(i2c_imx, 0, atomic);
917+
if (!i2c_imx->stopped)
918+
i2c_imx_bus_busy(i2c_imx, 0, atomic);
891919
} else {
892920
/*
893921
* For i2c master receiver repeat restart operation like:

drivers/i2c/busses/i2c-mlxbf.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,9 +1258,9 @@ static int mlxbf_i2c_get_gpio(struct platform_device *pdev,
12581258
return -EFAULT;
12591259

12601260
gpio_res->io = devm_ioremap(dev, params->start, size);
1261-
if (IS_ERR(gpio_res->io)) {
1261+
if (!gpio_res->io) {
12621262
devm_release_mem_region(dev, params->start, size);
1263-
return PTR_ERR(gpio_res->io);
1263+
return -ENOMEM;
12641264
}
12651265

12661266
return 0;
@@ -1323,9 +1323,9 @@ static int mlxbf_i2c_get_corepll(struct platform_device *pdev,
13231323
return -EFAULT;
13241324

13251325
corepll_res->io = devm_ioremap(dev, params->start, size);
1326-
if (IS_ERR(corepll_res->io)) {
1326+
if (!corepll_res->io) {
13271327
devm_release_mem_region(dev, params->start, size);
1328-
return PTR_ERR(corepll_res->io);
1328+
return -ENOMEM;
13291329
}
13301330

13311331
return 0;
@@ -1717,9 +1717,9 @@ static int mlxbf_i2c_init_coalesce(struct platform_device *pdev,
17171717
return -EFAULT;
17181718

17191719
coalesce_res->io = ioremap(params->start, size);
1720-
if (IS_ERR(coalesce_res->io)) {
1720+
if (!coalesce_res->io) {
17211721
release_mem_region(params->start, size);
1722-
return PTR_ERR(coalesce_res->io);
1722+
return -ENOMEM;
17231723
}
17241724

17251725
priv->coalesce = coalesce_res;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ static irqreturn_t cci_isr(int irq, void *dev)
194194
if (unlikely(val & CCI_IRQ_STATUS_0_I2C_M1_ERROR)) {
195195
if (val & CCI_IRQ_STATUS_0_I2C_M1_Q0_NACK_ERR ||
196196
val & CCI_IRQ_STATUS_0_I2C_M1_Q1_NACK_ERR)
197-
cci->master[0].status = -ENXIO;
197+
cci->master[1].status = -ENXIO;
198198
else
199-
cci->master[0].status = -EIO;
199+
cci->master[1].status = -EIO;
200200

201201
writel(CCI_HALT_REQ_I2C_M1_Q0Q1, cci->base + CCI_HALT_REQ);
202202
ret = IRQ_HANDLED;

drivers/i2c/busses/i2c-qup.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,8 @@ static int qup_i2c_bam_schedule_desc(struct qup_i2c_dev *qup)
801801
if (ret || qup->bus_err || qup->qup_err) {
802802
reinit_completion(&qup->xfer);
803803

804-
if (qup_i2c_change_state(qup, QUP_RUN_STATE)) {
804+
ret = qup_i2c_change_state(qup, QUP_RUN_STATE);
805+
if (ret) {
805806
dev_err(qup->dev, "change to run state timed out");
806807
goto desc_err;
807808
}

0 commit comments

Comments
 (0)