* [PATCH] i2c-mpc: Wait for STOP to hit the bus @ 2012-08-30 10:40 Joakim Tjernlund [not found] ` <1346323204-19210-1-git-send-email-Joakim.Tjernlund-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: Joakim Tjernlund @ 2012-08-30 10:40 UTC (permalink / raw) To: linux-i2c, linuxppc-dev mpc_i2c_stop() only initiates STOP but does not wait for it to hit the I2C bus. This is a problem when using I2C devices which uses fairly long clock stretching just before STOP if you also have an i2c-mux which may switch to another bus before STOP has been processed. Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se> --- drivers/i2c/busses/i2c-mpc.c | 18 +++++++++++++++++- 1 files changed, 17 insertions(+), 1 deletions(-) diff --git drivers/i2c/busses/i2c-mpc.c drivers/i2c/busses/i2c-mpc.c index 3d31879..c08f287 100644 --- drivers/i2c/busses/i2c-mpc.c +++ drivers/i2c/busses/i2c-mpc.c @@ -574,7 +574,23 @@ static int mpc_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) mpc_write(i2c, pmsg->addr, pmsg->buf, pmsg->len, i); } } - mpc_i2c_stop(i2c); + mpc_i2c_stop(i2c); /* Initiate STOP */ + orig_jiffies = jiffies; + /* Wait until STOP is seen, allow up to 1 s */ + while (readb(i2c->base + MPC_I2C_SR) & CSR_MBB) { + if (time_after(jiffies, orig_jiffies + HZ)) { + u8 status = readb(i2c->base + MPC_I2C_SR); + + dev_dbg(i2c->dev, "timeout\n"); + if ((status & (CSR_MCF | CSR_MBB | CSR_RXAK)) != 0) { + writeb(status & ~CSR_MAL, + i2c->base + MPC_I2C_SR); + mpc_i2c_fixup(i2c); + } + return -EIO; + } + cond_resched(); + } return (ret < 0) ? ret : num; } -- 1.7.8.6 ^ permalink raw reply related [flat|nested] 6+ messages in thread
[parent not found: <1346323204-19210-1-git-send-email-Joakim.Tjernlund-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org>]
* Re: [PATCH] i2c-mpc: Wait for STOP to hit the bus [not found] ` <1346323204-19210-1-git-send-email-Joakim.Tjernlund-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org> @ 2012-09-02 2:48 ` Tabi Timur-B04825 [not found] ` <6AE080B68D46FC4BA2D2769E68D765B708019E97-RL0Hj/+nBVC81RJBUSuqCa4g8xLGJsHaLnY5E4hWTkheoWH0uzbU5w@public.gmane.org> [not found] ` <OF0ACFB3FB.F2667AE9-ONC1257A6D.004E0ADE-C1257A6D.004EEB75@LocalDomain> 2012-09-14 14:02 ` Wolfram Sang 1 sibling, 2 replies; 6+ messages in thread From: Tabi Timur-B04825 @ 2012-09-02 2:48 UTC (permalink / raw) To: Joakim Tjernlund Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org On Thu, Aug 30, 2012 at 5:40 AM, Joakim Tjernlund <Joakim.Tjernlund-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org> wrote: > - mpc_i2c_stop(i2c); > + mpc_i2c_stop(i2c); /* Initiate STOP */ > + orig_jiffies = jiffies; > + /* Wait until STOP is seen, allow up to 1 s */ > + while (readb(i2c->base + MPC_I2C_SR) & CSR_MBB) { > + if (time_after(jiffies, orig_jiffies + HZ)) { > + u8 status = readb(i2c->base + MPC_I2C_SR); > + > + dev_dbg(i2c->dev, "timeout\n"); > + if ((status & (CSR_MCF | CSR_MBB | CSR_RXAK)) != 0) { > + writeb(status & ~CSR_MAL, > + i2c->base + MPC_I2C_SR); > + mpc_i2c_fixup(i2c); > + } > + return -EIO; > + } > + cond_resched(); > + } Shouldn't the while-loop be inside mpc_i2c_stop() itself? -- Timur Tabi Linux kernel developer at Freescale ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <6AE080B68D46FC4BA2D2769E68D765B708019E97-RL0Hj/+nBVC81RJBUSuqCa4g8xLGJsHaLnY5E4hWTkheoWH0uzbU5w@public.gmane.org>]
* Re: [PATCH] i2c-mpc: Wait for STOP to hit the bus [not found] ` <6AE080B68D46FC4BA2D2769E68D765B708019E97-RL0Hj/+nBVC81RJBUSuqCa4g8xLGJsHaLnY5E4hWTkheoWH0uzbU5w@public.gmane.org> @ 2012-09-02 14:22 ` Joakim Tjernlund 0 siblings, 0 replies; 6+ messages in thread From: Joakim Tjernlund @ 2012-09-02 14:22 UTC (permalink / raw) To: Tabi Timur-B04825 Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org Tabi Timur-B04825 <B04825-KZfg59tc24xl57MIdRCFDg@public.gmane.org> wrote on 2012/09/02 04:48:01: > On Thu, Aug 30, 2012 at 5:40 AM, Joakim Tjernlund > <Joakim.Tjernlund-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org> wrote: > > > - mpc_i2c_stop(i2c); > > + mpc_i2c_stop(i2c); /* Initiate STOP */ > > + orig_jiffies = jiffies; > > + /* Wait until STOP is seen, allow up to 1 s */ > > + while (readb(i2c->base + MPC_I2C_SR) & CSR_MBB) { > > + if (time_after(jiffies, orig_jiffies + HZ)) { > > + u8 status = readb(i2c->base + MPC_I2C_SR); > > + > > + dev_dbg(i2c->dev, "timeout\n"); > > + if ((status & (CSR_MCF | CSR_MBB | CSR_RXAK)) != 0) { > > + writeb(status & ~CSR_MAL, > > + i2c->base + MPC_I2C_SR); > > + mpc_i2c_fixup(i2c); > > + } > > + return -EIO; > > + } > > + cond_resched(); > > + } > > Shouldn't the while-loop be inside mpc_i2c_stop() itself? Possibly but I choosed to do it this way as there is a similar loop in the beginning of mpc_xfer(). I figured it has better visibility if it is in the same function. Jocke ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <OF0ACFB3FB.F2667AE9-ONC1257A6D.004E0ADE-C1257A6D.004EEB75@LocalDomain>]
* Re: [PATCH] i2c-mpc: Wait for STOP to hit the bus [not found] ` <OF0ACFB3FB.F2667AE9-ONC1257A6D.004E0ADE-C1257A6D.004EEB75@LocalDomain> @ 2012-09-11 10:13 ` Joakim Tjernlund 0 siblings, 0 replies; 6+ messages in thread From: Joakim Tjernlund @ 2012-09-11 10:13 UTC (permalink / raw) Cc: Tabi Timur-B04825, linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org Joakim Tjernlund/Transmode wrote on 2012/09/02 16:22:00: > > Tabi Timur-B04825 <B04825-KZfg59tc24xl57MIdRCFDg@public.gmane.org> wrote on 2012/09/02 04:48:01: > > On Thu, Aug 30, 2012 at 5:40 AM, Joakim Tjernlund > > <Joakim.Tjernlund-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org> wrote: > > > > > - mpc_i2c_stop(i2c); > > > + mpc_i2c_stop(i2c); /* Initiate STOP */ > > > + orig_jiffies = jiffies; > > > + /* Wait until STOP is seen, allow up to 1 s */ > > > + while (readb(i2c->base + MPC_I2C_SR) & CSR_MBB) { > > > + if (time_after(jiffies, orig_jiffies + HZ)) { > > > + u8 status = readb(i2c->base + MPC_I2C_SR); > > > + > > > + dev_dbg(i2c->dev, "timeout\n"); > > > + if ((status & (CSR_MCF | CSR_MBB | CSR_RXAK)) != 0) { > > > + writeb(status & ~CSR_MAL, > > > + i2c->base + MPC_I2C_SR); > > > + mpc_i2c_fixup(i2c); > > > + } > > > + return -EIO; > > > + } > > > + cond_resched(); > > > + } > > > > Shouldn't the while-loop be inside mpc_i2c_stop() itself? > > Possibly but I choosed to do it this way as there is a similar loop in the beginning of mpc_xfer(). > I figured it has better visibility if it is in the same function. > > Jocke Ping? Anything holding this patch back? Jocke ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] i2c-mpc: Wait for STOP to hit the bus [not found] ` <1346323204-19210-1-git-send-email-Joakim.Tjernlund-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org> 2012-09-02 2:48 ` Tabi Timur-B04825 @ 2012-09-14 14:02 ` Wolfram Sang [not found] ` <20120914140234.GH2630-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> 1 sibling, 1 reply; 6+ messages in thread From: Wolfram Sang @ 2012-09-14 14:02 UTC (permalink / raw) To: Joakim Tjernlund Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ [-- Attachment #1: Type: text/plain, Size: 738 bytes --] On Thu, Aug 30, 2012 at 12:40:04PM +0200, Joakim Tjernlund wrote: > mpc_i2c_stop() only initiates STOP but does not wait for it to > hit the I2C bus. This is a problem when using I2C devices which > uses fairly long clock stretching just before STOP if you also > have an i2c-mux which may switch to another bus before STOP has > been processed. > > Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org> Patch didn't apply, because it was a p0-patch. Checkpatch would have warned you. Fixed that and applied to -next, thanks! -- Pengutronix e.K. | Wolfram Sang | Industrial Linux Solutions | http://www.pengutronix.de/ | [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <20120914140234.GH2630-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>]
* Re: [PATCH] i2c-mpc: Wait for STOP to hit the bus [not found] ` <20120914140234.GH2630-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> @ 2012-09-14 14:21 ` Joakim Tjernlund 0 siblings, 0 replies; 6+ messages in thread From: Joakim Tjernlund @ 2012-09-14 14:21 UTC (permalink / raw) To: Wolfram Sang Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote on 2012/09/14 16:02:34: > > On Thu, Aug 30, 2012 at 12:40:04PM +0200, Joakim Tjernlund wrote: > > mpc_i2c_stop() only initiates STOP but does not wait for it to > > hit the I2C bus. This is a problem when using I2C devices which > > uses fairly long clock stretching just before STOP if you also > > have an i2c-mux which may switch to another bus before STOP has > > been processed. > > > > Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org> > > Patch didn't apply, because it was a p0-patch. Checkpatch would have > warned you. Bugger, it is my git config setting: [diff] noprefix = true I always forget to remove that one before generating patches, I will have to remove it. > > Fixed that and applied to -next, thanks! Thanks ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-09-14 14:21 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-08-30 10:40 [PATCH] i2c-mpc: Wait for STOP to hit the bus Joakim Tjernlund [not found] ` <1346323204-19210-1-git-send-email-Joakim.Tjernlund-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org> 2012-09-02 2:48 ` Tabi Timur-B04825 [not found] ` <6AE080B68D46FC4BA2D2769E68D765B708019E97-RL0Hj/+nBVC81RJBUSuqCa4g8xLGJsHaLnY5E4hWTkheoWH0uzbU5w@public.gmane.org> 2012-09-02 14:22 ` Joakim Tjernlund [not found] ` <OF0ACFB3FB.F2667AE9-ONC1257A6D.004E0ADE-C1257A6D.004EEB75@LocalDomain> 2012-09-11 10:13 ` Joakim Tjernlund 2012-09-14 14:02 ` Wolfram Sang [not found] ` <20120914140234.GH2630-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> 2012-09-14 14:21 ` Joakim Tjernlund
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).