From: James Hogan <james.hogan-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
To: Sifan Naeem <Sifan.Naeem-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
Cc: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>,
"linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH 6/7] i2c: img-scb: add handle for stop detected interrupt
Date: Wed, 29 Jul 2015 22:23:39 +0100 [thread overview]
Message-ID: <20150729212339.GA9258@jhogan-linux.le.imgtec.org> (raw)
In-Reply-To: <A0E307549471DA4DBAF2DE2DE6CBFB7E4966DE38-brIQrgj5TFtJFJhlrACyRFBRoQTxkR7k@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 5508 bytes --]
On Wed, Jul 29, 2015 at 06:06:24PM +0100, Sifan Naeem wrote:
> Hi James,
>
> > -----Original Message-----
> > From: James Hogan
> > Sent: 29 July 2015 16:34
> > To: Sifan Naeem; Wolfram Sang; linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> > Subject: Re: [PATCH 6/7] i2c: img-scb: add handle for stop detected interrupt
> >
> > On 27/07/15 12:56, Sifan Naeem wrote:
> > > Stop Detected interrupt is triggered when a Stop bit is detected on
> > > the bus, which indicates the end of the current transfer.
> > >
> > > When the end of a transfer is indicated by the Stop bit interrupt,
> > > drain the FIFO and signal completion for the transaction. But if the
> > > interrupt was triggered before all data is written to the fifo or with
> > > more data expected return error with transfer complete signal.
> > >
> > > Halting the bus is no longer necessary after a stop bit is detected on
> > > the bus, as there cannot be a repeated start transfer when the stop
> > > bit has been issued, hence remove the transaction halt bit.
> > >
> > > Signed-off-by: Sifan Naeem <sifan.naeem-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
> > > ---
> > > drivers/i2c/busses/i2c-img-scb.c | 28 +++++++++++++++++++++++++++-
> > > 1 file changed, 27 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/i2c/busses/i2c-img-scb.c
> > > b/drivers/i2c/busses/i2c-img-scb.c
> > > index 10141a9..90faf48 100644
> > > --- a/drivers/i2c/busses/i2c-img-scb.c
> > > +++ b/drivers/i2c/busses/i2c-img-scb.c
> > > @@ -152,6 +152,7 @@
> > > #define INT_TRANSACTION_DONE BIT(15)
> > > #define INT_SLAVE_EVENT BIT(16)
> > > #define INT_TIMING BIT(18)
> > > +#define INT_STOP_DETECTED BIT(19)
> > >
> > > #define INT_FIFO_FULL_FILLING (INT_FIFO_FULL |
> > INT_FIFO_FILLING)
> > >
> > > @@ -175,7 +176,8 @@
> > > INT_WRITE_ACK_ERR | \
> > > INT_FIFO_FULL | \
> > > INT_FIFO_FILLING | \
> > > - INT_FIFO_EMPTY)
> > > + INT_FIFO_EMPTY | \
> > > + INT_STOP_DETECTED)
> > >
> > > #define INT_ENABLE_MASK_WAITSTOP (INT_SLAVE_EVENT | \
> > > INT_ADDR_ACK_ERR | \
> > > @@ -907,6 +909,18 @@ static unsigned int img_i2c_auto(struct img_i2c
> > *i2c,
> > > return ISR_COMPLETE(0);
> > > }
> > > }
> > > + if (int_status & INT_STOP_DETECTED) {
> > > + int ret;
> > > + /*
> > > + * Stop bit indicates the end of the transfer, it means
> > > + * we should read all the data (or drain the FIFO). We
> > > + * must signal completion for this transaction.
> > > + */
> > > + img_i2c_transaction_halt(i2c, false);
> >
> > to get a stop bit detected, wouldn't transaction halt already have to be off?
>
> Yes, but in case we were too slow re-enabling the master halt and a stop was detected simultaneously to when master halt was set.
Okay, I already checked to make sure the t_halt thing is being done with
the spinlock held in both places, and irqs disabled in non-irq context,
since you wouldn't want a preemption or irq in between to delay t_halt
getting set anyway, in case it reached the stop bit without halting.
So you should be okay. On UP you'll never handle an irq in between as
irqs are disabled, and on SMP the spinlock will ensure the bulk of the
irq handler and t_halt thing in user context can't run concurrently on
different CPUs.
Thanks
James
> >
> > > + img_i2c_read_fifo(i2c);
> > > + ret = (i2c->msg.len == 0) ? 0 : EIO;
> >
> > If it wasn't fully transferred, wouldn't that already imply an
> > INT_WRITE_ACK_ERR or INT_ADDR_ACK_ERR, which should've already been
> > handled?
> >
> This was added as a safety check, yes I guess it's impossible to get a stop bit before all data is transferred without an error condition.
> >
> > Could it then be as simple as this? (untested):
> >
> Yes, this would do.
>
> Thanks,
> Sifan
> > diff --git a/drivers/i2c/busses/i2c-img-scb.c b/drivers/i2c/busses/i2c-img-
> > scb.c
> > index 00ffd6613680..f694b47dcf74 100644
> > --- a/drivers/i2c/busses/i2c-img-scb.c
> > +++ b/drivers/i2c/busses/i2c-img-scb.c
> > @@ -867,6 +867,13 @@ static unsigned int img_i2c_auto(struct img_i2c *i2c,
> >
> > mod_timer(&i2c->check_timer, jiffies + msecs_to_jiffies(1));
> >
> > + if (int_status & INT_STOP_DETECTED) {
> > + /* Drain remaining data in FIFO and complete transaction */
> > + if (i2c->msg.flags & I2C_M_RD)
> > + img_i2c_read_fifo(i2c);
> > + return ISR_COMPLETE(0);
> > + }
> > +
> > if (i2c->msg.flags & I2C_M_RD) {
> > if (int_status & INT_FIFO_FULL_FILLING) {
> > img_i2c_read_fifo(i2c);
> >
> > Cheers
> > James
> >
> > > + return ISR_COMPLETE(ret);
> > > + }
> > > } else {
> > > if (int_status & INT_FIFO_EMPTY) {
> > > if (i2c->msg.len == 0) {
> > > @@ -916,6 +930,18 @@ static unsigned int img_i2c_auto(struct img_i2c
> > *i2c,
> > > }
> > > img_i2c_write_fifo(i2c);
> > > }
> > > + if (int_status & INT_STOP_DETECTED) {
> > > + int ret;
> > > +
> > > + img_i2c_transaction_halt(i2c, false);
> > > + /*
> > > + * Stop bit indicates the end of a transfer and if the
> > > + * transfer has ended before all data is written to the
> > > + * fifo, return an error with transfer complete signal.
> > > + */
> > > + ret = (i2c->msg.len == 0) ? 0 : EIO;
> > > + return ISR_COMPLETE(ret);
> > > + }
> > > }
> > >
> > > return 0;
> > >
>
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2015-07-29 21:23 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-27 11:55 [PATCH 0/7] i2c: img-scb: enchancements to support i2c on pistachio Sifan Naeem
[not found] ` <1437998162-32724-1-git-send-email-sifan.naeem-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-07-27 11:55 ` [PATCH 1/7] i2c: img-scb: support I2C_M_IGNORE_NAK Sifan Naeem
[not found] ` <1437998162-32724-2-git-send-email-sifan.naeem-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-07-29 13:58 ` James Hogan
2015-07-27 11:55 ` [PATCH 2/7] i2c: img-scb: support repeated starts on IP v3.3 Sifan Naeem
[not found] ` <1437998162-32724-3-git-send-email-sifan.naeem-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-07-29 14:17 ` James Hogan
2015-07-27 11:55 ` [PATCH 3/7] i2c: img-scb: mark transaction as complete when all data is read Sifan Naeem
[not found] ` <1437998162-32724-4-git-send-email-sifan.naeem-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-07-29 14:21 ` James Hogan
[not found] ` <55B8E15B.9070002-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-07-29 14:37 ` Sifan Naeem
2015-07-27 11:55 ` [PATCH 4/7] i2c: img-scb: mark transaction as complete when no more data to write Sifan Naeem
[not found] ` <1437998162-32724-5-git-send-email-sifan.naeem-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-07-29 14:22 ` James Hogan
[not found] ` <55B8E19A.8010302-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-07-29 14:38 ` Sifan Naeem
2015-07-27 11:56 ` [PATCH 5/7] i2c: img-scb: remove fifo EMPTYING interrupts handle Sifan Naeem
[not found] ` <1437998162-32724-6-git-send-email-sifan.naeem-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-07-29 16:01 ` James Hogan
[not found] ` <55B8F8C1.8030507-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-07-29 17:00 ` Sifan Naeem
2015-07-27 11:56 ` [PATCH 6/7] i2c: img-scb: add handle for stop detected interrupt Sifan Naeem
[not found] ` <1437998162-32724-7-git-send-email-sifan.naeem-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-07-29 15:34 ` James Hogan
[not found] ` <55B8F271.6060003-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-07-29 17:06 ` Sifan Naeem
[not found] ` <A0E307549471DA4DBAF2DE2DE6CBFB7E4966DE38-brIQrgj5TFtJFJhlrACyRFBRoQTxkR7k@public.gmane.org>
2015-07-29 21:23 ` James Hogan [this message]
2015-07-27 11:56 ` [PATCH 7/7] i2c: img-scb: add handle for Master halt interrupt Sifan Naeem
[not found] ` <1437998162-32724-8-git-send-email-sifan.naeem-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-07-29 15:59 ` James Hogan
[not found] ` <55B8F849.4080105-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-07-29 17:13 ` Sifan Naeem
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=20150729212339.GA9258@jhogan-linux.le.imgtec.org \
--to=james.hogan-1axoqhu6uovqt0dzr+alfa@public.gmane.org \
--cc=Sifan.Naeem-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.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).