[U-Boot-Users] Using a second I2C interface
Menon, Nishanth
x0nishan at ti.com
Tue May 16 16:50:04 CEST 2006
Hi All,
Here is another approach I followed for OMAP2430 (which has 2 i2c controller, one of which is a High speed I2C controller).
common/cmd_i2c.c:
#if defined(CFG_I2C_BUS_SELECT)
int do_i2c_bus(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
int bus_idx, bus_spd, res = 0;
if (argc < 3) {
printf("Usage[%d]:\n%s\n", argc, cmdtp->usage);
return 1;
}
bus_idx = simple_strtoul(argv[1], NULL, 16);
bus_spd = simple_strtoul(argv[2], NULL, 16);
printf("Setting bus[%d] to Speed[%d]: ", bus_idx, bus_spd);
res = select_bus(bus_idx, bus_spd);
if (res) {
printf("FAILED\n");
} else {
printf("PASS\n");
}
return res;
}
#endif /* bus select */
#if defined(CFG_I2C_BUS_SELECT)
U_BOOT_CMD(ibus, 3, 1, do_i2c_bus,
"ibus - Select i2c Bus\n",
"bus_index speed\n - Selects the bus index and sets the speed (0x64(ST),0x190(FS),0xD48(HS))\n"
" (reports success/failure)\n");
#endif
Allows one to select the bus and then use the normal i2c cmds to work on it.. speed of the bus is not variable and is coded into macros.
Regards,
Nishanth Menon
________________________________________
From: u-boot-users-admin at lists.sourceforge.net [mailto:u-boot-users-admin at lists.sourceforge.net] On Behalf Of Ben Warren
Sent: Friday, May 12, 2006 1:28 PM
To: Kumar Gala
Cc: u-boot-users at lists.sourceforge.net
Subject: Re: [U-Boot-Users] Using a second I2C interface
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
. On Fri, 2006-05-12 at 13:00 -0500, Kumar Gala wrote:
On May 12, 2006, at 9:36 AM, Ben Warren wrote:
> 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
More information about the U-Boot
mailing list