diff options
author | David Jander <david@xxxxxxxxxxx> | 2011-12-06 12:56:12 +0100 |
---|---|---|
committer | John Weber <rjohnweber@gmail.com> | 2013-07-28 23:44:59 -0500 |
commit | 29c8561c8d6d248f2b6726384815a136c2fbd859 (patch) | |
tree | e0feb3181d675b109e16e97433f90899c2e1fae7 | |
parent | 5ff30ca8128bb3840350e5902ac68246fbc2aa21 (diff) | |
download | linux-29c8561c8d6d248f2b6726384815a136c2fbd859.tar.gz |
[RFC PATCH] i2c-imx.c: Add support for I2C bus fault recovery
In the event that a I2C bus is disturbed, for instance by a slave missing
a clock pulse, it is desirable to have a way to get the bus back working
other than by power-cycling the whole system. This patch makes it possible to
to have a special function in board support code issue an I2C reset, since
the IMX peripheral is not capable of doing this, and it needs to be done
by bit-banging the corresponding pins in GPIO mode.
The reset function needs to check if the bus is hung by checking the state
of SDA and issue a reset by pulsing SCL a few times as long as SDA is low.
Signed-off-by: David Jander <david@xxxxxxxxxxx>
Conflicts:
drivers/i2c/busses/i2c-imx.c
(cherry picked from commit c1c409c8e9f96e1bd16717733c7456497b42d558)
-rw-r--r-- | arch/arm/plat-mxc/include/mach/i2c.h | 2 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-imx.c | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/arch/arm/plat-mxc/include/mach/i2c.h b/arch/arm/plat-mxc/include/mach/i2c.h index 4a5dc5c6d8e8..7ed4f64c86a2 100644 --- a/arch/arm/plat-mxc/include/mach/i2c.h +++ b/arch/arm/plat-mxc/include/mach/i2c.h @@ -13,12 +13,14 @@ * struct imxi2c_platform_data - structure of platform data for MXC I2C driver * @init: Initialise gpio's and other board specific things * @exit: Free everything initialised by @init + * @reset: Issue I2C reset if needed (toggle SCL via GPIO access) * @bitrate: Bus speed measured in Hz * **/ struct imxi2c_platform_data { int (*init)(struct device *dev); void (*exit)(struct device *dev); + int (*reset)(struct device *dev); int bitrate; }; diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 8cec1965dec3..2e20a7843ca9 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -124,6 +124,7 @@ struct imx_i2c_struct { int stopped; unsigned int ifdr; /* IMX_I2C_IFDR */ unsigned int cur_clk; + int (*reset)(struct device *dev); }; /** Functions for IMX I2C adapter driver *************************************** @@ -253,6 +254,10 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx) /* Wait controller to be stable */ udelay(50); + /* Check if bus is busy (hung if not multi-master) and issue reset */ + if (i2c_imx->reset && i2c_imx->reset(&i2c_imx->adapter.dev)) + return -ETIMEDOUT; + /* Start I2C transaction */ temp = readb(i2c_imx->base + IMX_I2C_I2CR); temp |= I2CR_MSTA; @@ -541,6 +546,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev) i2c_imx->irq = irq; i2c_imx->base = base; i2c_imx->res = res; + i2c_imx->reset = pdata->reset; /* Get I2C clock */ i2c_imx->clk = clk_get(&pdev->dev, "i2c_clk"); |