linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Juergen Fitschen <me@jue.yt>
To: Wolfram Sang <wsa@the-dreams.de>
Cc: linux-i2c@vger.kernel.org
Subject: Re: I2C slave mode for i2c-at91 driver
Date: Wed, 18 Oct 2017 14:32:53 +0200	[thread overview]
Message-ID: <029b74bfca29bb33fe551975e3d1f7ce@jfitschen.de> (raw)
In-Reply-To: <20171018073725.6qtglbpquyqx5xyq@ninjato>

Hi Wolfram,

>> 1) According to [1] the return value of the I2C_SLAVE_WRITE_RECEIVED 
>> event
>> determines whether the received byte shall be ACKed or NACKed. The 
>> problem
>> with the Atmel hardware is that it is not possible to manipulate the 
>> ACK bit
>> of the current byte in flight; it will be ACKed automatically. It is 
>> only
>> possible to (N)ACK the following byte(s) since some FIFO magic is 
>> going on
>> inside the hardware.
>
> So, it is not possible to NACK the last byte?

If you would like to receive 3 bytes from a remote master and the last 
byte shall be NACKed, the backend must have the following behaviour to 
be compatible with the SAMA5 MPUs:

                                  +-----+-+-----+-+-----+-+
   Data on wire:                  |BYTE1|A|BYTE2|A|BYTE3|N|
                                  +-----+-+-----+-+-----+-+
   I2C_SLAVE_WRITE_RECEIVED fired:        ^       ^       ^
   Event's return value:                  A       N       X  (X=don't 
care)

But if I understand the documentation correctly, the return value 
corresponds to the currently received byte and not the next byte. So the 
following backend behaviour is described by the docs:

                                  +-----+-+-----+-+-----+-+
   Data on wire:                  |BYTE1|A|BYTE2|A|BYTE3|N|
                                  +-----+-+-----+-+-----+-+
   I2C_SLAVE_WRITE_RECEIVED fired:      ^       ^       ^
   Event's return value:                A       A       N

Or am I wrong?


>> Do you think it is a valid approach to ignore the return value and 
>> always
>> ACK received bytes? Or would you rather set the behaviour for the 
>> following
>> bytes? That would delay the desired ACK bit by at least one byte.
>
> Tricky, since both options are really sub-optimal. I tend to think 
> that
> reporting the error a bit later is the slightly better option. Most
> client drivers will act on the fact that the whole transfer failed
> somehow. Where it fails is not so essential. We don't have proper 
> means
> to report the exact position of the failure currently anyhow.

I had a look into the i2c-designware driver sources. As far as I 
understand it also does not respect the return value of the 
I2C_SLAVE_WRITE_RECEIVED event. It just prints out debug messages if the 
received byte shall be ACKed.


>> How would you implement blocking master transactions while slave 
>> mode is
>> enabled? I would return EBUSY if master_xfer is called.
>
> The i2c-designware driver has the same problem. We decided to have
> seperate struct i2c_algorithms for master and slave. The core helper
> i2c_detect_slave_mode() can help you to determine which mode should 
> be
> used. The designware drive might give you some inspiration.

Thank you for the hint! This really helps.


Kind regards,
   Juergen

      reply	other threads:[~2017-10-18 13:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-17 10:56 I2C slave mode for i2c-at91 driver Juergen Fitschen
2017-10-18  7:31 ` Uwe Kleine-König
2017-10-18  7:43   ` Wolfram Sang
2017-10-18  8:00     ` Uwe Kleine-König
2017-10-18 12:40   ` Juergen Fitschen
2017-10-18  7:37 ` Wolfram Sang
2017-10-18 12:32   ` Juergen Fitschen [this message]

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=029b74bfca29bb33fe551975e3d1f7ce@jfitschen.de \
    --to=me@jue.yt \
    --cc=linux-i2c@vger.kernel.org \
    --cc=wsa@the-dreams.de \
    /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).