* [PATCH] i2c: imx: add retries for i2c-0 on Ventana boards
@ 2016-07-07 14:03 Tim Harvey
2016-07-08 6:28 ` Uwe Kleine-König
0 siblings, 1 reply; 5+ messages in thread
From: Tim Harvey @ 2016-07-07 14:03 UTC (permalink / raw)
To: Wolfram Sang; +Cc: Fabio Estevam, linux-i2c, linux-kernel
Gateworks Ventana IMX6 based boards have a Gateworks System Controller [1]
(gsc) device that can NAK i2c transactions when its busy in an ADC loop. As
this is always on i2c-0 we will add retries for that bus for any Ventana
board.
Signed-off-by: Tim Harvey <tharvey@gateworks.com>
---
drivers/i2c/busses/i2c-imx.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 1844bc9..aec71c3 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -460,6 +460,8 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
{
if (imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR) & I2SR_RXAK) {
dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
+ if (i2c_imx->adapter.retries)
+ return -EAGAIN;
return -ENXIO; /* No ACK */
}
@@ -1068,6 +1070,16 @@ static int i2c_imx_probe(struct platform_device *pdev)
i2c_imx->adapter.dev.of_node = pdev->dev.of_node;
i2c_imx->base = base;
+ /*
+ * The Gateworks Ventana has an i2c based system controller on i2c-0
+ * which emulates several standard i2c devices with existing drivers.
+ * That device can NAK when its in an ADC loop. Add bus retries.
+ */
+ if (of_machine_is_compatible("gw,ventana") && phy_addr == 0x021a0000) {
+ dev_info(&pdev->dev, "Adding retries for Ventana GSC\n");
+ i2c_imx->adapter.retries = 3;
+ }
+
/* Get I2C clock */
i2c_imx->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(i2c_imx->clk)) {
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] i2c: imx: add retries for i2c-0 on Ventana boards
2016-07-07 14:03 [PATCH] i2c: imx: add retries for i2c-0 on Ventana boards Tim Harvey
@ 2016-07-08 6:28 ` Uwe Kleine-König
2016-07-08 19:49 ` Tim Harvey
0 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2016-07-08 6:28 UTC (permalink / raw)
To: Tim Harvey; +Cc: Wolfram Sang, Fabio Estevam, linux-i2c, linux-kernel
Hello Tim,
On Thu, Jul 07, 2016 at 07:03:49AM -0700, Tim Harvey wrote:
> Gateworks Ventana IMX6 based boards have a Gateworks System Controller [1]
> (gsc) device that can NAK i2c transactions when its busy in an ADC loop. As
> this is always on i2c-0 we will add retries for that bus for any Ventana
> board.
The right thing is to fix the drivers IMHO.
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 1844bc9..aec71c3 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -460,6 +460,8 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
> {
> if (imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR) & I2SR_RXAK) {
> dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
> + if (i2c_imx->adapter.retries)
> + return -EAGAIN;
This is wrong, struct i2c_adapter::retries is for restarting a transfer
on arbitration loss.
> return -ENXIO; /* No ACK */
> }
>
> @@ -1068,6 +1070,16 @@ static int i2c_imx_probe(struct platform_device *pdev)
> i2c_imx->adapter.dev.of_node = pdev->dev.of_node;
> i2c_imx->base = base;
>
> + /*
> + * The Gateworks Ventana has an i2c based system controller on i2c-0
> + * which emulates several standard i2c devices with existing drivers.
> + * That device can NAK when its in an ADC loop. Add bus retries.
> + */
> + if (of_machine_is_compatible("gw,ventana") && phy_addr == 0x021a0000) {
Please don't. If you want to do handle a device in a special way, invent
a device tree property, add it to your machine description and add
handling here. Using of_machine_is_compatible + base address of the
device to decide about configuration is a no go.
> + dev_info(&pdev->dev, "Adding retries for Ventana GSC\n");
> + i2c_imx->adapter.retries = 3;
> + }
> +
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] i2c: imx: add retries for i2c-0 on Ventana boards
2016-07-08 6:28 ` Uwe Kleine-König
@ 2016-07-08 19:49 ` Tim Harvey
2016-07-08 21:07 ` Uwe Kleine-König
0 siblings, 1 reply; 5+ messages in thread
From: Tim Harvey @ 2016-07-08 19:49 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: Wolfram Sang, Fabio Estevam, linux-i2c, linux-kernel
On Thu, Jul 7, 2016 at 11:28 PM, Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
> Hello Tim,
>
> On Thu, Jul 07, 2016 at 07:03:49AM -0700, Tim Harvey wrote:
>> Gateworks Ventana IMX6 based boards have a Gateworks System Controller [1]
>> (gsc) device that can NAK i2c transactions when its busy in an ADC loop. As
>> this is always on i2c-0 we will add retries for that bus for any Ventana
>> board.
>
> The right thing is to fix the drivers IMHO.
>
Hi Uwe,
Thanks for the feedack!
The issue I have is that the i2c device emulates several other devices
with existing drivers (pca953x, ds1672, at24) and those drivers don't
have any retry mechanism in place for a retry.
Maybe if I converted those drivers to use regmap I could implement a
regmap with retries in the mfd driver for my device?
Regards,
Tim
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] i2c: imx: add retries for i2c-0 on Ventana boards
2016-07-08 19:49 ` Tim Harvey
@ 2016-07-08 21:07 ` Uwe Kleine-König
2016-07-09 2:31 ` Wolfram Sang
0 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2016-07-08 21:07 UTC (permalink / raw)
To: Tim Harvey, Wolfram Sang; +Cc: Fabio Estevam, linux-i2c, linux-kernel
Hello Tim, hello Wolfram,
On Fri, Jul 08, 2016 at 12:49:04PM -0700, Tim Harvey wrote:
> On Thu, Jul 7, 2016 at 11:28 PM, Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:
> > Hello Tim,
> >
> > On Thu, Jul 07, 2016 at 07:03:49AM -0700, Tim Harvey wrote:
> >> Gateworks Ventana IMX6 based boards have a Gateworks System Controller [1]
> >> (gsc) device that can NAK i2c transactions when its busy in an ADC loop. As
> >> this is always on i2c-0 we will add retries for that bus for any Ventana
> >> board.
> >
> > The right thing is to fix the drivers IMHO.
> >
> The issue I have is that the i2c device emulates several other devices
> with existing drivers (pca953x, ds1672, at24) and those drivers don't
> have any retry mechanism in place for a retry.
>
> Maybe if I converted those drivers to use regmap I could implement a
> regmap with retries in the mfd driver for my device?
Wolfram: what do you think?
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-07-09 2:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-07 14:03 [PATCH] i2c: imx: add retries for i2c-0 on Ventana boards Tim Harvey
2016-07-08 6:28 ` Uwe Kleine-König
2016-07-08 19:49 ` Tim Harvey
2016-07-08 21:07 ` Uwe Kleine-König
2016-07-09 2:31 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).