From: u.kleine-koenig@pengutronix.de (Uwe Kleine-König)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/3] i2c: slave-eeprom: add eeprom simulator driver
Date: Sun, 23 Nov 2014 21:20:08 +0100 [thread overview]
Message-ID: <20141123202008.GE4431@pengutronix.de> (raw)
In-Reply-To: <20141122182630.GD9698@katana>
Hello Wolfram,
On Sat, Nov 22, 2014 at 07:26:30PM +0100, Wolfram Sang wrote:
>
> > this mail is thematically more a reply to patch 1 and maybe just serves
> > my understanding of the slave support.
>
> Sure. This shows how badly needed the documentation is :)
>
> ...
> > > + break;
> > > +
> > > + case I2C_SLAVE_STOP:
> > > + eeprom->first_write = true;
> > > + break;
> > > +
> > > + default:
> > > + break;
> > > + }
> > > +
> > > + return 0;
> > > +}
> > This is the most interesting function here because it uses the new
> > interface, the functions below are only to update and show the simulated
> > eeprom contents and driver boilerplate, right?
>
> Yes.
>
> > When the eeprom driver is probed and the adapter driver notices a read
> > request for the respective i2c address, this callback is called with
> > event=I2C_SLAVE_REQ_READ_START. Returning 0 here and provide the first
> > byte to send make the adapter ack the read request and send the data
> > provided. If something != 0 is returned a NAK is sent?
>
> We only send NAK on write requests (I use read/write from the master
I don't understand this. Who is "we" in this case?
> perspective). Then, we have to say if the received byte was successfully
> processed. When reading, the master has to ack the successful reception
> of the byte.
Right, I got this wrong in my question. On a read request (as seen from
the master) the master has to ack.
> > How is the next byte requested from the slave driver? I assume with two
> > additional calls to the callback, first with
> > event=I2C_SLAVE_REQ_READ_END, then event=I2C_SLAVE_REQ_READ_START once
> > more. Would it make sense to reduce this to a single call? Does the
> > driver at READ_END time already know if its write got acked? If so, how?
>
> No single call. I had this first, but my experiments showed that it is
> important for the EEPROM driver to only increase the internal pointer
> when the byte was ACKed. Otherwise, I was off-by-one.
Sure, the driver has to know how his read response was received by the
master. But assuming I understand your abstraction right there is some
redundancy. There are only three cases on a read request (well plus error
handling):
- master sends ACK, reads next byte
in this case the slave must provide another word
In your abstraction this implies
callback(I2C_SLAVE_REQ_READ_END); <-- this is redundant
callback(I2C_SLAVE_REQ_READ_START);
- master sends ACK, then P or Sr
callback(I2C_SLAVE_REQ_READ_END);
maybe callback(I2C_SLAVE_STOP)
- master sends NACK
in this case the message ends and the master has to send Sr or P.
In your case this results in:
nothing for the NACK?
maybe callback(I2C_SLAVE_STOP)
The situations where the slave has to react are:
- slave was addressed with R
input: address
output: NAK or (ACK + data byte)
- slave was addressed with #W:
input: address
output: NAK or ACK
- data sent by slave-transmitter was acked
output: next data byte (maybe unused because master sends Sr or P)
- data sent by slave-transmitter was nacked
output: void (unless we want to support IGNORE_NAK :-)
- slave received a data byte (write)
input: data
output: NAK or ACK
This looks like a better model in my eyes. In this model the slave
driver doesn't even need to be informed about P. Not entirely sure about
"data sent by slave-transmitter was nacked".
> Ideally, I2C_SLAVE_REQ_READ_END should be used when the master ACKed the
> byte, right. However, the rcar hardware doesn't have an interrupt for
> this, so I imply that the start of a new read request ends the old one.
> I probably should add a comment for that.
>
> > This means that for each byte the callback is called. Would it make
> > sense to make the API more flexible and allow the slave driver to return
> > a buffer? This would remove some callback overhead and might allow to
> > let the adapter driver make use of its DMA mechanism.
>
> For DMA, I haven't seen DMA slave support yet. Makes sense to me, we
haha, there is only a single slave driver yet and you're the author.
> wouldn't know the transfer size, since the master can send a stop
> anytime. This makes possible gains of using a buffer also speculative.
> Also, I2C is still a low-bandwith bus, so usually we have a high number
> of small transfers.
>
> For now, I'd skip this idea. As I said in another thread, we need more
> use cases. If the need arises, we can come up with something. I don't
> think the current design prevents such an addition?
It would change the API, but starting to get experience with byte
banging is probably OK.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | http://www.pengutronix.de/ |
next prev parent reply other threads:[~2014-11-23 20:20 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-18 16:04 [PATCH 0/3] i2c: slave support framework for Linux devices Wolfram Sang
2014-11-18 16:04 ` [PATCH 1/3] i2c: core changes for slave support Wolfram Sang
2014-11-18 16:04 ` [PATCH 2/3] i2c: slave-eeprom: add eeprom simulator driver Wolfram Sang
2014-11-20 22:39 ` Stijn Devriendt
2014-11-22 18:12 ` Wolfram Sang
2014-11-25 22:07 ` Stijn Devriendt
2014-11-26 12:22 ` Wolfram Sang
2014-11-26 12:25 ` Alexander Kochetkov
2014-11-26 12:49 ` Wolfram Sang
2014-11-21 7:19 ` Uwe Kleine-König
2014-11-21 14:16 ` Uwe Kleine-König
2014-11-22 18:14 ` Wolfram Sang
2014-11-23 18:52 ` Uwe Kleine-König
2014-11-22 18:26 ` Wolfram Sang
2014-11-23 20:20 ` Uwe Kleine-König [this message]
2014-11-24 20:40 ` Wolfram Sang
2014-11-18 16:04 ` [PATCH 3/3] i2c: rcar: add slave support Wolfram Sang
2014-12-11 21:26 ` [PATCH 0/3] i2c: slave support framework for Linux devices Wolfram Sang
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=20141123202008.GE4431@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.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).