Skip to content

Commit 1885429

Browse files
NXP-CarlosSongAndi Shyti
authored andcommitted
i2c: imx-lpi2c: add generic GPIO recovery for LPI2C
This adds i2c bus recovery to the lpi2c driver. Uses the generic recovery function setting the SCL/SDA pads as GPIO pins and sending 9 clocks to try and recover the bus. Signed-off-by: Carlos Song <carlos.song@nxp.com> Reviewed-by: Clark Wang <xiaoning.wang@nxp.com> Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com> Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
1 parent 747bdf9 commit 1885429

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

drivers/i2c/busses/i2c-imx-lpi2c.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ struct lpi2c_imx_struct {
106106
unsigned int txfifosize;
107107
unsigned int rxfifosize;
108108
enum lpi2c_imx_mode mode;
109+
struct i2c_bus_recovery_info rinfo;
109110
};
110111

111112
static void lpi2c_imx_intctrl(struct lpi2c_imx_struct *lpi2c_imx,
@@ -133,6 +134,8 @@ static int lpi2c_imx_bus_busy(struct lpi2c_imx_struct *lpi2c_imx)
133134

134135
if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) {
135136
dev_dbg(&lpi2c_imx->adapter.dev, "bus not work\n");
137+
if (lpi2c_imx->adapter.bus_recovery_info)
138+
i2c_recover_bus(&lpi2c_imx->adapter);
136139
return -ETIMEDOUT;
137140
}
138141
schedule();
@@ -190,6 +193,8 @@ static void lpi2c_imx_stop(struct lpi2c_imx_struct *lpi2c_imx)
190193

191194
if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) {
192195
dev_dbg(&lpi2c_imx->adapter.dev, "stop timeout\n");
196+
if (lpi2c_imx->adapter.bus_recovery_info)
197+
i2c_recover_bus(&lpi2c_imx->adapter);
193198
break;
194199
}
195200
schedule();
@@ -325,6 +330,8 @@ static int lpi2c_imx_txfifo_empty(struct lpi2c_imx_struct *lpi2c_imx)
325330

326331
if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) {
327332
dev_dbg(&lpi2c_imx->adapter.dev, "txfifo empty timeout\n");
333+
if (lpi2c_imx->adapter.bus_recovery_info)
334+
i2c_recover_bus(&lpi2c_imx->adapter);
328335
return -ETIMEDOUT;
329336
}
330337
schedule();
@@ -526,6 +533,20 @@ static irqreturn_t lpi2c_imx_isr(int irq, void *dev_id)
526533
return IRQ_HANDLED;
527534
}
528535

536+
static int lpi2c_imx_init_recovery_info(struct lpi2c_imx_struct *lpi2c_imx,
537+
struct platform_device *pdev)
538+
{
539+
struct i2c_bus_recovery_info *bri = &lpi2c_imx->rinfo;
540+
541+
bri->pinctrl = devm_pinctrl_get(&pdev->dev);
542+
if (IS_ERR(bri->pinctrl))
543+
return PTR_ERR(bri->pinctrl);
544+
545+
lpi2c_imx->adapter.bus_recovery_info = bri;
546+
547+
return 0;
548+
}
549+
529550
static u32 lpi2c_imx_func(struct i2c_adapter *adapter)
530551
{
531552
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
@@ -600,6 +621,12 @@ static int lpi2c_imx_probe(struct platform_device *pdev)
600621
lpi2c_imx->txfifosize = 1 << (temp & 0x0f);
601622
lpi2c_imx->rxfifosize = 1 << ((temp >> 8) & 0x0f);
602623

624+
/* Init optional bus recovery function */
625+
ret = lpi2c_imx_init_recovery_info(lpi2c_imx, pdev);
626+
/* Give it another chance if pinctrl used is not ready yet */
627+
if (ret == -EPROBE_DEFER)
628+
goto rpm_disable;
629+
603630
ret = i2c_add_adapter(&lpi2c_imx->adapter);
604631
if (ret)
605632
goto rpm_disable;

0 commit comments

Comments
 (0)