Skip to contentSkip to conversation

Using a second I2C interface

U-Boot-Users Ben Warren 4 participants 8 messages May 12, 2006 – May 16, 2006

lore
Share & tools
lore

Ben Warren

author
#0 lore raw

Hello,

The CPU I'm using (MPC8349) has two hardware I2C interfaces, and I'd like to access the second one in U-boot. Implementing this looks easy to me, but I don't want to reinvent the wheel if it's already been done elsewhere. Has anyone done this? If not, I'll follow up with a proposal.

regards,
Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.denx.de/pipermail/u-boot/attachments/20060512/a8a75115/attachment.htm

author
#1 lore raw

Let me follow up by saying that there is some kludgy code that uses the second port, but it's hard-coded and not nearly generic enough in my mind.

Ben

Quoted 10 lines · Ben Warren

Hello,

The CPU I'm using (MPC8349) has two hardware I2C interfaces, and I'd like to access the second one in U-boot. Implementing this looks easy to me, but I don't want to reinvent the wheel if it's already been done elsewhere. Has anyone done this? If not, I'll follow up with a proposal.

regards,
Ben

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.denx.de/pipermail/u-boot/attachments/20060512/9fc6238f/attachment.htm

#2 lore raw
In reply to Ben Warren
Quoted 7 lines · Ben Warren

Hello,

The CPU I'm using (MPC8349) has two hardware I2C interfaces, and I'd like to access the second one in U-boot. Implementing this looks easy to me, but I don't want to reinvent the wheel if it's already been done elsewhere. Has anyone done this? If not, I'll follow up with a proposal.

Depending on what you want to do, you can cheat and just change the pointer to the 2nd interface. If you want something more full featured up to the command level then I think some discussion would be required on how the commands should work for specifying which controller to use.

- kumar

author
#3 lore raw

Here's how I've done things in my sandbox:

All public I2C calls take a uchar as the first argument. Since I2C only uses 7 bits for addressing, the MSB is unused (at least, at the function call level. I know the hardware uses the bit for w/r). I've commandeered this bit to denote controller number. This way, the existing API doesn't need to be changed, just the drivers that choose to implement it. I've modified the MPC8349 driver and the 'iprobe' command to do this. To use the other commands, as well as the API itself, I've just been adding 0x80 manually, but it could be done more nicely like:

#define i2c_wr(bus, dev, ...) i2c_write((bus)==2 ? dev+0x80 : dev, ...)

Of course, this solution isn't scalable beyond two controllers, but I'm not sure we need to worry about that.

Any thoughts?

Ben

Quoted 10 lines · Kumar Gala
Quoted 7 lines · Ben Warren

Hello,

The CPU I'm using (MPC8349) has two hardware I2C interfaces, and I'd like to access the second one in U-boot. Implementing this looks easy to me, but I don't want to reinvent the wheel if it's already been done elsewhere. Has anyone done this? If not, I'll follow up with a proposal.

Quoted 7 lines

Depending on what you want to do, you can cheat and just change the pointer to the 2nd interface. If you want something more full featured up to the command level then I think some discussion would be required on how the commands should work for specifying which controller to use.

- kumar

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.denx.de/pipermail/u-boot/attachments/20060512/c33e880b/attachment.htm

#4 lore raw
Quoted 7 lines · In message <[email protected]> you wrote:

Here's how I've done things in my sandbox:

All public I2C calls take a uchar as the first argument. Since I2C only uses 7 bits for addressing, the MSB is unused (at least, at the function call level. I know the hardware uses the bit for w/r). I've commandeered this bit to denote controller number. This way, the

And what if you have 3 I2C busses? Sorry, but I will no accept such a hack.

Best regards,

Wolfgang Denk

Signature · 4 lines
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
There is an order of things in this universe.
	-- Apollo, "Who Mourns for Adonais?" stardate 3468.1
#5 lore raw
In reply to Kumar Gala

Hello,

Quoted 7 lines · in message <[email protected]> you wrote:
Quoted 6 lines

The CPU I'm using (MPC8349) has two hardware I2C interfaces, and I'd like to access the second one in U-boot. Implementing this looks easy to me, but I don't want to reinvent the wheel if it's already been done elsewhere. Has anyone done this? If not, I'll follow up with a proposal.

Quoted 5 lines

Depending on what you want to do, you can cheat and just change the pointer to the 2nd interface. If you want something more full featured up to the command level then I think some discussion would be required on how the commands should work for specifying which controller to use.

A clean design should allow to switch I2C busses usign a command; additionally, I think we should try to stay backward-compatible with the existing code. Eventually this is not too difficult: similar to the "ide" or "usb" commands we could create a new command "i2c device" which takes as argument the number of the I2C bus which shal become the current (= active) bus. Then all existing I2C related commands can be left unchanged (and "i2c device" without arguments should of course print the ID of the current bus).

In parallel, existing I2C commands could be changed to migrate to a new "i2c" group of commands: "imd" would become "i2c md", "imw" becomes "i2c mw", "iprobe" becomes "i2c probe", etc. For some (long) transition period old and new commands could be provided in parallel (at least optionally). Later, the old syntax could be dropped.

Best regards,

Wolfgang Denk

Signature · 4 lines
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Ever try. Ever fail. No matter. Try again. Fail again.  Fail  better.
                                                        -- S. Beckett
#6 lore raw

Hello!

Quoted 8 lines · Wolfgang Denk

A clean design should allow to switch I2C busses usign a command; additionally, I think we should try to stay backward-compatible with the existing code. Eventually this is not too difficult: similar to the "ide" or "usb" commands we could create a new command "i2c device" which takes as argument the number of the I2C bus which shal become the current (= active) bus. Then all existing I2C related commands can be left unchanged (and "i2c device" without arguments should of course print the ID of the current bus).

It has to be taken into account that the I2C busses may have different adress length. So either the address length has to be read back from the low-level driver or a table has to be maintained in the I2C command implementations.

With best regards
Andreas Schweigstill

PS.: Has anybody written some "high-level" I2C commands for chipcard
interfaces?

Signature · 5 lines
Dipl.-Phys. Andreas Schweigstill
Schweigstill IT | Embedded Systems
Schauenburgerstra?e 116, D-24118 Kiel, Germany
Phone: (+49) 431 5606-435, Fax: (+49) 431 5606-436
Mobile: (+49) 171 6921973, Web: http://www.schweigstill.de/
author
#7 lore raw
In reply to Wolfgang Denk

Wolfgang,

This sounds like a sensible approach. This should clean the code up nicely (as you'll notice, the patch that I submitted yesterday adds quite a bit of noisy code). Let's look at what Richard Woodruff submits, and we can take it from there.

Too bad I didn't get your input until this morning, even though your message went out on Friday...

regards,
Ben

Quoted 31 lines · Wolfgang Denk

Hello,

Quoted 7 lines · in message <[email protected]> you wrote:
Quoted 6 lines

The CPU I'm using (MPC8349) has two hardware I2C interfaces, and I'd like to access the second one in U-boot. Implementing this looks easy to me, but I don't want to reinvent the wheel if it's already been done elsewhere. Has anyone done this? If not, I'll follow up with a proposal.

Quoted 5 lines

Depending on what you want to do, you can cheat and just change the pointer to the 2nd interface. If you want something more full featured up to the command level then I think some discussion would be required on how the commands should work for specifying which controller to use.

A clean design should allow to switch I2C busses usign a command; additionally, I think we should try to stay backward-compatible with the existing code. Eventually this is not too difficult: similar to the "ide" or "usb" commands we could create a new command "i2c device" which takes as argument the number of the I2C bus which shal become the current (= active) bus. Then all existing I2C related commands can be left unchanged (and "i2c device" without arguments should of course print the ID of the current bus).

In parallel, existing I2C commands could be changed to migrate to a new "i2c" group of commands: "imd" would become "i2c md", "imw" becomes "i2c mw", "iprobe" becomes "i2c probe", etc. For some (long) transition period old and new commands could be provided in parallel (at least optionally). Later, the old syntax could be dropped.

Quoted 4 lines

Best regards,

Wolfgang Denk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.denx.de/pipermail/u-boot/attachments/20060516/2d97f759/attachment.htm