From: "Albrecht Dreß" <albrecht.dress@arcor.de>
To: Joakim Tjernlund <joakim.tjernlund@transmode.se>
Cc: linuxppc-dev@ozlabs.org, devicetree-discuss@lists.ozlabs.org,
ben-linux@fluff.org, iws@ovro.caltech.edu
Subject: Re: [Patch v2 1/2] 5200/mpc: improve i2c bus error recovery
Date: Thu, 18 Feb 2010 19:45:29 +0100 [thread overview]
Message-ID: <1266518744.5877.0@antares> (raw)
In-Reply-To: <OFC412BED7.5D5934A3-ONC12576CE.005D5F44-C12576CE.005EBE55@transmode.se> (from joakim.tjernlund@transmode.se on Thu Feb 18 18:14:51 2010)
[-- Attachment #1: Type: text/plain, Size: 3091 bytes --]
Hi Joakim:
Am 18.02.10 18:14 schrieb(en) Joakim Tjernlund:
> > [snip]
> > > > static void mpc_i2c_fixup(struct mpc_i2c *i2c)
> > > > {
> > > > - writeccr(i2c, 0);
> > > > - udelay(30);
> > > > - writeccr(i2c, CCR_MEN);
> > > > - udelay(30);
> > > > - writeccr(i2c, CCR_MSTA | CCR_MTX);
> > > > - udelay(30);
> > > > - writeccr(i2c, CCR_MSTA | CCR_MTX | CCR_MEN);
> > > > - udelay(30);
> > > > - writeccr(i2c, CCR_MEN);
> > > > - udelay(30);
> > > > + int k;
> > > > + u32 delay_val = 1000000 / i2c->real_clk + 1;
> > > > +
> > > > + if (delay_val < 2)
> > > > + delay_val = 2;
> > > > +
> > > > + for (k = 9; k; k--) {
> > > > + writeccr(i2c, 0);
> > > > + writeccr(i2c, CCR_MSTA | CCR_MTX | CCR_MEN);
> > > > + udelay(delay_val);
> > > > + writeccr(i2c, CCR_MEN);
> > > > + udelay(delay_val << 1);
> > > > + }
> > > > }
> > >
>>> I am curious, didn't old method work with by just wrapping a for(k=9; k; k--) around it? How did the wave form look?
> >
>> Sure does that work! The waveform was somewhat "streched", mainly due to the delays between some of the writeccr() calls which don't change the sda/scl lines. Unfortunately I didn't take shots from the scope.
>
> Yeah, the long delays has to go. So the wave form was the same but more stretched in time? I ask because I don't understand the writeccr(i2c, CCR_MSTA | CCR_MTX); is supposed to do.
Afaict, this is really a no-op. The '5200 user's manual says about MEN
<snip>
* 0 module is reset and disabled. This is the Power-ON reset. When low the interface is held in reset, but registers can still be accessed.
* 1 I2C module is enabled. Bit must be set before other CR bits have any effect.
</snip>
The change in the MSTA is needed -with the proper delays- as to generate the START and STOP conditions.
Unfortunately, the data sheet is not very clear (or my English too bad), but reading it *after* seeing the signals on the scope, I can at least guess what they mean :-/
Thus, the old code will probably produce SDA and SCL held high for ~90us, then a SDA/SCL low for ~30us (plus/minus the delays the hw adds internally according to the clock setting), and then a ~30us SDA/SCL high. It is not possible to get the necessary delays from the data sheet, but as I said I empirically verified some cases to be safe.
> The old code only works when the device is stuck at the last bit. To cope with any bit (worst case is the first bit) you need 9 cycles, 8 bits + ack = 9
>
> Just toggling the clock 9 cycles should unlock any slave stuck in a read operation. To unlock slaves stuck in a write operation you also need to generate a START in every cycle too.
Yes, of course... this was the initial motivation of the patch, as I *have* a slave which sometimes needs more than one cycle!
> As far as I can tell your patch does all of the above so
>
> Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se>
Thanks a lot again for your time, and your helpful comments!
Best, Albrecht.
[-- Attachment #2: Type: application/pgp-signature, Size: 190 bytes --]
next prev parent reply other threads:[~2010-02-18 18:45 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-18 15:04 [Patch v2 1/2] 5200/mpc: improve i2c bus error recovery Albrecht Dreß
2010-02-18 17:14 ` Joakim Tjernlund
2010-02-18 17:41 ` Grant Likely
2010-02-18 18:07 ` Joakim Tjernlund
2010-02-18 18:45 ` Albrecht Dreß [this message]
-- strict thread matches above, loose matches on Subject: below --
2010-02-17 18:59 Albrecht Dreß
2010-02-17 20:10 ` Grant Likely
2010-02-18 8:09 ` Joakim Tjernlund
2010-02-18 9:09 ` Albrecht Dreß
2010-02-18 12:33 ` Joakim Tjernlund
2010-02-18 13:23 ` Joakim Tjernlund
2010-05-05 22:09 ` Ira W. Snyder
2010-05-06 17:54 ` Albrecht Dreß
2010-05-06 18:06 ` Grant Likely
2010-05-16 17:47 ` Albrecht Dreß
2010-05-19 16:02 ` Grant Likely
2010-06-16 19:30 ` Albrecht Dreß
2013-03-13 5:30 ` panpan2523
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1266518744.5877.0@antares \
--to=albrecht.dress@arcor.de \
--cc=ben-linux@fluff.org \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=iws@ovro.caltech.edu \
--cc=joakim.tjernlund@transmode.se \
--cc=linuxppc-dev@ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).