[PATCH] Driver updates: - In the case of I2C bus dead lock occurred during driver probing, it is better try to recovery it. so added bus recovery step in octeon_i2c_probe(); - The purpose of function octeon_i2c_start() is to send START, so after bus recovery, also need try to send START again.
From: hgt463
Date: Thu Nov 23 2017 - 05:46:09 EST
Signed-off-by: hgt463 <sean.c.zhang@xxxxxxxxx>
---
drivers/i2c/busses/i2c-octeon-core.c | 31 +++++++++++++++++++++++++++=
+++-
drivers/i2c/busses/i2c-octeon-platdrv.c | 15 +++++++++------
2 files changed, 39 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/busses/i2c-octeon-core.c b/drivers/i2c/busses/i2c-=
octeon-core.c
index 1d87757..3ae1e03 100644
--- a/drivers/i2c/busses/i2c-octeon-core.c
+++ b/drivers/i2c/busses/i2c-octeon-core.c
@@ -255,6 +255,35 @@ static int octeon_i2c_recovery(struct octeon_i2c *i2c)
return ret;
}
=20
+/*
+ * octeon_i2c_start_retry - send START to the bus after bus recovery.
+ * @i2c: The struct octeon_i2c
+ *
+ * Returns 0 on success, otherwise a negative errno.
+ */
+static int octeon_i2c_start_retry(struct octeon_i2c *i2c)
+{
+ int ret;
+ u8 stat;
+
+ ret =3D octeon_i2c_recovery(i2c);
+ if (ret)
+ goto error;
+
+ octeon_i2c_ctl_write(i2c, TWSI_CTL_ENAB | TWSI_CTL_STA);
+ ret =3D octeon_i2c_wait(i2c);
+ if (ret)
+ goto error;
+
+ stat =3D octeon_i2c_stat_read(i2c);
+ if (stat =3D=3D STAT_START || stat =3D=3D STAT_REP_START)
+ /* START successful, bail out */
+ return 0;
+
+error:
+ return (ret) ? ret : -EAGAIN;
+}
+
/**
* octeon_i2c_start - send START to the bus
* @i2c: The struct octeon_i2c
@@ -280,7 +309,7 @@ static int octeon_i2c_start(struct octeon_i2c *i2c)
=20
error:
/* START failed, try to recover */
- ret =3D octeon_i2c_recovery(i2c);
+ ret =3D octeon_i2c_start_retry(i2c);
return (ret) ? ret : -EAGAIN;
}
=20
diff --git a/drivers/i2c/busses/i2c-octeon-platdrv.c b/drivers/i2c/busses/i=
2c-octeon-platdrv.c
index 64bda83..98063af 100644
--- a/drivers/i2c/busses/i2c-octeon-platdrv.c
+++ b/drivers/i2c/busses/i2c-octeon-platdrv.c
@@ -228,12 +228,6 @@ static int octeon_i2c_probe(struct platform_device *pd=
ev)
if (OCTEON_IS_MODEL(OCTEON_CN38XX))
i2c->broken_irq_check =3D true;
=20
- result =3D octeon_i2c_init_lowlevel(i2c);
- if (result) {
- dev_err(i2c->dev, "init low level failed\n");
- goto out;
- }
-
octeon_i2c_set_clock(i2c);
=20
i2c->adap =3D octeon_i2c_ops;
@@ -245,6 +239,15 @@ static int octeon_i2c_probe(struct platform_device *pd=
ev)
i2c_set_adapdata(&i2c->adap, i2c);
platform_set_drvdata(pdev, i2c);
=20
+ stat =3D octeon_i2c_stat_read(i2c);
+ if (stat !=3D STAT_IDLE) {
+ result =3D octeon_i2c_recovery(i2c);
+ if (result) {
+ dev_err(i2c->dev, "octeon i2c recovery failed\n");
+ goto out;
+ }
+ }
+
result =3D i2c_add_adapter(&i2c->adap);
if (result < 0)
goto out;
Attached patch for you review. Thanks in advance.
BR,
Sean Zhang
--_002_VI1PR0702MB3615DF756007C1F87BED50BB8E210VI1PR0702MB3615_
Content-Type: application/octet-stream; name="0001-Driver-updates.patch"
Content-Description: 0001-Driver-updates.patch
Content-Disposition: attachment; filename="0001-Driver-updates.patch";
size=2929; creation-date="Thu, 23 Nov 2017 11:05:47 GMT";
modification-date="Thu, 23 Nov 2017 11:27:08 GMT"
Content-Transfer-Encoding: base64
RnJvbSAwOWQ5ZjBjZTY1OGQ3ZjZhNTBkMWFmMzUyZGRlNjE5YzI5YmM4YmNmIE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBoZ3Q0NjMgPHNlYW4uYy56aGFuZ0Bub2tpYS5jb20+CkRhdGU6
IFRodSwgMjMgTm92IDIwMTcgMTg6NDY6MDkgKzA4MDAKU3ViamVjdDogW1BB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