linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Rosin <peda@axentia.se>
To: "Adamski,
	Krzysztof (Nokia - PL/Wrocław)" <krzysztof.adamski@nokia.com>,
	"Wolfram Sang" <wsa@the-dreams.de>
Cc: "linux-i2c@vger.kernel.org" <linux-i2c@vger.kernel.org>
Subject: Re: Two separate i2c transfers
Date: Fri, 15 May 2020 10:02:31 +0200	[thread overview]
Message-ID: <e8d2d552-d1eb-1c71-1aeb-6ec9876f33f0@axentia.se> (raw)
In-Reply-To: <1f6b97e9-9ff8-2cdb-c6c5-16304f067d47@nokia.com>



On 2020-05-15 09:04, Adamski, Krzysztof (Nokia - PL/Wrocław) wrote:
> Hi Wolfram, Peter,
> 
> Thank you for the quick response.
> 
> W dniu 14.05.2020 o 16:50, Wolfram Sang pisze:
>> Hi Krzysztof,
>>
>> On Thu, May 14, 2020 at 02:41:17PM +0200, Adamski, Krzysztof (Nokia - PL/Wrocław) wrote:
>>
>> Adding Peter as the mux maintainer to CC.
>>
>>> I have a problem that I think cannot be currently easily addressed by I2C framework in the kernel and I'm seeking for an
>>> advice on how to approach this. I have an I2C device that can be accessed from two I2C masters connected to I2C bus
>>> master selector channels. Both masters must do such a sequence before performing long operation:
>>
>> I need a diagram of that setup. What is the BMS? A chip? Some software?
>> Can you draw a graph and give names of chips etc...?
>>
>> And, of course, why on earth do you need to access the same chip from
>> two masters within one Linux? :) (That's how I understood it)
>>

*snip* useful layout.

> I was thinking that maybe a lock like this could be expressed by i2c_lock_bus with some special flag that would make
> sure no deselect is called in i2c_mux_master_xfer() (and would be ignored if our parent is not an arbiter)? We already
> have the I2C_MUX_ARBITRATOR flag and the i2c_mux_core does have an arbitrator bool so it is just a matter of allowing to
> do this kind of deeper lock on the bus.

Yes, that definitely makes it clearer. So, what you need is something
more complex than an I2C xfer between select/deselect. Your proposal
to add a flag to not do the deselect should probably have a matching
flag to not do the select on the following xfer. Otherwise that second
xfer is likely to do useless work. This should probably also be two
independent flags, so that you can add intermediate xfers that neither
select nor deselect. But you also need an explicit deselect mechanism
for use if there is a problem half way through...

But, I think all that exposes the too much to the users, and while it
is certainly possible (most things are), I not a huge fan of it.
Maintainers of other subsystems will not know the rules, and drivers
are, over time, bound to start using these facilities in half-baked
ways.

I would rather have some generic I2C mechanism to request more than
a single xfer as a unit, such that the muxes/arbs/gates can then lock
the mux/arb/gate, do the select, feed the unit to the parent adapter
and finally deselect and unlock the mux/arb/gate. With the locking
and selecting centralized instead of spread out to all users. This
helps avoid bugs where things are not cleaned up on error paths etc.

How that "I2C unit" should be constructed is another matter. The
cool thing of the day seems to be eBPF programs, but I don't know
if that fits here?

Note that there are other users needing more complex "units" than
xfers. Muxes themselves could use it, and there are a number of
drivers that lock the adapter manually, do a couple of unlocked xfers,
and then unlock the adapter. All that could probably be cleaned up a
bit with a generic "I2C unit" facility.

Cheers,
Peter

  parent reply	other threads:[~2020-05-15  8:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-14 12:41 Two separate i2c transfers Adamski, Krzysztof (Nokia - PL/Wrocław)
2020-05-14 14:50 ` Wolfram Sang
2020-05-15  7:04   ` Adamski, Krzysztof (Nokia - PL/Wrocław)
2020-05-15  7:53     ` Wolfram Sang
2020-05-15  8:51       ` Adamski, Krzysztof (Nokia - PL/Wrocław)
2020-05-15  9:20         ` Wolfram Sang
2020-05-15  9:24           ` Peter Rosin
2020-05-15  9:31             ` Wolfram Sang
2020-05-15  9:46           ` Adamski, Krzysztof (Nokia - PL/Wrocław)
2020-05-15  8:02     ` Peter Rosin [this message]
2020-05-15  8:36       ` Adamski, Krzysztof (Nokia - PL/Wrocław)
2020-05-15 21:19         ` Peter Rosin
2020-05-17 21:32           ` Peter Rosin
2020-05-19 12:59             ` Adamski, Krzysztof (Nokia - PL/Wrocław)

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=e8d2d552-d1eb-1c71-1aeb-6ec9876f33f0@axentia.se \
    --to=peda@axentia.se \
    --cc=krzysztof.adamski@nokia.com \
    --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).