I2C rework -- what do you think?
cover I2C rework -- what do you think?
Hi everyone,
Here is the first draft of major I2C subsystem rework. This is not a patch that should be applied to the tree--it will break systems with I2C busses over multiplexers and probably something else--but rather a Request For Comments. I would like to here all the objections, suggestions etc. before I go on and undertake a big job to change all the boards and other stuff to the new code. It is a big job and I don't want to spend a lot of time doing something that nobody would accept.
My goal is to somehow untie I2C subsystem from platform-specific parts. This is not an attempt for a "code cleanup" though some cleanup could be achieved in process. But this is not a goal, it is just a probable side effect.
Primary goal is to allow multiple I2C busses on a board served by different I2C controllers (on-SoC, external, bit-banging.) As of now we have rudimentary support for multiple BUILT-IN adapters in some SoCs (e.g. fsl_i2c.c) but this support is platform specific and does NOT allow any additional (external etc.) adapters.
This is not a problem for a vast majority of supported boards that usually have a single I2C bus but there are cases when boards have several busses served by different I2C adapters. I personally have the first prototype of such a board right now in PCB fab. It's MPC8548E based mATX motherboard that uses both built-in I2C adapters (fsl_i2c.c) AND the third one off of SM502 chip sitting on PCI bus. All 3 busses are required for proper system initialization and operation because we have 3 I2C devices with the same address, 0x68 that can not be changed.
For existing boards we have just 2 MUTUALLY EXCLUSIVE options, CONFIG_HARD_I2C and CONFIG_SOFT_I2C. That gives very little control over I2C subsystem. It won't even allow for having a bit-banged I2C bus in addition to a hardware adapter, less for several such busses or anything external (e.g. some chipset adapters that would give some control over sensors and such.) This is obvious even from that HARD/SOFT I2C exclusivness -- bit-banging I2C interface is ortogonal to a built-in hardware one so why wouldn't we were able to use both? One can even have several bit-banging busses as long as GPIO pins are available...
There are 2 different ways to address this issue -- make another platform specific monster or rework the entire I2C subsystem to make that multibus support generic and common U-Bootwide.
This is an attempt to make I2C uniform and scalable.
Here is a little manifest...
First of all, there is a basic entity, I2C bus. It can be a simple I2C bus from the only I2C adapter on a SoC, several busses from several adapters, both on-SoC and external, and several busses growing off of several adapters via I2C multiplexers/switches (e.g. PCA9544 etc.) They are all the same for the rest of code accessed with single set of i2c_read()/i2c_write() and friends for all busses no matter what adapter they are on and if they are directly connected to an adapter or reached through a set of I2C mux chips.
Any I2C operation is performed on the CURRENT bus. Current bus is set with i2c_set_bus_num(). In case of directly connected busses it merely changes a global variable that is used as an index into an array. If some busses are connected via I2C muxes, it disconnects the previously connected muxes if any and sets all chips along the path to the new bus so next access will go to that bus.
All those paths are statically allocated at compile time according to board's config file. That means we can use I2C from flash before U-Boot is relocated to DRAM thus allowing us to use SPD for DRAM initialization. It is also means we do NOT need that "i2c bus" or whatever command to setup a bus behind muxes for consecutive access--we just choose that bus number and that's it.
All busses are explicitely defined in boards' config files so we know exactly where all accesses are going.
I did test it on MPC8548CDS system and it works OK. There is a patch for MPC8548CDS.h in the patchset that changes it to the new I2C code and a speculative example of multiadapter multibus configuration with 3 adapters and 5 busses 3 of which are connected with I2C muxes, 2 from them are multihop.
Please let me know guys what you think so I would be able to start with a big patch.
---
******************************************************************
* KSI at home KOI8 Net < > The impossible we do immediately. *
* Las Vegas NV, USA < > Miracles require 24-hour notice. *
******************************************************************
cover I2C rework -- what do you think?
Hello ksi,
Quoted 10 lines · ksi at koi8.net wrote:
Hi everyone,
Here is the first draft of major I2C subsystem rework. This is not a patch that should be applied to the tree--it will break systems with I2C busses over multiplexers and probably something else--but rather a Request For Comments. I would like to here all the objections, suggestions etc. before I go on and undertake a big job to change all the boards and other stuff to the new code. It is a big job and I don't want to spend a lot of time doing something that nobody would accept.
Yes, this would be a big job, and how do you want to test this for ~200 boards?
Quoted 2 lines
My goal is to somehow untie I2C subsystem from platform-specific parts. This
Isn t this so?
Quoted 9 lines
is not an attempt for a "code cleanup" though some cleanup could be achieved in process. But this is not a goal, it is just a probable side effect.
Primary goal is to allow multiple I2C busses on a board served by different I2C controllers (on-SoC, external, bit-banging.) As of now we have rudimentary support for multiple BUILT-IN adapters in some SoCs (e.g.
fsl_i2c.c) but this support is platform specific and does NOT allow any additional (external etc.) adapters.
Ah... okay, this lacks in the actual u-boot i2c layer. I see here to ways:
a) Rewriting the complete code. This is really a big change (maybe, I am not a I2C expert, the cleaner way, but this will need a long time and a
good test
period ...)
b) It should be possible to extend the i2c hardware specific functions, to allow
more then one i2c platform adapter. Switching between those should
possible
with the "i2c dev" command (Which I think is the reason for this
command)
also "i2c bus" should be extend to choose, which "real" I2C Bus it uses. Something like this comes in my mind:
i2c bus devid=[muxtype:muxaddr:muxchannel]
with devid (an existing device id see "i2c dev" command) if "devid=" is missing, old behaviour (backward compatible)
Quoted 4 lines
This is not a problem for a vast majority of supported boards that usually have a single I2C bus but there are cases when boards have several busses served by different I2C adapters. I personally have the first prototype of
[...]
Quoted 10 lines
Here is a little manifest...
First of all, there is a basic entity, I2C bus. It can be a simple I2C bus from the only I2C adapter on a SoC, several busses from several adapters, both on-SoC and external, and several busses growing off of several adapters via I2C multiplexers/switches (e.g. PCA9544 etc.) They are all the same for the rest of code accessed with single set of i2c_read()/i2c_write() and friends for all busses no matter what adapter they are on and if they are directly connected to an adapter or reached through a set of I2C mux chips.
Quoted 9 lines
Any I2C operation is performed on the CURRENT bus. Current bus is set with
i2c_set_bus_num(). In case of directly connected busses it merely changes a global variable that is used as an index into an array. If some busses are connected via I2C muxes, it disconnects the previously connected muxes if any and sets all chips along the path to the new bus so next access will go to that bus.All those paths are statically allocated at compile time according to
Why must be this statically defined? Think of a Hardwaremanufacturer who has several boardvariants. In your case, he must have for every board a config file -> different binaries. In the case using "i2c bus" he has one binary
which is able to work with all of his variants! And he can connect on a running system on an actual not used I2C Bus, another mux for example, and can configure this "new" bus per commandline without generating a new binary, flashing, resetting the board!
Ah, now I understand why you have to change all config files for all existing
boards which uses I2C. Think of my suggestion to integrate the "multi real bus"
in the existing code, so you dont have to do this ... boards which have only one Hardware I2C Bus automagically use this bus, because i2c_bus_cur = 0!
Quoted 3 lines
board's config file. That means we can use I2C from flash before U-Boot is relocated to DRAM thus allowing us to use SPD for DRAM initialization. It is
You can also use in actual code SPD EEprom for DRAM initialization. Guess the following example:
SPD EEprom reached over 2 muxes:
define an Environment var like:SPD_EEprom =pca9554a:70:5:pca9544a:71:4
now make bevor accessing the SPD EEprom:
i2c_mux_ident_muxstring_f (getenv ("SPD_EEprom");
and you can access the SPD EEProm! (And nice side effect, the way to your SPD EEprom is not fix in the code, you can choose it easy per Env var!)
But, so my feeling, it would be a good idea, to connect a SPD EEprom not over a mux, at least only on channel 0, so no mux commands are necessary to read from the SPD EEprom after reset.
Quoted 4 lines
also means we do NOT need that "i2c bus" or whatever command to setup a bus behind muxes for consecutive access--we just choose that bus number and that's it.
That has nothing to do with the "i2c bus" command. This command only adds new virtual buss to the "i2c dev" list (device number). you can then select this bus with "i2c dev [device number]" or in code with i2c_set_bus_num([device number]) . You see, this is also just an integer, you have to choose!
Quoted 3 lines
All busses are explicitely defined in boards' config files so we know exactly where all accesses are going.
Actual Code too. Make a "i2c dev" and you get the actual bus number, if it is a virtual
bus, you can use "i2c bus" to get a list of this virtual busses.
Quoted 6 lines
I did test it on MPC8548CDS system and it works OK. There is a patch for
MPC8548CDS.hin the patchset that changes it to the new I2C code and a speculative example of multiadapter multibus configuration with 3 adapters and 5 busses 3 of which are connected with I2C muxes, 2 from them are multihop.
Nice, but why you ignored the existing interface for handling with muxes? I think it is easier to extend the existing interface to support multiple "real"
interfaces ...
Quoted 2 lines
Please let me know guys what you think so I would be able to start with a big patch.
I think, the mux functionality is independent from the problem to have more then one hardware I2C Bus, or?
So, maybe you could integrate your "multiple hardware I2C Bus" concept (which looks good at a first look) in the existing code? I vote for accesing the I2C Bus over a mux with the actual way:
- defining with the "i2c bus" command a new "virtual" i2c device and
- accesing this with the standard command "i2c dev" because this is a more flexible way.
Wolfgang: Maybe we should have a "i2c" Tree for testing purposes, if we step into this "multi hardware I2C busses" theme.
bye
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
cover I2C rework -- what do you think?
Quoted 14 lines · Heiko Schocher
Hello ksi,
Quoted 3 lines · ksi at koi8.net wrote:
Hi everyone,
Here is the first draft of major I2C subsystem rework. This is not a
patch
Quoted 1 line
that should be applied to the tree--it will break systems with I2C
busses
Quoted 1 line
over multiplexers and probably something else--but rather a Request
For
Quoted 1 line
Comments. I would like to here all the objections, suggestions etc.
before I
Quoted 1 line
go on and undertake a big job to change all the boards and other stuff
Quoted 8 lines
to
Quoted 1 line
the new code. It is a big job and I don't want to spend a lot of time
doing
Quoted 2 lines
something that nobody would accept.
Yes, this would be a big job, and how do you want to test this for ~200 boards?
It's physically impossible -- I simply don't have all those board even if I had time to do it. However we have people with those boards who can test their parts.
I can test if it compiles for all boards. It is not black magic, just logical code and if it worked for several boards I can't see why it wouldn't work for majority of others. Those few that required some kind of magical touch and got broken we'll fix.
Quoted 19 lines
Quoted 1 line
My goal is to somehow untie I2C subsystem from platform-specific
parts. This
Quoted 1 line
Isn t this so?
Quoted 1 line
is not an attempt for a "code cleanup" though some cleanup could be
achieved
Quoted 3 lines
in process. But this is not a goal, it is just a probable side effect.
Primary goal is to allow multiple I2C busses on a board served by
different
Quoted 3 lines
I2C controllers (on-SoC, external, bit-banging.) As of now we have rudimentary support for multiple BUILT-IN adapters in some SoCs (e.g.
fsl_i2c.c) but this support is platform specific and does NOT allowany
Quoted 2 lines
additional (external etc.) adapters.
Quoted 8 lines
Ah... okay, this lacks in the actual u-boot i2c layer. I see here to ways:
a) Rewriting the complete code. This is really a big change (maybe, I am not
a I2C expert, the cleaner way, but this will need a long time and a
good test
period ...)
Eh, it ain't rocket science... Yes, it would require some time but nothing special...
Quoted 5 lines
b) It should be possible to extend the i2c hardware specific functions, to allow
more then one i2c platform adapter. Switching between those should
possible
with the "i2c dev" command (Which I think is the reason for this
Quoted 8 lines
command)
also "i2c bus" should be extend to choose, which "real" I2C Bus it uses. Something like this comes in my mind:
i2c bus devid=[muxtype:muxaddr:muxchannel]
with devid (an existing device id see "i2c dev"
command)
if "devid=" is missing, old behaviour (backward
compatible)
It makes no sence to me. Having just several busses--some direct, some via muxes--looks more natural, IMHO. If one wanted to check the exact path to that bus he could use "i2c bus bus_no" command. Other than that I can't see any reason for such information.
And remember, all those "i2c xyz" commands are just interactive commands that are usually used for debugging purposes or during board bringup process. The internal interface is more important and it is much easier an logical to just do "i2c_set_bus(N)" and then use regular i2c_read/i2_write or whatever is required. That makes the entire code uniform, without special treatment for muxed busses etc. Kinda like Unix where everything's a file :)
Quoted 40 lines
Quoted 1 line
This is not a problem for a vast majority of supported boards that
usually
Quoted 1 line
have a single I2C bus but there are cases when boards have several
busses
Quoted 1 line
served by different I2C adapters. I personally have the first
prototype of
Quoted 1 line
[...]
Quoted 3 lines
Here is a little manifest...
First of all, there is a basic entity, I2C bus. It can be a simple I2C
bus
Quoted 1 line
from the only I2C adapter on a SoC, several busses from several
adapters,
Quoted 1 line
both on-SoC and external, and several busses growing off of several
adapters
Quoted 1 line
via I2C multiplexers/switches (e.g. PCA9544 etc.) They are all the
same for
Quoted 1 line
the rest of code accessed with single set of i2c_read()/i2c_write()
and
Quoted 1 line
friends for all busses no matter what adapter they are on and if they
are
Quoted 1 line
directly connected to an adapter or reached through a set of I2C mux
chips.
Quoted 2 lines
Any I2C operation is performed on the CURRENT bus. Current bus is set
with
Quoted 1 line
i2c_set_bus_num(). In case of directly connected busses it merelychanges a
Quoted 1 line
global variable that is used as an index into an array. If some busses
are
Quoted 1 line
connected via I2C muxes, it disconnects the previously connected muxes
if
Quoted 1 line
any and sets all chips along the path to the new bus so next access
will go
Quoted 4 lines
to that bus.
All those paths are statically allocated at compile time according to
Quoted 8 lines
Why must be this statically defined? Think of a Hardwaremanufacturer who has several boardvariants. In your case, he must have for every board a config file -> different binaries. In the case using "i2c bus" he has one binary
which is able to work with all of his variants! And he can connect on a running system on an actual not used I2C Bus, another mux for example, and can configure this "new" bus per commandline without generating a new binary, flashing, resetting the board!
Eh, first of all we do have a lot of configuration files for different boards. And this is, IMHO, logical because every other board is different in some respect. There is no way we can make a universal U-Boot binary that works on each and every board. Furthermore, even if we could it would've been very big binary with lots of excessive code. It is not a U-Boot goal to be plug-and-pray do-all program -- it is a targeted highly specialized firmware of a smallest size possible. It is built for every particular board exactly to its hardware specs.
Then, if one even didn't use some available hardware I2C bus for anything at all it is not such a big deal to have that particular bus also enabled in the config file. It won't take much space and/or require additional effort to do. Once one have a bus he can use for experiments there is not rocket science to just configure possible muxes on that bus with a single mw command and use it as he wants. This is exactly what all those interactive commands for. All those additional busses/muxes/whatever will not be needed once the board design is finalized.
Quoted 8 lines
Ah, now I understand why you have to change all config files for all existing
boards which uses I2C. Think of my suggestion to integrate the "multi real bus"
in the existing code, so you dont have to do this ... boards which have only
one Hardware I2C Bus automagically use this bus, becausei2c_bus_cur= 0!
That is exactly what I'm going to do as a first step. For the new code to take effect one must define "CONFIG_NEW_I2C" in config file. If it is not defined no new code is used. Then I will work on each and every board/CPU one by one and when all of them are converted I will remove that define.
As a matter of fact I can only see 2 boards that use that existing mux code, namely mgsuvd and mgcoge. That will be trivial to rework.
Quoted 15 lines
Quoted 1 line
board's config file. That means we can use I2C from flash before
U-Boot is
Quoted 1 line
relocated to DRAM thus allowing us to use SPD for DRAM initialization.
It is
Quoted 1 line
You can also use in actual code SPD EEprom for DRAM initialization. Guess
the following example:SPD EEprom reached over 2 muxes:
define an Environment var like:
SPD_EEprom=pca9554a:70:5:pca9544a:71:4
Quoted 7 lines
now make bevor accessing the SPD EEprom:
i2c_mux_ident_muxstring_f(getenv ("SPD_EEprom");and you can access the SPD EEProm! (And nice side effect, the way to your
SPD EEprom is not fix in the code, you can choose it easy per Env var!)
I don't think it is a good idea. It breaks uniformity, i.e. one would have to have different functions for different boards (or unnecessary overloaded functions that would fit all.)
Quoted 3 lines
But, so my feeling, it would be a good idea, to connect a SPD EEprom not over a mux, at least only on channel 0, so no mux commands are necessary to read from the SPD EEprom after reset.
I totally agree but it is not always possible.
Quoted 4 lines
Quoted 1 line
also means we do NOT need that "i2c bus" or whatever command to setup
a bus
Quoted 1 line
behind muxes for consecutive access--we just choose that bus number
and
Quoted 8 lines
Quoted 2 lines
that's it.
That has nothing to do with the "i2c bus" command. This command only adds new virtual buss to the "i2c dev" list (device number). you can then select this bus with "i2c dev [device number]" or in code with
i2c_set_bus_num([device number]). You see, this is also just an integer, you have to choose!
I don't like an idea of adding virtual busses dynamically with an interactive command. Also it is not needed at all, one can easily switch muxes manually, with simple memory write command for some muxes that are not a part of board's permanent hardware.
Quoted 16 lines
Quoted 3 lines
All busses are explicitely defined in boards' config files so we know exactly where all accesses are going.
Actual Code too. Make a "i2c dev" and you get the actual bus number, if it is a virtual
bus, you can use "i2c bus" to get a list of this virtual busses.Quoted 1 line
I did test it on MPC8548CDS system and it works OK. There is a patch
for
Quoted 2 lines
MPC8548CDS.hin the patchset that changes it to the new I2C code and a speculative example of multiadapter multibus configuration with 3adapters
Quoted 3 lines
and 5 busses 3 of which are connected with I2C muxes, 2 from them are multihop.
Quoted 5 lines
Nice, but why you ignored the existing interface for handling with muxes?
I think it is easier to extend the existing interface to support multiple "real"
interfaces ...
I don't think it is needed at all. One has some number of busses on the board and all of them are active. Just switch to another bus and you're good to talk to that bus. If one needs something special, he can easily achieve it with writing to those muxes with existing read/write commands.
Quoted 8 lines
Quoted 1 line
Please let me know guys what you think so I would be able to start
with a
Quoted 1 line
big patch.
I think, the mux functionality is independent from the problem to have more
then one hardware I2C Bus, or?
No, it is dependent. Bus is a bus, no matter if it is a directly connected one or reached through some muxes. It is easier to use one entity (bus) instead of two separate ones (bus and mux.)
Quoted 7 lines
So, maybe you could integrate your "multiple hardware I2C Bus" concept (which looks good at a first look) in the existing code? I vote for accesing the I2C Bus over a mux with the actual way:
- defining with the "i2c bus" command a new "virtual" i2c device and
- accesing this with the standard command "i2c dev" because this is a more flexible way.
This is the command interface that is only of limited use. And there is no need to make a CLI user manually setup anything that is already defined in board config.
CLI is easy, I'm now trying to make a template driven, self-generating from config file multi-bus software I2C driver...
---
******************************************************************
* KSI at home KOI8 Net < > The impossible we do immediately. *
* Las Vegas NV, USA < > Miracles require 24-hour notice. *
******************************************************************
cover I2C rework -- what do you think?
Hello ksi,
Quoted 6 lines · ksi at koi8.net schrieb:
Quoted 5 lines · Heiko Schocher
Quoted 3 lines · ksi at koi8.net wrote:
Hi everyone,
Here is the first draft of major I2C subsystem rework. This is not a
patch
[...]
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
the new code. It is a big job and I don't want to spend a lot of time
doing
Quoted 2 lines
something that nobody would accept.
Yes, this would be a big job, and how do you want to test this for ~200 boards?
It's physically impossible -- I simply don't have all those board even if I had time to do it. However we have people with those boards who can test their parts.
Ack.
Quoted 5 lines
I can test if it compiles for all boards. It is not black magic, just logical code and if it worked for several boards I can't see why it wouldn't
work for majority of others. Those few that required some kind of magical touch and got broken we'll fix.
Ack.
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
My goal is to somehow untie I2C subsystem from platform-specific
parts. This
Quoted 1 line
Isn t this so?
[...]
Quoted 12 lines
Quoted 12 lines
Quoted 1 line
Primary goal is to allow multiple I2C busses on a board served by
different
Quoted 3 lines
I2C controllers (on-SoC, external, bit-banging.) As of now we have rudimentary support for multiple BUILT-IN adapters in some SoCs (e.g.
fsl_i2c.c) but this support is platform specific and does NOT allowany
Quoted 2 lines
additional (external etc.) adapters.
Ah... okay, this lacks in the actual u-boot i2c layer. I see here to ways:
Quoted 8 lines
Quoted 5 lines
a) Rewriting the complete code. This is really a big change (maybe, I am not
a I2C expert, the cleaner way, but this will need a long time and a
good test
period ...)Eh, it ain't rocket science... Yes, it would require some time but nothing special...
Ack.
Quoted 27 lines
Quoted 5 lines
b) It should be possible to extend the i2c hardware specific functions, to allow
more then one i2c platform adapter. Switching between those should
possible
with the "i2c dev" command (Which I think is the reason for thisQuoted 8 lines
command)
also "i2c bus" should be extend to choose, which "real" I2C Bus it uses. Something like this comes in my mind:
i2c bus devid=[muxtype:muxaddr:muxchannel]
with devid (an existing device id see "i2c dev"
command)
if "devid=" is missing, old behaviour (backward
compatible)It makes no sence to me. Having just several busses--some direct, some via muxes--looks more natural, IMHO. If one wanted to check the exact path to that bus he could use "i2c bus
bus_no" command. Other than that I can't see any reason for such information.And remember, all those "i2c xyz" commands are just interactive commands that are usually used for debugging purposes or during board bringup process. The internal interface is more important and it is much easier an logical to just do "
i2c_set_bus(N)" and then use regular i2c_read/i2_write or whatever is required. That makes the entire code uniform, without special
treatment for muxed busses etc. Kinda like Unix where everything's a file :)
Quoted 5 lines · I wrote:
Quoted 5 lines
That has nothing to do with the "i2c bus" command. This command only adds new virtual buss to the "i2c dev" list (device number). you can then select this bus with "i2c dev [device number]" or in code with
i2c_set_bus_num([device number]). You see, this is also just an integer, you have to choose!
Once again, you must with actual code also just do a i2c_set_bus_num () to switch between busses (real or virtual).
[...]
Quoted 9 lines
Quoted 8 lines
Ah, now I understand why you have to change all config files for all existing
boards which uses I2C. Think of my suggestion to integrate the "multi real bus"
in the existing code, so you dont have to do this ... boards which have only
one Hardware I2C Bus automagically use this bus, becausei2c_bus_cur= 0!
Quoted 4 lines
That is exactly what I'm going to do as a first step. For the new code to take effect one must define "
CONFIG_NEW_I2C" in config file. If it is not defined no new code is used. Then I will work on each and every board/CPU one by one and when all of them are converted I will remove that define.
OK,. But if I look in your patch you delete the "i2c bus" command, and this breaks at least 2 boards.
Quoted 3 lines
As a matter of fact I can only see 2 boards that use that existing mux code,
namely mgsuvd and mgcoge. That will be trivial to rework.
Yes, for those I made the "i2c bus" command. And it will follow soon 2 more boards ...
Quoted 19 lines
Quoted 19 lines
Quoted 1 line
board's config file. That means we can use I2C from flash before
U-Boot is
Quoted 1 line
relocated to DRAM thus allowing us to use SPD for DRAM initialization.
It is
Quoted 1 line
You can also use in actual code SPD EEprom for DRAM initialization. Guess
the following example:SPD EEprom reached over 2 muxes:
define an Environment var like:
SPD_EEprom=pca9554a:70:5:pca9544a:71:4now make bevor accessing the SPD EEprom:
i2c_mux_ident_muxstring_f(getenv ("SPD_EEprom");
Quoted 7 lines
Quoted 3 lines
and you can access the SPD EEProm! (And nice side effect, the way to your
SPD EEprom is not fix in the code, you can choose it easy per Env var!)I don't think it is a good idea. It breaks uniformity, i.e. one would have to have different functions for different boards (or unnecessary overloaded functions that would fit all.)
It was just a example, to show, that it is possible, not actually used.
Quoted 13 lines
Quoted 4 lines
Quoted 1 line
also means we do NOT need that "i2c bus" or whatever command to setup
a bus
Quoted 1 line
behind muxes for consecutive access--we just choose that bus number
and
Quoted 8 lines
Quoted 2 lines
that's it.
That has nothing to do with the "i2c bus" command. This command only adds new virtual buss to the "i2c dev" list (device number). you can then select this bus with "i2c dev [device number]" or in code with
i2c_set_bus_num([device number]). You see, this is also just an integer, you have to choose!
Quoted 5 lines
I don't like an idea of adding virtual busses dynamically with an interactive command. Also it is not needed at all, one can easily switch muxes manually, with simple memory write command for some muxes that are not
a part of board's permanent hardware.
It is needed! If, for example an EEprom, is not always on the same virtual bus. Some boards have no mux, some 1, some 2 ... and if we have this virtual busses statically, we must have for all boards an extra u-boot binary. The only Hardware difference for this boards is, how things are connected to the I2C bus ... and it is not OK for this manufacturer, to have for every board a different u-boot binary!
So, why shouldnt it possible to add to your proposal a possibility to add virtual i2c busses dynamically? (using a list instead of a fix table for example)
Quoted 22 lines
Quoted 16 lines
Quoted 3 lines
All busses are explicitely defined in boards' config files so we know exactly where all accesses are going.
Actual Code too. Make a "i2c dev" and you get the actual bus number, if it is a virtual
bus, you can use "i2c bus" to get a list of this virtual busses.Quoted 1 line
I did test it on MPC8548CDS system and it works OK. There is a patch
for
Quoted 2 lines
MPC8548CDS.hin the patchset that changes it to the new I2C code and a speculative example of multiadapter multibus configuration with 3adapters
Quoted 3 lines
and 5 busses 3 of which are connected with I2C muxes, 2 from them are multihop.
Quoted 5 lines
Nice, but why you ignored the existing interface for handling with muxes?
I think it is easier to extend the existing interface to support multiple "real"
interfaces ...
Quoted 5 lines
I don't think it is needed at all. One has some number of busses on the board and all of them are active. Just switch to another bus and you're good
to talk to that bus. If one needs something special, he can easily achieve it with writing to those muxes with existing read/write commands.
But it is in the code, because it is needed!
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Please let me know guys what you think so I would be able to start
with a
Quoted 1 line
big patch.
Quoted 7 lines
Quoted 3 lines
I think, the mux functionality is independent from the problem to have more
then one hardware I2C Bus, or?No, it is dependent. Bus is a bus, no matter if it is a directly connected one or reached through some muxes. It is easier to use one entity (bus) instead of two separate ones (bus and mux.)
You are here wrong. You didnt read my answer. Again:
with "i2c bus" you add virtual busses
with "i2c dev" you can switch between real *and* this virtual busses,
without thinking about what sort of bus it is.
just one command for switching between busses!
Quoted 11 lines
Quoted 7 lines
So, maybe you could integrate your "multiple hardware I2C Bus" concept (which looks good at a first look) in the existing code? I vote for accesing the I2C Bus over a mux with the actual way:
- defining with the "i2c bus" command a new "virtual" i2c device and
- accesing this with the standard command "i2c dev" because this is a more flexible way.This is the command interface that is only of limited use. And there is no need to make a CLI user manually setup anything that is already defined in board config.
Really? If commands are saved in Environmentvars, they maybe executed automagic on every reset ... thinking of for example "run net_nfs" which uses at least "tftp", "bootm", "setenv", ...
Quoted 2 lines
CLI is easy, I'm now trying to make a template driven, self-generating from config file multi-bus software I2C driver...
or just try to make this
i2c_adap_t *i2c_adap[CONFIG_SYS_NUM_I2C_ADAPTERS] = CONFIG_SYS_I2C_ADAPTERS;
dynamically and extendable and I am happy ;-)
bye
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
cover I2C rework -- what do you think?
Quoted 133 lines · Heiko Schocher
Hello ksi,
Quoted 6 lines · ksi at koi8.net schrieb:
Quoted 5 lines · Heiko Schocher
Quoted 3 lines · ksi at koi8.net wrote:
Hi everyone,
Here is the first draft of major I2C subsystem rework. This is not a
patch
[...]
Quoted 1 line
Quoted 1 line
Quoted 1 line
the new code. It is a big job and I don't want to spend a lot of
time
Quoted 5 lines
Quoted 5 lines
doing
Quoted 2 lines
something that nobody would accept.
Yes, this would be a big job, and how do you want to test this for
~200
Quoted 3 lines
Quoted 1 line
boards?
It's physically impossible -- I simply don't have all those board even
if I
Quoted 1 line
had time to do it. However we have people with those boards who can
test
Quoted 1 line
their parts.
Ack.
Quoted 4 lines
I can test if it compiles for all boards. It is not black magic, just logical code and if it worked for several boards I can't see why it wouldn't
work for majority of others. Those few that required some kind ofmagical
Quoted 1 line
touch and got broken we'll fix.
Ack.
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
My goal is to somehow untie I2C subsystem from platform-specific
parts. This
Quoted 1 line
Isn t this so?
[...]
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Primary goal is to allow multiple I2C busses on a board served by
different
Quoted 2 lines
I2C controllers (on-SoC, external, bit-banging.) As of now we have rudimentary support for multiple BUILT-IN adapters in some SoCs
(e.g.
Quoted 9 lines
Quoted 9 lines
Quoted 1 line
fsl_i2c.c) but this support is platform specific and does NOT allowany
Quoted 2 lines
additional (external etc.) adapters.
Ah... okay, this lacks in the actual u-boot i2c layer. I see here to ways:
a) Rewriting the complete code. This is really a big change (maybe, I
am
Quoted 2 lines
Quoted 2 lines
not
a I2C expert, the cleaner way, but this will need a long time anda
Quoted 4 lines
Quoted 2 lines
good test
period ...)Eh, it ain't rocket science... Yes, it would require some time but
nothing
Quoted 1 line
special...
Ack.
Quoted 1 line
Quoted 1 line
b) It should be possible to extend the i2c hardware specific
functions,
Quoted 2 lines
Quoted 2 lines
to allow
more then one i2c platform adapter. Switching between thoseshould
Quoted 11 lines
Quoted 10 lines
possible
with the "i2c dev" command (Which I think is the reason for this
command)
also "i2c bus" should be extend to choose, which "real" I2C Bus it uses. Something like this comes in my mind:
i2c bus devid=[muxtype:muxaddr:muxchannel]
with devid (an existing device id see "i2c dev"
command)
if "devid=" is missing, old behaviour (backward
compatible)Quoted 1 line
It makes no sence to me. Having just several busses--some direct, some
via
Quoted 1 line
muxes--looks more natural, IMHO. If one wanted to check the exact path
to
Quoted 1 line
that bus he could use "i2c bus
bus_no" command. Other than that Ican't see
Quoted 3 lines
any reason for such information.
And remember, all those "i2c xyz" commands are just interactive
commands
Quoted 2 lines
that are usually used for debugging purposes or during board bringup process. The internal interface is more important and it is much
easier an
Quoted 1 line
logical to just do "
i2c_set_bus(N)" and then use regulari2c_read/i2_write
Quoted 4 lines
or whatever is required. That makes the entire code uniform, without special
treatment for muxed busses etc. Kinda like Unix where everything's a file :)Quoted 5 lines · I wrote:
Quoted 5 lines
That has nothing to do with the "i2c bus" command. This command only adds new virtual buss to the "i2c dev" list (device number). you can then select this bus with "i2c dev [device number]" or in code with
i2c_set_bus_num([device number]). You see, this is also just an integer, you have to choose!Once again, you must with actual code also just do a
i2c_set_bus_num() to switch between busses (real or virtual).[...]
Quoted 5 lines
Quoted 5 lines
Ah, now I understand why you have to change all config files for all existing
boards which uses I2C. Think of my suggestion to integrate the "multi real bus"
in the existing code, so you dont have to do this ... boards whichhave
Quoted 2 lines
Quoted 2 lines
only
one Hardware I2C Bus automagically use this bus, becausei2c_bus_cur=
Quoted 3 lines
Quoted 1 line
0!
That is exactly what I'm going to do as a first step. For the new code
to
Quoted 1 line
take effect one must define "
CONFIG_NEW_I2C" in config file. If it is
Quoted 8 lines
not
Quoted 1 line
defined no new code is used. Then I will work on each and every
board/CPU
Quoted 1 line
one by one and when all of them are converted I will remove that
define.
OK,. But if I look in your patch you delete the "i2c bus" command, and this breaks at least 2 boards.
Yep. As I said it was not a real patch, just a request for comments. I will take care to make the real one work.
Quoted 7 lines
Quoted 4 lines
As a matter of fact I can only see 2 boards that use that existing mux code,
namely mgsuvd and mgcoge. That will be trivial to rework.Yes, for those I made the "i2c bus" command. And it will follow soon 2 more boards ...
OK, I will look at those boards and make sure they work. Anyway it is just a work in progress; no actual patch submitted so far...
Quoted 25 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
board's config file. That means we can use I2C from flash before
U-Boot is
Quoted 1 line
relocated to DRAM thus allowing us to use SPD for DRAM
initialization.
Quoted 12 lines
Quoted 12 lines
It is
Quoted 1 line
You can also use in actual code SPD EEprom for DRAM initialization. Guess
the following example:SPD EEprom reached over 2 muxes:
define an Environment var like:
SPD_EEprom=pca9554a:70:5:pca9544a:71:4Quoted 7 lines
Quoted 7 lines
now make bevor accessing the SPD EEprom:
i2c_mux_ident_muxstring_f(getenv ("SPD_EEprom");and you can access the SPD EEProm! (And nice side effect, the way to your
SPD EEprom is not fix in the code, you can choose it easy per Envvar!)
Quoted 1 line
Quoted 7 lines
Quoted 1 line
I don't think it is a good idea. It breaks uniformity, i.e. one would
have
Quoted 1 line
to have different functions for different boards (or unnecessary
overloaded
Quoted 1 line
functions that would fit all.)
It was just a example, to show, that it is possible, not actually used.
OK.
Quoted 32 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
also means we do NOT need that "i2c bus" or whatever command to
setup
Quoted 6 lines
Quoted 6 lines
a bus
Quoted 1 line
behind muxes for consecutive access--we just choose that bus number
and
Quoted 2 lines
that's it.
Quoted 8 lines
Quoted 5 lines
That has nothing to do with the "i2c bus" command. This command only adds new virtual buss to the "i2c dev" list (device number). you can then select this bus with "i2c dev [device number]" or in code with
i2c_set_bus_num([device number]). You see, this is also just an integer, you have to choose!I don't like an idea of adding virtual busses dynamically with an interactive command. Also it is not needed at all, one can easily
switch
Quoted 1 line
muxes manually, with simple memory write command for some muxes that
are
Quoted 2 lines
not
a part of board's permanent hardware.It is needed! If, for example an EEprom, is not always on the same virtual
bus. Some boards have no mux, some 1, some 2 ... and if we have this virtual
busses statically, we must have for all boards an extra u-boot binary. The only Hardware difference for this boards is, how things are connected
to the I2C bus ... and it is not OK for this manufacturer, to have for every board a different u-boot binary!
Quoted 3 lines
So, why shouldnt it possible to add to your proposal a possibility to add virtual i2c busses dynamically? (using a list instead of a fix table for example)
It is definitely a possibility but it would break uniformity. One can not use lists while U-Boot is running out of ROM and DRAM is not active. That means we should use an additional mechanism for those busses added later on.
One solution is to make num_i2c_busses (or whatever) a variable initially set by config file define and then modified when new busses are added. It also means we should use pointers instead of just array of structures and bring in the whole bunch of list management functions like find_next, find_prev, find_first etc. It might make board developer's life slightly easier but would add complexity to U-Boot and increase its memory footprint.
I'm not sure yet that that little convenience is worth that.
OK, I will return to it after I have that template driven multibus soft I2C driver done.
Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
All busses are explicitely defined in boards' config files so we
know
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
exactly where all accesses are going.
Actual Code too. Make a "i2c dev" and you get the actual bus number,
if
Quoted 2 lines
Quoted 2 lines
it is a virtual
bus, you can use "i2c bus" to get a list of this virtual busses.
Quoted 16 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
I did test it on MPC8548CDS system and it works OK. There is a patch
for
Quoted 1 line
MPC8548CDS.hin the patchset that changes it to the new I2C code anda
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
speculative example of multiadapter multibus configuration with 3
adapters
Quoted 1 line
and 5 busses 3 of which are connected with I2C muxes, 2 from them
are
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
multihop.
Nice, but why you ignored the existing interface for handling with muxes?
I think it is easier to extend the existing interface to support multiple "real"
interfaces ...
It steers us into a bunch of board-specific hacks and quirks instead of making something uniform. We do not have a luxury of working DRAM when we starting up and that code is required to bring up DRAM. I'm trying to avoid separate code for startup and full blown operation.
Furthermore, U-Boot is NOT an OS, it is a bootloader. It is nice to have a bunch of utility commands in its CLI but it is not what it is for. Hardware configuration is rigid as far as U-Boot concerned. One has such and such hardware onboard and he is free to choose anything from whatever is in but not to add anything else on the fly.
There is also no one-size-fits-all U-Boot, it is specifically built for each and every specific board. If you look at e.g. PC BIOS'es, they are made for exactly one specific motherboard. U-Boot is not different in this respect.
Quoted 10 lines
Quoted 1 line
I don't think it is needed at all. One has some number of busses on
the
Quoted 1 line
board and all of them are active. Just switch to another bus and
you're
Quoted 2 lines
good
to talk to that bus. If one needs something special, he can easilyachieve
Quoted 1 line
it with writing to those muxes with existing read/write commands.
But it is in the code, because it is needed!
I will return to it when it comes to the real patch.
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Please let me know guys what you think so I would be able to start
with a
Quoted 1 line
big patch.
I think, the mux functionality is independent from the problem to
have
Quoted 2 lines
Quoted 2 lines
more
then one hardware I2C Bus, or?
It is. But it's logical to reduce the number of entities and make everything a bus instead of having 2 different entities. Occam's Razor...
Quoted 6 lines
Quoted 1 line
No, it is dependent. Bus is a bus, no matter if it is a directly
connected
Quoted 1 line
one or reached through some muxes. It is easier to use one entity
(bus)
Quoted 1 line
instead of two separate ones (bus and mux.)
Quoted 15 lines
You are here wrong. You didnt read my answer. Again:
with "i2c bus" you add virtual busses
with "i2c dev" you can switch between real *and* this virtual busses,
without thinking about what sort of bus it is.just one command for switching between busses!
Quoted 7 lines
Quoted 7 lines
So, maybe you could integrate your "multiple hardware I2C Bus" concept (which looks good at a first look) in the existing code? I vote for accesing the I2C Bus over a mux with the actual way:
- defining with the "i2c bus" command a new "virtual" i2c device and
- accesing this with the standard command "i2c dev" because this is a more flexible way.
It is more flexible, I agree. But it multiplies entities. And doesn't add anything that couldn't be achieved with other existing commands.
Look, I2C bus behind muxes is just an already defined bus and a set of regular single-register I2C chips connected to that bus. In order to "add" that virtual bus one can simply switch to the appropriate existing bus and write a byte or two to those chips with existing i2c write commands.
That means that that "i2c bus" command in nothing more than a shortcut. It can be easily implemented even as U-Boot environmental variable that one can run...
Quoted 11 lines
Quoted 1 line
This is the command interface that is only of limited use. And there
is no
Quoted 1 line
need to make a CLI user manually setup anything that is already
defined in
Quoted 1 line
board config.
Really? If commands are saved in Environmentvars, they maybe executed automagic
on every reset ... thinking of for example "runnet_nfs" which uses at least
"tftp", "bootm", "setenv", ...
Exactly my point. Instead of making a cosmetic command one can simply use a sequence of "i2c dev existing_bus", "i2c mw mux_addr 0.0 some_value".
Quoted 10 lines
Quoted 1 line
CLI is easy, I'm now trying to make a template driven, self-generating
from
Quoted 1 line
config file multi-bus software I2C driver...
or just try to make this
i2c_adap_t*i2c_adap[CONFIG_SYS_NUM_I2C_ADAPTERS] =CONFIG_SYS_I2C_ADAPTERS;dynamically and extendable and I am happy ;-)
No, one can NOT use a dynamic set of adapters because this set determines which drivers got included into the final binary. This is COMPILE time define.
OK, let me make some real patch and then we'll return to our discussion :)
Anyways thank you very much for a feedback, I really appreciate it. And I will try to make you happy :)
---
******************************************************************
* KSI at home KOI8 Net < > The impossible we do immediately. *
* Las Vegas NV, USA < > Miracles require 24-hour notice. *
******************************************************************
cover I2C rework -- what do you think?
Hello ksi,
Quoted 5 lines · ksi at koi8.net wrote:
Quoted 4 lines · Heiko Schocher
Hello ksi,
Quoted 2 lines · ksi at koi8.net schrieb:
Quoted 1 line · Heiko Schocher
ksi at koi8.net wrote:
[...]
Quoted 5 lines
Quoted 2 lines
OK,. But if I look in your patch you delete the "i2c bus" command, and this breaks at least 2 boards.
Yep. As I said it was not a real patch, just a request for comments. I will take care to make the real one work.
Ok.
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
As a matter of fact I can only see 2 boards that use that existing mux code,
namely mgsuvd and mgcoge. That will be trivial to rework.Yes, for those I made the "i2c bus" command. And it will follow soon 2 more boards ...
OK, I will look at those boards and make sure they work. Anyway it is just a
work in progress; no actual patch submitted so far...
[...]
Quoted 19 lines
Quoted 10 lines
It is needed! If, for example an EEprom, is not always on the same virtual
bus. Some boards have no mux, some 1, some 2 ... and if we have this virtual
busses statically, we must have for all boards an extra u-boot binary. The only Hardware difference for this boards is, how things are connected
to the I2C bus ... and it is not OK for this manufacturer, to have for every board a different u-boot binary!Quoted 3 lines
So, why shouldnt it possible to add to your proposal a possibility to add virtual i2c busses dynamically? (using a list instead of a fix table for example)
It is definitely a possibility but it would break uniformity. One can not use lists while U-Boot is running out of ROM and DRAM is not active. That means we should use an additional mechanism for those busses added later on.
Quoted 7 lines
One solution is to make
num_i2c_busses(or whatever) a variable initially set by config file define and then modified when new busses are added. It also means we should use pointers instead of just array of structures and bring in the whole bunch of list management functions likefind_next,find_prev,find_firstetc. It might make board developer's life slightly easier but would add complexity to U-Boot and increase its memory footprint.
OK, let us think a little about it.
Quoted 4 lines
I'm not sure yet that that little convenience is worth that.
OK, I will return to it after I have that template driven multibus soft I2C driver done.
Ok.
Quoted 26 lines
Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
All busses are explicitely defined in boards' config files so we
know
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
exactly where all accesses are going.
Actual Code too. Make a "i2c dev" and you get the actual bus number,
if
Quoted 2 lines
Quoted 2 lines
it is a virtual
bus, you can use "i2c bus" to get a list of this virtual busses.Quoted 16 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
I did test it on MPC8548CDS system and it works OK. There is a patch
for
Quoted 1 line
MPC8548CDS.hin the patchset that changes it to the new I2C code anda
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
speculative example of multiadapter multibus configuration with 3
adapters
Quoted 1 line
and 5 busses 3 of which are connected with I2C muxes, 2 from them
are
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
multihop.
Nice, but why you ignored the existing interface for handling with muxes?
I think it is easier to extend the existing interface to support multiple "real"
interfaces ...
Quoted 4 lines
It steers us into a bunch of board-specific hacks and quirks instead of making something uniform. We do not have a luxury of working DRAM when we starting up and that code is required to bring up DRAM. I'm trying to avoid separate code for startup and full blown operation.
Yes, I know, this is a problem.
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
I don't think it is needed at all. One has some number of busses on
the
Quoted 1 line
board and all of them are active. Just switch to another bus and
you're
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
good
to talk to that bus. If one needs something special, he can easilyachieve
Quoted 1 line
it with writing to those muxes with existing read/write commands.
But it is in the code, because it is needed!
I will return to it when it comes to the real patch.
Ok, thanks.
[...]
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
So, maybe you could integrate your "multiple hardware I2C Bus" concept (which looks good at a first look) in the existing code? I vote for accesing the I2C Bus over a mux with the actual way:
- defining with the "i2c bus" command a new "virtual" i2c device and
- accesing this with the standard command "i2c dev" because this is a more flexible way.It is more flexible, I agree. But it multiplies entities. And doesn't add anything that couldn't be achieved with other existing commands.
Look, I2C bus behind muxes is just an already defined bus and a set of regular single-register I2C chips connected to that bus. In order to "add" that virtual bus one can simply switch to the appropriate existing bus and write a byte or two to those chips with existing i2c write commands.
Quoted 4 lines
That means that that "i2c bus" command in nothing more than a shortcut. It can be easily implemented even as U-Boot environmental variable that one can
run...
Hmm.. so we need no i2c mux support?
Quoted 9 lines
Quoted 9 lines
Quoted 1 line
CLI is easy, I'm now trying to make a template driven, self-generating
from
Quoted 1 line
config file multi-bus software I2C driver...
or just try to make this
i2c_adap_t*i2c_adap[CONFIG_SYS_NUM_I2C_ADAPTERS] =CONFIG_SYS_I2C_ADAPTERS;
Quoted 7 lines
Quoted 1 line
dynamically and extendable and I am happy ;-)
No, one can NOT use a dynamic set of adapters because this set determines which drivers got included into the final binary. This is COMPILE time define.
OK, let me make some real patch and then we'll return to our discussion :)
Ok.
Quoted 2 lines
Anyways thank you very much for a feedback, I really appreciate it. And I will try to make you happy :)
:-)
bye
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
cover I2C rework -- what do you think?
On Thu, 29 Jan 2009, Heiko Schocher wrote:
[dd]
Quoted 8 lines
Quoted 1 line
That means that that "i2c bus" command in nothing more than a
shortcut. It
Quoted 1 line
can be easily implemented even as U-Boot environmental variable that
one
Quoted 2 lines
can
run...Hmm.. so we need no i2c mux support?
Yep. It can be emulated by a couple of existing commands.
---
******************************************************************
* KSI at home KOI8 Net < > The impossible we do immediately. *
* Las Vegas NV, USA < > Miracles require 24-hour notice. *
******************************************************************